Commit graph

2383 commits

Author SHA1 Message Date
Prashanth Swaminathan
7b873fb033 Merge "string/memory functions: avoid qemu bugs/performance issues." into main am: c20bf013a1 am: 453fbd0e9a am: 7c32826486
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2806377

Change-Id: I110797573c0c309313815c0e2144c786d1b0fd13
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-11-17 19:18:42 +00:00
Elliott Hughes
e7b35c0dc4 Merge "libc_init_static.cpp: drop gold support." into main am: 63dce74ca0 am: b620ed5206 am: 7e7d42a8ce
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2836070

Change-Id: Ie8642466c77ed05b82e9d0dfc56b5cfb9f9d129e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-11-17 18:26:20 +00:00
Prashanth Swaminathan
c20bf013a1 Merge "string/memory functions: avoid qemu bugs/performance issues." into main 2023-11-17 17:47:20 +00:00
Elliott Hughes
d65368e7d7 libc_init_static.cpp: drop gold support.
The NDK no longer includes gold, so static binaries built by the NDK no
longer need to support gold.

Test: bionic static unit tests
Change-Id: Idddcb9eb18921acfc1ae2a3c755592a5ab30290a
2023-11-16 17:31:09 -08:00
Elliott Hughes
aefe999d92 string/memory functions: avoid qemu bugs/performance issues.
Use V on real hardware, but GC on qemu.

Change-Id: I419546d94555540e14a14dcc52bd99413cbbcfa1
2023-11-15 15:49:57 -08:00
Christopher Ferris
abe2b20309 Merge "Stop fp unwinding if the pc is 0." into main am: 0b27d314d6 am: 94df76e5ed am: e013c439b8
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2813433

Change-Id: Iaef76f9c61b7a645343ed407747ca2edef72565c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-11-01 21:32:30 +00:00
Christopher Ferris
0b27d314d6 Merge "Stop fp unwinding if the pc is 0." into main 2023-11-01 19:50:33 +00:00
Christopher Ferris
cfcb7b6c83 Stop fp unwinding if the pc is 0.
The android_unsafe_frame_pointer_chase keeps going even when a
frame is 0. Modify the unwind to stop when this case is found.

I found this while running the GwpAsanCrasherTest.run_gwp_asan_test
from debuggerd_test and printing the tombstone created. The
deallocated by and allocated by stack traces always ended in 0 frame.

After fixing this, the last 0 frame is no longer present.

Test: Ran the debuggerd test and printed the tombstone on a raven
Test: verifying that the last frame is non-zero.
Test: Ran the bionic unit tests.
Change-Id: I8d64679277abcf5f237e6759051db11ffaa34c2f
2023-10-31 14:14:28 -07:00
Treehugger Robot
d78dfdb75a Merge changes from topic "appcompat_override" into main am: 0207a6a186 am: 9460fe5a83 am: 3fd59cb6af
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2796861

Change-Id: I1c6d5b67876e69650e721e465533ee897983efc4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-10-31 03:56:37 +00:00
Christopher Ferris
44dfd3ebab Merge "Add android_mallopt M_GET_DECAY_TIME_ENABLED." into main am: 35aaed9e1b am: be90376e0c am: 41f64cc03d
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2810911

Change-Id: Ib46ad5bb6ed2dbd74462544ffe940f348bf24586
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-10-31 03:56:04 +00:00
Treehugger Robot
0207a6a186 Merge changes from topic "appcompat_override" into main
* changes:
  Move __system_properties_reload to LIBC from LIBC_PLATFORM
  Write appcompat_override system properties
2023-10-31 02:29:57 +00:00
Christopher Ferris
b4e560ed7c Add android_mallopt M_GET_DECAY_TIME_ENABLED.
The bionic benchmarks set the decay time in various ways, but
don't necessarily restore it properly. Add a new method for
getting the current decay time and then a way to restore it.

