fix signatures of mmap-related functions from libc
This commit is contained in:
parent
2fd618e77a
commit
bb0a42745f
@ -96,7 +96,7 @@ fn protect_last_page(stack: &MemoryMap) -> bool {
|
|||||||
// This may seem backwards: the start of the segment is the last page?
|
// 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
|
// Yes! The stack grows from higher addresses (the end of the allocated
|
||||||
// block) to lower addresses (the start of the allocated block).
|
// 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::mprotect(last_page, page_size() as libc::size_t,
|
||||||
libc::PROT_NONE) != -1
|
libc::PROT_NONE) != -1
|
||||||
}
|
}
|
||||||
|
@ -2057,7 +2057,7 @@ pub mod consts {
|
|||||||
pub static MAP_FIXED : c_int = 0x0010;
|
pub static MAP_FIXED : c_int = 0x0010;
|
||||||
pub static MAP_ANON : c_int = 0x0020;
|
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_CURRENT : c_int = 0x0001;
|
||||||
pub static MCL_FUTURE : c_int = 0x0002;
|
pub static MCL_FUTURE : c_int = 0x0002;
|
||||||
@ -2268,7 +2268,7 @@ pub mod consts {
|
|||||||
pub static MAP_FIXED : c_int = 0x0010;
|
pub static MAP_FIXED : c_int = 0x0010;
|
||||||
pub static MAP_ANON : c_int = 0x0800;
|
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_CURRENT : c_int = 0x0001;
|
||||||
pub static MCL_FUTURE : c_int = 0x0002;
|
pub static MCL_FUTURE : c_int = 0x0002;
|
||||||
@ -2804,7 +2804,7 @@ pub mod consts {
|
|||||||
pub static MAP_FIXED : c_int = 0x0010;
|
pub static MAP_FIXED : c_int = 0x0010;
|
||||||
pub static MAP_ANON : c_int = 0x1000;
|
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_CURRENT : c_int = 0x0001;
|
||||||
pub static MCL_FUTURE : c_int = 0x0002;
|
pub static MCL_FUTURE : c_int = 0x0002;
|
||||||
@ -3192,7 +3192,7 @@ pub mod consts {
|
|||||||
pub static MAP_FIXED : c_int = 0x0010;
|
pub static MAP_FIXED : c_int = 0x0010;
|
||||||
pub static MAP_ANON : c_int = 0x1000;
|
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_CURRENT : c_int = 0x0001;
|
||||||
pub static MCL_FUTURE : c_int = 0x0002;
|
pub static MCL_FUTURE : c_int = 0x0002;
|
||||||
@ -3951,19 +3951,19 @@ pub mod funcs {
|
|||||||
pub fn mlockall(flags: c_int) -> c_int;
|
pub fn mlockall(flags: c_int) -> c_int;
|
||||||
pub fn munlockall() -> c_int;
|
pub fn munlockall() -> c_int;
|
||||||
|
|
||||||
pub fn mmap(addr: *c_void,
|
pub fn mmap(addr: *mut c_void,
|
||||||
len: size_t,
|
len: size_t,
|
||||||
prot: c_int,
|
prot: c_int,
|
||||||
flags: c_int,
|
flags: c_int,
|
||||||
fd: c_int,
|
fd: c_int,
|
||||||
offset: off_t)
|
offset: off_t)
|
||||||
-> *mut c_void;
|
-> *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;
|
-> 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;
|
-> c_int;
|
||||||
pub fn shm_open(name: *c_char, oflag: c_int, mode: mode_t)
|
pub fn shm_open(name: *c_char, oflag: c_int, mode: mode_t)
|
||||||
-> c_int;
|
-> c_int;
|
||||||
@ -4208,9 +4208,9 @@ pub mod funcs {
|
|||||||
|
|
||||||
extern {
|
extern {
|
||||||
pub fn getdtablesize() -> c_int;
|
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;
|
-> 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;
|
-> c_int;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1338,7 +1338,6 @@ impl MemoryMap {
|
|||||||
/// `ErrZeroLength`.
|
/// `ErrZeroLength`.
|
||||||
pub fn new(min_len: uint, options: &[MapOption]) -> Result<MemoryMap, MapError> {
|
pub fn new(min_len: uint, options: &[MapOption]) -> Result<MemoryMap, MapError> {
|
||||||
use libc::off_t;
|
use libc::off_t;
|
||||||
use cmp::Equiv;
|
|
||||||
|
|
||||||
if min_len == 0 {
|
if min_len == 0 {
|
||||||
return Err(ErrZeroLength)
|
return Err(ErrZeroLength)
|
||||||
@ -1371,10 +1370,10 @@ impl MemoryMap {
|
|||||||
if fd == -1 && !custom_flags { flags |= libc::MAP_ANON; }
|
if fd == -1 && !custom_flags { flags |= libc::MAP_ANON; }
|
||||||
|
|
||||||
let r = unsafe {
|
let r = unsafe {
|
||||||
libc::mmap(addr as *c_void, len as libc::size_t, prot, flags, fd,
|
libc::mmap(addr as *mut c_void, len as libc::size_t, prot, flags,
|
||||||
offset)
|
fd, offset)
|
||||||
};
|
};
|
||||||
if r.equiv(&libc::MAP_FAILED) {
|
if r == libc::MAP_FAILED {
|
||||||
Err(match errno() as c_int {
|
Err(match errno() as c_int {
|
||||||
libc::EACCES => ErrFdNotAvail,
|
libc::EACCES => ErrFdNotAvail,
|
||||||
libc::EBADF => ErrInvalidFd,
|
libc::EBADF => ErrInvalidFd,
|
||||||
@ -1410,8 +1409,8 @@ impl Drop for MemoryMap {
|
|||||||
if self.len == 0 { /* workaround for dummy_stack */ return; }
|
if self.len == 0 { /* workaround for dummy_stack */ return; }
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
// FIXME: what to do if this fails?
|
// `munmap` only fails due to logic errors
|
||||||
let _ = libc::munmap(self.data as *c_void, self.len as libc::size_t);
|
libc::munmap(self.data as *mut c_void, self.len as libc::size_t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user