Skip to content

Commit 4965dc0

Browse files
committed
---
yaml --- r: 6270 b: refs/heads/master c: b3cf0c4 h: refs/heads/master v: v3
1 parent de18333 commit 4965dc0

File tree

7 files changed

+31
-145
lines changed

7 files changed

+31
-145
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: ced0d4f15e11e2c74766d1055146946ded3fba51
2+
refs/heads/master: b3cf0c4d1b9a28847bac8080a17d748704e01d7f

trunk/mk/rt.mk

+1-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ RUNTIME_CS_$(1) := \
6767

6868
RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \
6969
rt/arch/$$(HOST_$(1))/ccall.S \
70-
rt/arch/$$(HOST_$(1))/morestack.S \
71-
rt/arch/$$(HOST_$(1))/record_sp.S
70+
rt/arch/$$(HOST_$(1))/morestack.S
7271

7372
RUNTIME_HDR_$(1) := rt/globals.h \
7473
rt/rust.h \

trunk/src/rt/arch/i386/morestack.S

+21-98
Original file line numberDiff line numberDiff line change
@@ -2,117 +2,40 @@
22

33
// __morestack
44
//
5-
// LLVM generates a call to this to allocate more stack space in a function
5+
// LLVM generates a call to this to allocate more stack space in a functiono
66
// prolog when we run out.
77

88
#if defined(__APPLE__) || defined(_WIN32)
9-
#define RUST_NEW_STACK _rust_new_stack
10-
#define RUST_DEL_STACK _rust_del_stack
11-
#define RUST_GET_PREV_STACK _rust_get_prev_stack
12-
#define RUST_GET_TASK _rust_get_task
13-
#define UPCALL_ALLOC_C_STACK _upcall_alloc_c_stack
14-
#define UPCALL_CALL_C_STACK _upcall_call_c_stack
15-
#define MORESTACK ___morestack
9+
#define RUST_NEW_STACK _rust_new_stack
10+
#define RUST_DEL_STACK _rust_del_stack
11+
#define MORESTACK ___morestack
1612
#else
17-
#define RUST_NEW_STACK rust_new_stack
18-
#define RUST_DEL_STACK rust_del_stack
19-
#define RUST_GET_PREV_STACK rust_get_prev_stack
20-
#define RUST_GET_TASK rust_get_task
21-
#define UPCALL_ALLOC_C_STACK upcall_alloc_c_stack
22-
#define UPCALL_CALL_C_STACK upcall_call_c_stack
23-
#define MORESTACK __morestack
13+
#define RUST_NEW_STACK rust_new_stack
14+
#define RUST_DEL_STACK rust_del_stack
15+
#define MORESTACK __morestack
2416
#endif
2517

26-
#ifdef __APPLE__
27-
#define ALIGNMENT 4
28-
#else
29-
#define ALIGNMENT 8
30-
#endif
31-
32-
#define RETURN_OFFSET 7
33-
3418
.globl RUST_NEW_STACK
3519
.globl RUST_DEL_STACK
36-
.globl RUST_GET_PREV_STACK
37-
.globl RUST_GET_TASK
38-
.globl UPCALL_ALLOC_C_STACK
39-
.globl UPCALL_CALL_C_STACK
20+
4021
.globl MORESTACK
4122

4223
MORESTACK:
43-
44-
// Sanity check to make sure that there is a currently-running task.
45-
subl $12,%esp
46-
calll RUST_GET_TASK
47-
testl %eax,%eax
48-
jz L$bail
49-
50-
subl $12,%esp
51-
pushl $12
52-
calll UPCALL_ALLOC_C_STACK
53-
movl %eax,%edx
54-
55-
// C stack | esp+12
56-
// ---------------------+-------------------------
57-
movl 20(%esp),%eax // | ra stksz argsz x ra args
58-
movl %eax,8(%edx) // argsz > | ra stksz argsz x ra args
59-
leal 32(%esp),%eax // argsz | ra stksz argsz x ra args
60-
movl %eax,4(%edx) // argp > argsz | ra stksz argsz x ra args
61-
movl 16(%esp),%eax // argp argsz | ra stksz argsz x ra args
62-
movl %eax,(%edx) // stksz > argp argsz | ra stksz argsz x ra args
63-
64-
calll L$pic_ref_pt_0
65-
L$pic_ref_pt_0:
66-
popl %eax
67-
68-
movl rust_new_stack_sym-L$pic_ref_pt_0(%eax),%eax
69-
movl %eax,(%esp)
70-
movl %edx,4(%esp)
71-
calll UPCALL_CALL_C_STACK
72-
73-
movl 16(%esp),%edx // Grab the return pointer.
74-
addl $RETURN_OFFSET,%edx // Skip past the `add esp,4` and the `ret`.
75-
76-
movl %eax,%esp // Switch stacks.
77-
subl $12,%esp // Align the stack.
24+
pushl 8(%esp) // argsz > ra stksz argsz x x ra args
25+
leal 28(%esp),%eax // argsz ra stksz argsz x x ra args
26+
pushl %eax // argp > argsz ra stksz argsz x x ra args
27+
pushl 12(%esp) // stksz > argp argsz ra stksz argsz x x ra args
28+
calll RUST_NEW_STACK
29+
addl $12,%esp // ra stksz argsz x x ra args
30+
31+
movl (%esp),%edx // Grab the return pointer.
32+
incl %edx // Skip past the `ret`.
33+
movl %eax,%esp // Switch to the new stack.
7834
calll *%edx // Re-enter the function that called us.
7935

