Skip to content

Commit be48cd8

Browse files
committed
make poison-on-free work, disable copying if borrowck is enabled
1 parent 17d6b09 commit be48cd8

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

src/rt/boxed_region.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
2-
31
#include "boxed_region.h"
42
#include "rust_globals.h"
53
#include "rust_task.h"
4+
#include "rust_env.h"
65

76
// #define DUMP_BOXED_REGION
87

@@ -52,8 +51,15 @@ void boxed_region::free(rust_opaque_box *box) {
5251
if (box->prev) box->prev->next = box->next;
5352
if (box->next) box->next->prev = box->prev;
5453
if (live_allocs == box) live_allocs = box->next;
54+
55+
if (env->poison_on_free) {
56+
memset(box_body(box), 0xab, box->td->size);
57+
return;
58+
}
59+
5560
box->prev = NULL;
5661
box->next = NULL;
5762
box->td = NULL;
63+
5864
backing_region->free(box);
5965
}

src/rt/boxed_region.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
struct type_desc;
77
class memory_region;
88
struct rust_opaque_box;
9+
struct rust_env;
910

1011
/* Tracks the data allocated by a particular task in the '@' region.
1112
* Currently still relies on the standard malloc as a backing allocator, but
1213
* this could be improved someday if necessary. Every allocation must provide
1314
* a type descr which describes the payload (what follows the header). */
1415
class boxed_region {
1516
private:
17+
rust_env *env;
1618
memory_region *backing_region;
1719
rust_opaque_box *live_allocs;
1820

@@ -24,8 +26,9 @@ class boxed_region {
2426
}
2527

2628
public:
27-
boxed_region(memory_region *br)
28-
: backing_region(br)
29+
boxed_region(rust_env *e, memory_region *br)
30+
: env(e)
31+
, backing_region(br)
2932
, live_allocs(NULL)
3033
{}
3134

src/rt/rust_task.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ rust_task::rust_task(rust_sched_loop *sched_loop, rust_task_state state,
2727
list_index(-1),
2828
rendezvous_ptr(0),
2929
local_region(&sched_loop->local_region),
30-
boxed(&local_region),
30+
boxed(sched_loop->kernel->env, &local_region),
3131
unwinding(false),
3232
propagate_failure(true),
3333
cc_counter(0),

src/rustc/driver/session.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ type options =
4848
no_trans: bool,
4949
no_asm_comments: bool,
5050
debug_rustc: bool,
51-
borrowck: uint}; // 0=off,1=warn,2=err
51+
52+
// temporary hack: 0=off,1=warn,2=err --> if 2, alias is disabled
53+
borrowck: uint,
54+
};
5255

5356
type crate_metadata = {name: str, data: [u8]};
5457

src/rustc/middle/alias.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ fn visit_block(cx: @ctx, b: ast::blk, sc: scope, v: vt<scope>) {
159159
}
160160

161161
fn cant_copy(cx: ctx, b: binding) -> bool {
162+
163+
if cx.tcx.sess.opts.borrowck == 2u {
164+
// borrowck is enabled. disable alias analysis.
165+
ret false;
166+
}
167+
162168
alt b.copied {
163169
not_allowed { ret true; }
164170
copied { ret false; }

0 commit comments

Comments
 (0)