Commit graph

3495 commits

Author SHA1 Message Date
Elliott Hughes
f5b4e3ce58 Add %b/%B to async-safe logging.
Missed this when we added the new C23 binary output to the printf()
family.

Also fix %X to use "0X" instead of "0x" and add missing tests.

Test: used by new LD_SHOW_AUXV functionality
Change-Id: I6623b92acec7daf534536697de0f87352a2653ad
2023-08-23 14:08:40 -07:00
Elliott Hughes
620a72252e riscv64: fix ifuncs, improve the ifunc tests.
Talking futher to the person doing the glibc risc-v ifunc work, they
clarified that glibc _is_ passing hwcap as the first argument, and the
null pointer is actually the second argument.

https://sourceware.org/pipermail/libc-alpha/2023-August/150967.html

So since our whole purpose here was source compatibility, let's do what
they're actually doing, and let's add some tests. I've also added a test
that __riscv_hwprobe() works from an ifunc resolver because that's one
place where it might well be used. That said, one other thing that came
out of the discussion is that I actually went away and looked at a
sample of top apps to see how many are using ifuncs currently. The
result? Zero. So although this _might_ be interesting long term
(especially if clang gets riscv64 FMV), I think we've done more than we
need to with riscv64 ifuncs for now!

Test: ran locally, both dynamic and static tests
Change-Id: Ie2044d9f4e47c32c00ad381f045c537f4df38b08
2023-08-21 16:17:35 -07:00
Treehugger Robot
d8708ba8b6 Merge "sys_hwprobe_test.cpp: compare vdso to syscall." into main 2023-08-21 20:47:52 +00:00
Mitch Phillips
f5c9a65046 Move bionic test libraries to a default, for easy consumption in cts.
This list has diverged between cts/ and bionic/. Instead of having to
maintain the list, let's just make cts/ inherit the one from bionic.

Bug: 296832150
Test: atest bionic-unit-tests CtsBionicTestCases
Change-Id: I271668e83aed239107b9129dfb707f03bae47cfa
2023-08-21 13:55:10 +02:00
Elliott Hughes
728aaf6800 sys_hwprobe_test.cpp: compare vdso to syscall.
Also fix a __has_include() that was copy & pasted without modification
from a different test.

Test: treehugger
Change-Id: Iafceb331a95ec788596ffdad60aa2202b692e589
2023-08-14 14:58:33 -07:00
Dan Albert
1982dce568 Merge changes I1a60d6ef,Idabf0107 into main
* changes:
  Fix result for zero-length non-null conversion.
  Fix mismatched return types for surrogate pairs.
2023-08-07 17:55:09 +00:00
Christopher Ferris
636b9b9bf2 Merge "Increase time to set allocation limit." into main 2023-08-04 22:54:05 +00:00
Christopher Ferris
e9ffc52da7 Increase time to set allocation limit.
Under some circumstances, it's possible to fail the enable allocation
limit android_mallopt call. Increase the total allowed time for the
function to complete.

In addition, if the enable fails, allow another limit call to succeed
in the future.

Finally, change the limit test to use _exit instead of exit.

Bug: 291672185

Test: Ran limit test thousands of times.
Test: Forced the limit to fail and verified the second call passes.
Change-Id: I0948e6fd97231a7538b9b82b76f0a207386681b1
2023-08-04 13:10:48 -07:00
Dan Albert
16007d5204 Fix result for zero-length non-null conversion.
Bug: None
Test: deleted the xfail half of the test
Change-Id: I1a60d6ef27ebad14de79ac3bc637a6f2280334d8
2023-08-04 19:48:56 +00:00
Dan Albert
3a8fed1ac3 Fix mismatched return types for surrogate pairs.
We've had these backward all this time. The relevant quote is in a
code comment in the implementation, but the first call after
completely decoding a code point that requires a surrogate pair should
return the number of bytes decoded by the most recent call, and the
second call should return -3 (if only C had given those some named
constants that might have been more obviously wrong).

Bug: https://issuetracker.google.com/289419882
Test: Fixed the test, tests run against glibc and musl to confirm
Change-Id: Idabf01075b1cad35b604ede8d676d6f0b1dc91e6
2023-08-04 19:48:35 +00:00
Dan Albert
9f30c6ba92 Disable 0b parsing test for glibc.
Bug: None
Test: ran on glibc
Change-Id: I390ea20015f94b26ab3cdbeb6ade6cbcfefa7b0a
2023-08-04 19:48:34 +00:00
Dan Albert
a40159fa22 Improve output for failed wcsto* tests.
Bug: None
Test: ran these and finally understood which sub-test was failing
Change-Id: I51c6536eba4b9c82ed4b062b1702128e23cf339c
2023-08-03 21:05:29 +00:00
Dan Albert
9f78c51e03 Add missing setlocale/uselocale for glibc tests.
Bug: None
Test: these
Change-Id: Ifa0a555e3a771b27ba733b1316f7531c7b262f8b
2023-08-03 21:05:29 +00:00
Dan Albert
5325653b0f Fix test for out of range multibyte characters.
Same as in uchar_test.cpp: glibc implements a much older unicode
standard which allows these.

Bug: None
Test: this is a test
Change-Id: Iead5eb01d391be85a7b1a034ea9e7f8828e81cdb
2023-08-03 21:04:31 +00:00
Dan Albert
512469a858 Fix wchar tests for zero length conversions.
Same as the previous change for the uchar tests: the tests are wrong
to match bionic's wrong implementation. Fix the test to encode the bug
for now while I get the tests into good shape, then I'll be back to
fix the bugs and remove the test differences.

Bug: None
Test: this is a test
Change-Id: I1123660994f755f8bac1f2656f6890d5a43310b3
2023-08-03 20:03:28 +00:00
Dan Albert
686e67d077 Fix wcsto*_l tests for glibc.
glibc immediately dereferences the locale passed to all wcsto*_l
functions, even if it won't be used, and even if it's
LC_GLOBAL_LOCALE, which isn't a pointer to valid memory.

Bug: None
Test: this is the test
Change-Id: Ia307cbd6a5c5b4b904c978a03e6d06c1cef6ceed
2023-08-03 19:59:11 +00:00
Tomasz Wasilczyk
704e4e6936 Define gettid symbol when testing on glibc < 2.30
Bug: 289414897
Test: it builds
Change-Id: Ic44514953f34096e8a681ef2587439953096ba53
2023-08-03 07:19:17 -07:00
Florian Mayer
8a2f0358ed Merge "Don't assume size of functions." into main 2023-07-29 01:48:02 +00:00
Florian Mayer
8fc5ab4f72 Don't assume size of functions.
Bug: 293532332
Change-Id: I93a8c5380b17b77ff85f4027b48ea5318a03e9e3
2023-07-28 15:51:38 -07:00
Elliott Hughes
f3d6b44e2b riscv64: add <sys/hwprobe.h>.
This is source compatible with the current proposal for glibc.

Bug: https://github.com/google/android-riscv64/issues/27
Test: treehugger
Change-Id: I428777e4eac1fe643d442a93a4b3ad1fdf0ffd97
2023-07-28 09:29:06 -07:00
Christopher Ferris
15c22cdee0 No tombstones under normal bionic unit tests run.
Change a test to use a signal that does not trigger a tombstone.

Also changed the gwp_asan_integration.DISABLED_assert_gwp_asan_enabled
test to inherit from the SilentDeathTest to prevent tombstones
being generated.

Test: Ran tests and no tombstones generated.
Change-Id: I0f104704829dde692aa515a63dea1c6971278c29
2023-07-24 17:51:41 -07:00
Christopher Ferris
c833fabed7 Mark death tests properly.
A few death tests are not set to silence tombstones, so fix
all of those occurrences.

Test: Ran all death tests and no tombstones generated.
Change-Id: If2b54b1a3432edbd54076439d40527d966607f70
2023-07-24 14:31:15 -07:00
Christopher Ferris
1b61cbf604 Merge "Fix potential flakiness in android_mallopt test." into main 2023-07-22 03:28:39 +00:00
Christopher Ferris
fe13041d22 Fix potential flakiness in android_mallopt test.
The set_allocation_limit_multiple_threads test could fail every
once in a while. So rewrite slightly so that the tests wait until
all of the threads are running before letting them start.

I also refactored the code to use std::thread instead of the raw
pthread functions.

Bug: 291672185

Test: Ran the test thousdands of times.
Change-Id: Ia0bdef93d58e0ff8266e551ed4a32e14ff829581
2023-07-21 13:42:09 -07:00
Dan Albert
09d3b5065d Disable uchar.start_state test for musl.
These all appear to be either musl bugs or underspecified corners of
the C standard, so rather than verify the musl behavior I've just
disabled the body of the test for musl.

Now that this is skipped, all the uchar tests are passing for bionic,
glibc, and musl.

Bug: None
Test: None
Change-Id: Icf88ef42e9b750ab45ba76bf8112967b00e72a9f
2023-07-20 22:09:30 +00:00
Dan Albert
a0d0e350a5 Add missing setlocale calls in tests.
Doesn't do anything for bionic (which is why this has gone unnoticed),
but it does change the locale for glibc and musl. After this patch,
all these tests pass on glibc. musl is still failing in
uchar.start_state, which I haven't finished investigating.

This should probably be a test fixture so it's harder to forget, but
there are a handful of tests here which don't call setlocale until
part way through the tests, and I'm not certain if that was attempting
to test some non-obvious behavior, or if that was just an accident. I
don't want to change that test behavior before understanding it
better, so this will do for now.

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: Ib781a41893f021e336e67281070932f41f792318
2023-07-20 17:15:59 +00:00
Treehugger Robot
a8a9c09e0f Merge "Fix another over-long UTF-8 sequence test." into main 2023-07-20 17:03:04 +00:00
Treehugger Robot
876f3668ac Merge changes I0845fdee,I879de1e8 into main
* changes:
  Fix mbrtoc16 reserved range test for musl.
  Fix surrogate pair deocding for musl/glibc.
