Skip to content

Commit

Permalink
Merge pull request #2884 from elliottslaughter/rust-upcalls
Browse files Browse the repository at this point in the history
Move fail upcall into rust
  • Loading branch information
pcwalton committed Jul 23, 2012
2 parents 019a41b + d257382 commit 874b2f1
Show file tree
Hide file tree
Showing 14 changed files with 264 additions and 58 deletions.
7 changes: 7 additions & 0 deletions src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export either, option, result, iter;
export libc, os, io, run, rand, sys, unsafe, logging;
export arc, comm, task, future, pipes;
export extfmt;
// The test harness links against core, so don't include runtime in tests.
// FIXME (#2861): Uncomment this after snapshot gets updated.
//#[cfg(notest)]
export rt;
export tuple;
export to_str, to_bytes;
export dvec, dvec_iter;
Expand Down Expand Up @@ -206,6 +210,9 @@ mod unsafe;
// Exported but not part of the public interface

mod extfmt;
// The test harness links against core, so don't include runtime in tests.
#[cfg(notest)]
mod rt;


// For internal use, not exported
Expand Down
61 changes: 61 additions & 0 deletions src/libcore/rt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//! Runtime calls emitted by the compiler.

import libc::c_char;
import libc::c_void;
import libc::size_t;
import libc::uintptr_t;

type rust_task = c_void;

extern mod rustrt {
#[rust_stack]
fn rust_upcall_fail(expr: *c_char, file: *c_char, line: size_t);

#[rust_stack]
fn rust_upcall_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char;

#[rust_stack]
fn rust_upcall_exchange_free(ptr: *c_char);

#[rust_stack]
fn rust_upcall_malloc(td: *c_char, size: uintptr_t) -> *c_char;

#[rust_stack]
fn rust_upcall_free(ptr: *c_char);
}

// FIXME (#2861): This needs both the attribute, and the name prefixed with
// 'rt_', otherwise the compiler won't find it. To fix this, see
// gather_rust_rtcalls.
#[rt(fail)]
fn rt_fail(expr: *c_char, file: *c_char, line: size_t) {
rustrt::rust_upcall_fail(expr, file, line);
}

#[rt(exchange_malloc)]
fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
ret rustrt::rust_upcall_exchange_malloc(td, size);
}

#[rt(exchange_free)]
fn rt_exchange_free(ptr: *c_char) {
rustrt::rust_upcall_exchange_free(ptr);
}

#[rt(malloc)]
fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char {
ret rustrt::rust_upcall_malloc(td, size);
}

#[rt(free)]
fn rt_free(ptr: *c_char) {
rustrt::rust_upcall_free(ptr);
}

// Local Variables:
// mode: rust;
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:
42 changes: 42 additions & 0 deletions src/rt/rust_upcall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ upcall_fail(char const *expr,
UPCALL_SWITCH_STACK(task, &args, upcall_s_fail);
}

// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with
// autogenerated wrappers for upcall_fail. Remove this when we fully move away
// away from the C upcall path.
extern "C" CDECL void
rust_upcall_fail(char const *expr,
char const *file,
size_t line) {
upcall_fail(expr, file, line);
}

struct s_trace_args {
rust_task *task;
char const *msg;
Expand Down Expand Up @@ -160,6 +170,14 @@ upcall_exchange_malloc(type_desc *td, uintptr_t size) {
return args.retval;
}

// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with
// autogenerated wrappers for upcall_exchange_malloc. Remove this when we
// fully move away away from the C upcall path.
extern "C" CDECL uintptr_t
rust_upcall_exchange_malloc(type_desc *td, uintptr_t size) {
return upcall_exchange_malloc(td, size);
}

struct s_exchange_free_args {
rust_task *task;
void *ptr;
Expand All @@ -179,6 +197,14 @@ upcall_exchange_free(void *ptr) {
UPCALL_SWITCH_STACK(task, &args, upcall_s_exchange_free);
}

// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with
// autogenerated wrappers for upcall_exchange_free. Remove this when we fully
// move away away from the C upcall path.
extern "C" CDECL void
rust_upcall_exchange_free(void *ptr) {
return upcall_exchange_free(ptr);
}

/**********************************************************************
* Allocate an object in the task-local heap.
*/
Expand Down Expand Up @@ -220,6 +246,14 @@ upcall_malloc(type_desc *td, uintptr_t size) {
return args.retval;
}

// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with
// autogenerated wrappers for upcall_malloc. Remove this when we fully move
// away away from the C upcall path.
extern "C" CDECL uintptr_t
rust_upcall_malloc(type_desc *td, uintptr_t size) {
return upcall_malloc(td, size);
}

/**********************************************************************
* Called whenever an object in the task-local heap is freed.
*/
Expand Down Expand Up @@ -252,6 +286,14 @@ upcall_free(void* ptr) {
UPCALL_SWITCH_STACK(task, &args, upcall_s_free);
}

// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with
// autogenerated wrappers for upcall_free. Remove this when we fully move away
// away from the C upcall path.
extern "C" CDECL void
rust_upcall_free(void* ptr) {
upcall_free(ptr);
}

/**********************************************************************
* Sanity checks on boxes, insert when debugging possible
* use-after-free bugs. See maybe_validate_box() in trans.rs.
Expand Down
7 changes: 4 additions & 3 deletions src/rustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ fn build_configuration(sess: session, argv0: ~str, input: input) ->
// If the user wants a test runner, then add the test cfg
let gen_cfg =
{
if sess.opts.test && !attr::contains_name(user_cfg, ~"test")
{
if sess.opts.test && !attr::contains_name(user_cfg, ~"test") {
~[attr::mk_word_item(@~"test")]
} else { ~[] }
} else {
~[attr::mk_word_item(@~"notest")]
}
};
ret vec::append(vec::append(user_cfg, gen_cfg), default_cfg);
}
Expand Down
Loading

0 comments on commit 874b2f1

Please sign in to comment.