Skip to content

Commit 3f62e51

Browse files
committed
Add cr_pid to FreeBSD xucred - an unreleased addition in FreeBSD 13
definition: https://svnweb.freebsd.org/base/head/sys/sys/ucred.h?view=markup#l85 manpage: https://www.freebsd.org/cgi/man.cgi?query=unix&sektion=0&manpath=FreeBSD+13-current&format=html Continue comparing and hashing __cr_unused1 for backwards compatibility.
1 parent fe4be35 commit 3f62e51

File tree

4 files changed

+98
-9
lines changed

4 files changed

+98
-9
lines changed

libc-test/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,9 @@ fn test_freebsd(target: &str) {
18211821
});
18221822

18231823
cfg.skip_struct(move |ty| {
1824+
if ty.starts_with("__c_anonymous_") {
1825+
return true;
1826+
}
18241827
match ty {
18251828
// `mmsghdr` is not available in FreeBSD 10
18261829
"mmsghdr" if Some(10) == freebsd_ver => true,
@@ -1898,6 +1901,9 @@ fn test_freebsd(target: &str) {
18981901
("Elf32_Phdr", "p_type") => true,
18991902
("Elf64_Phdr", "p_type") => true,
19001903

1904+
// not available until FreeBSD 12, and is an anonymous union there.
1905+
("xucred", "cr_pid__c_anonymous_union") => true,
1906+
19011907
_ => false,
19021908
}
19031909
});

src/unix/bsd/freebsdlike/dragonfly/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ s! {
171171
pub sdl_route: [::c_ushort; 16],
172172
}
173173

174+
pub struct xucred {
175+
pub cr_version: ::c_uint,
176+
pub cr_uid: ::uid_t,
177+
pub cr_ngroups: ::c_short,
178+
pub cr_groups: [::gid_t; 16],
179+
__cr_unused1: *mut ::c_void,
180+
}
181+
174182
pub struct stack_t {
175183
pub ss_sp: *mut ::c_char,
176184
pub ss_size: ::size_t,
@@ -238,7 +246,6 @@ s_no_extra_traits! {
238246
pub sigev_value: ::sigval,
239247
__unused3: *mut ::c_void //actually a function pointer
240248
}
241-
242249
}
243250

244251
cfg_if! {

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ s_no_extra_traits! {
135135
pub __ut_spare: [::c_char; 64],
136136
}
137137

138+
#[cfg(libc_union)]
139+
pub union __c_anonymous_cr_pid {
140+
__cr_unused: *mut ::c_void,
141+
pub cr_pid: ::pid_t,
142+
}
143+
144+
pub struct xucred {
145+
pub cr_version: ::c_uint,
146+
pub cr_uid: ::uid_t,
147+
pub cr_ngroups: ::c_short,
148+
pub cr_groups: [::gid_t; 16],
149+
#[cfg(libc_union)]
150+
pub cr_pid__c_anonymous_union: __c_anonymous_cr_pid,
151+
#[cfg(not(libc_union))]
152+
__cr_unused1: *mut ::c_void,
153+
}
154+
138155
pub struct sockaddr_dl {
139156
pub sdl_len: ::c_uchar,
140157
pub sdl_family: ::c_uchar,
@@ -217,6 +234,73 @@ cfg_if! {
217234
}
218235
}
219236

237+
#[cfg(libc_union)]
238+
impl PartialEq for __c_anonymous_cr_pid {
239+
fn eq(&self, other: &__c_anonymous_cr_pid) -> bool {
240+
unsafe { self.cr_pid == other.cr_pid}
241+
}
242+
}
243+
#[cfg(libc_union)]
244+
impl Eq for __c_anonymous_cr_pid {}
245+
#[cfg(libc_union)]
246+
impl ::fmt::Debug for __c_anonymous_cr_pid {
247+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
248+
f.debug_struct("cr_pid")
249+
.field("cr_pid", unsafe { &self.cr_pid })
250+
.finish()
251+
}
252+
}
253+
#[cfg(libc_union)]
254+
impl ::hash::Hash for __c_anonymous_cr_pid {
255+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
256+
unsafe { self.cr_pid.hash(state) };
257+
}
258+
}
259+
260+
impl PartialEq for xucred {
261+
fn eq(&self, other: &xucred) -> bool {
262+
#[cfg(libc_union)]
263+
let equal_cr_pid = self.cr_pid__c_anonymous_union
264+
== other.cr_pid__c_anonymous_union;
265+
#[cfg(not(libc_union))]
266+
let equal_cr_pid = self.__cr_unused1 == other.__cr_unused1;
267+
268+
self.cr_version == other.cr_version
269+
&& self.cr_uid == other.cr_uid
270+
&& self.cr_ngroups == other.cr_ngroups
271+
&& self.cr_groups == other.cr_groups
272+
&& equal_cr_pid
273+
}
274+
}
275+
impl Eq for xucred {}
276+
impl ::fmt::Debug for xucred {
277+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
278+
let mut struct_formatter = f.debug_struct("xucred");
279+
struct_formatter.field("cr_version", &self.cr_version);
280+
struct_formatter.field("cr_uid", &self.cr_uid);
281+
struct_formatter.field("cr_ngroups", &self.cr_ngroups);
282+
struct_formatter.field("cr_groups", &self.cr_groups);
283+
#[cfg(libc_union)]
284+
struct_formatter.field(
285+
"cr_pid__c_anonymous_union",
286+
&self.cr_pid__c_anonymous_union
287+
);
288+
struct_formatter.finish()
289+
}
290+
}
291+
impl ::hash::Hash for xucred {
292+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
293+
self.cr_version.hash(state);
294+
self.cr_uid.hash(state);
295+
self.cr_ngroups.hash(state);
296+
self.cr_groups.hash(state);
297+
#[cfg(libc_union)]
298+
self.cr_pid__c_anonymous_union.hash(state);
299+
#[cfg(not(libc_union))]
300+
self.__cr_unused1.hash(state);
301+
}
302+
}
303+
220304
impl PartialEq for sockaddr_dl {
221305
fn eq(&self, other: &sockaddr_dl) -> bool {
222306
self.sdl_len == other.sdl_len

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,6 @@ s! {
219219
pub cmcred_groups: [::gid_t; CMGROUP_MAX],
220220
}
221221

222-
pub struct xucred {
223-
pub cr_version: ::c_uint,
224-
pub cr_uid: ::uid_t,
225-
pub cr_ngroups: ::c_short,
226-
pub cr_groups: [::gid_t; 16],
227-
__cr_unused1: *mut ::c_void,
228-
}
229-
230222
pub struct rtprio {
231223
pub type_: ::c_ushort,
232224
pub prio: ::c_ushort,

0 commit comments

Comments
 (0)