refactor: decapitalize enums

master
Sean McBride 5 years ago
parent ef648ab47c
commit 7919dff0ba

@ -16,11 +16,11 @@ static inline void
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);
memset((void *)actx->regs, 0, sizeof(reg_t) * ureg_count);
actx->regs[UREG_RSP] = sp;
actx->regs[UREG_RIP] = ip;
actx->variant = ARCH_CONTEXT_FAST;
actx->regs[ureg_rsp] = sp;
actx->regs[ureg_rip] = ip;
actx->variant = arch_context_fast;
}
/**

@ -19,28 +19,28 @@
typedef uint64_t reg_t;
/* Userspace Registers. */
enum UREGS
/* Register context saved and restored on user-level, direct context switches. */
typedef enum
{
UREG_RSP = 0,
UREG_RIP = 1,
UREG_COUNT
};
ureg_rsp = 0,
ureg_rip = 1,
ureg_count
} ureg_t;
/* The enum is compared directly in assembly, so maintain integral values! */
enum ARCH_CONTEXT
typedef enum
{
ARCH_CONTEXT_UNUSED = 0,
ARCH_CONTEXT_FAST = 1,
ARCH_CONTEXT_SLOW = 2,
ARCH_CONTEXT_RUNNING = 3
};
arch_context_unused = 0,
arch_context_fast = 1,
arch_context_slow = 2,
arch_context_running = 3
} arch_context_t;
struct arch_context {
enum ARCH_CONTEXT variant;
reg_t regs[UREG_COUNT];
mcontext_t mctx;
arch_context_t variant;
reg_t regs[ureg_count];
mcontext_t mctx;
};
/*

@ -44,7 +44,7 @@ arch_mcontext_restore(mcontext_t *active_context, struct arch_context *sandbox_c
assert(sandbox_context != NULL);
/* Validate that the sandbox_context is well formed */
assert(sandbox_context->variant == ARCH_CONTEXT_SLOW);
assert(sandbox_context->variant == arch_context_slow);
assert(sandbox_context->mctx.gregs[REG_RSP] != 0);
assert(sandbox_context->mctx.gregs[REG_RIP] != 0);
@ -67,16 +67,16 @@ arch_context_restore(mcontext_t *active_context, struct arch_context *sandbox_co
{
assert(active_context != NULL);
assert(sandbox_context != NULL);
assert(sandbox_context->variant == ARCH_CONTEXT_FAST);
assert(sandbox_context->variant == arch_context_fast);
assert(sandbox_context != &worker_thread_base_context);
/* TODO: Phani explained that we need to be able to restore a sandbox with an IP of 0. Why is this? */
assert(sandbox_context->regs[UREG_RSP]);
assert(sandbox_context->regs[ureg_rsp]);
active_context->gregs[REG_RSP] = sandbox_context->regs[UREG_RSP];
active_context->gregs[REG_RIP] = sandbox_context->regs[UREG_RIP] + ARCH_SIG_JMP_OFF;
sandbox_context->regs[UREG_RSP] = 0;
sandbox_context->regs[UREG_RIP] = 0;
active_context->gregs[REG_RSP] = sandbox_context->regs[ureg_rsp];
active_context->gregs[REG_RIP] = sandbox_context->regs[ureg_rip] + ARCH_SIG_JMP_OFF;
sandbox_context->regs[ureg_rsp] = 0;
sandbox_context->regs[ureg_rip] = 0;
}
/**
@ -101,9 +101,9 @@ arch_mcontext_save(struct arch_context *sandbox_context, const mcontext_t *activ
assert(active_context->gregs[REG_RSP] != 0);
/* Set variant to slow */
sandbox_context->variant = ARCH_CONTEXT_SLOW;
sandbox_context->regs[UREG_RSP] = 0;
sandbox_context->regs[UREG_RIP] = 0;
sandbox_context->variant = arch_context_slow;
sandbox_context->regs[ureg_rsp] = 0;
sandbox_context->regs[ureg_rip] = 0;
/* Copy mcontext */
memcpy(&sandbox_context->mctx, active_context, sizeof(mcontext_t));

@ -15,7 +15,7 @@
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);
memset((void *)actx->regs, 0, sizeof(reg_t) * ureg_count);
if (sp) {
/*
@ -36,9 +36,9 @@ static void __attribute__((noinline)) arch_context_init(struct arch_context *act
: "memory", "cc", "rbx");
}
actx->regs[UREG_RSP] = sp;
actx->regs[UREG_RIP] = ip;
actx->variant = ARCH_CONTEXT_FAST;
actx->regs[ureg_rsp] = sp;
actx->regs[ureg_rip] = ip;
actx->variant = arch_context_fast;
}
@ -56,7 +56,7 @@ arch_context_switch(struct arch_context *current, struct arch_context *next)
/* Assumption: Software Interrupts are disabled by caller */
assert(software_interrupt_is_disabled);
if (next->variant == ARCH_CONTEXT_FAST && (next->regs[UREG_RIP] == 0 || next->regs[UREG_RSP] == 0)) {
if (next->variant == arch_context_fast && (next->regs[ureg_rip] == 0 || next->regs[ureg_rsp] == 0)) {
debuglog("Next Context was Fast Variant, but data was invalid.");
assert(0);
}
@ -72,7 +72,7 @@ arch_context_switch(struct arch_context *current, struct arch_context *next)
if (next == NULL) next = &worker_thread_base_context;
/* Assumption: The context we are switching to should have saved a context in some form */
assert(next->variant == ARCH_CONTEXT_FAST || next->variant != ARCH_CONTEXT_UNUSED);
assert(next->variant == arch_context_fast || next->variant != arch_context_unused);
reg_t *current_registers = current->regs, *next_registers = next->regs;
assert(current_registers && next_registers);
@ -87,13 +87,13 @@ arch_context_switch(struct arch_context *current, struct arch_context *next)
*/
"movq $2f, 8(%%rax)\n\t" /* Write the address of label 2 to current_registers[1] (instruction_pointer). */
"movq %%rsp, (%%rax)\n\t" /* current_registers[0] (stack_pointer) = stack_pointer */
"movq $1, (%%rcx)\n\t" /* current->variant = ARCH_CONTEXT_FAST; */
"movq $1, (%%rcx)\n\t" /* current->variant = arch_context_fast; */
/*
* Check if the variant of the context we're trying to switch to is SLOW (mcontext-based)
* If it is, jump to label 1 to restore the preempted sandbox
*/
"cmpq $2, (%%rdx)\n\t" /* if (next->variant == ARCH_CONTEXT_SLOW); */
"cmpq $2, (%%rdx)\n\t" /* if (next->variant == arch_context_slow); */
"je 1f\n\t" /* goto 1; restore the existing sandbox using mcontext */
/*
@ -105,7 +105,7 @@ arch_context_switch(struct arch_context *current, struct arch_context *next)
/*
* Slow Path
* If the variant is ARCH_CONTEXT_SLOW, that means the sandbox was preempted and we need to
* If the variant is arch_context_slow, that means the sandbox was preempted and we need to
* fallback to a full mcontext-based context switch. We do this by invoking
* arch_context_mcontext_restore, which fires a SIGUSR1 signal. The SIGUSR1 signal handler
* executes the mcontext-based context switch.
@ -119,12 +119,12 @@ arch_context_switch(struct arch_context *current, struct arch_context *next)
* The sandbox either resumes at label 2 or 3 depending on if an offset of 8 is used.
*/
"2:\n\t"
"movq $3, (%%rdx)\n\t" /* next->variant = ARCH_CONTEXT_FAST; */
"movq $3, (%%rdx)\n\t" /* next->variant = arch_context_fast; */
".align 8\n\t"
/* This label is used in conjunction with a static offset */
"3:\n\t"
/* TODO: Should we set next->variant = ARCH_CONTEXT_SLOW here?;*/
/* TODO: Should we set next->variant = arch_context_slow here?;*/
"popq %%rbp\n\t" /* base_pointer = stack[--stack_len]; Base Pointer is restored */
:
: "a"(current_registers), "b"(next_registers), "c"(&current->variant), "d"(&next->variant)

@ -173,7 +173,7 @@ local_runqueue_minheap_preempt(ucontext_t *user_context)
* If last in a user-level context switch state,
* do not enable software interrupts.
*/
if (next_sandbox->ctxt.variant == ARCH_CONTEXT_SLOW) {
if (next_sandbox->ctxt.variant == arch_context_slow) {
arch_mcontext_restore(&user_context->uc_mcontext, &next_sandbox->ctxt);
} else {
arch_context_restore(&user_context->uc_mcontext, &next_sandbox->ctxt);

@ -124,7 +124,7 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void
assert(current_sandbox);
/* Extra checks to verify that preemption properly set context state */
assert(current_sandbox->ctxt.variant == ARCH_CONTEXT_SLOW);
assert(current_sandbox->ctxt.variant == arch_context_slow);
software_interrupt_SIGUSR_count++;
debuglog("usr1:%d\n", software_interrupt_SIGUSR_count);

Loading…
Cancel
Save