Rename upcall_malloc_dyn to just upcall_malloc.

This commit is contained in:
Michael Sullivan 2012-06-21 10:47:27 -07:00
parent 9a2b60dfce
commit 393f739990
4 changed files with 60 additions and 100 deletions

View File

@ -143,66 +143,46 @@ upcall_trace(char const *msg,
* Allocate an object in the exchange heap * Allocate an object in the exchange heap
*/ */
extern "C" CDECL uintptr_t
exchange_malloc(rust_task *task, type_desc *td, uintptr_t size) {
LOG(task, mem, "upcall exchange malloc(0x%" PRIxPTR ")", td);
size_t total_size = get_box_size(size, td->align);
void *p = task->kernel->calloc(total_size, "exchange malloc");
rust_opaque_box *header = static_cast<rust_opaque_box*>(p);
header->ref_count = -1; // This is not ref counted
header->td = td;
header->prev = 0;
header->next = 0;
return (uintptr_t)header;
}
// FIXME: remove after snapshot (6/13/12)
struct s_exchange_malloc_args { struct s_exchange_malloc_args {
rust_task *task; rust_task *task;
uintptr_t retval; uintptr_t retval;
type_desc *td; type_desc *td;
};
extern "C" CDECL void
upcall_s_exchange_malloc(s_exchange_malloc_args *args) {
rust_task *task = args->task;
LOG_UPCALL_ENTRY(task);
args->retval = exchange_malloc(task, args->td, args->td->size);
}
extern "C" CDECL uintptr_t
upcall_exchange_malloc(type_desc *td) {
rust_task *task = rust_get_current_task();
s_exchange_malloc_args args = {task, 0, td};
UPCALL_SWITCH_STACK(task, &args, upcall_s_exchange_malloc);
return args.retval;
}
struct s_exchange_malloc_dyn_args {
rust_task *task;
uintptr_t retval;
type_desc *td;
uintptr_t size; uintptr_t size;
}; };
extern "C" CDECL void extern "C" CDECL void
upcall_s_exchange_malloc_dyn(s_exchange_malloc_dyn_args *args) { upcall_s_exchange_malloc(s_exchange_malloc_args *args) {
rust_task *task = args->task; rust_task *task = args->task;
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, mem, "upcall exchange malloc(0x%" PRIxPTR ")", args->td);
args->retval = exchange_malloc(task, args->td, args->size); size_t total_size = get_box_size(args->size, args->td->align);
// FIXME--does this have to be calloc? (Issue #2682)
void *p = task->kernel->calloc(total_size, "exchange malloc");
rust_opaque_box *header = static_cast<rust_opaque_box*>(p);
header->ref_count = -1; // This is not ref counted
header->td = args->td;
header->prev = 0;
header->next = 0;
args->retval = (uintptr_t)header;
} }
extern "C" CDECL uintptr_t
upcall_exchange_malloc(type_desc *td, uintptr_t size) {
rust_task *task = rust_get_current_task();
s_exchange_malloc_args args = {task, 0, td, size};
UPCALL_SWITCH_STACK(task, &args, upcall_s_exchange_malloc);
return args.retval;
}
// FIXME: remove after snapshot (6/21/12)
extern "C" CDECL uintptr_t extern "C" CDECL uintptr_t
upcall_exchange_malloc_dyn(type_desc *td, uintptr_t size) { upcall_exchange_malloc_dyn(type_desc *td, uintptr_t size) {
rust_task *task = rust_get_current_task(); rust_task *task = rust_get_current_task();
s_exchange_malloc_dyn_args args = {task, 0, td, size}; s_exchange_malloc_args args = {task, 0, td, size};
UPCALL_SWITCH_STACK(task, &args, upcall_s_exchange_malloc_dyn); UPCALL_SWITCH_STACK(task, &args, upcall_s_exchange_malloc);
return args.retval; return args.retval;
} }
@ -229,69 +209,49 @@ upcall_exchange_free(void *ptr) {
* Allocate an object in the task-local heap. * Allocate an object in the task-local heap.
*/ */
extern "C" CDECL uintptr_t
shared_malloc(rust_task *task, type_desc *td, uintptr_t size) {
LOG(task, mem, "upcall malloc(0x%" PRIxPTR ")", td);
cc::maybe_cc(task);
// FIXME--does this have to be calloc?
rust_opaque_box *box = task->boxed.calloc(td, size);
void *body = box_body(box);
debug::maybe_track_origin(task, box);
LOG(task, mem,
"upcall malloc(0x%" PRIxPTR ") = box 0x%" PRIxPTR
" with body 0x%" PRIxPTR,
td, (uintptr_t)box, (uintptr_t)body);
return (uintptr_t)box;
}
// FIXME: remove after snapshot (6/13/12)
struct s_malloc_args { struct s_malloc_args {
rust_task *task; rust_task *task;
uintptr_t retval; uintptr_t retval;
type_desc *td; type_desc *td;
};
extern "C" CDECL void
upcall_s_malloc(s_malloc_args *args) {
rust_task *task = args->task;
LOG_UPCALL_ENTRY(task);
args->retval = shared_malloc(task, args->td, args->td->size);
}
extern "C" CDECL uintptr_t
upcall_malloc(type_desc *td) {
rust_task *task = rust_get_current_task();
s_malloc_args args = {task, 0, td};
UPCALL_SWITCH_STACK(task, &args, upcall_s_malloc);
return args.retval;
}
struct s_malloc_dyn_args {
rust_task *task;
uintptr_t retval;
type_desc *td;
uintptr_t size; uintptr_t size;
}; };
extern "C" CDECL void extern "C" CDECL void
upcall_s_malloc_dyn(s_malloc_dyn_args *args) { upcall_s_malloc(s_malloc_args *args) {
rust_task *task = args->task; rust_task *task = args->task;
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, mem, "upcall malloc(0x%" PRIxPTR ")", args->td);
args->retval = shared_malloc(task, args->td, args->size); cc::maybe_cc(task);
// FIXME--does this have to be calloc? (Issue #2682)
rust_opaque_box *box = task->boxed.calloc(args->td, args->size);
void *body = box_body(box);
debug::maybe_track_origin(task, box);
LOG(task, mem,
"upcall malloc(0x%" PRIxPTR ") = box 0x%" PRIxPTR
" with body 0x%" PRIxPTR,
args->td, (uintptr_t)box, (uintptr_t)body);
args->retval = (uintptr_t)box;
} }
extern "C" CDECL uintptr_t
upcall_malloc(type_desc *td, uintptr_t size) {
rust_task *task = rust_get_current_task();
s_malloc_args args = {task, 0, td, size};
UPCALL_SWITCH_STACK(task, &args, upcall_s_malloc);
return args.retval;
}
// FIXME: remove after snapshot (6/21/12)
extern "C" CDECL uintptr_t extern "C" CDECL uintptr_t
upcall_malloc_dyn(type_desc *td, uintptr_t size) { upcall_malloc_dyn(type_desc *td, uintptr_t size) {
rust_task *task = rust_get_current_task(); rust_task *task = rust_get_current_task();
s_malloc_dyn_args args = {task, 0, td, size}; s_malloc_args args = {task, 0, td, size};
UPCALL_SWITCH_STACK(task, &args, upcall_s_malloc_dyn); UPCALL_SWITCH_STACK(task, &args, upcall_s_malloc);
return args.retval; return args.retval;
} }

