Commit graph

877 commits

Author SHA1 Message Date
Tomasz Wasilczyk
aab4105ef6 Drop const assignment operator.
Also, silence cert-oop54-cpp - self-assignment is already handled in
VectorImpl class.

Bug: 289151149
Test: it builds
Change-Id: I8be7714ed53d1515df7cfdf6de6f3c90b3e5cc76
2023-06-28 11:21:47 -07:00
Fabien Sanglard
2aba0a2283 Fix LruCache, allow std:string caching
The default initalization for mNullValue uses 0 which is in the case of
a std::string TValue will invoke the contructor with undefined behavior
parameter.

Using an empty uniform initialization {} addresses the problem.

Test: Already tested in lrucache_test.cpp
Bug: 257127748
Change-Id: I37420ce8a16c99f3014538a0208d7e113870b1c7
2023-06-15 00:37:52 +00:00
Hao Chen
b3e1993ee5 Add the Missing Header
`stderror` is used in this file and it is defined in `string.h/cstring`, so
the header file needs to be directly included.

Test: build
Bug: 285204695
Change-Id: Idf34126626ad0e9bb397df3d5da50439bf18381d
2023-06-05 13:49:17 -07:00
Hans Boehm
3e8ad4d546 Halve iteration count for some RefBase tests
The RacingDestructors test was occasionally timing out, by non-huge
amounts. Halve the number of iterations for long-running tests here.

Bug: 284964396
Test: Treehugger
Change-Id: If639ce98fbeb783431f07006dece4cd69f9f8b50
2023-05-31 10:19:54 -07:00
zijunzhao
6634c1741e Fix the missing std
Bug: b/239662094
Test: enable Wunqualified-std-cast-call locally and run m to build
Change-Id: I203af8dbbbf1d889b9fc5efd5b62fa165ee09dc2
2023-03-01 23:30:29 +00:00
Zhi Dou
ff9e640e43 Replace "apex_inherit" min_sdk_version
Replace "apex_inherit" min_sdk_version to a conditional setting. If
environment veriable KEEP_APEX_INHERIT is set, using "apex_inherit" as
the min_sdk_version, otherwise set the number to "29". For more detail
please refer
https://docs.google.com/document/d/1R2vZw0cQa-haAMgFyQ682uSq9aGBNQrzMHKIsU17-XY/edit?usp=sharing&resourcekey=0-gUbs463r9LCKs7vdP_Xkmg

Test: build APEX uses this library, and presubmit
Bug: 254634795
Change-Id: If7acfce5fb2e1cb1cc7208a8c57b1e1cd1499c11
Merged-In: Ie6984128e6b84ba73de3f4c08eca5560657c5ca2
2022-12-20 16:05:54 +00:00
Hsin-Yi Chen
20d45cc9ce Merge "Add an ABI dump directory for libutils" 2022-12-09 01:57:43 +00:00
Hsin-Yi Chen
3de02bd0d5 Add an ABI dump directory for libutils
The ABI dumps add visibility for API changes in a commonly used library.

Test: development/vndk/tools/header-checker/utils/create_reference_dumps.py \
      -libs libutils -products aosp_arm64 \
      -ref-dump-dir system/core/libutils/abi-dumps
Test: m libutils.vendor
Bug: 227282691
Change-Id: I498c62853562a8fc6702bdd622603b6f7d516274
2022-12-08 11:06:22 +08:00
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