Commit graph

796 commits

Author SHA1 Message Date
Steven Moreland
9d8af6af65 RefBase: disallow make_shared, make_unique
It's risky to mix multiple-ownership types. Taken from SharedRefBase.

Bug: 232557259
Test: N/A
Change-Id: Ic0dbd6d11e44fa9db87c4f9b1776d4989cbf9f56
2022-06-22 21:54:43 +00:00
Treehugger Robot
c545516e2c Merge "Doc Thread requirement." 2022-05-12 01:53:32 +00:00
Steven Moreland
90722d254e Doc Thread requirement.
Fixes: 230893354
Test: N/A
Change-Id: I426184840c7bf61fe3369388cfc6db184470acf0
2022-05-11 23:13:17 +00:00
Christopher Ferris
ab63124cd9 Use the new AndroidUnwinder object.
Replaces libbacktrace in CallStack. There is one small behavioral
change, the BuildId data is added to the unwinds.

Bug: 120606663

Test: All unit tests pass.
Test: Run the fuzzer for over an hour without any crashes.
Change-Id: Ic8a4247c515ce0d3cdc4d2cc15167d1948b15fa5
2022-05-10 17:19:12 -07:00
Elliott Hughes
a5f2e4d421 libutils: clearer abort on overflow.
Let's turn a bug into a feature... Since this code is built with intsan,
anyone who caused overflow here will have had an abort, so we know
no-one actually needs the BAD_INDEX return that was presumably the
original author's intent. So let's just mandate that, since it's a lot
harder to ignore an abort than it is to ignore an error return.

Bug: http://b/179044558
Test: treehugger
Change-Id: I08f1018f9da1e09de885699138b7543d55bb2a36
2022-04-27 14:29:44 -07:00
Steven Moreland
6c509ca3c3 Mark libutilscallstack min sdk version.
Mark this as 29 for easy inclusion in APEXes when debugging. Make
sure we don't introduce calls to things here which would prevent
this from being used on old platforms.

Fixes: 228561718
Test: build
Change-Id: I2574455dbfe681117e4afcf6eef3546be51393fa
2022-04-11 22:30:07 +00:00
Florian Mayer
e0240d3f61 Make callback outlive LruCache.
The callback can be called by the destructor of LruCache, so it needs to be destructed last.

Bug: 227635615
Change-Id: I7d965a2000c1ec32d9c9e88d25ab0c1ba3e9c739
2022-03-31 20:21:28 +00:00
Treehugger Robot
ec8519e953 Merge "Tweak linux_glibc properties for musl builds in system/core" 2022-03-30 00:09:01 +00:00
Andrei Homescu
1a867dcb6e Fix build error from signed/unsigned comparison
Bug: 224644083
Test: m
Change-Id: I9adbe1ea53193d8c59f9022754cd3e23533e54ad
2022-03-29 00:30:34 +00:00
Colin Cross
10bbb01823 Tweak linux_glibc properties for musl builds in system/core
For convenience, builds against musl libc currently use the
linux_glibc properties because they are almost always linux-specific
and not glibc-specific.  In preparation for removing this hack,
tweak the linux_glibc properties by either moving them to host_linux,
which will apply to linux_glibc, linux_musl and linux_bionic, or
by setting appropriate musl or linux_musl properties.  Properties
that must not be repeated while musl uses linux_musl and also still
uses the linux_glibc properties are moved to glibc properties, which
don't apply to musl.  Whether these stay as glibc properties or get
moved back to linux_glibc later once the musl hack is removed is TBD.

Bug: 223257095
Test: m checkbuild
Test: m USE_HOST_MUSL=true host-native
Change-Id: I076fa026d7dddfccfa5cc395dd06bdc979eee1d8
2022-03-24 15:59:08 -07:00
Andrei Homescu
fcbc96191c Fix TEMP_FAILURE_RETRY on non-GNU C++ dialects
TEMP_FAILURE_RETRY uses typeof which is only allowed by gcc and clang
for GNU dialects. This switches to __typeof__ which is always supported.

