Skip to content

Commit a2bbdd3

Browse files
committed
rt: Remove upcall_shared_malloc/free/realloc
1 parent 80dc2e1 commit a2bbdd3

File tree

8 files changed

+6
-115
lines changed

8 files changed

+6
-115
lines changed

src/rt/rust_task.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#include "rust_task.h"
99
#include "rust_cc.h"
10-
#include "rust_upcall.h"
1110
#include "rust_env.h"
1211
#include "rust_port.h"
1312

@@ -130,6 +129,8 @@ cleanup_task(cleanup_args *args) {
130129
}
131130
}
132131

132+
extern "C" CDECL void upcall_exchange_free(void *ptr);
133+
133134
// This runs on the Rust stack
134135
void task_start_wrapper(spawn_args *a)
135136
{
@@ -161,7 +162,7 @@ void task_start_wrapper(spawn_args *a)
161162
// free the environment (which should be a unique closure).
162163
const type_desc *td = env->td;
163164
td->drop_glue(NULL, NULL, td->first_param, box_body(env));
164-
upcall_shared_free(env);
165+
upcall_exchange_free(env);
165166
}
166167

167168
// The cleanup work needs lots of stack

src/rt/rust_upcall.cpp

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -318,81 +318,6 @@ upcall_validate_box(rust_opaque_box* ptr) {
318318
}
319319
}
320320

321-
/**********************************************************************
322-
* Allocate an object in the exchange heap.
323-
*/
324-
325-
struct s_shared_malloc_args {
326-
uintptr_t retval;
327-
size_t nbytes;
328-
};
329-
330-
extern "C" CDECL void
331-
upcall_s_shared_malloc(s_shared_malloc_args *args) {
332-
rust_task *task = rust_get_current_task();
333-
LOG_UPCALL_ENTRY(task);
334-
335-
LOG(task, mem, "upcall shared_malloc(%" PRIdPTR ")", args->nbytes);
336-
void *p = task->kernel->malloc(args->nbytes, "shared malloc");
337-
memset(p, '\0', args->nbytes);
338-
LOG(task, mem, "upcall shared_malloc(%" PRIdPTR ") = 0x%" PRIxPTR,
339-
args->nbytes, (uintptr_t)p);
340-
args->retval = (uintptr_t) p;
341-
}
342-
343-
extern "C" CDECL uintptr_t
344-
upcall_shared_malloc(size_t nbytes) {
345-
s_shared_malloc_args args = {0, nbytes};
346-
UPCALL_SWITCH_STACK(&args, upcall_s_shared_malloc);
347-
return args.retval;
348-
}
349-
350-
/**********************************************************************
351-
* Called whenever an object in the exchange heap is freed.
352-
*/
353-
354-
struct s_shared_free_args {
355-
void *ptr;
356-
};
357-
358-
extern "C" CDECL void
359-
upcall_s_shared_free(s_shared_free_args *args) {
360-
rust_task *task = rust_get_current_task();
361-
LOG_UPCALL_ENTRY(task);
362-
363-
rust_sched_loop *sched_loop = task->sched_loop;
364-
DLOG(sched_loop, mem,
365-
"upcall shared_free(0x%" PRIxPTR")",
366-
(uintptr_t)args->ptr);
367-
task->kernel->free(args->ptr);
368-
}
369-
370-
extern "C" CDECL void
371-
upcall_shared_free(void* ptr) {
372-
s_shared_free_args args = {ptr};
373-
UPCALL_SWITCH_STACK(&args, upcall_s_shared_free);
374-
}
375-
376-
struct s_shared_realloc_args {
377-
void *retval;
378-
void *ptr;
379-
size_t size;
380-
};
381-
382-
extern "C" CDECL void
383-
upcall_s_shared_realloc(s_shared_realloc_args *args) {
384-
rust_task *task = rust_get_current_task();
385-
LOG_UPCALL_ENTRY(task);
386-
args->retval = task->kernel->realloc(args->ptr, args->size);
387-
}
388-
389-
extern "C" CDECL void *
390-
upcall_shared_realloc(void *ptr, size_t size) {
391-
s_shared_realloc_args args = {NULL, ptr, size};
392-
UPCALL_SWITCH_STACK(&args, upcall_s_shared_realloc);
393-
return args.retval;
394-
}
395-
396321
/**********************************************************************/
397322