Right now the assumption is that the decay time defaults to zero,
but in the near future that assumption might be incorrect. Therefore
using this method will future proof the code.

Bug: 302212507

Test: Unit tests pass for both static and dynamic executables.
Test: Ran bionic benchmarks that were modified.
Change-Id: Ia77ff9ffee3081c5c1c02cb4309880f33b284e82
2023-10-30 15:30:16 -07:00
Nate Myren
0ab0615f8c Move __system_properties_reload to LIBC from LIBC_PLATFORM
The zygote cannot have visiblity to LIBC_PLATFORM methods. Therefore,
move __system_properties_reload to LIBC, and rename it
__system_properties_zygote_reload, and indicate in comments that it
should not be used by non-zygote apps

Bug: 291814949
Test: atest CtsBionicRootTestCases
Change-Id: Iee8fa0c76b740543c05a433393f2f4bef36d6d3d
2023-10-25 17:41:33 -07:00
Nate Myren
b8c87b14b0 Write appcompat_override system properties
Create a second set of system properties, that can be overlaid over the
real ones if necessary, for appcompat purposes.

Bug: 291814949
Ignore-AOSP-First: Aosp -> internal merge conflict
Test: manual, treehugger, system_properties_test

Change-Id: I541d3658cab7753c16970957c6ab4fc8bd68d8f3
Merged-In: I884a78b67679c1f0b90a6c0159b17ab007f8cc60
2023-10-19 13:35:57 -07:00
Nate Myren
19d8167626 Merge "Write appcompat_override system properties" into main 2023-10-19 19:29:59 +00:00
Nate Myren
ae7f33dd57 Write appcompat_override system properties
Create a second set of system properties, that can be overlaid over the
real ones if necessary, for appcompat purposes.

Bug: 291814949
Ignore-AOSP-First: Aosp -> internal merge conflict
Test: manual, treehugger, system_properties_test

Change-Id: I884a78b67679c1f0b90a6c0159b17ab007f8cc60
2023-10-18 17:28:42 -07:00
Mitch Phillips
25ab1c2abf Merge "Use DYNAMIC entries for MTE enablement" into main am: 363e743200 am: 3b3a96de07 am: 059d2db070
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2765590

Change-Id: I307efae2207df52c9dffdfb920fa9df075d5c695
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-10-18 12:31:48 +00:00
Mitch Phillips
363e743200 Merge "Use DYNAMIC entries for MTE enablement" into main 2023-10-18 10:17:37 +00:00
Mitch Phillips
7c1f3770af Use DYNAMIC entries for MTE enablement
Adds support for the dynamic entries to specify MTE enablement. This is
now the preferred way for dynamically linked executables to specify to
the loader what mode MTE should be in, and whether stack MTE should be
enabled. In future, this is also needed for MTE globals support.

Leave the existing ELF note parsing as a backup option because dynamic
entries are not supported for fully static executables, and there's
still a bunch of glue sitting around in the build system and tests that
explicitly include the note. When -fsanitize=memtag* is specified, lld
will create the note implicitly (along with the new dynamic entries),
but at some point once we've cleaned up all the old references to the
note, we can remove the notegen from lld.

Bug: N/A
Test: atest bionic-unit-tests CtsBionicTestCases --test-filter=*Memtag*
Test: Build/boot the device under _fullmte.

Change-Id: I954b7e78afa5ff4274a3948b968cfad8eba94d88
2023-10-17 13:49:24 +02:00
Elliott Hughes
32c281cbb8 Merge "Clarify the fcntl() "that's not how F_SETFD works" error." into main am: b4e2219987 am: dfb9662b24 am: 4f1282b9bf am: 98c1a703b7 am: a4427fa9ab
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2780900

Change-Id: I7bc9c9f3e374731e0fdcf7b0815e09ff011a67b5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-10-12 20:35:45 +00:00
Elliott Hughes
25af17c587 Clarify the fcntl() "that's not how F_SETFD works" error.
The first app developer (we know of) that hit this didn't understand
what it was trying to tell them.