2023-07-20 17:03:03 +00:00
Elliott Hughes
ab9028c8ba Merge "De-pessimize SigSetConverter usage." into main 2023-07-20 16:03:27 +00:00
Dan Albert
f5b8c7dcf4 Fix another over-long UTF-8 sequence test.
This one forgot to set its locale, so it was passing on glibc (because
the sequence here wasn't valid in its default locale) and failing on
musl, both for the wrong reasons.

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: Ic6bcd1836ba23c7010e2cde673a3beca73778021
2023-07-19 21:54:09 +00:00
Dan Albert
ef8e1581ce Fix mbrtoc16 reserved range test for musl.
Musl was treating 0xf0 as a valid character in its default locale. I
didn't dig into whether that was a musl bug or whether it was actually
translating whatever extended ASCII character that was into the
correct code point (tbh I don't know what the rule there is either).

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: I0845fdee9a016ad67ccff3716129ff29f83a63d7
2023-07-19 21:54:09 +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
1e8e0c1f03 Fix surrogate pair deocding for musl/glibc.
Bug: https://issuetracker.google.com/289419882
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: I879de1e88d27b28f3c4892ab1b00bd942a32383e
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
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
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
Dan Albert
d0b8d3c901 Merge "Fix 5-byte mbrtoc16 test for glibc/musl." into main 2023-07-18 22:25:11 +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
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
Treehugger Robot
cfb9030ff0 Merge "Add a test for a recent POSIX change." 2023-06-26 22:51:13 +00:00
Elliott Hughes
e18c1fa371 Add a test for a recent POSIX change.
No code change required.

Bug: https://austingroupbugs.net/view.php?id=1647
Test: treehugger
Change-Id: I411a009bccafb4e2738f22199c64d8fe7dc105e3
2023-06-26 13:12:57 -07:00
Florian Mayer
bdc192cf4b Simplify MemtagNoteTests
It's easier to just disable hwasan than to handle it in the test.

Change-Id: I511c63ae8916e03d33984a749f279fabbd0a75e3
2023-06-23 13:21:19 -07:00
Treehugger Robot
8d21eac241 Merge "Format parameter for MemtagNoteTest" 2023-06-23 19:29:04 +00:00
Florian Mayer
ab9c6b1c6a Format parameter for MemtagNoteTest
Test: atest bionic-unit-tests
Change-Id: I8b8e6fb0146f600431cbf043cf212a69ecf6b648
2023-06-23 08:34:11 -07:00
Elliott Hughes
5ea305b10e Document how to use tzalloc()/tzfree() with std::unique_ptr.
The hidden pointer makes this trickier than the usual incantation, so
leave some copy & paste lying around for anyone trying to work this out.

Test: treehugger
Change-Id: I26e94bf7a74ce3e43de587edc52ab63e36d1d86b
2023-06-22 20:54:12 +00:00
Elliott Hughes
31fc69f67f Fix tzalloc(nullptr) and add a test.
This works (by reading /etc/localtime) on NetBSD, but not on Android
since we have no such file. Fix that by using our equivalent system
property instead.

Also s/time zone/timezone/ in documentation and comments. We've always
been inconsistent about this (as is upstream in code comments and
documentation) but it seems especially odd now we expose a _type_ that
spells it "timezone" to talk of "time zone" even as we're describing
that type and its associated functions.

Bug: https://github.com/chronotope/chrono/issues/499
Test: treehugger
Change-Id: I142995a3ab4deff1073a0aa9e63ce8eac850b93d
2023-06-22 09:51:01 -07:00
Christopher Ferris
e9a7b81d4a Add new mallopt M_LOG_STATS.
This new mallopt cause statistics of the allocator to be printed in
the log.

Add a stats print for jemalloc.

This is designed to be used as part of a dumpsys meminfo --XXXX
option so that it's easier to get information about apps that
have an unusual memory footprint.

Test: Unit tests pass.
Test: Ran on a device using jemalloc and verified log data.
Test: Ran on a device using scudo and verified log data.
Change-Id: I6fa44ce619c064b2596fbbb478c231994af94f4c
2023-06-17 00:00:02 +00:00
Elliott Hughes
f5cd29269f Merge "Expose tzalloc()/localtime_rz()/mktime_z()/tzfree()." 2023-06-16 15:14:24 +00:00
Elliott Hughes
2bd4316bd6 Expose tzalloc()/localtime_rz()/mktime_z()/tzfree().
* Rationale

The question often comes up of how to use multiple time zones in C code.
If you're single-threaded, you can just use setenv() to manipulate $TZ.
toybox does this, for example. But that's not thread-safe in two
distinct ways: firstly, getenv() is not thread-safe with respect to
modifications to the environment (and between the way putenv() is
specified and the existence of environ, it's not obvious how to fully
fix that), and secondly the _caller_ needs to ensure that no other
threads are using tzset() or any function that behaves "as if" tzset()
was called (which is neither easy to determine nor easy to ensure).

This isn't a bigger problem because most of the time the right answer
is to stop pretending that libc is at all suitable for any i18n, and
switch to icu4c instead. (The NDK icu4c headers do not include ucal_*,
so this is not a realistic option for most applications.)

But what if you're somewhere in between? Like the rust chrono library,
for example? What then?

Currently their "least worst" option is to reinvent the entire wheel and
read our tzdata files. Which isn't a great solution for anyone, for
obvious maintainability reasons.

So it's probably time we broke the catch-22 here and joined NetBSD in
offering a less broken API than standard C has for the last 40 years.
Sure, any would-be caller will have to have a separate "is this
Android?" and even "is this API level >= 35?" path, but that will fix
itself sometime in the 2030s when developers can just assume "yes, it
is", whereas if we keep putting off exposing anything, this problem
never gets solved.

(No-one's bothered to try to implement the std::chrono::time_zone
functionality in libc++ yet, but they'll face a similar problem if/when
they do.)

* Implementation

The good news is that tzcode already implements these functions, so
there's relatively little here.

I've chosen not to expose `struct state` because `struct __timezone_t`
makes for clearer error messages, given that compiler diagnostics will
show the underlying type name (`struct __timezone_t*`) rather than the
typedef name (`timezone_t`) that's used in calling code.

I've moved us over to FreeBSD's wcsftime() rather than keep the OpenBSD
one building --- I've long wanted to only have one implementation here,
and FreeBSD is already doing the "convert back and forth, calling the
non-wide function in the middle" dance that I'd hoped to get round to
doing myself someday. This should mean that our strftime() and
wcsftime() behaviors can't easily diverge in future, plus macOS/iOS are
mostly FreeBSD, so any bugs will likely be interoperable with the other
major mobile operating system, so there's something nice for everyone
there!

The FreeBSD wcsftime() implementation includes a wcsftime_l()
implementation, so that's one stub we can remove. The flip side of that
is that it uses mbsrtowcs_l() and wcsrtombs_l() which we didn't
previously have. So expose those as aliases of mbsrtowcs() and
wcsrtombs().

Bug: https://github.com/chronotope/chrono/issues/499
Test: treehugger
Change-Id: Iee1b9d763ead15eef3d2c33666b3403b68940c3c
2023-06-16 08:10:47 -07:00
zijunzhao
4e274fa0a9 Nullability check for socket module.
Bugs: b/245972273
Test: adb shell
Change-Id: Id0f1aa156ff010358f2484b2f58aa3beacc1409c
2023-06-15 23:51:02 +00:00
zijunzhao
cc475cf28d Implement C23 scanf 'wf' length modifiers
wfN: Specifies that a following b, d, i, o, u, x, or X conversion specifier applies to a fastest minimum-width integer argument with a specific width where N is a positive decimal integer with no leading zeros (the argument will have been promoted according to the integer promotions, but its value shall be converted to the unpromoted type); or that a following n conversion specifier applies to a pointer to a fastest minimum-width integer type argument with a width of N bits. All fastest minimum-width integer types (7.22.1.3) defined in the header <stdint.h> shall be supported. Other supported values of N are implementation-defined.

Bug: b/271903607
Test: adb shell
Change-Id: Iaa1f6d87251144de0b763672ca93f23272880ad1
2023-06-14 17:15:58 +00:00
Elliott Hughes
8fc6fcdfab <complex.h>: stop using __INTRODUCED_IN_(32|64).
Although the existing annotations were strictly true (see
https://github.com/android/ndk/issues/1888#issuecomment-1581773348 for
the gory details), given the Play Store requirement that 32-bit code
must have a 64-bit version, it's not obviously useful to offer a
function for 32-bit before 64-bit.

Test: treehugger
Change-Id: I8ca11b874c26dfaa632690f510cb5409d95012e9
2023-06-12 10:22:12 -07:00
Elliott Hughes
87e170df01 Merge "Remove __RENAME_LDBL." 2023-06-09 13:38:40 +00:00
zijunzhao
7890484cae Implement C23 scanf 'w' length modifiers
wN: Specifies that a following b, d, i, o, u, x, or X conversion specifier applies to an integer argument with a specific width where N is a positive decimal integer with no leading zeros (the argument will have been promoted according to the integer promotions, but its value shall be converted to the unpromoted type); or that a following n conversion specifier applies to a pointer to an integer type argument with a width of N bits. All minimum-width integer types (7.22.1.2) and exact-width integer types (7.22.1.1) defined in the header <stdint.h> shall be supported. Other supported values of N are implementation-defined.

Bug: b/271903607
Test: adb shell
Change-Id: I595fd2ac7bc40d9fb7f1935b39933a6cc068eeff
2023-06-08 21:41:26 +00:00
Elliott Hughes
ab2d3e1049 Remove __RENAME_LDBL.
Discussion of this during my recent minor cleanup convinced me that we
should just remove __RENAME_LDBL. There's no obvious benefit to being
able to build something for 32-bit if you can't build the same code for
64-bit, given that most new hardware (and entire verticals such as Auto)
are 64-bit-only, and the Play Store requires any app with 32-bit code to
also ship 64-bit code.

Test: treehugger
Change-Id: I1c5503b968ca66925d7bd125bd3630c41ec1bfd0
2023-06-07 17:20:53 +00:00
Florian Mayer
2df8ae0f4f Fix elftls_dl#dtv_resize with HWASan
Bug: 271343561
Change-Id: I26755aff68e6c9c2f5454dac0229758b57fd1754
2023-05-26 14:11:40 -07:00
zijunzhao
969d6c129a Nullability check for shm module.
Bugs: b/245972273
Test: adb shell
Change-Id: I9bdd5727719311d063fa126fc286618e9d24a45b
2023-05-23 19:15:25 +00:00
Elliott Hughes
f52b2165cb time.mktime_EOVERFLOW: set an explicit timezone.
Bug: http://b/283397453
Test: export TZ=Asia/Shanghai
Change-Id: Ia03822adad367abf35a0fdf55d7367cd1764fcdd
2023-05-19 16:09:47 -07:00
zijunzhao
2572571786 Nullability check for mman module.
Bugs: b/245972273
Test: adb shell
Change-Id: Ib5c4887d89581eaedcf4a3e128811a6a374a8d1b
2023-05-18 19:02:25 +00:00
zijunzhao
2067ec5967 Nullability check for time module.
Bug: b/245972273
Test: adb shell
Change-Id: I61f69f48f3428ef1f544dd01e573ff078a9eab17
2023-05-16 00:17:36 +00:00
Elliott Hughes
531199c56c printf unification: floating point.
The only remaining differences between vfprintf.cpp and vfwprintf.cpp
after this are the wide/narrow conversions for %c, %m, and %s. I've used
"chars" and "bytes" for the named constants for the directions because
(a) I find -1 and 1 pretty confusing and (b) although "narrow" is the
obvious opposite of "wide", only Windows actually moved to wide
characters, so "narrow" (aka "multibyte", and probably "utf8") is the
default/normal case. Even though C confuses bytes and characters via its
`char` type, "bytes" versus "chars" seems like the appropriate
terminology (and it's what Java/Python use).

Also improve the swprintf tests assertion so failures are readable.

Test: treehugger
Change-Id: Ife8f70f65ec28d96058a7d68df353945524835d2
2023-05-11 16:51:13 -07:00
Elliott Hughes
44befb2286 Merge "Clean up stdio snprintf()/swprintf() tests." 2023-05-09 18:15:16 +00:00
Treehugger Robot
68904aee7b Merge "Make fork equivalent to vfork when HWASan or MTE stack tagging is enabled." 2023-05-09 00:53:48 +00:00
Elliott Hughes
8fd4e96e2a Clean up stdio snprintf()/swprintf() tests.
This reduces the amount of boilerplate for these tests, and ensures that
we have a corresponding swprintf() test for every snprintf() test
(except the handful where it doesn't make sense; we have no FORTIFY for
the wide-character routine, for example).

Test: treehugger
Change-Id: I14091683494bbb414f1a72bddc9835b86ff62526
2023-05-08 17:31:40 -07:00
Peter Collingbourne
b6a592b25b Make fork equivalent to vfork when HWASan or MTE stack tagging is enabled.
Bug: 274056091
Change-Id: Iac029ca6b0e26f57f20c0a54822b75e3cae67344
2023-05-08 15:26:00 -07:00
Elliott Hughes
32c9572424 Explain the header tests better.
Bug: https://github.com/google/android-riscv64/issues/88
Test: N/A
Change-Id: Ia2a8673e96eb7aeb795fb7158f4814e5af9c8e94
2023-05-08 19:14:28 +00:00
Elliott Hughes
e023a02cce Merge "<time.h>: change the new C23 TIME_ constants." 2023-05-04 17:35:17 +00:00
Elliott Hughes
1dff230f75 Merge "syslog.h: implement LOG_PERROR." 2023-05-04 15:09:51 +00:00
Elliott Hughes
7db0a6cc5f <time.h>: change the new C23 TIME_ constants.
Jens Gustedt suggested a better implementation last year on the musl
mailing list: https://www.openwall.com/lists/musl/2022/11/19/1

It means the constants are sparse, but in return it means we can add
future constants and they'll be backward compatible. (Sadly you'll need
to be on API level 35 before you can use anything but TIME_UTC.)

I doubt this will ever matter, because everyone should just stick to
clock_gettime()/clock_getres() anyway, and anyone who does have a
legitimate use for timespec_get() and timespec_getres() probably needs
to support non-Linux and so can't use any clocks that aren't in ISO C
anyway. But given that we don't _have_ to paint ourselves into a corner
here, we may as well take the opportunity to not do so.

Test: strace
Change-Id: I293d32fcbcf7f6703564dac0978ae2a10192a482
2023-05-03 15:37:46 -07:00
Elliott Hughes
213d943a33 syslog.h: implement LOG_PERROR.
This is the one openlog() flag that toybox uses. We should probably try
to unify toybox's POSIX logger and Android-specific log at some point,
and this will help.

Also fix our behavior with an empty format string, noticed while adding
tests.

Test: treehugger
Test: adb shell logger -s foo
Change-Id: Ic027e78a460be3db83cc4c6f9946c9efa22be6e1
2023-05-03 14:19:40 -07:00
zijunzhao
1fdece95d3 Implement C23 printf 'wf' length modifiers
wfN: Specifies that a following b, d, i, o, u, x, or X conversion specifier applies to a fastest minimum-width integer argument with a specific width where N is a positive decimal integer with no leading zeros (the argument will have been promoted according to the integer promotions, but its value shall be converted to the unpromoted type); or that a following n conversion specifier applies to a pointer to a fastest minimum-width integer type argument with a width of N bits. All fastest minimum-width integer types (7.22.1.3) defined in the header <stdint.h> shall be supported. Other supported values of N are implementation-defined.

Bug: b/271903607
Test: adb shell
Change-Id: Ida36d5a50af2a46fd04cb5fe039793d8872f9f3b
2023-05-02 21:06:09 +00:00
Elliott Hughes
2b8ca55d14 Fix the WIFSTOPPED definition.
Although this breaks job control in several shells (including mksh),
this has been broken since the initial commit and no-one's noticed until
now.

Bug: https://github.com/android/ndk/issues/1878
Test: treehugger
Change-Id: Id7c4805965c5e5847db99b57df1af13355adcc22
2023-05-01 19:48:12 +00:00
Almaz Mingaleev
d86a3ab241 Update tzcode from 2022a to 2023a.
57b8fc957a
changes the way overflows are tracked: now compiler builtins
are used instead of manual arithmetics. But as int_fast32_t on
64-bit Android takes 8 bytes, new logic behaves differently.
See time_test.cpp changes for more details.

Changes were applied using following commands:
  1) Checkout tzcode repo
  2) Prepare patches for all tzcode file using
    git diff 2022a 2023a -- <file-name> > <file-name-patch>
  3) Apply these patches to files in bionic using
    patch -p1 <file-name> <file-name-patch>

