Commit graph

543 commits

Author SHA1 Message Date
Xin Li
b091f4d40b DO NOT MERGE - Merge QQ1A.200105.003 into stage-aosp-master
Change-Id: I307003cb8d6311ed3662535a54ac8586b8a25bd0
2020-01-02 13:29:54 -08:00
Steven Moreland
243f57bb82 libutils: sp/wp: undef #defines
Seems these undefs are slightly out of sync/out of date.

Bug: N/A
Test: libutils_test
Change-Id: I884ae1ca97754a6459a2c7844264f513eecddaba
2019-12-19 16:17:33 -08:00
Steven Moreland
1e8e49cc2c statusToString: parenthesize strerror
For clarity, when printint w/o delination, noticed in b/145776393.

Test: view output of statusToString from a dumpsys change
Change-Id: I5ea9f052c223f167dd58923e2470c852907c97b8
2019-12-10 18:43:53 +00:00
Hans Boehm
5341172587 Add check to sp<> raw pointer constructor
For the raw pointer constructor, check that the argument is not on the
stack. Passing a stack pointer as an sp<> parameter is dangerous,
since we will attempt to deallocate the object once the sp<> is no
longer needed. We approximate ste stack ccheck by testing whether it
is on the same page as the frame pointer.

Do the same for raw pointer assignment.

Bug: 138956784
Test: Boot AOSP
Change-Id: I2c2405be443389af7e6a713aadcb3ee1f372a85e
2019-11-26 15:32:40 -08:00
Steven Moreland
591cab8cee Add statusToString function.
For libbinder, not having these statuses printed out causes never ending
problems for developers.

Bug: 144534032
Test: libhidl_test tests this, which is on TH here
Change-Id: I02f37fb1e5b743131598ddc95ef89ebdfbdff615
2019-11-18 17:38:22 +00:00
Steven Moreland
b5d3e902ff FlattenableUtils::align memsets
Bug: 141890807
Test: boot, check data is zero'd
Change-Id: I45aaeac369f4c5cf3eb44f61c233e00f870a5c79
(cherry picked from commit bf824f8fa5)
(cherry picked from commit e62a9d7669)
2019-11-15 06:15:49 +00:00
Steven Moreland
5f46923634 Trace.h: explicitly use global namespace
Imagine an AIDL file:
  package android.foo;
  interface IFoo {}

The AIDL C++ backend will generate classes like "::android::foo::IFoo".
In order to avoid ODR conflict, the NDK (Stable C) backend linking
against libbinder_ndk puts everything under the "::aidl" namespace. So,
we have "::aidl::android::foo::IFoo". When using ScopedTrace in a class
implementing a class from this backend, there is this problem.

Bug: 141828236
Test: works
Change-Id: Iafadea11788d4c011229657b4f53063bcf65f8d8
2019-11-05 17:59:46 -08:00
Steven Moreland
ae9749a29a libutils: flattenable deprecation comment
This class isn't used very much and it isn't supported by AIDL. In order
to recommend new users against this and recommend an alternative, added
a comment here.

Bug: 142282873
Test: N/A

Change-Id: If7c6c9fac6c868ed6a515e658de752092d25d5f9
2019-10-07 18:14:14 -07:00
Vic Yang
5a141424e6 Fix memory leak in String16
Newly allocated SharedBuffer already has reference count 1, so we
should not call acquire().

Bug: 141764153
Test: Run String16Test.* with ASan that was able to detect the leak
      without this change.
Change-Id: Ib8b1b707b028386d717414d8c5ec5ea7b4b59464
2019-09-27 21:07:00 -07:00
Steven Moreland
1cb99ea59b libutils: Trace.h for everything but windows
libcutils has trace implemented for host. In order to increase code
portability, opening that up for libutils Trace.h usage as well.

