add key_t to sys_types, cleanup sys_ipc and sys_shm
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_ipc.h.html
|
||||
#
|
||||
# Spec quotations relating to includes:
|
||||
# - The <sys/ipc.h> header shall define the uid_t, gid_t, mode_t, and key_t types as described in <sys/types.h>
|
||||
sys_includes = []
|
||||
# - "The <sys/ipc.h> header shall define the uid_t, gid_t, mode_t, and key_t types as described in <sys/types.h>."
|
||||
include_guard = "_RELIBC_SYS_IPC_H"
|
||||
after_includes = """
|
||||
#include <bits/gid-t.h> // for gid_t from sys/types.h
|
||||
#include <bits/uid-t.h> // for uid_t from sys/types.h
|
||||
#include <bits/key-t.h> // for key_t from sys/types.h
|
||||
#include <bits/mode-t.h> // for mode_t from sys/types.h
|
||||
#include <bits/mode-t.h> // for mode_t from sys/types.h
|
||||
"""
|
||||
language = "C"
|
||||
style = "Tag"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
# POSIX header spec: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_shm.h.html
|
||||
#
|
||||
# Spec quotations relating to includes:
|
||||
# - The <sys/shm.h> header shall define the type intptr_t as described in <stdint.h>
|
||||
# - The <sys/shm.h> header shall define the pid_t, size_t, and time_t types as described in <sys/types.h>
|
||||
# - In addition, the <sys/shm.h> header shall include the <sys/ipc.h> header.
|
||||
# - "The <sys/shm.h> header shall define the type intptr_t as described in <stdint.h>."
|
||||
# - "The <sys/shm.h> header shall define the pid_t, size_t, and time_t types as described in <sys/types.h>."
|
||||
# - "In addition, the <sys/shm.h> header shall include the <sys/ipc.h> header."
|
||||
sys_includes = ["sys/ipc.h", "stdint.h"]
|
||||
include_guard = "_RELIBC_SYS_SHM_H"
|
||||
after_includes = """
|
||||
#include <bits/pid-t.h> // for pid_t from sys/types.h
|
||||
#include <bits/size-t.h> // for size_t from sys/types.h
|
||||
#include <bits/time-t.h> // for time_t from sys/types.h
|
||||
#include <bits/size-t.h> // for size_t from sys/types.h
|
||||
#include <bits/time-t.h> // for time_t from sys/types.h
|
||||
"""
|
||||
language = "C"
|
||||
style = "Tag"
|
||||
|
||||
@@ -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::<c_char>();
|
||||
|
||||
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::<ShmHeader>();
|
||||
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::<ShmHeader>()) };
|
||||
let header = base_ptr as *mut ShmHeader;
|
||||
let header = base_ptr.cast::<ShmHeader>();
|
||||
let total_size = unsafe { (*header).total_size };
|
||||
|
||||
unsafe { Sys::munmap(base_ptr as *mut c_void, total_size) }
|
||||
unsafe { Sys::munmap(base_ptr.cast::<c_void>(), 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ after_includes = """
|
||||
#include <bits/gid-t.h>
|
||||
#include <bits/id-t.h>
|
||||
#include <bits/ino-t.h>
|
||||
#include <bits/key-t.h>
|
||||
#include <bits/mode-t.h>
|
||||
#include <bits/nlink-t.h>
|
||||
#include <bits/off-t.h>
|
||||
@@ -24,7 +25,6 @@ after_includes = """
|
||||
"""
|
||||
include_guard = "_RELIBC_SYS_TYPES_INTERNAL_H"
|
||||
language = "C"
|
||||
style = "Type"
|
||||
no_includes = true
|
||||
|
||||
[export]
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user