Bug: 279742606
Test: CtsBionicTestCases
Test: CtsLibcoreTestCases
Test: CtsLibcoreOjTestCases
Test: atest toybox-tests
Change-Id: I7772a90538b8185bdd2f4be6e9d1740c95509d6c
2023-04-28 16:52:53 +01:00
Elliott Hughes
0593e7922f Merge "C23: add timespec_getres() and the new TIME_* constants." 2023-04-27 15:25:06 +00:00
zijunzhao
e1833e54a7 Set __BIONIC_COMPLICATED_NULLNESS for the vsnprintf family
When annotating the netinet directory aosp/2552567, we realize the
argment s for vsnprintf family can be null only if the buffer size is 0.
So we correct them and add some tests to verify our assumption.

Bugs: b/245972273
Test: adb shell
Change-Id: I51063286272be0daee0d7c1453a374b1f5674481
2023-04-26 23:14:36 +00:00
Elliott Hughes
52541eea33 C23: add timespec_getres() and the new TIME_* constants.
Nothing to see here --- you'll want to keep using POSIX clock_gettime()
and clock_getres() instead. But portable code might use this eventually,
and it's trivial, so let's add it anyway.

(The whole "zero as an error return" precluding the direct use of
Linux's CLOCK_ constants is what really makes this a terrible API ---
we're going to have to add explicit translation any time they add a
new base.)

Test: treehugger
Change-Id: Iddb6cbe67b67b2b10fdd8b5ee654896d23deee47
2023-04-25 17:29:22 -07:00
Elliott Hughes
88ba3c1af3 Fix the hwasan_test copyright header.
Someone uploaded --no-verify, and now I'm being asked to change the
NOTICE file. Instead, let's just use the existing BSD header for 2023,
since we've been trying to keep the tests BSD licensed anyway.

Test: treehugger
Change-Id: I4a5b1a50c65bebaaa3015634b67868b3b7a7ce32
2023-04-24 17:10:20 -07:00
Zijun Zhao
727ebe08ca Merge "Nullability check for sem module." 2023-04-22 01:13:01 +00:00
Elliott Hughes
d25afca1cc Fix pthread#pthread_heap_allocated_stack for jemalloc.
Since we need a page-aligned allocation for a thread stack, explicitly
ask for one. (Scudo happens to just give us one anyway for an allocation
this large, but 32-bit jemalloc does not.)

