Commit graph

40 commits

Author SHA1 Message Date
Elliott Hughes
1eacc0edc0 bpfmt all the .bp files to silence ayeaye.
Test: treehugger
Change-Id: I5b7add6f013dcd2d4eee4851b7a2a22310c6d533
2024-01-19 19:05:36 +00:00
Elliott Hughes
3f98012768 async_safe_log.cpp: remove unused #includes.
Test: treehugger
Change-Id: I044e58e9ab1163c94e9d4912b4d2412cffd3d4ad
2023-11-28 15:16:47 +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
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
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
Peter Collingbourne
84979776d0 Fix stack use-after-scope in async_safe_log.
The buffer filled in by strerror_r needs to stay in scope while
it is pointed to by str.

Bug: 273807460
Change-Id: I494ca8b8aca2b28ec2f0f3da72d845db99633553
2023-03-15 15:21:58 -07:00
Brian Duddie
e78ea1fc0c Open libasync_safe to any APEX
Permits usage of fdsan in libcutils.

Bug: 244214188
Test: build
Change-Id: I7ac5248c697853aec1210b16b79a84de9046d0d3
2022-09-02 22:43:56 +00:00
Shikha Panwar
307254c616 Make libasync_safe available in com.android.virt
This is required because virtualization_service use
libtombstoned_client_rust which has transitive dependency on
libasync_safe

Test: atest MicrodroidHostTestCases
Bug: 202153827
Change-Id: I9e670d02995f9ed9e67791aaecb300b6bfdbdb03
2022-04-06 21:00:13 +00:00
zijunzhao
75c36fe0c2 Add %m and %#x support for async_safe logging
Bugs: None
Test: None
Change-Id: I889015b89b85e222e26f8aa20e35d46a86a0cb7c
2022-02-17 07:23:58 +00:00
Jingwen Chen
c57947860d bp2build: remove some bp2build_available props, use package_allowlist instead.
Test: build/bazel/scripts/milestone-2/demo.sh full

Test: bazel query //bionic/...
Change-Id: I737574766be898279d8bf6f3f0adb43dcc40c220
2021-03-19 02:06:27 -04:00
Nicolas Geoffray
4647d4839f Add min_sdk_version for ART module.
Bug: 180399951
Test: m
Change-Id: I54eb06ae4a695ae184de4fb72fc0092910836652
2021-03-08 17:29:41 +00:00
Bob Badour
aa7d835fdd Add LOCAL_LICENSE_KINDS to bionic
Added SPDX-license-identifier-Apache-2.0 to:
  apex/Android.bp
  libdl/Android.bp
  tools/Android.bp
  tools/versioner/Android.bp
  tools/versioner/src/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD to:
  benchmarks/Android.bp
  benchmarks/linker_relocation/gen/Android.bp
  libc/malloc_debug/Android.bp
  libc/system_properties/Android.bp
  tests/Android.bp
  tests/libs/Android.bp
  tests/libs/Android.build.dlext_testzip.mk
  tests/make_fortify_compile_test.mk

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-ISC SPDX-license-identifier-MIT
    legacy_notice legacy_unencumbered
to:
  libc/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-MIT legacy_unencumbered
to:
  libm/Android.bp

Added SPDX-license-identifier-Apache-2.0 legacy_unencumbered
to:
  libc/tools/Android.bp

Added SPDX-license-identifier-BSD
to:
  benchmarks/linker_relocation/Android.bp
  benchmarks/spawn/Android.bp
  libc/async_safe/Android.bp
  libc/malloc_hooks/Android.bp
  libfdtrack/Android.bp
  linker/Android.bp
  tests/headers/Android.bp
  tests/headers/posix/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all
Exempt-From-Owner-Approval: janitorial work
Change-Id: Ib05bcaa276b3aa71a7654ccbe8e67e1f16aec9f3
2021-02-19 23:38:28 +00:00
Rupert Shuttleworth
fd64868a92 Mark cc_library_headers targets as being bp2build_available.
Test: build/bazel/scripts/bp2build-sync.sh write.
Change-Id: I78a491d20779f50757b55c8e5305b588bf613839
2021-02-16 03:39:20 +00:00
Justin Yun
869a0faf21 Add "product_available" to product available modules
"vendor_available" modules were available to product modules.
However, not all "vendor_available" modules are required to be
available to product modules. Some modules want to be available only
to product modules but not vendor modules.

