chore: refactor out arch_context_t

master
Sean McBride 5 years ago
parent 2f164c3430
commit a2319f2a68

@ -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);

@ -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);

@ -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);

@ -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 */

Loading…
Cancel
Save