Bug: http://b/277598913
Test: treehugger
(cherry picked from https://android-review.googlesource.com/q/commit:18e335b3da7ae1afd74055cbe7f0d85541863691)
Merged-In: I41eeb6aadb6a22bf5d9619e768e5e0a76617f747
Change-Id: I41eeb6aadb6a22bf5d9619e768e5e0a76617f747
2023-04-21 22:37:54 +00:00
Elliott Hughes
1c1e1a6f04 Merge "Fix pthread#pthread_heap_allocated_stack for jemalloc." 2023-04-21 22:18:00 +00:00
zijunzhao
271d4d2515 Nullability check for sem module.
Bugs: b/245972273
Test: adb shell
Change-Id: Ie29aa34c449300c53591557c99b6ec08ebe3efcf
2023-04-21 21:34:11 +00:00
Elliott Hughes
18e335b3da Fix pthread#pthread_heap_allocated_stack for jemalloc.
Since we need a page-aligned allocation for a thread stack, explicitly
ask for one. (Scudo happens to just give us one anyway for an allocation
this large, but 32-bit jemalloc does not.)

Bug: http://b/277598913
Test: treehugger
Change-Id: I41eeb6aadb6a22bf5d9619e768e5e0a76617f747
2023-04-21 11:18:40 -07:00
zijunzhao
3b846ea6e7 Implement C23 printf 'w' length modifiers
wN: Specifies that a following b, d, i, o, u, x, or X
conversion specifier applies to an integer argument with
a specific width where N is a positive decimal integer with
no leading zeros

Bug: b/271903607
Test: adb shell
Change-Id: I688f6cefeb2e5c8325b007a59935a46f4116ac29
2023-04-20 20:34:33 +00:00
Zijun Zhao
e2c25fa87f Merge "stdio_test: improve the %b/%B tests." 2023-04-20 18:59:59 +00:00
Elliott Hughes
e393d48bc7 Merge "Clarify dlfcn.dladdr_libc slightly." 2023-04-20 15:06:48 +00:00
zijunzhao
7ce2f95e28 Nullability check for wchar module.
Bugs: b/245972273
Test: adb shell
Change-Id: I9898a1120c2364e5269633a67bf789a8bb943ba5
2023-04-20 01:41:49 +00:00
Elliott Hughes
e50d9d2418 stdio_test: improve the %b/%B tests.
Test all the widths, and test the PRIb* macros too.

Test: treehugger
Change-Id: I86c222b4c6282ab557e6456a892c007f09cd53db
2023-04-19 16:41:37 -07:00
Elliott Hughes
17b2bae190 Merge "Make tmpfile() respect $TMPDIR." 2023-04-19 20:01:51 +00:00
Elliott Hughes
0cf311c53b Clarify dlfcn.dladdr_libc slightly.
This isn't a very helpful way to say "realpath() failed":
```
bionic/tests/dlfcn_test.cpp:(1006) Failure in test dlfcn.dladdr_libc
Value of: realpath("/system/lib64/" "hwasan/libc.so", libc_realpath) == libc_realpath
  Actual: false
Expected: true
```

Bug: http://b/278795547
Test: treehugger
Change-Id: I1078ab4a675b956327f2578086a1a5e7d8a2928b
2023-04-19 20:01:17 +00:00
Elliott Hughes
8b86c0bdeb Make tmpfile() respect $TMPDIR.
Contrary to the old comment, POSIX says nothing about whether or not
tmpfile() respects $TMPDIR, and it's significantly more useful on
Android if it does (because there's no shared /tmp that everyone can
write to).

Bug: https://issuetracker.google.com/36991167
Test: treehugger
Change-Id: I3cc45adff167420f100c8ed1c63cba1ea67e9f70
2023-04-18 17:11:06 -07:00
Treehugger Robot
a1ff2e6159 Merge "Nullability check for msg module." 2023-04-17 18:09:10 +00:00
zijunzhao
c76899fe5e Nullability check for msg module.
Bugs: b/245972273
Test: adb shell
Change-Id: Iefb2ae298240b91fcf5657aca0e6f8370095f50b
2023-04-15 01:13:26 +00:00
Florian Mayer
4967017c86 Merge "Introduce hwasan mode for linker" 2023-04-14 23:27:56 +00:00
Colin Cross
6ff7f99b61 Merge "Skip utmp_test.cpp for musl" 2023-04-14 19:39:37 +00:00
Colin Cross
118202b132 Skip utmp_test.cpp for musl
Musl #defines utmp to utmpx, which causes the tests in utmp_test.cpp
to collide with the ones in utmpx_test.cpp.  Skip the utmp_test.cpp
when building for musl.

Test: m USE_HOST_MUSL=true
Change-Id: Ie05ddf6e1fd8c3bcc687d2537c19b6ab70ab8d67
2023-04-14 09:33:11 -07:00
Treehugger Robot
177b724cb4 Merge "Nullability check for random module." 2023-04-14 14:41:12 +00:00
Florian Mayer
c10d064b5c Introduce hwasan mode for linker
This mode instructs the linker to search for libraries in hwasan
subdirectories of all library search paths. This is set up to contain a
hwasan-enabled copy of libc, which is needed for HWASan programs to
operate. There are two ways this mode can be enabled:

* for native binaries, by using the linker_hwasan64 symlink as its
  interpreter
* for apps: by setting the LD_HWASAN environment variable in wrap.sh

Bug: 276930343
Change-Id: I0f4117a50091616f26947fbe37a28ee573b97ad0
2023-04-14 01:33:30 -07:00
zijunzhao
e43d55348f Nullability check for random module.
Bugs: b/245972273
Test: adb shell
Change-Id: Ie7e06bcf4fda1b177c8d8fcb6a813c1b4a50ea26
2023-04-14 01:01:37 +00:00
zijunzhao
d3e0652877 Nullability check for semaphore module
Bugs: b/245972273
Test: adb shell
Change-Id: I52598efabf40a49dc75057dc8acb8228ed039fca
2023-04-12 18:07:11 +00:00
Christopher Ferris
80e5ee7e23 Merge "Add annotations." 2023-04-06 22:00:14 +00:00
Christopher Ferris
59075565d2 Add annotations.
Bug: 265431689

Test: NA
Change-Id: I0c19fc76b1ccdcb9f42167b52d1df247765fcd34
Merged-In: I0c19fc76b1ccdcb9f42167b52d1df247765fcd34
(cherry picked from commit ed4ad19662)
2023-04-06 19:30:23 +00:00
Elliott Hughes
7b5cc4b251 Merge "<spawn.h>: add posix_spawn_file_actions_addchdir_np()/posix_spawn_file_actions_addfchdir_np()." 2023-04-06 17:51:45 +00:00
Elliott Hughes
462ca8b314 <spawn.h>: add posix_spawn_file_actions_addchdir_np()/posix_spawn_file_actions_addfchdir_np().
The recent header nullability additions and the corresponding source
cleanup made me notice that we're missing a couple of actions that most
of the other implementations have. They've also been added to the _next_
revision of POSIX, unchanged except for the removal of the `_np` suffix.

They're trivial to implement, the testing is quite simple too, and
if they're going to be in POSIX soon, having them accessible in older
versions of Android via __RENAME() seems useful. (No-one else has shipped
the POSIX names yet.)

Bug: http://b/152414297
Test: treehugger
Change-Id: I0d2a1e47fbd2e826cff9c45038928aa1b6fcce59
2023-04-04 17:28:39 -07:00
Elliott Hughes
dbf5b2eb55 Add POSIX <utmpx.h>.
Now <utmpx.h> isn't any more useful on Android than <utmp.h> is, but it
is POSIX, and -- importantly -- we can implement it with just a header
file, so code can use it on every existing API level.

macOS does indeed only have the <utmpx.h> functions (although it does
still have the <utmp.h> header!), so potentially portable code might
want <utmpx.h> on Android. (glibc/musl both have both headers.)

Bug: https://github.com/landley/toybox/pull/213
Test: treehugger
Change-Id: Iaa88167708182009a63e2e1a15f11186b251ed02
2023-04-03 17:20:58 -07:00
Mitch Phillips
e6d5099fcc Merge "[GWP-ASan] Remove system_default torture tests." 2023-04-03 17:05:35 +00:00
zijunzhao
2146303272 Nullability check for sched module.
Bugs: b/245972273
Test: adb shell
Change-Id: Icb8028ec5864370c0ebfb300f9b6df01edf2742d
2023-03-29 21:46:57 +00:00
Mitch Phillips
c59d5cc5f1 [GWP-ASan] Remove system_default torture tests.
While these tests were running, other native processes would get torture GWP-ASan. This can lead to OOMs.

Bug: 273904016
Change-Id: Ia813a73bfc1c379633be022dbf4b7d567069c731
Test: atest bionic-unit-tests (in presubmit)
2023-03-27 14:34:40 +00:00
Treehugger Robot
bc28931eb9 Merge "Skip the MemtagNoteTests when the overriding sysprop is set." 2023-03-23 22:36:51 +00:00
Peter Collingbourne
d642c30ee0 Skip the MemtagNoteTests when the overriding sysprop is set.
Bug: 273807460
Change-Id: Ieb33354fd8a705c1b2a661055f69d2ec4b32b5e8
2023-03-22 20:08:42 -07:00
Treehugger Robot
688bddc1e5 Merge "Fix setjmp.bug_152210274 with HWASan/stack MTE enabled." 2023-03-22 23:29:31 +00:00
Peter Collingbourne
85a7f6b391 Merge "Disable stack tagging in CloneStartRoutine." 2023-03-22 21:14:54 +00:00
Peter Collingbourne
25a7c3fd57 Fix setjmp.bug_152210274 with HWASan/stack MTE enabled.
This test was flaky because there was no synchronization between the end
of the test function scope and the jumper threads, resulting in a racy
use-after-scope when accessing the thread array. Fix it by joining the
threads before leaving the test function scope.

Replace the thread array access, which can race with the store to the
thread array in the main thread, with an access to a pre-initialized
variable, which acts as a kind of enforcement that the threads are done
before leaving the test.

Bug: 227390656
Change-Id: Icfbb0d7cae66c12e5ce31072c34529e3c5fdf563
2023-03-22 13:49:53 -07:00
Peter Collingbourne
955f04425e Disable stack tagging in CloneStartRoutine.
We don't support running threads on a tagged stack. Untagging SP may
lead to accesses to the stack via a non-SP register, which will be tag
checked, and the check will fail. And indeed that's exactly what the
__bionic_clone function does in its first instruction. Fix the problem by
disabling HWASan and MTE stack tagging on CloneStartRoutine, and remove
the call to untag_address, as it is unnecessary.

Bug: 273807460
Change-Id: I94cc56c816897531c0113c856b54ec41b4aab874
2023-03-21 22:57:50 -07:00
Elliott Hughes
060cd2438c Merge "riscv64 SCS support." 2023-03-21 22:10:56 +00:00
Christopher Ferris
35759fa84c Fix mte build breakage.
The strerror_buf is way too large, so instead of using a separate
buffer for just this string, reuse the already existing buffer.
Increase the buffer size to cover the maximum errno string.

Add a unit test to verify that none of the errno values are cut off
in the async_safe_format_buffer function when passing %m.

Bug: 274474681

Test: New unit test passes.
Test: Changing the buffer to a small value and verify that the test fails.
Change-Id: I4cb4652709582a8a6b958e12de5d923ec950e6b6
2023-03-21 18:11:02 +00:00
Christopher Ferris
dcd1403818 Merge "Add support for M_PURGE_ALL." 2023-03-17 21:06:20 +00:00
zijunzhao
106aa0074d Nullability check for locale module
Bugs: b/245972273
Test: adb shell
Change-Id: If730065895e0f074318df545906b7e60fcae053d
2023-03-16 21:42:57 +00:00
Yi Kong
714a33d32d Set optnone attribute for modify_stack_protector_test
clang-r487747 gets too clever and removes the store, even if it is
declared as volatile. Set optnone to prevent the compiler optimizing out
the store.

Test: atest CtsBionicTestCases
Bug: 271214588
Change-Id: I14a537ecd4657ee3f510ff531313bd9d56f22f47
2023-03-15 01:03:59 +09:00
Christopher Ferris
d86eb8665c Add support for M_PURGE_ALL.
This is a new mallopt option that will force purge absolutely
everything no matter how long it takes to purge.

Wrote a unit test for the new mallopt, and added a test to help
verify that new mallopt parameters do not conflict with each other.

Modified some benchmarks to use this new parameter so that we can
get better RSS data.

Added a new M_PURGE_ALL benchmark.

Bug: 243851006

Test: All unit tests pass.
Test: Ran changed benchmarks.
Change-Id: I1b46a5e6253538108e052d11ee46fd513568adec
2023-03-13 19:55:32 -07:00
Zijun Zhao
2c445d9979 Merge "Nullability check for stdio module" 2023-03-08 05:16:57 +00:00
Elliott Hughes
b6e7e2c39b Merge "Remove #pragma workarounds for %b/%B." 2023-03-07 16:24:18 +00:00
zijunzhao
00a3dbaab6 Nullability check for stdio module
Bugs: b/245972273
Test: adb shell
Change-Id: I6d1f2afad6ab3f884795a2d33875684a14fe54d6
2023-03-07 01:07:19 +00:00
Elliott Hughes
6f231ce503 Remove #pragma workarounds for %b/%B.
We have a new enough clang now that it knows about %b/%B.

Test: treehugger
Change-Id: I92f21e3bebdd652a4826ce8caa33400c3e3db72f
2023-03-06 23:30:12 +00:00
Florian Mayer
ee824ae6e0 Merge "add test for using malloced stack for pthread_create" 2023-03-06 20:52:25 +00:00
Christopher Ferris
90dd5f0fd1 Merge "Don't run GWP ASan integration tests under HWASan." 2023-03-03 01:48:58 +00:00
Florian Mayer
f966620ca0 add test for using malloced stack for pthread_create
Bug: 148982147
Change-Id: I65e284a083236f1a552fb1e2fefe1c268ed2ecc3
2023-03-02 15:34:10 -08:00
Christopher Ferris
92a4d2bcee Don't run GWP ASan integration tests under HWASan.
Bug: 267386540

Test: All unit tests pass on normal build.
Test: All GWP ASan tests are skipped under hwasan.
Change-Id: I6d6860090b62e7187cf947de0a9bc30d00330554
2023-03-02 21:57:12 +00:00
Zijun Zhao
6bda367899 Merge "Nullability check for dlfcn module" 2023-03-02 00:32:47 +00:00
Florian Mayer
2b67014e11 Disable elftls_dl#dtv_resize on HWASan
A new TLS variable was added to HWASan RT in the new toolchain and
this tests needs to be adjusted. Skipping for now.

Bug: 271243811
Change-Id: Ie6664a9ac350624e8e963a36e4248d0d051bc8c1
2023-03-01 21:40:17 +00:00
zijunzhao
447c346475 Nullability check for dlfcn module
Bugs: b/245972273
Test: adb shell
Change-Id: I0ecde8a0f1f71b6ec2262ff637d33c518578d54d
2023-03-01 21:29:41 +00:00
Elliott Hughes
9a7155dbbd riscv64 SCS support.
Bug: https://github.com/google/android-riscv64/issues/55
Test: treehugger
Change-Id: I05d48a07a302305126942d38529ffa280640c7b7
2023-02-23 01:21:07 +00:00
Christopher Ferris
8ab38e2b9a Skip zeroed malloc tests on hwasan.
The gwp_asan_integration.malloc_tests_under_torture test fails
when trying to run the malloc.zeroed* tests. So skip these
tests in that config.

Bug: 267386540

Test: All tests pass in hwasan and normal config.
Change-Id: I8edce28ee21eeecbcc9afb7db4ffdb6371a914b0
2023-02-07 13:11:05 -08:00
Mitch Phillips
7a8366fede Extend bionic-unit-tests timeout.
GWP-ASan stress tests can take a while, especially under HWASan.

Bug: 238585984
Test: sleep(100) in one of the tests, and then 'atest bionic-unit-tests'
Merged-In: Ibd983da1c8fd06cffed756cf3b24523f4671d49e
Change-Id: Ibd983da1c8fd06cffed756cf3b24523f4671d49e
(cherry picked from commit 1f3c8d688c)
2023-02-01 12:43:34 +00:00
Christopher Ferris
02b6bbc7b7 Verify that allocated memory is always zeroed.
If this is a low ram device, then do not run these tests. Otherwise,
verify that memory returned from the allocator is zero.

Bug: 171429763
Bug: 264539505
Bug: 265431478

Test: New unit tests pass on scudo.
Test: New unit tests fail on original jemalloc.
Test: New unit tests pass on jemalloc that always zeroes memory.
Test: New unit tests are skipped on low ram device.
Test: Ran unit tests atest CtsBionicTestCases in above scenarios.
Change-Id: Id62ab74f649c0f7c14a951235fe79972926ecec0
2023-01-26 15:19:09 -08:00
zijunzhao
d9755064a6 Nullability check for utmp module
Bugs: b/245972273
Test: None
Change-Id: Ie37781b87ad13119d1ebc4cd053e184d482d5b58
2023-01-25 19:22:27 +00:00
Treehugger Robot
0ad996d4eb Merge "Re-enable the POSIX header tests for musl." 2023-01-20 02:57:33 +00:00
Elliott Hughes
d05de20794 Re-enable the POSIX header tests for musl.
Bug: http://b/265874089
Test: treehugger
Change-Id: I05892d4a57fcceab0322c910d6482929b82bc5ee
2023-01-19 21:39:37 +00:00
Treehugger Robot
c3952c9059 Merge "Add #ifdefs to make POSIX header tests pass for musl" 2023-01-19 21:31:25 +00:00
Colin Cross
b6830ca1fc Add #ifdefs to make POSIX header tests pass for musl
Bug: 265874089
Test: m USE_HOST_MUSL=true libbionic_tests_headers_posix
Change-Id: I6ae3ed3b91d5389f838b4a4f66c86bb00a27561a
2023-01-19 11:28:28 -08:00
Christopher Ferris
2ef59371ff Only run mallopt_smoke test on bionic.
Even though glibc has mallopt, there is no way to guarantee that
we use an invalid argument. Since this test is only really useful
for bionic, only run it on bionic.

Test: Ran glibc and verified the test is skipped.
Change-Id: If991e8804b21c83f3d7e3b15a0b60e48da331567
2023-01-18 15:08:37 -08:00
zijunzhao
e620266d1c Nullability check for time module.
Bugs: b/245972273
Test: None
Change-Id: I65adc146f88bbd948f61d2f22bdec344faba09ae
2023-01-05 00:18:18 +00:00
Chih-hung Hsieh
dc9ad89dfe Merge "Disable clang-tidy for malloc_test.cpp" 2022-12-16 20:20:51 +00:00
Chih-Hung Hsieh
6fae614060 Disable clang-tidy for malloc_test.cpp
Many clang-analyzer-unix.Malloc warnings from this file
are leaks after test failure and we can ignore them.
Clang-tidy cannot compile this file within 90 second
time limit most of the time, which makes maintaining
it free of clang-tidy warnings impractical.

Bug: 259995529
Test: presubmit; make tidy-bionic-tests_subset
Change-Id: I532c761744b0400dec33363a3235f81ac7fbbb30
2022-12-15 19:35:13 -08:00
Ryan Prichard
d791a6501e Merge changes I7ba9cef9,Ia191be0b,I16ba3dc8
* changes:
  Expose unwinder APIs in NDK stubs for R and up.
  Use abi::__cxa_demangle declared in cxxabi.h
  __cxa_atexit_test: declare __cxa_atexit and __cxa_finalize
2022-12-13 00:53:40 +00:00
Ryan Prichard
c2adad1815 Use abi::__cxa_demangle declared in cxxabi.h
Bug: http://b/175635923
Test: treehugger
Change-Id: Ia191be0b4861b011640edc703b55c13c88bce300
2022-12-09 16:10:00 -08:00
Ryan Prichard
321f34979c __cxa_atexit_test: declare __cxa_atexit and __cxa_finalize
After updating libc++, they're no longer declared in cxxabi.h, so the
test must declare them locally.

8bd0dc5bfe

Temporarily use a return type of "int" to avoid a Clang error about
conflicting return types.

Bug: http://b/175635923
Test: treehugger
Change-Id: I16ba3dc8cc84cc18ee7fbfe9d2e3fa0cd4eefeae
2022-12-08 17:43:29 -08:00
Elie Kheirallah
056549795c Add rlim64_t to libc/include/sys/resource
crosvm is using rlim64_t. Adding for portability.

Bug: 255594691
Test: m libc && m bionic
Change-Id: I752bfdaa23d900278fe7224306d785b0c9f67d3f
2022-12-08 23:32:11 +00:00
zijunzhao
5a918d922b Nullability check for stdlib module.
Bugs: b/245972273
Test: None

Change-Id: Ib33a5359a924c21888f268158c4d7f824740dd55
2022-12-02 21:00:02 +00:00
Florian Mayer
7c2ce66b52 Merge "[MTE] test for exception cleanup." 2022-12-02 00:54:32 +00:00
Elliott Hughes
dfe67d266c Tell people when they've messed up with fcntl(FD_SETFD).
This is a subtle bug that even experts struggle with.

Test: treehugger
Change-Id: If9cf16a1c32c836f5688bb3374cfd21d55125b17
2022-11-30 20:19:22 +00:00
Elliott Hughes
ec9f023f41 Add invalid riscv64 ELF files for the linker tests.
The libtest_empty.so was built by the "libtest_empty" build rule, and
the other files are copies of that with small edits made by the toybox
hexedit tool. I worked out what to edit in each case from a combination
of "what does the name imply?" and "what does a diff of the xxd output
of the corresponding two arm64 files show?".

I failed to produce a working (by which I mean "failing") local-tls
file despite my best efforts. I'm not sure what exactly it was about the
gold-generated files we didn't like, because the commentary implies that
this would be problematic:

    39: 0000000000000004     4 TLS     LOCAL  DEFAULT   12 tls_var_2

But it loads without complaint.

Test: ran locally
Change-Id: I3b9b2b4db1f8827243541cf13380c6ceb840f123
2022-11-16 00:52:26 +00:00
Elliott Hughes
73840b56b2 Merge "Update sys_ptrace_test.cpp for riscv64." 2022-11-15 17:22:35 +00:00
Elliott Hughes
89719df107 Update sys_ptrace_test.cpp for riscv64.
We'll want to come back to this once either Zcmp's push/pop instructions
or V's vector loads/stores are available. But for now, we have no >64b
stores.

But at least this builds.

Test: treehugger
Change-Id: I9503e890cacb198f4ba987bfc92f6eff21c290b0
2022-11-12 00:08:17 +00:00
Elliott Hughes
fc03503f67 Update a comment to be more intention-revealing.
And also inclusive of riscv64.

Test: treehugger
Change-Id: I27280e1d934ce3bb47026820b75850c824801022
2022-11-11 22:52:04 +00:00
dimitry
2cc2910e70 Disable MemtagNoteTest#SEGV for native bridge
This commit disables MemtagNoteTest#SEGV when running
on native bridge.

Bug: http://b/242170715
Test: run arm64 Bionic tests on T Emulator
Change-Id: I8ae99c5ba22f09a8d7e751f8bb4938894abe231f
2022-11-08 05:50:07 +00:00
Florian Mayer
f5f4112b07 [MTE] test for exception cleanup.
This depends on the LLVM change https://reviews.llvm.org/D135639.

Test: adb shell /data/local/tmp/stack_tagging_helper exception_cleanup
Bug: 174878242
Change-Id: Ia1dfdbe482b40c174acaf6c1ac4ad054470d10b8
2022-11-07 18:17:44 -08:00
dimitry
dd64a6e28a Disable MemtagNoteTest#SEGV for native bridge
This commit disables MemtagNoteTest#SEGV when running
on native bridge.

Bug: http://b/242170715
Test: run arm64 Bionic tests on T Emulator
Change-Id: I8ae99c5ba22f09a8d7e751f8bb4938894abe231f
2022-11-07 18:39:42 +01:00
Orion Hodson
974b15e0ab Merge "Fix-up for change in pwd/grp ids for PRNG seeder daemon" into android13-tests-dev am: d06e75b7e3
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2273426

Change-Id: I4d17c2c68d9661530371c53d109410397edbe7c5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-10-31 07:54:37 +00:00
Orion Hodson
f5fd5adf04 Fix-up for change in pwd/grp ids for PRNG seeder daemon
The PRNG seeder daemon is introduced in TM-QPR2 which can lead to
breakage running Android 13 CTS tests depending on when the platform
and CTS tests are built.

Fix: 253185870
Test: run cts --module CtsBionicTestCases
Change-Id: I94fa0aa2f32b09222aee08891e7643bf14d1a204
2022-10-27 11:21:29 +01:00
Treehugger Robot
4b0e16bc72 Merge "Fix stdio -NaN tests for riscv64." 2022-10-26 02:17:22 +00:00
Elliott Hughes
e0a9a3836c Fix stdio -NaN tests for riscv64.
riscv64 hates nans. From the spec: "Except when otherwise stated, if the
result of a floating-point operation is NaN, it is the canonical NaN.
The canonical NaN has a positive sign and all significand bits clear
except the MSB, a.k.a. the quiet bit."

This broke our tests here because the float-to-double instruction isn't
one of the "otherwise stated" cases, so it turns -nanf() into +nan().
The sign manipulation instructions are "otherwise stated" cases, though,
so as long as we avoid a conversion we're fine. And we didn't actually
_need_ a float here (pretty much by definition, since varargs means you
always end up with a double anyway), so we can just simplify things and
switch to using doubles directly to fix the tests.

Test: bionic-unit-tests-static
Change-Id: I13aa452dd6cc8708275f7676b37fc772b37a7b32
2022-10-25 22:56:43 +00:00
Elliott Hughes
4ceb3474be Add riscv64 lrint.S.
This is mainly just to match what we have for arm64.

The test failures before and after this change are all for the long
double variant, which this change doesn't touch. (The problem there is
that clang is calling `__fixtfdi` for the cast in lrintl(), but that
doesn't respect the current rounding mode, which lrintl() is required
to do. `#pragma STDC FENV_ACCESS ON` doesn't fix this, so there's going
to be some llvm work needed to fix this.)

