diff options
| author | Corey Richardson <corey@octayn.net> | 2014-01-18 17:50:49 -0500 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-01-24 22:30:01 -0800 |
| commit | bf5152f486a88ea106a820387d7d807ea99962af (patch) | |
| tree | 22774779486e84acd449da5fd0d8a669c64cdb31 /src/libgreen | |
| parent | 7499e2dd4596893980aaed0ca0558eec89ce47ad (diff) | |
| download | rust-bf5152f486a88ea106a820387d7d807ea99962af.tar.gz rust-bf5152f486a88ea106a820387d7d807ea99962af.zip | |
Fix zero-sized memory mapping
Diffstat (limited to 'src/libgreen')
| -rw-r--r-- | src/libgreen/coroutine.rs | 2 | ||||
| -rw-r--r-- | src/libgreen/stack.rs | 16 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/libgreen/coroutine.rs b/src/libgreen/coroutine.rs index 3d7dc58a1b2..c001d40a246 100644 --- a/src/libgreen/coroutine.rs +++ b/src/libgreen/coroutine.rs @@ -49,7 +49,7 @@ impl Coroutine { pub fn empty() -> Coroutine { Coroutine { - current_stack_segment: Stack::new(0), + current_stack_segment: unsafe { Stack::dummy_stack() }, saved_context: Context::empty() } } diff --git a/src/libgreen/stack.rs b/src/libgreen/stack.rs index a5d5174b91b..84c1572ad35 100644 --- a/src/libgreen/stack.rs +++ b/src/libgreen/stack.rs @@ -9,7 +9,8 @@ // except according to those terms. use std::rt::env::max_cached_stacks; -use std::os::{errno, page_size, MemoryMap, MapReadable, MapWritable, MapNonStandardFlags}; +use std::os::{errno, page_size, MemoryMap, MapReadable, MapWritable, + MapNonStandardFlags, MapVirtual}; #[cfg(not(windows))] use std::libc::{MAP_STACK, MAP_PRIVATE, MAP_ANON}; use std::libc::{c_uint, c_int, c_void, uintptr_t}; @@ -33,6 +34,8 @@ static STACK_FLAGS: c_int = MAP_PRIVATE | MAP_ANON; static STACK_FLAGS: c_int = 0; impl Stack { + /// Allocate a new stack of `size`. If size = 0, this will fail. Use + /// `dummy_stack` if you want a zero-sized stack. pub fn new(size: uint) -> Stack { // Map in a stack. Eventually we might be able to handle stack allocation failure, which // would fail to spawn the task. But there's not many sensible things to do on OOM. @@ -62,12 +65,21 @@ impl Stack { return stk; } + /// Create a 0-length stack which starts (and ends) at 0. + pub unsafe fn dummy_stack() -> Stack { + Stack { + buf: MemoryMap { data: 0 as *mut u8, len: 0, kind: MapVirtual }, + min_size: 0, + valgrind_id: 0 + } + } + /// Point to the low end of the allocated stack pub fn start(&self) -> *uint { self.buf.data as *uint } - /// Point one word beyond the high end of the allocated stack + /// Point one uint beyond the high end of the allocated stack pub fn end(&self) -> *uint { unsafe { self.buf.data.offset(self.buf.len as int) as *uint |
