refactor: break signal handlers into inline funcs

main
Sean McBride 4 years ago
parent 2d1678e091
commit 3cec497a9b

@ -45,26 +45,14 @@ extern pthread_t runtime_worker_threads[];
static inline void software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void *user_context_raw);
/**
* The handler function for Software Interrupts (signals)
* SIGALRM is executed periodically by an interval timer, causing preemption of the current sandbox
* SIGUSR1 restores a preempted sandbox
* @param signal_type
* SIGALRM is the preemption signal that occurs every quantum of execution
* @param signal_info data structure containing signal info
* @param user_context_raw void* to a user_context struct
* @param user_context userland context
* @param current_sandbox the sanbox active on the worker thread
*/
static inline void
software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void *user_context_raw)
sigalrm_handler(siginfo_t *signal_info, ucontext_t *user_context, struct sandbox *current_sandbox)
{
#ifdef PREEMPT_DISABLE
assert(0);
#else
ucontext_t * user_context = (ucontext_t *)user_context_raw;
struct sandbox *current_sandbox = current_sandbox_get();
switch (signal_type) {
case SIGALRM: {
/* SIGALRM is the preemption signal that occurs every quantum of execution */
/*
* A POSIX signal is delivered to only one thread.
* We need to ensure this thread broadcasts to all other threads
@ -111,9 +99,16 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void
return;
}
case SIGUSR1: {
/* SIGUSR1 restores a preempted sandbox using mcontext. */
/**
* SIGUSR1 restores a preempted sandbox using mcontext
* @param signal_info data structure containing signal info
* @param user_context userland context
* @param current_sandbox the sanbox active on the worker thread
*/
static inline void
sigusr1_handler(siginfo_t *signal_info, ucontext_t *user_context, struct sandbox *current_sandbox)
{
/* Assumption: Caller disables interrupt before triggering SIGUSR1 */
assert(!software_interrupt_is_enabled());
@ -132,6 +127,31 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void
return;
}
/**
* The handler function for Software Interrupts (signals)
* SIGALRM is executed periodically by an interval timer, causing preemption of the current sandbox
* SIGUSR1 restores a preempted sandbox
* @param signal_type
* @param signal_info data structure containing signal info
* @param user_context_raw void* to a user_context struct
*/
static inline void
software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void *user_context_raw)
{
#ifdef PREEMPT_DISABLE
panic("Unexpectedly invoked signal handlers when PREEMPT_DISABLE set\n");
#else
ucontext_t * user_context = (ucontext_t *)user_context_raw;
struct sandbox *current_sandbox = current_sandbox_get();
switch (signal_type) {
case SIGALRM: {
return sigalrm_handler(signal_info, user_context, current_sandbox);
}
case SIGUSR1: {
return sigusr1_handler(signal_info, user_context, current_sandbox);
}
default:
if (signal_info->si_code == SI_TKILL) {
panic("Unexpectedly received signal %d from a thread kill, but we have no handler\n",

Loading…
Cancel
Save