Before:
    FORTIFY: fcntl(F_SETFD) passed non-FD_CLOEXEC flag: 0x801

After:
    FORTIFY: fcntl(F_SETFD) only supports FD_CLOEXEC but was passed 0x801

Bug: https://issuetracker.google.com/304348746
Test: treehugger
Change-Id: I8522e851d8f74c91152ebae68b083b5272d49255
2023-10-12 16:04:14 +00:00
Elliott Hughes
f1ce4648a9 Merge "Remove <ctype.h> cruft." into main am: 389a40a0a8 am: a468e56569 am: bc717f9b8d am: 4ca2aabbff am: ac7ef66045
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2455758

Change-Id: If05fcc6343f23138f026fe0759948ca3f6fae967
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-10-07 00:59:27 +00:00
Elliott Hughes
389a40a0a8 Merge "Remove <ctype.h> cruft." into main 2023-10-06 19:49:26 +00:00
Elliott Hughes
e37068889d Remove <ctype.h> cruft.
The NDK only supports API 21 and later, so we don't need to worry
about older API levels any more.

All the functions in this file are trivial, being but a single
instruction on most architectures. For that reason, we inline them by
default. (We continue to also provide actual symbols for any caller
that needs them --- in particular existing binaries!)

Also inline all the _l() variants too. No-one should be using them,
but since we're already using trickery to only implement the non-_l()
variants once, we may as well use the same trick for both.

Test: treehugger
Change-Id: I17637c49dd14be9e5ecb8246e72e8acc662739f1
2023-10-06 15:06:17 +00:00
Elliott Hughes
7add1bbca8 Merge "Add strerrordesc_np() and strerrorname_np()." into main am: a67fe1b171 am: d37c19670a am: 5f921a71e1 am: 546379ea3d am: a2224bbe45
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2760166

Change-Id: Iae04cc2f17e272e0212b92dbeb5d776aeeb8cc62
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-28 04:05:28 +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
7eac72c3cc Merge "Add epoll_pwait2()." into main am: 906d7d41e4 am: 484056aaf2 am: 96a6c6abc1 am: a607f6744f am: cbaea16804
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2656904

Change-Id: I8915b268e7ec3c1abe1ff11d8090ca8f84316b97
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-06 01:48:32 +00:00
Elliott Hughes
906d7d41e4 Merge "Add epoll_pwait2()." into main 2023-09-05 21:48:08 +00:00
Yabin Cui
ac668cc137 Merge "Let executables not rely on sentinels in preinit_array/init_array/fini_array" into main am: 4d3903eab9 am: 7ea5e44c24 am: 0774e1ef51 am: 745305bb5c am: afefe1c2c2
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2725997

Change-Id: I423ecb4bf9822058ceb7f2ae215c3b3f693ee7a2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-01 21:32:03 +00:00
Yabin Cui
0774e1ef51 Merge "Let executables not rely on sentinels in preinit_array/init_array/fini_array" into main am: 4d3903eab9 am: 7ea5e44c24
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2725997

Change-Id: Idcfe610a1a10dafdc5b999834dfa2ec4e72785e6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-01 19:01:34 +00:00
Yabin Cui
7ea5e44c24 Merge "Let executables not rely on sentinels in preinit_array/init_array/fini_array" into main am: 4d3903eab9
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2725997

Change-Id: Ia86ca98c161ebdc6d631ccbdd1ea416298879858
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-01 18:08:55 +00:00
Yabin Cui
744cfd3720 Let executables not rely on sentinels in preinit_array/init_array/fini_array
Currently, we use sentinels (starting with -1 and ending with 0) in
preinit_array/init_array/fini_array in executables. But after using LTO,
the sentinels can be reordered by LLD and no longer work. So make below
changes to not rely on them:
  1. In crtbegin.c, use symbols (like __init_array_start) inserted by the
     linker.
  2. Add array_count fields in structors_array_t.
  3. In static libc, use array_count fields to decide array lengths.
  4. To make new dynamic executables work with old libc.so, create a fake
     fini_array with sentinels, and pass it to __libc_init. The fake
     fini_array contains a function to call functions in real fini_array.
  5. To make old dynamic executables work with new libc.so, libc.so
     still uses sentinels to decide the length of fini_array.

