Skip to content

some mmap-related tweaks in the libc crate #14984

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
Jun 18, 2014
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
2 changes: 1 addition & 1 deletion src/libgreen/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn protect_last_page(stack: &MemoryMap) -> bool {
// This may seem backwards: the start of the segment is the last page?
// Yes! The stack grows from higher addresses (the end of the allocated
// block) to lower addresses (the start of the allocated block).
let last_page = stack.data as *libc::c_void;
let last_page = stack.data as *mut libc::c_void;
libc::mprotect(last_page, page_size() as libc::size_t,
libc::PROT_NONE) != -1
}
Expand Down
20 changes: 10 additions & 10 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,7 @@ pub mod consts {
pub static MAP_FIXED : c_int = 0x0010;
pub static MAP_ANON : c_int = 0x0020;

pub static MAP_FAILED : *c_void = -1 as *c_void;
pub static MAP_FAILED : *mut c_void = -1 as *mut c_void;

pub static MCL_CURRENT : c_int = 0x0001;
pub static MCL_FUTURE : c_int = 0x0002;
Expand Down Expand Up @@ -2268,7 +2268,7 @@ pub mod consts {
pub static MAP_FIXED : c_int = 0x0010;
pub static MAP_ANON : c_int = 0x0800;

pub static MAP_FAILED : *c_void = -1 as *c_void;
pub static MAP_FAILED : *mut c_void = -1 as *mut c_void;

pub static MCL_CURRENT : c_int = 0x0001;
pub static MCL_FUTURE : c_int = 0x0002;
Expand Down Expand Up @@ -2804,7 +2804,7 @@ pub mod consts {
pub static MAP_FIXED : c_int = 0x0010;
pub static MAP_ANON : c_int = 0x1000;

pub static MAP_FAILED : *c_void = -1 as *c_void;
pub static MAP_FAILED : *mut c_void = -1 as *mut c_void;

pub static MCL_CURRENT : c_int = 0x0001;
pub static MCL_FUTURE : c_int = 0x0002;
Expand Down Expand Up @@ -3192,7 +3192,7 @@ pub mod consts {
pub static MAP_FIXED : c_int = 0x0010;
pub static MAP_ANON : c_int = 0x1000;

pub static MAP_FAILED : *c_void = -1 as *c_void;
pub static MAP_FAILED : *mut c_void = -1 as *mut c_void;

pub static MCL_CURRENT : c_int = 0x0001;
pub static MCL_FUTURE : c_int = 0x0002;
Expand Down Expand Up @@ -3951,19 +3951,19 @@ pub mod funcs {
pub fn mlockall(flags: c_int) -> c_int;
pub fn munlockall() -> c_int;

pub fn mmap(addr: *c_void,
pub fn mmap(addr: *mut c_void,
len: size_t,
prot: c_int,
flags: c_int,
fd: c_int,
offset: off_t)
-> *mut c_void;
pub fn munmap(addr: *c_void, len: size_t) -> c_int;
pub fn munmap(addr: *mut c_void, len: size_t) -> c_int;

pub fn mprotect(addr: *c_void, len: size_t, prot: c_int)
pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int)
-> c_int;

pub fn msync(addr: *c_void, len: size_t, flags: c_int)
pub fn msync(addr: *mut c_void, len: size_t, flags: c_int)
-> c_int;
pub fn shm_open(name: *c_char, oflag: c_int, mode: mode_t)
-> c_int;
Expand Down Expand Up @@ -4208,9 +4208,9 @@ pub mod funcs {

extern {
pub fn getdtablesize() -> c_int;
pub fn madvise(addr: *c_void, len: size_t, advice: c_int)
pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int)
-> c_int;
pub fn mincore(addr: *c_void, len: size_t, vec: *c_uchar)
pub fn mincore(addr: *mut c_void, len: size_t, vec: *mut c_uchar)
-> c_int;
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,6 @@ impl MemoryMap {
/// `ErrZeroLength`.
pub fn new(min_len: uint, options: &[MapOption]) -> Result<MemoryMap, MapError> {
use libc::off_t;
use cmp::Equiv;

if min_len == 0 {
return Err(ErrZeroLength)
Expand Down Expand Up @@ -1371,10 +1370,10 @@ impl MemoryMap {
if fd == -1 && !custom_flags { flags |= libc::MAP_ANON; }

let r = unsafe {
libc::mmap(addr as *c_void, len as libc::size_t, prot, flags, fd,
offset)
libc::mmap(addr as *mut c_void, len as libc::size_t, prot, flags,
fd, offset)
};
if r.equiv(&libc::MAP_FAILED) {
if r == libc::MAP_FAILED {
Err(match errno() as c_int {
libc::EACCES => ErrFdNotAvail,
libc::EBADF => ErrInvalidFd,
Expand Down Expand Up @@ -1410,8 +1409,8 @@ impl Drop for MemoryMap {
if self.len == 0 { /* workaround for dummy_stack */ return; }

unsafe {
// FIXME: what to do if this fails?
let _ = libc::munmap(self.data as *c_void, self.len as libc::size_t);
// `munmap` only fails due to logic errors
libc::munmap(self.data as *mut c_void, self.len as libc::size_t);
}
}
}
Expand Down