Merge pull request #96 from polachok/shm

SysV shared memory APIs
This commit is contained in:
Alex Crichton 2015-12-15 09:40:30 -08:00
commit a02fdc290c
5 changed files with 118 additions and 1 deletions

View file

@ -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,
}

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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
}
}