Bug: 224644083
Test: m
Change-Id: I96d48d2f0dc5cd9ab903755d93c71c4eb80f7529
2022-03-16 20:54:31 +00:00
Andrei Homescu
aa4ebf2ce1 Fix Errors.h on systems that define NO_ERROR
Some systems (originally only Windows) define their own
NO_ERROR macro that overlaps with the enumerator from Errors.h.
The enumerator is only defined if the macro was not.

Bug: 224644083
Test: m
Change-Id: Iee0932b5259b3bfcf6494656b27e6e7488319f5c
2022-03-16 02:15:04 +00:00
Andrei Homescu
5c15de21da Disable call stacks on every OS except Linux/Android
To keep libutils (and consequently libbinder) as compact
and portable as possible, this disables call stacks on all
operating systems except Linux and Android.

Bug: 224644083
Test: m
Change-Id: I0d77c49022e852c2b8607f555174c4f9d54ed3df
2022-03-16 01:35:19 +00:00
Steven Moreland
f164de8935 libutils: ~RefBase more logs
This code was a bit confusing because Android runs with an old debug
mode on. The flag around this is removed to make it more clear what
is going on, and the log is promoted D -> W.

Bug: N/A
Test: boot, check logs
Change-Id: I4645b1a7b8e252336a6f9482ce6b57e1b907619d
2022-03-11 02:46:31 +00:00
Anis Assi
e75dd9a1c1 Adding libutils owner smoreland@ as fuzz targets owner for alerts
Bug: 221891733
Change-Id: I85ff5c754fb2eb85331e84b3dbacd24844d54efc
2022-03-08 19:48:21 +00:00
Atneya Nair
dde6034eac Fix OkOrFail<status_t> conversion ambiguities
OkOrFail<status_t> has specialized conversions for Result<int, StatusT>
to avoid ambiguous implicit conversion sequences. Since user conversion
operators sequences can be followed by integral promotion, specializing
for integral types is necessary.

Specialize ResultError<StatusT> so calling code() returns a status_t
instead of a StatusT and message() is implemented even when not carrying
a string.
Eventually, these classes should be combined.

Add equality operators for ResultError<StatusT>.

Bug: 219580167
Test: atest Errors_test.cpp
Merged-In: I14acecfd2aef33c40e79ddb091e2f4af9291d837
Change-Id: Ifb5ed3c2d3452b10901e4aeb19368d873225d9ce
2022-02-25 14:27:41 -05:00
Treehugger Robot
4a39ba316f Merge "libutils: Remove a little dead code" 2022-02-08 23:12:39 +00:00
Greg Kaiser
044be6bceb libutils: Remove a little dead code
With our recent change 0455a2c39c,
there's some logic that can be simplified to make this slightly
easier to read.

This CL does not change the behavior of this code.

Bug: 208895940
Test: TreeHugger
Change-Id: I4de2dbaf4406cbb7785df8839bb3ae453186ea69
2022-02-08 07:37:13 -08:00
Steven Moreland
39fc18b0cd libutils -= libprocessgroup dep
:)

This pulls in quite a few things into a lot of processes. Removing it
separately, in case the use of SetTaskProfiles needs to be reverted,
removing this as well might cause that revert to have linker errors
if new static users of libutils are introduced in the meantime.

Bug: 208895940
Test: build
Change-Id: Iaf5b5d41328c1b1f50bb32be8a6a1bd3a0c3f22f
2022-02-08 01:56:45 +00:00
Tim Murray
0455a2c39c libutils: don't call SetTaskProfiles around priority
Threads should always be in the same state as their parents. This also
implies that the additional SetTaskProfiles is unnecessary when
creating a new thread.

