From 55056537176f94130b1bae4f4d526b00c19f4729 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 12 May 2024 16:01:19 +0100 Subject: [PATCH] adding aligned_alloc support for the following: - linux glibc/musl. - all supported BSD implements it. - apple. - solarish. close #3689 --- libc-test/semver/apple.txt | 1 + libc-test/semver/dragonfly.txt | 1 + libc-test/semver/freebsd.txt | 1 + libc-test/semver/linux-gnu.txt | 1 + libc-test/semver/linux-musl.txt | 1 + libc-test/semver/netbsd.txt | 1 + libc-test/semver/openbsd.txt | 1 + src/unix/bsd/mod.rs | 1 + src/unix/linux_like/linux/gnu/mod.rs | 3 +++ src/unix/linux_like/linux/musl/mod.rs | 1 + src/unix/solarish/mod.rs | 1 + 11 files changed, 13 insertions(+) diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index e01934bf0ceb3..db8a721df4444 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -1836,6 +1836,7 @@ aio_return aio_suspend aio_write aiocb +aligned_alloc arc4random arc4random_buf arc4random_uniform diff --git a/libc-test/semver/dragonfly.txt b/libc-test/semver/dragonfly.txt index febed0b3a7aa9..b72e2fcd04ff1 100644 --- a/libc-test/semver/dragonfly.txt +++ b/libc-test/semver/dragonfly.txt @@ -1246,6 +1246,7 @@ aio_suspend aio_waitcomplete aio_write aiocb +aligned_alloc arc4random arc4random_buf arc4random_uniform diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index 1144c4d4c2481..efb43d8b6898a 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -1703,6 +1703,7 @@ aio_suspend aio_waitcomplete aio_write aiocb +aligned_alloc arc4random arc4random_buf arc4random_uniform diff --git a/libc-test/semver/linux-gnu.txt b/libc-test/semver/linux-gnu.txt index 09625b8280c5a..4c066b43d726c 100644 --- a/libc-test/semver/linux-gnu.txt +++ b/libc-test/semver/linux-gnu.txt @@ -609,6 +609,7 @@ aio_return aio_suspend aio_write aiocb +aligned_alloc backtrace clock_adjtime copy_file_range diff --git a/libc-test/semver/linux-musl.txt b/libc-test/semver/linux-musl.txt index 7e5a81194bdf8..850655f026219 100644 --- a/libc-test/semver/linux-musl.txt +++ b/libc-test/semver/linux-musl.txt @@ -56,6 +56,7 @@ aio_return aio_suspend aio_write aiocb +aligned_alloc clock_adjtime copy_file_range ctermid diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index 353b1e7356ff5..4ce262fdfe406 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -1202,6 +1202,7 @@ aio_return aio_suspend aio_write aiocb +aligned_alloc arc4random arc4random_buf arc4random_uniform diff --git a/libc-test/semver/openbsd.txt b/libc-test/semver/openbsd.txt index fd4563212d60d..155174e80da1d 100644 --- a/libc-test/semver/openbsd.txt +++ b/libc-test/semver/openbsd.txt @@ -1007,6 +1007,7 @@ __errno abs accept4 acct +aligned_alloc arc4random arc4random_buf arc4random_uniform diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 6ee2a3de44035..92f2f81e39a8d 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -915,6 +915,7 @@ extern "C" { timeptr: *const ::tm, locale: ::locale_t, ) -> ::size_t; + pub fn aligned_alloc(alignment: ::size_t, size: ::size_t) -> *mut ::c_void; } cfg_if! { diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index 4b3ee5a15ce34..928ff14e98edb 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -1537,6 +1537,9 @@ extern "C" { // Added in `glibc` 2.34 pub fn close_range(first: ::c_uint, last: ::c_uint, flags: ::c_int) -> ::c_int; + + // Added in `glibc` 2.16 + pub fn aligned_alloc(alignment: ::size_t, size: ::size_t) -> *mut ::c_void; } cfg_if! { diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index 36d8c20381432..7e937d7285dc3 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -885,6 +885,7 @@ extern "C" { pub fn dirname(path: *mut ::c_char) -> *mut ::c_char; pub fn basename(path: *mut ::c_char) -> *mut ::c_char; + pub fn aligned_alloc(alignment: ::size_t, size: ::size_t) -> *mut ::c_void; } // Alias to 64 to mimic glibc's LFS64 support diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index 7ed00413dc7f2..1f5a9bd3549a1 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -3212,6 +3212,7 @@ extern "C" { pub fn __major(version: ::c_int, devnum: ::dev_t) -> ::major_t; pub fn __minor(version: ::c_int, devnum: ::dev_t) -> ::minor_t; pub fn __makedev(version: ::c_int, majdev: ::major_t, mindev: ::minor_t) -> ::dev_t; + pub fn aligned_alloc(alignment: ::size_t, size: ::size_t) -> *mut ::c_void; } #[link(name = "sendfile")]