From a2319f2a68286a22b8095bda60383e26bf8ee206 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Fri, 10 Jul 2020 13:40:15 -0400 Subject: [PATCH] chore: refactor out arch_context_t --- runtime/include/arch/aarch64/context.h | 12 +++++------- runtime/include/arch/x86_64/context.h | 12 +++++------- runtime/include/sandbox.h | 4 ++-- runtime/src/worker_thread.c | 10 +++++----- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/runtime/include/arch/aarch64/context.h b/runtime/include/arch/aarch64/context.h index 365b1dd..ac0a2ba 100644 --- a/runtime/include/arch/aarch64/context.h +++ b/runtime/include/arch/aarch64/context.h @@ -18,14 +18,12 @@ struct arch_context { mcontext_t mctx; }; -typedef struct arch_context arch_context_t; - extern void __attribute__((noreturn)) worker_thread_sandbox_switch_preempt(void); -extern __thread arch_context_t worker_thread_base_context; +extern __thread struct arch_context worker_thread_base_context; /* Initialized a context, zeroing out registers and setting the Instruction and Stack pointers */ static inline void -arch_context_init(arch_context_t *actx, reg_t ip, reg_t sp) +arch_context_init(struct arch_context *actx, reg_t ip, reg_t sp) { memset(&actx->mctx, 0, sizeof(mcontext_t)); memset((void *)actx->regs, 0, sizeof(reg_t) * ARCH_NREGS); @@ -35,7 +33,7 @@ arch_context_init(arch_context_t *actx, reg_t ip, reg_t sp) } static int -arch_mcontext_restore(mcontext_t *mc, arch_context_t *ctx) +arch_mcontext_restore(mcontext_t *mc, struct arch_context *ctx) { assert(ctx != &worker_thread_base_context); @@ -58,7 +56,7 @@ arch_mcontext_restore(mcontext_t *mc, arch_context_t *ctx) } static void -arch_mcontext_save(arch_context_t *ctx, mcontext_t *mc) +arch_mcontext_save(struct arch_context *ctx, mcontext_t *mc) { assert(ctx != &worker_thread_base_context); @@ -68,7 +66,7 @@ arch_mcontext_save(arch_context_t *ctx, mcontext_t *mc) static inline int -arch_context_switch(arch_context_t *ca, arch_context_t *na) +arch_context_switch(struct arch_context *ca, struct arch_context *na) { if (!ca) { assert(na); diff --git a/runtime/include/arch/x86_64/context.h b/runtime/include/arch/x86_64/context.h index 01fe1a8..9f160f1 100644 --- a/runtime/include/arch/x86_64/context.h +++ b/runtime/include/arch/x86_64/context.h @@ -31,12 +31,10 @@ struct arch_context { mcontext_t mctx; }; -typedef struct arch_context arch_context_t; - extern void __attribute__((noreturn)) worker_thread_sandbox_switch_preempt(void); -extern __thread arch_context_t worker_thread_base_context; +extern __thread struct arch_context worker_thread_base_context; -static void __attribute__((noinline)) arch_context_init(arch_context_t *actx, reg_t ip, reg_t sp) +static void __attribute__((noinline)) arch_context_init(struct arch_context *actx, reg_t ip, reg_t sp) { memset(&actx->mctx, 0, sizeof(mcontext_t)); memset((void *)actx->regs, 0, sizeof(reg_t) * UREG_COUNT); @@ -72,7 +70,7 @@ static void __attribute__((noinline)) arch_context_init(arch_context_t *actx, re * 1 = special processing because thread was last in a user-level context switch state */ static int -arch_mcontext_restore(mcontext_t *mc, arch_context_t *ctx) +arch_mcontext_restore(mcontext_t *mc, struct arch_context *ctx) { assert(ctx != &worker_thread_base_context); assert(!software_interrupt_is_enabled()); @@ -102,7 +100,7 @@ arch_mcontext_restore(mcontext_t *mc, arch_context_t *ctx) * @param mc - source */ static void -arch_mcontext_save(arch_context_t *ctx, mcontext_t *mc) +arch_mcontext_save(struct arch_context *ctx, mcontext_t *mc) { assert(ctx != &worker_thread_base_context); @@ -119,7 +117,7 @@ arch_mcontext_save(arch_context_t *ctx, mcontext_t *mc) * which defaults to resuming execution of main */ static inline int -arch_context_switch(arch_context_t *current, arch_context_t *next) +arch_context_switch(struct arch_context *current, struct arch_context *next) { /* if both current and next are NULL, there is no state change */ assert(current != NULL || next != NULL); diff --git a/runtime/include/sandbox.h b/runtime/include/sandbox.h index 082376b..3c82033 100644 --- a/runtime/include/sandbox.h +++ b/runtime/include/sandbox.h @@ -42,7 +42,7 @@ struct sandbox { void * stack_start; uint32_t stack_size; - arch_context_t ctxt; /* register context for context switch. */ + struct arch_context ctxt; /* register context for context switch. */ uint64_t total_time; uint64_t start_time; @@ -80,7 +80,7 @@ struct sandbox { **************************/ -extern __thread arch_context_t *worker_thread_next_context; +extern __thread struct arch_context *worker_thread_next_context; extern void worker_thread_block_current_sandbox(void); extern void worker_thread_on_sandbox_exit(struct sandbox *sandbox); diff --git a/runtime/src/worker_thread.c b/runtime/src/worker_thread.c index 80c2677..5b54e0c 100644 --- a/runtime/src/worker_thread.c +++ b/runtime/src/worker_thread.c @@ -21,10 +21,10 @@ **************************/ /* context pointer used to store and restore a preempted sandbox. SIGUSR1 */ -__thread arch_context_t *worker_thread_next_context = NULL; +__thread struct arch_context *worker_thread_next_context = NULL; /* context of the runtime thread before running sandboxes or to resume its "main". */ -__thread arch_context_t worker_thread_base_context; +__thread struct arch_context worker_thread_base_context; /* libuv i/o loop handle per sandboxing thread! */ __thread uv_loop_t worker_thread_uvio_handle; @@ -47,12 +47,12 @@ worker_thread_switch_to_sandbox(struct sandbox *next_sandbox) /* Assumption: The caller disables interrupts */ assert(software_interrupt_is_disabled); - arch_context_t *next_register_context = NULL; + struct arch_context *next_register_context = NULL; if (next_sandbox != NULL) next_register_context = &next_sandbox->ctxt; /* Get the old sandbox we're switching from */ - struct sandbox *previous_sandbox = current_sandbox_get(); - arch_context_t *previous_register_context = NULL; + struct sandbox * previous_sandbox = current_sandbox_get(); + struct arch_context *previous_register_context = NULL; if (previous_sandbox != NULL) previous_register_context = &previous_sandbox->ctxt; /* Set the current sandbox to the next */