Skip to content

Commit 8c43ce6

Browse files
committed
Bring in the line-length police
1 parent bf5152f commit 8c43ce6

File tree

2 files changed

+114
-84
lines changed

2 files changed

+114
-84
lines changed

src/libgreen/stack.rs

+35-33
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,46 @@
1010

1111
use std::rt::env::max_cached_stacks;
1212
use std::os::{errno, page_size, MemoryMap, MapReadable, MapWritable,
13-
MapNonStandardFlags, MapVirtual};
14-
#[cfg(not(windows))]
15-
use std::libc::{MAP_STACK, MAP_PRIVATE, MAP_ANON};
16-
use std::libc::{c_uint, c_int, c_void, uintptr_t};
13+
MapNonStandardFlags, MapVirtual};
14+
use std::libc;
1715

1816
/// A task's stack. The name "Stack" is a vestige of segmented stacks.
1917
pub struct Stack {
2018
priv buf: MemoryMap,
2119
priv min_size: uint,
22-
priv valgrind_id: c_uint,
20+
priv valgrind_id: libc::c_uint,
2321
}
2422

2523
// Try to use MAP_STACK on platforms that support it (it's what we're doing
2624
// anyway), but some platforms don't support it at all. For example, it appears
2725
// that there's a bug in freebsd that MAP_STACK implies MAP_FIXED (so it always
2826
// fails): http://lists.freebsd.org/pipermail/freebsd-bugs/2011-July/044840.html
2927
#[cfg(not(windows), not(target_os = "freebsd"))]
30-
static STACK_FLAGS: c_int = MAP_STACK | MAP_PRIVATE | MAP_ANON;
28+
static STACK_FLAGS: libc::c_int = libc::MAP_STACK | libc::MAP_PRIVATE |
29+
libc::MAP_ANON;
3130
#[cfg(target_os = "freebsd")]
32-
static STACK_FLAGS: c_int = MAP_PRIVATE | MAP_ANON;
31+
static STACK_FLAGS: libc::c_int = libc::MAP_PRIVATE | libc::MAP_ANON;
3332
#[cfg(windows)]
34-
static STACK_FLAGS: c_int = 0;
33+
static STACK_FLAGS: libc::c_int = 0;
3534

3635
impl Stack {
3736
/// Allocate a new stack of `size`. If size = 0, this will fail. Use
3837
/// `dummy_stack` if you want a zero-sized stack.
3938
pub fn new(size: uint) -> Stack {
40-
// Map in a stack. Eventually we might be able to handle stack allocation failure, which
41-
// would fail to spawn the task. But there's not many sensible things to do on OOM.
42-
// Failure seems fine (and is what the old stack allocation did).
39+
// Map in a stack. Eventually we might be able to handle stack
40+
// allocation failure, which would fail to spawn the task. But there's
41+
// not many sensible things to do on OOM. Failure seems fine (and is
42+
// what the old stack allocation did).
4343
let stack = match MemoryMap::new(size, [MapReadable, MapWritable,
4444
MapNonStandardFlags(STACK_FLAGS)]) {
4545
Ok(map) => map,
46-
Err(e) => fail!("Creating memory map for stack of size {} failed: {}", size, e)
46+
Err(e) => fail!("mmap for stack of size {} failed: {}", size, e)
4747
};
4848

49-
// Change the last page to be inaccessible. This is to provide safety; when an FFI
50-
// function overflows it will (hopefully) hit this guard page. It isn't guaranteed, but
51-
// that's why FFI is unsafe. buf.data is guaranteed to be aligned properly.
49+
// Change the last page to be inaccessible. This is to provide safety;
50+
// when an FFI function overflows it will (hopefully) hit this guard
51+
// page. It isn't guaranteed, but that's why FFI is unsafe. buf.data is
52+
// guaranteed to be aligned properly.
5253
if !protect_last_page(&stack) {
5354
fail!("Could not memory-protect guard page. stack={:?}, errno={}",
5455
stack, errno());
@@ -61,7 +62,9 @@ impl Stack {
6162
};
6263

6364
// XXX: Using the FFI to call a C macro. Slow
64-
stk.valgrind_id = unsafe { rust_valgrind_stack_register(stk.start(), stk.end()) };
65+
stk.valgrind_id = unsafe {
66+
rust_valgrind_stack_register(stk.start(), stk.end())
67+
};
6568
return stk;
6669
}
6770

@@ -87,30 +90,27 @@ impl Stack {
8790
}
8891
}
8992

90-
// These use ToPrimitive so that we never need to worry about the sizes of whatever types these
91-
// (which we would with scalar casts). It's either a wrapper for a scalar cast or failure: fast, or
92-
// will fail during compilation.
9393
#[cfg(unix)]
9494
fn protect_last_page(stack: &MemoryMap) -> bool {
95-
use std::libc::{mprotect, PROT_NONE, size_t};
9695
unsafe {
97-
// This may seem backwards: the start of the segment is the last page? Yes! The stack grows
98-
// from higher addresses (the end of the allocated block) to lower addresses (the start of
99-
// the allocated block).
100-
let last_page = stack.data as *c_void;
101-
mprotect(last_page, page_size() as size_t, PROT_NONE) != -1
96+
// This may seem backwards: the start of the segment is the last page?
97+
// Yes! The stack grows from higher addresses (the end of the allocated
98+
// block) to lower addresses (the start of the allocated block).
99+
let last_page = stack.data as *libc::c_void;
100+
libc::mprotect(last_page, page_size() as libc::size_t,
101+
libc::PROT_NONE) != -1
102102
}
103103
}
104104

105105
#[cfg(windows)]
106106
fn protect_last_page(stack: &MemoryMap) -> bool {
107-
use std::libc::{VirtualProtect, PAGE_NOACCESS, SIZE_T, LPDWORD, DWORD};
108107
unsafe {
109108
// see above
110-
let last_page = stack.data as *mut c_void;
111-
let mut old_prot: DWORD = 0;
112-
VirtualProtect(last_page, page_size() as SIZE_T, PAGE_NOACCESS,
113-
&mut old_prot as LPDWORD) != 0
109+
let last_page = stack.data as *mut libc::c_void;
110+
let mut old_prot: libc::DWORD = 0;
111+
libc::VirtualProtect(last_page, page_size() as libc::SIZE_T,
112+
libc::PAGE_NOACCESS,
113+
&mut old_prot as libc::LPDWORD) != 0
114114
}
115115
}
116116

@@ -124,7 +124,8 @@ impl Drop for Stack {
124124
}
125125

126126
pub struct StackPool {
127-
// Ideally this would be some datastructure that preserved ordering on Stack.min_size.
127+
// Ideally this would be some datastructure that preserved ordering on
128+
// Stack.min_size.
128129
priv stacks: ~[Stack],
129130
}
130131

@@ -151,6 +152,7 @@ impl StackPool {
151152
}
152153

153154
extern {
154-
fn rust_valgrind_stack_register(start: *uintptr_t, end: *uintptr_t) -> c_uint;
155-
fn rust_valgrind_stack_deregister(id: c_uint);
155+
fn rust_valgrind_stack_register(start: *libc::uintptr_t,
156+
end: *libc::uintptr_t) -> libc::c_uint;
157+
fn rust_valgrind_stack_deregister(id: libc::c_uint);
156158
}

0 commit comments

Comments
 (0)