Skip to content

Commit caeaf33

Browse files
authored
Cast the 'addr' argument of 'madvise()' for AIX (#2655)
* Cast the 'addr' argument of 'madvise()' to match the AIX function signature in the 'libc' crate. * Added changelog.
1 parent 7f0fe67 commit caeaf33

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

changelog/2655.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cast the 'addr' argument of 'madvise()' to '*mut u8' on AIX to match the signature in the AIX libc.

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)