Przeglądaj źródła

[Pal] Add noreturn function attribute where appropriate

Isaku Yamahata 5 lat temu
rodzic
commit
312159dbcb

+ 3 - 1
Pal/lib/assert.h

@@ -12,6 +12,8 @@
 #ifndef ASSERT_H
 #define ASSERT_H
 
+#include <stdnoreturn.h>
+
 #define COMPILE_TIME_ASSERT(pred) switch(0){case 0:case (pred):;}
 
 /* All environments should implement warn, which prints a non-optional debug
@@ -20,7 +22,7 @@
  */
 
 void warn (const char *format, ...);
-void __abort(void);
+noreturn void __abort(void);
 
 # define assert(test)                                                   \
     ({                                                                  \

+ 1 - 1
Pal/src/db_exception.c

@@ -88,7 +88,7 @@ void DkExceptionReturn (PAL_PTR event)
 }
 
 /* This does not return */
-void __abort(void) {
+noreturn void __abort(void) {
     _DkProcessExit(-ENOTRECOVERABLE);
 }
 

+ 1 - 1
Pal/src/db_process.c

@@ -61,7 +61,7 @@ DkProcessCreate (PAL_STR uri, PAL_STR * args)
     LEAVE_PAL_CALL_RETURN(handle);
 }
 
-void DkProcessExit (PAL_NUM exitcode)
+noreturn void DkProcessExit (PAL_NUM exitcode)
 {
     ENTER_PAL_CALL(DkProcessExit);
     _DkProcessExit(exitcode);

+ 1 - 1
Pal/src/db_threading.c

@@ -79,7 +79,7 @@ void DkThreadYieldExecution (void)
 
 /* PAL call DkThreadExit: simply exit the current thread
    no matter what */
-__attribute__((noreturn)) void DkThreadExit (void)
+noreturn void DkThreadExit (void)
 {
     ENTER_PAL_CALL(DkThreadExit);
     _DkThreadExit();

+ 1 - 1
Pal/src/host/FreeBSD/db_process.c

@@ -383,7 +383,7 @@ no_data:
     memcpy(&pal_sec, &proc_args->pal_sec, sizeof(struct pal_sec));
 }
 
-void _DkProcessExit (int exitcode)
+noreturn void _DkProcessExit (int exitcode)
 {
     INLINE_SYSCALL(exit, 1, exitcode);
 }

+ 4 - 1
Pal/src/host/Linux-SGX/db_process.c

@@ -323,7 +323,7 @@ int init_child_process (PAL_HANDLE * parent_handle)
 
 void print_alloced_pages (void);
 
-void _DkProcessExit (int exitcode)
+noreturn void _DkProcessExit (int exitcode)
 {
 #if PRINT_ENCLAVE_STAT
     print_alloced_pages();
@@ -331,6 +331,9 @@ void _DkProcessExit (int exitcode)
     if (exitcode)
         SGX_DBG(DBG_I, "DkProcessExit: Returning exit code %d\n", exitcode);
     ocall_exit(exitcode);
+    while (true) {
+        /* nothing */;
+    }
 }
 
 int _DkProcessSandboxCreate (const char * manifest, int flags)

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

@@ -720,6 +720,9 @@ int ecall_thread_start (void)
     return sgx_ecall(ECALL_THREAD_START, NULL);
 }
 
-void __abort(void) {
+noreturn void __abort(void) {
     INLINE_SYSCALL(exit_group, 1, -1);
+    while (true) {
+        /* nothing */;
+    }
 }

+ 4 - 1
Pal/src/host/Linux/db_process.c

@@ -420,9 +420,12 @@ no_data:
     memcpy(&pal_sec, &proc_args->pal_sec, sizeof(struct pal_sec));
 }
 
-void _DkProcessExit (int exitcode)
+noreturn void _DkProcessExit (int exitcode)
 {
     INLINE_SYSCALL(exit_group, 1, exitcode);
+    while (true) {
+        /* nothing */;
+    }
 }
 
 int ioctl_set_graphene (struct config_store * config, int ndefault,

+ 1 - 1
Pal/src/host/Skeleton/db_process.c

@@ -41,7 +41,7 @@ int _DkProcessCreate (PAL_HANDLE * handle, const char * uri,
     return -PAL_ERROR_NOTIMPLEMENTED;
 }
 
-void _DkProcessExit (int exitcode)
+noreturn void _DkProcessExit (int exitcode)
 {
     /* need to be implemented */
 }

+ 3 - 2
Pal/src/pal.h

@@ -29,6 +29,7 @@
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
+#include <stdnoreturn.h>
 
 typedef uint64_t      PAL_NUM;
 typedef const char *  PAL_STR;
@@ -245,7 +246,7 @@ DkVirtualMemoryProtect (PAL_PTR addr, PAL_NUM size, PAL_FLG prot);
 PAL_HANDLE
 DkProcessCreate (PAL_STR uri, PAL_STR * args);
 
-void
+noreturn void
 DkProcessExit (PAL_NUM exitCode);
 
 #define PAL_SANDBOX_PIPE         0x1
@@ -398,7 +399,7 @@ DkThreadDelayExecution (PAL_NUM duration);
 void
 DkThreadYieldExecution (void);
 
-__attribute__((noreturn)) void
+noreturn void
 DkThreadExit (void);
 
 PAL_BOL

+ 1 - 1
Pal/src/pal_internal.h

@@ -305,7 +305,7 @@ void _DkThreadYieldExecution (void);
 int _DkThreadResume (PAL_HANDLE threadHandle);
 int _DkProcessCreate (PAL_HANDLE * handle, const char * uri,
                       const char ** args);
-void _DkProcessExit (int exitCode);
+noreturn void _DkProcessExit (int exitCode);
 int _DkProcessSandboxCreate (const char * manifest, int flags);
 
 /* DkMutex calls */

+ 4 - 1
Pal/src/security/Linux/main.c

@@ -588,8 +588,11 @@ exit:
 }
 
 /* This does not return */
-void __abort(void) {
+noreturn void __abort(void) {
     INLINE_SYSCALL(exit_group, 1, -1);
+    while (true) {
+        /* nothing */;
+    }
 }
 
 void warn (const char *format, ...)