rt: Begin moving stack-building functions to rust_stack.cpp

This commit is contained in:
Brian Anderson 2012-02-08 15:28:25 -08:00
parent 2983e77383
commit e0d5b92b84
5 changed files with 68 additions and 53 deletions

View File

@ -45,6 +45,7 @@ RUNTIME_CS_$(1) := \
rt/rust_task_thread.cpp \
rt/rust_scheduler.cpp \
rt/rust_task.cpp \
rt/rust_stack.cpp \
rt/rust_task_list.cpp \
rt/rust_port.cpp \
rt/rust_upcall.cpp \
@ -84,6 +85,7 @@ RUNTIME_HDR_$(1) := rt/globals.h \
rt/rust_scheduler.h \
rt/rust_shape.h \
rt/rust_task.h \
rt/rust_stack.h \
rt/rust_task_list.h \
rt/rust_log.h \
rt/circular_buffer.h \

42
src/rt/rust_stack.cpp Normal file
View File

@ -0,0 +1,42 @@
#include "rust_internal.h"
#include "vg/valgrind.h"
#include "vg/memcheck.h"
// 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
config_valgrind_stack(stk_seg *stk) {
stk->valgrind_id =
VALGRIND_STACK_REGISTER(&stk->data[0],
stk->end);
#ifndef NVALGRIND
// Establish that the stack is accessible. This must be done when reusing
// 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));
#endif
}
void
unconfig_valgrind_stack(stk_seg *stk) {
VALGRIND_STACK_DEREGISTER(stk->valgrind_id);
}
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");
}
void
check_stack_canary(stk_seg *stk) {
assert(!memcmp(stk->data, stack_canary, sizeof(stack_canary))
&& "Somebody killed the canary");
}

23
src/rt/rust_stack.h Normal file
View File

@ -0,0 +1,23 @@
struct stk_seg {
stk_seg *prev;
stk_seg *next;
uintptr_t end;
unsigned int valgrind_id;
#ifndef _LP64
uint32_t pad;
#endif
uint8_t data[];
};
void
config_valgrind_stack(stk_seg *stk);
void
unconfig_valgrind_stack(stk_seg *stk);
void
add_stack_canary(stk_seg *stk);
void
check_stack_canary(stk_seg *stk);

View File

@ -2,9 +2,6 @@
#include "rust_internal.h"
#include "rust_cc.h"
#include "vg/valgrind.h"
#include "vg/memcheck.h"
#ifndef __WIN32__
#include <execinfo.h>
#endif
@ -60,12 +57,6 @@
#endif
#endif
// 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};
static size_t
get_next_stk_size(rust_task_thread *thread, rust_task *task,
size_t min, size_t current, size_t requested) {
@ -90,38 +81,6 @@ get_next_stk_size(rust_task_thread *thread, rust_task *task,
// Task stack segments. Heap allocated and chained together.
static void
config_valgrind_stack(stk_seg *stk) {
stk->valgrind_id =
VALGRIND_STACK_REGISTER(&stk->data[0],
stk->end);
#ifndef NVALGRIND
// Establish that the stack is accessible. This must be done when reusing
// 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));
#endif
}
static void
unconfig_valgrind_stack(stk_seg *stk) {
VALGRIND_STACK_DEREGISTER(stk->valgrind_id);
}
static 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");
}
static void
check_stack_canary(stk_seg *stk) {
assert(!memcmp(stk->data, stack_canary, sizeof(stack_canary))
&& "Somebody killed the canary");
}
// The amount of stack in a segment available to Rust code
static size_t
user_stack_size(stk_seg *stk) {

View File

@ -15,6 +15,7 @@
#include "rust_kernel.h"
#include "rust_obstack.h"
#include "boxed_region.h"
#include "rust_stack.h"
// Corresponds to the rust chan (currently _chan) type.
struct chan_handle {
@ -24,18 +25,6 @@ struct chan_handle {
struct rust_box;
struct stk_seg {
stk_seg *prev;
stk_seg *next;
uintptr_t end;
unsigned int valgrind_id;
#ifndef _LP64
uint32_t pad;
#endif
uint8_t data[];
};
struct frame_glue_fns {
uintptr_t mark_glue_off;
uintptr_t drop_glue_off;