Skip to content
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

Revert change to stop zeroing the exchange heap #5047

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/libcore/private/exchange_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use c_malloc = libc::malloc;
use c_free = libc::free;
use managed::raw::{BoxHeaderRepr, BoxRepr};
use cast::transmute;
use ptr::null;
use ptr::{set_memory, null};
use intrinsic::TyDesc;

pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
Expand All @@ -25,6 +25,10 @@ pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
let p = c_malloc(total_size as size_t);
assert p.is_not_null();

// FIXME #4761: Would be very nice to not memset all allocations
let p: *mut u8 = transmute(p);
set_memory(p, 0, total_size);

// FIXME #3475: Converting between our two different tydesc types
let td: *TyDesc = transmute(td);

Expand Down
4 changes: 2 additions & 2 deletions src/libstd/uv_ll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,15 +1444,15 @@ pub mod test {
buf_base as uint,
buf_len as uint,
nread));
let bytes = vec::from_buf(buf_base, nread as uint);
let bytes = vec::from_buf(buf_base, buf_len);
let request_str = str::from_bytes(bytes);

let client_data = get_data_for_uv_handle(
client_stream_ptr as *libc::c_void) as *tcp_server_data;

let server_kill_msg = (*client_data).server_kill_msg;
let write_req = (*client_data).server_write_req;
if str::contains(request_str, server_kill_msg) {
if (str::contains(request_str, server_kill_msg)) {
log(debug, ~"SERVER: client req contains kill_msg!");
log(debug, ~"SERVER: sending response to client");
read_stop(client_stream_ptr);
Expand Down
13 changes: 10 additions & 3 deletions src/rt/memory_region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,8 @@ memory_region::realloc(void *mem, size_t orig_size) {
}

void *
memory_region::malloc(size_t size, const char *tag) {
# if RUSTRT_TRACK_ALLOCATIONS >= 1
memory_region::malloc(size_t size, const char *tag, bool zero) {
size_t old_size = size;
# endif
size += HEADER_SIZE;
alloc_header *mem = (alloc_header *)::malloc(size);
if (mem == NULL) {
Expand All @@ -145,9 +143,18 @@ memory_region::malloc(size_t size, const char *tag) {
void *data = get_data(mem);
claim_alloc(data);

if(zero) {
memset(data, 0, old_size);
}

return data;
}

void *
memory_region::calloc(size_t size, const char *tag) {
return malloc(size, tag, true);
}

memory_region::~memory_region() {
if (_synchronized) { _lock.lock(); }
if (_live_allocations == 0 && !_detailed_leaks) {
Expand Down
3 changes: 2 additions & 1 deletion src/rt/memory_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class memory_region {
public:
memory_region(rust_env *env, bool synchronized);
memory_region(memory_region *parent);
void *malloc(size_t size, const char *tag);
void *malloc(size_t size, const char *tag, bool zero = true);
void *calloc(size_t size, const char *tag);
void *realloc(void *mem, size_t size);
void free(void *mem);
~memory_region();
Expand Down
10 changes: 9 additions & 1 deletion src/rt/rust_exchange_alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@
uintptr_t exchange_count = 0;

void *
rust_exchange_alloc::malloc(size_t size) {
rust_exchange_alloc::malloc(size_t size, bool zero) {
void *value = ::malloc(size);
assert(value);
if (zero) {
memset(value, 0, size);
}

sync::increment(exchange_count);

return value;
}

void *
rust_exchange_alloc::calloc(size_t size) {
return this->malloc(size);
}

void *
rust_exchange_alloc::realloc(void *ptr, size_t size) {
void *new_ptr = ::realloc(ptr, size);
Expand Down
3 changes: 2 additions & 1 deletion src/rt/rust_exchange_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

class rust_exchange_alloc {
public:
void *malloc(size_t size);
void *malloc(size_t size, bool zero = true);
void *calloc(size_t size);
void *realloc(void *mem, size_t size);
void free(void *mem);
};
Expand Down
5 changes: 5 additions & 0 deletions src/rt/rust_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ rust_kernel::malloc(size_t size, const char *tag) {
return exchange_alloc.malloc(size);
}

void *
rust_kernel::calloc(size_t size, const char *tag) {
return exchange_alloc.calloc(size);
}

void *
rust_kernel::realloc(void *mem, size_t size) {
return exchange_alloc.realloc(mem, size);
Expand Down
1 change: 1 addition & 0 deletions src/rt/rust_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class rust_kernel {
void fatal(char const *fmt, ...);

void *malloc(size_t size, const char *tag);
void *calloc(size_t size, const char *tag);
void *realloc(void *mem, size_t size);
void free(void *mem);
rust_exchange_alloc *region() { return &exchange_alloc; }
Expand Down
4 changes: 2 additions & 2 deletions src/rt/rust_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ check_stack_canary(stk_seg *stk) {
stk_seg *
create_stack(memory_region *region, size_t sz) {
size_t total_sz = sizeof(stk_seg) + sz;
stk_seg *stk = (stk_seg *)region->malloc(total_sz, "stack");
stk_seg *stk = (stk_seg *)region->malloc(total_sz, "stack", false);
memset(stk, 0, sizeof(stk_seg));
stk->end = (uintptr_t) &stk->data[sz];
add_stack_canary(stk);
Expand All @@ -75,7 +75,7 @@ destroy_stack(memory_region *region, stk_seg *stk) {
stk_seg *
create_exchange_stack(rust_exchange_alloc *exchange, size_t sz) {
size_t total_sz = sizeof(stk_seg) + sz;
stk_seg *stk = (stk_seg *)exchange->malloc(total_sz);
stk_seg *stk = (stk_seg *)exchange->malloc(total_sz, false);
memset(stk, 0, sizeof(stk_seg));
stk->end = (uintptr_t) &stk->data[sz];
add_stack_canary(stk);
Expand Down
5 changes: 5 additions & 0 deletions src/rt/rust_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ rust_task::backtrace() {
#endif
}

void *
rust_task::calloc(size_t size, const char *tag) {
return local_region.calloc(size, tag);
}

size_t
rust_task::get_next_stack_size(size_t min, size_t current, size_t requested) {
LOG(this, mem, "calculating new stack size for 0x%" PRIxPTR, this);
Expand Down
22 changes: 22 additions & 0 deletions src/test/run-pass/rustdocvalgrind.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Regression test. This didn't valgrind after we stopped zeroing the exchange heap

pub struct VariantDoc {
desc: Option<~str>,
sig: Option<~str>
}

fn main() {
let variants = ~[
VariantDoc {
desc: None,
sig: None
}
];

let _vdoc = do vec::map(variants) |variant| {
VariantDoc {
desc: None,
.. copy *variant
}
};
}