History log of /bionic/libc/async_safe/async_safe_log.cpp
Revision Date Author Comments
8aecba7aa6b7f7b92f69c0d3febef59fdb135f87 18-Oct-2017 Elliott Hughes <enh@google.com> 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
854556c41e20c37b210498b0374415b640104785 19-Sep-2017 Elliott Hughes <enh@google.com> 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).

(cherry picked from commit 53dc9dd70155fd75af744cbebecc563658c69818)

Bug: http://b/65608572
Test: ran tests
Change-Id: I881029d9fd368b8556843e70fdb278fbe51dbfee
Merged-In: I881029d9fd368b8556843e70fdb278fbe51dbfee
53dc9dd70155fd75af744cbebecc563658c69818 19-Sep-2017 Elliott Hughes <enh@google.com> 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
92476407115f4431c5888c02cdb5f476b26e393a 22-Aug-2017 Christopher Ferris <cferris@google.com> 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
695713e931f0436aca56be9c0dacf2a5dd4e56e7 21-Jun-2017 Elliott Hughes <enh@google.com> 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
7a3681e5b6c39bc2b3b62031ca5941dbf7bc4e63 25-Apr-2017 Christopher Ferris <cferris@google.com> 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