View File

@ -10,9 +10,9 @@ import lib::llvm::{type_names, ModuleRef, ValueRef, TypeRef};
type upcalls = type upcalls =
{_fail: ValueRef, {_fail: ValueRef,
trace: ValueRef, trace: ValueRef,
malloc_dyn: ValueRef, malloc: ValueRef,
free: ValueRef, free: ValueRef,
exchange_malloc_dyn: ValueRef, exchange_malloc: ValueRef,
exchange_free: ValueRef, exchange_free: ValueRef,
validate_box: ValueRef, validate_box: ValueRef,
mark: ValueRef, mark: ValueRef,
@ -55,14 +55,14 @@ fn declare_upcalls(targ_cfg: @session::config,
trace: dv("trace", [T_ptr(T_i8()), trace: dv("trace", [T_ptr(T_i8()),
T_ptr(T_i8()), T_ptr(T_i8()),
int_t]), int_t]),
malloc_dyn: malloc:
nothrow(d("malloc_dyn", nothrow(d("malloc",
[T_ptr(tydesc_type), int_t], [T_ptr(tydesc_type), int_t],
T_ptr(T_i8()))), T_ptr(T_i8()))),
free: free:
nothrow(dv("free", [T_ptr(T_i8())])), nothrow(dv("free", [T_ptr(T_i8())])),
exchange_malloc_dyn: exchange_malloc:
nothrow(d("exchange_malloc_dyn", nothrow(d("exchange_malloc",
[T_ptr(tydesc_type), int_t], [T_ptr(tydesc_type), int_t],
T_ptr(T_i8()))), T_ptr(T_i8()))),
exchange_free: exchange_free:

View File

@ -356,9 +356,9 @@ fn malloc_raw_dyn(bcx: block, t: ty::t, heap: heap,
let ccx = bcx.ccx(); let ccx = bcx.ccx();
let (mk_fn, upcall) = alt heap { let (mk_fn, upcall) = alt heap {
heap_shared { (ty::mk_imm_box, ccx.upcalls.malloc_dyn) } heap_shared { (ty::mk_imm_box, ccx.upcalls.malloc) }
heap_exchange { heap_exchange {
(ty::mk_imm_uniq, ccx.upcalls.exchange_malloc_dyn ) (ty::mk_imm_uniq, ccx.upcalls.exchange_malloc )
} }
}; };

View File

@ -545,7 +545,7 @@ fn make_opaque_cbox_take_glue(
let sz = Add(bcx, sz, shape::llsize_of(ccx, T_box_header(ccx))); let sz = Add(bcx, sz, shape::llsize_of(ccx, T_box_header(ccx)));
// Allocate memory, update original ptr, and copy existing data // Allocate memory, update original ptr, and copy existing data
let malloc = ccx.upcalls.exchange_malloc_dyn; let malloc = ccx.upcalls.exchange_malloc;
let cbox_out = Call(bcx, malloc, [tydesc, sz]); let cbox_out = Call(bcx, malloc, [tydesc, sz]);
let cbox_out = PointerCast(bcx, cbox_out, llopaquecboxty); let cbox_out = PointerCast(bcx, cbox_out, llopaquecboxty);
call_memmove(bcx, cbox_out, cbox_in, sz); call_memmove(bcx, cbox_out, cbox_in, sz);