rt: Add RUST_DEBUG_MEM to rust_env to avoid races
This commit is contained in:
parent
ebba8b4e35
commit
63d18658c1
7 changed files with 63 additions and 7 deletions
|
@ -145,11 +145,7 @@ unsafe fn each_live_alloc(f: &fn(box: *mut BoxRepr, uniq: bool) -> bool) {
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn debug_mem() -> bool {
|
fn debug_mem() -> bool {
|
||||||
use os;
|
::rt::env::get().debug_mem
|
||||||
use libc;
|
|
||||||
do os::as_c_charp("RUST_DEBUG_MEM") |p| {
|
|
||||||
unsafe { libc::getenv(p) != null() }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
|
|
47
src/libcore/rt/env.rs
Normal file
47
src/libcore/rt/env.rs
Normal file
|
@ -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;
|
||||||
|
}
|
|
@ -45,3 +45,4 @@ mod work_queue;
|
||||||
mod stack;
|
mod stack;
|
||||||
mod context;
|
mod context;
|
||||||
mod thread;
|
mod thread;
|
||||||
|
pub mod env;
|
||||||
|
|
|
@ -876,6 +876,11 @@ rust_dbg_extern_identity_u8(char u) {
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" rust_env*
|
||||||
|
rust_get_rt_env() {
|
||||||
|
rust_task *task = rust_get_current_task();
|
||||||
|
return task->kernel->env;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#define DETAILED_LEAKS "DETAILED_LEAKS"
|
#define DETAILED_LEAKS "DETAILED_LEAKS"
|
||||||
#define RUST_SEED "RUST_SEED"
|
#define RUST_SEED "RUST_SEED"
|
||||||
#define RUST_POISON_ON_FREE "RUST_POISON_ON_FREE"
|
#define RUST_POISON_ON_FREE "RUST_POISON_ON_FREE"
|
||||||
|
#define RUST_DEBUG_MEM "RUST_DEBUG_MEM"
|
||||||
|
|
||||||
#if defined(__WIN32__)
|
#if defined(__WIN32__)
|
||||||
static int
|
static int
|
||||||
|
@ -128,6 +129,7 @@ load_env(int argc, char **argv) {
|
||||||
env->poison_on_free = getenv(RUST_POISON_ON_FREE) != NULL;
|
env->poison_on_free = getenv(RUST_POISON_ON_FREE) != NULL;
|
||||||
env->argc = argc;
|
env->argc = argc;
|
||||||
env->argv = argv;
|
env->argv = argv;
|
||||||
|
env->debug_mem = getenv(RUST_DEBUG_MEM) != NULL;
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,16 +14,20 @@
|
||||||
|
|
||||||
#include "rust_globals.h"
|
#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 {
|
struct rust_env {
|
||||||
size_t num_sched_threads;
|
size_t num_sched_threads;
|
||||||
size_t min_stack_size;
|
size_t min_stack_size;
|
||||||
size_t max_stack_size;
|
size_t max_stack_size;
|
||||||
char* logspec;
|
char* logspec;
|
||||||
bool detailed_leaks;
|
rust_bool detailed_leaks;
|
||||||
char* rust_seed;
|
char* rust_seed;
|
||||||
bool poison_on_free;
|
rust_bool poison_on_free;
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
|
rust_bool debug_mem;
|
||||||
};
|
};
|
||||||
|
|
||||||
rust_env* load_env(int argc, char **argv);
|
rust_env* load_env(int argc, char **argv);
|
||||||
|
|
|
@ -201,3 +201,4 @@ rust_dbg_extern_identity_u64
|
||||||
rust_dbg_extern_identity_TwoU64s
|
rust_dbg_extern_identity_TwoU64s
|
||||||
rust_dbg_extern_identity_double
|
rust_dbg_extern_identity_double
|
||||||
rust_dbg_extern_identity_u8
|
rust_dbg_extern_identity_u8
|
||||||
|
rust_get_rt_env
|
||||||
|
|
Loading…
Reference in a new issue