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);