Commit graph

920 commits

Author SHA1 Message Date
Tomasz Wasilczyk
b6f459abbc Allow disabling callstack
Bug: 302723053
Test: mma
Change-Id: Idea326cc9914d4c81d75dad287e169c09a736486
2023-10-27 10:48:43 -07:00
Steven Moreland
c738370273 libutils_binder: isolate headers
This isolated all libutils_binder headers from libutils
except for RefBase use of CallStack.h. This header can
be disabled with a macro option easily.

Bug: N/A
Test: N/A
Change-Id: I83af091fc17b5418ab9e4d7fc41fb43792ec547d
2023-10-24 23:45:01 +00:00
Steven Moreland
7a1ca59839 libutils: split out libutils_binder
Dependencies of libbinder, so we can build
a core libbinder library, libbinder_sdk.

This is preparing the way to move this part of libbinder
together with binder code into a single project.

Bug: 302720583
Change-Id: Icff078ac6e36c7f2b91cf815d5b9ed19b2e706e1
2023-10-09 21:56:15 +00:00
Steven Moreland
0666c3a632 libutils: remove unused 'CALLSTACKS'
This macro is set, but it doesn't exist.

Bug: 302720583
Test: build
Change-Id: I88032c24b8bc8dc52d521e769149cbd8f619dde8
2023-10-07 00:35:38 +00:00
Steven Moreland
066e625b6b libutils: use log/log.h internally
utils/Log.h is one less file we need if we're
splitting up this library for binder.

Bug: 302720583
Test: build
Change-Id: Ibc7ec5402df342627f465354d7cf59e98f450a31
2023-10-07 00:29:44 +00:00
Tomasz Wasilczyk
8c9c7d076f Merge "Revert "Revert "Lock down String8|16.string() usage""" into main 2023-09-27 15:06:23 +00:00
Ryan Prichard
532a608f58 Merge changes I7790dde8,I065907a5,Id2e82024 into main
* changes:
  Add missing <assert.h> include
  Add missing <functional> and <vector> includes
  snapuserd_test: don't discard result of std::async
2023-09-22 19:42:45 +00:00
Ryan Prichard
999efbef09 Add missing <functional> and <vector> includes
Bug: 175635923
Test: m MODULES-IN-system-core-libutils
Change-Id: I065907a58a88723ae512f155dfde2d2fcb3fc322
2023-09-21 17:52:29 -07:00
Tomasz Wasilczyk
2b1a0599c4 Don't depend on String8 cast to C string
Bug: 295394788
Test: m checkbuild
Change-Id: I5b86ae56250d409a23ab3f2bc72b725bcf6ab23e
2023-09-20 15:11:54 +00:00
Tomasz Wasilczyk
010c37b615 Revert "Revert "Lock down String8|16.string() usage""
This reverts commit 7210b285c2.

Reason for revert: attempt re-submit

Change-Id: Ia95d11628c512163ae3d13cbdd5ebbe60f435937
2023-09-15 22:22:14 +00:00
Devika Krishnadas
7210b285c2 Revert "Lock down String8|16.string() usage"
This reverts commit 8b95a12489.

Reason for revert: DroidMonitor: Test failure

Change-Id: I09230ea7c3b80e1b4d277d3c6c6355a38f7bbc92
2023-09-15 18:46:03 +00:00
Tomasz Wasilczyk
8b95a12489 Lock down String8|16.string() usage
All users should migrate to .c_str()

Bug: 295394788
Test: make checkbuild
Change-Id: Ic6295848cf3377e0bf5334448d5ed7ea53fae7ae
2023-09-14 18:37:52 +00:00
Tomasz Wasilczyk
358a982b71 Merge "Lock down String8.isEmpty() usage" into main 2023-09-14 16:18:49 +00:00
Tomasz Wasilczyk
8b5c8477f9 Lock down String8.isEmpty() usage
All users should migrate to .empty()

Bug: 295394788
Test: make checkbuild
Change-Id: I5ec7921b9cf70e6b0857e1087f141dce958d2587
2023-09-14 15:04:00 +00:00
Tomasz Wasilczyk
771bda6c0b Merge "Implement android::String access methods that avoid C string cast" into main 2023-09-12 20:43:20 +00:00
Tomasz Wasilczyk
86c9ea8f86 Implement android::String access methods that avoid C string cast
Bug: 295394788
Test: m checkbuild
Change-Id: If25fd69319171e8c549fc8fcfd95a0819291d8e6
2023-09-12 17:25:29 +00:00
Tomasz Wasilczyk
8245afd47d Merge "Revert "Revert "Revert "Revert "Drop all path-related methods from android::String8""""" into main 2023-09-12 14:02:13 +00:00
Tomasz Wasilczyk
a1853516ff Revert "Revert "Revert "Revert "Drop all path-related methods from android::String8""""
This reverts commit 141255f30c.

Reason for revert: Attempt re-submit again