Bug: 295944813
Bug: https://github.com/android/ndk/issues/1461
Test: run bionic-unit-tests-static
Test: test static executables manually
Test: boot cf_gwear_x86-trunk_staging-userdebug
Change-Id: I1ce31f07bcfe0e99b4237984898a8fc9e98ff426
2023-09-01 10:17:05 -07:00
Elliott Hughes
4c238d8dea Merge "__riscv_hwprobe: don't try to set errno." into main am: 4de14c7499 am: e62a9e0329 am: d086dd0ef4 am: e888177487 am: 95c3c58d2e
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2731044

Change-Id: Ia88d2ff7a36534c56969ba62a48518c164c35dea
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-30 20:15:29 +00:00
Elliott Hughes
d086dd0ef4 Merge "__riscv_hwprobe: don't try to set errno." into main am: 4de14c7499 am: e62a9e0329
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2731044

Change-Id: Ie20354036f9bd578b23344a5e6388ee68bfcb274
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-30 16:51:25 +00:00
Elliott Hughes
e62a9e0329 Merge "__riscv_hwprobe: don't try to set errno." into main am: 4de14c7499
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2731044

Change-Id: I9a73661a7e500e689285e62f57773b727d94ce5b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-30 16:02:53 +00:00
Elliott Hughes
92424f76cb Merge "<termios.h>: add two new POSIX functions." into main am: b130e6dae0 am: f9189bb67d am: 0e87776adc am: 42fd8dbd98 am: 678e06ac31
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2729340

Change-Id: I4289276cf2977a006d1a771e8bec2a74a7902912
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-30 01:39:55 +00:00
Elliott Hughes
0e87776adc Merge "<termios.h>: add two new POSIX functions." into main am: b130e6dae0 am: f9189bb67d
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2729340

Change-Id: I42a8041d25c29bd58ffdd91e29a3feef8ec85be4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-29 23:16:11 +00: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
f9189bb67d Merge "<termios.h>: add two new POSIX functions." into main am: b130e6dae0
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2729340

Change-Id: I8640dfffbc43c7a5c0a5b1dcd42d8b031b25eb4b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-29 22:25:52 +00: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
Xin Li
5439bde949 Merge "Merge Android U (ab/10368041)" into aosp-main-future 2023-08-28 22:13:38 +00:00
Elliott Hughes
7dae3812d7 Merge "sysconf(): implement cache queries." into main am: a71a15fe34 am: 3996bbe901 am: a9ca959498 am: 3e268603ec am: 6a12624063
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2721536

Change-Id: I115e6e6175972cf111078edad7ed67ed8de76df3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-28 17:54:43 +00: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
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
Xin Li
661155efcb Merge Android U (ab/10368041)
Bug: 291102124
Merged-In: I89679e7152f197f9d0961eee352189bc7d1d1c50
Change-Id: I02dd1d48d478b0e0d702f1653271437e2cf7cef7
2023-08-23 14:43:14 -07:00
Kalesh Singh
ac516c4239 Merge "bionic: libc_init_static: Use page_size()" into main am: 8cd1ddcbf0 am: 5c7512474e am: 9ac016c5df am: 542dc8ea3f am: f4fa351c9c
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2719578

