Commit graph

39069 commits

Author SHA1 Message Date
Elliott Hughes
ab9028c8ba Merge "De-pessimize SigSetConverter usage." into main 2023-07-20 16:03:27 +00:00
Treehugger Robot
87e7955d9f Merge "Sync upstream NetBSD." into main 2023-07-20 14:21:01 +00:00
Treehugger Robot
6de9b74b73 Merge "Sync upstream OpenBSD." into main 2023-07-20 14:15:45 +00:00
Treehugger Robot
8a771303b8 Merge "Sync upstream FreeBSD libm (trivial changes)." into main 2023-07-20 14:15:41 +00:00
Treehugger Robot
a1fa960388 Merge "Sync upstream FreeBSD libm (real changes)." into main 2023-07-20 14:14:20 +00:00
Treehugger Robot
b6dda030a8 Merge "Sync upstream FreeBSD (qsort)." into main 2023-07-20 01:48:59 +00:00
Treehugger Robot
52206450c4 Merge changes Iac46bc9c,I4f853107 into main
* changes:
  Invert over-long UTF-8 bool for readability.
  Add musl handling in run-on-host.sh.
2023-07-20 00:46:03 +00:00
Treehugger Robot
f0d6c0a1d8 Merge "Sync with upstream FreeBSD." into main 2023-07-19 23:21:01 +00:00
Dan Albert
78da292886 Invert over-long UTF-8 bool for readability.
Also actually assign a bool to it. I'd originally written a #define
and apparently forgot to fix the value. I'm a bit surprised that clang
didn't complain.

Bug: None
Test: ./tests/run-on-host.sh 64 --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Test: ./tests/run-on-host.sh musl --gtest_filter="uchar.*"
Change-Id: Iac46bc9c48fd70853d5c447e812e25e617281d2b
2023-07-19 21:54:09 +00:00
Dan Albert
b9bc50910e Add musl handling in run-on-host.sh.
Bug: None
Test: ./tests/run-on-host.sh glibc
Test: ./tests/run-on-host.sh musl
Change-Id: I4f85310750402e1187358aeb4a585f26092b97ac
2023-07-19 21:53:11 +00:00
Dan Albert
1b256de728 Merge changes Ia7dd2ded,I9e85a9ae,Id7436404 into main
* changes:
  Fix uchar.mbrtoc16_zero_len for glibc and musl.
  Fix mbrtoc32 tests for out of range code points.
  Fix mbrtoc32 test for musl and glibc.
2023-07-19 21:47:54 +00:00
Elliott Hughes
65ab63bcea Sync upstream FreeBSD (qsort).
This gives us C11 Annex K's qsort_s(), which -- despite being Annex K --
is potentially useful in that it resolves the long-standing argument
about what the signature of qsort_r() is supposed to be. I'll import
it here first, and worry about actually using it separately (given that
glibc/musl and macOS/iOS don't have it; only Windows and [now] FreeBSD,
but not even the other BSDs).

For now, though, this change is a no-op.

Bug: http://b/17203231
Bug: http://b/31807750
Test: treehugger
Change-Id: Id8d2916b608ba8251df8643694da542e9b11eaae
2023-07-19 14:14:58 -07:00
Elliott Hughes
8810bd7585 Sync upstream FreeBSD libm (real changes).
Test: treehugger
Change-Id: Icf591ba195a3f5080203b157aa7f43d518a9cc69
2023-07-19 14:11:58 -07:00
Elliott Hughes
c1e46b62e9 Sync upstream FreeBSD libm (trivial changes).
More interesting changes to come, but there's enough of this noise I'm
separating it out...

Test: treehugger
Change-Id: I0efc0ac860a147112369df7561ee48a92a2a5e84
2023-07-19 14:08:03 -07:00
Elliott Hughes
ac496ec2ba Sync upstream OpenBSD.
A couple of minor optimizations since the last sync.

Test: treehugger
Change-Id: Ibba2cd6749f989a24b74a64d0db180bd0458fdc8
2023-07-19 13:36:44 -07:00
Elliott Hughes
60260e22e7 Sync upstream NetBSD.
Only one trivial change.

Test: treehugger
Change-Id: Ibae666f752425a74e984b202fa42e13bcd284a30
2023-07-19 13:33:13 -07:00
Elliott Hughes
523b03a2dc Sync with upstream FreeBSD.
Only trivial changes here.

