rt: Account for the size of stack_canary in create_stack

This commit is contained in:
Brian Anderson 2012-02-10 11:26:50 -08:00
parent fc028c30a0
commit dd0ae80e63

View file

@ -13,13 +13,19 @@ struct stk_seg {
uint8_t data[]; 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 void
add_stack_canary(stk_seg *stk); add_stack_canary(stk_seg *stk);
template <class T> template <class T>
stk_seg * stk_seg *
create_stack(T allocer, size_t sz) { 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"); stk_seg *stk = (stk_seg *)allocer->malloc(total_sz, "stack");
memset(stk, 0, sizeof(stk_seg)); memset(stk, 0, sizeof(stk_seg));
add_stack_canary(stk); add_stack_canary(stk);