398323
struct s_str_new_uniq_args {

src/rt/rust_upcall.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
21
#ifndef RUST_UPCALL_H
32
#define RUST_UPCALL_H
43

5-
// Upcalls used from C code on occasion:
6-
7-
extern "C" CDECL void upcall_shared_free(void* ptr);
8-
94
#endif

src/rt/rustrt.def.in

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@ upcall_validate_box
7474
upcall_log_type
7575
upcall_malloc
7676
upcall_rust_personality
77-
upcall_s_shared_malloc
78-
upcall_shared_malloc
79-
upcall_shared_free
80-
upcall_shared_realloc
8177
upcall_vec_grow
8278
upcall_str_new
8379
upcall_str_new_uniq

src/rustc/back/upcall.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ type upcalls =
1616
exchange_malloc_dyn: ValueRef,
1717
exchange_free: ValueRef,
1818
validate_box: ValueRef,
19-
shared_malloc: ValueRef,
20-
shared_free: ValueRef,
21-
shared_realloc: ValueRef,
2219
mark: ValueRef,
2320
vec_grow: ValueRef,
2421
str_new_uniq: ValueRef,
@@ -75,13 +72,6 @@ fn declare_upcalls(targ_cfg: @session::config,
7572
nothrow(dv("exchange_free", [T_ptr(T_i8())])),
7673
validate_box:
7774
nothrow(dv("validate_box", [T_ptr(T_i8())])),
78-
shared_malloc:
79-
nothrow(d("shared_malloc", [size_t], T_ptr(T_i8()))),
80-
shared_free:
81-
nothrow(dv("shared_free", [T_ptr(T_i8())])),
82-
shared_realloc:
83-
nothrow(d("shared_realloc", [T_ptr(T_i8()), size_t],
84-
T_ptr(T_i8()))),
8575
mark:
8676
d("mark", [T_ptr(T_i8())], int_t),
8777
vec_grow:

src/rustc/middle/trans/base.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,6 @@ fn trans_free(cx: block, v: ValueRef) -> block {
236236
cx
237237
}
238238

239-
fn trans_shared_free(cx: block, v: ValueRef) -> block {
240-
let _icx = cx.insn_ctxt("trans_shared_free");
241-
Call(cx, cx.ccx().upcalls.shared_free,
242-
[PointerCast(cx, v, T_ptr(T_i8()))]);
243-
ret cx;
244-
}
245-
246239
fn trans_unique_free(cx: block, v: ValueRef) -> block {
247240
let _icx = cx.insn_ctxt("trans_shared_free");
248241
Call(cx, cx.ccx().upcalls.exchange_free,
@@ -333,15 +326,6 @@ fn GEP_enum(bcx: block, llblobptr: ValueRef, enum_id: ast::def_id,
333326
GEPi(bcx, typed_blobptr, [0u, ix])
334327
}
335328

336-
// trans_shared_malloc: expects a type indicating which pointer type we want
337-
// and a size indicating how much space we want malloc'd.
338-
fn shared_malloc(cx: block, llptr_ty: TypeRef, llsize: ValueRef)
339-
-> ValueRef {
340-
let _icx = cx.insn_ctxt("opaque_shared_malloc");
341-
let rval = Call(cx, cx.ccx().upcalls.shared_malloc, [llsize]);
342-
PointerCast(cx, rval, llptr_ty)
343-
}
344-
345329
// Returns a pointer to the body for the box. The box may be an opaque
346330
// box. The result will be casted to the type of body_t, if it is statically
347331
// known.

src/rustc/middle/trans/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ fn add_clean_temp_mem(cx: block, val: ValueRef, ty: ty::t) {
271271
}
272272
}
273273
fn add_clean_free(cx: block, ptr: ValueRef, shared: bool) {
274-
let free_fn = if shared { bind base::trans_shared_free(_, ptr) }
274+
let free_fn = if shared { bind base::trans_unique_free(_, ptr) }
275275
else { bind base::trans_free(_, ptr) };
276276
in_scope_cx(cx) {|info|
277277
info.cleanups += [clean_temp(ptr, free_fn,

src/rustc/middle/trans/tvec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import syntax::ast;
22
import driver::session::session;
33
import lib::llvm::{ValueRef, TypeRef};
44
import back::abi;
5-
import base::{call_memmove, shared_malloc,
5+
import base::{call_memmove,
66
INIT, copy_val, load_if_immediate, get_tydesc,
77
sub_block, do_spill_noroot,
88
dest, bcx_icx};
@@ -115,7 +115,7 @@ fn make_free_glue(bcx: block, vptr: ValueRef, vec_ty: ty::t) ->
115115
let bcx = if ty::type_needs_drop(tcx, unit_ty) {
116116
iter_vec(bcx, vptr, vec_ty, base::drop_ty)
117117
} else { bcx };
118-
base::trans_shared_free(bcx, vptr)
118+
base::trans_unique_free(bcx, vptr)
119119
}
120120
}
121121

0 commit comments

Comments
 (0)