Skip to content

Commit

Permalink
auto merge of #14984 : thestinger/rust/libc, r=alexcrichton
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Jun 18, 2014
2 parents 34e3232 + bb0a427 commit 78cb2f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
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

0 comments on commit 78cb2f5

Please sign in to comment.