Browse Source

[Pal/{Linux,Linux-SGX}] Cleanup after introducing signal-stack and XSAVE area

Now Linux and Linux-SGX PALs have dedicated signal stacks and correctly
save-restore XSAVE area. Thus, several old tricks can be removed:
- PAL_EVENT is removed (it was used as an opaque object propagated to
  LibOS and back to PAL on DkExceptionReturn, but now this function
  is a no-op and doesn't need PAL_EVENT).
- `-fno-ommit-framepoint` is dropped from Linux-SGX build flags (new
  implementation of stack switching does not require frame pointer).
Isaku Yamahata 4 years ago
parent
commit
a7565cf5ba

+ 0 - 1
Pal/src/host/Linux-SGX/Makefile.am

@@ -2,7 +2,6 @@
 HOST_DIR = host/$(PAL_HOST)
 
 CFLAGS	= -Wall -fPIC -O2 -maes -std=c11 -U_FORTIFY_SOURCE \
-	  -fno-omit-frame-pointer \
 	  -fno-stack-protector -fno-builtin -Wtrampolines
 
 EXTRAFLAGS = -Wextra $(call cc-option,-Wnull-dereference)

+ 4 - 38
Pal/src/host/Linux-SGX/db_exception.c

@@ -36,28 +36,12 @@
 #include <linux/signal.h>
 #include <ucontext.h>
 
-typedef struct exception_event {
-    PAL_IDX             event_num;
-    PAL_CONTEXT *       context;
-} PAL_EVENT;
-
-static void _DkGenericEventTrigger (PAL_IDX event_num, PAL_EVENT_HANDLER upcall,
-                                    PAL_NUM arg, PAL_CONTEXT* context)
-{
-    struct exception_event event;
-
-    event.event_num = event_num;
-    event.context = context;
-
-    (*upcall) ((PAL_PTR) &event, arg, context);
-}
-
 static bool
 _DkGenericSignalHandle(int event_num, PAL_NUM arg, PAL_CONTEXT* context) {
     PAL_EVENT_HANDLER upcall = _DkGetExceptionHandler(event_num);
 
     if (upcall) {
-        _DkGenericEventTrigger(event_num, upcall, arg, context);
+        (*upcall)(NULL, arg, context);
         return true;
     }
 
@@ -291,30 +275,12 @@ void _DkExceptionHandler(
     restore_pal_context(uc, &ctx);
 }
 
-void _DkRaiseFailure (int error)
-{
-    PAL_EVENT_HANDLER upcall = _DkGetExceptionHandler(PAL_EVENT_FAILURE);
-
-    if (!upcall)
-        return;
-
-    PAL_EVENT event;
-    event.event_num = PAL_EVENT_FAILURE;
-    event.context   = NULL;
-
-    (*upcall) ((PAL_PTR) &event, error, NULL);
+void _DkRaiseFailure(int error) {
+    _DkGenericSignalHandle(PAL_EVENT_FAILURE, error, /*context=*/NULL);
 }
 
 void _DkExceptionReturn(void* event) {
-    PAL_EVENT* e = event;
-    PAL_CONTEXT* ctx = e->context;
-
-    if (!ctx) {
-        return;
-    }
-
-    sgx_cpu_context_t uc;
-    restore_pal_context(&uc, ctx);
+    __UNUSED(event);
 }
 
 noreturn void _DkHandleExternalEvent(

+ 19 - 38
Pal/src/host/Linux/db_exception.c

@@ -164,12 +164,6 @@ int block_async_signals (bool block)
     return block_signals(block, async_signals, nasync_signals);
 }
 
-typedef struct {
-    PAL_IDX         event_num;
-    PAL_CONTEXT     context;
-    ucontext_t *    uc;
-} PAL_EVENT;
-
 static int get_event_num (int signum)
 {
     switch(signum) {
@@ -183,20 +177,20 @@ static int get_event_num (int signum)
     }
 }
 
-static void _DkGenericEventTrigger (PAL_IDX event_num, PAL_EVENT_HANDLER upcall,
-                                    PAL_NUM arg, ucontext_t * uc)
-{
-    PAL_EVENT event;
-    event.event_num = event_num;
-
-    if (uc) {
-        memcpy(&event.context, uc->uc_mcontext.gregs, sizeof(PAL_CONTEXT));
-        event.context.fpregs = (PAL_XREGS_STATE*)uc->uc_mcontext.fpregs;
+static void _DkGenericEventTrigger(PAL_EVENT_HANDLER upcall,
+                                   PAL_NUM arg, ucontext_t* uc) {
+    if (!uc) {
+        (*upcall)(NULL, arg, NULL);
+        return;
     }
 
-    event.uc = uc;
-
-    (*upcall) ((PAL_PTR) &event, arg, &event.context);
+    PAL_CONTEXT context;
+    memcpy(&context, uc->uc_mcontext.gregs, sizeof(context));
+    context.fpregs = (PAL_XREGS_STATE*)uc->uc_mcontext.fpregs;
+    (*upcall)(NULL, arg, &context);
+    /* copy the context back to ucontext */
+    memcpy(uc->uc_mcontext.gregs, &context, sizeof(context));
+    uc->uc_mcontext.fpregs = (struct _libc_fpstate*)context.fpregs;
 }
 
 static bool _DkGenericSignalHandle (int event_num, siginfo_t * info,
@@ -212,7 +206,7 @@ static bool _DkGenericSignalHandle (int event_num, siginfo_t * info,
             event_num == PAL_EVENT_ILLEGAL)
             arg = (PAL_NUM) (info ? info->si_addr : 0);
 
-        _DkGenericEventTrigger(event_num, upcall, arg, uc);
+        _DkGenericEventTrigger(upcall, arg, uc);
         return true;
     }
 
@@ -336,18 +330,11 @@ void __check_pending_event (void)
     }
 }
 
-void _DkRaiseFailure (int error)
-{
+void _DkRaiseFailure(int error) {
     PAL_EVENT_HANDLER upcall = _DkGetExceptionHandler(PAL_EVENT_FAILURE);
-
-    if (!upcall)
-        return;
-
-    PAL_EVENT event;
-    event.event_num = PAL_EVENT_FAILURE;
-    event.uc = NULL;
-
-    (*upcall) ((PAL_PTR) &event, error, NULL);
+    if (upcall) {
+        _DkGenericEventTrigger(upcall, error, NULL);
+    }
 }
 
 struct signal_ops {
@@ -413,12 +400,6 @@ err:
     INIT_FAIL(-ret, "cannot setup signal handlers");
 }
 
-void _DkExceptionReturn (void * event)
-{
-    PAL_EVENT * e = event;
-    if (e->uc) {
-        /* copy the context back to ucontext */
-        memcpy(e->uc->uc_mcontext.gregs, &e->context, sizeof(PAL_CONTEXT));
-        e->uc->uc_mcontext.fpregs = (struct _libc_fpstate*)e->context.fpregs;
-    }
+void _DkExceptionReturn(void* event) {
+    __UNUSED(event);
 }