From 31052b5ef54f1138b42692997b9aa7182ad5ebc2 Mon Sep 17 00:00:00 2001 From: auronandace Date: Mon, 27 Apr 2026 16:06:17 +0100 Subject: [PATCH] verify sys_mman header includes --- src/header/sys_mman/cbindgen.toml | 10 +++++++++- src/header/sys_mman/mod.rs | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/header/sys_mman/cbindgen.toml b/src/header/sys_mman/cbindgen.toml index 72405bf5ab..63f6299c7e 100644 --- a/src/header/sys_mman/cbindgen.toml +++ b/src/header/sys_mman/cbindgen.toml @@ -1,4 +1,10 @@ -sys_includes = ["stdarg.h", "stdint.h", "sys/types.h"] +# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_mman.h.html +# +# Spec quotations relating to includes: +# - "The header shall define the mode_t, off_t, and size_t types as described in ." +# - "The header shall define the following symbolic constants as described in " +# - "Inclusion of the header may make visible all symbols from the header." +sys_includes = ["sys/types.h", "fcntl.h"] include_guard = "_RELIBC_SYS_MMAN_H" after_includes = """ @@ -8,6 +14,8 @@ language = "C" style = "Tag" no_includes = true cpp_compat = true +# make size_t actually size_t instead of uintptr_t (which would require stdint.h) +usize_is_size_t = true [enum] prefix_with_name = true diff --git a/src/header/sys_mman/mod.rs b/src/header/sys_mman/mod.rs index 95f79f1b3f..0930c9660c 100644 --- a/src/header/sys_mman/mod.rs +++ b/src/header/sys_mman/mod.rs @@ -62,7 +62,7 @@ pub unsafe extern "C" fn madvise(addr: *mut c_void, len: size_t, flags: c_int) - /// See . #[unsafe(no_mangle)] -pub unsafe extern "C" fn mlock(addr: *const c_void, len: usize) -> c_int { +pub unsafe extern "C" fn mlock(addr: *const c_void, len: size_t) -> c_int { unsafe { Sys::mlock(addr, len) } .map(|()| 0) .or_minus_one_errno() @@ -107,8 +107,8 @@ pub unsafe extern "C" fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) - #[unsafe(no_mangle)] pub unsafe extern "C" fn mremap( old_address: *mut c_void, - old_size: usize, - new_size: usize, + old_size: size_t, + new_size: size_t, flags: c_int, mut __valist: ... ) -> *mut c_void { @@ -132,7 +132,7 @@ pub unsafe extern "C" fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> /// See . #[unsafe(no_mangle)] -pub unsafe extern "C" fn munlock(addr: *const c_void, len: usize) -> c_int { +pub unsafe extern "C" fn munlock(addr: *const c_void, len: size_t) -> c_int { unsafe { Sys::munlock(addr, len) } .map(|()| 0) .or_minus_one_errno()