Skip to content

Commit

Permalink
Auto merge of rust-lang#401 - alexander255:master, r=alexcrichton
Browse files Browse the repository at this point in the history
Add System V message queue bindings for Linux (glibc/musl)
  • Loading branch information
bors authored Sep 26, 2016
2 parents e3d05ca + 7590565 commit 4548dc6
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 3 deletions.
3 changes: 2 additions & 1 deletion libc-test/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn main() {
cfg.header("sys/signalfd.h");
cfg.header("sys/xattr.h");
cfg.header("sys/ipc.h");
cfg.header("sys/msg.h");
cfg.header("sys/shm.h");
cfg.header("pty.h");
}
Expand Down Expand Up @@ -332,7 +333,8 @@ fn main() {
// kernel regardless
"RLIMIT_NLIMITS" |
"TCP_COOKIE_TRANSACTIONS" |
"RLIMIT_RTTIME" if musl => true,
"RLIMIT_RTTIME" |
"MSG_COPY" if musl => true,
// work around super old mips toolchain
"SCHED_IDLE" | "SHM_NORESERVE" => mips,

Expand Down
26 changes: 26 additions & 0 deletions src/unix/notbsd/linux/mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,32 @@ s! {
__unused5: ::c_ulong
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
#[cfg(target_endian = "big")]
__glibc_reserved1: ::c_ulong,
pub msg_stime: ::time_t,
#[cfg(target_endian = "little")]
__glibc_reserved1: ::c_ulong,
#[cfg(target_endian = "big")]
__glibc_reserved2: ::c_ulong,
pub msg_rtime: ::time_t,
#[cfg(target_endian = "little")]
__glibc_reserved2: ::c_ulong,
#[cfg(target_endian = "big")]
__glibc_reserved3: ::c_ulong,
pub msg_ctime: ::time_t,
#[cfg(target_endian = "little")]
__glibc_reserved3: ::c_ulong,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__glibc_reserved4: ::c_ulong,
__glibc_reserved5: ::c_ulong,
}

pub struct statfs {
pub f_type: ::c_long,
pub f_bsize: ::c_long,
Expand Down
14 changes: 14 additions & 0 deletions src/unix/notbsd/linux/mips64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ s! {
__unused5: ::c_ulong
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
pub msg_stime: ::time_t,
pub msg_rtime: ::time_t,
pub msg_ctime: ::time_t,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__glibc_reserved4: ::c_ulong,
__glibc_reserved5: ::c_ulong,
}

pub struct statfs {
pub f_type: ::c_long,
pub f_bsize: ::c_long,
Expand Down
33 changes: 32 additions & 1 deletion src/unix/notbsd/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ pub type ino64_t = u64;
pub type off64_t = i64;
pub type blkcnt64_t = i64;
pub type rlim64_t = u64;
pub type key_t = ::c_int;
pub type shmatt_t = ::c_ulong;
pub type mqd_t = ::c_int;
pub type msgqnum_t = ::c_ulong;
pub type msglen_t = ::c_ulong;
pub type nfds_t = ::c_ulong;
pub type nl_item = ::c_int;

Expand Down Expand Up @@ -190,6 +191,17 @@ s! {
pub if_name: *mut ::c_char,
}

// System V IPC
pub struct msginfo {
pub msgpool: ::c_int,
pub msgmap: ::c_int,
pub msgmax: ::c_int,
pub msgmnb: ::c_int,
pub msgmni: ::c_int,
pub msgssz: ::c_int,
pub msgtql: ::c_int,
pub msgseg: ::c_ushort,
}
}

pub const ABDAY_1: ::nl_item = 0x20000;
Expand Down Expand Up @@ -430,6 +442,9 @@ pub const SCHED_RR: ::c_int = 2;
pub const SCHED_BATCH: ::c_int = 3;
pub const SCHED_IDLE: ::c_int = 5;

// System V IPC
pub const IPC_PRIVATE: ::key_t = 0;

pub const IPC_CREAT: ::c_int = 0o1000;
pub const IPC_EXCL: ::c_int = 0o2000;
pub const IPC_NOWAIT: ::c_int = 0o4000;
Expand All @@ -438,6 +453,12 @@ 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 MSG_STAT: ::c_int = 11;
pub const MSG_INFO: ::c_int = 12;

pub const MSG_NOERROR: ::c_int = 0o10000;
pub const MSG_EXCEPT: ::c_int = 0o20000;
pub const MSG_COPY: ::c_int = 0o40000;

pub const SHM_R: ::c_int = 0o400;
pub const SHM_W: ::c_int = 0o200;
Expand Down Expand Up @@ -522,6 +543,8 @@ extern {
pub fn getpwent() -> *mut passwd;
pub fn shm_open(name: *const c_char, oflag: ::c_int,
mode: mode_t) -> ::c_int;

// System V IPC
pub fn shmget(key: ::key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int;
pub fn shmat(shmid: ::c_int,
shmaddr: *const ::c_void,
Expand All @@ -530,6 +553,14 @@ extern {
pub fn shmctl(shmid: ::c_int,
cmd: ::c_int,
buf: *mut ::shmid_ds) -> ::c_int;
pub fn ftok(pathname: *const ::c_char, proj_id: ::c_int) -> ::key_t;
pub fn msgctl(msqid: ::c_int, cmd: ::c_int, buf: *mut msqid_ds) -> ::c_int;
pub fn msgget(key: ::key_t, msgflg: ::c_int) -> ::c_int;
pub fn msgrcv(msqid: ::c_int, msgp: *mut ::c_void, msgsz: ::size_t,
msgtyp: ::c_long, msgflg: ::c_int) -> ::ssize_t;
pub fn msgsnd(msqid: ::c_int, msgp: *const ::c_void, msgsz: ::size_t,
msgflg: ::c_int) -> ::c_int;

pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
-> ::c_int;
pub fn __errno_location() -> *mut ::c_int;
Expand Down
17 changes: 17 additions & 0 deletions src/unix/notbsd/linux/musl/b32/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ s! {
__pad2: ::c_ulong,
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
pub msg_stime: ::time_t,
__unused1: ::c_int,
pub msg_rtime: ::time_t,
__unused2: ::c_int,
pub msg_ctime: ::time_t,
__unused3: ::c_int,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__pad1: ::c_ulong,
__pad2: ::c_ulong,
}

pub struct statfs {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
Expand Down
17 changes: 17 additions & 0 deletions src/unix/notbsd/linux/musl/b32/asmjs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ s! {
__pad2: ::c_ulong,
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
pub msg_stime: ::time_t,
__unused1: ::c_int,
pub msg_rtime: ::time_t,
__unused2: ::c_int,
pub msg_ctime: ::time_t,
__unused3: ::c_int,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__pad1: ::c_ulong,
__pad2: ::c_ulong,
}

pub struct statfs {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
Expand Down
26 changes: 26 additions & 0 deletions src/unix/notbsd/linux/musl/b32/mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@ s! {
__pad2: ::c_ulong,
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
#[cfg(target_endian = "big")]
__unused1: ::c_int,
pub msg_stime: ::time_t,
#[cfg(target_endian = "little")]
__unused1: ::c_int,
#[cfg(target_endian = "big")]
__unused2: ::c_int,
pub msg_rtime: ::time_t,
#[cfg(target_endian = "little")]
__unused2: ::c_int,
#[cfg(target_endian = "big")]
__unused3: ::c_int,
pub msg_ctime: ::time_t,
#[cfg(target_endian = "little")]
__unused3: ::c_int,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__pad1: ::c_ulong,
__pad2: ::c_ulong,
}

pub struct statfs {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
Expand Down
17 changes: 17 additions & 0 deletions src/unix/notbsd/linux/musl/b32/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ s! {
__pad2: ::c_ulong,
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
pub msg_stime: ::time_t,
__unused1: ::c_int,
pub msg_rtime: ::time_t,
__unused2: ::c_int,
pub msg_ctime: ::time_t,
__unused3: ::c_int,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__pad1: ::c_ulong,
__pad2: ::c_ulong,
}

pub struct statfs {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
Expand Down
14 changes: 14 additions & 0 deletions src/unix/notbsd/linux/musl/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ s! {
__pad2: ::c_ulong,
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
pub msg_stime: ::time_t,
pub msg_rtime: ::time_t,
pub msg_ctime: ::time_t,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__pad1: ::c_ulong,
__pad2: ::c_ulong,
}

pub struct statfs {
pub f_type: ::c_ulong,
pub f_bsize: ::c_ulong,
Expand Down
17 changes: 17 additions & 0 deletions src/unix/notbsd/linux/other/b32/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ s! {
__unused4: ::c_ulong,
__unused5: ::c_ulong
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
pub msg_stime: ::time_t,
__glibc_reserved1: ::c_ulong,
pub msg_rtime: ::time_t,
__glibc_reserved2: ::c_ulong,
pub msg_ctime: ::time_t,
__glibc_reserved3: ::c_ulong,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__glibc_reserved4: ::c_ulong,
__glibc_reserved5: ::c_ulong,
}
}

pub const O_DIRECT: ::c_int = 0x10000;
Expand Down
17 changes: 17 additions & 0 deletions src/unix/notbsd/linux/other/b32/powerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ s! {
__glibc_reserved5: ::c_ulong,
__glibc_reserved6: ::c_ulong,
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
__glibc_reserved1: ::c_uint,
pub msg_stime: ::time_t,
__glibc_reserved2: ::c_uint,
pub msg_rtime: ::time_t,
__glibc_reserved3: ::c_uint,
pub msg_ctime: ::time_t,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__glibc_reserved4: ::c_ulong,
__glibc_reserved5: ::c_ulong,
}
}

pub const O_DIRECT: ::c_int = 0x20000;
Expand Down
17 changes: 17 additions & 0 deletions src/unix/notbsd/linux/other/b32/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ s! {
__unused4: ::c_ulong,
__unused5: ::c_ulong
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
pub msg_stime: ::time_t,
__glibc_reserved1: ::c_ulong,
pub msg_rtime: ::time_t,
__glibc_reserved2: ::c_ulong,
pub msg_ctime: ::time_t,
__glibc_reserved3: ::c_ulong,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__glibc_reserved4: ::c_ulong,
__glibc_reserved5: ::c_ulong,
}
}

pub const O_DIRECT: ::c_int = 0x4000;
Expand Down
14 changes: 14 additions & 0 deletions src/unix/notbsd/linux/other/b64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ s! {
pub mem_unit: ::c_uint,
pub _f: [::c_char; 0],
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
pub msg_stime: ::time_t,
pub msg_rtime: ::time_t,
pub msg_ctime: ::time_t,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__glibc_reserved4: ::c_ulong,
__glibc_reserved5: ::c_ulong,
}
}

pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;
Expand Down
1 change: 1 addition & 0 deletions src/unix/notbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub type speed_t = ::c_uint;
pub type tcflag_t = ::c_uint;
pub type loff_t = ::c_longlong;
pub type clockid_t = ::c_int;
pub type key_t = ::c_int;
pub type id_t = ::c_uint;

pub enum timezone {}
Expand Down

0 comments on commit 4548dc6

Please sign in to comment.