On Mon, Oct 16, 2017 at 12:02 AM, barret rhoden <[email protected]> wrote: > Hi - > > On 2017-10-13 at 11:30 'Dmitry Vyukov' via Akaros wrote: >> I need to skip faulting operations in a C program. On linux I do the >> following: > >> [snip] > >> Is it possible to return from handler and alter thread's context? Just >> altering RIP would do, because I can set RIP a another function which >> will longjmp. > > This is definitely doable on Akaros, though not with a long jump from a > signal handler. Our POSIX support isn't 100%, esp for signal handling. > > The trick is to cast the ucontext to struct user_context. Then you can > modify rip in place. The structs are in kern/include/ros/trapframe.h > and kern/arch/x86/ros/trapframe64.h. > > > Example: > > #include <stdlib.h> > #include <parlib/stdio.h> > #include <parlib/parlib.h> > #include <unistd.h> > #include <signal.h> > #include <pthread.h> > > static void sig_action(int signr, siginfo_t *info, void *__ctx) > { > struct user_context *u_ctx = __ctx; > > printf("Got posix signal %d, info %p, u_ctx %p\n", signr, info, > u_ctx); > assert(u_ctx->type = ROS_HW_CTX); > u_ctx->tf.hw_tf.tf_rip += 8; > } > > struct sigaction sigact = {.sa_sigaction = sig_action, 0}; > > int main(int argc, char **argv) > { > pthread_self(); /* force usage of pthread 2LS, which supports signals > */ > sigaction(SIGSEGV, &sigact, 0); > printf("Hello world from program %s!!\n", argv[0]); > /* 8 byte instruction */ > asm volatile("movq 0x0, %%rax" : : : "eax"); > printf("continued!!\n"); > return 0; > }
Thanks. This seems to work for me. >> Is there any way to turn "Uthread sighandler faulted" into a >> non-error? I don't see why it should terminate my program. Faulting in >> a signal handler should be OK. > > Probably, though it'd make our signal handling more difficult. Right > now, every uthread can run a signal handler as part of an alternate > context. But it doesn't nest yet. (user/parlib/signal.c L 179 or so). > This is probably why you were able to longjmp out of the signal handler > just once. The first time, you got out, but the uthread thought it was > still in the signal handling mode. If you need this to work, I can try > and sort it out. If I have a way to alter RIP, then I don't need this. -- You received this message because you are subscribed to the Google Groups "Akaros" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
