Browse Source

altstack: Declare memory clobbers

altstack includes a couple of inline asm blocks with x86 push and pop
instructions.  These instructions will access memory (the stack), but
that's not declared in inline asm statement.  We seem to be getting away
with it, but in theory that could allow the compiler to re-order accesses
to local variables across the asm block.  Since those blocks change the
location of the stack, that could be very bad.

Adding a "memory" clobber should prevent this (effectively making the asm
blocks a compiler memory barrier).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
David Gibson 10 years ago
parent
commit
dd3f80c16c
1 changed files with 3 additions and 2 deletions
  1. 3 2
      ccan/altstack/altstack.c

+ 3 - 2
ccan/altstack/altstack.c

@@ -108,9 +108,10 @@ int altstack(rlim_t max, void *(*fn)(void *), void *arg, void **out)
 			"mov %1, %%rsp\n\t"
 			"mov %1, %%rsp\n\t"
 			"sub $8, %%rsp\n\t"
 			"sub $8, %%rsp\n\t"
 			"push %%r10"
 			"push %%r10"
-			: "=r" (rsp_save_[0]) : "0" (m + max) : "r10");
+			: "=r" (rsp_save_[0]) : "0" (m + max) : "r10", "memory");
 		out_ = fn_(arg_);
 		out_ = fn_(arg_);
-		asm volatile ("pop %rsp");
+		asm volatile ("pop %%rsp"
+			      : : : "memory");
 		ret = 0;
 		ret = 0;
 		if (out) *out = out_;
 		if (out) *out = out_;
 	}
 	}