Skip to content

Commit f7649b5

Browse files
committed
---
yaml --- r: 13126 b: refs/heads/master c: 508ccca h: refs/heads/master v: v3
1 parent 26b4ba8 commit f7649b5

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 6d37c90ce638f6bbf2b9abdc6625fcb1d8887bfe
2+
refs/heads/master: 508ccca014fcc3a8ef241868ea05e36058b3e61c
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rt/rust_upcall.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,61 @@ upcall_trace(char const *msg,
151151
UPCALL_SWITCH_STACK(&args, upcall_s_trace);
152152
}
153153

154+
/**********************************************************************
155+
* Allocate an object in the exchange heap
156+
*/
157+
158+
struct s_exchange_malloc_args {
159+
uintptr_t retval;
160+
type_desc *td;
161+
};
162+
163+
extern "C" CDECL void
164+
upcall_s_exchange_malloc(s_exchange_malloc_args *args) {
165+
rust_task *task = rust_get_current_task();
166+
LOG_UPCALL_ENTRY(task);
167+
168+
LOG(task, mem, "upcall exchange malloc(0x%" PRIxPTR ")", args->td);
169+
170+
// Copied from boxed_region
171+
size_t header_size = sizeof(rust_opaque_box);
172+
size_t body_size = args->td->size;
173+
size_t body_align = args->td->align;
174+
size_t total_size = align_to(header_size, body_align) + body_size;
175+
176+
void *p = task->kernel->malloc(total_size, "exchange malloc");
177+
memset(p, '\0', total_size);
178+
179+
rust_opaque_box *header = static_cast<rust_opaque_box*>(p);
180+
header->td = args->td;
181+
182+
args->retval = (uintptr_t)header;
183+
}
184+
185+
extern "C" CDECL uintptr_t
186+
upcall_exchange_malloc(type_desc *td) {
187+
s_exchange_malloc_args args = {0, td};
188+
UPCALL_SWITCH_STACK(&args, upcall_s_exchange_malloc);
189+
return args.retval;
190+
}
191+
192+
struct s_exchange_free_args {
193+
void *ptr;
194+
};
195+
196+
extern "C" CDECL void
197+
upcall_s_exchange_free(s_exchange_free_args *args) {
198+
rust_task *task = rust_get_current_task();
199+
LOG_UPCALL_ENTRY(task);
200+
task->kernel->free(args->ptr);
201+
}
202+
203+
extern "C" CDECL void
204+
upcall_exchange_free(void *ptr) {
205+
s_exchange_free_args args = {ptr};
206+
UPCALL_SWITCH_STACK(&args, upcall_s_exchange_free);
207+
}
208+
154209
/**********************************************************************
155210
* Allocate an object in the task-local heap.
156211
*/

trunk/src/rt/rustrt.def.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ upcall_call_shim_on_rust_stack
8888
upcall_new_stack
8989
upcall_del_stack
9090
upcall_reset_stack_limit
91+
upcall_exchange_malloc
92+
upcall_exchange_free
9193
rust_uv_loop_new
9294
rust_uv_loop_delete
9395
rust_uv_loop_refcount
@@ -161,4 +163,4 @@ rust_port_take
161163
rust_port_drop
162164
rust_port_task
163165
rust_task_inhibit_kill
164-
rust_task_allow_kill
166+
rust_task_allow_kill

trunk/src/rustc/back/upcall.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type upcalls =
1212
trace: ValueRef,
1313
malloc: ValueRef,
1414
free: ValueRef,
15+
exchange_malloc: ValueRef,
16+
exchange_free: ValueRef,
1517
validate_box: ValueRef,
1618
shared_malloc: ValueRef,
1719
shared_free: ValueRef,
@@ -62,6 +64,11 @@ fn declare_upcalls(targ_cfg: @session::config,
6264
T_ptr(T_i8()))),
6365
free:
6466
nothrow(dv("free", [T_ptr(T_i8())])),
67+
exchange_malloc:
68+
nothrow(d("exchange_malloc", [T_ptr(tydesc_type)],
69+
T_ptr(T_i8()))),
70+
exchange_free:
71+
nothrow(dv("exchange_free", [T_ptr(T_i8())])),
6572
validate_box:
6673
nothrow(dv("validate_box", [T_ptr(T_i8())])),
6774
shared_malloc:

0 commit comments

Comments
 (0)