Skip to content

Commit 1abc149

Browse files
committed
---
yaml --- r: 14337 b: refs/heads/try c: 853e200 h: refs/heads/master i: 14335: 4cc2ad4 v: v3
1 parent 197d2ab commit 1abc149

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 2796ab6de9eefb3d009a410e45f5c154469c94b7
5+
refs/heads/try: 853e2003b8383749596e5b7b153186e2eef32455
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rt/rust_stack.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#include "vg/valgrind.h"
44
#include "vg/memcheck.h"
55

6+
#ifdef _LP64
7+
const uintptr_t canary_value = 0xABCDABCDABCDABCD;
8+
#else
9+
const uintptr_t canary_value = 0xABCDABCD;
10+
#endif
11+
612
void
713
register_valgrind_stack(stk_seg *stk) {
814
stk->valgrind_id =
@@ -17,8 +23,7 @@ prepare_valgrind_stack(stk_seg *stk) {
1723
// old stack segments, since the act of popping the stack previously
1824
// caused valgrind to consider the whole thing inaccessible.
1925
size_t sz = stk->end - (uintptr_t)&stk->data[0];
20-
VALGRIND_MAKE_MEM_UNDEFINED(stk->data + sizeof(stack_canary),
21-
sz - sizeof(stack_canary));
26+
VALGRIND_MAKE_MEM_UNDEFINED(stk->data, sz);
2227
#endif
2328
}
2429

@@ -29,12 +34,10 @@ deregister_valgrind_stack(stk_seg *stk) {
2934

3035
void
3136
add_stack_canary(stk_seg *stk) {
32-
memcpy(stk->data, stack_canary, sizeof(stack_canary));
33-
assert(sizeof(stack_canary) == 16 && "Stack canary was not the expected size");
37+
stk->canary = canary_value;
3438
}
3539

3640
void
3741
check_stack_canary(stk_seg *stk) {
38-
assert(!memcmp(stk->data, stack_canary, sizeof(stack_canary))
39-
&& "Somebody killed the canary");
42+
assert(stk->canary == canary_value && "Somebody killed the canary");
4043
}

branches/try/src/rt/rust_stack.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@ struct stk_seg {
1010
uint32_t pad;
1111
#endif
1212

13+
uintptr_t canary;
14+
1315
uint8_t data[];
1416
};
1517

16-
// A value that goes at the end of the stack and must not be touched
17-
const uint8_t stack_canary[] = {0xAB, 0xCD, 0xAB, 0xCD,
18-
0xAB, 0xCD, 0xAB, 0xCD,
19-
0xAB, 0xCD, 0xAB, 0xCD,
20-
0xAB, 0xCD, 0xAB, 0xCD};
21-
2218
// Used by create_stack
2319
void
2420
register_valgrind_stack(stk_seg *stk);
@@ -34,7 +30,7 @@ add_stack_canary(stk_seg *stk);
3430
template <class T>
3531
stk_seg *
3632
create_stack(T allocer, size_t sz) {
37-
size_t total_sz = sizeof(stk_seg) + sz + sizeof(stack_canary);
33+
size_t total_sz = sizeof(stk_seg) + sz;
3834
stk_seg *stk = (stk_seg *)allocer->malloc(total_sz, "stack");
3935
memset(stk, 0, sizeof(stk_seg));
4036
stk->end = (uintptr_t) &stk->data[sz];

0 commit comments

Comments
 (0)