Change-Id: I33f2ad296febef576d344601004c4d99ba249caa
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-23 03:27:00 +00:00
Kalesh Singh
8cd1ddcbf0 Merge "bionic: libc_init_static: Use page_size()" into main 2023-08-23 00:16:26 +00:00
Juan Yescas
9e24def386 Merge "bionic: Use max_page_size() instead of PAGE_SIZE" into main am: ac587f827c am: c48775c9fa am: 94f8520923 am: 83395bc0c3 am: 31a450554d
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2719394

Change-Id: I41be7b98903fd23e2ae3c9f5763c4cbf2e95b90e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-22 18:09:37 +00:00
Elliott Hughes
8c4e1adab2 Merge "riscv64: fix ifuncs, improve the ifunc tests." into main am: d53ad05e38 am: c512636d31 am: 96591865e3 am: b889ba04ca am: 28765348af
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2695693

Change-Id: I4010768df4e17016fa731f8ba7451f752464177f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-22 18:08:30 +00:00
Juan Yescas
ac587f827c Merge "bionic: Use max_page_size() instead of PAGE_SIZE" into main 2023-08-22 15:22:44 +00:00
Juan Yescas
3649db34a1 bionic: Use max_page_size() instead of PAGE_SIZE
Android V will support page size agnostic targets. The bionic macro
PAGE_SIZE won't be defined for the agnostic targets.

The PAGE_SIZE macro will be replaced by max_page_size() instead.

- For not agnostic builds, max_page_size() will be replaced by 4096.
- For agnostic builds, it will  be replaced by 16384

Bug: 296907948
Test: source build/envsetup.sh
      lunch aosp_cf_arm64_phone_pgagnostic
      m

      source build/envsetup.sh
      aosp_cf_x86_64_phone-userdebug
      m

Change-Id: I81731a2ec59decd19ab9fd714d4f2ac20df873b7
2023-08-22 05:34:55 +00:00
Kalesh Singh
183f58bb2a bionic: libc_init_static: Use page_size()
Use the real page size from getauxval() for memtag stack
MTE protection.

Bug: 296275298
Test: atest -c bionic-unit-tests
Change-Id: I1711291b918b09e5464f1d15358dd1ff7fa2f371
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
2023-08-21 16:55:41 -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
Elliott Hughes
99fe0dfbe0 Merge "Point to the riscv64 psABI frame pointer documentation." into main am: c983dbf0b2 am: 948133436e am: a52ed9c983 am: 9ae386ef4d am: 6be58129c0
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2707397

Change-Id: If0a85a2463ad72eeed780d49fc73eb9eec658429
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-16 19:13:34 +00:00
Elliott Hughes
f9571ec851 Point to the riscv64 psABI frame pointer documentation.
Test: N/A
Change-Id: I6639ecfe75a4f0e3caaf7347676997e0e214f6c8
2023-08-14 19:19:39 +00:00
Dan Albert
1adec823d5 Merge changes I1a60d6ef,Idabf0107 into main am: 1982dce568 am: d5ef5029fe am: 0378513f6d am: cdd4a25109 am: a287663d1c
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2670156

Change-Id: I9e3dfb1928d414dd66db5fe1b2309a83f5147a71
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-07 21:47:46 +00: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
282a23364d Merge "Increase time to set allocation limit." into main am: 636b9b9bf2 am: 8e060cc24f am: 8223f8601d am: 7e16f5b009 am: 92de0990f5
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2694747

Change-Id: I3d5a9788b696cfa1fec8ba99ccddb48f667cd5ef
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-05 02:00:44 +00:00
Treehugger Robot
0293cd474c Merge changes Ia6b8cff4,I390ea200 into main am: 007bb4d1e8 am: 8003988d69 am: e1be10f328 am: 0d863ca056 am: 9f60001427
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2670165

Change-Id: I79c687319663c740feed983847eefaf4c2824698
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-05 01:59:51 +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
a9e914dd2f Make multibyte result constants public.
The magic numbers that C defines are obnoxious. We had partial
definitions for these internally. Add the missing one and move them to
a public header for anyone else that may want to use them.

