Skip to content

Commit 0cbc6c5

Browse files
committed
---
yaml --- r: 14505 b: refs/heads/try c: 7e9aa6c h: refs/heads/master i: 14503: b08163e v: v3
1 parent cc42e4f commit 0cbc6c5

File tree

6 files changed

+29
-34
lines changed

6 files changed

+29
-34
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: b3f77bf92703543793a8073c8319e461e024cb69
5+
refs/heads/try: 7e9aa6c3c2ae054e32dfcc7c5e4830ce7c4c6921
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rt/rust_kernel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class rust_kernel {
5959
void *malloc(size_t size, const char *tag);
6060
void *realloc(void *mem, size_t size);
6161
void free(void *mem);
62+
memory_region *region() { return &_region; }
6263

6364
void fail();
6465

branches/try/src/rt/rust_stack.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,20 @@ void
4141
check_stack_canary(stk_seg *stk) {
4242
assert(stk->canary == canary_value && "Somebody killed the canary");
4343
}
44+
45+
stk_seg *
46+
create_stack(memory_region *region, size_t sz) {
47+
size_t total_sz = sizeof(stk_seg) + sz;
48+
stk_seg *stk = (stk_seg *)region->malloc(total_sz, "stack", false);
49+
memset(stk, 0, sizeof(stk_seg));
50+
stk->end = (uintptr_t) &stk->data[sz];
51+
add_stack_canary(stk);
52+
register_valgrind_stack(stk);
53+
return stk;
54+
}
55+
56+
void
57+
destroy_stack(memory_region *region, stk_seg *stk) {
58+
deregister_valgrind_stack(stk);
59+
region->free(stk);
60+
}

branches/try/src/rt/rust_stack.h

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef RUST_STACK_H
22
#define RUST_STACK_H
33

4+
#include "memory_region.h"
5+
46
struct stk_seg {
57
stk_seg *prev;
68
stk_seg *next;
@@ -15,36 +17,11 @@ struct stk_seg {
1517
uint8_t data[];
1618
};
1719

18-
// Used by create_stack
19-
void
20-
register_valgrind_stack(stk_seg *stk);
21-
22-
// Used by destroy_stack
23-
void
24-
deregister_valgrind_stack(stk_seg *stk);
25-
26-
// Used by create_stack
27-
void
28-
add_stack_canary(stk_seg *stk);
29-
30-
template <class T>
3120
stk_seg *
32-
create_stack(T allocer, size_t sz) {
33-
size_t total_sz = sizeof(stk_seg) + sz;
34-
stk_seg *stk = (stk_seg *)allocer->malloc(total_sz, "stack");
35-
memset(stk, 0, sizeof(stk_seg));
36-
stk->end = (uintptr_t) &stk->data[sz];
37-
add_stack_canary(stk);
38-
register_valgrind_stack(stk);
39-
return stk;
40-
}
41-
42-
template <class T>
21+
create_stack(memory_region *region, size_t sz);
22+
4323
void
44-
destroy_stack(T allocer, stk_seg *stk) {
45-
deregister_valgrind_stack(stk);
46-
allocer->free(stk);
47-
}
24+
destroy_stack(memory_region *region, stk_seg *stk);
4825

4926
// Must be called before each time a stack is reused to tell valgrind
5027
// that the stack is accessible.

branches/try/src/rt/rust_task.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ void
552552
rust_task::free_stack(stk_seg *stk) {
553553
LOGPTR(thread, "freeing stk segment", (uintptr_t)stk);
554554
total_stack_sz -= user_stack_size(stk);
555-
destroy_stack(this, stk);
555+
destroy_stack(&local_region, stk);
556556
}
557557

558558
void
@@ -596,7 +596,7 @@ rust_task::new_stack(size_t requested_sz) {
596596
}
597597

598598
size_t sz = rust_stk_sz + RED_ZONE_SIZE;
599-
stk_seg *new_stk = create_stack(this, sz);
599+
stk_seg *new_stk = create_stack(&local_region, sz);
600600
LOGPTR(thread, "new stk", (uintptr_t)new_stk);
601601
new_stk->prev = NULL;
602602
new_stk->next = stk;

branches/try/src/rt/rust_task_thread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ rust_task_thread::start_main_loop() {
290290

291291
I(this, !extra_c_stack);
292292
if (cached_c_stack) {
293-
destroy_stack(kernel, cached_c_stack);
293+
destroy_stack(kernel->region(), cached_c_stack);
294294
cached_c_stack = NULL;
295295
}
296296
}
@@ -369,15 +369,15 @@ void
369369
rust_task_thread::prepare_c_stack(rust_task *task) {
370370
I(this, !extra_c_stack);
371371
if (!cached_c_stack && !task->have_c_stack()) {
372-
cached_c_stack = create_stack(kernel, C_STACK_SIZE);
372+
cached_c_stack = create_stack(kernel->region(), C_STACK_SIZE);
373373
prepare_valgrind_stack(cached_c_stack);
374374
}
375375
}
376376

377377
void
378378
rust_task_thread::unprepare_c_stack() {
379379
if (extra_c_stack) {
380-
destroy_stack(kernel, extra_c_stack);
380+
destroy_stack(kernel->region(), extra_c_stack);
381381
extra_c_stack = NULL;
382382
}
383383
}

0 commit comments

Comments
 (0)