Test: boots, TH
Bug: 208895940
Change-Id: Id971c6e87d342a695bea106cdd258bc0ef6f7ecb
2022-02-08 01:54:09 +00:00
Colin Cross
02a3f958db Use 0 instead of NULL for comparison to char16_t
musl libc defines NULL as nullptr, which is explicitly allowed by
C++11.  nullptr_t cannot be implicitly cast to an integral type.
Use 0 instead.

Bug: 190084016
Test: m USE_HOST_MUSL=true host-native
Change-Id: I0c3b6c94cd69262f574414bf52494333f2f2645a
2022-01-13 13:41:59 -08:00
Jiyong Park
e060580c31 Merge changes from topic "or_return"
* changes:
  Sort exported headers of libutils
  OR_RETURN supports status_t
2022-01-12 07:27:41 +00:00
Jiyong Park
8b196a7336 Sort exported headers of libutils
Bug: N/A
Test: build

Change-Id: I658155371ca32a7e9ba7e82f8e43780c515df77b
2022-01-12 09:23:46 +09:00
Jiyong Park
705abe2d30 OR_RETURN supports status_t
This change provide a specialization of android::base::OkOrFail for
status_t. As a result, a statement whose type is status_t can be used
with OR_RETURN.

The specialization also provides conversion operators to Result<T,
StatusT> where StatusT is a wrapper type for status_t. This allows
OR_RETURN macro to be used in newer functions that returns Result<T,
StatusT>.

Example usage:

\#include <utils/ErrorsMacros.h>

status_t legacy_inner();

status_t legacy_outer() {
  OR_RETURN(legacy_inner());
  return OK;
}

Result<T, StatusT> new_outer() {
  OR_RETURN(legacy_inner()); // the same macro
  return T{...};
}

Bug: 209929099
Test: atest libutils_test
Change-Id: I0def0e84ce3f0c4ff6d508c202bd51902dfc9618
2022-01-12 09:20:27 +09:00
Yi Kong
6ee028f165 Enable afdo for libutils
Enable PGO (profile guided optimisation) for better performance.

Test: presubmit
Bug: 195134194
Change-Id: If9abecd830573946fc52b28afd7599800367aa09
2021-12-23 15:57:40 +08:00
Wei Wang
e73180f8f5 libutils: do not follow process's group
1) App doesn't have cgroup access and there is no purpose of reading cgroup
for app. For system_server it should be known in foreground group. So
there is no benefit of reading group.

2) Reading cgroup in apps can also cause contention for other cgroup
operations.

3) vendor can change cgroup setting and get_sched_policy may return
incorrect information for get_sched_policy_profile_name.

Test: Boot
Bug: 210011562
Signed-off-by: Wei Wang <wvw@google.com>
Merged-In: I8e8c8b346984781c56ec93c0616121f7d5c99fe5
Change-Id: I8e8c8b346984781c56ec93c0616121f7d5c99fe5
(cherry picked from commit defb7773121545130fff80928ebcd7d6015be1d1)
2021-12-13 10:05:05 -08:00
Chris Parsons
820da65897 Remove libdl from shared_libs
This entry is redundant, as system_shared_libs by default includes
libdl.

This should be a no-op change for the current build system, but avoids
an issue on the alternative (experimantal) build system, Bazel.

Test: md5sum libutils.so before/after on aosp_flame, verified no changes
Change-Id: I18f6e67c3e23299a0f1e0ef530a0a809b068dc03
2021-11-29 17:43:04 -05:00
Xin Li
6042b45f56 Merge "Merge Android 12" 2021-10-07 23:50:14 +00:00
Wei Wang
1132977223 Merge changes from topic "sysbg_aosp"
* changes:
  task_profiles: add ServicePerformance to legacy device policy
  libutils: use system_background for low prio tasks in framework
