From 96fa9a67d63f1d27ab8e9db8d9d4adb3bd4ca0b7 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 9 Nov 2021 22:03:30 +0000 Subject: [PATCH] freebsd sem api addition --- libc-test/build.rs | 4 ++++ libc-test/semver/freebsd.txt | 5 +++++ src/unix/bsd/freebsdlike/freebsd/mod.rs | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 182dd5669f9a8..384ebdba499c3 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1844,6 +1844,7 @@ fn test_freebsd(target: &str) { "sys/random.h", "sys/resource.h", "sys/rtprio.h", + "sys/sem.h", "sys/shm.h", "sys/socket.h", "sys/stat.h", @@ -2175,6 +2176,9 @@ fn test_freebsd(target: &str) { // We ignore this field because we needed to use a hack in order to make rust 1.19 // happy... ("kinfo_proc", "ki_sparestrings") => true, + + // `__sem_base` is a private struct field + ("semid_ds", "__sem_base") => true, _ => false, } }); diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index 04359e1d9041f..e2b9aa8315496 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -1735,6 +1735,11 @@ sem_init sem_open sem_timedwait sem_unlink +sembuf +semctl +semget +semid_ds +semop sendfile sendmmsg sendmsg diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index ca9ad8a19072f..0374ff5edc59d 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -87,6 +87,11 @@ s! { pub struct _sem { data: [u32; 4], } + pub struct sembuf { + pub sem_num: ::c_ushort, + pub sem_op: ::c_short, + pub sem_flg: ::c_short, + } pub struct msqid_ds { pub msg_perm: ::ipc_perm, @@ -445,6 +450,18 @@ s! { pub n_type: ::c_uchar, pub n_value: ::kvaddr_t, } + + pub struct __c_anonymous_sem { + _priv: ::uintptr_t, + } + + pub struct semid_ds { + pub sem_perm: ::ipc_perm, + pub __sem_base: *mut __c_anonymous_sem, + pub sem_nsems: ::c_ushort, + pub sem_otime: ::time_t, + pub sem_ctime: ::time_t, + } } s_no_extra_traits! { @@ -2196,6 +2213,9 @@ extern "C" { 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 semget(key: ::key_t, nsems: ::c_int, semflg: ::c_int) -> ::c_int; + pub fn semctl(semid: ::c_int, semnum: ::c_int, cmd: ::c_int, ...) -> ::c_int; + pub fn semop(semid: ::c_int, sops: *mut sembuf, nsops: ::size_t) -> ::c_int; 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 msgsnd(