Skip to content

Commit bb08807

Browse files
committed
---
yaml --- r: 5595 b: refs/heads/master c: 1eaaae8 h: refs/heads/master i: 5593: 16156b4 5591: 9f5df28 v: v3
1 parent a91fbee commit bb08807

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

[refs]

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

trunk/src/rt/arch/i386/context.h

+18-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
#ifndef CONTEXT_H
44
#define CONTEXT_H
55

6+
#include <cstdlib>
67
#include <inttypes.h>
8+
#include <stdint.h>
9+
10+
template<typename T>
11+
T align_down(T sp)
12+
{
13+
// There is no platform we care about that needs more than a
14+
// 16-byte alignment.
15+
return (T)((uint32_t)sp & ~(16 - 1));
16+
}
717

818
struct registers_t {
919
// general purpose registers
@@ -26,16 +36,15 @@ class context {
2636
context *next;
2737

2838
void swap(context &out);
29-
3039
void call(void *f, void *arg, void *sp);
31-
};
3240

33-
template<typename T>
34-
T align_down(T sp)
35-
{
36-
// There is no platform we care about that needs more than a
37-
// 16-byte alignment.
38-
return (T)((int)sp & ~(16 - 1));
39-
}
41+
// Note that this doesn't actually adjust esp. Instead, we adjust esp when
42+
// we actually do the call. This is needed for exception safety -- if the
43+
// function being called causes the task to fail, then we have to avoid
44+
// leaking space on the C stack.
45+
inline void *alloc_stack(size_t nbytes) {
46+
return (void *)(align_down(regs.esp - nbytes));
47+
}
48+
};
4049

4150
#endif

trunk/src/rt/intrinsics/intrinsics.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// -I../arch/i386 -fno-stack-protector -o intrinsics.ll intrinsics.cpp`
33

44
#include "../rust_internal.h"
5+
#include "../rust_scheduler.h"
56
#include <cstdlib>
67
#include <cstring>
78

@@ -46,3 +47,4 @@ rust_intrinsic_recv(rust_task *task, void **retptr, type_desc *ty,
4647
rust_port *port) {
4748
port_recv(task, (uintptr_t*)retptr, port);
4849
}
50+

trunk/src/rt/rust_upcall.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@ upcall_dynastack_free(rust_task *task, void *ptr) {
202202
return task->dynastack.free(ptr);
203203
}
204204

205+
/**
206+
* Allocates |nbytes| bytes in the C stack and returns a pointer to the start
207+
* of the allocated space.
208+
*/
209+
extern "C" CDECL void *
210+
upcall_alloc_c_stack(size_t nbytes) {
211+
rust_scheduler *sched = rust_scheduler::get_task()->sched;
212+
return sched->c_context.alloc_stack(nbytes);
213+
}
214+
205215
extern "C" _Unwind_Reason_Code
206216
__gxx_personality_v0(int version,
207217
_Unwind_Action actions,

trunk/src/rt/rustrt.def.in

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ task_sleep
6565
task_yield
6666
task_join
6767
unsupervise
68+
upcall_alloc_c_stack
6869
upcall_cmp_type
6970
upcall_dynastack_alloc
7071
upcall_dynastack_alloc_2

0 commit comments

Comments
 (0)