2021-10-07 17:54:40 +00:00
Wei Wang
c39d60d114 libutils: use system_background for low prio tasks in framework
Bug: 201428466
Test: Build and boot check system_server's sched group
Signed-off-by: Wei Wang <wvw@google.com>
Change-Id: Iffc47fdaf3ef8fba6eb01a12cf534a0393e3e91c
2021-10-06 13:04:22 -07:00
Treehugger Robot
7dc38fe273 Merge "Looper: Use sequence numbers in epoll_event to track requests" am: 663c692a2d
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1795650

Change-Id: Id4072ec03cbd6f0c5eb6a54d8c37d9dd453cf989
2021-09-13 12:11:00 +00:00
Treehugger Robot
663c692a2d Merge "Looper: Use sequence numbers in epoll_event to track requests" 2021-09-13 11:58:45 +00:00
Prabir Pradhan
729057ab8c Looper: Use sequence numbers in epoll_event to track requests
Previously, Looper internally kept track of the requests to add fds
using the fd value itself. It used an internal sequence number
associated with each request to add a callback to avoid a situation
where a callback is unexpectedly called. However, since it used the fd
value rather than the sequence number to register events into epoll,
there was still a way where unintended hangups could occur.

This exact sequence of events caused unintended behavior in Looper:
- An fd (FD) is added to the looper.
- Looper registers FD into epoll using its FD number.
- FD is closed.
- A hangup event arrives from epoll_wait while the Looper is polling.
Looper is waiting for the lock to process the callback for FD, because
it is blocked by:
- A new fd is created and added to the looper. Since the lowest number
fd is reused, this new fd has the same value as FD.
- The poll request for Looper is now unblocked, so it looks up the
callback associated with FD to process the hangup.
- Since FD is already associated with the new callback, the new callback
is called unintentionally.

This CL uses the sequence number to register fds into epoll. That way,
when we get a hangup from epoll that is associated with a sequence
number, there is no way an unexpected callback will called.

This CL also adds a test to verify this behavior. Due to the
nondeterministic nature of this multi-thread scenario, the test verifies
this scenario repeatedly. Without the fix in Looper, the test is flaky,
but should never fail after the fix.

Bug: 195020232
Bug: 189135695
Test: atest libutils_test --rerun-until-failure
Ignore-AOSP-First: Topic CL aosp/1799831 has a merge conflict with
internal master, resolved in ag/15613419.

Change-Id: Ib4edab7f2407adaef6a1708b29bc52634f25dbb6
2021-09-01 14:52:52 +00:00
Steven Moreland
e5eede1551 Merge "RefBase: Unknown mFlag meaning" am: 53e977339b
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1805816

Change-Id: I3594e5658cc4759c0552aedb394f397be94d81d5
2021-08-24 20:27:09 +00:00
陈冠有
0cbef728f9 RefBase: Unknown mFlag meaning
Change-Id: I3ddd1895c48c682bdb0868e890c62029710bf1c8
2021-08-22 16:36:36 +00:00
Elliott Hughes
5153cdee39 Merge "Split up the system/core/ TEST_MAPPING." am: 0589b7eb94
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1797132

Change-Id: I49316e97d5997bf5a0e5f7932aa3f1016b4566e6
2021-08-18 16:41:35 +00:00
Elliott Hughes
22e082e87a Split up the system/core/ TEST_MAPPING.
A lot of things had moved out of system/core/ without their TEST_MAPPING
entries having gone with them, reducing the amount of presubmit coverage
for those things.

In order to reduce the likelihood of that happening again, I've pushed
all that remained in the system/core/ TEST_MAPPING down into the
individual subdirectories.

Test: treehugger
Change-Id: Ib75d65f9200fa64ae1552471da6fbe5b7023cf94
2021-08-16 16:37:10 -07:00
Treehugger Robot
f34b2446bb Merge "Revert "Revert "Remove unused String8::setPathName.""" am: f9a9ee048c am: e9a9a4f071
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1771595

Change-Id: I815e30f78c4a129de8186bd1b08278024fdf01d6
2021-07-20 20:07:22 +00:00
Greg Kaiser
d03851e549 Revert "Revert "Remove unused String8::setPathName.""
This reverts commit 70d9fb63e6.