Change-Id: I0e568fdf8f7a141ee3c5d54f68530ff478a47439
2023-09-11 17:45:16 +00:00
Rhed Jao
d395f638fa Merge "Revert "Revert "Revert "Drop all path-related methods from android::String8"""" into main 2023-09-11 03:43:31 +00:00
Rhed Jao
141255f30c Revert "Revert "Revert "Drop all path-related methods from android::String8"""
This reverts commit 4b6a7c3940.

Reason for revert: b/299695302, b/299694769

Change-Id: I89c6719d23446f2f9ce24e5b75d321538b580431
2023-09-11 02:05:58 +00:00
Tomasz Wasilczyk
b2b037d9f0 Merge "Revert "Revert "Drop all path-related methods from android::String8""" into main 2023-09-08 19:59:48 +00:00
Tomasz Wasilczyk
9cbae9d75b Merge "Drop String8::std_string" into main 2023-09-08 18:17:25 +00:00
Tomasz Wasilczyk
4b6a7c3940 Revert "Revert "Drop all path-related methods from android::String8""
This reverts commit cff2e40d19.

Reason for revert: Attempt re-submit

Change-Id: I8802b519e4ae3046858b854815ba580c7a6b965d
2023-09-08 11:03:59 -07:00
Tomasz Wasilczyk
cff2e40d19 Revert "Drop all path-related methods from android::String8"
This reverts commit b9dc1c2991.

Reason for revert: http://b/299624573

Change-Id: I0d5993295df65ec31c180b6b5a76fbe939891f45
2023-09-08 17:08:39 +00:00
Tomasz Wasilczyk
adaf33026a Drop String8::std_string
This method was preserved under assumption it would be baked into many
prebuilts, but since it's inline, there should be no linkage to libutils
- thus, should be safe to remove anyway.

Bug: 35363681
Bug: 295394788
Test: treehugger
Change-Id: I59964935600e9e786424136177bfc8a70bebec67
2023-09-08 09:51:24 -07:00
Tomasz Wasilczyk
b9dc1c2991 Drop all path-related methods from android::String8
Move them to androidfw and aapt, the last users.

Bug: 295394788
Test: m checkbuild
Change-Id: I7268b88d11bf221f93efed06cfd1ee65449a2421
2023-09-08 03:07:52 +00:00
Hsin-Yi Chen
e474f21a45 Check the ABI of libutils for vendor and product only
It is not necessary to compare the dumps with the library installed in
system partition.

Test: m out/target/product/generic_x86_64/lsdump_paths.txt
Bug: 280008249
Change-Id: I8fc39ad17d37cd43bf1d77ba23dde55d05dadce1
2023-09-04 03:38:15 +00:00
Treehugger Robot
18560efc30 Merge "Migrate from android::String isEmpty to empty" into main 2023-08-25 17:07:42 +00:00
Tomasz Wasilczyk
9578c774a9 Merge "Implement String8|16::empty and String16::length" into main 2023-08-24 18:31:56 +00:00
Tomasz Wasilczyk
92ad0d32c0 Merge "Lose convertToResPath to aapt." into main 2023-08-24 16:46:49 +00:00
Elliott Hughes
1d98fe0d39 Lose convertToResPath to aapt.
aapt (not aapt2) is the only user.

Test: treehugger
Change-Id: Ie69f84f4f805c69f838e345b44755a316b9f9b06
2023-08-24 04:33:05 +00:00
Tomasz Wasilczyk
f597129282 Migrate from android::String isEmpty to empty
This empty method is different from the old one - it aligns with
std::string definition.

Bug: 295394788
Test: make checkbuild
Change-Id: Id6baed8cde01a75a8839ad6b4475a31ba1f49c8a
2023-08-18 22:07:28 +00:00
Tomasz Wasilczyk
2676893dd8 Implement String8|16::empty and String16::length
This time following std::string::empty meaning.

String16::length is for parity with String8::length and to
follow std::string::length/size duo.

Bug: 295394788
Test: mma
Change-Id: I43df2cbb9ca6f980a4cf6d971064d594d661f884
2023-08-18 22:07:28 +00:00
Tomasz Wasilczyk
6d1b644930 Drop String::empty()
This method causes confuction and bugs by having the same name, but
different meaning versus std::string::empty().

Bug: 295394788
Test: make checkbuild
Change-Id: I15aadc023b20559930e4ec79f43f7032e8cd90d0
2023-08-18 22:07:28 +00:00
Tomasz Wasilczyk
18b746188c Migrate String8/16 from .string() to c_str()
This will align usage with std::string.

Bug: 295394788
Test: make checkbuild
Change-Id: Ic5c215b011197950dcbcb0339f44cc68fefc65a1
2023-08-11 19:53:20 +00:00
Tomasz Wasilczyk
90af4157c5 Add String16::c_str and start using it.
This is for parity with String8::c_str and in general the first step
in transition from String8|16.string() - to make it more similar to
std::string.

