mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
signal: ucontext and a fix
This commit is contained in:
@@ -162,7 +162,7 @@ typedef struct {
|
||||
} checkargs_t;
|
||||
|
||||
// SHOULD NOT BE CALLED WITH THE SCHEDULER STACK
|
||||
static void userspacecheck(void *_args) {
|
||||
static bool userspacecheck(void *_args) {
|
||||
checkargs_t *args = _args;
|
||||
thread_t *thread = current_thread();
|
||||
|
||||
@@ -171,7 +171,10 @@ static void userspacecheck(void *_args) {
|
||||
sched_threadexit();
|
||||
}
|
||||
|
||||
while (signal_check(thread, args->context, args->syscall, args->syscallret, args->syscallerrno)) ;
|
||||
bool need_context_switch = false;
|
||||
|
||||
while (signal_check(thread, args->context, args->syscall, args->syscallret, args->syscallerrno, &need_context_switch)) ;
|
||||
return need_context_switch;
|
||||
}
|
||||
|
||||
static void checktrampoline(context_t *context, void *_args) {
|
||||
@@ -203,7 +206,10 @@ __attribute__((no_caller_saved_registers)) void sched_userspacecheck(context_t *
|
||||
if (&args < (checkargs_t *)current_cpu()->schedulerstack && &args >= (checkargs_t *)((uintptr_t)current_cpu()->schedulerstack - SCHEDULER_STACK_SIZE)) {
|
||||
arch_context_saveandcall(checktrampoline, current_thread()->kernelstacktop, &args);
|
||||
} else {
|
||||
userspacecheck(&args);
|
||||
if (userspacecheck(&args)) {
|
||||
// need context switch
|
||||
arch_context_switch(context);
|
||||
}
|
||||
}
|
||||
|
||||
current_cpu()->intstatus = intstatus;
|
||||
|
||||
@@ -423,7 +423,7 @@ void signal_signalproc(struct proc_t *proc, int signal) {
|
||||
}
|
||||
|
||||
// returns true if should retry check
|
||||
bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uint64_t syscallret, uint64_t syscallerrno) {
|
||||
bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uint64_t syscallret, uint64_t syscallerrno, bool *need_context_switch) {
|
||||
bool retry = false;
|
||||
proc_t *proc = thread->proc;
|
||||
|
||||
@@ -563,6 +563,7 @@ bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uin
|
||||
}
|
||||
memcpy(&sigframe.context, context, sizeof(context_t));
|
||||
memcpy(&sigframe.extracontext, &thread->extracontext, sizeof(extracontext_t));
|
||||
arch_sigframe_prepare_mcontext(&sigframe);
|
||||
// TODO siginfo
|
||||
|
||||
if (usercopy_touser(stack, &sigframe, sizeof(sigframe_t))) {
|
||||
@@ -591,11 +592,13 @@ bool signal_check(struct thread_t *thread, context_t *context, bool syscall, uin
|
||||
CTX_SP(context) = (uint64_t)stack;
|
||||
CTX_ARG0(context) = signal;
|
||||
CTX_ARG1(context) = 0; // TODO pass siginfo
|
||||
CTX_ARG2(context) = 0; // TODO ucontext
|
||||
CTX_ARG2(context) = (uint64_t)ARCH_SIGFRAME_GET_UCONTEXT_POINTER((sigframe_t*)stack);
|
||||
|
||||
// reset handler if asked for
|
||||
if (action->flags & SA_RESETHAND)
|
||||
memset(action, 0, sizeof(sigaction_t));
|
||||
|
||||
*need_context_switch = true;
|
||||
}
|
||||
|
||||
leave:
|
||||
|
||||
Reference in New Issue
Block a user