Test: treehugger
Change-Id: Ie4c0c0c74482192bf53b4c1021b0183cb8f046bd
2023-07-19 12:56:55 -07:00
Elliott Hughes
215baed16f De-pessimize SigSetConverter usage.
While looking at the disassembly for the epoll stuff I noticed that this
expands to quite a lot of code that the compiler can't optimize out for
LP64 (because it doesn't know that the "copy the argument into a local
and then use the local" bit isn't important).

There are two obvious options here. Something like this:
```
  int signalfd64(int fd, const sigset64_t* mask, int flags) {
    return __signalfd4(fd, mask, sizeof(*mask), flags);
  }

  int signalfd(int fd, const sigset_t* mask, int flags) {
  #if defined(__LP64__)
    return signalfd64(fd, mask, flags);
  #else
    SigSetConverter set = {.sigset = *mask};
    return signalfd64(fd, &set.sigset64, flags);
  #endif
  }
```
Or something like this:
```
  int signalfd64(int fd, const sigset64_t* mask, int flags) {
    return __signalfd4(fd, mask, sizeof(*mask), flags);
  }

  #if defined(__LP64__)
  __strong_alias(signalfd, signalfd64);
  #else
  int signalfd(int fd, const sigset_t* mask, int flags) {
    SigSetConverter set = {};
    set.sigset = *mask;
    return signalfd64(fd, &set.sigset64, flags);
  }
  #endif
```
The former is slightly more verbose, but seems a bit more obvious, so I
initially went with that. (The former is more verbose in the generated
code too, given that the latter expands to _no_ code, just another symbol
pointing to the same code address.)

Having done that, I realized that slight changes to the interface would
let clang optimize away most/all of the overhead for LP64 with the only
preprocessor hackery being in SigSetConverter itself.

I also pulled out the legacy bsd `int` conversions since they're only
used in two (secret!) functions, so it's clearer to just have a separate
union for them. While doing so, I suppressed those functions for
riscv64, since there's no reason to keep carrying that mistake forward.

posix_spawn() is another simple case that doesn't actually benefit from
SigSetConverter, so I've given that its own anonymous union too.

Test: treehugger
Change-Id: Iaf67486da40d40fc53ec69717c3492ab7ab81ad6
2023-07-19 12:20:07 -07:00
Zijun Zhao
46f1873b1e Merge "Fix duplicate symbols error in bionic" into main 2023-07-19 18:13:11 +00:00
Dan Albert
9a9bbe5fc6 Fix uchar.mbrtoc16_zero_len for glibc and musl.
Bug: None
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Change-Id: Ia7dd2dedd39ac287350bab42493e886939556111
2023-07-19 18:04:10 +00:00
Dan Albert
9fa76f1374 Fix mbrtoc32 tests for out of range code points.
Same as the earlier fix for mbrtoc16. Other implementations support
the older RFC, bionic supports the new one.

Bug: None
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Change-Id: I9e85a9ae53aaaa112a76665063acd2bd856b26cf
2023-07-19 17:59:29 +00:00
Dan Albert
0b8fbdf4b3 Fix mbrtoc32 test for musl and glibc.
glibc and musl both interpreted the spec differently than we did
(better, imo) for the return value of a zero-length conversion. Fix
the test to handle that.

Also converted the test from ASSERT to EXPECT to reduce the number of
builds needed to find failures.

Bug: None
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.*"
Change-Id: Id74364040ce3b0e21bacd78f70467053cc8a6058
2023-07-19 17:59:27 +00:00
Treehugger Robot
0b310d9e57 Merge "Remove unused _ARC4_ATFORK() macro." into main 2023-07-19 01:36:18 +00:00
Treehugger Robot
b88a23ec58 Merge "Fix the (unused) return type for readlinkat() in SYSCALLS.TXT." into main 2023-07-18 22:57:19 +00:00
Elliott Hughes
f9a9537a26 Remove unused _ARC4_ATFORK() macro.
Test: treehugger
Change-Id: Ie1ac8a5512f89da34f8d04f177bc8d4a303c42d2
2023-07-18 22:44:40 +00:00
zijunzhao
3b57730346 Fix duplicate symbols error in bionic
Symbol __rand48_seed, __rand48_mult and __rand48_add are duplicate when switch -fcommon to -fno-common, but this was already fixed upstream, so sync with upstream's version.

Bug: b/151457797
Test: mm
Change-Id: Ie673a4c58671cdac405e0ff313c5898728f7b426
2023-07-18 22:39:33 +00:00
Elliott Hughes
9634513a63 Merge "Update <sys/cachectl.h>." into main 2023-07-18 22:36:53 +00:00
Dan Albert
d0b8d3c901 Merge "Fix 5-byte mbrtoc16 test for glibc/musl." into main 2023-07-18 22:25:11 +00:00
Treehugger Robot
7ca162602b Merge "Make getentropy available from <unistd.h>" into main 2023-07-18 20:10:06 +00:00
Elliott Hughes
8d350da500 Update <sys/cachectl.h>.
NDK API review complained about missing nullability annotations (added),
not having a `__riscv` #if guard around this function (added), and not
using `__INTRODUCED_IN(35)`. I haven't done the last of these because
that seems less helpful than the traditional "nothing" meaning "always
available" (since this riscv64-only function will be available from
whatever the first riscv64 API level ends up being).

