Commit graph

293 commits

Author SHA1 Message Date
Elliott Hughes
98c76496be libbase: assume clang.
Bug: N/A
Test: builds
Change-Id: Ic3d3bee26496025324a3d070e3fcbf6d7b917709
2018-07-02 10:53:22 -07:00
Inseob Kim
ad9f6b12e2 Fix misleading comments
Bug: N/A
Test: N/A
Change-Id: I714a0f523eb803cb619acaddff4f769622cfc8b6
2018-06-29 18:09:55 +09:00
Elliott Hughes
4d8bbc6f8b libbase: switch to #pragma once.
Bug: N/A
Test: builds
Change-Id: I125498ac4257ac4e901c6f2a5f1bfac1432d859d
2018-06-26 17:17:41 -07:00
Elliott Hughes
d8a4c60276 Simplify __attribute__((__printf__)) use.
We don't need this now everyone's using clang...

Bug: http://b/69933068
Test: ran tests
Change-Id: I88f0cf03981ade47e210387fd6f3a2706dfeb9b8
2018-06-26 13:07:21 -07:00
Pirama Arumuga Nainar
a2df1ef441 Do not customize __format__ for Windows/MinGW to gnu_printf
Bug: http://b/69933090
Bug: http://b/69933068

MinGW uses gnu_printf to force C99 printf analysis with GCC, but clang
does not support gnu_printf.  So just use the default that's used for
other platforms.  This also mirrors upstream commit
015e637b4b/.

Test: m native-host-cross with Clang.
Change-Id: I3deb266d70e25296c4ae1d58637afbabc3d949c1
2018-06-25 11:52:54 -07:00
Pirama Arumuga Nainar
8e52362e45 Adapt to switch to Clang for Windows host builds
Bug: http://b/69933068

Bug: http://b/91353691: std::chrono_utils is not available in the
libstdc++ in the mingw/gcc prebuilts.  They can be used once we switch
to using libc++ for Windows host.

Test: m native-host-cross with Clang
Change-Id: If9f0f1f201d5e4e445890075ad64c2d6086b0491
2018-06-25 11:47:52 -07:00
Elliott Hughes
11a64eb0e8 libbase: fix libbase_test.logging.StdioLogger.
I don't think the StdioLogger test ever passed. Move GetFileBasename
to where we can use it from StdioLogger, and undo the mix of anonymous
namespace vs static to consistently use static (which is the majority)
while we're touching those lines.

Bug: N/A
Test: ran tests
Change-Id: I95b3966cdb8af642bed71752bd7d4e3a86ac84ca
2018-06-06 12:54:41 -07:00
Elliott Hughes
d580c441ab Merge "libbase: add host properties support." 2018-05-29 23:59:50 +00:00
Elliott Hughes
dc80312628 libbase: add host properties support.
Move init and libprocessgroup away from their existing hacks.

Bug: N/A
Test: ran tests
Change-Id: Ifabdd38e0cc4ab2582f1ea59d32159d386f48eb6
2018-05-24 18:04:31 -07:00
Jiyong Park
a0e75045e6 Build adbd for recovery
adbd (and its dependencies) are marked as recovery_available:true so
that recovery version of the binary is built separately from the one for
system partition. This allows us to stop copying the system version to
the recovery partition and also opens up the way to enable shared
libraries in the recovery partition. Then we can also build adbd as a
dynamic executable.

Bug: 79146551
Test: m -j adbd.recovery
Change-Id: Ib95614c7435f9d0afc02a0c7d5ae1a94e439e32a
2018-05-24 14:11:11 +09:00
Elliott Hughes
1be0d1481b Add StdioLogger for command-line tools.
Bug: N/A
Test: ran tests
Change-Id: If366a4ea25aea1becdd3e443eba225e9bd52ebba
2018-05-23 10:06:20 -07:00
Jiyong Park
612210c75b Mark as recovery_available: true
Libraries that are direct or indirect dependencies of modules installed
to recovery partition (e.g. toybox) are marked as recovery_available:
true. This allows a recovery variant of the lib is created when it is
depended by other recovery or recovery_available modules.

Bug: 67916654
Bug: 64960723
Test: m -j
Change-Id: Ie59155c08890e96ce1893fa3687afcf763d7aea3
2018-05-15 09:47:04 +09:00
Elliott Hughes
40fdf3f4ab Add test_suites lines.
Bug: N/A
Test: builds
Change-Id: Ic5e2b9206bcfcb53c774989013b5db6aab462e42
2018-04-27 16:12:06 -07:00
Elliott Hughes
955b6a4792 Add android::base::ParseByteCount.
Bug: N/A
Test: ran tests
Change-Id: Ib2adcf0a5b9494fcf8259b29974303e8516a9ad9
2018-04-19 19:49:16 -07:00
Elliott Hughes
1b86d41c78 Add SIZEOF_MEMBER.
Bug: N/A
Test: ran tests
Change-Id: Icb7e8ae83d242c867b71a990b08eb1a62ed1482c
2018-04-11 12:29:50 -07:00
Mark Salyzyn
2507a048ab base: kernel logging get pre-opened /dev/kmsg from environment
If the environment has an instance of /dev/kmsg pre-opened, pick up.
This happens when an init script has 'file w /dev/kmsg' in the
daemon's recipe.

