diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-02-15 15:41:59 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-02-17 11:37:17 -0800 |
| commit | 853e2003b8383749596e5b7b153186e2eef32455 (patch) | |
| tree | d40153901e6b2bc8c8448f7a1c58adb440c8d385 /src/rt | |
| parent | 2796ab6de9eefb3d009a410e45f5c154469c94b7 (diff) | |
| download | rust-853e2003b8383749596e5b7b153186e2eef32455.tar.gz rust-853e2003b8383749596e5b7b153186e2eef32455.zip | |
rt: Make the stack canary just a word on the stk_seg struct
Diffstat (limited to 'src/rt')
| -rw-r--r-- | src/rt/rust_stack.cpp | 15 | ||||
| -rw-r--r-- | src/rt/rust_stack.h | 10 |
2 files changed, 12 insertions, 13 deletions
diff --git a/src/rt/rust_stack.cpp b/src/rt/rust_stack.cpp index 84e4215ac67..37acc438672 100644 --- a/src/rt/rust_stack.cpp +++ b/src/rt/rust_stack.cpp @@ -3,6 +3,12 @@ #include "vg/valgrind.h" #include "vg/memcheck.h" +#ifdef _LP64 +const uintptr_t canary_value = 0xABCDABCDABCDABCD; +#else +const uintptr_t canary_value = 0xABCDABCD; +#endif + void register_valgrind_stack(stk_seg *stk) { stk->valgrind_id = @@ -17,8 +23,7 @@ prepare_valgrind_stack(stk_seg *stk) { // old stack segments, since the act of popping the stack previously // caused valgrind to consider the whole thing inaccessible. size_t sz = stk->end - (uintptr_t)&stk->data[0]; - VALGRIND_MAKE_MEM_UNDEFINED(stk->data + sizeof(stack_canary), - sz - sizeof(stack_canary)); + VALGRIND_MAKE_MEM_UNDEFINED(stk->data, sz); #endif } @@ -29,12 +34,10 @@ deregister_valgrind_stack(stk_seg *stk) { void add_stack_canary(stk_seg *stk) { - memcpy(stk->data, stack_canary, sizeof(stack_canary)); - assert(sizeof(stack_canary) == 16 && "Stack canary was not the expected size"); + stk->canary = canary_value; } void check_stack_canary(stk_seg *stk) { - assert(!memcmp(stk->data, stack_canary, sizeof(stack_canary)) - && "Somebody killed the canary"); + assert(stk->canary == canary_value && "Somebody killed the canary"); } diff --git a/src/rt/rust_stack.h b/src/rt/rust_stack.h index f6704a9f0eb..e8be2f2c083 100644 --- a/src/rt/rust_stack.h +++ b/src/rt/rust_stack.h @@ -10,15 +10,11 @@ struct stk_seg { uint32_t pad; #endif + uintptr_t canary; + 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}; - // Used by create_stack void register_valgrind_stack(stk_seg *stk); @@ -34,7 +30,7 @@ add_stack_canary(stk_seg *stk); template <class T> stk_seg * create_stack(T allocer, size_t sz) { - size_t total_sz = sizeof(stk_seg) + sz + sizeof(stack_canary); + size_t total_sz = sizeof(stk_seg) + sz; stk_seg *stk = (stk_seg *)allocer->malloc(total_sz, "stack"); memset(stk, 0, sizeof(stk_seg)); stk->end = (uintptr_t) &stk->data[sz]; |
