Skip to content

Commit 50dc80f

Browse files
committed
rt: Give upcall_new_stack the same convention as other upcalls
1 parent bedcaad commit 50dc80f

File tree

3 files changed

+33
-58
lines changed

3 files changed

+33
-58
lines changed

src/rt/arch/i386/morestack.S

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,27 @@
6868

6969
#if defined(__APPLE__)
7070
#define RUST_GET_TASK L_rust_get_task$stub
71+
#define UPCALL_NEW_STACK L_upcall_new_stack$stub
7172
#define UPCALL_DEL_STACK L_upcall_del_stack$stub
72-
#define UPCALL_CALL_C L_upcall_call_shim_on_c_stack$stub
7373
#define MORESTACK ___morestack
7474
#else
7575
#if defined(__linux__)
7676
#define UPCALL_NEW_STACK upcall_new_stack
7777
#define UPCALL_DEL_STACK upcall_del_stack
7878
#define RUST_GET_TASK rust_get_task
79-
#define UPCALL_CALL_C upcall_call_shim_on_c_stack
8079
#define MORESTACK __morestack
8180
#else
8281
#define UPCALL_NEW_STACK _upcall_new_stack
8382
#define UPCALL_DEL_STACK _upcall_del_stack
8483
#define RUST_GET_TASK _rust_get_task
85-
#define UPCALL_CALL_C _upcall_call_shim_on_c_stack
8684
#define MORESTACK ___morestack
8785
#endif
8886
#endif
8987

90-
.globl UPCALL_NEW_STACK
9188
#ifndef __APPLE__
89+
.globl UPCALL_NEW_STACK
9290
.globl UPCALL_DEL_STACK
9391
.globl RUST_GET_TASK
94-
.globl UPCALL_CALL_C_STACK
9592
#endif
9693
.globl MORESTACK
9794

@@ -170,29 +167,19 @@ MORESTACK:
170167
// The size of the stack arguments to copy to the new stack,
171168
// ane of the the arguments to __morestack
172169
movl 56(%esp),%eax
173-
movl %eax,20(%esp)
170+
movl %eax,8(%esp)
174171
// The address of the stack arguments to the original function
175172
leal 64(%esp),%eax
176-
movl %eax,16(%esp)
173+
movl %eax,4(%esp)
177174
// The amount of stack needed for the original function,
178175
// the other argument to __morestack
179176
movl 52(%esp),%eax // The amount of stack needed
180-
movl %eax,12(%esp)
181-
// Out pointer to the new stack
182-
movl $0, 8(%esp)
177+
movl %eax,(%esp)
183178

184-
#ifdef __APPLE__
185-
call 1f
186-
1: popl %eax
187-
movl L_upcall_new_stack$non_lazy_ptr-1b(%eax),%eax
188-
movl %eax, 4(%esp)
189-
#else
190-
movl $UPCALL_NEW_STACK,4(%esp)
191-
#endif
179+
call UPCALL_NEW_STACK
192180

193-
leal 8(%esp), %eax
194-
movl %eax,(%esp)
195-
call UPCALL_CALL_C
181+
// Save the address of the new stack
182+
movl %eax, (%esp)
196183

197184
// Grab the __morestack return pointer
198185
movl 48(%esp),%eax
@@ -204,7 +191,7 @@ MORESTACK:
204191
movl 24(%esp), %edx
205192

206193
// Switch stacks
207-
movl 8(%esp),%esp
194+
movl (%esp),%esp
208195
// Re-enter the function that called us
209196
call *%eax
210197

@@ -253,26 +240,21 @@ MORESTACK:
253240

254241
#ifdef __APPLE__
255242

256-
.section __IMPORT,__pointers,non_lazy_symbol_pointers
257-
L_upcall_new_stack$non_lazy_ptr:
258-
.indirect_symbol _upcall_new_stack
259-
.long 0
260-
261243
.section __IMPORT,__jump_table,symbol_stubs,pure_instructions+self_modifying_code,5
262244

263245
// Linker will replace the hlts (the ascii) with jmp
264246
L_rust_get_task$stub:
265247
.indirect_symbol _rust_get_task
266248
.ascii "\364\364\364\364\364"
267249

250+
L_upcall_new_stack$stub:
251+
.indirect_symbol _upcall_new_stack
252+
.ascii "\364\364\364\364\364"
253+
268254
L_upcall_del_stack$stub:
269255
.indirect_symbol _upcall_del_stack
270256
.ascii "\364\364\364\364\364"
271257

