From bb0a42745f7a951c298b7bc2e07f7ba1fee14100 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 17 Jun 2014 17:14:55 -0400 Subject: [PATCH] fix signatures of mmap-related functions from libc --- src/libgreen/stack.rs | 2 +- src/liblibc/lib.rs | 20 ++++++++++---------- src/libstd/os.rs | 11 +++++------ 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/libgreen/stack.rs b/src/libgreen/stack.rs index 2e385f75e1d..526ce66b1ea 100644 --- a/src/libgreen/stack.rs +++ b/src/libgreen/stack.rs @@ -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 } diff --git a/src/liblibc/lib.rs b/src/liblibc/lib.rs index 05d9988a139..2a464d82fd9 100644 --- a/src/liblibc/lib.rs +++ b/src/liblibc/lib.rs @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; } } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index dfbf61cc890..4d58d4674bf 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -1338,7 +1338,6 @@ impl MemoryMap { /// `ErrZeroLength`. pub fn new(min_len: uint, options: &[MapOption]) -> Result { use libc::off_t; - use cmp::Equiv; if min_len == 0 { return Err(ErrZeroLength) @@ -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, @@ -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); } } }