I've replaced the ASSERTs with EXPECTs in the relevant test to ensure
we're checking all the other assertions despite the `long double`
failures.

Test: bionic-unit-tests-static
Change-Id: Ia24bf21619631b6f8b3b607d30536011bb4cd826
2022-10-25 22:27:10 +00:00
Treehugger Robot
b9af0678e1 Merge "Fix bionic tests for undefined __SIGRTMIN in musl" 2022-10-20 23:12:21 +00:00
Colin Cross
23b986c0c8 Fix bionic tests for undefined __SIGRTMIN in musl
Musl doesn't export __SIGRTMIN, and it is being removed from the
Android wrappers to avoid accidentally referencing bionic's
reserved signals when compiling against musl.

Bug: 190084016
Test: m USE_HOST_MUSL=true host-native -k
Change-Id: I342666a17abc31bbc57b383b5cc881c2752886f7
2022-10-20 13:16:21 -07:00
Treehugger Robot
f2be65d0f7 Merge "Remove explicit lists of ABIs." 2022-10-19 18:08:17 +00:00
Elliott Hughes
3f73ea6547 Remove explicit lists of ABIs.
Rather than add riscv64 to these lists, let's just outsource to libbase.

Test: treehugger
Change-Id: Ifd0f19564b9bca4544ef60c05eda9591fd8958dd
2022-10-19 16:20:02 +00:00
Elliott Hughes
017bd9882a riscv64: fix <fenv.h> tests.
Group riscv64 with arm/arm64, and allow for the fact that there's no
FE_DENORMAL in the riscv64 spec.