To cover the requirement, we separate "product_available" from
"vendor_available".
"vendor_available" will not provide product available module.

Bug: 150902910
Test: build
Change-Id: I13b8222e191333c6c2cb7794ef3344fdcc6ebe98
2020-11-11 15:29:47 +09:00
Yifan Hong
02bee7182e Merge "Make vendor_ramdisk_available." 2020-10-29 17:17:29 +00:00
Yifan Hong
b04490d7e5 Make vendor_ramdisk_available.
Test: pass
Bug: 156098440
Change-Id: I8fe2deb8fa3b24c227202be02d8af648629cffeb
2020-10-27 17:06:45 -07:00
Martin Stjernholm
81c260d34b Rename ART release APEX to com.android.art.
Test: See https://r.android.com/1457217
Bug: 169639321
Change-Id: I71c75987ebfb1196d63f452945c5d387f2976d86
Merged-In: I71c75987ebfb1196d63f452945c5d387f2976d86
2020-10-21 15:41:02 +01:00
Josh Gao
d37113311c async_safe: don't call libc's socket.
Like with close, socket is no longer a simple syscall, so we can get
recursive calls that deadlock.

Bug: http://b/165206592
Test: bionic-unit-tests on cuttlefish
Test: treehugger
Change-Id: I2ba77d733d1ebf08a91afd6ca179e7ae6ae3866e
2020-08-21 14:23:57 -07:00
Elliott Hughes
3205cddff0 linker: CHECK() or async_safe_fatal() rather than abort().
In particular, add the strerror() output if mprotect() fails.

Fix the CHECK macro so that you can make assertions involving operator%
without that being confused for a printf format specifier.

Bug: https://issuetracker.google.com/158645318
Test: treehugger
Change-Id: I6817f8ca5f094c52dc2c9067bfac90385a8743f5
2020-06-10 14:49:28 -07:00
Jiyong Park
2aa19dcb59 Set apex_available property
The marked library(ies) were available to the APEXes via the
hand-written whitelist in build/soong/apex/apex.go. Trying to remove the
whitelist by adding apex_available property to the Android.bp of the
libraries.

Bug: 150999716
Test: m
Change-Id: I6ea7fee2a135298085d3965d3578d9ecd53ee405
2020-04-08 22:52:06 +09:00
Yifan Hong
5a39cee1ce Make ramdisk_available.
Test: pass
Bug: 147347110
Change-Id: I142311a7558a19d209bcd63207a88e12cf6f130e
2020-01-22 12:09:33 -08:00
Tom Cherry
2185a12312 Add a README.md for async_safe
Particularly to document why both this and liblog exist, when they do
essentially the same thing.

Test: n/a
Change-Id: I216194402a12270cfbb6bc9b840d054dc9c1dc16
2020-01-17 12:12:26 -08:00
dimitry
7f04880820 Enable native_bridge_support
Enable native bridge support for bionic libraries.
Makes it possible to use them in binaries for translated
architectures.

Bug: http://b/77159578
Test: make
Change-Id: Iccd4ad7aecfa5260cc15f09ca975d2e18987278a
2019-05-06 17:13:51 +02:00
Alex Light
7448f3e5dd Mark lib_async_safe_headers as supporting linux_bionic
This target is needed by linux_bionic targets and so should support
it.

Test: ./art/tools/build_linux_bionic.sh com.android.runtime.host
Change-Id: Ib12f1cf1d70e606b0921f507b3e460f5d543017e
2019-02-19 09:47:40 -08:00
Elliott Hughes
3019d78d4a libasync_safe: stop clobbering other folks' identifiers.
The log priorities and ids are in an NDK header, available to everyone.

Move CHECK into its own header for now. This would be better if it was
more like the <android-base/logging.h> CHECK family, but I don't have an
easy way to do that without lots of copy & paste, so punting for now.

