Commit graph

3419 commits

Author SHA1 Message Date
Elliott Hughes
b2f2fc8184 Remove unreliable CFI test.
Remove tests of implementation details rather than the CFI
functionality itself. In particular, CFI is designed to protect against
invalid calls to executable code, whereas heap memory is covered by page
protection.

Bug: http://b/298741930
Test: treehugger
Change-Id: Ib7f8af283b4c0001da8fa80a1b281bdc4c50af51
2023-10-06 16:58:12 -07:00
Treehugger Robot
51be22c28d Merge "Consistently use #if defined(__BIONIC__)." into main 2023-09-28 20:17:02 +00:00
Elliott Hughes
fc1b3b8b7e Merge "Use strerrorname_np() in ASSERT_ERRNO()." into main 2023-09-28 20:03:47 +00:00
Elliott Hughes
e7943f8b95 Consistently use #if defined(__BIONIC__).
Test: treehugger
Change-Id: I844b909404532eb9165cba1ed6f237bdd4a46990
2023-09-28 10:47:51 -07:00
Elliott Hughes
11069030d6 Remove an obsolete TODO now we have a new clang.
Test: treehugger
Change-Id: I19751fe73f4cd3400005d0ccad0bccb0a74f6fc8
2023-09-28 08:22:26 -07:00
Elliott Hughes
d2250edc10 Use strerrorname_np() in ASSERT_ERRNO().
Hopefully this is totally unambiguous and non-confusing output:
```
Expected equality of these values:
  Errno(22)
    Which is: EINVAL
  Errno((*__errno()))
    Which is: ENOSYS
```

Test: treehugger
Change-Id: Iefe6a8a6447e76681c18256d2713e2c527081c75
2023-09-28 08:15:36 -07:00
Elliott Hughes
a67fe1b171 Merge "Add strerrordesc_np() and strerrorname_np()." into main 2023-09-27 22:26:37 +00:00
Elliott Hughes
2109f12c3b Add strerrordesc_np() and strerrorname_np().
strerrordesc_np() isn't very useful (being just another name for
strerror()), but strerrorname_np() lets you get "ENOSYS" for ENOSYS,
which will make some of our test assertion messages clearer when we
switch over from strerror().

This also adds `%#m` formatting to all the relevant functions.

Test: treehugger
Change-Id: Icfe07a39a307d591c3f4f2a09d008dc021643062
2023-09-27 11:21:12 -07:00
Elliott Hughes
4ae4be9263 Clean up how we skip tests when a syscall isn't in the kernel.
The close_range() test in particular has been confusing a lot of
partners. I think the sys_epoll_test.cpp idiom is the clearest of the
ones in use, so let's use that everywhere. (I haven't actually touched
the SysV IPC tests, because if we do touch them, _deleting_ them --
since all those syscalls are not allowed on Android -- is probably the
change to be made!)

I'm on the fence about factoring this idiom out into a macro. There
should never be too many of these, and we should probably be removing
them? Is anyone still running the current bionic tests on 4.3 kernels
without membarrier(2), and if they are --- why?!

For now though, I haven't removed any of our existing tests; I've just
moved them over to the sys_epoll_test.cpp style.

Test: treehugger
Change-Id: Ie69a0bb8f416c79957188e187610ff8a3c4d1e8f
2023-09-22 17:15:25 -07:00
Elliott Hughes
95646e6666 Add ASSERT_ERRNO and EXPECT_ERRNO (and use them).
We've talked about this many times in the past, but partners struggle to
understand "expected 38, got 22" in these contexts, and I always have to
go and check the header files just to be sure I'm sure.

I actually think the glibc geterrorname_np() function (which would
return "ENOSYS" rather than "Function not implemented") would be more
helpful, but I'll have to go and implement that first, and then come
back.

Being forced to go through all our errno assertions did also make me
want to use a more consistent style for our ENOSYS assertions in
particular --- there's a particularly readable idiom, and I'll also come
back and move more of those checks to the most readable idiom.

I've added a few missing `errno = 0`s before tests, and removed a few
stray `errno = 0`s from tests that don't actually make assertions about
errno, since I had to look at every single reference to errno anyway.

