From 81e3a88a1fbc35cd537d0cdb6ccbe57d4c2c53f9 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Thu, 23 Jul 2020 12:31:40 -0400 Subject: [PATCH] chore: fix case on enums --- runtime/include/arch/aarch64/context.h | 46 +++++++++++++------------- runtime/include/arch/common.h | 24 +++++++------- runtime/include/arch/context.h | 10 +++--- runtime/include/arch/x86_64/context.h | 38 ++++++++++----------- runtime/src/software_interrupt.c | 2 +- 5 files changed, 60 insertions(+), 60 deletions(-) diff --git a/runtime/include/arch/aarch64/context.h b/runtime/include/arch/aarch64/context.h index b665962..e83fec6 100644 --- a/runtime/include/arch/aarch64/context.h +++ b/runtime/include/arch/aarch64/context.h @@ -18,13 +18,13 @@ arch_context_init(struct arch_context *actx, reg_t ip, reg_t sp) assert(actx != NULL); if (ip == 0 && sp == 0) { - actx->variant = arch_context_variant_unused; + actx->variant = ARCH_CONTEXT_VARIANT_UNUSED; } else { - actx->variant = arch_context_variant_fast; + actx->variant = ARCH_CONTEXT_VARIANT_FAST; } - actx->regs[ureg_rsp] = sp; - actx->regs[ureg_rip] = ip; + actx->regs[UREG_SP] = sp; + actx->regs[UREG_IP] = ip; } /** @@ -43,15 +43,15 @@ arch_context_restore(mcontext_t *active_context, struct arch_context *sandbox_co /* Assumption: Base Context is only ever used by arch_context_switch */ assert(sandbox_context != &worker_thread_base_context); - assert(sandbox_context->regs[ureg_rsp]); - assert(sandbox_context->regs[ureg_rip]); + assert(sandbox_context->regs[UREG_SP]); + assert(sandbox_context->regs[UREG_IP]); /* Transitioning from Fast -> Running */ - assert(sandbox_context->variant == arch_context_variant_fast); - sandbox_context->variant = arch_context_variant_running; + assert(sandbox_context->variant == ARCH_CONTEXT_VARIANT_FAST); + sandbox_context->variant = ARCH_CONTEXT_VARIANT_RUNNING; - active_context->sp = sandbox_context->regs[ureg_rsp]; - active_context->pc = sandbox_context->regs[ureg_rip] + ARCH_SIG_JMP_OFF; + active_context->sp = sandbox_context->regs[UREG_SP]; + active_context->pc = sandbox_context->regs[UREG_IP] + ARCH_SIG_JMP_OFF; } /** @@ -79,15 +79,15 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) if (b == NULL) b = &worker_thread_base_context; /* A Transition {Unused, Running} -> Fast */ - assert(a->variant == arch_context_variant_unused || a->variant == arch_context_variant_running); + assert(a->variant == ARCH_CONTEXT_VARIANT_UNUSED || a->variant == ARCH_CONTEXT_VARIANT_RUNNING); /* B Transition {Fast, Slow} -> Running */ - assert(b->variant == arch_context_variant_fast || b->variant == arch_context_variant_slow); + assert(b->variant == ARCH_CONTEXT_VARIANT_FAST || b->variant == ARCH_CONTEXT_VARIANT_SLOW); /* Assumption: Fastpath state is well formed */ - if (b->variant == arch_context_variant_fast) { - assert(b->regs[ureg_rip] != 0); - assert(b->regs[ureg_rsp] != 0); + if (b->variant == ARCH_CONTEXT_VARIANT_FAST) { + assert(b->regs[UREG_IP] != 0); + assert(b->regs[UREG_SP] != 0); } reg_t *a_registers = a->regs, *b_registers = b->regs; @@ -97,12 +97,12 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) "adr x1, reset%=\n\t" "str x1, [%[a], 8]\n\t" "str x0, [%[a]]\n\t" - "mov x0, #1\n\t" - "str x0, [%[av]]\n\t" + "mov x0, #1\n\t" + "str x0, [%[av]]\n\t" "ldr x1, [%[bv]]\n\t" - "sub x1, x1, #2\n\t" + "sub x1, x1, #2\n\t" "cbz x1, slow%=\n\t" - "ldr x0, [%[b]]\n\t" + "ldr x0, [%[b]]\n\t" "ldr x1, [%[b], 8]\n\t" "mov sp, x0\n\t" "br x1\n\t" @@ -115,11 +115,11 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) ".align 8\n\t" "exit%=:\n\t" : - : [ a ] "r"(a_registers), [ b ] "r"(b_registers), [ av ] "r"(&a->variant), [ bv ] "r"(&b->variant), - [ slowpath ] "r"(&arch_context_restore_preempted) + : [ a ] "r"(a_registers), [ b ] "r"(b_registers), [ av ] "r"(&a->variant), [ bv ] "r"(&b->variant), + [ slowpath ] "r"(&arch_context_restore_preempted) : "memory", "cc", "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9", "x10", "x11", "x12", - "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", "x24", - "d8", "d9", "d10", "d11", "d12", "d13", "d14", "d15"); + "x13", "x14", "x15", "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23", "x24", "d8", "d9", + "d10", "d11", "d12", "d13", "d14", "d15"); return 0; } diff --git a/runtime/include/arch/common.h b/runtime/include/arch/common.h index 3c349d0..507c22f 100644 --- a/runtime/include/arch/common.h +++ b/runtime/include/arch/common.h @@ -22,31 +22,31 @@ typedef uint64_t reg_t; /* Register context saved and restored on user-level, direct context switches. */ typedef enum { - ureg_rsp = 0, - ureg_rip = 1, - ureg_count + UREG_SP = 0, + UREG_IP = 1, + UREG_COUNT } ureg_t; /* The enum is compared directly in assembly, so maintain integral values! */ typedef enum { - arch_context_variant_unused = 0, /* Has not have saved a context */ - arch_context_variant_fast = 1, /* Saved a fastpath context */ - arch_context_variant_slow = 2, /* Saved a slowpath context */ - arch_context_variant_running = 3 /* Context is executing and content is out of date */ + ARCH_CONTEXT_VARIANT_UNUSED = 0, /* Has not have saved a context */ + ARCH_CONTEXT_VARIANT_FAST = 1, /* Saved a fastpath context */ + ARCH_CONTEXT_VARIANT_SLOW = 2, /* Saved a slowpath context */ + ARCH_CONTEXT_VARIANT_RUNNING = 3 /* Context is executing and content is out of date */ } arch_context_variant_t; static inline char * arch_context_variant_print(arch_context_variant_t context) { switch (context) { - case arch_context_variant_unused: + case ARCH_CONTEXT_VARIANT_UNUSED: return "Unused"; - case arch_context_variant_fast: + case ARCH_CONTEXT_VARIANT_FAST: return "Fast"; - case arch_context_variant_slow: + case ARCH_CONTEXT_VARIANT_SLOW: return "Slow"; - case arch_context_variant_running: + case ARCH_CONTEXT_VARIANT_RUNNING: return "Running"; default: panic("Encountered unexpected arch_context variant\n"); @@ -56,7 +56,7 @@ arch_context_variant_print(arch_context_variant_t context) struct arch_context { arch_context_variant_t variant; - reg_t regs[ureg_count]; + reg_t regs[UREG_COUNT]; mcontext_t mctx; }; diff --git a/runtime/include/arch/context.h b/runtime/include/arch/context.h index 7a4dbf5..67e7b0f 100644 --- a/runtime/include/arch/context.h +++ b/runtime/include/arch/context.h @@ -48,8 +48,8 @@ arch_mcontext_restore(mcontext_t *active_context, struct arch_context *sandbox_c assert(sandbox_context != &worker_thread_base_context); /* Transitioning from Slow -> Running */ - assert(sandbox_context->variant == arch_context_variant_slow); - sandbox_context->variant = arch_context_variant_running; + assert(sandbox_context->variant == ARCH_CONTEXT_VARIANT_SLOW); + sandbox_context->variant = ARCH_CONTEXT_VARIANT_RUNNING; /* Restore mcontext */ memcpy(active_context, &sandbox_context->mctx, sizeof(mcontext_t)); @@ -74,9 +74,9 @@ arch_mcontext_save(struct arch_context *sandbox_context, const mcontext_t *activ assert(sandbox_context != &worker_thread_base_context); /* Transitioning from {Unused, Running} -> Slow */ - assert(sandbox_context->variant == arch_context_variant_unused - || sandbox_context->variant == arch_context_variant_running); - sandbox_context->variant = arch_context_variant_slow; + assert(sandbox_context->variant == ARCH_CONTEXT_VARIANT_UNUSED + || sandbox_context->variant == ARCH_CONTEXT_VARIANT_RUNNING); + sandbox_context->variant = ARCH_CONTEXT_VARIANT_SLOW; /* Copy mcontext */ memcpy(&sandbox_context->mctx, active_context, sizeof(mcontext_t)); diff --git a/runtime/include/arch/x86_64/context.h b/runtime/include/arch/x86_64/context.h index 2b85121..0b5e7f8 100644 --- a/runtime/include/arch/x86_64/context.h +++ b/runtime/include/arch/x86_64/context.h @@ -16,9 +16,9 @@ static void __attribute__((noinline)) arch_context_init(struct arch_context *act assert(actx != NULL); if (ip == 0 && sp == 0) { - actx->variant = arch_context_variant_unused; + actx->variant = ARCH_CONTEXT_VARIANT_UNUSED; } else { - actx->variant = arch_context_variant_fast; + actx->variant = ARCH_CONTEXT_VARIANT_FAST; } if (sp) { @@ -40,8 +40,8 @@ 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->regs[UREG_SP] = sp; + actx->regs[UREG_IP] = ip; } /** @@ -60,15 +60,15 @@ arch_context_restore(mcontext_t *active_context, struct arch_context *sandbox_co /* Assumption: Base Context is only ever used by arch_context_switch */ assert(sandbox_context != &worker_thread_base_context); - assert(sandbox_context->regs[ureg_rsp]); - assert(sandbox_context->regs[ureg_rip]); + assert(sandbox_context->regs[UREG_SP]); + assert(sandbox_context->regs[UREG_IP]); /* Transitioning from Fast -> Running */ - assert(sandbox_context->variant == arch_context_variant_fast); - sandbox_context->variant = arch_context_variant_running; + assert(sandbox_context->variant == ARCH_CONTEXT_VARIANT_FAST); + sandbox_context->variant = ARCH_CONTEXT_VARIANT_RUNNING; - active_context->gregs[REG_RSP] = sandbox_context->regs[ureg_rsp]; - active_context->gregs[REG_RIP] = sandbox_context->regs[ureg_rip] + ARCH_SIG_JMP_OFF; + active_context->gregs[REG_RSP] = sandbox_context->regs[UREG_SP]; + active_context->gregs[REG_RIP] = sandbox_context->regs[UREG_IP] + ARCH_SIG_JMP_OFF; } /** @@ -96,15 +96,15 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) if (b == NULL) b = &worker_thread_base_context; /* A Transition {Unused, Running} -> Fast */ - assert(a->variant == arch_context_variant_unused || a->variant == arch_context_variant_running); + assert(a->variant == ARCH_CONTEXT_VARIANT_UNUSED || a->variant == ARCH_CONTEXT_VARIANT_RUNNING); /* B Transition {Fast, Slow} -> Running */ - assert(b->variant == arch_context_variant_fast || b->variant == arch_context_variant_slow); + assert(b->variant == ARCH_CONTEXT_VARIANT_FAST || b->variant == ARCH_CONTEXT_VARIANT_SLOW); /* Assumption: Fastpath state is well formed */ - if (b->variant == arch_context_variant_fast) { - assert(b->regs[ureg_rip] != 0); - assert(b->regs[ureg_rsp] != 0); + if (b->variant == ARCH_CONTEXT_VARIANT_FAST) { + assert(b->regs[UREG_IP] != 0); + assert(b->regs[UREG_SP] != 0); } reg_t *a_registers = a->regs, *b_registers = b->regs; @@ -122,7 +122,7 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) */ "movq $2f, 8(%%rax)\n\t" /* Write the address of label 2 to context a's IP. */ "movq %%rsp, (%%rax)\n\t" /* a_registers[0] (stack_pointer) = stack_pointer */ - "movq $1, (%%rcx)\n\t" /* a->variant = arch_context_variant_fast; */ + "movq $1, (%%rcx)\n\t" /* a->variant = ARCH_CONTEXT_VARIANT_FAST; */ /* * Execute a fastpath or slowpath context switch based on context B's variant @@ -130,7 +130,7 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) * If slow (mcontext-based), jump to label 1 to restore via a signal handler * Otherwise, fall through and execute fast path. */ - "cmpq $2, (%%rdx)\n\t" /* if (b->variant == arch_context_variant_slow); */ + "cmpq $2, (%%rdx)\n\t" /* if (b->variant == ARCH_CONTEXT_VARIANT_SLOW); */ "je 1f\n\t" /* goto 1; restore the existing sandbox using mcontext */ /* @@ -147,7 +147,7 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) /* * Slow Path - * If the variant is arch_context_variant_slow, that means the sandbox was preempted and we need to + * If the variant is ARCH_CONTEXT_VARIANT_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_restore_preempted, which fires a SIGUSR1 signal. The SIGUSR1 signal handler * executes the mcontext-based context switch. @@ -160,7 +160,7 @@ arch_context_switch(struct arch_context *a, struct arch_context *b) * This label is saved as the IP of a context during a fastpath context switch */ "2:\n\t" - "movq $3, (%%rdx)\n\t" /* b->variant = arch_context_variant_running; */ + "movq $3, (%%rdx)\n\t" /* b->variant = ARCH_CONTEXT_VARIANT_RUNNING; */ ".align 8\n\t" /* diff --git a/runtime/src/software_interrupt.c b/runtime/src/software_interrupt.c index 93d60f5..55e711b 100644 --- a/runtime/src/software_interrupt.c +++ b/runtime/src/software_interrupt.c @@ -121,7 +121,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_variant_slow); + assert(current_sandbox->ctxt.variant == ARCH_CONTEXT_VARIANT_SLOW); software_interrupt_SIGUSR_count++; debuglog("usr1:%d\n", software_interrupt_SIGUSR_count);