Bug: None
Test: None
Change-Id: Ia6b8cff4310bcccb23078c52216528db668ac966
2023-08-04 19:48:35 +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
Elliott Hughes
7cf203ac7b Merge "riscv64: use vdso for __riscv_hwprobe()." into main am: 2df6e5fa8f am: c02a094d8a am: 43f24adf4b am: 975c506d5b am: a5ca582ccb
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2681597

Change-Id: I2b8d0f374171dab25f6296447e0729c458663ac3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-01 17:38:20 +00:00
Elliott Hughes
87d276faa3 Merge "riscv64: pass a null argument to ifunc resolvers." into main am: 95936aec6f am: cf530e5d7e am: 7eba97778c am: 57712d3921 am: a385bfdc55
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2684726

Change-Id: Id3683fdb2d9b348b10596f94c2d71c1f6181d261
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-08-01 17:38:03 +00:00
Elliott Hughes
2df6e5fa8f Merge "riscv64: use vdso for __riscv_hwprobe()." into main 2023-08-01 14:32:52 +00:00
Elliott Hughes
b08f79af78 riscv64: pass a null argument to ifunc resolvers.
glibc maintainer Florian Weimer pointed out that glibc passes a null first
argument to riscv64 ifunc resolvers. While not super useful right now,
that does make it much easier to switch to providing arguments in future,
such as my favorite idea of passing a default set of hwprobe key/value
pairs, along with a count of how many pairs.

Test: treehugger
Change-Id: Ibe2148dc28aa6ad230e6324b6d725fe472b7ef33
2023-07-31 19:34:38 +00:00
Elliott Hughes
9a7d048712 riscv64: use vdso for __riscv_hwprobe().
Also de-pessimize time(), where the vdso entrypoint only exists on
x86/x86-64 anyway.

Bug: https://github.com/google/android-riscv64/issues/8
Test: strace
Change-Id: I14cb2a3130b6ff88d06d43ea13d3a825a26de290
2023-07-31 12:24:31 -07:00
Elliott Hughes
2d1a9a9073 Merge "De-pessimize SigSetConverter usage." into main am: ab9028c8ba am: 75e41cca99 am: e345b3f4a2 am: 72678232a0 am: aa2c50d8ee
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2660920

Change-Id: Ibac8e4c8d183e0a66e1e0ef195ea804251db7853
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-20 19:57:39 +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
Paul Lawrence
71ade013f4 Listen on property_service_for_system socket for powerctl messages
It is easy to dos the property_service socket, since it will wait for a
complete data packet from one command before moving on to the next one.

To prevent low privilege apps interfering with system and root apps,
add a second property_service socket that only they can use.

However, since writes to properties are not thread-safe, limit use of
this second socket to just sys.powerctl messages. These are the messages
that this security issue is concerned about, and they do not actually
write to the properties, rather they are acted upon immediately.

Bug: 262208935
Test: Builds, boots
Ignore-AOSP-First: Security fix
Change-Id: I1e96444115de4cc0b021c6864922845de331f6a7
2023-07-18 08:51:19 -07:00
Paul Lawrence
05328b4160 Revert "Use proprety_socket_for_system if permissions allow" am: 78973da8ef am: 5210d35c91
Original change: https://googleplex-android-review.googlesource.com/c/platform/bionic/+/24028889

Change-Id: I26225b9eb5a8e6875577eddb18f3bf9e83456f90
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-17 17:37:46 +00:00
Paul Lawrence
425d8361ca Revert "Fix deadlock caused by two-threaded property controls" am: d1076eb728 am: 981e477fa8
Original change: https://googleplex-android-review.googlesource.com/c/platform/bionic/+/24028888

Change-Id: I86a696f956e6fea4787924ce731287bfbc4dfc27
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-17 17:37:43 +00:00
Elliott Hughes
8eae8d506c Merge "Consistently use %m rather than strerror() in logging." into main am: a4b7949aca am: f681964728 am: 12fd33dfe4 am: ea65516304 am: 42071860a1 am: d591bee9e1
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2655789