libcutils android_get_control_file operations are open-coded to
prevent a dependency on libcutils itself.  Also check that /dev/kmsg
file descriptor is valid and open'd for write only.

Test: check to make sure init() kernel logging still works
Bug: 77541952
Bug: 77661605
Change-Id: I007553acd594ef0815d23f32f8aa2867518570ba
2018-04-09 07:19:33 -07:00
Treehugger Robot
3b279aa5c7 Merge "Allow android::base::ScopeGuard in STL containers" 2018-03-26 23:05:25 +00:00
Luis Hector Chavez
b77035b89a Allow android::base::ScopeGuard in STL containers
This change lets android::base::ScopeGuard be useful in STL containers
(e.g. std::vector<android::base::ScopeGuard<std::function<void()>>>). It
also provides perfect forwarding for android::base::make_scope_guard.

Bug: 34764308
Test: libbase_test

Change-Id: I7d1e5494b0f0695763cff0700efdb9ec18ae85c8
2018-03-26 13:30:09 -07:00
Josh Gao
5791e21697 base: export GetThreadId.
and stop using the incorrect (on Mac) version in adb..

Test: mma
Change-Id: If28f6c8d73b03db863be13ed88df81422c3aef87
2018-03-16 15:35:52 -07:00
Yabin Cui
ef58cef982 base: Add TemporaryFile::DoNotRemove().
Bug: http://b/73127105
Test: none.
Change-Id: I563c12bfb629ddd630568dda4817fb10cc9940a8
2018-03-08 17:59:36 -08:00
Andreas Gampe
1923e768ef Base: Add default tag manipulation
Allow the default tag (the program name) to be overwritten.

Bug: 34867873
Test: m
Test: logging_test
Test: manual
Change-Id: I4ef32bad413a7cc82e46ce16a2f26212925964b1
2018-03-06 14:45:11 -08:00
Erik Kline
b154d18d11 EndsWith *suffix*
Possibly an old copy and paste error.

Test: built
Change-Id: Ie86203d65b4021ed4b787d2330729ab0b1d73e9d
2018-02-27 16:12:55 +09:00
Andreas Gampe
af05f3b761 Base: Add an NDK-compiled version of libbase
To support building libraries for CTS.

Bug: 73206894
Bug: 73659009
Test: mmma system/core/base
Change-Id: I630be88f44cf5cefcb13be7959fc1a710686e29b
2018-02-21 01:59:24 +00:00
Elliott Hughes
dc699a269f bpfmt.
Bug: N/A
Test: builds
Change-Id: I89ad00e1c4c7e0767bc80a7ac7935a4d55e090ac
2018-02-16 17:58:14 -08:00
yusukes
d3b9404241 Prevent WaitForProperty() from using ~100% of CPU time on 32bit builds
Since 'struct timespec' members (time_t and long) are both 32bit on
32bit systems, and std::chrono::{seconds,nanoseconds}::rep are both
>32bit, timespec members assigned in DurationToTimeSpec() can have a
negative value, especially when WaitForProperty() is called with the
default timeout value which is std::chrono::milliseconds::max().

Regarding functionality, passing a negative value to
__system_property_wait() is okay because WaitForProperty() still
waits for the property value (so unit tests are passing), but while
WaitForProperty() does that, the function, to be more exact,
SystemProperties::Wait() in bionic/, consumes ~100% of CPU time. This
happens because SystemProperties::Wait() which implements
__system_property_wait() has a tight while-loop with a __futex_wait()
call, and the futex call immediately returns EINVAL when the timespec
passed in has a negative value.

With this CL, WaitForProperty() will never pass a negative timespec
to __system_property_wait(), and therefore the __futex_wait() call
in bionic works as expected without consuming too much CPU time even
on 32bit systems.

Bug: None
Test: libbase_test32 still passes
Test: strace no longer shows repeated EINVALs from __futex_wait
Change-Id: Id1834fac8cd2876b02dbe4479bf3d3eda2fa7da1
2018-02-14 10:07:54 -08:00
Mark Salyzyn
0c071c9de7 base: adb.exe build error
Windows build of adb is broken because of the lack of
std::chrono_literals and for an implementation of
android::boot_clock::now().