Test: fenv.*
Change-Id: Ibf188bcedffd092a7ef1555fa2762e249e1f9845
2022-10-18 23:47:28 +00:00
Elliott Hughes
e1905ed629 riscv64 setjmp.
Signed-off-by: Mao Han <han_mao@linux.alibaba.com>
Signed-off-by: Xia Lifang <lifang_xia@linux.alibaba.com>
Signed-off-by: Chen Guoyin <chenguoyin.cgy@linux.alibaba.com>
Signed-off-by: Wang Chen <wangchen20@iscas.ac.cn>
Signed-off-by: Lu Xufan <luxufan@iscas.ac.cn>
Test: m
Change-Id: I02cf117f67bda74516e4de8cd6f4c05efdb9a85b
2022-10-17 23:23:36 +00:00
Elliott Hughes
d25a5e73f8 Add an explicit test that fegetenv()/fesetenv() includes the rounding mode.
I haven't found this explicitly stated anywhere, but it's how our
existing implementations behave, and it seems obviously implied by
the word "entire" in POSIX's claim that fenv_t "Represents the entire
floating-point environment".

Test: treehugger
Change-Id: Ic8fc993775b4ded57dc88766a7d24d0954f3b56d
2022-10-14 20:55:23 +00:00
Elliott Hughes
5cc8a46419 riscv64's struct stat is the same as arm64's.
(And all other new architectures.)

Signed-off-by: Mao Han <han_mao@linux.alibaba.com>
Signed-off-by: Xia Lifang <lifang_xia@linux.alibaba.com>
Signed-off-by: Chen Guoyin <chenguoyin.cgy@linux.alibaba.com>
Signed-off-by: Wang Chen <wangchen20@iscas.ac.cn>
Signed-off-by: Lu Xufan <luxufan@iscas.ac.cn>
Test: treehugger
Change-Id: Iceb2dd16c738302624980179788c4a2e68b797ed
2022-10-06 00:26:18 +00:00
Automerger Merge Worker
4b13827fe4 Merge "Merge "stack_protector_DeathTest#modify_stack_protector: avoid flake." into android12-tests-dev am: 793d1fb5ab" into android12L-tests-dev am: 6aa3bdfb16
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2240186

Change-Id: I479c56a6509cef84a1f614a937a6434ebce5dbcd
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-10-06 00:22:47 +00:00
Florian Mayer
e2a10da5be Merge "Do not strip bionic test helpers" 2022-10-04 16:13:59 +00:00
Elliott Hughes
b24c89b4df stack_protector_DeathTest#modify_stack_protector: avoid flake.
I've never been able to repro the flake myself (in hundreds of thousands
of runs), but it's certainly possible that a byte of the cookie is
already zero. So let's invert the byte we plan to corrupt rather than
set it to zero.

Bug: http://b/202948861
Test: treehugger
Change-Id: Iccd552fe302d6c01e376819d23c11a308e03acdb
(cherry picked from commit 23ce50c172)
2022-10-04 00:00:50 +00:00
Florian Mayer
37b4a152a4 Do not strip bionic test helpers
Change-Id: I651511cf11d38f8012ddf968dacae530e7a66d69
2022-10-03 23:35:22 +00:00
Florian Mayer
7819140c5a [MTE] use GTEST_SKIP on non-MTE hw for memtag_stack_test
Bug: 174878242
Change-Id: If980ac4d9bf4bada6e150a5f30c486bdd6de3508
2022-09-30 23:02:52 +00:00
Colin Cross
26532523c6 Cast sysinfo.uptime for musl
Upstream musl libc defines sysinfo.uptime as unsigned long, while the
kernel and glibc define it as long.  Cast it to long for the
comparision.

Bug: 190084016
Test: bionic-unit-tests-glibc
Change-Id: Ib322472d512a9a7474a936e33f35523e1dc995d9
2022-09-29 11:15:06 -07:00
Elliott Hughes
23ce50c172 stack_protector_DeathTest#modify_stack_protector: avoid flake.
I've never been able to repro the flake myself (in hundreds of thousands
of runs), but it's certainly possible that a byte of the cookie is
already zero. So let's invert the byte we plan to corrupt rather than
set it to zero.

Bug: http://b/202948861
Test: treehugger
Change-Id: Iccd552fe302d6c01e376819d23c11a308e03acdb
2022-09-27 22:37:03 +00:00
Elliott Hughes
82be76b5a2 Add __freadahead.
At the time I added <stdio_ext.h>, I just added what was on the man
page (which matched glibc), not realizing that musl and glibc had
slightly different functionality in their headers.

The toybox maintainer came up with a legitimate use case for this, for
which there is no portable workaround, so I'm adding it here. I'm not
adding the other functions that are in musl but not glibc for lack of a
motivating use case.

Bug: http://lists.landley.net/htdig.cgi/toybox-landley.net/2022-April/020864.html
Test: treehugger
Change-Id: I073baa86ff0271064d4e2f20a584d38787ead6b0
2022-09-22 23:47:42 +00:00
Florian Mayer
298bcecead Merge "Add android_mallopt to query MTE stack state" 2022-09-09 00:49:08 +00:00
Christopher Ferris
76da7bad0e Fix tests/NOTICE file.
Some previous change did not update the NOTICE file properly.

Test: Uploads.
Change-Id: I9d1797cbb7d0d0485e697e8038497f182e33446c
2022-09-08 21:54:29 +00:00
Florian Mayer
cc61ad895e Add android_mallopt to query MTE stack state
Bug: 244364391
Change-Id: Ie6267201f0c2e293b27c71cd160a2311c9de8091
2022-09-07 23:38:42 +00:00
Florian Mayer
44742701c9 Merge "Revert^2 "memtag_stack tests."" 2022-09-01 19:29:33 +00:00
Florian Mayer
c82d7fcd22 Revert^2 "memtag_stack tests."
8162b05ccd

Change-Id: I68c1988b0d76dddfaf69189cfd439192cabda00d
2022-08-31 20:57:03 +00:00
Florian Mayer
376e9b07ca Merge "Revert "memtag_stack tests."" 2022-08-31 18:37:29 +00:00
Florian Mayer
8162b05ccd Revert "memtag_stack tests."
Revert "[soong] Add memtag-stack sanitizer, switch to linker-gen..."

Revert submission 2096883-memtag-stack

Reason for revert: b/244454542
Reverted Changes:
I7fee03d90:memtag_stack tests.
I52d2318c8:[soong] Add memtag-stack sanitizer, switch to link...

Change-Id: I0dac2a6a6757a78c9f831cd7cc463b0e0f6376c6
2022-08-31 18:30:18 +00:00
Florian Mayer
5c6c043820 Merge "memtag_stack tests." 2022-08-31 17:53:43 +00:00
Evgenii Stepanov
d624d2f3d9 memtag_stack tests.
This tests cover stack tagging setup in response to NT_MEMTAG_STACK and
vfork and longjmp support.

Bug: b/174878242
Test: fvp_mini with ToT LLVM
  SANITIZE_TARGET="memtag_heap"
  SANITIZE_TARGET="memtag_heap,memtag_stack"

Change-Id: I7fee03d901092d9428d86a6fab6bef4e2e3b51eb
2022-08-30 18:00:21 +00:00
Xin Li
75f40e8dcb Merge android12L-tests-dev@8941410.
Change-Id: I5c71068d05f27bff99f1adc17400c0ec709b4dd0
2022-08-17 22:08:00 -07:00
Elliott Hughes
f9fac36f15 Merge "Add C23's memset_explicit()." 2022-08-11 22:01:28 +00:00
Elliott Hughes
d1c3d4a454 Merge "Add %b and %B support to the scanf/wscanf and strto*/wcsto* families." 2022-08-11 21:22:23 +00:00
Elliott Hughes
1f462dec34 Add %b and %B support to the scanf/wscanf and strto*/wcsto* families.
Coming to C23 via WG14 N2630.

This one is a little interesting, because it actually changes existing
behavior. Previously "0b101" would be parsed as "0", "b", "101" by these
functions. I'm led to believe that glibc plans to actually have separate
versions of these functions for C23 and pre-C23, so callers can have the
behavior they (implicitly) specify by virtue of which -std= they compile
with. Android has never really done anything like that, and I'm pretty
sure app developers have more than enough to worry about with API levels
without having to deal with the cartesian product of API level and C
standard.

Therefore, my plan A is "if you're running on Android >= U, you get C23
behavior". My plan B in the (I think unlikely) event that that actually
causes trouble for anyone is "if you're _targeting_ Android >= U, you
get C23 behavior". I don't think we'd actually want to have two versions
of each of these functions under any circumstances --- that seems by far
the most confusing option.

Test: treehugger
Change-Id: I0bbb30315d3fabd306905ad1484361f5d8745935
2022-08-11 00:25:08 +00:00
Elliott Hughes
0d64243407 Add C23's memset_explicit().
https://open-std.org/jtc1/sc22/wg14/www/docs/n2897.htm

Test: treehugger
Change-Id: Ia0cfc72bdf3c22eda6a4fc9adaa4c0ca0ff9a7c8
2022-08-10 23:36:16 +00:00
Elliott Hughes
462c542855 Merge "Don't even try to allocate 2GiB on LP32." 2022-08-03 15:35:49 +00:00
Florian Mayer
5d35ab8f42 [MTE] Add comment about nested ScopedDisableMTE in test.
Change-Id: I02a4b44ebe1fad6f00b10d1083b43b52a0b5c316
2022-08-02 23:52:43 +00:00
Elliott Hughes
0cac2919fd Don't even try to allocate 2GiB on LP32.
std::vector will just throw std::length_error anyway...

