Skip to content

Commit 78cb2f5

Browse files
committed
auto merge of #14984 : thestinger/rust/libc, r=alexcrichton
2 parents 34e3232 + bb0a427 commit 78cb2f5

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/libgreen/stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ fn protect_last_page(stack: &MemoryMap) -> bool {
9696
// This may seem backwards: the start of the segment is the last page?
9797
// Yes! The stack grows from higher addresses (the end of the allocated
9898
// block) to lower addresses (the start of the allocated block).
99-
let last_page = stack.data as *libc::c_void;
99+
let last_page = stack.data as *mut libc::c_void;
100100
libc::mprotect(last_page, page_size() as libc::size_t,
101101
libc::PROT_NONE) != -1
102102
}

src/liblibc/lib.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ pub mod consts {
20572057
pub static MAP_FIXED : c_int = 0x0010;
20582058
pub static MAP_ANON : c_int = 0x0020;
20592059

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

20622062
pub static MCL_CURRENT : c_int = 0x0001;
20632063
pub static MCL_FUTURE : c_int = 0x0002;
@@ -2268,7 +2268,7 @@ pub mod consts {
22682268
pub static MAP_FIXED : c_int = 0x0010;
22692269
pub static MAP_ANON : c_int = 0x0800;
22702270

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

22732273
pub static MCL_CURRENT : c_int = 0x0001;
22742274
pub static MCL_FUTURE : c_int = 0x0002;
@@ -2804,7 +2804,7 @@ pub mod consts {
28042804
pub static MAP_FIXED : c_int = 0x0010;
28052805
pub static MAP_ANON : c_int = 0x1000;
28062806

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

28092809
pub static MCL_CURRENT : c_int = 0x0001;
28102810
pub static MCL_FUTURE : c_int = 0x0002;
@@ -3192,7 +3192,7 @@ pub mod consts {
31923192
pub static MAP_FIXED : c_int = 0x0010;
31933193
pub static MAP_ANON : c_int = 0x1000;
31943194

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

31973197
pub static MCL_CURRENT : c_int = 0x0001;
31983198
pub static MCL_FUTURE : c_int = 0x0002;
@@ -3951,19 +3951,19 @@ pub mod funcs {
39513951
pub fn mlockall(flags: c_int) -> c_int;
39523952
pub fn munlockall() -> c_int;
39533953

3954-
pub fn mmap(addr: *c_void,
3954+
pub fn mmap(addr: *mut c_void,
39553955
len: size_t,
39563956
prot: c_int,
39573957
flags: c_int,
39583958
fd: c_int,
39593959
offset: off_t)
39603960
-> *mut c_void;
3961-
pub fn munmap(addr: *c_void, len: size_t) -> c_int;
3961+
pub fn munmap(addr: *mut c_void, len: size_t) -> c_int;
39623962

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

3966-
pub fn msync(addr: *c_void, len: size_t, flags: c_int)
3966+
pub fn msync(addr: *mut c_void, len: size_t, flags: c_int)
39673967
-> c_int;
39683968
pub fn shm_open(name: *c_char, oflag: c_int, mode: mode_t)
39693969
-> c_int;
@@ -4208,9 +4208,9 @@ pub mod funcs {
42084208

42094209
extern {
42104210
pub fn getdtablesize() -> c_int;
4211-
pub fn madvise(addr: *c_void, len: size_t, advice: c_int)
4211+
pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int)
42124212
-> c_int;
4213-
pub fn mincore(addr: *c_void, len: size_t, vec: *c_uchar)
4213+
pub fn mincore(addr: *mut c_void, len: size_t, vec: *mut c_uchar)
42144214
-> c_int;
42154215
}
42164216
}

src/libstd/os.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,6 @@ impl MemoryMap {
13381338
/// `ErrZeroLength`.
13391339
pub fn new(min_len: uint, options: &[MapOption]) -> Result<MemoryMap, MapError> {
13401340
use libc::off_t;
1341-
use cmp::Equiv;
13421341

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

13731372
let r = unsafe {
1374-
libc::mmap(addr as *c_void, len as libc::size_t, prot, flags, fd,
1375-
offset)
1373+
libc::mmap(addr as *mut c_void, len as libc::size_t, prot, flags,
1374+
fd, offset)
13761375
};
1377-
if r.equiv(&libc::MAP_FAILED) {
1376+
if r == libc::MAP_FAILED {
13781377
Err(match errno() as c_int {
13791378
libc::EACCES => ErrFdNotAvail,
13801379
libc::EBADF => ErrInvalidFd,
@@ -1410,8 +1409,8 @@ impl Drop for MemoryMap {
14101409
if self.len == 0 { /* workaround for dummy_stack */ return; }
14111410

14121411
unsafe {
1413-
// FIXME: what to do if this fails?
1414-
let _ = libc::munmap(self.data as *c_void, self.len as libc::size_t);
1412+
// `munmap` only fails due to logic errors
1413+
libc::munmap(self.data as *mut c_void, self.len as libc::size_t);
14151414
}
14161415
}
14171416
}

0 commit comments

Comments
 (0)