Bug: 124524556
Test: use Trace.h on host glinux
Change-Id: Ia873f88e7436a18f6c0f761000bf697c68ffea17
2019-09-20 11:28:00 -07:00
Brett Chabot
1af6acc4d3 Use Android systemTime implementation for host linux.
The Android framework, notably android.view.Choreographer, assumes
that System.nanoTime and SystemClock.uptimeMills return consistent
values. This was true on device, but not on host.

This commit makes those values consistent on host linux. The necessary
support should be in place in kernels 2.6.39 and newer, which have been
available since 2012.

Test: m -j libutils
Change-Id: I833a89a810ae9fb3e8c01f6095ee2aca893c284f
2019-09-19 15:32:33 -07:00
Elliott Hughes
c21c0ac740 Merge "Remove unused big-endian cruft." 2019-09-19 21:26:11 +00:00
Steven Moreland
c1e04d8ac5 libutils: increase test TIMING_TOLERANCE_MS
25 -> 100, because we are seeing larger values sometimes on cuttlefish.

Fixes: 141212746
Test: libutils_test
Change-Id: I371416473b97f46891104ff9d893ec38c25728aa
2019-09-18 20:35:49 +00:00
Elliott Hughes
b6e7de2221 Remove unused big-endian cruft.
Test: builds
Change-Id: I19fef65d311923e4e6dac7307914f5fbb92b7bde
2019-09-18 08:02:10 -07:00
Treehugger Robot
f613b4a9a6 Merge "Reland "libutils: Introduce StaticString16""" 2019-09-06 02:29:23 +00:00
Vic Yang
9fb93edd5b Reland "libutils: Introduce StaticString16""
This reverts commit 1270e4fbf1.

Bug: 138856262
Test: Run unit tests.
Change-Id: I37be01d7d4f98a83078870cb0917275336fa2bbd
Merged-In: I8da93f2c9b95183e32d4a2ea895f90c449abbe4d
2019-09-05 13:19:14 -07:00
Steven Moreland
c732c03482 compare android::Vector and std::vector
Have been wondering for a while.

Test: libutils_benchmark
--------------------------------------------------------------------
Benchmark                          Time             CPU   Iterations
--------------------------------------------------------------------
BM_fill_android_vector          24.6 ns         24.5 ns     28207074
BM_fill_std_vector              5.24 ns         5.21 ns    130675479
BM_prepend_android_vector       5783 ns         5770 ns       100000
BM_prepend_std_vector           5731 ns         5717 ns       100000

Change-Id: Ie296ce2c4395121b6a456d57421f820909418afe
2019-09-03 18:11:43 -07:00
Kevin Han
1270e4fbf1 Revert "Reland "libutils: Introduce StaticString16"""
This reverts commit c55ac92bd6.

Reason for revert: Breaks down-stream branches. See b/140315617

Change-Id: I4937fdf4bdcc7a44d5f10700ecf2d5e96aef7d27
Merged-In: I8da93f2c9b95183e32d4a2ea895f90c449abbe4d
2019-08-30 23:50:38 +00:00
Vic Yang
c55ac92bd6 Reland "libutils: Introduce StaticString16""
This time with old branches excluded.

Bug: 138856262
Test: Run unit tests.
Change-Id: Id0bb1d54b71e38244d64f1b684db1fda81de854c
Merged-In: I8da93f2c9b95183e32d4a2ea895f90c449abbe4d
2019-08-30 11:01:27 -07:00
Vic Yang
86eaa8de78 Revert "libutils: Introduce StaticString16"
This reverts commit d4cb489434.

Reason for revert: Breaking aosp_bonito-userdebug

Change-Id: Iea72f39d40f476002ce0ad6b5ce3b4e1ca570de7
2019-08-29 22:47:07 +00:00
Vic Yang
d4cb489434 libutils: Introduce StaticString16
This is a backward compatible implementation of compile time
constructed String16 support.

As much as we'd like a regular constexpr constructor for String16, we
want to make sure the regular non-static String16 does not regress.
We also need to make sure prebuilts built with previous version of
String16 still works with new libutils.  This means we cannot change
the size of String16 objects and we cannot make anything virtual.