272-
L_upcall_call_shim_on_c_stack$stub:
273-
.indirect_symbol _upcall_call_shim_on_c_stack
274-
.ascii "\364\364\364\364\364"
275-
276258
.subsections_via_symbols
277259
#endif
278260

src/rt/arch/x86_64/morestack.S

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@
99
#if defined(__APPLE__) || defined(_WIN32)
1010
#define UPCALL_NEW_STACK _upcall_new_stack
1111
#define UPCALL_DEL_STACK _upcall_del_stack
12-
#define UPCALL_CALL_C _upcall_call_shim_on_c_stack
1312
#define MORESTACK ___morestack
1413
#else
1514
#define UPCALL_NEW_STACK upcall_new_stack
1615
#define UPCALL_DEL_STACK upcall_del_stack
17-
#define UPCALL_CALL_C upcall_call_shim_on_c_stack
1816
#define MORESTACK __morestack
1917
#endif
2018

2119
.globl UPCALL_NEW_STACK
2220
.globl UPCALL_DEL_STACK
23-
.globl UPCALL_CALL_C
2421
.globl MORESTACK
2522

2623
#if defined(__linux__)
@@ -70,29 +67,22 @@ MORESTACK:
7067
// Calculate the address of the stack arguments.
7168
// We have the base pointer, __morestack's return address,
7269
// and __morestack's caller's return address to skip
73-
movq %rbp, %rcx
74-
addq $24, %rcx // Base pointer, return address x2
70+
movq %rbp, %rax
71+
addq $24, %rax // Base pointer, return address x2
7572

7673
// The arguments to __morestack are passed in %r10 & %r11
7774

78-
pushq %r11 // Size of stack arguments
79-
pushq %rcx // Address of stack arguments
80-
pushq %r10 // The amount of stack needed
81-
pushq $0 // Out pointer
75+
movq %r11, %rdx // Size of stack arguments
76+
movq %rax, %rsi // Address of stack arguments
77+
movq %r10, %rdi // The amount of stack needed
8278

83-
movq UPCALL_NEW_STACK@GOTPCREL(%rip), %rsi
84-
movq %rsp, %rdi
8579
#ifdef __APPLE__
86-
call UPCALL_CALL_C
80+
call UPCALL_NEW_STACK
8781
#endif
8882
#ifdef __linux__
89-
call UPCALL_CALL_C@PLT
83+
call UPCALL_NEW_STACK@PLT
9084
#endif
9185

92-
// Pop the new_stack_args struct
93-
popq %rax
94-
addq $24, %rsp
95-
9686
// Pop the saved arguments
9787
popq %r9
9888
popq %r8

src/rt/rust_upcall.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -595,23 +595,26 @@ upcall_log_type(const type_desc *tydesc, uint8_t *data, uint32_t level) {
595595
UPCALL_SWITCH_STACK(&args, upcall_s_log_type);
596596
}
597597

598-
struct rust_new_stack2_args {
599-
void *new_stack;
598+
struct s_new_stack_args {
599+
void *result;
600600
size_t stk_sz;
601601
void *args_addr;
602602
size_t args_sz;
603603
};
604604

605-
// A new stack function suitable for calling through
606-
// upcall_call_shim_on_c_stack
607-
// FIXME: Convert this to the same arrangement as
608-
// the other upcalls, simplify __morestack
609605
extern "C" CDECL void
610-
upcall_new_stack(struct rust_new_stack2_args *args) {
606+
upcall_s_new_stack(struct s_new_stack_args *args) {
611607
rust_task *task = rust_scheduler::get_task();
612-
args->new_stack = task->new_stack(args->stk_sz,
613-
args->args_addr,
614-
args->args_sz);
608+
args->result = task->new_stack(args->stk_sz,
609+
args->args_addr,
610+
args->args_sz);
611+
}
612+
613+
extern "C" CDECL void *
614+
upcall_new_stack(size_t stk_sz, void *args_addr, size_t args_sz) {
615+
s_new_stack_args args = {NULL, stk_sz, args_addr, args_sz};
616+
UPCALL_SWITCH_STACK(&args, upcall_s_new_stack);
617+
return args.result;
615618
}
616619

617620
extern "C" CDECL void

0 commit comments

Comments
 (0)