Skip to content

Commit 874b2f1

Browse files
committed
Merge pull request #2884 from elliottslaughter/rust-upcalls
Move fail upcall into rust
2 parents 019a41b + d257382 commit 874b2f1

14 files changed

+264
-58
lines changed

src/libcore/core.rc

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export either, option, result, iter;
4141
export libc, os, io, run, rand, sys, unsafe, logging;
4242
export arc, comm, task, future, pipes;
4343
export extfmt;
44+
// The test harness links against core, so don't include runtime in tests.
45+
// FIXME (#2861): Uncomment this after snapshot gets updated.
46+
//#[cfg(notest)]
47+
export rt;
4448
export tuple;
4549
export to_str, to_bytes;
4650
export dvec, dvec_iter;
@@ -206,6 +210,9 @@ mod unsafe;
206210
// Exported but not part of the public interface
207211

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

210217

211218
// For internal use, not exported

src/libcore/rt.rs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//! Runtime calls emitted by the compiler.
2+
3+
import libc::c_char;
4+
import libc::c_void;
5+
import libc::size_t;
6+
import libc::uintptr_t;
7+
8+
type rust_task = c_void;
9+
10+
extern mod rustrt {
11+
#[rust_stack]
12+
fn rust_upcall_fail(expr: *c_char, file: *c_char, line: size_t);
13+
14+
#[rust_stack]
15+
fn rust_upcall_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char;
16+
17+
#[rust_stack]
18+
fn rust_upcall_exchange_free(ptr: *c_char);
19+
20+
#[rust_stack]
21+
fn rust_upcall_malloc(td: *c_char, size: uintptr_t) -> *c_char;
22+
23+
#[rust_stack]
24+
fn rust_upcall_free(ptr: *c_char);
25+
}
26+
27+
// FIXME (#2861): This needs both the attribute, and the name prefixed with
28+
// 'rt_', otherwise the compiler won't find it. To fix this, see
29+
// gather_rust_rtcalls.
30+
#[rt(fail)]
31+
fn rt_fail(expr: *c_char, file: *c_char, line: size_t) {
32+
rustrt::rust_upcall_fail(expr, file, line);
33+
}
34+
35+
#[rt(exchange_malloc)]
36+
fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
37+
ret rustrt::rust_upcall_exchange_malloc(td, size);
38+
}
39+
40+
#[rt(exchange_free)]
41+
fn rt_exchange_free(ptr: *c_char) {
42+
rustrt::rust_upcall_exchange_free(ptr);
43+
}
44+
45+
#[rt(malloc)]
46+
fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char {
47+
ret rustrt::rust_upcall_malloc(td, size);
48+
}
49+
50+
#[rt(free)]
51+
fn rt_free(ptr: *c_char) {
52+
rustrt::rust_upcall_free(ptr);
53+
}
54+
55+
// Local Variables:
56+
// mode: rust;
57+
// fill-column: 78;
58+
// indent-tabs-mode: nil
59+
// c-basic-offset: 4
60+
// buffer-file-coding-system: utf-8-unix
61+
// End:

src/rt/rust_upcall.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ upcall_fail(char const *expr,
9898
UPCALL_SWITCH_STACK(task, &args, upcall_s_fail);
9999
}
100100

101+
// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with
102+
// autogenerated wrappers for upcall_fail. Remove this when we fully move away
103+
// away from the C upcall path.
104+
extern "C" CDECL void
105+
rust_upcall_fail(char const *expr,
106+
char const *file,
107+
size_t line) {
108+
upcall_fail(expr, file, line);
109+
}
110+
101111
struct s_trace_args {
102112
rust_task *task;
103113
char const *msg;
@@ -160,6 +170,14 @@ upcall_exchange_malloc(type_desc *td, uintptr_t size) {
160170
return args.retval;
161171
}
162172

173+
// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with
174+
// autogenerated wrappers for upcall_exchange_malloc. Remove this when we
175+
// fully move away away from the C upcall path.
176+
extern "C" CDECL uintptr_t
177+
rust_upcall_exchange_malloc(type_desc *td, uintptr_t size) {
178+
return upcall_exchange_malloc(td, size);
179+
}
180+
163181
struct s_exchange_free_args {
164182
rust_task *task;
165183
void *ptr;
@@ -179,6 +197,14 @@ upcall_exchange_free(void *ptr) {
179197
UPCALL_SWITCH_STACK(task, &args, upcall_s_exchange_free);
180198
}
181199

200+
// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with
201+
// autogenerated wrappers for upcall_exchange_free. Remove this when we fully
202+
// move away away from the C upcall path.
203+
extern "C" CDECL void
204+
rust_upcall_exchange_free(void *ptr) {
205+
return upcall_exchange_free(ptr);
206+
}
207+
182208
/**********************************************************************
183209
* Allocate an object in the task-local heap.
184210
*/
@@ -220,6 +246,14 @@ upcall_malloc(type_desc *td, uintptr_t size) {
220246
return args.retval;
221247
}
222248

249+
// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with
250+
// autogenerated wrappers for upcall_malloc. Remove this when we fully move
251+
// away away from the C upcall path.
252+
extern "C" CDECL uintptr_t
253+
rust_upcall_malloc(type_desc *td, uintptr_t size) {
254+
return upcall_malloc(td, size);
255+
}
256+
223257
/**********************************************************************
224258
* Called whenever an object in the task-local heap is freed.
225259
*/
@@ -252,6 +286,14 @@ upcall_free(void* ptr) {
252286
UPCALL_SWITCH_STACK(task, &args, upcall_s_free);
253287
}
254288

289+
// FIXME (#2861): Alias used by libcore/rt.rs to avoid naming conflicts with
290+
// autogenerated wrappers for upcall_free. Remove this when we fully move away
291+
// away from the C upcall path.
292+
extern "C" CDECL void
293+
rust_upcall_free(void* ptr) {
294+
upcall_free(ptr);
295+
}
296+
255297
/**********************************************************************
256298
* Sanity checks on boxes, insert when debugging possible
257299
* use-after-free bugs. See maybe_validate_box() in trans.rs.

src/rustc/driver/driver.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ fn build_configuration(sess: session, argv0: ~str, input: input) ->
6969
// If the user wants a test runner, then add the test cfg
7070
let gen_cfg =
7171
{
72-
if sess.opts.test && !attr::contains_name(user_cfg, ~"test")
73-
{
72+
if sess.opts.test && !attr::contains_name(user_cfg, ~"test") {
7473
~[attr::mk_word_item(@~"test")]
75-
} else { ~[] }
74+
} else {
75+
~[attr::mk_word_item(@~"notest")]
76+
}
7677
};
7778
ret vec::append(vec::append(user_cfg, gen_cfg), default_cfg);
7879
}

0 commit comments

Comments
 (0)