Test: make -j vts
Bug: 72941624
Change-Id: Ie65fed098633eb45a94ea553de6903f8d55fc5b2
2018-02-05 09:33:10 -08:00
Vasily Tarasov
713f289dd0 Adding per-method clang thread safety annotations
Change-Id: Ic92702a06570f48bf3616e0ee959a49e1eec393c
2018-01-10 12:25:32 -08:00
Elliott Hughes
3d7fa22164 Add __attribute__((__format__)) to fastboot's die().
Also make the <android-base/stringprintf.h> macro less likely to collide.

Bug: N/A
Test: builds
Change-Id: I868a0a0002c9c53c1ec0670153df2af5f48fd969
2018-01-09 11:18:10 -08:00
Tomasz Wasilczyk
d535a9cab9 Merge "Use LOG_TAG instead of binary name as a tag." 2017-12-20 21:28:29 +00:00
Elliott Hughes
dbbba76f88 Merge "Add std::string StartsWith*/EndsWith* overloads." 2017-12-20 20:21:55 +00:00
Tomasz Wasilczyk
c251600102 Use LOG_TAG instead of binary name as a tag.
If LOG_TAG was not defined, falling back to a default
behaviour (using binary name).

Bug: 35361699
Test: manual
Change-Id: I209a6ebaf0df882f98642f6d1831766cb296c951
2017-12-20 10:59:46 -08:00
Elliott Hughes
579e682628 Add std::string StartsWith*/EndsWith* overloads.
We should have done this from the beginning. Thanks to Windows, we're not
going to be able to switch libbase over to std::string_view any time soon.

Bug: N/A
Test: ran tests
Change-Id: Iff2f56986e39de53f3ac484415378af17dacf26b
2017-12-20 09:42:22 -08:00
Josh Gao
30171a8b47 base: extract {ASSERT,EXPECT}_MATCH helpers from debuggerd_test.
Add some helper macros that perform regex string matching to
<android-base/test_utils.h>.

Test: libbase_test32/64 on host
Change-Id: I1b0f03dc73f8b4fdfb8ac6c75d59ef421e0e9640
2017-12-19 17:16:12 -08:00
Elliott Hughes
3289b9c928 Merge "Add OWNERS." 2017-12-07 23:21:26 +00:00
Elliott Hughes
693d63f9cf Add OWNERS.
Bug: N/A
Test: N/A
Change-Id: Ie785058c0f5eb9b4086c98ccba6e63e3ed411b65
2017-12-07 13:30:03 -08:00
Yabin Cui
464ea61143 base: allow creating tempfile in a custom temporary dir.
Bug: http://b/70232908
Test: none.
Change-Id: I24b894793f6725186b3582a91db083427e51aa5a
2017-12-06 14:20:07 -08:00
Dan Willemsen
528f144e77 Fix / suppress new unused warnings for mingw+clang
Bug: 69933068
Test: mmma system/core
Change-Id: I089166a979d3d8c5ada38a7745d507b555048499
2017-11-29 21:37:28 -08:00
Chih-Hung Hsieh
122352d983 Use -Werror in system/core
* Move -Wall -Werror from cppflags to cflags.
* Fix/suppress warning on unused variables.

Bug: 66996870
Test: build with WITH_TIDY=1
Change-Id: I1e05e96a1d0bcb2ccef1ce456504b3af57167cc5
2017-11-01 11:32:55 -07:00
Tom Cherry
fbbf27da02 Add test for android::base::Split with a trailing empty part.
Test: this new unit test
Change-Id: Ia14ba878f2866e333a69f1e6f7f56b66a7e657a5
2017-10-26 10:50:20 -07:00
Christopher N. Hesse
684b442b9f libcutils: Fix thread ID on macOS
macOS 10.12 / Xcode 8 actively prohibit the syscall(2)
usage.

Change-Id: I91ff16600a76e97d0b9b5db7e8905b969fb3482f
2017-10-22 22:58:41 +02:00
Dan Willemsen
bdddcab3bd Use target.linux for all linux kernel based targets
Now in Android.bp files, target.linux applies to all targets running a
linux kernel (android, linux_glibc, linux_bionic). So common
flags/sources/etc can be combined instead of copying them to each
target.

Test: m
Change-Id: If7ad138ea1c540c160731f86b6ccc0daa5c69b83
2017-10-16 20:55:39 -07:00
Tom Cherry
31121cafec Move some properties users to __system_property_read_callback()
This is needed if they will ever handle ro. properties that have
values longer than 92 characters.

Bug: 23102347
Bug: 34954705
Test: read and write properties with value length > 92 characters
Change-Id: I44aa135c97ec010f12162c30f743387810ae2c5d
2017-10-10 15:03:33 -07:00
Mark Salyzyn
1f9fa7e907 base: chrono_utils: supported in linux
Tried to use this on host executable, and it always read back zero
for duration.  Expanded code to support any linux build.

