Parcourir la source

[Pal/Linux-SGX] Add format check to pal_printf

Add __attribute__((format(printf))) check to pal_printf and
fix corresponding format errors.
Isaku Yamahata il y a 5 ans
Parent
commit
8dd311a353

+ 8 - 8
Pal/regression/AtomicMath.c

@@ -23,9 +23,9 @@ int main (int argc, char ** argv, char ** envp)
   atomic_sub(INT_MIN, &a_int);
 
   if (my_int == atomic_read(&a_int))
-    pal_printf("Subtract INT_MIN: Both values match %lld\n", my_int);
+    pal_printf("Subtract INT_MIN: Both values match %ld\n", my_int);
   else
-    pal_printf("Subtract INT_MIN: Values do not match %lld, %lld\n", my_int, atomic_read(&a_int));
+    pal_printf("Subtract INT_MIN: Values do not match %ld, %ld\n", my_int, atomic_read(&a_int));
 
   atomic_set(&a_int, 0);
   my_int = 0;
@@ -34,9 +34,9 @@ int main (int argc, char ** argv, char ** envp)
   atomic_sub(INT_MAX, &a_int);
 
   if (my_int == atomic_read(&a_int))
-    pal_printf("Subtract INT_MAX: Both values match %lld\n", my_int);
+    pal_printf("Subtract INT_MAX: Both values match %ld\n", my_int);
   else
-    pal_printf("Subtract INT_MAX: Values do not match %lld, %lld\n", my_int, atomic_read(&a_int));
+    pal_printf("Subtract INT_MAX: Values do not match %ld, %ld\n", my_int, atomic_read(&a_int));
   
   /* Check that 64-bit signed values also wrap properly. */
   atomic_set(&a_int, 0);
@@ -46,9 +46,9 @@ int main (int argc, char ** argv, char ** envp)
   atomic_sub(LLONG_MIN, &a_int);
 
   if (my_int == atomic_read(&a_int))
-    pal_printf("Subtract LLONG_MIN: Both values match %lld\n", my_int);
+    pal_printf("Subtract LLONG_MIN: Both values match %ld\n", my_int);
   else
-    pal_printf("Subtract LLONG_MIN: Values do not match %lld, %lld\n", my_int, atomic_read(&a_int));
+    pal_printf("Subtract LLONG_MIN: Values do not match %ld, %ld\n", my_int, atomic_read(&a_int));
 
   atomic_set(&a_int, 0);
   my_int = 0;
@@ -57,9 +57,9 @@ int main (int argc, char ** argv, char ** envp)
   atomic_sub(LLONG_MAX, &a_int);
 
   if (my_int == atomic_read(&a_int))
-    pal_printf("Subtract LLONG_MAX: Both values match %lld\n", my_int);
+    pal_printf("Subtract LLONG_MAX: Both values match %ld\n", my_int);
   else
-    pal_printf("Subtract LLONG_MAX: Values do not match %lld, %lld\n", my_int, atomic_read(&a_int));
+    pal_printf("Subtract LLONG_MAX: Values do not match %ld, %ld\n", my_int, atomic_read(&a_int));
 
   
   return 0;

+ 9 - 9
Pal/regression/Bootstrap.c

@@ -27,22 +27,22 @@ int main (int argc, char ** argv, char ** envp)
         pal_printf("argv[%d] = %s\n", i, argv[i]);
 
     /* unique process ID */
-    pal_printf("Process ID: %016x\n", pal_control.process_id);
+    pal_printf("Process ID: %016lx\n", pal_control.process_id);
 
     /* unique host ID */
-    pal_printf("Host ID: %016x\n", pal_control.host_id);
+    pal_printf("Host ID: %016lx\n", pal_control.host_id);
 
     /* parent process */
-    pal_printf("Parent Process: %016lx\n", pal_control.parent_process);
+    pal_printf("Parent Process: %p\n", pal_control.parent_process);
 
     /* test debug stream */
     char msg[] = "Written to Debug Stream\n";
     DkStreamWrite(pal_control.debug_stream, 0, sizeof(msg), msg, NULL);
 
     /* page size */
-    pal_printf("Page Size: %d\n", pal_control.pagesize);
+    pal_printf("Page Size: %ld\n", pal_control.pagesize);
     /* Allocation Alignment */
-    pal_printf("Allocation Alignment: %d\n", pal_control.alloc_align);
+    pal_printf("Allocation Alignment: %ld\n", pal_control.alloc_align);
 
     /* user address range */
     pal_printf("User Address Range: %p - %p\n",
@@ -67,12 +67,12 @@ int main (int argc, char ** argv, char ** envp)
         (void *) &test_func < pal_control.executable_range.end)
         pal_printf("Executable Range OK\n");
 