To add a flag to indicate whether a String16 is static without
increasing the size of non-static String16 objects, we repurpose a
reserved field in SharedBuffer as "for client use".  With this, we can
tag every String16 and perform memory operation differently based on
how the underlying buffers are allocated.

By using StaticString16, we are able to eliminate the runtime
construction of a String16 and move it out of .bss section.

Bug: 138856262
Test: Run newly added unit tests.
Change-Id: I72bb8dc27a59b9ef34e0d934bc1e00b0f675855a
2019-08-09 11:01:37 -07:00
Treehugger Robot
d7546f1d57 Merge "Remove two more unused utf32 functions." 2019-08-02 19:29:45 +00:00
Steven Moreland
18daa7b5f0 libutils: RefBase remove 'basetype' typedefs
useless/unused

Bug: N/A
Test: N/A
Change-Id: I72462a64411a58d22e071f20e2c950bd99fdffb1
2019-07-16 21:06:28 +00:00
Elliott Hughes
9658fc0823 Remove two more unused utf32 functions.
Test: builds
Change-Id: I6ab2104fc6836e9edb772e8368199e6171e9d87a
2019-07-16 07:56:23 -07:00
Steven Moreland
c0927e64b1 libutils: remove references to unimplemented func
printWeakPointer isn't implemented anywhere. This also allows us to
remove a forward declaration of TextOutput.

Bug: N/A
Test: N/A
Change-Id: Ie2debdfda17b7cc1d599c431eaf4c362a591e482
2019-07-11 17:50:52 -07:00
Steven Moreland
0e19f3b4cc Remove utf32 functions.
These don't appear to be used by anything.

Bug: N/A
Test: binary inspection + code inspection
Change-Id: I6c12db26c320a66bcf6e28618c6e9f61b40d985e
2019-07-02 18:15:03 -07:00
dimitry
454ba7ec88 Enable native_bridge_support for libutils
Android build system added support for building translated binaries
used on natively bridged targets (arm on x86 for example).

However in order to avoid building unnecessary binaries and libraries
for such architectures most modules do not support native bridge by default.

All needed modules have to explicitly indicate if they may be used as part
of translated binary build.

This change enabled native bridge support for libutils which is a
greylisted library (available for apps targeting Android version < N).

Bug: http://b/77159578
Test: make
Change-Id: I58667558d2a673fc0d882cf623b7a1b6f6f305ec
2019-05-16 13:48:17 +02:00
Alessio Balsini
1406207e67 Looper: missing cinttypes when debugging poll/callbacks
When enabling DEBUG_POLL_AND_WAKE or DEBUG_CALLBACKS, compiler complains
for the undefined PRI* fprintf format constants.
Fix by including the missing cinttypes.

Test: m
Bug: none
Change-Id: I0a7b5b45bd274eefa9644cba491a8dc28f1992ff
2019-05-11 20:53:47 +01:00
Treehugger Robot
ee4cc04429 Merge "libutils: more detailed logging." 2019-04-02 02:45:41 +00:00
Steven Moreland
d33a2ee172 libutilscallstack: removed from darwin
libbacktrace only includes its Backtrace.cpp on the linux targets
but not windows or darwin targets. So, both should be disabled.

Previously, libutilscallstack was only ever a static library on
these platforms. Since nothing provided the symbols, these targets
couldn't have been used.

Fixes: 129636352
Test: m

Change-Id: I3f0b09e1d67c485b3ea57f58d1220d9516b326f2
2019-04-01 15:16:13 -07:00
Elliott Hughes
fd12160087 libutils: more detailed logging.
The question arose on the bug of whether this is a legit errno or just
a stale value.