Test: works on host
Bug: 38446744
Bug: 66912053
Change-Id: I4a2cbbfff3e7739b54cb6c6e877898de4d3d2296
2017-10-03 14:53:26 -07:00
Dan Willemsen
4852933707 Rename target.linux[_x86[_64]] to target.linux_glibc[_x86[_64]]
In the future, target.linux will apply to all targets running a linux kernel
(android, linux_glibc, linux_bionic). So move all current users to the specific
linux_glibc.

There will be another cleanup pass later that will move some instances back to
target.linux if the properties should be shared with target.android and
target.linux_bionic, but target.linux needs to be removed first.

Test: out/soong/build.ninja identical before/after
Change-Id: I72ef34689c60ce547cab2898e354b027e335f6a1
Exempt-From-Owner-Approval: build system cleanup
2017-10-02 10:44:29 -07:00
Dan Willemsen
1e45d533b3 Remove default libraries
libdl is part of system_shared_libs now. -ldl -lpthread -lm are now defaults
for host_ldlibs on Linux and Darwin. -lrt is a default for host_ldlibs on
Linux.

Test: m host
Change-Id: I0b3c147b00a8ab6ff289b85db55b88836c905f5c
Exempt-From-Owner-Approval: build system cleanup
2017-09-29 13:17:06 -07:00
Andreas Gampe
c8f935aa5e Base: Warn on using ostream<< with std::string*
In most reasonable cases, this is actually a bug. So add a diagnostic.

Test: m
Change-Id: Ib506b45dbdbafcb1893486b08ef13ec8f11d0357
2017-09-22 16:25:58 -07:00
Andreas Gampe
2db3823632 Revert "Base: Delete ostream<< with std::string*"
This reverts commit 4ef5011a7b.

Reason for revert: Breaks an internal mocking case that cannot be changed.

Test: m
Change-Id: I83f9338bde02eb2b45b3e52b66ef78490ddbeeda
2017-09-21 17:53:00 -07:00
Andreas Gampe
4ef5011a7b Base: Delete ostream<< with std::string*
In most reasonable cases, this is actually a bug. So delete the
operator overload and let the compiler complain.

Test: m
Change-Id: I7d66ec2f33cc46588b6f549876241871f19ce995
2017-09-20 10:54:20 -07:00
Tianjie Xu
f9bc1b0571 Add the Release function for TemporaryFiles
Some tests may create a File* by calling fdopen() on the temp file's
fd. We should release the ownership of fd in this case to avoid the
double close.

Bug: 65430057
Test: libbase unit tests pass
Change-Id: I54fcce2029f9a574f53afdbdda737ee58620c73a
2017-09-11 14:08:32 -07:00
Josh Gao
4221e2cc03 base: hopefully fix the mac build.
Test: none
Change-Id: Idd4f353a158a0c096d16ecf87e239c50aba79cf7
2017-08-29 21:28:32 -07:00
Josh Gao
fdf832dfd3 base: add Pipe and Socketpair wrappers.
Also, switch debuggerd_handler over to using android::base::unique_fd.

Test: treehugger
Change-Id: I97b2ce22f1795ce1c4370f95d00d769846cc54b8
2017-08-28 14:51:07 -07:00
Dimitry Ivanov
2732a7e023 Merge "Define current ABI string in android-base/macros.h" 2017-08-24 09:38:34 +00:00
dimitry
b6ba817de4 Define current ABI string in android-base/macros.h
Test: make
Change-Id: I8200d7b3232edba43a583c5ff1e1b0f78c768f69
2017-08-23 20:46:38 +02:00
Justin Yun
9ca92458e2 Mark the modules as VNDK-SP in Android.bp
As a VNDK-SP module, Android.bp must have 'vndk' tag as well as
'vendor_available: true'.

The 'vndk' tag for VNDK-SP formated as follows:
vndk: {
    enabled: true,
    support_system_process: true,
},

VNDK-SP modules will be installed both in system/lib(64) as normal
and in system/lib(64)/vndk-sp as a vendor variant.

Bug: 63866913
Test: build and boot with BOARD_VNDK_VERSION=current
Merged-In: I51fe0859f63ad58b7b91909e7d7d4206443228cd
Change-Id: I51fe0859f63ad58b7b91909e7d7d4206443228cd
(cherry picked from commit aeb68e86e4)
2017-08-23 17:56:13 +09:00
Josh Gao
b5c90e9d6b Merge "Revert "base: work around thread safety analysis bug."" 2017-08-02 23:10:42 +00:00
Josh Gao
c54e3dba8d Revert "base: work around thread safety analysis bug."
This reverts commit e4509da961.

Reason for revert: probably breaks checkbuild?

