Skip to content

Commit 0545e4a

Browse files
committed
Support [rust_stack] annotation on native functions (crudely)
1 parent 894b746 commit 0545e4a

File tree

6 files changed

+53
-31
lines changed

6 files changed

+53
-31
lines changed

src/libcore/comm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ fn recv_<T: send>(p: *rust_port) -> T {
141141
let yieldp = ptr::addr_of(yield);
142142
let mut res;
143143
res = rusti::init::<T>();
144-
log(debug, ptr::addr_of(res));
145144
rustrt::port_recv(ptr::addr_of(res) as *uint, p, yieldp);
146145

147146
if yield != 0u {

src/libcore/ptr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import libc::c_void;
1313
#[nolink]
1414
#[abi = "cdecl"]
1515
native mod libc_ {
16+
#[rust_stack]
1617
fn memcpy(dest: *c_void, src: *c_void, n: libc::size_t) -> *c_void;
18+
#[rust_stack]
1719
fn memmove(dest: *c_void, src: *c_void, n: libc::size_t) -> *c_void;
1820
}
1921

src/libcore/task.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ fn yield() {
442442

443443
let task_ = rustrt::rust_get_task();
444444
let mut killed = false;
445-
rusti::task_yield(task_, killed);
445+
rustrt::rust_task_yield(task_, killed);
446446
if killed && !failing() {
447447
fail "killed";
448448
}
@@ -533,12 +533,10 @@ fn spawn_raw(opts: task_opts, +f: fn~()) unsafe {
533533

534534
}
535535

536-
#[abi = "rust-intrinsic"]
537-
native mod rusti {
538-
fn task_yield(task: *rust_task, &killed: bool);
539-
}
540-
541536
native mod rustrt {
537+
#[rust_stack]
538+
fn rust_task_yield(task: *rust_task, &killed: bool);
539+
542540
fn rust_get_sched_id() -> sched_id;
543541
fn rust_new_sched(num_threads: libc::uintptr_t) -> sched_id;
544542

src/libcore/unsafe.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,4 @@ mod tests {
3434
fn test_reinterpret_cast() unsafe {
3535
assert reinterpret_cast(1) == 1u;
3636
}
37-
38-
#[test]
39-
#[should_fail]
40-
#[ignore(cfg(target_os = "win32"))]
41-
fn test_reinterpret_cast_wrong_size() unsafe {
42-
let _i: uint = reinterpret_cast(0u8);
43-
}
4437
}

src/rustc/middle/trans/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,7 +2625,7 @@ enum call_args {
26252625
// - new_fn_ctxt
26262626
// - trans_args
26272627
fn trans_args(cx: block, llenv: ValueRef, args: call_args, fn_ty: ty::t,
2628-
dest: dest, generic_intrinsic: bool)
2628+
dest: dest, always_valid_retptr: bool)
26292629
-> {bcx: block, args: [ValueRef], retslot: ValueRef} {
26302630
let _icx = cx.insn_ctxt("trans_args");
26312631
let mut temp_cleanups = [];
@@ -2639,7 +2639,7 @@ fn trans_args(cx: block, llenv: ValueRef, args: call_args, fn_ty: ty::t,
26392639
// Arg 0: Output pointer.
26402640
let llretslot = alt dest {
26412641
ignore {
2642-
if ty::type_is_nil(retty) && !generic_intrinsic {
2642+
if ty::type_is_nil(retty) && !always_valid_retptr {
26432643
llvm::LLVMGetUndef(T_ptr(T_nil()))
26442644
} else {
26452645
let {bcx: cx, val} = alloc_ty(bcx, retty);

src/rustc/middle/trans/native.rs

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -652,24 +652,50 @@ fn trans_native_mod(ccx: @crate_ctxt,
652652
}
653653

654654
let lname = link_name(native_item);
655-
// Declare the "prototype" for the base function F:
656-
let llbasefn = alt tys.x86_64_tys {
657-
some(x86_64) {
658-
decl_x86_64_fn(x86_64) {|fnty|
659-
decl_fn(ccx.llmod, lname, cc, fnty)
660-
}
661-
}
662-
_ {
663-
let llbasefnty = T_fn(tys.arg_tys, tys.ret_ty);
664-
decl_fn(ccx.llmod, lname, cc, llbasefnty)
665-
}
666-
};
655+
let llbasefn = base_fn(ccx, lname, tys, cc);
667656
// Name the shim function
668657
let shim_name = lname + "__c_stack_shim";
669658
ret build_shim_fn_(ccx, shim_name, llbasefn, tys, cc,
670659
build_args, build_ret);
671660
}
672661

662+
fn base_fn(ccx: @crate_ctxt, lname: str, tys: @c_stack_tys,
663+
cc: lib::llvm::CallConv) -> ValueRef {
664+
// Declare the "prototype" for the base function F:
665+
alt tys.x86_64_tys {
666+
some(x86_64) {
667+
decl_x86_64_fn(x86_64) {|fnty|
668+
decl_fn(ccx.llmod, lname, cc, fnty)
669+
}
670+
}
671+
_ {
672+
let llbasefnty = T_fn(tys.arg_tys, tys.ret_ty);
673+
decl_fn(ccx.llmod, lname, cc, llbasefnty)
674+
}
675+
}
676+
}
677+
678+
// FIXME this is very shaky and probably gets ABIs wrong all over
679+
// the place
680+
fn build_direct_fn(ccx: @crate_ctxt, decl: ValueRef,
681+
item: @ast::native_item, tys: @c_stack_tys,
682+
cc: lib::llvm::CallConv) {
683+
let fcx = new_fn_ctxt(ccx, [], decl, none);
684+
let bcx = top_scope_block(fcx, none), lltop = bcx.llbb;
685+
let llbasefn = base_fn(ccx, link_name(item), tys, cc);
686+
let ty = ty::lookup_item_type(ccx.tcx,
687+
ast_util::local_def(item.id)).ty;
688+
let args = vec::from_fn(ty::ty_fn_args(ty).len(), {|i|
689+
get_param(decl, i + first_real_arg)
690+
});
691+
let retval = Call(bcx, llbasefn, args);
692+
if !ty::type_is_nil(ty::ty_fn_ret(ty)) {
693+
Store(bcx, retval, fcx.llretptr);
694+
}
695+
build_return(bcx);
696+
finish_fn(fcx, lltop);
697+
}
698+
673699
fn build_wrap_fn(ccx: @crate_ctxt,
674700
tys: @c_stack_tys,
675701
llshimfn: ValueRef,
@@ -717,10 +743,14 @@ fn trans_native_mod(ccx: @crate_ctxt,
717743
alt native_item.node {
718744
ast::native_item_fn(fn_decl, _) {
719745
let id = native_item.id;
720-
let tys = c_stack_tys(ccx, id);
721746
let llwrapfn = get_item_val(ccx, id);
722-
let llshimfn = build_shim_fn(ccx, native_item, tys, cc);
723-
build_wrap_fn(ccx, tys, llshimfn, llwrapfn);
747+
let tys = c_stack_tys(ccx, id);
748+
if attr::attrs_contains_name(native_item.attrs, "rust_stack") {
749+
build_direct_fn(ccx, llwrapfn, native_item, tys, cc);
750+
} else {
751+
let llshimfn = build_shim_fn(ccx, native_item, tys, cc);
752+
build_wrap_fn(ccx, tys, llshimfn, llwrapfn);
753+
}
724754
}
725755
}
726756
}

0 commit comments

Comments
 (0)