Bug: http://b/129139241
Test: ran tests
Change-Id: I486176496028f04d4fcccdd0b29a3df6b13849c9
2019-04-01 12:24:19 -07:00
Steven Moreland
43f29072a9 Merge "libutils/libcutils: make host more like device" 2019-03-29 23:05:20 +00:00
Mikhail Naganov
e1a285ddc1 libutils: Fix thread safety annotations in Mutex
The annotations for Mutex::tryLock and timedLock were
incorrectly specifying the return value for the successful
acquisition.

Test: make libutils_test
Change-Id: I9729b6555ede5cb1d6db046e33c35bf5926c7755
2019-03-29 12:21:57 -07:00
Steven Moreland
e6132be529 libutils/libcutils: make host more like device
Having shared host libraries allows libraries depending on these to use
'shared_libs' for these. This simplifies configurations since these
libraries don't have to specify 'shared_libs' on all non-host targets.

Bug: 124524556
Test: build only

Change-Id: I09fb4a4fb66ea0a87cb76b1e6f400c537a11f082
2019-03-28 18:44:32 -07:00
Hans Boehm
6e75ad6e13 Revert "Revert "Fix wp and sp comparison bugs""
Fix wp and sp comparison bugs

Make clear() actually clear wp m_refs, so that nulls compare equal.

Make equality consistent with < and >, ensuring that a weak pointer
cannot be both equal to and greater than another.

Don't rely on the built-in < and > operators to correctly order
different objects. The standard does not guarantee that, and there is
a risk of compiler relying on that lack of guarantee.

Remove unnecessary comparison overloads, especially those
comparing a wp<> to an sp<>.

Change the remaining wp<> to sp<> comparisons to check for equivalence
of the mRefs pointer instead of the object address, thus eliminating
the dubious equal comparison result for a dead wp<> and an sp<> that
happen to point to the same object address.

Add comparison tests.

This reverts commit a2a2ad8057.

The original code, and my original CL, both failed to initialize m_refs
in various wp<> constructors. This now became more important, since
comparisons now rely more on m_refs. However I believe it was always
a bug, since some comparisons always relied on m_refs.

Test: Treehugger, boot AOSP, atest RefBase
Bug: 126922090
This reverts commit a2a2ad8057.

Reason for revert: Reapply after constructor fixes.

Change-Id: I2c8917416a2306e36d2b6bb7b397f653020e5688
2019-03-13 13:26:35 -07:00
Hans Boehm
a2a2ad8057 Revert "Fix wp and sp comparison bugs"
This reverts commit 029b12ebde.

Reason for revert: There appear to be problems with null comparisons. Reported failure in HwcBufferCacheTest.

Change-Id: I19745bb281dabe8b05c2df3fe95e7be7a49dcd51
2019-03-13 03:24:12 +00:00
Hans Boehm
029b12ebde Fix wp and sp comparison bugs
Make clear() actually clear wp m_refs, so that nulls compare equal.

Make equality consistent with < and >, ensuring that a weak pointer
cannot be both equal to and greater than another.

Don't rely on the built-in < and > operators to correctly order
different objects. The standard does not guarantee that, and there is
a risk of compiler relying on that lack of guarantee.

Remove unnecessary comparison overloads, especially those
comparing a wp<> to an sp<>.

Change the remaining wp<> to sp<> comparisons to check for equivalence
of the mRefs pointer instead of the object address, thus eliminating
the dubious equal comparison result for a dead wp<> and an sp<> that
happen to point to the same object address.

Add comparison tests.

Test: Treehugger, boot AOSP, atest RefBase
Bug: 126922090
Change-Id: I15911150e0fc85ace2c4b77d337826e12793c690
2019-03-09 21:41:37 -08:00
Elliott Hughes
cb65c354a0 Add test_suites to libutils_test.
Also move the singleton test out because our infrastructure can't cope
with tests that have their own test libraries.

Bug: http://b/124838889
Test: atest
Change-Id: Iddce3325a56d44a4288ace2a29921a3e02367413
2019-02-25 12:26:00 -08:00
Elliott Hughes
01705e4f1d Clean up libcutils/libutils tests.
Move tests in the same directory as the corresponding code, so it's
easier to see what is/isn't tested.

