parlib: Basic implementation of sigaltstack
authorBrian Wheatman <wheatman@google.com>
Fri, 20 Jul 2018 17:38:30 +0000 (13:38 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Tue, 31 Jul 2018 17:48:56 +0000 (13:48 -0400)
Change-Id: Iab287b7a14873fcf77063b4dd98fb98d4c32f75d
Signed-off-by: Brian Wheatman <wheatman@google.com>
[Added 'parlib' to the title]
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
user/parlib/include/parlib/signal.h
user/parlib/signal.c
user/parlib/uthread.c

index 355fdab..e4546ec 100644 (file)
@@ -20,6 +20,7 @@ struct sigstate {
        sigset_t mask;
        sigset_t pending;
        struct sigdata *data;
+       uintptr_t sigalt_stacktop;
 };
 
 /* A set of functions related to handling posix signals on akaros. The
index 4680411..34d4acc 100644 (file)
@@ -187,6 +187,9 @@ static void __prep_sighandler(struct uthread *uthread,
        if (info != NULL)
                uthread->sigstate.data->info = *info;
 
+       if (uthread->sigstate.sigalt_stacktop != 0)
+               stack = uthread->sigstate.sigalt_stacktop;
+
        init_user_ctx(&uthread->sigstate.data->u_ctx, (uintptr_t)entry, stack);
        /* The uthread may or may not be UTHREAD_SAVED.  That depends on whether the
         * uthread was in that state initially.  We're swapping into the location of
@@ -300,6 +303,21 @@ void uthread_prep_signal_from_fault(struct uthread *uthread,
 static int __sigaltstack(__const struct sigaltstack *__restrict __ss,
                          struct sigaltstack *__restrict __oss)
 {
+       if (__ss->ss_flags != 0) {
+               errno = EINVAL;
+               return -1;
+       }
+       if (__oss != NULL) {
+               errno = EINVAL;
+               return -1;
+       }
+       if (__ss->ss_size < MINSIGSTKSZ) {
+               errno = ENOMEM;
+               return -1;
+       }
+       uintptr_t stack_top = (uintptr_t) __ss->ss_sp + __ss->ss_size;
+
+       current_uthread->sigstate.sigalt_stacktop = stack_top;
        return 0;
 }
 
index db71ae0..9f133c4 100644 (file)
@@ -47,6 +47,8 @@ static void uthread_init_thread0(struct uthread *uthread)
        atomic_set(&uthread->join_ctl.state, UTH_JOIN_DETACHED);
        /* Reset the signal state */
        uthread->sigstate.mask = 0;
+       /* sig alt stack pointer */
+       uthread->sigstate.sigalt_stacktop = 0;
        __sigemptyset(&uthread->sigstate.pending);
        uthread->sigstate.data = NULL;
        /* utf/as doesn't represent the state of the uthread (we are running) */
@@ -317,6 +319,7 @@ void uthread_init(struct uthread *new_thread, struct uth_thread_attr *attr)
                new_thread->sigstate.mask = 0;
        __sigemptyset(&new_thread->sigstate.pending);
        new_thread->sigstate.data = NULL;
+       new_thread->sigstate.sigalt_stacktop = 0;
        new_thread->flags = 0;
        new_thread->sysc = NULL;
        /* the utf holds the GP context of the uthread (set by the 2LS earlier).