Skip to content

Commit cc58dea

Browse files
committed
Cast the 'addr' argument of 'madvise()' to match the AIX function signature in the 'libc' crate.
1 parent a72936d commit cc58dea

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/sys/mman.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,22 @@ pub unsafe fn madvise(
555555
length: size_t,
556556
advise: MmapAdvise,
557557
) -> Result<()> {
558+
let ptr = {
559+
// The AIX signature of 'madvise()' differs from the POSIX specification,
560+
// which expects 'void *' as the type of the 'addr' argument, whereas AIX uses
561+
// 'caddr_t' (i.e., 'char *').
562+
#[cfg(target_os = "aix")]
563+
{
564+
addr.as_ptr() as *mut u8
565+
}
566+
#[cfg(not(target_os = "aix"))]
567+
{
568+
addr.as_ptr()
569+
}
570+
};
571+
558572
unsafe {
559-
Errno::result(libc::madvise(addr.as_ptr(), length, advise as i32))
560-
.map(drop)
573+
Errno::result(libc::madvise(ptr, length, advise as i32)).map(drop)
561574
}
562575
}
563576

0 commit comments

Comments
 (0)