Change-Id: I65b74a72874bddd3c924097d9ba0fc34a140f2cd
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-13 22:50:59 +00:00
Elliott Hughes
ea65516304 Merge "Consistently use %m rather than strerror() in logging." into main am: a4b7949aca am: f681964728 am: 12fd33dfe4
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2655789

Change-Id: If5cdf60df4cf663efcca8c246fa81fee778a085c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-13 16:07:25 +00:00
Elliott Hughes
2557f73c05 Consistently use %m rather than strerror() in logging.
When I added %m to async_safe_* too, we never followed up and cleaned up
callers.

Test: treehugger
Change-Id: If81943c4c45de49f0fb4bc29cfbd3fc53d4a47fe
2023-07-12 21:16:31 +00:00
Kelvin Zhang
f48bd84efc Merge "Check for mprotect result" into main am: 0b2996f144 am: fd88338ed7 am: bb9ceed708 am: 4917ef4f28 am: 9bfc89f9c3 am: d527e08d47
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2654229

Change-Id: I3dd97860caad449924adb5f4794de63dc9ea694e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-12 06:00:56 +00:00
Kelvin Zhang
4917ef4f28 Merge "Check for mprotect result" into main am: 0b2996f144 am: fd88338ed7 am: bb9ceed708
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2654229

Change-Id: Ib82d7a96364fc94e394175785db37ac6132b2ff5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-12 03:41:53 +00:00
Kelvin Zhang
fd93b6031e Check for mprotect result
Failure to mark shadow stack page as writable will result in a SEGV
fault later when a function tries to save return addresses to shadow
stack. The engineer looking at the crash report would be very confused
because the program crashes at very beginning of an innocent looking
function. For ease of debugging, check for shadow stack errors early.

Test: th
Bug: 279808236
Bug: 253652966
Change-Id: Id2da68fa984b5dfb1846ed14aa7ededee7f2508f
2023-07-11 15:42:32 -07:00
Paul Lawrence
78973da8ef Revert "Use proprety_socket_for_system if permissions allow"
This reverts commit 24839a681e.

These fixes for b/262208935 introduced a race condition. We believe the
race is fixed by ag/23879563, but at this point in the release feel that
reverting the fixes and refixing in main is the better solution

Test: Builds, boots
Bug: 283202477
Bug: 288991737
Ignore-AOSP-First: Reverting CL only in internal
Change-Id: If0736e504928641c85934eae4d298f14e711116c
2023-07-11 14:02:53 -07:00
Paul Lawrence
d1076eb728 Revert "Fix deadlock caused by two-threaded property controls"
This reverts commit aeddfc4aaf.

These fixes for b/262208935 introduced a race condition. We believe the
race is fixed by ag/23879563, but at this point in the release feel that
reverting the fixes and refixing in main is the better solution

Test: Builds, boots
Bug: 283202477
Bug: 288991737
Ignore-AOSP-First: Reverting CL only in internal
Change-Id: If7e9e5f99728c2f3a18b08346b4cf3449132f920
2023-07-11 14:01:57 -07:00
Steven Moreland
4b3d3fa472 Merge "Revert^2 "fdsan android::Parcel"" 2023-06-30 17:02:54 +00:00
Florian Mayer
28f93db5a7 Merge "[HWASan] add comment to explain why we can use __has_feature" am: 26e0e00279 am: f04c163217 am: 8d60940a21
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2636328

Change-Id: Iaf1938cc09d60b775134d703b7d9324fcd8aa07f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-23 03:50:10 +00:00
Florian Mayer
26e0e00279 Merge "[HWASan] add comment to explain why we can use __has_feature" 2023-06-23 01:16:22 +00:00
Steven Moreland
1d413fce69 Revert^2 "fdsan android::Parcel"
7836677d99

