diff --git a/src/header/bits_key-t/cbindgen.toml b/src/header/bits_key-t/cbindgen.toml index 8ed688136d..431fbddd41 100644 --- a/src/header/bits_key-t/cbindgen.toml +++ b/src/header/bits_key-t/cbindgen.toml @@ -2,10 +2,9 @@ # # POSIX headers that require key_t: # - sys/ipc.h -sys_includes = [] +# - sys/types (where it should be defined) include_guard = "_RELIBC_BITS_KEY_T_H" language = "C" -style = "type" no_includes = true cpp_compat = true [export] diff --git a/src/header/sys_ipc/cbindgen.toml b/src/header/sys_ipc/cbindgen.toml index 9931d0fc0d..f6f0397d8c 100644 --- a/src/header/sys_ipc/cbindgen.toml +++ b/src/header/sys_ipc/cbindgen.toml @@ -1,14 +1,13 @@ # POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_ipc.h.html # # Spec quotations relating to includes: -# - The header shall define the uid_t, gid_t, mode_t, and key_t types as described in -sys_includes = [] +# - "The header shall define the uid_t, gid_t, mode_t, and key_t types as described in ." include_guard = "_RELIBC_SYS_IPC_H" after_includes = """ #include // for gid_t from sys/types.h #include // for uid_t from sys/types.h #include // for key_t from sys/types.h -#include // for mode_t from sys/types.h +#include // for mode_t from sys/types.h """ language = "C" style = "Tag" diff --git a/src/header/sys_ipc/mod.rs b/src/header/sys_ipc/mod.rs index 5c2634007e..736665ca51 100644 --- a/src/header/sys_ipc/mod.rs +++ b/src/header/sys_ipc/mod.rs @@ -13,15 +13,22 @@ pub const IPC_R: u32 = 0o400; pub const IPC_W: u32 = 0o200; pub const IPC_M: u32 = 0o10000; +/// Remove identifier. pub const IPC_RMID: i32 = 0; +/// Set options. pub const IPC_SET: i32 = 1; +/// Get options. pub const IPC_STAT: i32 = 2; // pub const IPC_INFO: i32 = 3; non posix unimplemented +/// Create entry if key does not exist. pub const IPC_CREAT: i32 = 0o1000; +/// Fail if key exists. pub const IPC_EXCL: i32 = 0o2000; +/// Error if request would need to wait. pub const IPC_NOWAIT: i32 = 0o4000; +/// Private key. pub const IPC_PRIVATE: key_t = 0; #[repr(C)] @@ -50,7 +57,7 @@ pub unsafe extern "C" fn ftok(path: *const c_char, id: c_int) -> key_t { } // Borrowed from musl - return (stat.st_ino & 0xffff) as key_t + (stat.st_ino & 0xffff) as key_t | ((stat.st_dev & 0xff) << 16) as key_t - | ((id & 0xff) << 24); + | ((id & 0xff) << 24) } diff --git a/src/header/sys_shm/cbindgen.toml b/src/header/sys_shm/cbindgen.toml index 09b240d40e..0b3f953d5f 100644 --- a/src/header/sys_shm/cbindgen.toml +++ b/src/header/sys_shm/cbindgen.toml @@ -1,15 +1,15 @@ # POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_shm.h.html # # Spec quotations relating to includes: -# - The header shall define the type intptr_t as described in -# - The header shall define the pid_t, size_t, and time_t types as described in -# - In addition, the header shall include the header. +# - "The header shall define the type intptr_t as described in ." +# - "The header shall define the pid_t, size_t, and time_t types as described in ." +# - "In addition, the header shall include the header." sys_includes = ["sys/ipc.h", "stdint.h"] include_guard = "_RELIBC_SYS_SHM_H" after_includes = """ #include // for pid_t from sys/types.h -#include // for size_t from sys/types.h -#include // for time_t from sys/types.h +#include // for size_t from sys/types.h +#include // for time_t from sys/types.h """ language = "C" style = "Tag" diff --git a/src/header/sys_shm/mod.rs b/src/header/sys_shm/mod.rs index ab691bfb75..8aca77004f 100644 --- a/src/header/sys_shm/mod.rs +++ b/src/header/sys_shm/mod.rs @@ -19,10 +19,14 @@ use crate::{ #[allow(non_camel_case_types)] pub type shmatt_t = core::ffi::c_ushort; +/// Attach read-only (else read-write). pub const SHM_RDONLY: c_int = 0o10000; +/// Round attach address to SHMLBA. pub const SHM_RND: c_int = 0o20000; +/// Segment low boundary address multiple. pub const SHMLBA: size_t = 4096; +/// Return value of `shmat()` indicating shared memory has not been attached. pub const SHM_FAILED: *mut c_void = -1isize as *mut c_void; #[repr(C)] @@ -53,7 +57,7 @@ pub unsafe extern "C" fn shmget(key: key_t, size: size_t, shmflg: c_int) -> c_in format!("/sysv_key_{}\0", key) }; - let path_ptr = path_str.as_ptr() as *const c_char; + let path_ptr = path_str.as_ptr().cast::(); let mut oflag = O_RDWR; if (shmflg & IPC_CREAT) != 0 { @@ -90,7 +94,7 @@ pub unsafe extern "C" fn shmat( shmflg: c_int, ) -> *mut c_void { let mut stat = stat::default(); - if unsafe { fstat(shmid, &mut stat) } < 0 { + if unsafe { fstat(shmid, &raw mut stat) } < 0 { return SHM_FAILED; } let size = stat.st_size as usize; @@ -105,7 +109,7 @@ pub unsafe extern "C" fn shmat( Err(_) => return SHM_FAILED, }; - let header = ptr as *mut ShmHeader; + let header = ptr.cast::(); unsafe { (*header).total_size = size; } @@ -121,10 +125,10 @@ pub unsafe extern "C" fn shmdt(shmaddr: *const c_void) -> c_int { } let base_ptr = unsafe { (shmaddr as *mut u8).sub(mem::size_of::()) }; - let header = base_ptr as *mut ShmHeader; + let header = base_ptr.cast::(); let total_size = unsafe { (*header).total_size }; - unsafe { Sys::munmap(base_ptr as *mut c_void, total_size) } + unsafe { Sys::munmap(base_ptr.cast::(), total_size) } .map(|_| 0) .or_minus_one_errno() } @@ -141,7 +145,7 @@ pub unsafe extern "C" fn shmctl(shmid: c_int, cmd: c_int, buf: *mut shmid_ds) -> } let mut stat = stat::default(); - if unsafe { fstat(shmid, &mut stat) } < 0 { + if unsafe { fstat(shmid, &raw mut stat) } < 0 { return -1; } diff --git a/src/header/sys_types_internal/cbindgen.toml b/src/header/sys_types_internal/cbindgen.toml index 0f992450c3..76052d3bc8 100644 --- a/src/header/sys_types_internal/cbindgen.toml +++ b/src/header/sys_types_internal/cbindgen.toml @@ -8,6 +8,7 @@ after_includes = """ #include #include #include +#include #include #include #include @@ -24,7 +25,6 @@ after_includes = """ """ include_guard = "_RELIBC_SYS_TYPES_INTERNAL_H" language = "C" -style = "Type" no_includes = true [export] diff --git a/src/header/sys_types_internal/mod.rs b/src/header/sys_types_internal/mod.rs index 6cfc7533b1..a566002380 100644 --- a/src/header/sys_types_internal/mod.rs +++ b/src/header/sys_types_internal/mod.rs @@ -16,6 +16,7 @@ pub use crate::header::{ bits_gid_t::gid_t, bits_id_t::id_t, bits_ino_t::ino_t, + bits_key_t::key_t, bits_mode_t::mode_t, bits_nlink_t::nlink_t, bits_off_t::off_t,