From c752ed0a37409d3b51684a68f5f42d5aea25485a Mon Sep 17 00:00:00 2001 From: DC Date: Tue, 17 Aug 2021 20:27:26 +0100 Subject: [PATCH] freebsd auxiliary vectors type addition --- libc-test/build.rs | 7 +- libc-test/semver/freebsd.txt | 16 ++++ src/unix/bsd/freebsdlike/freebsd/mod.rs | 105 ++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index a4f65ba0e9247..b2bc6740f70e7 100755 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1744,6 +1744,7 @@ fn test_freebsd(target: &str) { "limits.h", "link.h", "locale.h", + "machine/elf.h", "machine/reg.h", "malloc_np.h", "mqueue.h", @@ -1818,7 +1819,8 @@ fn test_freebsd(target: &str) { cfg.type_name(move |ty, is_struct, is_union| { match ty { // Just pass all these through, no need for a "struct" prefix - "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" | "Elf64_Phdr" => ty.to_string(), + "FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr" | "Elf64_Phdr" + | "Elf32_Auxinfo" | "Elf64_Auxinfo" => ty.to_string(), // FIXME: https://github.com/rust-lang/libc/issues/1273 "sighandler_t" => "sig_t".to_string(), @@ -2036,6 +2038,9 @@ fn test_freebsd(target: &str) { // is PATH_MAX long but tests can't accept multi array as equivalent. ("kinfo_vmentry", "kve_path") => true, + // a_un field is a union + ("Elf32_Auxinfo", "a_un") => true, + ("Elf64_Auxinfo", "a_un") => true, _ => false, } }); diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index 497687a0e49d3..a5838c61e0215 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -76,11 +76,25 @@ ATF_COM ATF_PERM ATF_PUBL ATF_USETRAILERS +AT_BASE AT_EACCESS +AT_EGID +AT_ENTRY +AT_EUID +AT_EXECPATH AT_FDCWD +AT_FLAGS +AT_GID +AT_NOTELF +AT_NULL +AT_PAGESZ +AT_PHDR +AT_PHENT +AT_PHNUM AT_REMOVEDIR AT_SYMLINK_FOLLOW AT_SYMLINK_NOFOLLOW +AT_UID B14400 B28800 B460800 @@ -269,6 +283,7 @@ EXTATTR_NAMESPACE_USER EXTB EXTPROC Elf32_Addr +Elf32_Auxinfo Elf32_Half Elf32_Lword Elf32_Off @@ -276,6 +291,7 @@ Elf32_Phdr Elf32_Sword Elf32_Word Elf64_Addr +Elf64_Auxinfo Elf64_Half Elf64_Lword Elf64_Off diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index f75970ed5c0b0..98976d53e40f1 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -266,6 +266,30 @@ s_no_extra_traits! { __unused1: ::c_int, __unused2: [::c_long; 7] } + + #[cfg(libc_union)] + pub union __c_anonymous_elf32_auxv_union { + pub a_val: ::c_int, + } + + #[cfg(libc_union)] + pub union __c_anonymous_elf64_auxv_union { + pub a_val: ::c_long, + pub a_ptr: *mut ::c_void, + pub a_fcn: extern "C" fn(), + } + + pub struct Elf32_Auxinfo { + pub a_type: ::c_int, + #[cfg(libc_union)] + pub a_un: __c_anonymous_elf32_auxv_union, + } + + pub struct Elf64_Auxinfo { + pub a_type: ::c_long, + #[cfg(libc_union)] + pub a_un: __c_anonymous_elf64_auxv_union, + } } cfg_if! { @@ -486,6 +510,70 @@ cfg_if! { self.sigev_notify_thread_id.hash(state); } } + #[cfg(libc_union)] + impl PartialEq for __c_anonymous_elf32_auxv_union { + fn eq(&self, other: &__c_anonymous_elf32_auxv_union) -> bool { + unsafe { self.a_val == other.a_val} + } + } + #[cfg(libc_union)] + impl Eq for __c_anonymous_elf32_auxv_union {} + #[cfg(libc_union)] + impl ::fmt::Debug for __c_anonymous_elf32_auxv_union { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("a_val") + .field("a_val", unsafe { &self.a_val }) + .finish() + } + } + impl PartialEq for Elf32_Auxinfo { + fn eq(&self, other: &Elf32_Auxinfo) -> bool { + self.a_type == other.a_type + && self.a_un == other.a_un + } + } + impl Eq for Elf32_Auxinfo {} + impl ::fmt::Debug for Elf32_Auxinfo { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("Elf32_Auxinfo") + .field("a_type", &self.a_type) + .field("a_un", &self.a_un) + .finish() + } + } + #[cfg(libc_union)] + impl PartialEq for __c_anonymous_elf64_auxv_union { + fn eq(&self, other: &__c_anonymous_elf64_auxv_union) -> bool { + unsafe { self.a_val == other.a_val + || self.a_ptr == other.a_ptr + || self.a_fcn == other.a_fcn } + } + } + #[cfg(libc_union)] + impl Eq for __c_anonymous_elf64_auxv_union {} + #[cfg(libc_union)] + impl ::fmt::Debug for __c_anonymous_elf64_auxv_union { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("a_val") + .field("a_val", unsafe { &self.a_val }) + .finish() + } + } + impl PartialEq for Elf64_Auxinfo { + fn eq(&self, other: &Elf64_Auxinfo) -> bool { + self.a_type == other.a_type + && self.a_un == other.a_un + } + } + impl Eq for Elf64_Auxinfo {} + impl ::fmt::Debug for Elf64_Auxinfo { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("Elf64_Auxinfo") + .field("a_type", &self.a_type) + .field("a_un", &self.a_un) + .finish() + } + } } } @@ -1266,6 +1354,23 @@ pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x200; pub const AT_SYMLINK_FOLLOW: ::c_int = 0x400; pub const AT_REMOVEDIR: ::c_int = 0x800; +pub const AT_NULL: ::c_int = 0; +pub const AT_IGNORE: ::c_int = 1; +pub const AT_EXECFD: ::c_int = 2; +pub const AT_PHDR: ::c_int = 3; +pub const AT_PHENT: ::c_int = 4; +pub const AT_PHNUM: ::c_int = 5; +pub const AT_PAGESZ: ::c_int = 6; +pub const AT_BASE: ::c_int = 7; +pub const AT_FLAGS: ::c_int = 8; +pub const AT_ENTRY: ::c_int = 9; +pub const AT_NOTELF: ::c_int = 10; +pub const AT_UID: ::c_int = 11; +pub const AT_EUID: ::c_int = 12; +pub const AT_GID: ::c_int = 13; +pub const AT_EGID: ::c_int = 14; +pub const AT_EXECPATH: ::c_int = 15; + pub const TABDLY: ::tcflag_t = 0x00000004; pub const TAB0: ::tcflag_t = 0x00000000; pub const TAB3: ::tcflag_t = 0x00000004;