Skip to content

Commit b74e625

Browse files
committed
Add a morestack_addr (temporary) intrinsic
1 parent 9bb97d7 commit b74e625

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/rustc/middle/trans/foreign.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,16 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
984984
lv_temporary),
985985
arg_vals(~[frameaddress_val]), ignore);
986986
}
987+
~"morestack_addr" => {
988+
// XXX This is a hack to grab the address of this particular
989+
// native function. There should be a general in-language
990+
// way to do this
991+
let llfty = type_of_fn(bcx.ccx(), ~[], ty::mk_nil(bcx.tcx()));
992+
let morestack_addr = decl_cdecl_fn(
993+
bcx.ccx().llmod, ~"__morestack", llfty);
994+
let morestack_addr = PointerCast(bcx, morestack_addr, T_ptr(T_nil()));
995+
Store(bcx, morestack_addr, fcx.llretptr);
996+
}
987997
_ => {
988998
// Could we make this an enum rather than a string? does it get
989999
// checked earlier?

src/rustc/middle/typeck/check.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,6 +2562,9 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
25622562
});
25632563
(0u, ~[arg(ast::by_ref, fty)], ty::mk_nil(tcx))
25642564
}
2565+
~"morestack_addr" => {
2566+
(0u, ~[], ty::mk_nil_ptr(tcx))
2567+
}
25652568
other => {
25662569
tcx.sess.span_err(it.span, ~"unrecognized intrinsic function: `" +
25672570
other + ~"`");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#[nolink]
2+
#[abi = "rust-intrinsic"]
3+
extern mod rusti {
4+
fn morestack_addr() -> *();
5+
}
6+
7+
fn main() {
8+
let addr = rusti::morestack_addr();
9+
assert addr.is_not_null();
10+
error!("%?", addr);
11+
}

0 commit comments

Comments
 (0)