Skip to content

rt: Add RUST_DEBUG_MEM to rust_env to avoid races #5342

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 1 commit into from
Mar 16, 2013
Merged
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: 1 addition & 5 deletions src/libcore/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@ unsafe fn each_live_alloc(f: &fn(box: *mut BoxRepr, uniq: bool) -> bool) {

#[cfg(unix)]
fn debug_mem() -> bool {
use os;
use libc;
do os::as_c_charp("RUST_DEBUG_MEM") |p| {
unsafe { libc::getenv(p) != null() }
}
::rt::env::get().debug_mem
}

#[cfg(windows)]
Expand Down
47 changes: 47 additions & 0 deletions src/libcore/rt/env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Runtime environment settings

use libc::{size_t, c_char, c_int};

pub struct Environment {
/// The number of threads to use by default
num_sched_threads: size_t,
/// The minimum size of a stack segment
min_stack_size: size_t,
/// The maximum amount of total stack per task before aborting
max_stack_size: size_t,
/// The default logging configuration
logspec: *c_char,
/// Record and report detailed information about memory leaks
detailed_leaks: bool,
/// Seed the random number generator
rust_seed: *c_char,
/// Poison allocations on free
poison_on_free: bool,
/// The argc value passed to main
argc: c_int,
/// The argv value passed to main
argv: **c_char,
/// Print GC debugging info
debug_mem: bool
}

/// Get the global environment settings
/// # Safety Note
/// This will abort the process if run outside of task context
pub fn get() -> &Environment {
unsafe { rust_get_rt_env() }
}

extern {
fn rust_get_rt_env() -> &Environment;
}
1 change: 1 addition & 0 deletions src/libcore/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ mod work_queue;
mod stack;
mod context;
mod thread;
pub mod env;
5 changes: 5 additions & 0 deletions src/rt/rust_builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,11 @@ rust_dbg_extern_identity_u8(char u) {
return u;
}

extern "C" rust_env*
rust_get_rt_env() {
rust_task *task = rust_get_current_task();
return task->kernel->env;
}

//
// Local Variables:
Expand Down
2 changes: 2 additions & 0 deletions src/rt/rust_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define DETAILED_LEAKS "DETAILED_LEAKS"
#define RUST_SEED "RUST_SEED"
#define RUST_POISON_ON_FREE "RUST_POISON_ON_FREE"
#define RUST_DEBUG_MEM "RUST_DEBUG_MEM"

#if defined(__WIN32__)
static int
Expand Down Expand Up @@ -128,6 +129,7 @@ load_env(int argc, char **argv) {
env->poison_on_free = getenv(RUST_POISON_ON_FREE) != NULL;
env->argc = argc;
env->argv = argv;
env->debug_mem = getenv(RUST_DEBUG_MEM) != NULL;
return env;
}

Expand Down
8 changes: 6 additions & 2 deletions src/rt/rust_env.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@

#include "rust_globals.h"

// Avoiding 'bool' type here since I'm not sure it has a standard size
typedef uint8_t rust_bool;

struct rust_env {
size_t num_sched_threads;
size_t min_stack_size;
size_t max_stack_size;
char* logspec;
bool detailed_leaks;
rust_bool detailed_leaks;
char* rust_seed;
bool poison_on_free;
rust_bool poison_on_free;
int argc;
char **argv;
rust_bool debug_mem;
};

rust_env* load_env(int argc, char **argv);
Expand Down
1 change: 1 addition & 0 deletions src/rt/rustrt.def.in
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,4 @@ rust_dbg_extern_identity_u64
rust_dbg_extern_identity_TwoU64s
rust_dbg_extern_identity_double
rust_dbg_extern_identity_u8
rust_get_rt_env