diff --git a/changelog/2655.fixed.md b/changelog/2655.fixed.md new file mode 100644 index 0000000000..287cff9d87 --- /dev/null +++ b/changelog/2655.fixed.md @@ -0,0 +1 @@ +Cast the 'addr' argument of 'madvise()' to '*mut u8' on AIX to match the signature in the AIX libc. diff --git a/src/sys/mman.rs b/src/sys/mman.rs index 867d207da3..bbb97f128b 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -555,9 +555,22 @@ pub unsafe fn madvise( length: size_t, advise: MmapAdvise, ) -> Result<()> { + let ptr = { + // The AIX signature of 'madvise()' differs from the POSIX specification, + // which expects 'void *' as the type of the 'addr' argument, whereas AIX uses + // 'caddr_t' (i.e., 'char *'). + #[cfg(target_os = "aix")] + { + addr.as_ptr() as *mut u8 + } + #[cfg(not(target_os = "aix"))] + { + addr.as_ptr() + } + }; + unsafe { - Errno::result(libc::madvise(addr.as_ptr(), length, advise as i32)) - .map(drop) + Errno::result(libc::madvise(ptr, length, advise as i32)).map(drop) } }