rt: Make the stack canary just a word on the stk_seg struct

This commit is contained in:
Brian Anderson
2012-02-15 15:41:59 -08:00
parent 2796ab6de9
commit 853e2003b8
2 changed files with 12 additions and 13 deletions
+9 -6
View File
@@ -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");
}