Change-Id: I04a6284dee82761c90fa355da0472855a228b849
2017-08-02 23:10:26 +00:00
Josh Gao
f3c7f10abd Merge "base: work around thread safety analysis bug." 2017-08-02 23:09:07 +00:00
Josh Gao
e4509da961 base: work around thread safety analysis bug.
Clang's assert_capability and assert_shared_capability annotations are
nonfunctional until https://reviews.llvm.org/rL309725 is relanded and
makes its way into our toolchain. Work around this by using the
equivalent assert_lock and assert_shared_lock.

Bug: http://b/64226736
Test: manual
Change-Id: I40711f162ea1d492f1e0b3eff88bf6ae6d995e2f
2017-08-02 14:44:58 -07:00
Adam Lesinski
5fff67f2ec Add definition of off64_t for mac os builds
Mac OS does not define off64_t, since off_t is always 64 bit.

Test: manual
Change-Id: Ib02a912a2eaf38143e124f2b6aaf294ecf84ff88
2017-07-25 16:26:23 -07:00
Adam Lesinski
a0360ad6a3 Merge "libziparchive: Use ReadAtOffset exclusively" 2017-07-25 22:22:21 +00:00
Adam Lesinski
de117e4a49 libziparchive: Use ReadAtOffset exclusively
The use of ReadAtOffset is meant to allow concurrent access
to the zip archive once it has been loaded. There were places
where this was the case, and some places that did a seek + read
combination, which could lead to data races.

NOTE: On Windows, we are not using pread as the implementation of
ReadAtOffset, therefore the guarantees on Windows are weaker.

On Linux, pread allows the file descriptor to be read at a specific
offset without changing the read pointer. This allows inherited fd's
and duped fds to be read concurrently.

On Windows, we use the ReadFile API, which allows for an atomic seek +
read operation, but modifies the read pointer. This means that any mix
use of ReadAtOffset and Read will have races. Just using ReadAtOffset is
safe.

For the Windows case, this is fine as the libziparchive code now only
uses ReadAtOffset.

Bug: 62184114
Bug: 62101783
Test: make ziparchive-tests (existing tests pass)
Change-Id: Ia7f9a30af2216682cdd9d578d26e84bc46773bb9
2017-07-25 18:12:12 +00:00
Lennart Wieboldt
cd15fc7ba8 Remove LOCAL_CLANG and clang: true
clang is the default compiler since Android nougat

Test: mma & verified it´s still build with clang
Change-Id: I34adaeef2f6558a09f26027271222bad94780507
Signed-off-by: Lennart Wieboldt <lennart.1997@gmx.de>
2017-07-25 14:29:50 +02:00
Tom Cherry
ede0d53850 Move Timer from init to libbase
Test: boot bullhead
Test: new libbase unit tests

Change-Id: Ic398a1daa1fe92c10ea7bc1e6ac3f781cee9a5b5
2017-07-10 09:28:24 -07:00
Renaud Paquay
e3e7813e5f Add (partial) support for Windows long paths
* Update android::base::utf8::open/unlink to support Windows long
  paths

* Add android::base::utf8::fopen, also with support for Windows long
  paths

* Upcoming CLs will add additional APIs to support additional use cases

Test: Added tests to utf8_test
Bug: 38268753
Change-Id: If72af327f3487766f5370a2f43ee9cabd4a8a810
2017-06-28 17:12:37 +00:00
George Burgess IV
6466ced8f6 logging: make LOG(FATAL) always run with the static analyzer.
::android::base::GetMinimumLogSeverity() is defined externally, so the
static analyzer was allowed to assume that we continue executing after a
LOG(FATAL).

I manually audited all of the code I have access to, and the only
"change the minimum log severity" statements I can see keep FATAL
enabled (...and continuing after a FATAL is highly sketchy to me
anyway).

(I'm sure I tested this at some point in making the previous patch. I
probably broke it in a refactor before sending it out for review; my
bad. :) )

Bug: None
Test: m without the static-analyzer builds; m with it yields fewer
false positives.

Change-Id: I216cd2034e1daa8d6f6c5e776f64b4cce88bb938
2017-05-31 14:41:22 +00:00
George Burgess IV
7e771de38f logging: always enable DCHECK for the static analyzer
This helps us have less false-positives.

We do this instead of `#undef NDEBUG`, since undefing NDEBUG actually
gave us more false-positives (...and build breakages) than simply
leaving it defined.

Bug: None
Test: Ran the static analyzer across internal master. 213 fewer warnings
(15 Medium, 2 Low, the remainder are 'Analyzer'). All of the dropped
warnings I audited were false-positives. It adds ~3 Tidy warnings.
Change-Id: Ibedab60ca7e9d2b0772896222b83d2e7ab064afe
2017-05-26 11:04:48 -07:00
Elliott Hughes
282ec458be Remove libbase's trivial libutils-headers dependency.
Bug: N/A
Test: builds
Change-Id: I59eb464a0127564a42775bf19b516ad8a53ee235
2017-05-15 17:31:15 -07:00
George Burgess IV
582ec2b078 fix static-analyzer logging/CHECK macros
Two small changes in one:

- `foo || for (;;abort()) bar();` isn't valid C or C++, since for is a
  statement. We need an expression instead.
- we'll now treat everything after LOG(foo) as unreachable in the
  static analyzer, as long as we can prove at compile-time that
  foo == FATAL.

The impact of this, running across internal master, is that we see ~50
fewer medium/high-severity false positives from clang-tidy. We see 15
new complaints about unreachable code (at the "tidy" severity), but all
of them are harmless AFAICT (e.g.

switch (foo) {
  // ...
  default:
    LOG(FATAL) << "Unhandled case!"; // or CHECK(false);
    break; // clang-tidy: unreachable break.
})

(Some of the macros were forcibly formatted by the clang-format hook)

Bug: None
Test: Ran
`DEFAULT_GLOBAL_TIDY_CHECKS=clang-analyzer*,-clang-analyzer-alpha* m`;
stared at warn.py output.

Change-Id: Ie984eda0481afad4274b9def7c61ba777cfa289a
2017-05-03 17:16:01 -07:00
Josh Gao
637483de91 base: remove execute bit from utf8.cpp, utf8_test.cpp.
Test: none
Change-Id: Idcd7feb2f3a7dc8706c498c55100e82d029858e0
2017-04-27 19:10:07 -07:00
Colin Cross
4eda982a77 Don't export libutils_headers from libbase
libutils headers are only used by the implementation of libbase,
and should not be exported to everything that uses libbase headers.

Test: m -j
Change-Id: I76f248908f649e3a3c91cd3e84d629a0049939ef
2017-04-20 10:36:32 -07:00
Steven Moreland
e131f31db5 libbase: fix build breakage
Two changes were merged at the same time that conflicted.

Test: builds
(cherry picked from commit 72b9d28423)
Merged-In: Ia6c730804cd5a3b2655e6d69b8e4f346d198dabb
Change-Id: Ia6c730804cd5a3b2655e6d69b8e4f346d198dabb
2017-04-19 10:39:54 -07:00
Steven Moreland
d10a023208 libbase: make vendor_available
By setting vendor_available, the following may become true:

* a prebuilt library from this release may be used at runtime by
  in a later releasse (by vendor code compiled against this release).
  so this library shouldn't depend on runtime state that may change
  in the future.
* this library may be loaded twice into a single process (potentially
  an old version and a newer version). The symbols will be isolated
  using linker namespaces, but this may break assumptions about 1
  library in 1 process (your singletons will run twice).

Background:

This means that these modules may be built and installed twice --
once for the system partition and once for the vendor partition. The
system version will build just like today, and will be used by the
framework components on /system. The vendor version will build
against a reduced set of exports and libraries -- similar to, but
separate from, the NDK. This means that all your dependencies must
also mark vendor_available.

At runtime, /system binaries will load libraries from /system/lib*,
while /vendor binaries will load libraries from /vendor/lib*. There
are some exceptions in both directions -- bionic(libc,etc) and liblog
are always loaded from /system. And SP-HALs (OpenGL, etc) may load
/vendor code into /system processes, but the dependencies of those
libraries will load from /vendor until it reaches a library that's
always on /system. In the SP-HAL case, if both framework and vendor
libraries depend on a library of the same name, both versions will be
loaded, but they will be isolated from each other.

It's possible to compile differently -- reducing your source files,
exporting different include directories, etc. For details see:

https://android-review.googlesource.com/368372

None of this is enabled unless the device opts into the system/vendor
split with BOARD_VNDK_VERSION := current.

Bug: 33241851
Test: build and flash internal marlin
Test: m -j libbase
Test: build with BOARD_VNDK_VERSION := current
(cherry picked from commit c28517f956)
Merged-In: I720a00deada4e62628e6fbc4ac830265de9c669f
Change-Id: I720a00deada4e62628e6fbc4ac830265de9c669f
2017-04-19 10:32:47 -07:00
Steven Moreland
3c71bbdde3 libbase: add libbase_headers
Test: can include headers in other soong modules
Bug: 33241851
(cherry picked from commit 8f56c1ecd7)
Merged-In: Ie3d11d1559f5aae46125695fd1f3a63da8e429ae
Change-Id: Ie3d11d1559f5aae46125695fd1f3a63da8e429ae
2017-04-19 10:32:41 -07:00
Tom Cherry
5c3961c547 Merge "Add android::base::ScopeGuard" 2017-04-06 22:41:02 +00:00
Tom Cherry
c996a8e73e Add android::base::ScopeGuard
Taken from bionic/libc/private/ScopeGuard.h.