Test: treehugger
Change-Id: Iba7c56f2adc30288c3e00ade106635e515e88179
2023-09-21 14:15:59 -07:00
Treehugger Robot
d72f4f8770 Merge "Consistent qualifier ordering." into main 2023-09-15 17:19:08 +00:00
Florian Mayer
6b4e6e470e Merge "Remove ASan test" into main 2023-09-14 19:19:01 +00:00
Elliott Hughes
30088848fc Consistent qualifier ordering.
Change our handful of `constexpr static`s to the much more common
`static constexpr`. It's easier to "follow existing style" when there
aren't two existing styles to copy from, and all else being equal,
"majority wins" :-)

Test: treehugger
Change-Id: Ifbf0f62ab84c9450bf9c2e49e96915c126fd20c4
2023-09-14 18:36:55 +00:00
Florian Mayer
12e38c23f1 Remove ASan test
ASan for device side is deprecated.
Bug: 300289881

Change-Id: I492ccbbeae43c84b53e92b062048c56ea974308e
2023-09-13 12:29:32 -07:00
Christopher Ferris
1de7a480bc Disable warning which is not detecting problems.
A clang update enabled -Wreorder-init-list by default. Since it doesn't
provide any benefit to the bionic code, disable the warning.

Test: Builds without warnings.
Change-Id: I5891527ef532b59dc2a02b39a5896112411d21f5
2023-09-12 13:03:02 -07:00
Colin Cross
90eef4250e Merge "Skip sysconf_cache for musl" into main 2023-09-06 17:14:57 +00:00
Elliott Hughes
906d7d41e4 Merge "Add epoll_pwait2()." into main 2023-09-05 21:48:08 +00:00
Colin Cross
cb5d3c1c33 Skip sysconf_cache for musl
Musl doesn't have the _SC_LEVEL?_?CACHE_SIZE sysconf macros.

Bug: 257334542
Test: m USE_HOST_MUSL=true host-native
Change-Id: I42e65daa9169e129059ddde5eee487ea51e6f143
2023-09-05 13:53:11 -07:00
Elliott Hughes
fce8a155df __riscv_hwprobe: don't try to set errno.
When used in an ifunc resolver, errno@plt won't be available. This is
the API the rivos folks contributing to glibc are leaning towards, for
the same reason. Hit by the berberis folks because they don't implement
the syscall so they were trying to set errno to ENOSYS.

Tested by looking at the generated assembler, and also disabling the
vdso (since on actual systems, this will go via the vdso).

Test: treehugger
Change-Id: Ie2779110f141f20efe97cb892fbdefd808b5339b
2023-08-29 15:41:36 -07:00
Elliott Hughes
647472db9b <termios.h>: add two new POSIX functions.
musl already added tcgetwinsize() and tcsetwinsize(), but I didn't
notice.

Trivial single-line inlines added to a header that's already written
that way.

Test: treehugger
Change-Id: Iac95ea6a89f3872025c512f7e61987b81d0aafa7
2023-08-29 09:33:04 -07:00
Elliott Hughes
a71a15fe34 Merge "sysconf(): implement cache queries." into main 2023-08-28 14:48:20 +00:00
Elliott Hughes
02df7388f1 sysconf(): implement cache queries.
This is a bit disappointing. I'd not implemented this in the past
because it wasn't available on all platforms, and -- although the
riscv64 implementation was just a cool optimization -- I thought that
the /sys stuff was actually portable, until I ran it on arm64 hardware.
So here we have getauxval() for riscv64, /sys for x86-64, and our best
guess based on ctr_el0 for arm64.

Bug: http://b/294034962
Test: ran tests on the host, an arm64 device, and riscv64 host and qemu
Change-Id: I420b69b976d30668d4d2ac548c4229e2a4eafb20
2023-08-28 14:48:12 +00:00
Elliott Hughes
bf4d3a95c1 Merge "Add %b/%B to async-safe logging." into main 2023-08-24 14:34:45 +00:00
Elliott Hughes
4c62e59fe6 Add epoll_pwait2().
I've also added doc comments for everything in <sys/epoll.h>.

I've also broken up the old "smoke" test (which was taking 2s on my
riscv64 qemu) to keep the total runtime for all the tests down to 200ms.

Test: treehugger
Change-Id: Icd939af51886fdf21432653a07373c1a0f26e422
2023-08-23 15:59:12 -07:00
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