mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-10 14:57:14 +00:00
make poison-on-free work, disable copying if borrowck is enabled
This commit is contained in:
parent
17d6b09d14
commit
be48cd87dc
@ -1,8 +1,7 @@
|
||||
|
||||
|
||||
#include "boxed_region.h"
|
||||
#include "rust_globals.h"
|
||||
#include "rust_task.h"
|
||||
#include "rust_env.h"
|
||||
|
||||
// #define DUMP_BOXED_REGION
|
||||
|
||||
@ -52,8 +51,15 @@ void boxed_region::free(rust_opaque_box *box) {
|
||||
if (box->prev) box->prev->next = box->next;
|
||||
if (box->next) box->next->prev = box->prev;
|
||||
if (live_allocs == box) live_allocs = box->next;
|
||||
|
||||
if (env->poison_on_free) {
|
||||
memset(box_body(box), 0xab, box->td->size);
|
||||
return;
|
||||
}
|
||||
|
||||
box->prev = NULL;
|
||||
box->next = NULL;
|
||||
box->td = NULL;
|
||||
|
||||
backing_region->free(box);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
struct type_desc;
|
||||
class memory_region;
|
||||
struct rust_opaque_box;
|
||||
struct rust_env;
|
||||
|
||||
/* Tracks the data allocated by a particular task in the '@' region.
|
||||
* Currently still relies on the standard malloc as a backing allocator, but
|
||||
@ -13,6 +14,7 @@ struct rust_opaque_box;
|
||||
* a type descr which describes the payload (what follows the header). */
|
||||
class boxed_region {
|
||||
private:
|
||||
rust_env *env;
|
||||
memory_region *backing_region;
|
||||
rust_opaque_box *live_allocs;
|
||||
|
||||
@ -24,8 +26,9 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
boxed_region(memory_region *br)
|
||||
: backing_region(br)
|
||||
boxed_region(rust_env *e, memory_region *br)
|
||||
: env(e)
|
||||
, backing_region(br)
|
||||
, live_allocs(NULL)
|
||||
{}
|
||||
|
||||
|
@ -27,7 +27,7 @@ rust_task::rust_task(rust_sched_loop *sched_loop, rust_task_state state,
|
||||
list_index(-1),
|
||||
rendezvous_ptr(0),
|
||||
local_region(&sched_loop->local_region),
|
||||
boxed(&local_region),
|
||||
boxed(sched_loop->kernel->env, &local_region),
|
||||
unwinding(false),
|
||||
propagate_failure(true),
|
||||
cc_counter(0),
|
||||
|
@ -48,7 +48,10 @@ type options =
|
||||
no_trans: bool,
|
||||
no_asm_comments: bool,
|
||||
debug_rustc: bool,
|
||||
borrowck: uint}; // 0=off,1=warn,2=err
|
||||
|
||||
// temporary hack: 0=off,1=warn,2=err --> if 2, alias is disabled
|
||||
borrowck: uint,
|
||||
};
|
||||
|
||||
type crate_metadata = {name: str, data: [u8]};
|
||||
|
||||
|
@ -159,6 +159,12 @@ fn visit_block(cx: @ctx, b: ast::blk, sc: scope, v: vt<scope>) {
|
||||
}
|
||||
|
||||
fn cant_copy(cx: ctx, b: binding) -> bool {
|
||||
|
||||
if cx.tcx.sess.opts.borrowck == 2u {
|
||||
// borrowck is enabled. disable alias analysis.
|
||||
ret false;
|
||||
}
|
||||
|
||||
alt b.copied {
|
||||
not_allowed { ret true; }
|
||||
copied { ret false; }
|
||||
|
Loading…
Reference in New Issue
Block a user