From dd0ae80e63beed52164eac76bc94b36b73b6c590 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 10 Feb 2012 11:26:50 -0800 Subject: [PATCH] rt: Account for the size of stack_canary in create_stack --- src/rt/rust_stack.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rt/rust_stack.h b/src/rt/rust_stack.h index 6d5fea0c7ef4..190cfba8c139 100644 --- a/src/rt/rust_stack.h +++ b/src/rt/rust_stack.h @@ -13,13 +13,19 @@ struct stk_seg { uint8_t data[]; }; +// A value that goes at the end of the stack and must not be touched +const uint8_t stack_canary[] = {0xAB, 0xCD, 0xAB, 0xCD, + 0xAB, 0xCD, 0xAB, 0xCD, + 0xAB, 0xCD, 0xAB, 0xCD, + 0xAB, 0xCD, 0xAB, 0xCD}; + void add_stack_canary(stk_seg *stk); template stk_seg * create_stack(T allocer, size_t sz) { - size_t total_sz = sizeof(stk_seg) + sz; + size_t total_sz = sizeof(stk_seg) + sz + sizeof(stack_canary); stk_seg *stk = (stk_seg *)allocer->malloc(total_sz, "stack"); memset(stk, 0, sizeof(stk_seg)); add_stack_canary(stk);