From 9a319349280f8458882c6196718cd74ded6b8c1e Mon Sep 17 00:00:00 2001 From: David Carlier Date: Thu, 29 Feb 2024 20:05:44 +0000 Subject: [PATCH 1/4] adding few android api 30 calls. close #3598. (backport ) (cherry picked from commit 7de90611bb9268b7f87444d39b5efc02b263efac) --- libc-test/build.rs | 2 +- libc-test/semver/android.txt | 5 ++ src/unix/linux_like/android/b32/mod.rs | 1 + .../linux_like/android/b64/aarch64/mod.rs | 1 + .../linux_like/android/b64/riscv64/mod.rs | 1 + src/unix/linux_like/android/b64/x86_64/mod.rs | 1 + src/unix/linux_like/android/mod.rs | 50 ++++++++++++++++++- 7 files changed, 59 insertions(+), 2 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index c4b344f41b028..6b3e6abb166c3 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2075,7 +2075,7 @@ fn test_android(target: &str) { "__system_property_wait" => true, // Added in API level 30, but tests use level 28. - "mlock2" => true, + "memfd_create" | "mlock2" | "renameat2" | "statx" | "statx_timestamp" => true, // Added in glibc 2.25. "getentropy" => true, diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index 2c49d75c4466f..06a28efaac820 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -3469,6 +3469,7 @@ memalign memchr memcmp memcpy +memfd_create memmem memmove memrchr @@ -3484,6 +3485,7 @@ mknodat mkstemp mktime mlock +mlock2 mlockall mmap mmap64 @@ -3672,6 +3674,7 @@ remove removexattr rename renameat +renameat2 res_init rewind rewinddir @@ -3797,6 +3800,8 @@ statfs statfs64 statvfs statvfs64 +statx +statx_timestamp strcasecmp strcasestr strcat diff --git a/src/unix/linux_like/android/b32/mod.rs b/src/unix/linux_like/android/b32/mod.rs index 1f4f796f2a94a..aa29267f9db50 100644 --- a/src/unix/linux_like/android/b32/mod.rs +++ b/src/unix/linux_like/android/b32/mod.rs @@ -9,6 +9,7 @@ pub type sigset_t = ::c_ulong; pub type socklen_t = i32; pub type time64_t = i64; pub type __u64 = ::c_ulonglong; +pub type __s64 = ::c_longlong; s! { pub struct sigaction { diff --git a/src/unix/linux_like/android/b64/aarch64/mod.rs b/src/unix/linux_like/android/b64/aarch64/mod.rs index 0d6f32ee3989c..9587770e8cb2c 100644 --- a/src/unix/linux_like/android/b64/aarch64/mod.rs +++ b/src/unix/linux_like/android/b64/aarch64/mod.rs @@ -1,6 +1,7 @@ pub type c_char = u8; pub type wchar_t = u32; pub type __u64 = ::c_ulonglong; +pub type __s64 = ::c_longlong; s! { pub struct stat { diff --git a/src/unix/linux_like/android/b64/riscv64/mod.rs b/src/unix/linux_like/android/b64/riscv64/mod.rs index 0251804691fd6..82a3aa62f51a5 100644 --- a/src/unix/linux_like/android/b64/riscv64/mod.rs +++ b/src/unix/linux_like/android/b64/riscv64/mod.rs @@ -2,6 +2,7 @@ pub type c_char = i8; pub type wchar_t = u32; pub type greg_t = i64; pub type __u64 = ::c_ulonglong; +pub type __s64 = ::c_longlong; s! { pub struct stat { diff --git a/src/unix/linux_like/android/b64/x86_64/mod.rs b/src/unix/linux_like/android/b64/x86_64/mod.rs index f871fb2cd4a61..57a41a224fe2c 100644 --- a/src/unix/linux_like/android/b64/x86_64/mod.rs +++ b/src/unix/linux_like/android/b64/x86_64/mod.rs @@ -2,6 +2,7 @@ pub type c_char = i8; pub type wchar_t = i32; pub type greg_t = i64; pub type __u64 = ::c_ulonglong; +pub type __s64 = ::c_longlong; s! { pub struct stat { diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 75f8a7877b617..3e30ce5bb17cf 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -514,8 +514,40 @@ s! { pub ifr6_addr: ::in6_addr, pub ifr6_prefixlen: u32, pub ifr6_ifindex: ::c_int, - } + } + + pub struct statx { + pub stx_mask: ::__u32, + pub stx_blksize: ::__u32, + pub stx_attributes: ::__u64, + pub stx_nlink: ::__u32, + pub stx_uid: ::__u32, + pub stx_gid: ::__u32, + pub stx_mode: ::__u16, + __statx_pad1: [::__u16; 1], + pub stx_ino: ::__u64, + pub stx_size: ::__u64, + pub stx_blocks: ::__u64, + pub stx_attributes_mask: ::__u64, + pub stx_atime: ::statx_timestamp, + pub stx_btime: ::statx_timestamp, + pub stx_ctime: ::statx_timestamp, + pub stx_mtime: ::statx_timestamp, + pub stx_rdev_major: ::__u32, + pub stx_rdev_minor: ::__u32, + pub stx_dev_major: ::__u32, + pub stx_dev_minor: ::__u32, + pub stx_mnt_id: ::__u64, + pub stx_dio_mem_align: ::__u32, + pub stx_dio_offset_align: ::__u32, + __statx_pad3: [::__u64; 12], + } + pub struct statx_timestamp { + pub tv_sec: ::__s64, + pub tv_nsec: ::__u32, + pub __reserved: ::__s32, + } } s_no_extra_traits! { @@ -4169,6 +4201,22 @@ extern "C" { pub fn fgets_unlocked(buf: *mut ::c_char, size: ::c_int, stream: *mut ::FILE) -> *mut ::c_char; pub fn klogctl(syslog_type: ::c_int, bufp: *mut ::c_char, len: ::c_int) -> ::c_int; + + pub fn memfd_create(name: *const ::c_char, flags: ::c_uint) -> ::c_int; + pub fn renameat2( + olddirfd: ::c_int, + oldpath: *const ::c_char, + newdirfd: ::c_int, + newpath: *const ::c_char, + flags: ::c_uint, + ) -> ::c_int; + pub fn statx( + dirfd: ::c_int, + pathname: *const c_char, + flags: ::c_int, + mask: ::c_uint, + statxbuf: *mut statx, + ) -> ::c_int; } cfg_if! { From b190462ddb90527b2356c532ac708091b6f8efcf Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 16 Aug 2024 21:38:13 +0100 Subject: [PATCH 2/4] adding aligned_alloc support for unixes. close #3689 (backport ) (cherry picked from commit f136b309a9c6128ffe7ca6dec7043b1f31a8e80e) --- libc-test/semver/unix.txt | 1 + src/unix/mod.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/libc-test/semver/unix.txt b/libc-test/semver/unix.txt index 6a18038c48ae3..093dde173137c 100644 --- a/libc-test/semver/unix.txt +++ b/libc-test/semver/unix.txt @@ -453,6 +453,7 @@ accept access addrinfo alarm +aligned_alloc atexit atof atoi diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 0a290b734a3d1..ebbf42d8140e2 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -940,6 +940,7 @@ extern "C" { pub fn pathconf(path: *const c_char, name: ::c_int) -> c_long; pub fn pipe(fds: *mut ::c_int) -> ::c_int; pub fn posix_memalign(memptr: *mut *mut ::c_void, align: ::size_t, size: ::size_t) -> ::c_int; + pub fn aligned_alloc(alignment: ::size_t, size: ::size_t) -> *mut ::c_void; #[cfg_attr( all(target_os = "macos", target_arch = "x86"), link_name = "read$UNIX2003" From 602f03954a04d3cbc6685c2af9ccf891a973d74c Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 18 Nov 2024 05:03:54 -0500 Subject: [PATCH 3/4] Small syncs from `main` to `libc-0.2` --- src/fuchsia/mod.rs | 2 +- src/lib.rs | 2 ++ src/macros.rs | 2 +- src/unix/aix/mod.rs | 8 ++++---- src/unix/aix/powerpc64.rs | 16 ++++++++-------- src/unix/bsd/apple/mod.rs | 6 ++---- src/unix/bsd/mod.rs | 6 +++--- src/unix/bsd/netbsdlike/netbsd/aarch64.rs | 1 + src/unix/linux_like/mod.rs | 2 +- src/unix/newlib/mod.rs | 2 +- src/unix/nto/mod.rs | 2 +- src/unix/redox/mod.rs | 2 +- src/unix/solarish/mod.rs | 4 ++-- 13 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index c4c7e6544b21b..ce274f2261279 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -382,7 +382,7 @@ s! { } pub struct fd_set { - fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], + fds_bits: [::c_ulong; FD_SETSIZE as usize / ULONG_SIZE], } pub struct tm { diff --git a/src/lib.rs b/src/lib.rs index 4f4cedb62f925..8af17cb0cb582 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,8 @@ cfg_if! { #[allow(unused_imports)] use core::clone::Clone; #[allow(unused_imports)] +use core::ffi; +#[allow(unused_imports)] use core::fmt; #[allow(unused_imports)] use core::hash; diff --git a/src/macros.rs b/src/macros.rs index ff8afee32281a..2661e0fb13827 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -98,7 +98,7 @@ macro_rules! s_paren { ($( $(#[$attr:meta])* pub struct $i:ident ( $($field:tt)* ); - )* ) => ($( + )*) => ($( __item! { #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] #[derive(Copy, Clone)] diff --git a/src/unix/aix/mod.rs b/src/unix/aix/mod.rs index d404c3e8b52a1..fc7a580eca28e 100644 --- a/src/unix/aix/mod.rs +++ b/src/unix/aix/mod.rs @@ -573,7 +573,7 @@ cfg_if! { } impl Eq for __sigaction_sa_union {} impl ::fmt::Debug for __sigaction_sa_union { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("__sigaction_sa_union") .field("__su_handler", unsafe { &self.__su_handler }) .field("__su_sigaction", unsafe { &self.__su_sigaction }) @@ -598,7 +598,7 @@ cfg_if! { } impl Eq for sigaction {} impl ::fmt::Debug for sigaction { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("sigaction") .field("sa_union", &self.sa_union) .field("sa_mask", &self.sa_mask) @@ -625,7 +625,7 @@ cfg_if! { } impl Eq for __poll_ctl_ext_u {} impl ::fmt::Debug for __poll_ctl_ext_u { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("__poll_ctl_ext_u") .field("addr", unsafe { &self.addr }) .field("data32", unsafe { &self.data32 }) @@ -655,7 +655,7 @@ cfg_if! { } impl Eq for poll_ctl_ext {} impl ::fmt::Debug for poll_ctl_ext { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("poll_ctl_ext") .field("version", &self.version) .field("command", &self.command) diff --git a/src/unix/aix/powerpc64.rs b/src/unix/aix/powerpc64.rs index e7f1b670823f8..f8ec9811be617 100644 --- a/src/unix/aix/powerpc64.rs +++ b/src/unix/aix/powerpc64.rs @@ -307,7 +307,7 @@ cfg_if! { } impl Eq for siginfo_t {} impl ::fmt::Debug for siginfo_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("siginfo_t") .field("si_signo", &self.si_signo) .field("si_errno", &self.si_errno) @@ -347,7 +347,7 @@ cfg_if! { } impl Eq for _kernel_simple_lock {} impl ::fmt::Debug for _kernel_simple_lock { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("_kernel_simple_lock") .field("_slock", unsafe { &self._slock }) .field("_slockp", unsafe { &self._slockp }) @@ -410,12 +410,12 @@ cfg_if! { && self.f_fnamep == other.f_fnamep && self.f_fdata == other.f_fdata && self.f_lock == other.f_lock - && self.f_offset_lock == other.f_offset_lock; + && self.f_offset_lock == other.f_offset_lock } } impl Eq for file {} impl ::fmt::Debug for file { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("file") .field("f_flag", &self.f_flag) .field("f_count", &self.f_count) @@ -466,7 +466,7 @@ cfg_if! { } impl Eq for __ld_info_file {} impl ::fmt::Debug for __ld_info_file { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("__ld_info_file") .field("_ldinfo_fd", unsafe { &self._ldinfo_fd }) .field("_ldinfo_fp", unsafe { &self._ldinfo_fp }) @@ -498,7 +498,7 @@ cfg_if! { } impl Eq for ld_info {} impl ::fmt::Debug for ld_info { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("ld_info") .field("ldinfo_next", &self.ldinfo_next) .field("ldinfo_flags", &self.ldinfo_flags) @@ -535,7 +535,7 @@ cfg_if! { } impl Eq for __pollfd_ext_u {} impl ::fmt::Debug for __pollfd_ext_u { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("__pollfd_ext_u") .field("addr", unsafe { &self.addr }) .field("data32", unsafe { &self.data32 }) @@ -563,7 +563,7 @@ cfg_if! { } impl Eq for pollfd_ext {} impl ::fmt::Debug for pollfd_ext { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("pollfd_ext") .field("fd", &self.fd) .field("events", &self.events) diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 74eb9b45d5d2e..1bf743e1cd7ad 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -1595,7 +1595,7 @@ s_no_extra_traits! { _os_unfair_lock_opaque: u32, } - #[repr(packed(1))] + #[repr(packed(1))] pub struct sockaddr_vm { pub svm_len: ::c_uchar, pub svm_family: ::sa_family_t, @@ -1722,8 +1722,7 @@ cfg_if! { } impl Eq for semun {} impl ::fmt::Debug for semun { - fn fmt(&self, f: &mut ::fmt::Formatter) - -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { f.debug_struct("semun") .field("val", unsafe { &self.val }) .finish() @@ -1775,7 +1774,6 @@ cfg_if! { && self.udata == other.udata } } - impl Eq for kevent {} impl ::fmt::Debug for kevent { fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index b49a83862f292..7e8d4d001c710 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -60,10 +60,10 @@ s! { pub struct fd_set { #[cfg(all(target_pointer_width = "64", any(target_os = "freebsd", target_os = "dragonfly")))] - fds_bits: [i64; FD_SETSIZE / 64], + fds_bits: [i64; FD_SETSIZE as usize / 64], #[cfg(not(all(target_pointer_width = "64", any(target_os = "freebsd", target_os = "dragonfly"))))] - fds_bits: [i32; FD_SETSIZE / 32], + fds_bits: [i32; FD_SETSIZE as usize / 32], } pub struct tm { @@ -129,7 +129,7 @@ s_no_extra_traits! { pub struct sockaddr_un { pub sun_len: u8, pub sun_family: sa_family_t, - pub sun_path: [c_char; 104] + pub sun_path: [::c_char; 104] } pub struct utsname { diff --git a/src/unix/bsd/netbsdlike/netbsd/aarch64.rs b/src/unix/bsd/netbsdlike/netbsd/aarch64.rs index 5f57779d3037e..e285d0617ce20 100644 --- a/src/unix/bsd/netbsdlike/netbsd/aarch64.rs +++ b/src/unix/bsd/netbsdlike/netbsd/aarch64.rs @@ -81,6 +81,7 @@ cfg_if! { } pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1; + pub const PT_GETREGS: ::c_int = PT_FIRSTMACH + 0; pub const PT_SETREGS: ::c_int = PT_FIRSTMACH + 1; pub const PT_GETFPREGS: ::c_int = PT_FIRSTMACH + 2; diff --git a/src/unix/linux_like/mod.rs b/src/unix/linux_like/mod.rs index bd943b99940f2..fd4c7868a63b9 100644 --- a/src/unix/linux_like/mod.rs +++ b/src/unix/linux_like/mod.rs @@ -85,7 +85,7 @@ s! { } pub struct fd_set { - fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], + fds_bits: [::c_ulong; FD_SETSIZE as usize / ULONG_SIZE], } pub struct tm { diff --git a/src/unix/newlib/mod.rs b/src/unix/newlib/mod.rs index 3b02d93fb3dd7..6ecda27e04711 100644 --- a/src/unix/newlib/mod.rs +++ b/src/unix/newlib/mod.rs @@ -183,7 +183,7 @@ s! { } pub struct fd_set { // Unverified - fds_bits: [::c_ulong; FD_SETSIZE / ULONG_SIZE], + fds_bits: [::c_ulong; FD_SETSIZE as usize / ULONG_SIZE], } pub struct passwd { // Unverified diff --git a/src/unix/nto/mod.rs b/src/unix/nto/mod.rs index 7c6eba66eea8d..90478d7aaf660 100644 --- a/src/unix/nto/mod.rs +++ b/src/unix/nto/mod.rs @@ -154,7 +154,7 @@ s! { } pub struct fd_set { - fds_bits: [::c_uint; 2 * FD_SETSIZE / ULONG_SIZE], + fds_bits: [::c_uint; 2 * FD_SETSIZE as usize / ULONG_SIZE], } pub struct tm { diff --git a/src/unix/redox/mod.rs b/src/unix/redox/mod.rs index 262079e042c5b..402857f9098cd 100644 --- a/src/unix/redox/mod.rs +++ b/src/unix/redox/mod.rs @@ -116,7 +116,7 @@ s! { } pub struct fd_set { - fds_bits: [::c_ulong; ::FD_SETSIZE / ULONG_SIZE], + fds_bits: [::c_ulong; ::FD_SETSIZE as usize / ULONG_SIZE], } pub struct in_addr { diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index a5190416836cd..503edf65663fd 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -513,9 +513,9 @@ s_no_extra_traits! { pub struct fd_set { #[cfg(target_pointer_width = "64")] - fds_bits: [i64; FD_SETSIZE / 64], + fds_bits: [i64; FD_SETSIZE as usize / 64], #[cfg(target_pointer_width = "32")] - fds_bits: [i32; FD_SETSIZE / 32], + fds_bits: [i32; FD_SETSIZE as usize / 32], } pub struct sockaddr_storage { From 4f2cde33a2ecb73bd3b3e3d0ff89d08a40ba35c5 Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Tue, 2 Apr 2024 03:05:04 -0400 Subject: [PATCH 4/4] Fix warning (backport ) (cherry picked from commit 581bccc3fbeeb0482a843a9afc84811168354b5a) --- src/unix/aix/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unix/aix/mod.rs b/src/unix/aix/mod.rs index fc7a580eca28e..a7ef2a073b7c1 100644 --- a/src/unix/aix/mod.rs +++ b/src/unix/aix/mod.rs @@ -60,6 +60,7 @@ pub type posix_spawn_file_actions_t = *mut ::c_char; pub type iconv_t = *mut ::c_void; e! { + #[repr(u32)] pub enum uio_rw { UIO_READ = 0, UIO_WRITE,