Bug: 295394788
Test: mma -j
Change-Id: I6c1411bef07c761fb2fb3fb38c27801ac4cffc57
2023-08-11 19:40:34 +00:00
Eric Miao
4a33c22c77 Merge "String8: fix infinite loop and segmentation fault in removeAll()" into main 2023-07-19 02:03:40 +00:00
Eric Miao
c6ce48ef19 String8: fix infinite loop and segmentation fault in removeAll()
Bug: 290835996
Test: libutils_fuzz_string8 for several minutes

String8::removeAll() has 2 serious problems:

1. When `other` is an empty string, `removeAll()` will loop infinitely
   due to below process:

   a) with `other` being empty string `""`, find() will call strstr()
      on an empty string, which always returns `mString`, and thus
      find() always return 0 in this case
   b) with find() returns 0 for empty string, the next while loop in
      String8::removeAll() will keep loop infinitely as `index` will
      always be 0

   This CL fixes this problem by returning true if `other` is an empty
   string (i.e. `strlen(other) == 0`), this follows the logic that an
   empty string will always be found and no actual remove needs to be
   done.

2. When `other` is a NULL string, strstr() has undefined behavior. See
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf.

   This undefined behavior on Android unfortunately causes immediate
   segmentation fault as the current `strstr` implementation in bionic
   libc doesn't check `needle` being NULL, and an access to a NULL
   location is performed to check if the `needle` string is an empty
   string, and thus causes segmentation fault.

   This CL gives an error message and aborts instead of having a
   segfault, and to keep some backward compatibility.

   This CL also adds test for String8::removeAll()

Change-Id: Ie2ccee6767efe0fed476db4ec6072717198279e9
2023-07-18 16:02:07 -07:00
Treehugger Robot
435b520bf0 Merge "Fix libutils_fuzz_string8 deadlock." into main 2023-07-18 21:49:06 +00:00
Steven Moreland
749becfa68 Fix libutils_fuzz_string8 deadlock.
Bug: 290835996
Test: libutils_fuzz_string8 for several minutes
Change-Id: I9b312dd968c380f4fa2a837d38121d0a7a7ac7b1
2023-07-18 21:04:07 +00:00
Eric Miao
cb199b4795 libutils: Improve performance of utf8_to_utf16/utf16_to_utf8
This CL improves the performance of below functions in helping with conversion
between utf8/utf16 with libutils:

  - utf8_to_utf16_length
  - utf8_to_utf16
  - utf16_to_utf8_length
  - utf16_to_utf

The basic idea is to keep the loop as tight as possible for the most
common cases, e.g. in UTF16-->UTF8 case, the most common case is
when the character is < 0x80 (ASCII), next is when it's < 0x0800 (
most Latin), and so on.

This version of implementation reduces the number of instructions
needed for every incoming utf-8 bytes in the original implementation
where:

  1) calculating how many bytes needed given a leading UTF-8 byte
     in utf8_codepoint_len(), it's a very clever way but involves
     multiple instructions to calculate regardless

  2) and an intermediate conversion to utf32, and then to utf16
     utf8_to_utf32_codepoint()

The end result is about ~1.5x throughput improvement.

Benchmark results on redfin (64bit) before the change:

utf8_to_utf16_length: bytes_per_second=307.556M/s
utf8_to_utf16:        bytes_per_second=246.664M/s
utf16_to_utf8_length: bytes_per_second=482.241M/s
utf16_to_utf8:        bytes_per_second=351.376M/s

After the change:

utf8_to_utf16_length: bytes_per_second=544.022M/s
utf8_to_utf16:        bytes_per_second=471.135M/s
utf16_to_utf8_length: bytes_per_second=685.381M/s
utf16_to_utf8:        bytes_per_second=580.004M/s

Ideas for future improvement could include alignment handling and loop
unrolling to increase throughput more.

This CL also fixes issues below:

  1. utf16_to_utf8_length() should return 0 when the source string has
     length of 0, the original code returns -1 as below:

    ssize_t utf16_to_utf8_length(const char16_t *src, size_t src_len)
    {
        if (src == nullptr || src_len == 0) {
            return -1;
        }
	...

  2. utf8_to_utf16() should check whether input string is valid.

Change-Id: I546138a7a8050681a524eabce9864219fc44f48e
2023-07-12 13:23:07 -07:00
Treehugger Robot
f5d4edaa31 Merge "libutils: rewrite Vector fuzzer" 2023-07-01 01:28:13 +00:00
Steven Moreland
379d5c83d5 libutils: rewrite Vector fuzzer
It could never have gotten much coverage.

Bug: 288741501
Test: libutils_fuzz_vector (2,000,000 iterations)
                           (~60k-100k iterations/s)
Change-Id: I6f442642b5a3246dd08784f735db5aad5fd4d398
2023-07-01 00:28:48 +00:00
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