summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-12-15 09:40:30 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-12-15 09:40:30 -0800
commita02fdc290c4a7c5fdc8ba27b0ac932d665addb75 (patch)
tree48dfb1af01b206cac6817a1156baa234119c001a
parente432357a377c660989d4030bd2bccc7a7dd14c2f (diff)
parent5ad78b842930be613801fdfc4a640ee20c6508ff (diff)
downloadrust-libc-a02fdc290c4a7c5fdc8ba27b0ac932d665addb75.tar.gz
Merge pull request #96 from polachok/shm
SysV shared memory APIs
-rw-r--r--libc-test/build.rs4
-rw-r--r--src/unix/notbsd/linux/mips.rs26
-rw-r--r--src/unix/notbsd/linux/mod.rs29
-rw-r--r--src/unix/notbsd/linux/musl.rs25
-rw-r--r--src/unix/notbsd/linux/other/mod.rs35
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
+ }
+}