Bug: https://issuetracker.google.com/issues/119713191
Test: boots
Change-Id: I4566be8a0a024fede0e2d257c98b908ec67af2a8
2019-02-14 14:23:13 -08:00
Logan Chien
17af91b588 Add libc_headers header lib
This commit extracts `libc_headers` for `libasync_safe` and
`libpropertyinfoparser` (in the `system/core` repository).

Before this change, `libasync_safe` expects that `libc` is automatically
added to `system_shared_libs` of the libasync_safe vendor variant even
if `libc_defaults` explicitly declines any `system_shared_libs`.

This commit defines `libc_headers` for `libasync_safe` and
`libpropertyinfoparser` so that they can find the headers from libc
without causing circular dependencies.

Bug: 123006819
Test: make checkbuild
Change-Id: I2435ab61d36ff79ca2b4ef70bd898b795159c725
2019-01-19 07:18:38 +08:00
Ryan Prichard
5de9a31c05 Add async_safe_format_fd_va_list
Bug: none
Test: bionic unit tests
Change-Id: I8c6b2d1d118f4182dd7bf1cbfba78f20b3cefc79
2018-10-08 13:27:16 -07:00
Yi Kong
32bc0fcf69 Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning.

Test: m
Bug: 68236239
Change-Id: I5b4123bc6709641315120a191e36cc57541349b2
2018-08-02 18:09:44 -07:00
Josh Gao
f6e5b58260 Introduce api to track fd ownership in libc.
Add two functions to allow objects that own a file descriptor to
enforce that only they can close their file descriptor.

Use them in FILE* and DIR*.

Bug: http://b/110100358
Test: bionic_unit_tests
Test: aosp/master boots without errors
Test: treehugger
Change-Id: Iecd6e8b26c62217271e0822dc3d2d7888b091a45
2018-07-19 14:28:54 -07:00
Jiyong Park
8d7866c58f Build recovery variant of the dynamic linker
In order to support shared libraries in the recovery mode, the dynamic
linker is now built with recovery_available: true option.

In addition, a few more modules (such as libasync, etc.) are also marked
as recovery_available: true as they are transitive dependencies of the
dynamic linker.

Bug: 63673171
Test: `adb reboot recovery; adb devices` shows the device ID
Test: `adb root && adb shell` and then
$ lsof -p `pidof adbd` shows that libm.so, libc.so, etc. are loaded from
the /lib directory.

Change-Id: Idd981d8cf25568a85b24032cf78e50adfd5f4a7f
2018-06-08 14:49:56 +09:00
Ryan Prichard
5258c2518e Fix async_safe_fatal overflow handling
Bug: b/79116392
Test: manual
Change-Id: I46cd1007be165489db27cdcd4b42ec69de40d645
2018-05-01 17:59:59 -07:00
Elliott Hughes
cbc80ba9d8 Switch the rest of our internal headers to #pragma once.
We've been using #pragma once for new internal files, but let's be more bold.

Bug: N/A
Test: builds
Change-Id: I7e2ee2730043bd884f9571cdbd8b524043030c07
2018-02-13 14:27:17 -08:00
Elliott Hughes
8aecba7aa6 Implement pthread_attr_getinheritsched/pthread_attr_setinheritsched.
Historically, Android defaulted to EXPLICIT but with a special case
because SCHED_NORMAL/priority 0 was awkward. Because the code couldn't
actually tell whether SCHED_NORMAL/priority 0 was a genuine attempt to
explicitly set those attributes (because the parent thread is SCHED_FIFO,
say) or just because the pthread_attr_t was left at its defaults.

Now we support INHERIT, we could call sched_getscheduler to see whether
we actually need to call sched_setscheduler, but since the major cost
is the fixed syscall overhead, we may as well just conservatively
call sched_setscheduler and let the kernel decide whether it's a
no-op. (Especially because we'd then have to add both sched_getscheduler
and sched_setscheduler to any seccomp filter.)

Platform code (or app code that only needs to support >= P) can actually
add a call to pthread_attr_setinheritsched to say that they just want
to inherit (if they know that none of their threads actually mess with
scheduler attributes at all), which will save them a sched_setscheduler
call except in the doubly-special case of SCHED_RESET_ON_FORK (which we
do handle).