Bug: http://b/291777120
Test: treehugger
Change-Id: I501b42851bd5b1612244bd86351628d249a57b99
2023-07-18 18:58:02 +00:00
Elliott Hughes
76879c921c Fix the (unused) return type for readlinkat() in SYSCALLS.TXT.
No functional change because the syscall wrapper generator doesn't use
the return types, but having the wrong return type is distracting.

Bug: https://github.com/android/ndk/issues/1908
Test: treehugger
Change-Id: I8b1a6ca11247554d28e85cb6c26ad8328c66a2b9
2023-07-18 15:24:22 +00:00
Dan Albert
1252ab04c3 Fix 5-byte mbrtoc16 test for glibc/musl.
Also split that case out into a separate test to avoid complicating
the test for the common cases.

Bug: None
Test: ./tests/run-on-host.sh glibc --gtest_filter="uchar.mbrtoc16"
Change-Id: If7e50f659ad99ee9bab8847fc7320c7bbd629c5d
2023-07-17 23:52:02 +00:00
David Benjamin
7110157e94 Make getentropy available from <unistd.h>
getentropy is originally an OpenBSD-ism, where it was in <unistd.h> from
day one:
https://man.openbsd.org/OpenBSD-5.6/getentropy

FreeBSD's and Linux's current man pages also document it this way:
https://man7.org/linux/man-pages/man3/getentropy.3.html
https://man.freebsd.org/cgi/man.cgi?query=getentropy&sektion=3&format=html

The man7.org URL is even cited by bionic itself in the comments, though
glibc originally put it in <sys/random.h> and added to <unistd.h> very
shortly afterwards:
https://sourceware.org/bugzilla/show_bug.cgi?id=17252#c9

The cited man page (maintained separately from glibc) originally
documented <sys/random.h>...
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/man3/getentropy.3?id=b0265728162cdcafb8e7d7f1372e8de1a4c963ed

But similarly fixed it to <unistd.h> three months later:
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/man3/getentropy.3?id=9cf011f94b56e8832c5a5d8cf66d4a115d34b9cc

musl matches the BSDs in putting it in <unistd.h>, but not
<sys/random.h>.
https://git.musl-libc.org/cgit/musl/tree/include/unistd.h?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc#n183

POSIX will likely place it there too:
https://www.austingroupbugs.net/view.php?id=1134

macOS and Fuchsia place it in <sys/random.h> and not <unistd.h>, though
given the rest of this precedent, they're clearly outliers. (Note iOS
does *not* have getentropy, just macOS. The system has it, but it's not
exposed as public API. See https://dev.gnupg.org/T5375 and
https://github.com/openssl/openssl/pull/15924.)

Use the more standard location in bionic and put getentropy in
<unistd.h>. This will improve portability and avoid needing workarounds
in BoringSSL. For compatibility, keep it also available in
<sys/random.h> by using a <bits/getentropy.h> header.

BYPASS_INCLUSIVE_LANGUAGE_REASON=Above URLs are not hosted by Android and reference the name of a command-line utility, short for 'manual', as in instruction manual

Bug: 290898063
Test: treehugger
Change-Id: Id2d6b6ea09d814e5ba2cb117a7af2c74861148fb
2023-07-17 21:50:53 +00:00
Elliott Hughes
a2cdb247e1 Merge "Add riscv_hwprobe to the seccomp allowlist." into main 2023-07-14 18:49:58 +00:00
Elliott Hughes
13b1d97406 Add riscv_hwprobe to the seccomp allowlist.
We're not ready to add a syscall wrapper to bionic for this (see
https://www.openwall.com/lists/libc-coord/2023/07/13/1 for more), but it's
useful for writing a CTS test ensuring that misaligned accesses are fast.

