Skip to content

Commit 9656cea

Browse files
committed
rt: Put 16 guard bytes at the end of the stack
1 parent 5d1a1dc commit 9656cea

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/rt/rust_task.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@
1414

1515
#include "globals.h"
1616

17+
// Each stack gets some guard bytes that valgrind will verify we don't touch
18+
#ifndef NVALGRIND
19+
#define STACK_NOACCESS_SIZE 16
20+
#else
21+
#define STACK_NOACCESS_SIZE 0
22+
#endif
23+
1724
// The amount of extra space at the end of each stack segment, available
1825
// to the rt, compiler and dynamic linker for running small functions
1926
// FIXME: We want this to be 128 but need to slim the red zone calls down
2027
#ifdef __i386__
21-
#define RED_ZONE_SIZE 65536
28+
#define RED_ZONE_SIZE (65536 + STACK_NOACCESS_SIZE)
2229
#endif
2330

2431
#ifdef __x86_64__
25-
#define RED_ZONE_SIZE 65536
32+
#define RED_ZONE_SIZE (65536 + STACK_NOACCESS_SIZE)
2633
#endif
2734

2835
// Stack size
@@ -56,6 +63,9 @@ new_stk(rust_scheduler *sched, rust_task *task, size_t minsz)
5663
stk->valgrind_id =
5764
VALGRIND_STACK_REGISTER(&stk->data[0],
5865
&stk->data[minsz + RED_ZONE_SIZE]);
66+
#ifndef NVALGRIND
67+
VALGRIND_MAKE_MEM_NOACCESS(stk->data, STACK_NOACCESS_SIZE);
68+
#endif
5969
task->stk = stk;
6070
return stk;
6171
}
@@ -67,6 +77,9 @@ del_stk(rust_task *task, stk_seg *stk)
6777

6878
task->stk = stk->next;
6979

80+
#ifndef NVALGRIND
81+
VALGRIND_MAKE_MEM_DEFINED(stk->data, STACK_NOACCESS_SIZE);
82+
#endif
7083
VALGRIND_STACK_DEREGISTER(stk->valgrind_id);
7184
LOGPTR(task->sched, "freeing stk segment", (uintptr_t)stk);
7285
task->free(stk);

0 commit comments

Comments
 (0)