diff options
author | Alexander Polakov <apolyakov@beget.ru> | 2015-12-14 02:09:45 +0300 |
---|---|---|
committer | root <admin@beget.ru> | 2015-12-15 18:15:05 +0300 |
commit | 58501564c49b904893363be6a1e50218f3e11d54 (patch) | |
tree | 129d228a52de611fc89ffca9e89209cfb374034e | |
parent | 087b5a4202b61f80b2ace96822b60c3d06cd66d3 (diff) | |
download | rust-libc-58501564c49b904893363be6a1e50218f3e11d54.tar.gz |
SysV shared memory APIs
-rw-r--r-- | libc-test/build.rs | 4 | ||||
-rw-r--r-- | src/unix/notbsd/linux/mips.rs | 26 | ||||
-rw-r--r-- | src/unix/notbsd/linux/mod.rs | 29 | ||||
-rw-r--r-- | src/unix/notbsd/linux/musl.rs | 25 | ||||
-rw-r--r-- | src/unix/notbsd/linux/other/mod.rs | 35 |
5 files changed, 118 insertions, 1 deletions
diff --git a/libc-test/build.rs b/libc-test/build.rs index e2a0818d46..b1ece4ea6a 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -111,6 +111,8 @@ fn main() { if linux { cfg.header("sys/xattr.h"); + cfg.header("sys/ipc.h"); + cfg.header("sys/shm.h"); } if linux || android { @@ -235,7 +237,7 @@ fn main() { "TCP_COOKIE_TRANSACTIONS" | "RLIMIT_RTTIME" if musl => true, // work around super old mips toolchain - "SCHED_IDLE" => mips, + "SCHED_IDLE" | "SHM_NORESERVE" => mips, _ => false, } diff --git a/src/unix/notbsd/linux/mips.rs b/src/unix/notbsd/linux/mips.rs index 8045119f90..5c0591f158 100644 --- a/src/unix/notbsd/linux/mips.rs +++ b/src/unix/notbsd/linux/mips.rs @@ -99,6 +99,32 @@ s! { __unused4: *mut ::c_void, __unused5: *mut ::c_void, } + + pub struct ipc_perm { + pub __key: ::key_t, + pub uid: ::uid_t, + pub gid: ::gid_t, + pub cuid: ::uid_t, + pub cgid: ::gid_t, + pub mode: ::c_uint, + pub __seq: ::c_ushort, + __pad1: ::c_ushort, + __unused1: ::c_ulong, + __unused2: ::c_ulong + } + + pub struct shmid_ds { + pub shm_perm: ::ipc_perm, + pub shm_segsz: ::size_t, + pub shm_atime: ::time_t, + pub shm_dtime: ::time_t, + pub shm_ctime: ::time_t, + pub shm_cpid: ::pid_t, + pub shm_lpid: ::pid_t, + pub shm_nattch: ::shmatt_t, + __unused4: ::c_ulong, + __unused5: ::c_ulong + } } pub const BUFSIZ: ::c_uint = 8192; diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 866a9fe534..d03c4d6446 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -11,6 +11,8 @@ pub type blkcnt64_t = i64; pub type rlim64_t = u64; pub type fsblkcnt_t = ::c_ulong; pub type fsfilcnt_t = ::c_ulong; +pub type key_t = ::c_int; +pub type shmatt_t = ::c_ulong; pub enum fpos64_t {} // TODO: fill this out with a struct @@ -287,9 +289,36 @@ pub const SCHED_RR: ::c_int = 2; pub const SCHED_BATCH: ::c_int = 3; pub const SCHED_IDLE: ::c_int = 5; +pub const IPC_CREAT: ::c_int = 0o1000; +pub const IPC_EXCL: ::c_int = 0o2000; +pub const IPC_NOWAIT: ::c_int = 0o4000; + +pub const IPC_RMID: ::c_int = 0; +pub const IPC_SET: ::c_int = 1; +pub const IPC_STAT: ::c_int = 2; +pub const IPC_INFO: ::c_int = 3; + +pub const SHM_R: ::c_int = 0o400; +pub const SHM_W: ::c_int = 0o200; + +pub const SHM_RDONLY: ::c_int = 0o10000; +pub const SHM_RND: ::c_int = 0o20000; +pub const SHM_REMAP: ::c_int = 0o40000; +pub const SHM_EXEC: ::c_int = 0o100000; + +pub const SHM_LOCK: ::c_int = 11; +pub const SHM_UNLOCK: ::c_int = 12; + +pub const SHM_HUGETLB: ::c_int = 0o4000; +pub const SHM_NORESERVE: ::c_int = 0o10000; + extern { pub fn shm_open(name: *const c_char, oflag: ::c_int, mode: mode_t) -> ::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; pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int; pub fn __errno_location() -> *mut ::c_int; diff --git a/src/unix/notbsd/linux/musl.rs b/src/unix/notbsd/linux/musl.rs index e8a643aa3d..4e6f803317 100644 --- a/src/unix/notbsd/linux/musl.rs +++ b/src/unix/notbsd/linux/musl.rs @@ -82,6 +82,31 @@ s! { pub _pad: [::c_int; 29], _align: [usize; 0], } + + pub struct ipc_perm { + pub __ipc_perm_key: ::key_t, + pub uid: ::uid_t, + pub gid: ::gid_t, + pub cuid: ::uid_t, + pub cgid: ::gid_t, + pub mode: ::mode_t, + pub __seq: ::c_int, + __unused1: ::c_long, + __unused2: ::c_long + } + + pub struct shmid_ds { + pub shm_perm: ::ipc_perm, + pub shm_segsz: ::size_t, + pub shm_atime: ::time_t, + pub shm_dtime: ::time_t, + pub shm_ctime: ::time_t, + pub shm_cpid: ::pid_t, + pub shm_lpid: ::pid_t, + pub shm_nattch: ::c_ulong, + __pad1: ::c_ulong, + __pad2: ::c_ulong, + } } pub const BUFSIZ: ::c_uint = 1024; diff --git a/src/unix/notbsd/linux/other/mod.rs b/src/unix/notbsd/linux/other/mod.rs index 2478677939..5c22f8e079 100644 --- a/src/unix/notbsd/linux/other/mod.rs +++ b/src/unix/notbsd/linux/other/mod.rs @@ -252,3 +252,38 @@ cfg_if! { // ... } } + +s! { + pub struct ipc_perm { + pub __key: ::key_t, + pub uid: ::uid_t, + pub gid: ::gid_t, + pub cuid: ::uid_t, + pub cgid: ::gid_t, + pub mode: ::c_ushort, + __pad1: ::c_ushort, + pub __seq: ::c_ushort, + __pad2: ::c_ushort, + __unused1: ::c_ulong, + __unused2: ::c_ulong + } + + pub struct shmid_ds { + pub shm_perm: ::ipc_perm, + pub shm_segsz: ::size_t, + pub shm_atime: ::time_t, + #[cfg(target_pointer_width = "32")] + __unused1: ::c_ulong, + pub shm_dtime: ::time_t, + #[cfg(target_pointer_width = "32")] + __unused2: ::c_ulong, + pub shm_ctime: ::time_t, + #[cfg(target_pointer_width = "32")] + __unused3: ::c_ulong, + pub shm_cpid: ::pid_t, + pub shm_lpid: ::pid_t, + pub shm_nattch: ::shmatt_t, + __unused4: ::c_ulong, + __unused5: ::c_ulong + } +} |