(I've also moved userfaultfd() next to membarrier() where it belongs:
the existing comment was incorrect.)

Bug: https://github.com/google/android-riscv64/issues/87
Test: treehugger
Change-Id: Ibe691e461c564caebfed295e7acda73cb9b97618
2023-07-14 14:09:32 +00:00
Elliott Hughes
a09f741c2a Merge "Add __riscv_flush_icache() to <sys/cachectl.h>." into main 2023-07-13 19:04:30 +00:00
Elliott Hughes
a4b7949aca Merge "Consistently use %m rather than strerror() in logging." into main 2023-07-13 13:36:46 +00:00
Elliott Hughes
74d9765be9 Add __riscv_flush_icache() to <sys/cachectl.h>.
The obsolete mips header rides again!

The most interesting part of this change is that I've removed the hack
that meant that all system call wrappers starting with `__` defaulted to
being hidden symbols. That's no longer useful given our linker scripts,
and it actively got in the way here because the public libc symbol
actually starts with `__` in glibc, and it would be weird and annoying
for developers if we chose a different name.

Test: strace
Change-Id: I230479787895e8e34f566ade36346a8241eea998
2023-07-12 16:30:55 -07:00
Elliott Hughes
2557f73c05 Consistently use %m rather than strerror() in logging.
When I added %m to async_safe_* too, we never followed up and cleaned up
callers.

Test: treehugger
Change-Id: If81943c4c45de49f0fb4bc29cfbd3fc53d4a47fe
2023-07-12 21:16:31 +00:00
Kelvin Zhang
0b2996f144 Merge "Check for mprotect result" into main 2023-07-12 01:34:42 +00:00
Kelvin Zhang
fd93b6031e Check for mprotect result
Failure to mark shadow stack page as writable will result in a SEGV
fault later when a function tries to save return addresses to shadow
stack. The engineer looking at the crash report would be very confused
because the program crashes at very beginning of an innocent looking
function. For ease of debugging, check for shadow stack errors early.

Test: th
Bug: 279808236
Bug: 253652966
Change-Id: Id2da68fa984b5dfb1846ed14aa7ededee7f2508f
2023-07-11 15:42:32 -07:00
Christopher Ferris
df85637d32 Merge "Update to v6.4 kernel headers." into main 2023-07-11 21:51:16 +00:00
Kelvin Zhang
52e3190b9b Merge "Fix shadowstack init crash on 16K page system" into main 2023-07-11 18:03:31 +00:00
Elliott Hughes
6a6f527dfc Merge "Clarify the <sys/ifunc.h> docs." into main 2023-07-11 15:17:35 +00:00
Treehugger Robot
9ac6169db4 Merge "Add multithreads throughput benchmark" into main 2023-07-11 06:26:51 +00:00
Kelvin Zhang
fb733613e9 Fix shadowstack init crash on 16K page system
shadowstack implicitly assumes that SCS_SIZE is a multiple of page size.
Currently, SCS_SIZE is set to 8K. This assumption is broken on 16K
platforms.

Test: launch_cvd --use_16k
Bug: 253652966
Bug: 279808236
Change-Id: I1180cfba32c98d638e18615ccfdc369beb390ea7
2023-07-10 16:04:01 -07:00
Elliott Hughes
0c50ed4c7c Clarify the <sys/ifunc.h> docs.
This confused the Arm folks implementing function multi-versioning.

Test: treehugger
Change-Id: Ib56fc142bed4a2f2a394d60a07f322add40702e5
2023-07-10 22:32:09 +00:00
Christopher Ferris
30573ba569 Merge "Modify how the malloc debug tests run." into main 2023-07-10 21:05:13 +00:00
Chia-hung Duan
4414844354 Add multithreads throughput benchmark
This is used to monitor the impact of different lock granularity in a
memory allocator. It creates different memory alloc/dealloc patterns
across different threads but keep the same amount of bytes to be
processed.

Bug: 288126442
Test: run benchmark with --benchmark_filter=BM_malloc_threads_throughput*

Change-Id: I24eea617a6346480524dcb8c0bdbe9bd8e90dd72
2023-07-10 18:23:09 +00:00
Christopher Ferris
37c3f3c67e Update to v6.4 kernel headers.
Kernel headers coming from:

Git: https://android.googlesource.com/kernel/common/
Branch: android-mainline
Tag: android-mainline-6.4

Test: Bionic unit tests pass.
Change-Id: I991f8eaa2b272a464166addb13e6bdc63734444d
2023-07-10 10:59:05 -07:00