Reason for revert: Outstanding usage of this method removed internally

Change-Id: Idcc00ec261aa1d97f11e47abdb08b10a37b5d20f
Test: Local build; treehugger (which I'll manually confirm runs on the appropriate targets)
2021-07-19 20:19:44 +00:00
Greg Kaiser
2cca5cc992 Merge "Revert "Remove unused String8::setPathName."" am: 615bf4ef14 am: 01f3306b69
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1768145

Change-Id: I9856b917353e57b048eeec2d3ed6d157165e1148
2021-07-15 13:56:01 +00:00
Greg Kaiser
70d9fb63e6 Revert "Remove unused String8::setPathName."
This reverts commit c214426e0c.

Reason for revert: This is not unused; broke build internally

Change-Id: I18e8b7954256ae015ad32743fa6a75850b00913e
2021-07-15 13:33:10 +00:00
Elliott Hughes
941b1a61b0 Merge "Remove unused String8::setPathName." am: 40a0664b84 am: 5f7d548dc6
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1765465

Change-Id: If7b66e7de22107110fa595827611f1bb1a83a9dc
2021-07-14 21:48:06 +00:00
Elliott Hughes
c214426e0c Remove unused String8::setPathName.
Test: treehugger
Change-Id: Idc8d7e748b0df4ce8a26227dc73a5eef2b04244f
2021-07-13 17:20:53 -07:00
Treehugger Robot
b8e683537f Merge "libutil: no special copy from StaticString16" am: 7d067aee62 am: ece939ecc9
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1751786

Change-Id: Ic13c3a84471160c534b0e84ac5d0987f457eef75
2021-06-30 02:51:49 +00:00
Treehugger Robot
dcd1cacbbb Merge "String16 is moveable (noexcept)" am: 3551e457ca am: 32ceaa1299
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1749261

Change-Id: Ia658a7b6ad2c21c83ef109230a4c5f0a7d02068a
2021-06-30 01:48:14 +00:00
Jooyung Han
6f92640d45 libutil: no special copy from StaticString16
String16's ctors already handle static strings, so we don't need a
specialized constructor which accepts StaticString16.

Bug: n/a
Test: libutils_test
Change-Id: I93a1ba70d743ff9c73f113d53ffba73cef6adade
2021-06-30 09:04:29 +09:00
Jooyung Han
98b396e785 String16 is moveable (noexcept)
String16 is still in use by AIDL compiler. Because String16 is not
noexcept-move-constructible, the C++ compiler will complain when it is
used with non-copyable types (such as ParcelFileDescriptor).

For example, when vector<Foo> is resized, copy-ctor of Foo is called,
which is not available.

  parcelable Foo {
    String s;
    ParcelFileDescriptor[] pfds;
  }

By providing noexcept move-ctor for String16, vector<Foo> can be resized
with no problem.

Btw, copy from StaticString16 is specialized for efficiency and move
from StaticString16 don't need to be different from copy.

Bug: 192136980
Test: libutils_test
Change-Id: I13744a2ceebf5781c3ef7f3a04237a6750b0db0a
2021-06-29 10:18:23 +09:00
Elliott Hughes
e227beedde Merge "Check for overflow in String16::append and String16::insert." into sc-dev am: eec890e173
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/14940186

Change-Id: I2f6c9abc6b2baf587980224698cdeba4d55ed2a8
2021-06-15 22:34:06 +00:00
Elliott Hughes
eec890e173 Merge "Check for overflow in String16::append and String16::insert." into sc-dev 2021-06-15 22:19:15 +00:00
Elliott Hughes
1ce243f7a6 Merge "Check for overflow in String8::real_append." into sc-dev am: 20462789dc
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/14941314

Change-Id: Ib18670bec989f9ec4ec628647718ed97e81468b3
2021-06-15 21:16:47 +00:00