Skip to content

add shm support for NetBSD and OpenBSD #1586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ fn test_openbsd(target: &str) {
"ufs/ufs/quota.h",
"pthread_np.h",
"sys/syscall.h",
"sys/shm.h",
}

cfg.skip_struct(move |ty| {
Expand Down Expand Up @@ -818,6 +819,7 @@ fn test_netbsd(target: &str) {
"netinet/dccp.h",
"sys/event.h",
"sys/quota.h",
"sys/shm.h",
}

cfg.type_name(move |ty, is_struct, is_union| {
Expand Down
35 changes: 35 additions & 0 deletions src/unix/bsd/netbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub type nl_item = c_long;
pub type clockid_t = ::c_int;
pub type id_t = u32;
pub type sem_t = *mut sem;
pub type key_t = c_long;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum timezone {}
Expand Down Expand Up @@ -63,6 +64,16 @@ s! {
pub l_type: ::c_short,
pub l_whence: ::c_short,
}

pub struct ipc_perm {
pub cuid: ::uid_t,
pub cgid: ::gid_t,
pub uid: ::uid_t,
pub gid: ::gid_t,
pub mode: ::mode_t,
pub seq: ::c_ushort,
pub key: ::key_t,
}
}

pub const D_T_FMT: ::nl_item = 0;
Expand Down Expand Up @@ -199,9 +210,20 @@ pub const MAP_SHARED: ::c_int = 0x0001;
pub const MAP_PRIVATE: ::c_int = 0x0002;
pub const MAP_FIXED: ::c_int = 0x0010;
pub const MAP_ANON: ::c_int = 0x1000;
pub const MAP_ANONYMOUS: ::c_int = MAP_ANON;

pub const MAP_FAILED: *mut ::c_void = !0 as *mut ::c_void;

pub const IPC_CREAT: ::c_int = 0o001000;
pub const IPC_EXCL: ::c_int = 0o002000;
pub const IPC_NOWAIT: ::c_int = 0o004000;

pub const IPC_PRIVATE: ::key_t = 0;

pub const IPC_RMID: ::c_int = 0;
pub const IPC_SET: ::c_int = 1;
pub const IPC_STAT: ::c_int = 2;

pub const MCL_CURRENT: ::c_int = 0x0001;
pub const MCL_FUTURE: ::c_int = 0x0002;

Expand Down Expand Up @@ -715,6 +737,19 @@ extern "C" {
pub fn getdomainname(name: *mut ::c_char, len: ::size_t) -> ::c_int;
pub fn setdomainname(name: *const ::c_char, len: ::size_t) -> ::c_int;
pub fn uname(buf: *mut ::utsname) -> ::c_int;

pub fn shmget(key: ::key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int;
pub fn shmat(
shmid: ::c_int,
shmaddr: *const ::c_void,
shmflg: ::c_int,
) -> *mut ::c_void;
pub fn shmdt(shmaddr: *const ::c_void) -> ::c_int;
pub fn shmctl(
shmid: ::c_int,
cmd: ::c_int,
buf: *mut ::shmid_ds,
) -> ::c_int;
}

cfg_if! {
Expand Down
13 changes: 13 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub type mqd_t = ::c_int;
type __pthread_spin_t = __cpu_simple_lock_nv_t;
pub type vm_size_t = ::uintptr_t;
pub type lwpid_t = ::c_uint;
pub type shmatt_t = ::c_uint;

impl siginfo_t {
pub unsafe fn si_value(&self) -> ::sigval {
Expand Down Expand Up @@ -281,6 +282,18 @@ s! {
pub msg_hdr: ::msghdr,
pub msg_len: ::c_uint,
}

pub struct shmid_ds {
pub shm_perm: ::ipc_perm,
pub shm_segsz: ::size_t,
pub shm_lpid: ::pid_t,
pub shm_cpid: ::pid_t,
pub shm_nattch: ::shmatt_t,
pub shm_atime: ::time_t,
pub shm_dtime: ::time_t,
pub shm_ctime: ::time_t,
_shm_internal: *mut ::c_void,
}
}

s_no_extra_traits! {
Expand Down
15 changes: 15 additions & 0 deletions src/unix/bsd/netbsdlike/openbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,21 @@ s! {
pub ar_pln: u8,
pub ar_op: u16,
}

pub struct shmid_ds {
pub shm_perm: ::ipc_perm,
pub shm_segsz: ::c_int,
pub shm_lpid: ::pid_t,
pub shm_cpid: ::pid_t,
pub shm_nattch: ::c_short,
pub shm_atime: ::time_t,
__shm_atimensec: c_long,
pub shm_dtime: ::time_t,
__shm_dtimensec: c_long,
pub shm_ctime: ::time_t,
__shm_ctimensec: c_long,
pub shm_internal: *mut ::c_void,
}
}

impl siginfo_t {
Expand Down