Test: New unit tests
Change-Id: If83c1990efbf294aee0b5d40a7a9ac326e5e765e
2017-04-05 16:15:33 -07:00
Christopher Ferris
48d08c2c9d Convert opens to use unique_fd.
Fixes a potential leak of fds in WriteStringToFile.

Test: I wrote a temporary test that failed the fchmod on host in
Test: WriteStringToFile. I verified this fails with the old code after running
Test: out of fds and passes with the new code.
Change-Id: I168160841e35dd480d59a69bb4aa8176899fbb32
2017-04-05 12:30:12 -07:00
James Hawkins
e78ea77f69 bootstat: Refactor init/utils/boot_clock into base/chrono_utils.
Use this for bootstat and init. This replaces the custom uptime parser in
bootstat.

This is a reland of aosp/338325 with a stubbed implementation for Darwin.

This change also has clang_format fixes (automatic).

Bug: 34352037
Test: chrono_utils_test
Change-Id: I72a62a3ca1ccfc0a4ccc6294ff1776c263144686
2017-03-30 14:24:12 -07:00
Tom Cherry
3d5729402e Fix timeouts for android::base::WaitForProperty*
std::chrono doesn't handle integer overflow, so using
std::chrono::milliseconds::max() to indicate an infinite timeout is
not handled well in the current code.  It causes an 'absolute_timeout'
earlier in time than 'now' and causes the associated WaitForProperty*
functions to return immediately.

Also, any duration_cast from relative_timeout to nanoseconds would
cause the same issue, as it would overflow in the conversion and
result in an invalid results.

This change prevents any duration_casts of relative_timeout to
nanoseconds and replaces the logic to wait on an absolute timeout with
logic that compares the time elapsed to the provided relative timeout.

This change also includes a test that std::chrono::milliseconds::max()
does not return immediately and that negative values do return immediately.

Test: Boot bullhead + libbase_test

Change-Id: I335bfa7ba71e86c20119a0ed46014cad44361162
2017-03-27 18:05:58 -07:00
Elliott Hughes
9bb7971ae7 Keep the ReadFileToString/ReadFdToString overhead down.
Bug: https://code.google.com/p/android/issues/detail?id=258500
Bug: http://b/36046324
Test: ran tests
Change-Id: I40e76a6dd164ea9a5e8e18159f543e1bb221dcba
2017-03-21 13:43:08 -07:00
Dimitry Ivanov
840b6019c0 Add android::base::Realpath.
Bug: http://b/31396973
Test: libbase_test on host and device
Change-Id: I1e5f15c76227ec1c2128baa38eb454d347987703
2017-03-15 22:20:50 -07:00
Tom Cherry
5b4eb23cfd Remove extraneous .clang-format files
The .clang-format files in the base, debuggerd, adb, libprocinfo, and
fastboot subdirectories each differ slightly from the top level
.clang-format-2 and .clang-format-4, but not in a substantially
meaningful way, as the source files in those directories have not been
re-formatted with clang-format.  Therefore, let's reduce the
differences and use only the two top level clang-format files.

Secondly perform some small clean-up of the top level .clang-format
files.  AllowShortBlocksOnASingleLine is already false in the Google
style, so it can be removed.  AllowShortFunctionsOnASingleLine should
not change between the -2 and -4 versions, so leave it at the Google
default style in both, which is 'All'.

The diff stats for these changes are:

./base/
Old:
640 insertions(+), 531 deletions(-)
New:
563 insertions(+), 808 deletions(-)

./debuggerd/
Old:
910 insertions(+), 886 deletions(-)
New:
991 insertions(+), 1023 deletions(-)

./adb/
Old:
2623 insertions(+), 2886 deletions(-)
New:
2655 insertions(+), 3103 deletions(-)

./libprocinfo/
Old:
2 insertions(+), 1 deletion(-)
New:
4 insertions(+), 18 deletions(-)

./fastboot/
Old:
618 insertions(+), 743 deletions(-)
New:
726 insertions(+), 882 deletions(-)

./init/
Old:
1755 insertions(+), 1866 deletions(-)
New:
1715 insertions(+), 1952 deletions(-)

Test: Above clang-format stats
Change-Id: I3f7b8ab0660c8394c5008ba95ea15e70dd22b55b
2017-03-14 14:06:31 -07:00
Keun-young Park
22a64b3a8a Merge "add base::WaitForPropertyCreation" 2017-02-28 22:39:41 +00:00
Keun-young Park
e2d986daa6 add base::WaitForPropertyCreation
- unlike base::WaitForProperty, which waits for specific value to
  be set, this one only waits until the property is created.

bug: 35178781
Test: added unit test
Change-Id: Idbf98c2152fe768357302f6b69310c55305f5d54
2017-02-28 12:08:54 -08:00
Colin Cross
bb3a515f46 Add GetExecutableDirectory to libbase
Tests will often want to get the executable directory in order to
find test data.