Fix naming of libcutils_tests (plural) to match the singular that's more
common (even though the plural makes more sense to me).

Add these two to system/core/'s TEST_MAPPING.

Remove obsolete AndroidTest.xml.

Fix a flaky (timing-dependent) libcutils test.

Test: ran tests
Change-Id: I7e0a31ff45c8a152562bf66fc97161594249366e
2019-02-11 13:15:56 -08:00
Elliott Hughes
eb0ef145fd MappedFile and FileMap should support zero-length mappings.
Bug: http://b/119818070 "app crashes when reading asset of zero length"
Test: ran tests
Change-Id: Idd2ad6f6e72c8e445aff78a460fac96dea41c950
2019-02-06 14:29:35 -08:00
Suren Baghdasaryan
1bcb634958 Merge changes from topic "re-revert move sched_policy functions"
* changes:
  DO NOT MERGE: Revert "Revert "Add dependencies on libprocessgroup for sched_policy users""
  DO NOT MERGE: Revert "Revert "libcutils: Move sched_policy functions into libprocessgroup""
  DO NOT MERGE: Revert "Revert "Add libprocessgroup into VNDK""
2019-01-25 17:09:02 +00:00
Elliott Hughes
cdd0aaa3ae Merge "Remove dead code." 2019-01-25 17:01:27 +00:00
Suren Baghdasaryan
9491078300 DO NOT MERGE: Revert "Revert "Add dependencies on libprocessgroup for sched_policy users""
This reverts commit 1bef8c550c.

Reason for revert: AOSP is fixed with new vendor image

Change-Id: Ib341ac80e2f88c13a7815a490ea2d9422ebdf55f
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-25 16:49:18 +00:00
Elliott Hughes
d2962c8a15 Remove dead code.
If this was strlcpy16 it wouldn't be such a bad idea, but strncpy16 is
just an accident waiting to happen...

Test: N/A
Change-Id: Id296fdeadfb9f1f70ddc8fb6d31b3b6b5178a12c
2019-01-24 13:07:18 -08:00
Suren Baghdasaryan
1bef8c550c DO NOT MERGE: Revert "Add dependencies on libprocessgroup for sched_policy users"
This reverts commit 02843339f9.

Reason for revert: Broke AOSP

Change-Id: I62f91c0adf440b5da0a145862b04dd27a7016faf
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-23 20:43:28 -08:00
Suren Baghdasaryan
02843339f9 Add dependencies on libprocessgroup for sched_policy users
After moving sched_policy functions into libprocessgroup its users require
additional dependency and inclusion of sched_policy_ctrl.h header.

Exempt-From-Owner-Approval: janitorial

Bug: 111307099
Test: builds, boots

Merged-In: Icc052080e1bce46ce06f7264446950cab0490a95
Change-Id: Icc052080e1bce46ce06f7264446950cab0490a95
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
2019-01-22 18:19:45 +00:00
Treehugger Robot
d0dec304c5 Merge "libutils: use libbase_headers instead of libbase." 2019-01-08 06:42:22 +00:00
Steven Moreland
8338072591 CallStack: include prefix/tag when unlinked
Bug: N/A
Test: manual
Change-Id: I8f7a19744af938a02d876ab81c1dafee04744f96
2019-01-03 10:17:07 -08:00
Josh Gao
f0ea1e6e5d libutils: use libbase_headers instead of libbase.
Bug: http://b/121391019
Test: treehugger
Change-Id: I0e5d218b9afe6f832cc6bd0ef78bc1a5581f3e2f
2019-01-02 14:31:26 -08:00
Nick Kralevich
0a8b4d1a8b use epoll_create1
epoll_create leaks file descriptors. Use epoll_create1(EPOLL_CLOEXEC)
instead.

Bug: 120983106
Test: compiles and boots
Change-Id: I7c135ee22aee61cc7895486fda904b1790c093d1
2018-12-17 09:39:24 -08:00