Bug: http://b/241114825
Test: treehugger
Change-Id: I44a9be9a5357c7b3a1c1d1273ef90a023a91e81b
2022-08-02 18:25:22 +00:00
Elliott Hughes
b813a6a6be Add %b and %B support to the printf/wprintf family.
Coming to C23 via WG14 N2630, and already in glibc.

We're still missing clang support for %b and %B in format string checking,
but it's probably easier to fix this first. (Apparently GCC already has
support because of glibc.)

Test: treehugger
Change-Id: Ie8bfe4630d00c50e1d047d6756a7f799205356db
2022-08-01 22:18:40 +00:00
Elliott Hughes
27b3ad2c78 Merge "Simplify the implementation of get_nproc()." 2022-07-29 18:19:29 +00:00
Elliott Hughes
6f4bb0771e Merge "fread: cope with >2GiB totals." 2022-07-29 16:16:27 +00:00
Elliott Hughes
be78fc90e6 fread: cope with >2GiB totals.
The FILE::_read function pointer takes an int rather than a size_t, so
we need to be careful to break large reads up for it.

fwrite() hasn't (yet) been optimized in this way, so it's immune for
now, but add the corresponding write test anyway.

Seeking already uses a off64_t function pointer where possible, so I
don't think there's anything more to be done there.

No other function pointers in FILE are relevant.

Bug: https://issuetracker.google.com/240139009
Test: treehugger
Change-Id: Ife2537e10f178bb0d980719592539f4b00b67031
2022-07-28 20:58:45 +00:00
Elliott Hughes
d771a7cde3 Simplify the implementation of get_nproc().
It came up on the musl mailing list that there's not actually any need
to iterate over the directory entries:

https://www.openwall.com/lists/musl/2022/07/27/1

This lets us reuse the code for "online" processors in the
implementation of "configured" processors. The question of whether
"configured" should correspond to Linux's "possible" or "present" isn't
obvious to me, but the distinction seems unlikely to matter on mobile
devices anyway, and that's a trivial change should it ever be needed.
Plus the motivating argument from the person who brought this up was
that callers asking for "configured" processors are probably asking for
an upper bound, which sounds convincing to me.

Test: treehugger
Change-Id: I0d4e13538dc6b09a6dba520d9ac24f436906f7c0
2022-07-28 17:52:46 +00:00
Almaz Mingaleev
24bfd8eed7 Handle null TM_ZONE in z case in strftime.
For correct %z output tzcode requires tm struct to be modified by
mktime call or be output of localtime. But as TM_ZONE is null, we
are comparing against +0000.

See https://mm.icann.org/pipermail/tz/2022-July/031674.html

Europe/Lisbon test is added to confirm that current implementation
deviates from libc specification and uses more than just tm_isdst
to find out a time zone's offset.

Bug: 239128167

Test: adb shell /data/nativetest64/bionic-unit-tests-static/bionic-unit-tests-static
Test: adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static

Change-Id: Ic27775c840467c4e9ef55bc730a313709372314b
2022-07-25 16:39:12 +01:00
Almaz Mingaleev
10fed72517 Add post 2100 year mktime test.
tzdata now has transitions up to the year 2100. Added test to make
sure that dates beyond that are handled properly too.

Bug: 25413083

Test: see system/timezone CL
Change-Id: I02ea04b2c5cfb47bde5fb05f108113901ea33a39
2022-07-15 14:36:26 +01:00
Mitch Phillips
1f3c8d688c Extend bionic-unit-tests timeout.
GWP-ASan stress tests can take a while, especially under HWASan.

Bug: 238585984
Test: sleep(100) in one of the tests, and then 'atest bionic-unit-tests'
Change-Id: Ibd983da1c8fd06cffed756cf3b24523f4671d49e
2022-07-11 09:35:12 -07:00
Almaz Mingaleev
ecca88329b Merge "Revert "Revert "Do not look for tzdata file in /data.""" 2022-06-30 16:17:05 +00:00
Almaz Mingaleev
da75bb637d Revert "Revert "Do not look for tzdata file in /data.""
This reverts commit 4e013233b8.

Issue was in unexpected returned fd and errno value combination.
See comments in bionic.cpp and time_test.cpp.

Bug: 236967833
Fix: 236967833

Test: atest CtsBionicTestCases
Test: atest toybox-tests

Change-Id: I51b3e1527ff16b2a6ea4d6fedf8102019f7fd896
2022-06-30 09:39:53 +01:00
Mitch Phillips
9634c36565 Add persistent GWP-ASan sysprops.
Adds persistent sysprops for test infra usage, and adds the tests for
the sysprops.

The test does some fancy flocking in order to restore any existing
GWP-ASan sysprop usage in the test cleanup.

Bug: 236738714
Test: atest bionic-unit-tests
Change-Id: I8956296d39c98ce8c7dd0a703b240530d8ad48db
2022-06-29 09:25:13 -07:00
Almaz Mingaleev
0219fe82c6 Merge "Bump tzcode from 2016g to 2022a*." 2022-06-08 07:53:40 +00:00
Almaz Mingaleev
5411aff6bb Bump tzcode from 2016g to 2022a*.
Upstream has renamed tzsetlcl to tzset_unlocked. As bionic's
implementation of tzset_unlock differs from upstream, these changes were
skipped.

Also, upstream has removed constants (SECSPERMIN, etc) from tzfile.h. As
they are used in strptime.c, I've decided to leave them in tzfile.h and
to not bring them into strptime.c.

HAVE_TZNAME and USG_COMPAT flags semantics were updated, thus setting
their values to 2 in Android.bp file. See
1a27ec76bc

* 4742526b7e
and 0e8f0b06ac
were picked up, which are not part of 2022a.

Changes were applied using following commands:
  1) Checkout tzcode repo
  2) Prepare patches for all tzcode file using
    git diff 2016g 2021e -- <file-name> > <file-name-patch>
  3) Apply these patches to files in bionic using
    patch -p1 <file-name> <file-name-patch>

Bug: 25413083
Test: CtsLibcoreTestCases
Test: CtsLibcoreOjTestCases
Test: CtsBionicTestCases

Change-Id: I9aba4cbeab30171a32f94d20c8e4057804a4c01f
2022-06-07 09:59:16 +01:00
Evgenii Stepanov
3031a7e45e memtag_stack: vfork and longjmp support.
With memtag_stack, each function is responsible for cleaning up
allocation tags for its stack frame. Allocation tags for anything below
SP must match the address tag in SP.

Both vfork and longjmp implement non-local control transfer which
abandons part of the stack without proper cleanup. Update allocation
tags:
* For longjmp, we know both source and destination values of SP.
* For vfork, save the value of SP before exit() or exec*() - the only
  valid ways of ending the child process according to POSIX - and reset
  tags from there to SP-in-parent.

This is not 100% solid and can be confused by a number of hopefully
uncommon conditions:
* Segmented stacks.
* Longjmp from sigaltstack into the main stack.
* Some kind of userspace thread implementation using longjmp (that's UB,
  longjmp can only return to the caller on the current stack).
* and other strange things.

This change adds a sanity limit on the size of the tag cleanup. Also,
this logic is only activated in the binaries that carry the
NT_MEMTAG_STACK note (set by -fsanitize=memtag-stack) which is meant as
a debugging configuration, is not compatible with pre-armv9 CPUs, and
should not be set on production code.

Bug: b/174878242
Test: fvp_mini with ToT LLVM (more test in a separate change)

Change-Id: Ibef8b2fc5a6ce85c8e562dead1019964d9f6b80b
2022-05-27 13:19:34 -07:00
Colin Cross
1b8ebeab1c Disable close_range test for musl
Musl doesn't have close_range, skip the test.

Bug: 190084016
Test: m USE_HOST_MUSL=true host-native
Change-Id: I7ed485f2d0ec08358c856430b7c4c45fbe45a39f
2022-05-23 16:07:22 -07:00
Automerger Merge Worker
d285f43605 Merge "Merge "mntent_test: don't assume /proc isn't the first mount." into android10-tests-dev am: 0462cfb766" into android11-tests-dev am: 0a5cc21c42
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2098734

Change-Id: Ic585470d3f383c9dcbc6e989b46ec8d6ce17eefd
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-18 00:51:35 +00:00
Shubhangi Pawar
ab9bb66180 Merge "mntent_test: don't assume /proc isn't the first mount." into android10-tests-dev am: 0462cfb766
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2098734

Change-Id: I92a208d548197b48fc35082b5e219895bf16a904
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-18 00:32:22 +00:00
Elliott Hughes
1727595b0e mntent_test: don't assume /proc isn't the first mount.
This test tried to be lazy and test both getmntent() and getmntent_r()
in the same test, but that led to an implicit assumption that /proc
isn't the first mount returned.

This new version is quite a bit more thorough than the old. It does
assume that the mount list doesn't change while the test is running, but
that seems like a reasonable assumption to make during CTS?

Bug: https://issuetracker.google.com/230228681
Test: treehugger
Change-Id: I5c5f0b86ae1c4df9a2ce69d48e1c3accb42c687b
(cherry picked from commit 1e393b0699)
2022-05-16 17:56:24 +00:00
Elliott Hughes
1e393b0699 mntent_test: don't assume /proc isn't the first mount.
This test tried to be lazy and test both getmntent() and getmntent_r()
in the same test, but that led to an implicit assumption that /proc
isn't the first mount returned.

This new version is quite a bit more thorough than the old. It does
assume that the mount list doesn't change while the test is running, but
that seems like a reasonable assumption to make during CTS?

Bug: https://issuetracker.google.com/230228681
Test: treehugger
Change-Id: I5c5f0b86ae1c4df9a2ce69d48e1c3accb42c687b
2022-05-13 16:06:54 -07:00
zijunzhao
c2e412e086 Add copy_file_range(2) syscall stub to bionic.
Test: treehugger
Bug: https://buganizer.corp.google.com/issues/227784687
Change-Id: I543306cd2234189401bf7c9d80d405eeb6e4d41d
2022-05-12 16:53:41 +00:00
Alix Espino
6087a278e0 Merge changes I158862fd,Ieb9de996
* changes:
  Removing clang_cflags to check if they're even necessary
  Moved contents of clang_cflags into cflags
2022-05-10 22:17:26 +00:00
Maciej Żenczykowski
b65e105047 add new Linux close_range() system call to bionic
See:
  https://man7.org/linux/man-pages/man2/close_range.2.html

Note: 'man close_range' documents 'flags' as unsigned int,
while glibc unistd.h as just 'int'.  Picking 'int' to match glibc,
though it probably doesn't matter.

BYPASS_INCLUSIVE_LANGUAGE_REASON=man is a cli command
Test: TreeHugger
Bug: 229913920
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1e2d1c8edc2ea28922d60f3ce3e534a784622cd1
2022-05-06 10:33:04 +00:00
Florian Mayer
bbe7c690f1 Merge "Fix missing null-terminator to exec call." am: 7587e20eaf
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2073947

