Browse Source

[Pal] add __attribute__((format (printf, )))

Add __attribute__((format (printf, ))) to functions where appropriate.
and fix found format mismatch.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
Isaku Yamahata 5 years ago
parent
commit
58cb88d2c1

+ 3 - 3
Pal/src/host/Linux-SGX/enclave_framework.c

@@ -56,7 +56,7 @@ int sgx_get_report (sgx_arch_hash_t * mrenclave,
         return -PAL_ERROR_DENIED;
 
     SGX_DBG(DBG_S, "Generated report:\n");
-    SGX_DBG(DBG_S, "    cpusvn:           %08x %08x\n", report->cpusvn[0],
+    SGX_DBG(DBG_S, "    cpusvn:           %08lx %08lx\n", report->cpusvn[0],
                                                 report->cpusvn[1]);
     SGX_DBG(DBG_S, "    mrenclave:        %s\n",        alloca_bytes2hexstr(report->mrenclave));
     SGX_DBG(DBG_S, "    mrsigner:         %s\n",        alloca_bytes2hexstr(report->mrsigner));
@@ -488,7 +488,7 @@ int copy_and_verify_trusted_file (const char * path, const void * umem,
          */
         if (memcmp(s, hash, sizeof(sgx_stub_t))) {
             SGX_DBG(DBG_E, "Accesing file:%s is denied. Does not match with MAC"
-                    " at chunk starting at %llu-%llu.\n",
+                    " at chunk starting at %lu-%lu.\n",
                     path, checking, checking_end);
             return -PAL_ERROR_DENIED;
         }
@@ -571,7 +571,7 @@ static int register_trusted_file (const char * uri, const char * checksum_str)
         }
 
         new->index = (++trusted_file_indexes);
-        SGX_DBG(DBG_S, "trusted: [%d] %s %s\n", new->index,
+        SGX_DBG(DBG_S, "trusted: [%ld] %s %s\n", new->index,
                 checksum_text, new->uri);
     } else {
         memset(&new->checksum, 0, sizeof(sgx_checksum_t));

+ 7 - 7
Pal/src/host/Linux-SGX/enclave_pages.c

@@ -35,7 +35,7 @@ void init_pages (void)
     heap_base = pal_sec.heap_min;
     heap_size = pal_sec.heap_max - pal_sec.heap_min;
 
-    SGX_DBG(DBG_M, "available heap size: %llu M\n",
+    SGX_DBG(DBG_M, "available heap size: %lu M\n",
            (heap_size - pal_sec.exec_size) / 1024 / 1024);
 
     if (pal_sec.exec_size) {
@@ -77,7 +77,7 @@ void * get_reserved_pages(void * addr, uint64_t size)
     if (!size)
         return NULL;
 
-    SGX_DBG(DBG_M, "*** get_reserved_pages: heap_base %p, heap_size %llu, limit %p ***\n", heap_base, heap_size, heap_base + heap_size);
+    SGX_DBG(DBG_M, "*** get_reserved_pages: heap_base %p, heap_size %lu, limit %p ***\n", heap_base, heap_size, heap_base + heap_size);
     if (addr >= heap_base + heap_size) {
         SGX_DBG(DBG_E, "*** allocating out of heap: %p ***\n", addr);
         return NULL;
@@ -89,7 +89,7 @@ void * get_reserved_pages(void * addr, uint64_t size)
     if ((uintptr_t) addr & (pgsz - 1))
         addr = (void *) ((uintptr_t) addr & ~(pgsz - 1));
 
-    SGX_DBG(DBG_M, "allocate %d bytes at %p\n", size, addr);
+    SGX_DBG(DBG_M, "allocate %ld bytes at %p\n", size, addr);
 
     _DkInternalLock(&heap_vma_lock);
 
@@ -135,7 +135,7 @@ void * get_reserved_pages(void * addr, uint64_t size)
 
     _DkInternalUnlock(&heap_vma_lock);
 
-    SGX_DBG(DBG_E, "*** Not enough space on the heap (requested = %llu) ***\n", size);
+    SGX_DBG(DBG_E, "*** Not enough space on the heap (requested = %lu) ***\n", size);
     __asm__ volatile("int $3");
     return NULL;
 
@@ -256,7 +256,7 @@ void free_pages(void * addr, uint64_t size)
 {
     void * addr_top = addr + size;
 
-    SGX_DBG(DBG_M, "free_pages: trying to free %p %llu\n", addr, size);
+    SGX_DBG(DBG_M, "free_pages: trying to free %p %lu\n", addr, size);
     
     if (!addr || !size)
         return;
@@ -276,7 +276,7 @@ void free_pages(void * addr, uint64_t size)
     if (addr < heap_base)
         addr = heap_base;
 
-    SGX_DBG(DBG_M, "free %d bytes at %p\n", size, addr);
+    SGX_DBG(DBG_M, "free %ld bytes at %p\n", size, addr);
 
     _DkInternalLock(&heap_vma_lock);
 
@@ -317,6 +317,6 @@ void print_alloced_pages (void)
     unsigned int max = atomic_read(&max_alloced_pages);
 
     printf("                >>>>>>>> "
-           "Enclave heap size =         %10ld pages / %10ld pages\n",
+           "Enclave heap size =         %10d pages / %10ld pages\n",
            val > max ? val : max, heap_size / pgsz);
 }

+ 1 - 1
Pal/src/host/Linux/db_exception.c

@@ -186,7 +186,7 @@ static void _DkGenericSighandler (int signum, siginfo_t * info,
         }
 
         printf("*** An unexpected %s occurred inside PAL. Exiting the thread. "
-               "(PID = %d, TID = %d, RIP = +%p) ***\n",
+               "(PID = %d, TID = %d, RIP = +0x%08lx) ***\n",
                name, pid, tid, rip - (uintptr_t) TEXT_START);
 
 #ifdef DEBUG

+ 2 - 2
Pal/src/pal_internal.h

@@ -401,9 +401,9 @@ void free (void * mem);
 #endif
 
 void _DkPrintConsole (const void * buf, int size);
-int printf  (const char  *fmt, ...);
+int printf  (const char  *fmt, ...) __attribute__((format (printf, 1, 2)));
 #include <stdarg.h>
-int vprintf(const char * fmt, va_list *ap);
+int vprintf(const char * fmt, va_list *ap) __attribute__((format (printf, 1, 0)));
 void write_log (int nstrs, ...);
 
 static inline void log_stream (const char * uri)