8036
// Now the function that called us has returned, so we need to delete the
8137
// old stack space.
82-
83-
calll RUST_GET_PREV_STACK
84-
movl %eax,%esp // Switch back to the old stack.
85-
86-
movl $0,(%esp)
87-
calll UPCALL_ALLOC_C_STACK
88-
89-
calll L$pic_ref_pt_1
90-
L$pic_ref_pt_1:
91-
popl %edx
92-
93-
movl rust_del_stack_sym-L$pic_ref_pt_1(%edx),%edx
94-
movl %edx,(%esp)
95-
movl %eax,4(%esp)
96-
calll UPCALL_CALL_C_STACK
97-
98-
addl $16,%esp
99-
retl $16 + ALIGNMENT // ra stksz argsz x ra args
100-
101-
L$bail:
102-
movl 12(%esp),%edx
103-
addl $RETURN_OFFSET,%edx
104-
addl $12+16,%esp
105-
jmpl *%edx
106-
107-
#ifdef __APPLE__
108-
109-
.section __IMPORT,__pointers,non_lazy_symbol_pointers
110-
rust_new_stack_sym:
111-
.indirect_symbol RUST_NEW_STACK
112-
.long 0
113-
rust_del_stack_sym:
114-
.indirect_symbol RUST_DEL_STACK
115-
.long 0
116-
117-
#endif
38+
calll RUST_DEL_STACK
39+
movl %eax,%esp
40+
retl $8 // ra stksz argsz x x ra args
11841

trunk/src/rt/rust.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "rust_internal.h"
2-
#include <cstdio>
32

43
struct
54
command_line_args : public kernel_owned<command_line_args>
@@ -76,8 +75,6 @@ int check_claims = 0;
7675

7776
extern "C" CDECL int
7877
rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
79-
fprintf(stderr, "rust_start, argc=%d argv=%p\n", argc, argv);
80-
8178
rust_env *env = load_env();
8279

8380
update_log_settings(crate_map, env->logspec);

trunk/src/rt/rust_scheduler.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
#include <stdarg.h>
33
#include <cassert>
4-
#include <pthread.h>
54
#include "rust_internal.h"
65
#include "globals.h"
76

@@ -13,9 +12,6 @@ DWORD rust_scheduler::task_key;
1312

1413
bool rust_scheduler::tls_initialized = false;
1514

16-
// Defined in arch/*/record_sp.S.
17-
extern "C" void rust_record_sp(uintptr_t sp);
18-
1915
rust_scheduler::rust_scheduler(rust_kernel *kernel,
2016
rust_srv *srv,
2117
int id) :
@@ -290,8 +286,6 @@ rust_scheduler::start_main_loop() {
290286
scheduled_task->state->name);
291287

292288
place_task_in_tls(scheduled_task);
293-
rust_record_sp(scheduled_task->stk->limit);
294-
//pthread_setspecific(89, (void *)scheduled_task->stk->limit);
295289

296290
interrupt_flag = 0;
297291