Change-Id: Id15a4a4e86f6bb05378ec1f775fb07693bd9fbda
Ignore-AOSP-First: this is an automerge
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
(cherry picked from commit 0f46547800)
2022-05-04 21:00:22 +00:00
Alix
9dff7da04c Removing clang_cflags to check if they're even necessary
Test: Treehugger & ran mma
Bug: 226636335

Change-Id: I158862fd23ad7050bde0916f24e12934b95f7646
2022-05-03 22:52:50 +00:00
Alix
d256925af4 Moved contents of clang_cflags into cflags
Test: Treehugger
Bug: 226636335
Change-Id: Ieb9de996a61418c8343885ae339589f0f48342d5
2022-05-03 22:50:24 +00:00
Florian Mayer
e2d50fe622 Properly fix heap_tagging_helper for HWASan.
Test: atest bionic-unit-tests
Change-Id: Ia9fbb436676257810d1c379d5d65dd7ccfcf90ac
2022-05-02 18:35:50 +00:00
Automerger Merge Worker
1627acb5e4 Merge "Merge "Fix unistd.exec_argv0_null for new kernels." into android10-tests-dev am: 16457fd9d0" into android11-tests-dev am: ede618aef2
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2078358

Change-Id: I716eacb116e3a4a29acd1aa10ad96f43c583b56b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-04-27 18:44:30 +00:00
Treehugger Robot
6c64caef7e Merge "Fix unistd.exec_argv0_null for new kernels." into android10-tests-dev am: 16457fd9d0
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2078358

Change-Id: I70cff5fe0a62321c8d71d1e88f616a21b4879cf8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-04-27 18:33:39 +00:00
Elliott Hughes
95577defec Fix unistd.exec_argv0_null for new kernels.
There are other options here (see the code comment for details), but
this is the least effort/least disruptive for now.

Bug: 228898932, 227498625
Test: treehugger
Change-Id: I33be6fbfc022238de2f1846a69af1e712a9d6391
(cherry picked from commit bb1cc5a82c)
2022-04-27 17:23:27 +00:00
Florian Mayer
dedca05e47 Do not use HWASan for heap_tagging_helper.
This tests PROT_MTE semantics, so we should disable HWASan.

Test: atest CtsBionicTestCases on flame_hwasan

Bug: 230048274
Bug: 230047253
Bug: 230456730

Change-Id: Ibc59b959d0b8353915629919c5d466a21dbe1c5a
2022-04-26 22:30:21 +00:00
Florian Mayer
7f6425c8c5 Fix missing null-terminator to exec call.
Change-Id: I4fcb11b7cfc9b744ad3320022c12ae2c93d3c401
2022-04-22 22:06:26 +00:00
Mitch Phillips
3865c8f942 Merge "[GWP-ASan] Provide runtime configuration through an env var + sysprop." 2022-04-21 18:12:43 +00:00
Mitch Phillips
e6997d52de [GWP-ASan] Provide runtime configuration through an env var + sysprop.
This patch introduces GWP-ASan system properties and environment
variables to control the internal sampling rates of GWP-ASan. This can
be used for:

 1. "Torture testing" the system, i.e. running it under an extremely
    high sampling rate under GWP-ASan.
 2. Increasing sampling remotely to allow further crash report
    collection of rare issues.

There are three sets of system properites:
 1. libc.debug.gwp_asan.*.system_default: Default values for native
    executables and system apps.
 2. libc.debug.gwp_asan.*.app_default: Default values for non-system
    apps, and
 3. libc.debug.gwp_asan.*.<basename/app_name>: Default values for an
    individual app or native process.

There are three variables that can be changed:
 1. The allocation sampling rate (default: 2500) - using the environment
    variable GWP_ASAN_SAMPLE_RATE or the libc.debug.gwp_asan.sample_rate.*
    system property.
 2. The process sampling rate (default: 128 for system apps/processes, 1
    for opted-in apps) - using the environment variable
    GWP_ASAN_PROCESS_SAMPLING or the libc.debug.gwp_asan.process_sampling.*
    system property,
 3. The number of slots available (default: 32) - using the environment
    variable GWP_ASAN_MAX_ALLOCS or the libc.debug.gwp_asan.max_allocs.*
    system property.

If not specified, #3 will be calculated as a ratio of the default
|2500 SampleRate : 32 slots|. So, a sample rate of "1250" (i.e. twice as
frequent sampling) will result in a doubling of the max_allocs to "64".

Bug: 219651032
Test: atest bionic-unit-tests
Change-Id: Idb40a2a4d074e01ce3c4e635ad639a91a32d570f
2022-04-20 11:26:00 -07:00
Florian Mayer
4817ca64bb Skip setjmp.bug_152210274 on HWASan.
Bug: 227390656
Change-Id: Ic6dc89d844bab4aba93132b3af7942961d3af644
2022-04-15 23:15:26 +00:00
Florian Mayer
750dcd326e Use SKIP_WITH_HWASAN macro from libbase.
Change-Id: I83681d2191bf4184e52d84d1107d61065927bb24
2022-04-15 16:14:56 -07:00
Christopher Ferris
bbf9cd86ca In android_set_abort_message, check for nullptr.
If a process is failing due to out of memory, some code calls
android_set_abort_message with a nullptr. Specifically, the libc++
library std::terminate can call do this. In this case, put a
null in the abort message.

Test: Call with nullptr and verify the code does not crash.
Test: Modified crasher to set an abort message and set a null abort
Test: message. Ran both, verified the abort message displays in
Test: first case, and doesn't display in the second case.
Change-Id: Ia9250f47e4537853ce93bbb20b35915a78caa502
2022-04-12 13:46:48 -07:00
Elliott Hughes
97ef479dfe Merge "Fix unistd.exec_argv0_null for new kernels." 2022-04-01 21:59:56 +00:00
Elliott Hughes
bb1cc5a82c Fix unistd.exec_argv0_null for new kernels.
There are other options here (see the code comment for details), but
this is the least effort/least disruptive for now.

Bug: http://b/227498625
Test: treehugger
Change-Id: I33be6fbfc022238de2f1846a69af1e712a9d6391
2022-04-01 11:12:36 -07:00
Elliott Hughes
6bdefa6ca2 Merge "C11 removed gets()." 2022-03-31 16:30:43 +00:00
Elliott Hughes
1063039d19 C11 removed gets().
Test: treehugger
Change-Id: I793e29cbd52dd882b72eb58055cbc0dd05eb0f59
2022-03-30 17:25:10 -07:00
Ryan Prichard
8ea6af53e2 Always process TLS relocs using general code path
This is important for enabling the error about unsupported TLS
relocations to local symbols. The fast path tends to skip this error,
because it fails during lookup_symbol(). Add a test for this error.

I didn't see a performance regression in the linker_relocation
benchmark.

Bug: http://b/226978634
Test: m bionic-unit-tests
Change-Id: Ibef9bde2973cf8c2d420ecc9e8fe2c69a5097ce2
2022-03-25 15:51:11 -07:00
Treehugger Robot
8321ff1468 Merge "Suppress -Wformat warning" 2022-03-16 18:55:05 +00:00
Yi Kong
f9b1313968 Suppress -Wformat warning
This is exactly what it is testing for.

Original warning:
  bionic/tests/stdio_test.cpp:370:47: error: '%n' specifier not supported on this platform [-Werror,-Wformat]
    EXPECT_DEATH(snprintf(buf, sizeof(buf), "a %n b", &i), "%n not allowed on Android");
                                               ~^

Test: presubmit
Bug: 219872355
Change-Id: I6e378722b2d681cf64f4cf31ef000bd28203b00d
2022-03-16 08:15:15 +00:00
Evgenii Stepanov
9705aac89a Fix mte tests to allow auto-upgrade.
The kernel MTE mode auto-upgrade feature (see mte_tcf_preferred) allows
silent auto-upgrade of Async MTE mode to Asymm or Sync depending on the
OS settings. Relax the tests to allow either Sync or Async faults when
requesting Async mode, and only Sync faults when requesting Sync.

Also tighten the MTENote test to check that both system allocator and
prctl are off when MTE is disabled.

Bug: 214622342
Test: bionic-unit-tests on fvp with all variations of
    /sys/devices/system/cpu/cpu*/mte_tcf_preferred=(async|asymm|sync)

Change-Id: I77a92789d6b330742d00b08c9f0fecc3a6c8fca6
2022-03-10 16:38:06 -08:00
Pirama Arumuga Nainar
fef519b637 Disable LTO for libBionicStandardTests
Bug: http://b/218788252

IR verifier too strict for ifunc resolver that accept parameters.  This
is only exposed with Thin LTO.  The error is:

  IFunc resolver has incorrect type
  i32 ()* @_Z5hwcapv

Test: mmma GLOBAL_THINLTO=true bionic
Change-Id: Ifed4041ee8557ba1a5eb7a5a82f54b5ca5c79161
2022-02-22 15:01:27 -08:00
Elliott Hughes
34da4b5842 Merge "posix_spawn: always clear O_CLOEXEC for dup'ed fds." 2022-02-18 00:24:12 +00:00
Treehugger Robot
5d3c384fa4 Merge "Explain why we test ifunc variables." 2022-02-17 22:04:08 +00:00
Pirama Arumuga Nainar
afc77a08b4 Merge "Cast ifunc resolver's return type" 2022-02-17 21:26:06 +00:00
Elliott Hughes
82c90724e3 Explain why we test ifunc variables.
Bug: http://b/218788252
Test: treehugger
Change-Id: I51825ab61adeaf6f1242df9a22f89cbd0671db48
2022-02-17 11:55:49 -08:00
Pirama Arumuga Nainar
9be2427895 Cast ifunc resolver's return type
Bug: http://b/218788252

Even though a resolver can return any pointer, LLVM IR verifier now
checks that the resolver returns a pointer to the ifunc's function type.

Test: m GLOBAL_THINLTO=true libtest_ifunc_variable_impl.so
Change-Id: I7d87ffcf50bab1d61b01328907e036c51feb6a0f
2022-02-17 11:36:04 -08:00
Zijun Zhao
99ed14b85b Merge "Add %m and %#x support for async_safe logging" 2022-02-17 17:23:32 +00:00
zijunzhao
75c36fe0c2 Add %m and %#x support for async_safe logging
Bugs: None
Test: None
Change-Id: I889015b89b85e222e26f8aa20e35d46a86a0cb7c
2022-02-17 07:23:58 +00:00
Elliott Hughes
62d49fd8e1 posix_spawn: always clear O_CLOEXEC for dup'ed fds.
dup2(2) is a no-op if the new and old fds are equal, but it's pretty
clear that any useful caller in the posix_spawn(3) context wants us to
clear O_CLOEXEC even if we don't actually "move" the fd.

Bug: https://www.austingroupbugs.net/view.php?id=411
Test: treehugger
Change-Id: I5ce1a1f9216df5afd295cc9e35b84527873e9541
2022-02-16 14:39:07 -08:00