An alternative would be "make pthread_attr_setschedparams and
pthread_attr_setschedprio set EXPLICIT and change the platform default
to INHERIT", but even though I can only think of weird pathological
examples where anyone would notice that change, that behavior -- of
pthread_attr_setschedparams/pthread_attr_setschedprio overriding an
earlier call to pthread_attr_setinheritsched -- isn't allowed by POSIX
(whereas defaulting to EXPLICIT is).

If we have a lot of trouble with this change in the app compatibility
testing phase, though, we'll want to reconsider this decision!

 -*-

This change also removes a comment about setting the scheduler attributes
in main_thread because we'd have to actually keep them up to date,
and it's not clear that doing so would be worth the trouble.

Also make async_safe_format_log preserve errno so we don't have to be
so careful around it.

Bug: http://b/67471710
Test: ran tests
Change-Id: Idd026c4ce78a536656adcb57aa2e7b2c616eeddf
2017-10-25 14:28:42 -07:00
Josh Gao
a0f6dc577e Trivial style fix.
Test: none
Change-Id: I710d29293171c6160558dab66c515eae16b92923
2017-10-16 21:31:37 -07:00
Elliott Hughes
53dc9dd701 Improve pthread_create failure handling.
Return EAGAIN rather than aborting if we fail to set up the TLS for a new
thread.

Add a test that uses all the VMAs so we can properly test these edge cases.

Add an explicit test for pthread_attr_setdetachstate, which we use in the
previous test, but other than that has no tests.

Remove support for ro.logd.timestamp/persist.logd.timestamp, which doesn't
seem to be used, and which prevents us from logging failures in cases where
mmap fails (because we need to mmap in the system property implementation).

Bug: http://b/65608572
Test: ran tests
Change-Id: I9009f06546e1c2cc55eff996d08b55eff3482343
2017-09-19 14:02:50 -07:00
Christopher Ferris
9247640711 Refactor BufferOutputStream.
- Rewrite BufferOutputStream to handle 0 sized buffers and to get rid
  of an unnecessary loop.
- Add tests to verify overflow corner cases.
- Implement async_safe_format_buffer to call async_safe_format_buffer_va_list
  instead of duplicate the code.

Test: Ran new unit tests, booted on angler.
Change-Id: I7fb13e209f5b7443d212f55aab4b05ff2e0e8219
2017-08-22 13:17:28 -07:00
Elliott Hughes
3f66e74b90 Remove nullability specifications.
Bug: http://b/64251432
Test: builds
Change-Id: I5b1613484783f7478d30b5e694007f77fa626659
2017-08-01 13:24:40 -07:00
Elliott Hughes
695713e931 Shave a stack frame off asserts.
No-one cares about seeing "async_safe_fatal" (which you have to admit is a
pretty confusing name for an app developer anyway).

On arm:

     #00 pc 0001a43c  /system/lib/libc.so (abort+63)
     #01 pc 0001a627  /system/lib/libc.so (__assert+14)

And aarch64:

     #00 pc 000000000001d75c  /system/lib64/libc.so (abort+120)
     #01 pc 000000000001dad0  /system/lib64/libc.so (__assert+44)

Bug: N/A
Test: ran `crasher assert` and `crasher64 assert`
Change-Id: I00be71c566c74cdb00f8e95d634777155bc3da03
2017-06-20 17:28:42 -07:00
Jiyong Park
f9f9a5d76c make libasync_safe vendor_available:true
This, when used with BOARD_VNDK_VERSION flag, enables the
module to be built and installed twice, one for /system,
other for /vendor.

libasync_safe is used by libbacktrace which is in turn used by libs in
/vendor and thus marked as vendor_available. Therefore, libasync_safe
is also marked as vendor_available.

Details: https://android-review.googlesource.com/368372

Bug: 33241851
Test: BOARD_VNDK_VERSION=current m libasync_safe.vendor successful

Merged-In: I4b4de3b99a024d52612109cee3d66b4e5fc12dec
Change-Id: I4b4de3b99a024d52612109cee3d66b4e5fc12dec
(cherry picked from commit ec0d6b416e)
2017-06-14 18:24:11 +09:00
Christopher Ferris
7a3681e5b6 Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.

Change the names of the functions to reflect the new name of the library.

Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.

Bug: 31919199

Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
2017-05-03 08:50:43 -07:00