Test: out/host/linux-x86/nativetest64/libbase_tests/libbase_tests
Change-Id: Ica9d211bcd039fcf83a22fd494816abd01b97aa3
2017-02-28 16:34:04 +00:00
Colin Cross
58021d15c9 Move adb_dirname and adb_basename to libbase
adb already provides an implementation of dirname and basename that
take and produce std::strings, move it into libbase so it can be
used in the implementation of GetExecutableDirectory.

Test: out/host/linux-x86/nativetest64/adb_test/adb_test
Test: out/host/linux-x86/nativetest64/libbase_test/libbase_test
Test: adb shell /data/nativetest64/libbase_test/libbase_test64
Change-Id: Ideb1627607b14562121316d4ed27fa6fb0930684
2017-02-27 18:18:31 -08:00
Elliott Hughes
8a16081fa1 Merge "Add cross-platform <android-base/endian.h>." 2017-02-25 02:07:05 +00:00
Elliott Hughes
1dbd976200 Add cross-platform <android-base/endian.h>.
Bionic has <sys/endian.h>, glibc <endian.h>, and macOS and Windows have
nothing. This has often been annoying.

Bug: N/A
Test: new tests
Change-Id: I2a40c570df6a9bb30607ace1af653265938cc4b8
2017-02-24 14:03:36 -08:00
Elliott Hughes
9f4c8f753b Add some basic docs for <android-base/logging.h>
Bug: http://b/35360600
Test: N/A
Change-Id: I3de6bbe4afc7ca6adbfb0c9b01a5a3d4c2c35cfc
2017-02-22 18:02:46 -08:00
Elliott Hughes
03edc9f764 Add timeout support to android::base::WaitForProperty.
Bug: http://b/35201172
Test: ran tests
Change-Id: I025aa0217dc94fabf0eb076b285a84866b00e741
2017-02-21 14:57:15 -08:00
Elliott Hughes
ec46f4ed28 Only sanitize Android.
Bug: N/A
Test: didn't
Change-Id: I9b9bc04112501eaa9f9ccf23152fc5d118b03000
2017-02-14 15:46:33 -08:00
James Hawkins
91cf0bd5c0 Merge "Revert "bootstat: Refactor init/utils/boot_clock into base/chrono_utils."" 2017-02-14 19:24:36 +00:00
James Hawkins
c8ac067773 Revert "bootstat: Refactor init/utils/boot_clock into base/chrono_utils."
This reverts commit 7c92e48450.

Mac sdk still broken (despite testing locally).

Change-Id: I7d9206e15997cd0efe081bd3fa17d53d2b20ec32
2017-02-14 19:20:20 +00:00
Treehugger Robot
aa9548dbb4 Merge "Fix ubsan failure in android::base::Split." 2017-02-14 18:43:17 +00:00
Treehugger Robot
e968b73e19 Merge "bootstat: Refactor init/utils/boot_clock into base/chrono_utils." 2017-02-14 18:35:54 +00:00
Treehugger Robot
01003d40fc Merge "Implement android::base::WaitForProperty." 2017-02-14 03:48:26 +00:00
Yabin Cui
b13d4a31a3 Merge "libbase: fix the way to find temp dir." 2017-02-14 00:29:40 +00:00
Yabin Cui
57e9cea099 libbase: fix the way to find temp dir.
Tests running in app context can't access /data/local/tmp,
so try current directory if /data/local/tmp is not accessible.

Bug: http://b/18790309
Test: run unit test in app context and shell context.
Change-Id: If66fe8f0ac3edb3a32a2a2a50a524364f818a58b
2017-02-13 15:50:56 -08:00
James Hawkins
7c92e48450 bootstat: Refactor init/utils/boot_clock into base/chrono_utils.
Use this for bootstat and init. This replaces the custom uptime parser in
bootstat.

This is a reland of aosp/332854 with a fix for Darwin.

Bug: 34352037
Test: chrono_utils_test
Change-Id: Ib2567d8df0e460ab59753ac1c053dd7f9f1008a7
2017-02-13 15:47:21 -08:00
Elliott Hughes
bf0dd7cb03 Fix ubsan failure in android::base::Split.
ubsan doesn't like us incrementing std::string::npos, even if we won't use
the result.

Bug: http://b/28729303
Test: ran tests
Change-Id: I8227eca57dc6f3e49626c7025514caa04ef18f0a
2017-02-13 14:13:24 -08:00
Elliott Hughes
b30769a87a Implement android::base::WaitForProperty.
Also adapt libcutils to the bionic change that was necessary for this.

Bug: http://b/35201172
Test: ran tests
Change-Id: I72a98b70b03d23e958b46778b505fbd5c86c32ae
2017-02-13 11:29:02 -08:00