Skip to content

Commit 5850156

Browse files
Alexander Polakovroot
Alexander Polakov
authored and
root
committed
SysV shared memory APIs
1 parent 087b5a4 commit 5850156

File tree

5 files changed

+118
-1
lines changed

5 files changed

+118
-1
lines changed

libc-test/build.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ fn main() {
111111

112112
if linux {
113113
cfg.header("sys/xattr.h");
114+
cfg.header("sys/ipc.h");
115+
cfg.header("sys/shm.h");
114116
}
115117

116118
if linux || android {
@@ -235,7 +237,7 @@ fn main() {
235237
"TCP_COOKIE_TRANSACTIONS" |
236238
"RLIMIT_RTTIME" if musl => true,
237239
// work around super old mips toolchain
238-
"SCHED_IDLE" => mips,
240+
"SCHED_IDLE" | "SHM_NORESERVE" => mips,
239241

240242
_ => false,
241243
}

src/unix/notbsd/linux/mips.rs

+26
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,32 @@ s! {
9999
__unused4: *mut ::c_void,
100100
__unused5: *mut ::c_void,
101101
}
102+
103+
pub struct ipc_perm {
104+
pub __key: ::key_t,
105+
pub uid: ::uid_t,
106+
pub gid: ::gid_t,
107+
pub cuid: ::uid_t,
108+
pub cgid: ::gid_t,
109+
pub mode: ::c_uint,
110+
pub __seq: ::c_ushort,
111+
__pad1: ::c_ushort,
112+
__unused1: ::c_ulong,
113+
__unused2: ::c_ulong
114+
}
115+
116+
pub struct shmid_ds {
117+
pub shm_perm: ::ipc_perm,
118+
pub shm_segsz: ::size_t,
119+
pub shm_atime: ::time_t,
120+
pub shm_dtime: ::time_t,
121+
pub shm_ctime: ::time_t,
122+
pub shm_cpid: ::pid_t,
123+
pub shm_lpid: ::pid_t,
124+
pub shm_nattch: ::shmatt_t,
125+
__unused4: ::c_ulong,
126+
__unused5: ::c_ulong
127+
}
102128
}
103129

104130
pub const BUFSIZ: ::c_uint = 8192;

src/unix/notbsd/linux/mod.rs

+29
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub type blkcnt64_t = i64;
1111
pub type rlim64_t = u64;
1212
pub type fsblkcnt_t = ::c_ulong;
1313
pub type fsfilcnt_t = ::c_ulong;
14+
pub type key_t = ::c_int;
15+
pub type shmatt_t = ::c_ulong;
1416

1517
pub enum fpos64_t {} // TODO: fill this out with a struct
1618

@@ -287,9 +289,36 @@ pub const SCHED_RR: ::c_int = 2;
287289
pub const SCHED_BATCH: ::c_int = 3;
288290
pub const SCHED_IDLE: ::c_int = 5;
289291

292+
pub const IPC_CREAT: ::c_int = 0o1000;
293+
pub const IPC_EXCL: ::c_int = 0o2000;
294+
pub const IPC_NOWAIT: ::c_int = 0o4000;
295+
296+
pub const IPC_RMID: ::c_int = 0;
297+
pub const IPC_SET: ::c_int = 1;
298+
pub const IPC_STAT: ::c_int = 2;
299+
pub const IPC_INFO: ::c_int = 3;
300+
301+
pub const SHM_R: ::c_int = 0o400;
302+
pub const SHM_W: ::c_int = 0o200;
303+
304+
pub const SHM_RDONLY: ::c_int = 0o10000;
305+
pub const SHM_RND: ::c_int = 0o20000;
306+
pub const SHM_REMAP: ::c_int = 0o40000;
307+
pub const SHM_EXEC: ::c_int = 0o100000;
308+
309+
pub const SHM_LOCK: ::c_int = 11;
310+
pub const SHM_UNLOCK: ::c_int = 12;
311+
312+
pub const SHM_HUGETLB: ::c_int = 0o4000;
313+
pub const SHM_NORESERVE: ::c_int = 0o10000;
314+
290315
extern {
291316
pub fn shm_open(name: *const c_char, oflag: ::c_int,
292317
mode: mode_t) -> ::c_int;
318+
pub fn shmget(key: ::key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int;
319+
pub fn shmat(shmid: ::c_int, shmaddr: *const ::c_void, shmflg: ::c_int) -> *mut ::c_void;
320+
pub fn shmdt(shmaddr: *const ::c_void) -> ::c_int;
321+
pub fn shmctl(shmid: ::c_int, cmd: ::c_int, buf: *mut ::shmid_ds) -> ::c_int;
293322
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
294323
-> ::c_int;
295324
pub fn __errno_location() -> *mut ::c_int;

src/unix/notbsd/linux/musl.rs

+25
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,31 @@ s! {
8282
pub _pad: [::c_int; 29],
8383
_align: [usize; 0],
8484
}
85+
86+
pub struct ipc_perm {
87+
pub __ipc_perm_key: ::key_t,
88+
pub uid: ::uid_t,
89+
pub gid: ::gid_t,
90+
pub cuid: ::uid_t,
91+
pub cgid: ::gid_t,
92+
pub mode: ::mode_t,
93+
pub __seq: ::c_int,
94+
__unused1: ::c_long,
95+
__unused2: ::c_long
96+
}
97+
98+
pub struct shmid_ds {
99+
pub shm_perm: ::ipc_perm,
100+
pub shm_segsz: ::size_t,
101+
pub shm_atime: ::time_t,
102+
pub shm_dtime: ::time_t,
103+
pub shm_ctime: ::time_t,
104+
pub shm_cpid: ::pid_t,
105+
pub shm_lpid: ::pid_t,
106+
pub shm_nattch: ::c_ulong,
107+
__pad1: ::c_ulong,
108+
__pad2: ::c_ulong,
109+
}
85110
}
86111

87112
pub const BUFSIZ: ::c_uint = 1024;

src/unix/notbsd/linux/other/mod.rs

+35
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,38 @@ cfg_if! {
252252
// ...
253253
}
254254
}
255+
256+
s! {
257+
pub struct ipc_perm {
258+
pub __key: ::key_t,
259+
pub uid: ::uid_t,
260+
pub gid: ::gid_t,
261+
pub cuid: ::uid_t,
262+
pub cgid: ::gid_t,
263+
pub mode: ::c_ushort,
264+
__pad1: ::c_ushort,
265+
pub __seq: ::c_ushort,
266+
__pad2: ::c_ushort,
267+
__unused1: ::c_ulong,
268+
__unused2: ::c_ulong
269+
}
270+
271+
pub struct shmid_ds {
272+
pub shm_perm: ::ipc_perm,
273+
pub shm_segsz: ::size_t,
274+
pub shm_atime: ::time_t,
275+
#[cfg(target_pointer_width = "32")]
276+
__unused1: ::c_ulong,
277+
pub shm_dtime: ::time_t,
278+
#[cfg(target_pointer_width = "32")]
279+
__unused2: ::c_ulong,
280+
pub shm_ctime: ::time_t,
281+
#[cfg(target_pointer_width = "32")]
282+
__unused3: ::c_ulong,
283+
pub shm_cpid: ::pid_t,
284+
pub shm_lpid: ::pid_t,
285+
pub shm_nattch: ::shmatt_t,
286+
__unused4: ::c_ulong,
287+
__unused5: ::c_ulong
288+
}
289+
}

0 commit comments

Comments
 (0)