Skip to content

Move fail upcall into rust #2884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/libcore/core.rc
Original file line number Diff line number Diff line change
@@ -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;
@@ -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
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
@@ -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;
@@ -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;
@@ -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.
*/
@@ -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.
*/
@@ -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.
7 changes: 4 additions & 3 deletions src/rustc/driver/driver.rs
Original file line number Diff line number Diff line change
@@ -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);
}
Loading