Commit graph

869 commits

Author SHA1 Message Date
Eric Miao
c2527073c2 libutils: Add more tests for Unicode
This CL added additional tests for converting between utf16 and utf8,
specifically tests that:

  1. check utf16_to_utf8_length() returns 0 if input is an
     empty UTF16 string

  2. check utf16_to_utf8_length() returns 1 if input is a
     single ASCII character UTF16 string

  3. check utf16_to_utf8_length() returns 3 if input is a
     single UTF-16 character between U+0800 - U+FFFF

  4. check utf16_to_utf8_length() returns 4 if input has
     a surrogate pair

  5. check unpaired UTF-16 surrogate is handled correctly
     (skipped)

  6. check utf16_to_utf8_length(0 handles invalid surrogate
     case correctly, by skipping the first but handling the
     rest correctly

  7. check a normal string with a mix of 1/2/3/4-byte UTF8
     characters is correctly converted by utf16_to_utf8()

  8. check conversion from invalid utf8 sequence with invalid
     leading byte and/or invalid trailing byte(s) should still
     work and not crash

Change-Id: If68e514af0e84ddebf5900b2e140e76ba4f44553
2022-12-06 15:14:27 -08:00
Biswapriyo Nath
890f064990 libutils: Fix missing definition of shared_ptr and unique_ptr
This includes memory header for shared_ptr and unique_ptr templates.
Fixes the following errors:

RefBase.h:803:1: error: ‘shared_ptr’ does not name a type
RefBase.h:810:1: error: ‘unique_ptr’ does not name a type

Change-Id: I6a7a67333c9ef05250c5a3c6199d7fac288f946b
2022-11-25 12:15:53 +05:30
Biswapriyo Nath
9e25bf0136 libutils: Include limits for std::numeric_limits::max
This fixes the following error:
core/libutils/String8.cpp:316:67: error: incomplete type 'std::numeric_limits<long long unsigned int>' used in nested name specifier
  316 |         if (static_cast<size_t>(n) > std::numeric_limits<size_t>::max() - 1 ||
      |                                                                   ^~~

Change-Id: I80cdd2442e2798c37e066e3fdeee7dd5ac34b669
2022-10-21 10:26:08 +05:30
Steven Moreland
b7412c8cd6 libutils: RefBase DEBUG_REF love
Done here:
- path saved to a useable location on host
- path always printed (for visibility for new users)
- open(.., 666) - That's '01204' not '0644' oops

Future considerations:
- make defines constexpr instead of ifdef
- copy malloc hook design to avoid needing to recompile code
- make libutilscallstack default on host
- run libutils tests, not just test compile debug mode
- code incorrectly prints ref 'doesn't exist'
  seems it's gotten out of sync, but still good enough
  to use stacktraces

Bug: 244325464
Test: manual
Change-Id: I732e5b8aec3cd946ef3559a2a814caf693846cc0
2022-10-10 16:58:57 +00:00
Steven Moreland
377adea81c libutils: DEBUG_* modes compile forever
I've seen these fixed before, so we compile the debug modes
now.

Bug: 244325464
Test: 'm libutils_test_compile'
Change-Id: I4271909e81893ad448bc46b8a3a567a84c40f8a3
2022-10-08 05:13:47 +00:00
Elliott Hughes
b795d6fa4b Fix the build with a newer LLVM.
Unify all our "noinline" variants to the current most common one, not
least because the new [[noinline]] syntax is fussier about where it goes.

Test: treehugger
Change-Id: Icfcb75c9d687f0f05c19f66ee778fd8962519436
2022-09-14 20:16:25 +00:00
Christopher Ferris
15fee82247 Fix thread unwind in CallStack.
The CallStack unwind of a different thread was broken since it
wasn't properly setting the tid value.

Fix this problem and add new unit tests to verify the behavior.

Bug: 246405269

Test: New unit tests pass.
Test: Ran unit tests for 1000 operations to verify not flaky.
Change-Id: I00342e6cdcdb4bcb68f29734dadee6c987c98040
2022-09-12 18:37:22 -07:00
Ryan Prichard
4913ca88e5 Remove unnecessary std::unary_function base classes
The function objects work equally well without them, and the base
classes were wrong for both types:
 * HashForEntry: returns size_t but declared to return hash_t
   (uint32_t)
 * EqualityForHashedEntries: returns bool and takes two parameters but
   declared to return hash_t and take one parameter

std::unary_function was deprecated in C++11 and removed in C++17.
Upstream libc++ now removes the type for new-enough C++ dialects.

Bug: http://b/175635923
Test: treehugger
Change-Id: I2ff15c5da6a4e4f71df08c243f8af2f11d8d2b0d
2022-08-26 20:24:57 -07:00
Steven Moreland
643d08e706 Merge "RefBase: test for stack check" am: 5daa3bb90e
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2169132

Change-Id: Ib7b35af8469fdc563244f2dde4a4e0ee91e7f35a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-29 18:31:32 +00:00
Steven Moreland
5daa3bb90e Merge "RefBase: test for stack check" 2022-07-29 18:10:03 +00:00
Steven Moreland
cd4ef87efd RefBase: test for stack check
Surprised this isn't breaking anything, so wanted to
make sure it worked.

Bug: 232557259
Test: libutils_test
Change-Id: Iaec47d644c02dc190e397c6f84dcfab4cc76f566
2022-07-29 00:54:57 +00:00
Steven Moreland
c55c68fe33 Merge "libutils: disallow extending lifetime on stack" am: ea25b4ba5b
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2166445

Change-Id: I48eb86eb8426b1e5c7c92f957173b2eb63870864
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-28 23:45:34 +00:00
Steven Moreland
ea25b4ba5b Merge "libutils: disallow extending lifetime on stack" 2022-07-28 23:17:35 +00:00
Steven Moreland
de52706513 Merge "libutils: RefBase always disallow on stack" am: 51e98b8378
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2166102

Change-Id: Ia8b3205fbb6e36b3c85a378df4c63db4f32759f5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-28 16:29:49 +00:00
Steven Moreland
51e98b8378 Merge "libutils: RefBase always disallow on stack" 2022-07-28 16:11:10 +00:00
Steven Moreland
414bab91eb Merge "libutils: RefBase: extra check for double own" am: b0fe01da56
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2166103

Change-Id: Ie252e8a229d8151aad82347f6b216dbed752d86b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-07-26 22:27:26 +00:00
Steven Moreland
d086fe5109 libutils: disallow extending lifetime on stack
Bug: 232557259
Test: libutils_test
Change-Id: Iacf45b9f295a48904606ced35994ba35566bfcc3
2022-07-26 22:11:13 +00:00
Steven Moreland
c340a08b1b libutils: RefBase always disallow on stack
Before, we only did this in sp<> constructors, but we can always make
this check during the initial incStrong.

Since prebuilts call into the existing report race function declared
in StrongPointer.h, we still call this function from RefBase.cpp.

Bug: 232557259
Test: libutils_test
Change-Id: I4080b1869b83ecf655fc9c182b6de768a6358adf
2022-07-26 22:10:51 +00:00
Steven Moreland
483a2def8d libutils: RefBase: extra check for double own
Bug: 232557259
Test: libutils_test
Change-Id: Ibd400750e7973600ec3fa493838a3b52cafe3add
2022-07-26 17:59:14 +00:00
Xin Li
ebe6598a1c Merge tm-dev-plus-aosp-without-vendor@8763363
Bug: 236760014
Merged-In: Ia927c19f544536f78c20ccef5830bd1be0cebf9b
Change-Id: I0267b9eaad470a56db68f3a0b99abfc41192c6d7
2022-06-28 21:23:43 +00:00
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
Hsin-Yi Chen
d82bd5a626 RESTRICT AUTOMERGE Ignore weak symbol difference in libutils ABI check am: c7d9320ca4
Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/18603830

Change-Id: Ia15131ac6bb49823df032e39a8ee81e5d332addb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-27 03:18:38 +00:00
Hsin-Yi Chen
c7d9320ca4 RESTRICT AUTOMERGE Ignore weak symbol difference in libutils ABI check
The diff_flags make the ABI checker ignore the weak symbol difference
caused by PGO.

Ignore-AOSP-First: This patch relaxes the ABI check for T only.
                   b/232982219 tracks the long-term solution.
Test: make libutils.vendor
Bug: 230076879
Change-Id: I8ec2c0f5a540263b4e8a0a4f9cf26f9c297593b5
2022-05-26 15:20:06 +08:00
Treehugger Robot
e7da3eb805 Merge "Doc Thread requirement." am: c545516e2c am: 40ce64b6db
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2094349

Change-Id: I95cebb43fcd70803fe0bdece39d57546053264cb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 03:21:16 +00:00
Treehugger Robot
c545516e2c Merge "Doc Thread requirement." 2022-05-12 01:53:32 +00:00
Christopher Ferris
39819bbc94 Merge "Use the new AndroidUnwinder object." am: af4db6749a am: ce1c33332c
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2095264

Change-Id: Icc76b39136bce395106c070aeb338d4e6922a28e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-12 00:32:48 +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
5affe3efe2 Merge "libutils: clearer abort on overflow." am: 4ba0e62970 am: 2c623bc650
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2078005

Change-Id: I150014b6afda9aff751383c5b5b6ff2934ec7400
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-04-28 01:15:58 +00:00
Elliott Hughes
b10bf63c93 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
(cherry picked from commit a5f2e4d421)
Merged-In: I08f1018f9da1e09de885699138b7543d55bb2a36
2022-04-28 00:25:25 +00: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
6a1358236e Merge "Mark libutilscallstack min sdk version." am: f5ca027819 am: d94c71f4fb am: 83441e640e
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2061788

Change-Id: I0675d8f86306e73c977b8eed9adb513d902ce684
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-04-12 18:54:48 +00: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
2b393f3664 Merge "Make callback outlive LruCache." am: 6948bbf62c am: 9e67f9302c am: 877cd36104
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2052189

Change-Id: Ibe676c9758cb914098ea775e05d8f468c0a564e2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-04-01 01:20:50 +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
68876679ff Merge "Tweak linux_glibc properties for musl builds in system/core" am: ec8519e953 am: e06b7e163e am: cd92c351b5
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2044103

Change-Id: I2165ce47c46d4d32a34b9b56f01ff415b09fe08b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-03-30 00:52:07 +00:00
Treehugger Robot
ec8519e953 Merge "Tweak linux_glibc properties for musl builds in system/core" 2022-03-30 00:09:01 +00:00
Treehugger Robot
916624491d Merge "Fix build error from signed/unsigned comparison" am: 98c7076202 am: 9f63827322 am: dd79fa2c8d
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2046028

Change-Id: Ia99c768ecfa04dffc1804f4eb37c5328980f5de7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-03-30 00:05:56 +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
Treehugger Robot
8da2dbe534 Merge "Fix TEMP_FAILURE_RETRY on non-GNU C++ dialects" am: addba34668 am: aae9c4ec53 am: 5c3f7bd328
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2025446

Change-Id: I73dae25afe75e8e26f365898685a6a17d6ff635d
2022-03-17 06:31:05 +00:00
Treehugger Robot
1727c0c622 Merge changes Iee0932b5,I0d77c490 am: f8cd69af8b am: e8c3bd931b am: 4db635bb0a
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2025448

Change-Id: Ic6452433dc944a8d53dc78c70815e18492f9f61b
2022-03-16 23:22:07 +00: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
91de6f1de6 Merge "libutils: ~RefBase more logs" am: 83785021f7 am: 976ee88aac am: 522182dff3
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2021996

Change-Id: Ia8aa98d8fa07b4994f767ce78e1d50e7f2130eba
2022-03-14 18:10:54 +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
Treehugger Robot
4c58cef88a Merge "Adding libutils owner smoreland@ as fuzz targets owner for alerts" am: 5520cb3309 am: bb9525cb67 am: 84fd9f8e99
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2016715

Change-Id: Ib21a3e63ac6bde2f2fd6a581050eedd0b0165c8b
2022-03-08 22:50:19 +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
Treehugger Robot
e76d8254bf Merge "Fix OkOrFail<status_t> conversion ambiguities" am: 5a1f51b070 am: fb78f6f5e4 am: 7826f9a738
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2000911

Change-Id: Ia5c6fc34fe562a143d18acd89688b88e125442b2
2022-02-25 22:34:41 +00:00