Skip to content

Commit 4548dc6

Browse files
authored
Auto merge of rust-lang#401 - alexander255:master, r=alexcrichton
Add System V message queue bindings for Linux (glibc/musl)
2 parents e3d05ca + 7590565 commit 4548dc6

File tree

15 files changed

+234
-3
lines changed

15 files changed

+234
-3
lines changed

libc-test/Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libc-test/build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ fn main() {
160160
cfg.header("sys/signalfd.h");
161161
cfg.header("sys/xattr.h");
162162
cfg.header("sys/ipc.h");
163+
cfg.header("sys/msg.h");
163164
cfg.header("sys/shm.h");
164165
cfg.header("pty.h");
165166
}
@@ -332,7 +333,8 @@ fn main() {
332333
// kernel regardless
333334
"RLIMIT_NLIMITS" |
334335
"TCP_COOKIE_TRANSACTIONS" |
335-
"RLIMIT_RTTIME" if musl => true,
336+
"RLIMIT_RTTIME" |
337+
"MSG_COPY" if musl => true,
336338
// work around super old mips toolchain
337339
"SCHED_IDLE" | "SHM_NORESERVE" => mips,
338340

src/unix/notbsd/linux/mips.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,32 @@ s! {
129129
__unused5: ::c_ulong
130130
}
131131

132+
pub struct msqid_ds {
133+
pub msg_perm: ::ipc_perm,
134+
#[cfg(target_endian = "big")]
135+
__glibc_reserved1: ::c_ulong,
136+
pub msg_stime: ::time_t,
137+
#[cfg(target_endian = "little")]
138+
__glibc_reserved1: ::c_ulong,
139+
#[cfg(target_endian = "big")]
140+
__glibc_reserved2: ::c_ulong,
141+
pub msg_rtime: ::time_t,
142+
#[cfg(target_endian = "little")]
143+
__glibc_reserved2: ::c_ulong,
144+
#[cfg(target_endian = "big")]
145+
__glibc_reserved3: ::c_ulong,
146+
pub msg_ctime: ::time_t,
147+
#[cfg(target_endian = "little")]
148+
__glibc_reserved3: ::c_ulong,
149+
__msg_cbytes: ::c_ulong,
150+
pub msg_qnum: ::msgqnum_t,
151+
pub msg_qbytes: ::msglen_t,
152+
pub msg_lspid: ::pid_t,
153+
pub msg_lrpid: ::pid_t,
154+
__glibc_reserved4: ::c_ulong,
155+
__glibc_reserved5: ::c_ulong,
156+
}
157+
132158
pub struct statfs {
133159
pub f_type: ::c_long,
134160
pub f_bsize: ::c_long,

src/unix/notbsd/linux/mips64.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ s! {
116116
__unused5: ::c_ulong
117117
}
118118

119+
pub struct msqid_ds {
120+
pub msg_perm: ::ipc_perm,
121+
pub msg_stime: ::time_t,
122+
pub msg_rtime: ::time_t,
123+
pub msg_ctime: ::time_t,
124+
__msg_cbytes: ::c_ulong,
125+
pub msg_qnum: ::msgqnum_t,
126+
pub msg_qbytes: ::msglen_t,
127+
pub msg_lspid: ::pid_t,
128+
pub msg_lrpid: ::pid_t,
129+
__glibc_reserved4: ::c_ulong,
130+
__glibc_reserved5: ::c_ulong,
131+
}
132+
119133
pub struct statfs {
120134
pub f_type: ::c_long,
121135
pub f_bsize: ::c_long,

src/unix/notbsd/linux/mod.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ pub type ino64_t = u64;
1111
pub type off64_t = i64;
1212
pub type blkcnt64_t = i64;
1313
pub type rlim64_t = u64;
14-
pub type key_t = ::c_int;
1514
pub type shmatt_t = ::c_ulong;
1615
pub type mqd_t = ::c_int;
16+
pub type msgqnum_t = ::c_ulong;
17+
pub type msglen_t = ::c_ulong;
1718
pub type nfds_t = ::c_ulong;
1819
pub type nl_item = ::c_int;
1920

@@ -190,6 +191,17 @@ s! {
190191
pub if_name: *mut ::c_char,
191192
}
192193

194+
// System V IPC
195+
pub struct msginfo {
196+
pub msgpool: ::c_int,
197+
pub msgmap: ::c_int,
198+
pub msgmax: ::c_int,
199+
pub msgmnb: ::c_int,
200+
pub msgmni: ::c_int,
201+
pub msgssz: ::c_int,
202+
pub msgtql: ::c_int,
203+
pub msgseg: ::c_ushort,
204+
}
193205
}
194206

195207
pub const ABDAY_1: ::nl_item = 0x20000;
@@ -430,6 +442,9 @@ pub const SCHED_RR: ::c_int = 2;
430442
pub const SCHED_BATCH: ::c_int = 3;
431443
pub const SCHED_IDLE: ::c_int = 5;
432444

445+
// System V IPC
446+
pub const IPC_PRIVATE: ::key_t = 0;
447+
433448
pub const IPC_CREAT: ::c_int = 0o1000;
434449
pub const IPC_EXCL: ::c_int = 0o2000;
435450
pub const IPC_NOWAIT: ::c_int = 0o4000;
@@ -438,6 +453,12 @@ pub const IPC_RMID: ::c_int = 0;
438453
pub const IPC_SET: ::c_int = 1;
439454
pub const IPC_STAT: ::c_int = 2;
440455
pub const IPC_INFO: ::c_int = 3;
456+
pub const MSG_STAT: ::c_int = 11;
457+
pub const MSG_INFO: ::c_int = 12;
458+
459+
pub const MSG_NOERROR: ::c_int = 0o10000;
460+
pub const MSG_EXCEPT: ::c_int = 0o20000;
461+
pub const MSG_COPY: ::c_int = 0o40000;
441462

442463
pub const SHM_R: ::c_int = 0o400;
443464
pub const SHM_W: ::c_int = 0o200;
@@ -522,6 +543,8 @@ extern {
522543
pub fn getpwent() -> *mut passwd;
523544
pub fn shm_open(name: *const c_char, oflag: ::c_int,
524545
mode: mode_t) -> ::c_int;
546+
547+
// System V IPC
525548
pub fn shmget(key: ::key_t, size: ::size_t, shmflg: ::c_int) -> ::c_int;
526549
pub fn shmat(shmid: ::c_int,
527550
shmaddr: *const ::c_void,
@@ -530,6 +553,14 @@ extern {
530553
pub fn shmctl(shmid: ::c_int,
531554
cmd: ::c_int,
532555
buf: *mut ::shmid_ds) -> ::c_int;
556+
pub fn ftok(pathname: *const ::c_char, proj_id: ::c_int) -> ::key_t;
557+
pub fn msgctl(msqid: ::c_int, cmd: ::c_int, buf: *mut msqid_ds) -> ::c_int;
558+
pub fn msgget(key: ::key_t, msgflg: ::c_int) -> ::c_int;
559+
pub fn msgrcv(msqid: ::c_int, msgp: *mut ::c_void, msgsz: ::size_t,
560+
msgtyp: ::c_long, msgflg: ::c_int) -> ::ssize_t;
561+
pub fn msgsnd(msqid: ::c_int, msgp: *const ::c_void, msgsz: ::size_t,
562+
msgflg: ::c_int) -> ::c_int;
563+
533564
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
534565
-> ::c_int;
535566
pub fn __errno_location() -> *mut ::c_int;

src/unix/notbsd/linux/musl/b32/arm.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ s! {
6868
__pad2: ::c_ulong,
6969
}
7070

71+
pub struct msqid_ds {
72+
pub msg_perm: ::ipc_perm,
73+
pub msg_stime: ::time_t,
74+
__unused1: ::c_int,
75+
pub msg_rtime: ::time_t,
76+
__unused2: ::c_int,
77+
pub msg_ctime: ::time_t,
78+
__unused3: ::c_int,
79+
__msg_cbytes: ::c_ulong,
80+
pub msg_qnum: ::msgqnum_t,
81+
pub msg_qbytes: ::msglen_t,
82+
pub msg_lspid: ::pid_t,
83+
pub msg_lrpid: ::pid_t,
84+
__pad1: ::c_ulong,
85+
__pad2: ::c_ulong,
86+
}
87+
7188
pub struct statfs {
7289
pub f_type: ::c_ulong,
7390
pub f_bsize: ::c_ulong,

src/unix/notbsd/linux/musl/b32/asmjs.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ s! {
6868
__pad2: ::c_ulong,
6969
}
7070

71+
pub struct msqid_ds {
72+
pub msg_perm: ::ipc_perm,
73+
pub msg_stime: ::time_t,
74+
__unused1: ::c_int,
75+
pub msg_rtime: ::time_t,
76+
__unused2: ::c_int,
77+
pub msg_ctime: ::time_t,
78+
__unused3: ::c_int,
79+
__msg_cbytes: ::c_ulong,
80+
pub msg_qnum: ::msgqnum_t,
81+
pub msg_qbytes: ::msglen_t,
82+
pub msg_lspid: ::pid_t,
83+
pub msg_lrpid: ::pid_t,
84+
__pad1: ::c_ulong,
85+
__pad2: ::c_ulong,
86+
}
87+
7188
pub struct statfs {
7289
pub f_type: ::c_ulong,
7390
pub f_bsize: ::c_ulong,

src/unix/notbsd/linux/musl/b32/mips.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,32 @@ s! {
6767
__pad2: ::c_ulong,
6868
}
6969

70+
pub struct msqid_ds {
71+
pub msg_perm: ::ipc_perm,
72+
#[cfg(target_endian = "big")]
73+
__unused1: ::c_int,
74+
pub msg_stime: ::time_t,
75+
#[cfg(target_endian = "little")]
76+
__unused1: ::c_int,
77+
#[cfg(target_endian = "big")]
78+
__unused2: ::c_int,
79+
pub msg_rtime: ::time_t,
80+
#[cfg(target_endian = "little")]
81+
__unused2: ::c_int,
82+
#[cfg(target_endian = "big")]
83+
__unused3: ::c_int,
84+
pub msg_ctime: ::time_t,
85+
#[cfg(target_endian = "little")]
86+
__unused3: ::c_int,
87+
__msg_cbytes: ::c_ulong,
88+
pub msg_qnum: ::msgqnum_t,
89+
pub msg_qbytes: ::msglen_t,
90+
pub msg_lspid: ::pid_t,
91+
pub msg_lrpid: ::pid_t,
92+
__pad1: ::c_ulong,
93+
__pad2: ::c_ulong,
94+
}
95+
7096
pub struct statfs {
7197
pub f_type: ::c_ulong,
7298
pub f_bsize: ::c_ulong,

src/unix/notbsd/linux/musl/b32/x86.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ s! {
6868
__pad2: ::c_ulong,
6969
}
7070

71+
pub struct msqid_ds {
72+
pub msg_perm: ::ipc_perm,
73+
pub msg_stime: ::time_t,
74+
__unused1: ::c_int,
75+
pub msg_rtime: ::time_t,
76+
__unused2: ::c_int,
77+
pub msg_ctime: ::time_t,
78+
__unused3: ::c_int,
79+
__msg_cbytes: ::c_ulong,
80+
pub msg_qnum: ::msgqnum_t,
81+
pub msg_qbytes: ::msglen_t,
82+
pub msg_lspid: ::pid_t,
83+
pub msg_lrpid: ::pid_t,
84+
__pad1: ::c_ulong,
85+
__pad2: ::c_ulong,
86+
}
87+
7188
pub struct statfs {
7289
pub f_type: ::c_ulong,
7390
pub f_bsize: ::c_ulong,

src/unix/notbsd/linux/musl/b64/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ s! {
7373
__pad2: ::c_ulong,
7474
}
7575

76+
pub struct msqid_ds {
77+
pub msg_perm: ::ipc_perm,
78+
pub msg_stime: ::time_t,
79+
pub msg_rtime: ::time_t,
80+
pub msg_ctime: ::time_t,
81+
__msg_cbytes: ::c_ulong,
82+
pub msg_qnum: ::msgqnum_t,
83+
pub msg_qbytes: ::msglen_t,
84+
pub msg_lspid: ::pid_t,
85+
pub msg_lrpid: ::pid_t,
86+
__pad1: ::c_ulong,
87+
__pad2: ::c_ulong,
88+
}
89+
7690
pub struct statfs {
7791
pub f_type: ::c_ulong,
7892
pub f_bsize: ::c_ulong,

src/unix/notbsd/linux/other/b32/arm.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ s! {
5353
__unused4: ::c_ulong,
5454
__unused5: ::c_ulong
5555
}
56+
57+
pub struct msqid_ds {
58+
pub msg_perm: ::ipc_perm,
59+
pub msg_stime: ::time_t,
60+
__glibc_reserved1: ::c_ulong,
61+
pub msg_rtime: ::time_t,
62+
__glibc_reserved2: ::c_ulong,
63+
pub msg_ctime: ::time_t,
64+
__glibc_reserved3: ::c_ulong,
65+
__msg_cbytes: ::c_ulong,
66+
pub msg_qnum: ::msgqnum_t,
67+
pub msg_qbytes: ::msglen_t,
68+
pub msg_lspid: ::pid_t,
69+
pub msg_lrpid: ::pid_t,
70+
__glibc_reserved4: ::c_ulong,
71+
__glibc_reserved5: ::c_ulong,
72+
}
5673
}
5774

5875
pub const O_DIRECT: ::c_int = 0x10000;

src/unix/notbsd/linux/other/b32/powerpc.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ s! {
5353
__glibc_reserved5: ::c_ulong,
5454
__glibc_reserved6: ::c_ulong,
5555
}
56+
57+
pub struct msqid_ds {
58+
pub msg_perm: ::ipc_perm,
59+
__glibc_reserved1: ::c_uint,
60+
pub msg_stime: ::time_t,
61+
__glibc_reserved2: ::c_uint,
62+
pub msg_rtime: ::time_t,
63+
__glibc_reserved3: ::c_uint,
64+
pub msg_ctime: ::time_t,
65+
__msg_cbytes: ::c_ulong,
66+
pub msg_qnum: ::msgqnum_t,
67+
pub msg_qbytes: ::msglen_t,
68+
pub msg_lspid: ::pid_t,
69+
pub msg_lrpid: ::pid_t,
70+
__glibc_reserved4: ::c_ulong,
71+
__glibc_reserved5: ::c_ulong,
72+
}
5673
}
5774

5875
pub const O_DIRECT: ::c_int = 0x20000;

src/unix/notbsd/linux/other/b32/x86.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ s! {
8787
__unused4: ::c_ulong,
8888
__unused5: ::c_ulong
8989
}
90+
91+
pub struct msqid_ds {
92+
pub msg_perm: ::ipc_perm,
93+
pub msg_stime: ::time_t,
94+
__glibc_reserved1: ::c_ulong,
95+
pub msg_rtime: ::time_t,
96+
__glibc_reserved2: ::c_ulong,
97+
pub msg_ctime: ::time_t,
98+
__glibc_reserved3: ::c_ulong,
99+
__msg_cbytes: ::c_ulong,
100+
pub msg_qnum: ::msgqnum_t,
101+
pub msg_qbytes: ::msglen_t,
102+
pub msg_lspid: ::pid_t,
103+
pub msg_lrpid: ::pid_t,
104+
__glibc_reserved4: ::c_ulong,
105+
__glibc_reserved5: ::c_ulong,
106+
}
90107
}
91108

92109
pub const O_DIRECT: ::c_int = 0x4000;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ s! {
3131
pub mem_unit: ::c_uint,
3232
pub _f: [::c_char; 0],
3333
}
34+
35+
pub struct msqid_ds {
36+
pub msg_perm: ::ipc_perm,
37+
pub msg_stime: ::time_t,
38+
pub msg_rtime: ::time_t,
39+
pub msg_ctime: ::time_t,
40+
__msg_cbytes: ::c_ulong,
41+
pub msg_qnum: ::msgqnum_t,
42+
pub msg_qbytes: ::msglen_t,
43+
pub msg_lspid: ::pid_t,
44+
pub msg_lrpid: ::pid_t,
45+
__glibc_reserved4: ::c_ulong,
46+
__glibc_reserved5: ::c_ulong,
47+
}
3448
}
3549

3650
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56;

src/unix/notbsd/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub type speed_t = ::c_uint;
66
pub type tcflag_t = ::c_uint;
77
pub type loff_t = ::c_longlong;
88
pub type clockid_t = ::c_int;
9+
pub type key_t = ::c_int;
910
pub type id_t = ::c_uint;
1011

1112
pub enum timezone {}

0 commit comments

Comments
 (0)