Skip to content

Commit bf32336

Browse files
committed
Auto merge of #1159 - cmbrandenburg:sysv_sem_support, r=alexcrichton
Add support for SysV semaphores on Apple platform
2 parents 01b2be3 + 7862f87 commit bf32336

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ matrix:
8888
- shellcheck --version
8989
- shellcheck ci/*.sh
9090

91+
allow_failures:
92+
- env: TARGET=aarch64-linux-android
93+
- env: TARGET=x86_64-linux-android
94+
9195
install: rustup target add $TARGET
9296
script:
9397
- cargo generate-lockfile --manifest-path libc-test/Cargo.toml

libc-test/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ fn main() {
186186
}
187187
cfg.header("netinet/in.h");
188188
cfg.header("sys/ipc.h");
189+
cfg.header("sys/sem.h");
189190
cfg.header("sys/shm.h");
190191

191192
if !ios {
@@ -453,7 +454,7 @@ fn main() {
453454
// Fixed on feature=align with repr(packed(4))
454455
// Once repr_packed stabilizes we can fix this unconditionally
455456
// and remove this check.
456-
"kevent" | "shmid_ds" if apple && x86_64 => true,
457+
"kevent" | "shmid_ds" | "semid_ds" if apple && x86_64 => true,
457458

458459
// This is actually a union, not a struct
459460
"sigval" => true,

src/unix/bsd/apple/mod.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,35 @@ s! {
535535
pub _key: ::key_t,
536536
}
537537

538+
// sys/sem.h
539+
540+
pub struct sembuf {
541+
pub sem_num: ::c_ushort,
542+
pub sem_op: ::c_short,
543+
pub sem_flg: ::c_short,
544+
}
545+
546+
#[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))]
547+
pub struct semid_ds {
548+
// Note the manpage shows different types than the system header.
549+
pub sem_perm: ipc_perm,
550+
pub sem_base: ::int32_t,
551+
pub sem_nsems: ::c_ushort,
552+
pub sem_otime: ::time_t,
553+
pub sem_pad1: ::int32_t,
554+
pub sem_ctime: ::time_t,
555+
pub sem_pad2: ::int32_t,
556+
pub sem_pad3: [::int32_t; 4],
557+
}
558+
559+
pub union semun {
560+
pub val: ::c_int,
561+
pub buf: *mut semid_ds,
562+
pub array: *mut ::c_ushort,
563+
}
564+
565+
// sys/shm.h
566+
538567
#[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))]
539568
pub struct shmid_ds {
540569
pub shm_perm: ipc_perm,
@@ -2297,6 +2326,17 @@ pub const IPC_R: ::c_int = 0x100;
22972326
pub const IPC_W: ::c_int = 0x80;
22982327
pub const IPC_M: ::c_int = 0x1000;
22992328

2329+
// sys/sem.h
2330+
pub const SEM_UNDO: ::c_int = 0o10000;
2331+
2332+
pub const GETNCNT: ::c_int = 3;
2333+
pub const GETPID: ::c_int = 4;
2334+
pub const GETVAL: ::c_int = 5;
2335+
pub const GETALL: ::c_int = 6;
2336+
pub const GETZCNT: ::c_int = 7;
2337+
pub const SETVAL: ::c_int = 8;
2338+
pub const SETALL: ::c_int = 9;
2339+
23002340
// sys/shm.h
23012341
pub const SHM_RDONLY: ::c_int = 0x1000;
23022342
pub const SHM_RND: ::c_int = 0x2000;
@@ -2387,6 +2427,13 @@ extern {
23872427
link_name = "mprotect$UNIX2003")]
23882428
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
23892429
-> ::c_int;
2430+
pub fn semget(key: key_t, nsems: ::c_int, semflg: ::c_int) -> ::c_int;
2431+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
2432+
link_name = "semctl$UNIX2003")]
2433+
pub fn semctl(semid: ::c_int,
2434+
semnum: ::c_int,
2435+
cmd: ::c_int, ...) -> ::c_int;
2436+
pub fn semop(semid: ::c_int, sops: *mut sembuf, nsops: ::size_t) -> ::c_int;
23902437
pub fn shm_open(name: *const ::c_char, oflag: ::c_int, ...) -> ::c_int;
23912438
pub fn ftok(pathname : *const c_char, proj_id : ::c_int) -> key_t;
23922439
pub fn shmat(shmid: ::c_int, shmaddr: *const ::c_void,

0 commit comments

Comments
 (0)