@@ -381,8 +375,6 @@ rust_scheduler::place_task_in_tls(rust_task *task) {
381375

382376
rust_task *
383377
rust_scheduler::get_task() {
384-
if (!tls_initialized)
385-
return NULL;
386378
rust_task *task = reinterpret_cast<rust_task *>
387379
(pthread_getspecific(task_key));
388380
assert(task && "Couldn't get the task from TLS!");
@@ -404,8 +396,6 @@ rust_scheduler::place_task_in_tls(rust_task *task) {
404396

405397
rust_task *
406398
rust_scheduler::get_task() {
407-
if (!tls_initialized)
408-
return NULL;
409399
rust_task *task = reinterpret_cast<rust_task *>(TlsGetValue(task_key));
410400
assert(task && "Couldn't get the task from TLS!");
411401
return task;

trunk/src/rt/rust_task.cpp

+6-23
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
#ifndef __WIN32__
99
#include <execinfo.h>
1010
#endif
11-
#include <iostream>
1211
#include <cassert>
1312
#include <cstring>
1413

1514
#include "globals.h"
1615

17-
#define RED_ZONE_SIZE 128
18-
1916
// Stack size
2017
size_t g_custom_min_stack_size = 0;
2118

@@ -37,16 +34,16 @@ new_stk(rust_scheduler *sched, rust_task *task, size_t minsz)
3734
size_t min_stk_bytes = get_min_stk_size(sched->min_stack_size);
3835
if (minsz < min_stk_bytes)
3936
minsz = min_stk_bytes;
40-
size_t sz = sizeof(stk_seg) + minsz + RED_ZONE_SIZE;
37+
size_t sz = sizeof(stk_seg) + minsz;
4138
stk_seg *stk = (stk_seg *)task->malloc(sz, "stack");
4239
LOGPTR(task->sched, "new stk", (uintptr_t)stk);
4340
memset(stk, 0, sizeof(stk_seg));
4441
stk->next = task->stk;
45-
stk->limit = (uintptr_t) &stk->data[minsz + RED_ZONE_SIZE];
42+
stk->limit = (uintptr_t) &stk->data[minsz];
4643
LOGPTR(task->sched, "stk limit", stk->limit);
4744
stk->valgrind_id =
4845
VALGRIND_STACK_REGISTER(&stk->data[0],
49-
&stk->data[minsz + RED_ZONE_SIZE]);
46+
&stk->data[minsz]);
5047
task->stk = stk;
5148
return stk;
5249
}
@@ -66,32 +63,18 @@ del_stk(rust_task *task, stk_seg *stk)
6663
// Entry points for `__morestack` (see arch/*/morestack.S).
6764
extern "C" void *
6865
rust_new_stack(size_t stk_sz, void *args_addr, size_t args_sz) {
69-
std::cerr << "*** New stack!\n";
70-
7166
rust_task *task = rust_scheduler::get_task();
72-
if (!task)
73-
return NULL;
74-
7567
stk_seg *stk_seg = new_stk(task->sched, task, stk_sz);
7668
memcpy(stk_seg->data, args_addr, args_sz);
7769
return stk_seg->data;
7870
}
7971

80-
extern "C" void
72+
extern "C" void *
8173
rust_del_stack() {
8274
rust_task *task = rust_scheduler::get_task();
75+
stk_seg *next_seg = task->stk->next;
8376
del_stk(task, task->stk);
84-
}
85-
86-
extern "C" void *
87-
rust_get_prev_stack() {
88-
rust_task *task = rust_scheduler::get_task();
89-
return task->stk->next;
90-
}
91-
92-
extern "C" rust_task *
93-
rust_get_task() {
94-
return rust_scheduler::get_task();
77+
return next_seg->data;
9578
}
9679

9780

trunk/src/rt/rustrt.def.in

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
__morestack
21
align_of
32
chan_id_send
43
check_claims
@@ -29,24 +28,19 @@ rand_free
2928
rand_new
3029
rand_next
3130
refcount
32-
rust_del_stack
3331
rust_file_is_dir
34-
rust_getcwd
35-
rust_get_prev_stack
3632
rust_get_stdin
3733
rust_get_stdout
3834
rust_get_stderr
3935
rust_str_push
4036
rust_list_files
4137
rust_port_size
42-
rust_new_stack
4338
rust_process_wait
4439
rust_ptr_eq
4540
rust_run_program
4641
rust_start
4742
rust_getcwd
4843
rust_task_sleep
49-
rust_get_task
5044
set_min_stack
5145
sched_threads
5246
size_of
@@ -67,10 +61,10 @@ upcall_dynastack_mark
6761
upcall_fail
6862
upcall_free
6963
upcall_get_type_desc
64+
upcall_vec_grow
65+
upcall_vec_push
7066
upcall_log_type
7167
upcall_malloc
7268
upcall_rust_personality
7369
upcall_shared_malloc
7470
upcall_shared_free
75-
upcall_vec_grow
76-
upcall_vec_push

0 commit comments

Comments
 (0)