Skip to content

Commit 487b454

Browse files
committed
add shm support for NetBSD and OpenBSD
initial work from @landryb for OpenBSD, various fixes and NetBSD support from me. Fixes #1585
1 parent 13d4a5d commit 487b454

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

libc-test/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ fn test_openbsd(target: &str) {
322322
"ufs/ufs/quota.h",
323323
"pthread_np.h",
324324
"sys/syscall.h",
325+
"sys/shm.h",
325326
}
326327

327328
cfg.skip_struct(move |ty| {
@@ -818,6 +819,7 @@ fn test_netbsd(target: &str) {
818819
"netinet/dccp.h",
819820
"sys/event.h",
820821
"sys/quota.h",
822+
"sys/shm.h",
821823
}
822824

823825
cfg.type_name(move |ty, is_struct, is_union| {

src/unix/bsd/netbsdlike/mod.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub type nl_item = c_long;
1010
pub type clockid_t = ::c_int;
1111
pub type id_t = u32;
1212
pub type sem_t = *mut sem;
13+
pub type key_t = c_long;
1314

1415
#[cfg_attr(feature = "extra_traits", derive(Debug))]
1516
pub enum timezone {}
@@ -63,6 +64,16 @@ s! {
6364
pub l_type: ::c_short,
6465
pub l_whence: ::c_short,
6566
}
67+
68+
pub struct ipc_perm {
69+
pub cuid: ::uid_t,
70+
pub cgid: ::gid_t,
71+
pub uid: ::uid_t,
72+
pub gid: ::gid_t,
73+
pub mode: ::mode_t,
74+
pub seq: ::c_ushort,
75+
pub key: ::key_t,
76+
}
6677
}
6778

6879
pub const D_T_FMT: ::nl_item = 0;
@@ -199,9 +210,20 @@ pub const MAP_SHARED: ::c_int = 0x0001;
199210
pub const MAP_PRIVATE: ::c_int = 0x0002;
200211
pub const MAP_FIXED: ::c_int = 0x0010;
201212
pub const MAP_ANON: ::c_int = 0x1000;
213+
pub const MAP_ANONYMOUS: ::c_int = MAP_ANON;
202214

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

217+
pub const IPC_CREAT: ::c_int = 0o001000;
218+
pub const IPC_EXCL: ::c_int = 0o002000;
219+
pub const IPC_NOWAIT: ::c_int = 0o004000;
220+
221+
pub const IPC_PRIVATE: ::key_t = 0;
222+
223+
pub const IPC_RMID: ::c_int = 0;
224+
pub const IPC_SET: ::c_int = 1;
225+
pub const IPC_STAT: ::c_int = 2;
226+
205227
pub const MCL_CURRENT: ::c_int = 0x0001;
206228
pub const MCL_FUTURE: ::c_int = 0x0002;
207229

@@ -715,6 +737,19 @@ extern "C" {
715737
pub fn getdomainname(name: *mut ::c_char, len: ::size_t) -> ::c_int;
716738
pub fn setdomainname(name: *const ::c_char, len: ::size_t) -> ::c_int;
717739
pub fn uname(buf: *mut ::utsname) -> ::c_int;
740+
741+
pub fn shmget(key: ::key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int;
742+
pub fn shmat(
743+
shmid: ::c_int,
744+
shmaddr: *const ::c_void,
745+
shmflg: ::c_int,
746+
) -> *mut ::c_void;
747+
pub fn shmdt(shmaddr: *const ::c_void) -> ::c_int;
748+
pub fn shmctl(
749+
shmid: ::c_int,
750+
cmd: ::c_int,
751+
buf: *mut ::shmid_ds,
752+
) -> ::c_int;
718753
}
719754

720755
cfg_if! {

src/unix/bsd/netbsdlike/netbsd/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub type mqd_t = ::c_int;
99
type __pthread_spin_t = __cpu_simple_lock_nv_t;
1010
pub type vm_size_t = ::uintptr_t;
1111
pub type lwpid_t = ::c_uint;
12+
pub type shmatt_t = ::c_uint;
1213

1314
impl siginfo_t {
1415
pub unsafe fn si_value(&self) -> ::sigval {
@@ -281,6 +282,18 @@ s! {
281282
pub msg_hdr: ::msghdr,
282283
pub msg_len: ::c_uint,
283284
}
285+
286+
pub struct shmid_ds {
287+
pub shm_perm: ::ipc_perm,
288+
pub shm_segsz: ::size_t,
289+
pub shm_lpid: ::pid_t,
290+
pub shm_cpid: ::pid_t,
291+
pub shm_nattch: ::shmatt_t,
292+
pub shm_atime: ::time_t,
293+
pub shm_dtime: ::time_t,
294+
pub shm_ctime: ::time_t,
295+
_shm_internal: *mut ::c_void,
296+
}
284297
}
285298

286299
s_no_extra_traits! {

src/unix/bsd/netbsdlike/openbsd/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,21 @@ s! {
306306
pub ar_pln: u8,
307307
pub ar_op: u16,
308308
}
309+
310+
pub struct shmid_ds {
311+
pub shm_perm: ::ipc_perm,
312+
pub shm_segsz: ::c_int,
313+
pub shm_lpid: ::pid_t,
314+
pub shm_cpid: ::pid_t,
315+
pub shm_nattch: ::c_short,
316+
pub shm_atime: ::time_t,
317+
__shm_atimensec: c_long,
318+
pub shm_dtime: ::time_t,
319+
__shm_dtimensec: c_long,
320+
pub shm_ctime: ::time_t,
321+
__shm_ctimensec: c_long,
322+
pub shm_internal: *mut ::c_void,
323+
}
309324
}
310325

311326
impl siginfo_t {

0 commit comments

Comments
 (0)