Change-Id: If972bf911fd61286780a7c9800239b83ecddccab
2023-06-22 23:03:57 +00:00
Florian Mayer
02108ce6b1 [HWASan] add comment to explain why we can use __has_feature
Bug: 276930343
Change-Id: I0b3e152269a147f67cae3c534be92ee169fe393b
2023-06-22 14:56:18 -07:00
Priyanka Advani
7836677d99 Revert "fdsan android::Parcel"
Revert submission 23699976-fdsan-parcel

Reason for revert: Possible culprit for b/288448299

Reverted changes: /q/submissionid:23699976-fdsan-parcel

Change-Id: I709d2629755b7d014763a7bbd03a65d9f6e7efa7
2023-06-22 21:22:35 +00:00
Christopher Ferris
0ceeea5a49 Merge "Add new mallopt M_LOG_STATS." am: 90e2827762 am: 29bedad140 am: 1e364e01b8
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2585453

Change-Id: Ia79a45c3a23c008e0c22cfb7e2c5e4ee000aa6f4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-20 22:42:53 +00: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
bc93a2acf2 Merge "Expose tzalloc()/localtime_rz()/mktime_z()/tzfree()." am: f5cd29269f am: 472f1d099e am: ecb17c8cf4
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2626240

Change-Id: I1cebfa0141dc9ed977927f88ba5813f18427deda
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-16 17:40:04 +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
Dimitry Ivanov
29fd8c0fbc Merge "Use more appropriate param type for __early_abort" am: 81d1e3df44 am: 344ab813b3 am: f11be221ad
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2627970

Change-Id: I35788ec65d04d2a3de62ffb8b2955ce8c571852a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-16 11:59:58 +00:00
dimitry
e07704aa6e Use more appropriate param type for __early_abort
Test: build, start emulator
Change-Id: I5f31ceb9a85ee7750f17edff76782c778a4515d8
2023-06-15 14:40:42 +00:00
Steven Moreland
94e2325940 fdsan android::Parcel
Parcel manages ownership of FDs from the binder kernel
in a complicated way. Since sizeof(Parcel) is frozen
in the ABI right now, and we can't allocate more things
on the heap in Parcel, we need to keep on managing
FD ownership manually there.

Ignore-AOSP-First: this requires some fixes only in
  git_master to avoid crashing

Bug: 287093457
Test: boot
Change-Id: I4976507727899f1bb09de41e97f329bee58a4572
2023-06-14 23:36:24 +00:00
Elliott Hughes
4250ecf354 Merge "Remove PAGE_SIZE call sites." am: 826ea44822 am: 891e3b0aa8 am: efbf89a550
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2083840

Change-Id: If14df13789935e08a8dd8f50fb91bf4699d17cda
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-13 22:41:51 +00:00
Peter Collingbourne
bb11ee6d9c Remove PAGE_SIZE call sites.
To enable experiments with non-4KiB page sizes, introduce
an inline page_size() function that will either return the runtime
page size (if PAGE_SIZE is not 4096) or a constant 4096 (elsewhere).
This should ensure that there are no changes to the generated code on
unaffected platforms.

Test: source build/envsetup.sh
      lunch aosp_cf_arm64_16k_phone-userdebug
      m -j32 installclean
      m -j32
Test: launch_cvd \
  -kernel_path /path/to/out/android14-5.15/dist/Image \
  -initramfs_path /path/to/out/android14-5.15/dist/initramfs.img \
  -userdata_format=ext4
Bug: 277272383
Bug: 230790254
Change-Id: Ic0ed98b67f7c6b845804b90a4e16649f2fc94028
2023-06-12 10:59:39 -07:00
Elliott Hughes
21894a6756 Merge "Remove __RENAME_LDBL." am: 87e170df01 am: e6351fb5f0 am: 8db2935824
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2619230

Change-Id: Id8878f6a19a428de18ab006aa9eda715bc1e2e64
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-09 15:53:57 +00:00