[OpenBIOS] [PATCH] Ensure saved context pointers in switch_to() for all archs are marked as volatile

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Sun Jul 3 18:42:39 CEST 2016


As discovered with the previous ppc patchset, the saved context pointer must be
marked as volatile, otherwise the compiler may decide to optimise away saving
the pointer to the local stack.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 openbios-devel/arch/amd64/context.c   |    5 +++--
 openbios-devel/arch/sparc64/context.c |    5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/openbios-devel/arch/amd64/context.c b/openbios-devel/arch/amd64/context.c
index 2e4df6a..33ab51e 100644
--- a/openbios-devel/arch/amd64/context.c
+++ b/openbios-devel/arch/amd64/context.c
@@ -97,14 +97,15 @@ init_context(uint8_t *stack, uint32_t stack_size, int num_params)
 /* Switch to another context. */
 struct context *switch_to(struct context *ctx)
 {
-    struct context *save, *ret;
+    volatile struct context *save;
+    struct context *ret;
 
     debug("switching to new context:\n");
     save = __context;
     __context = ctx;
     asm ("pushl %cs; call __switch_context");
     ret = __context;
-    __context = save;
+    __context = (struct context *)save;
     return ret;
 }
 
diff --git a/openbios-devel/arch/sparc64/context.c b/openbios-devel/arch/sparc64/context.c
index 98932ee..823116f 100644
--- a/openbios-devel/arch/sparc64/context.c
+++ b/openbios-devel/arch/sparc64/context.c
@@ -88,7 +88,8 @@ init_context(uint8_t *stack, uint64_t stack_size, int num_params)
 /* Switch to another context. */
 struct context *switch_to(struct context *ctx)
 {
-    struct context *save, *ret;
+    volatile struct context *save;
+    struct context *ret;
 
     debug("switching to new context: entry point %#llx stack 0x%016llx\n", ctx->pc, ctx->regs[REG_SP]);
     save = __context;
@@ -96,7 +97,7 @@ struct context *switch_to(struct context *ctx)
     //asm ("pushl %cs; call __switch_context");
     asm ("call __switch_context_nosave; nop");
     ret = __context;
-    __context = save;
+    __context = (struct context *)save;
     return ret;
 }
 
-- 
1.7.10.4




More information about the OpenBIOS mailing list