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); 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 the preemption signal that occurs every quantum of execution
* 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 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 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. * A POSIX signal is delivered to only one thread.
* We need to ensure this thread broadcasts to all other threads * We need to ensure this thread broadcasts to all other threads
@ -110,10 +98,17 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void
local_runqueue_preempt(user_context); local_runqueue_preempt(user_context);
return; 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 */ /* Assumption: Caller disables interrupt before triggering SIGUSR1 */
assert(!software_interrupt_is_enabled()); assert(!software_interrupt_is_enabled());
@ -131,6 +126,31 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void
software_interrupt_enable(); software_interrupt_enable();
return; 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: default:
if (signal_info->si_code == SI_TKILL) { if (signal_info->si_code == SI_TKILL) {

Loading…
Cancel
Save