-    pal_printf("CPU num: %d\n",      pal_control.cpu_info.cpu_num);
+    pal_printf("CPU num: %ld\n",      pal_control.cpu_info.cpu_num);
     pal_printf("CPU vendor: %s\n",   pal_control.cpu_info.cpu_vendor);
     pal_printf("CPU brand: %s\n",    pal_control.cpu_info.cpu_brand);
-    pal_printf("CPU family: %d\n",   pal_control.cpu_info.cpu_family);
-    pal_printf("CPU model: %d\n",    pal_control.cpu_info.cpu_model);
-    pal_printf("CPU stepping: %d\n", pal_control.cpu_info.cpu_stepping);
+    pal_printf("CPU family: %ld\n",   pal_control.cpu_info.cpu_family);
+    pal_printf("CPU model: %ld\n",    pal_control.cpu_info.cpu_model);
+    pal_printf("CPU stepping: %ld\n", pal_control.cpu_info.cpu_stepping);
     pal_printf("CPU flags: %s\n",    pal_control.cpu_info.cpu_flags);
 
     return 0;

+ 3 - 3
Pal/regression/Exception.c

@@ -11,7 +11,7 @@
 
 void handler1 (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
 {
-    pal_printf("Arithmetic Exception Handler 1: %p, rip = %p\n",
+    pal_printf("Arithmetic Exception Handler 1: 0x%08lx, rip = 0x%08lx\n",
                arg, context->rip);
 
     while (*(unsigned char *) context->rip != 0x90)
@@ -22,7 +22,7 @@ void handler1 (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
 
 void handler2 (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
 {
-    pal_printf("Arithmetic Exception Handler 2: %p, rip = %p\n",
+    pal_printf("Arithmetic Exception Handler 2: 0x%08lx, rip = 0x%08lx\n",
                arg, context->rip);
 
     while (*(unsigned char *) context->rip != 0x90)
@@ -33,7 +33,7 @@ void handler2 (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
 
 void handler3 (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
 {
-    pal_printf("Memory Fault Exception Handler: %p, rip = %p\n",
+    pal_printf("Memory Fault Exception Handler: 0x%08lx, rip = 0x%08lx\n",
                arg, context->rip);
 
     while (*(unsigned char *) context->rip != 0x90)

+ 2 - 2
Pal/regression/File.c

@@ -57,7 +57,7 @@ int main (int argc, char ** argv, char ** envp)
 
         PAL_STREAM_ATTR attr1;
         if (DkStreamAttributesQuerybyHandle(file1, &attr1))
-            pal_printf("Query by Handle: type = %d, size = %d\n",
+            pal_printf("Query by Handle: type = %d, size = %ld\n",
                        attr1.handle_type, attr1.pending_size);
 
         /* test file map */
@@ -108,7 +108,7 @@ int main (int argc, char ** argv, char ** envp)
 
     PAL_STREAM_ATTR attr2;
     if (DkStreamAttributesQuery("file:File", &attr2))
-        pal_printf("Query: type = %d, size = %d\n",
+        pal_printf("Query: type = %d, size = %ld\n",
                    attr2.handle_type, attr2.pending_size);
 
     /* test regular file creation */

+ 1 - 1
Pal/regression/Ipc.c

@@ -12,7 +12,7 @@ static const char * volatile message = NULL;
 void handler (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
 {
     if (message)
-        pal_printf(message);
+        pal_printf("%s", message);
 
     while (*(unsigned char *) context->rip != 0x90)
         context->rip++;

+ 1 - 1
Pal/regression/Memory.c

@@ -72,7 +72,7 @@ int main (int argc, char ** argv, char ** envp)
         pal_printf("Memory Allocation with Address OK\n");
 
     /* Testing total memory */
-    pal_printf("Total Memory: %llu\n", pal_control.mem_info.mem_total);
+    pal_printf("Total Memory: %lu\n", pal_control.mem_info.mem_total);
 
     /* Testing available memory (must be within valid range) */
     PAL_NUM avail = DkMemoryAvailableQuota();

+ 4 - 4
Pal/regression/Misc.c

@@ -10,8 +10,8 @@ int main (int argc, const char ** argv, const char ** envp)
     unsigned long time1 = DkSystemTimeQuery();
     unsigned long time2 = DkSystemTimeQuery();
 
-    pal_printf("Time Query 1: %lld\n", time1);
-    pal_printf("Time Query 2: %lld\n", time2);
+    pal_printf("Time Query 1: %ld\n", time1);
+    pal_printf("Time Query 2: %ld\n", time2);
 
     if (time1 <= time2)
         pal_printf("Query System Time OK\n");
@@ -20,7 +20,7 @@ int main (int argc, const char ** argv, const char ** envp)
     DkThreadDelayExecution(10000);
     unsigned long time4 = DkSystemTimeQuery();
 
-    pal_printf("Sleeped %lld Microseconds\n", time4 - time3);
+    pal_printf("Sleeped %ld Microseconds\n", time4 - time3);
 
     if (time3 < time4 && time4 - time3 > 10000)
         pal_printf("Delay Execution for 10000 Microseconds OK\n");
@@ -29,7 +29,7 @@ int main (int argc, const char ** argv, const char ** envp)
     DkThreadDelayExecution(3000000);
     unsigned long time6 = DkSystemTimeQuery();
 
-    pal_printf("Sleeped %lld Microseconds\n", time6 - time5);
+    pal_printf("Sleeped %ld Microseconds\n", time6 - time5);
 
     if (time5 < time6 && time6 - time5 > 3000000)
         pal_printf("Delay Execution for 3 Seconds OK\n");

+ 3 - 3
Pal/regression/Semaphore.c

@@ -18,9 +18,9 @@ void helper_timeout(PAL_NUM timeout) {
     /* Wait on the binary semaphore with a timeout */
     PAL_HANDLE rv = DkObjectsWaitAny(1, &sem1, timeout);
     if (rv == NULL)
-        pal_printf("Locked binary semaphore timed out (%d).\n", timeout);
+        pal_printf("Locked binary semaphore timed out (%ld).\n", timeout);
     else 
-        pal_printf("Acquired locked binary semaphore!?! Got back %p; sem1 is %p (%d)\n", rv, sem1, timeout);
+        pal_printf("Acquired locked binary semaphore!?! Got back %p; sem1 is %p (%ld)\n", rv, sem1, timeout);
     
     DkObjectClose(sem1);
 }
@@ -38,7 +38,7 @@ void helper_success(PAL_NUM timeout) {
     /* Wait on the binary semaphore with a timeout */
     PAL_HANDLE rv = DkObjectsWaitAny(1, &sem1, timeout);
     if (rv == sem1)
-        pal_printf("Locked binary semaphore successfully (%d).\n", timeout);
+        pal_printf("Locked binary semaphore successfully (%ld).\n", timeout);
     else 
         pal_printf("Failed to lock binary semaphore: Got back %p; sem1 is %p\n", rv, sem1);
     

+ 1 - 1
Pal/regression/Thread.c

@@ -12,7 +12,7 @@ static volatile int count1 = 0;
 
 int callback1 (void * args)
 {
-    pal_printf("Run in Child Thread: %s\n", args);
+    pal_printf("Run in Child Thread: %s\n", (char *) args);
 
     while (count1 < 10) {
         while (!(count1 % 2))

+ 1 - 1
Pal/src/host/Linux-SGX/pal_linux.h

@@ -215,7 +215,7 @@ extern struct pal_enclave_config {
 #define SGX_DBG(class, fmt...) \
     do { if ((class) & DBG_LEVEL) printf(fmt); } while (0)
 #else
-int pal_printf(const char * fmt, ...);
+#include <pal_debug.h>
 
 #define SGX_DBG(class, fmt...) \
     do { if ((class) & DBG_LEVEL) pal_printf(fmt); } while (0)

+ 1 - 1
Pal/src/host/Linux-SGX/sgx_enclave.c

@@ -27,7 +27,7 @@ static int sgx_ocall_exit(void* prv)
     int64_t rv = (int64_t) prv;
     ODEBUG(OCALL_EXIT, NULL);
     if (rv != (int64_t) ((uint8_t) rv)) {
-        SGX_DBG(DBG_E, "Saturation error in exit code %d, getting rounded down to %u\n", rv, (uint8_t) rv);
+        SGX_DBG(DBG_E, "Saturation error in exit code %ld, getting rounded down to %u\n", rv, (uint8_t) rv);
         rv = 255;
     }
     INLINE_SYSCALL(exit, 1, (int)rv);

+ 4 - 4
Pal/src/host/Linux-SGX/sgx_framework.c

@@ -176,7 +176,7 @@ int create_enclave(sgx_arch_secs_t * secs,
                        "You may need to set sysctl vm.mmap_min_addr to zero\n");
 
         SGX_DBG(DBG_I, "enclave ECREATE failed in allocating EPC memory "
-                "(errno = %d)\n", ERRNO_P(addr));
+                "(errno = %ld)\n", ERRNO_P(addr));
         return -ENOMEM;
     }
 
@@ -214,7 +214,7 @@ int create_enclave(sgx_arch_secs_t * secs,
     SGX_DBG(DBG_I, "    miscselect:   0x%08x\n",   secs->miscselect);
     SGX_DBG(DBG_I, "    attr:         0x%016lx\n", secs->attributes.flags);
     SGX_DBG(DBG_I, "    xfrm:         0x%016lx\n", secs->attributes.xfrm);
-    SGX_DBG(DBG_I, "    ssaframesize: %ld\n",      secs->ssaframesize);
+    SGX_DBG(DBG_I, "    ssaframesize: %d\n",       secs->ssaframesize);
     SGX_DBG(DBG_I, "    isvprodid:    0x%08x\n",   secs->isvprodid);
     SGX_DBG(DBG_I, "    isvsvn:       0x%08x\n",   secs->isvsvn);
 
@@ -264,10 +264,10 @@ int add_pages_to_enclave(sgx_arch_secs_t * secs,
     }
 
     if (size == pagesize)
-        SGX_DBG(DBG_I, "adding page  to enclave: %016lx [%s:%s] (%s)%s\n",
+        SGX_DBG(DBG_I, "adding page  to enclave: %p [%s:%s] (%s)%s\n",
                 addr, t, p, comment, m);
     else
-        SGX_DBG(DBG_I, "adding pages to enclave: %016lx-%016lx [%s:%s] (%s)%s\n",
+        SGX_DBG(DBG_I, "adding pages to enclave: %p-%p [%s:%s] (%s)%s\n",
                 addr, addr + size, t, p, comment, m);
 
 

+ 1 - 1
Pal/src/host/Linux-SGX/sgx_thread.c

@@ -54,7 +54,7 @@ void unmap_tcs (void)
     struct thread_map * map = &enclave_thread_map[index];
     if (index >= enclave_thread_num)
         return;
-    SGX_DBG(DBG_I, "unmap TCS at 0x%08lx\n", map->tcs);
+    SGX_DBG(DBG_I, "unmap TCS at %p\n", map->tcs);
     current_tcs = NULL;
     ((struct enclave_dbginfo *) DBGINFO_ADDR)->thread_tids[index] = 0;
     map->tid = 0;

+ 1 - 1
Pal/src/pal_debug.h

@@ -29,7 +29,7 @@
 #include "pal.h"
 #include <assert.h>
 
-int pal_printf (const char *fmt, ...);
+int pal_printf (const char *fmt, ...) __attribute__((format(printf, 1, 2)));
 
 void DkDebugAttachBinary (PAL_STR uri, PAL_PTR start_addr);
 void DkDebugDetachBinary (PAL_PTR start_addr);

+ 1 - 1
Pal/test/Cpuid.c

@@ -17,7 +17,7 @@ int main (int argc, char ** argv, char ** envp)
                    "=d"(values[3])
                 :: "memory");
 
-    pal_printf("cpuid[0] = %08x %08x %08x %08x\n", values[0], values[1],
+    pal_printf("cpuid[0] = %08lx %08lx %08lx %08lx\n", values[0], values[1],
                values[2], values[3]);
 
     return 0;

+ 1 - 1
Pal/test/Exception.c

@@ -11,7 +11,7 @@ int i = 0;
 
 void handler (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
 {
-    pal_printf("failure in the handler: %p\n", arg);
+    pal_printf("failure in the handler: 0x%08lx\n", arg);
     count++;
 
     if (count == 30)

+ 2 - 2
Pal/test/Fork.c

@@ -18,12 +18,12 @@ PAL_HANDLE _fork (void * args)
 
     if (args == NULL) {
         struct stack_frame cur_frame = *frame;
-        pal_printf("return address is %08x\n", cur_frame.ret);
+        pal_printf("return address is %p\n", cur_frame.ret);
         return DkThreadCreate(&_fork, &cur_frame);
     }
     else {
         struct stack_frame * las_frame = (struct stack_frame *) args;
-        pal_printf("(in child) return address is %08x\n", las_frame->ret);
+        pal_printf("(in child) return address is %p\n", las_frame->ret);
         return NULL;
     }
 }

+ 1 - 1
Pal/test/Process.c

@@ -53,7 +53,7 @@ int main (int argc, char ** argv)
         } else {
             unsigned long end = DkSystemTimeQuery ();
             unsigned long start = atol (argv[2]);
-            pal_printf ("wall time = %d\n", end - start);
+            pal_printf ("wall time = %ld\n", end - start);
         }
     }
 

+ 1 - 1
Pal/test/Tcp.c

@@ -93,7 +93,7 @@ int main (int argc, char ** argv)
         pal_printf("end time = %lu\n", end);
 
         unsigned long start = atol(argv[1]);
-        pal_printf("wall time = %d\n", end - start);
+        pal_printf("wall time = %ld\n", end - start);
 
         int retval = 0;
         DkStreamWrite(pal_control.parent_process, 0, sizeof(int), &retval, NULL);

+ 1 - 1
Pal/test/Udp.c

@@ -43,7 +43,7 @@ int main (int argc, char ** argv)
         }
 
         unsigned long end = DkSystemTimeQuery();
-        pal_printf("wall time = %d\n", end - start);
+        pal_printf("wall time = %ld\n", end - start);
 
         int retval;
         DkStreamRead(proc, 0, sizeof(int), &retval, NULL, 0);