Commit graph

1587 commits

Author SHA1 Message Date
Elliott Hughes
53dc9dd701 Improve pthread_create failure handling.
Return EAGAIN rather than aborting if we fail to set up the TLS for a new
thread.

Add a test that uses all the VMAs so we can properly test these edge cases.

Add an explicit test for pthread_attr_setdetachstate, which we use in the
previous test, but other than that has no tests.

Remove support for ro.logd.timestamp/persist.logd.timestamp, which doesn't
seem to be used, and which prevents us from logging failures in cases where
mmap fails (because we need to mmap in the system property implementation).

Bug: http://b/65608572
Test: ran tests
Change-Id: I9009f06546e1c2cc55eff996d08b55eff3482343
2017-09-19 14:02:50 -07:00
Treehugger Robot
dacbb04cde Merge "Support larger guard regions." 2017-09-19 01:08:25 +00:00
Christopher Ferris
7a5bb687f4 Merge "Drop thread list lock before abort." 2017-09-19 00:15:32 +00:00
Elliott Hughes
d6c678ca90 Support larger guard regions.
This also fixes a long-standing bug where the guard region would be taken
out of the stack itself, rather than being -- as POSIX demands -- additional
space after the stack. Historically a 128KiB stack with a 256KiB guard would
have given you an immediate crash.

Bug: http://b/38413813
Test: builds, boots
Change-Id: Idd12a3899be1d92fea3d3e0fa6882ca2216bd79c
2017-09-18 16:09:43 -07:00
Christopher Ferris
7982914fae Drop thread list lock before abort.
Bug: 65656273

Test: Ran the app and verified it crashes instead of deadlocks.
Change-Id: I7dbe653d50a635a23993c99c5f73ca094ee80b28
2017-09-18 14:40:35 -07:00
Treehugger Robot
0c9ea17e0c Merge "Always log errno when aborting." 2017-09-18 21:33:54 +00:00
Elliott Hughes
7b0af7ad82 Always log errno when aborting.
(Where errno is relevant.)

Also consistently use -1 as the fd for anonymous mmaps. (It doesn't matter,
but it's more common, and potentially more intention-revealing.)

Bug: http://b/65608572
Test: ran tests
Change-Id: Ie9a207632d8242f42086ba3ca862519014c3c102
2017-09-15 16:18:49 -07:00
Elliott Hughes
50cda38f1d Use __RENAME for long double functions.
We can cut a lot of stuff out of the NDK's libandroid_support with this,
and reduce unnecessary relocations for all LP32 code. LP64 code should
be unaffected.

Bug: https://issuetracker.google.com/64450768
Bug: https://github.com/android-ndk/ndk/issues/507
Test: ran tests, plus manual readelf on the _test.o files
Change-Id: I3de6015921195304ea9c829ef31665cd34664066
2017-09-14 16:10:43 -07:00
Elliott Hughes
4c9d528a25 Merge "Finish <search.h>." 2017-09-11 18:39:30 +00:00
Jayant Chowdhary
ab2f79c0da For devices which are not treble enabled, return the system shell.
For treble enabled devices, still return the appropriate shell depending
on whether the process is a vendor process or a system one.

Test: Manual testing: on a bullhead device, ran test programs from
      /vendor/bin which used popen() and system(). The calls succeeded.

Bug: 65054230

Bug: 64516799

Merged-In: I15dfdbb107cfca7c0f92f337c9bb46b9876eb38e
Change-Id: I15dfdbb107cfca7c0f92f337c9bb46b9876eb38e
(cherry picked from commit 1e52871773)
2017-09-07 17:19:21 -07:00
Elliott Hughes
7379018162 <stdbool.h> not necessary in C++.
Bug: N/A
Test: builds
Change-Id: I40fffe92d4273eab5a98bd65013bb9da2aea2171
2017-09-07 13:28:14 -07:00
Elliott Hughes
5702c6ff45 Finish <search.h>.
I'm unable to find a bug, but we've had requests for this internally
once or twice (though I pointed those folks at the STL), and there's
code we build for the host or in our bootloaders that would use this,
and there's reasonable-looking FreeBSD implementation ready and waiting.

Bug: N/A
Test: ran tests
Change-Id: I6ddee4b71bea4c22ed015debd31d3eaac4fcdd35
2017-08-31 17:38:51 -07:00
Elliott Hughes
a648733cb7 Implement <iconv.h>.
Bug: http://b/32978596
Test: ran tests
Change-Id: I56b6ae3d9c5a3a56d2b4afba33fb8f9e964bf7b9
2017-08-25 08:47:41 -07:00
Elliott Hughes
5da4fe4ada Fix overflow in get_phys_pages and get_avphys_pages.
On LP32 mem_unit will be 4096 to allow more than 4GiB in the "ulong"
fields, but we need to promote to a 64-bit type before we multiply.

Bug: N/A
Test: tested manually with an x86 static binary on my 64GiB desktop.
Signed-off-by: YiPing Xu <xuyiping@hisilicon.com>
Change-Id: Id663932503b75793bb7c26a008129f3e2e4cccbf
2017-08-24 16:51:48 -07:00
Treehugger Robot
7b4fb64177 Merge "Add more const-correct C++ overloads." 2017-08-24 02:31:35 +00:00
Elliott Hughes
8f0c87e21f Remove dead longjmperror.
This used to be used by the ARM longjmp implementation, but hasn't been in
libc.so for as long as we've used a linker script.

Bug: N/A
Test: builds
Change-Id: I3dff4d154d5e317955c349c9eaa08b982cbf0285
2017-08-23 15:40:03 -07:00
Elliott Hughes
df9a489b2b Add more const-correct C++ overloads.
libc++ actually provides overloads for all the standard C library stuff,
so we just need to handle the POSIX and GNU extensions, of which there
are just two more: memrchr and strcasestr.

Bug: http://b/22768375
Test: builds
Change-Id: Ie9ed1fbcc794e14a0c9bba13b5307ad677949613
2017-08-23 14:34:40 -07:00
Sandeep Patil
4a3c9751eb Merge "libc: Add support to allow library calls to find appropriate shell executable for a process" 2017-08-22 19:55:41 +00:00
Sandeep Patil
9b1ca569db libc: Add support to allow library calls to find appropriate shell executable for a process
Library calls like system() and popen() invoke the shell executable
pointed to by '_PATH_BSHELL' in order to run the command passed into the
function. The _PATH_BSHELL points to /system/bin/sh by default and thus
breaks any vendor process trying to use system() / popen(), as they are
denied access to system shell by selinux.

This CL make necessary changes, so the implmentations of system() and popen()
can use the appropriate shell (e.g. /vendor/bin/sh for processes running
out of /vendor partition). Also, changes the implementation of system()
and popen().

Bug: 64832610
Test: Manual, Using a test program running from /system/bin and
      /vendor/bin to ensure correct shell is being used.

Change-Id: Ie7168d69decb1ae98284446ae7db34dec930dc33
Merged-In: Ie7168d69decb1ae98284446ae7db34dec930dc33
Signed-off-by: Sandeep Patil <sspatil@google.com>
(cherry picked from commit aa3e32422c)
2017-08-22 10:17:28 -07:00
Tom Cherry
55d0f16369 Merge "Always use CLOCK_MONOTONIC for pthreads and semaphores"
am: cbb09bcbb1

Change-Id: Ic0192542c3f4de8afc4cdc4719c2db1e59bcfc4b
2017-08-18 20:06:28 +00:00
Tom Cherry
cbb09bcbb1 Merge "Always use CLOCK_MONOTONIC for pthreads and semaphores" 2017-08-18 19:59:26 +00:00
Tom Cherry
ac49cedc7e Always use CLOCK_MONOTONIC for pthreads and semaphores
pthread's and semaphore's default behavior is to use CLOCK_REALTIME,
however this behavior is essentially never intended, as that clock is
prone to change discontinuously.

What users really intend is to use CLOCK_MONOTONIC, however only
pthread_cond_timedwait() provides this as an option and even there, a
large amount of existing code does not opt into CLOCK_MONOTONIC.

We have seen numerous bugs directly attributable to this difference.
Therefore, we provide this general workaround to always use
CLOCK_MONOTONIC for waiting, regardless of what the input timespec
is.

Specifically this impacts the below APIs:
pthread_mutex_timedlock()
pthread_cond_timedwait()
pthread_rwlock_timedrdlock()
pthread_rwlock_timedwrlock()
sem_timedwait()

Test: boot bullhead, boot sailfish
Test: bionic pthread/semaphore unit tests
Test: check that pthread_cond_timedwait() timeouts are uneffected by
      CLOCK_REALTIME time changes

Bug: 64694413
Bug: 64623895
Bug: 35756266
Bug: 35678943
Change-Id: Ibba98f5d88be1c306d14e9b9366302ecbef6d534
2017-08-18 09:11:05 -07:00
Dimitry Ivanov
a86d68dcd2 Merge "Report correct errno on clone failure"
am: b2688f4a2a

Change-Id: I7ea8aae468320c16665729a3a925dc921ea35726
2017-08-16 11:27:21 +00:00
dimitry
6de60874aa Report correct errno on clone failure
Test: make
Change-Id: Id0af3678627c06167a6d434d8616c4a304e1fbc0
2017-08-14 14:42:19 +02:00
Elliott Hughes
212ea2b74e Merge "With O_TMPFILE, open(2) takes a mode argument."
am: 2fdefadcee

Change-Id: I5cd1f9103b4b5f20f18fd3f7f5be2511e2b1990f
2017-08-04 20:20:38 +00:00
Elliott Hughes
b115aefbb3 With O_TMPFILE, open(2) takes a mode argument.
Strictly, the mode isn't really meaningful unless you supply O_EXCL,
but the kernel will take it and fstat will return it even if you
never give the file a name.

Also warn for O_TMPFILE without a mode at compile time where possible.

Bug: N/A
Test: ran tests
Change-Id: I729b6d6e6190676fd017a1190b6200bf9abdbfd8
2017-08-04 10:20:18 -07:00
George Burgess IV
5869bbe1d0 Merge "libc fortify: make string.h use diagnose_if"
am: b1b125ead1

Change-Id: I9e4508c73a83987bbd21550538ff77d6cb65cace
2017-08-03 03:29:34 +00:00
George Burgess IV
b6300463a8 libc fortify: make string.h use diagnose_if
This also has a handful of style fixups, to make this file more
consistent. And removes __bionic_zero_size_is_okay_t, since there's a
better workaround available.

Bug: 12231437
Test: m checkbuild on bionic internal master; CtsBionicTestCases show
no new failures.

Change-Id: I75a020630dbab0ce828563502900cba14ae992d1
2017-08-01 22:41:11 -07:00
Elliott Hughes
b3f1343098 Merge "Remove restrict/__restrict."
am: 6616056f0f

Change-Id: I5343c191c3f424343d1c7617e054b2347d0dc6b5
2017-08-01 17:52:30 +00:00
Elliott Hughes
ec6850d849 Remove restrict/__restrict.
We've never really used __restrict: only <string.h> and <stdio.h> (which
are still very similar to upstream BSD headers) consistently have these
annotations. Neither clang nor GCC warns for trivial cases, and there's
little obvious documentation benefit.

Bug: http://b/30833514
Test: builds
Change-Id: I3e4384281865475d0c55d764b546d8166419ee31
2017-08-01 08:28:46 -07:00
Elliott Hughes
b82a2d0bd5 Merge "POSIX getlogin_r/LOGIN_NAME_MAX/TTY_NAME_MAX."
am: 8aa4bc7c55

Change-Id: I578d3e5c096401b0447f9ed7223d3e20ffb5b19e
2017-07-29 14:59:15 +00:00
Elliott Hughes
06bd5862b1 POSIX getlogin_r/LOGIN_NAME_MAX/TTY_NAME_MAX.
Bug: N/A
Test: ran tests
Change-Id: I97c8ecc82fb09c3fa4bb5e6f000d46f04f3d1702
2017-07-28 16:34:38 -07:00
Elliott Hughes
a97079d94e Merge "Implement wcwidth(3) in terms of icu4c."
am: bafa1985ec

Change-Id: Ia7e74b6124206fe5f2c5bf372c03ee5246045462
2017-07-28 21:50:26 +00:00
Elliott Hughes
c41b560f5f Implement wcwidth(3) in terms of icu4c.
Based on com.google.i18n.CharWidth by the icu-team folks.

Bug: N/A
Test: ran tests
Change-Id: Ia9d818ec4ae60f2f3978533195330d00699397c5
2017-07-27 17:08:24 -07:00
George Burgess IV
78d878c8df Merge "libc: Move FORTIFY into one file; make style fixups"
am: 4f36cabd8d

Change-Id: I17f125e6100e0af30c083df7a6a7a19a90696dc3
2017-07-26 02:55:44 +00:00
George Burgess IV
d34b0a946c libc: Move FORTIFY into one file; make style fixups
This addresses post-commit feedback from
I88c39ca166bacde0b692aa3063e743bb046a5d2f. With this, our FORTIFY impl
now sits in one file.

Bug: 12231437
Test: mma; no new CtsBionicTestCases failures on bullhead internal
master.
Change-Id: I6f9ff81c3e86cf9d6a0efa650eb5765f1e2fa09c
2017-07-25 17:39:21 -07:00
George Burgess IV
b231a63354 Merge "Split our FORTIFY implementation into libc_fortify"
am: 086b1b5a22

Change-Id: I6e05d09bc00135657a35420fe102a37ccf8c59fc
2017-07-25 18:13:10 +00:00
Treehugger Robot
086b1b5a22 Merge "Split our FORTIFY implementation into libc_fortify" 2017-07-25 18:05:42 +00:00
George Burgess IV
6cb0687932 Split our FORTIFY implementation into libc_fortify
As requested in the bug. This also rips __memcpy_chk out of memcpy.S,
which lets us cut down on copypasta (all of the implementations look
identical).

Bug: 12231437
Test: mma on aosp_{arm,arm64,mips,x86,x86_64} internal master;
checkbuild on bullhead internal master; CtsBionicTestCases on bullhead.
No new failures.
Change-Id: I88c39ca166bacde0b692aa3063e743bb046a5d2f
2017-07-24 14:20:16 -07:00
Elliott Hughes
778b1bd7f6 Merge "Replace killpg."
am: 57ad09278f

Change-Id: Ib1902dbe08b5c797278a4425ae8434dcadd7f06b
2017-07-24 20:22:39 +00:00
Elliott Hughes
57ad09278f Merge "Replace killpg." 2017-07-24 20:16:40 +00:00
George Burgess IV
9a626a86e1 Merge "Remove outdated _FORTIFY_SOURCE #undefs"
am: 71853ad5c5

Change-Id: I4778897a4f7ccb9bb302480696ef765d549733d0
2017-07-21 21:41:51 +00:00
George Burgess IV
53c4c8abb0 Remove outdated _FORTIFY_SOURCE #undefs
AFAICT, all of these were added prior to the new-style FORTIFY going
in. Because clang saw two definitions of the "same" function, it got
upset. (e.g. 35d937e4eb)

Now that our FORTIFY functions are overloads of their library functions,
these undefs can be removed.

(This is a step toward making FORTIFY a library with -U_FORTIFY_SOURCE
on it, as requested in the bug.)

Bug: 12231437
Test: CtsBionicUnitTests. No new failures.

Change-Id: I844ff77106ee2bea72ae1cd0bb85d146939ecd05
2017-07-21 11:25:52 -07:00
Elliott Hughes
452c185a0b Merge "Hide various mbstate implementation details."
am: dcdd0e3760

Change-Id: I4f2941939f40c04344f3f9dcfd5debe7780d9275
2017-07-15 03:19:16 +00:00
Elliott Hughes
697f42afdb Hide various mbstate implementation details.
...by inlining them.

Also fix a couple of harmless bugs in passing. I've added tests, but in
both cases I don't think it was actually possible to hit the bad behavior:
we'd hit another test and fail immediately after in an externally
indistinguishable way.

Bug: N/A
Test: readelf
Change-Id: I8466050b0bfe2b7b94c76b383cf10c1d9d28debd
2017-07-14 17:00:05 -07:00
Dan Albert
021d7ca543 Merge "Move wchar _l functions out of wchar.cpp."
am: 78c8b306ee

Change-Id: Ia871cf273fde5c70737378b0a7634f2a634d5587
2017-07-13 19:27:42 +00:00
Dan Albert
3f03579589 Move wchar _l functions out of wchar.cpp.
We don't need these in libandroid_support, but we do need the other
parts of wchar.cpp, and they're not really related.

Test: make checkbuild
Bug: None
Change-Id: I40f3089b034abfd4873e81c0b6216a7cfd977d8d
2017-07-13 10:29:20 -07:00
Dan Albert
5f78abdbd8 Merge changes from topic 'locale-android-support'
am: 2d585e0070

Change-Id: I993d7f4c2bd448aa11f0ad30d6db4cba625cb590
2017-07-13 08:37:05 +00:00
Dan Albert
2d585e0070 Merge changes from topic 'locale-android-support'
* changes:
  Add a non-TLS slot implementation of locale.cpp.
  Move non-locale.h APIs out of locale.cpp.
2017-07-13 08:34:57 +00:00
Dan Albert
1a8b7f2d1c Add a non-TLS slot implementation of locale.cpp.
libandroid_support shouldn't be using Bionic's TLS slot. Add a
thread_local based implementation. We can't use the thread_local
implementation in bionic because the linker needs this and pthread
thread-locals (which is how thread_local is implemented) doesn't work
that early.

Test: make checkbuild
Test: adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
Bug: https://github.com/android-ndk/ndk/issues/300
Change-Id: I7dcbf554ade2264d541d722fa3f86df04926e67a
2017-07-12 13:47:42 -07:00
Dan Albert
e2fd01035b Move non-locale.h APIs out of locale.cpp.
libandroid_support only needs the locale.h stuff.

Test: make checkbuild
Bug: None
Change-Id: I0c53fe9d2df4f9ff4b99771727034508bc89cb32
2017-07-12 12:41:47 -07:00
Elliott Hughes
7532b32627 Replace killpg.
Upstream's killpg is diverging further from glibc behavior, so let's just fork.

Bug: N/A
Test: ran tests
Change-Id: I70a3543018bc0a5c0bbf019ac527043b90568fda
2017-07-11 15:00:17 -07:00
Victor Khimenko
ea426865a8 Merge "Move environ valiable into it's own file"
am: 73d17e7720

Change-Id: I9b9533f7e3a70aa5b1e917953b51cc73d7881f32
2017-07-10 22:46:44 +00:00
Victor Khimenko
73d17e7720 Merge "Move environ valiable into it's own file" 2017-07-10 22:33:54 +00:00
Elliott Hughes
0969d4609c Merge "Make inline tcsetattr definition match constants."
am: e76ff925df

Change-Id: Ia6a48c54ac793c510ff2ab5559b920dd84ff02b9
2017-07-10 20:50:34 +00:00
Victor Khimenko
0a0743f864 Move environ valiable into it's own file
Test: build statically the example program below

  char** environ;
  int main() {
  }

Change-Id: I3f01652da1d5063d92ba7cbff7fb09bd0a89325c
2017-07-10 21:44:17 +02:00
Elliott Hughes
1449974d27 Make inline tcsetattr definition match constants.
Before this change we have the old NDK inline termios functions with the
modern constants. Unfortunately the old NDK inline functions relied on
hacking the constants. Fix things by sharing the implementation between
the platform and the NDK headers.

Bug: https://github.com/android-ndk/ndk/issues/441
Test: ran tests
Change-Id: I2773634059530bc954167f29c4783413a2294d5a
2017-07-05 12:00:29 -07:00
George Burgess IV
f437c90407 Merge "bionic: fix assorted static analyzer warnings"
am: e202036e03

Change-Id: I88dce02b7f483fb7bc2819406d800d5056c2fc48
2017-06-29 16:34:13 +00:00
George Burgess IV
705910094d bionic: fix assorted static analyzer warnings
Warnings:

bionic/libc/bionic/fts.c:722:5: warning: Null passed to a callee that
requires a non-null 1st parameter

bionic/libc/bionic/sched_cpualloc.c:34:25: warning: Result of 'malloc'
is converted to a pointer of type 'cpu_set_t', which is incompatible
with sizeof operand type 'unsigned long'

bionic/linker/linker_main.cpp:315:7: warning: Access to field 'e_type'
results in a dereference of a null pointer (loaded from variable
'elf_hdr')

bionic/linker/linker_main.cpp:493:66: warning: Access to field 'e_phoff'
results in a dereference of a null pointer (loaded from variable
'elf_hdr')

bionic/linker/linker_main.cpp:90:14: warning: Access to field 'next'
results in a dereference of a null pointer (loaded from variable 'prev')

Bug: None
Test: mma; analyzer warnings are gone. CtsBionicTestCases pass.
Change-Id: I699a60c2c6f64c50b9ea06848a680c98a8abb44a
2017-06-28 15:03:15 -07:00
Stephen Crane
ff5a101adf Merge "Disable stack protector for __libc_preinit" am: 814e3a2b31
am: aca18a3d3a

Change-Id: Id1d3447b37dd37aec7d82c757eb87b2cc1fe2d08
2017-06-22 01:47:27 +00:00
Stephen Crane
f4b1cbda4a Disable stack protector for __libc_preinit
__libc_preinit sets up the stack protector global cookie value, and thus
cannot intialize a stack protector cookie for itself in the function
prologue. LTO compilation can inline functions requiring a stack
protector into __libc_preinit. This patch disables stack protection for
__libc_preinit and forces all potentially inlined functions into a
helper that can have a stack protector.

Test: run bionic-unit-tests

Change-Id: I45911611190f216c91eb6feff722967214c5f99f
2017-06-21 23:53:46 +00:00
Elliott Hughes
02a12a3fd4 Merge "Shave another uninteresting stack frame off aborts." am: e300bf837f
am: 14dddaef5a

Change-Id: I364afd38ee1112cac0bc30232bdb43e4f31c0e17
2017-06-21 00:32:19 +00:00
Elliott Hughes
d7c52625f2 Shave another uninteresting stack frame off aborts.
With this, stack frame 0 is the abort, not tgkill.

arm:

     #00 pc 0001a41c  /system/lib/libc.so (abort+63)

arm64:

     #00 pc 000000000001d75c  /system/lib64/libc.so (abort+120)

Also "include what you use" for <sys/syscall.h>.

Bug: N/A
Test: ran `crasher abort` and `crasher64 abort`
Change-Id: I6517ac67b39b4133e890d52efc115071c812958b
2017-06-20 14:58:16 -07:00
Elliott Hughes
069be703ff Merge "Move a <wchar.h> implementation detail into the implementation." am: 0bd23e4706
am: 1c9325d8f7

Change-Id: I26bb23ea144f72cf3922a390554cf3179b663b51
2017-06-15 21:45:07 +00:00
Elliott Hughes
e2d4663b27 Move a <wchar.h> implementation detail into the implementation.
No other C library expose these, and I couldn't find any callers.

Bug: http://b/62531921
Test: builds
Change-Id: I4a3505bc0897286a4036c48066b98d16665b573a
2017-06-15 10:37:26 -07:00
Elliott Hughes
edc195b403 Merge "Remove volatile from the __errno declaration." am: 7f6bcc4780
am: ccc97f46d3

Change-Id: Ied1902ae342999dc7e344528570793d711946d3c
2017-06-14 01:03:36 +00:00
Treehugger Robot
7f6bcc4780 Merge "Remove volatile from the __errno declaration." 2017-06-14 00:44:33 +00:00
Elliott Hughes
e452cb1ff3 Remove volatile from the __errno declaration.
This breaks code that declares `errno` itself for whatever crazy reason:

  b.c:22:12: error: conflicting types for '__errno'
  extern int errno;
             ^
  /usr/local/google/ndkports/toolchain/bin/../sysroot/usr/include/errno.h:47:20: note: expanded from macro 'errno'
  #define  errno   (*__errno())
                     ^
  /usr/local/google/ndkports/toolchain/bin/../sysroot/usr/include/errno.h:44:15: note: previous declaration is here
  volatile int* __errno(void) __attribute_const__;
                ^

Bug: N/A
Test: built various bits of GNU source
Change-Id: I27c03bf3bde419a001f98f1ea6c267c847f31271
2017-06-13 16:02:07 -07:00
Goran Ferenc
12678c583c Merge "MIPS: 32/64-bit VDSO support" am: 72c8fce6c9 am: d32465b255
am: 85fb061c24

Change-Id: Idc1b6422a1c3213d0c746e135f6c15b49fc5dbc8
2017-06-01 17:59:47 +00:00
Goran Ferenc
996f6decfa MIPS: 32/64-bit VDSO support
File libc/SYSCALLS.TXT is updated to generate bionic's system call wrappers
for clock_gettime() & gettimeofday() that will be called if kernel vdso
implementations fail to execute.
The system call wrappers are generated using a python script gensyscalls.py.

Since all architectures support vdso now, there is no more need for conditional
statements regarding supported architectures in libc/bionic/vdso.cpp &
libc/private/bionic_vdso.h files.

Test: builds
Change-Id: I7213f29c179a7929851499d78a72900638ae861a
Signed-off-by: Goran Ferenc <goran.ferenc@imgtec.com>
2017-06-01 08:50:57 -07:00
Mikhail Lappo
620834f8b4 Merge "Va_end should be used with va_start" am: 137a2cf967 am: c29146f9d0
am: 4b0c81661b

Change-Id: Iff6b2d83e33badd2b7fa46e265b5399141120e98
2017-05-20 22:22:26 +00:00
Mikhail Lappo
13ec1cf3da Va_end should be used with va_start
va_start is used and va_end should
be invoked accordingly

Change-Id: I2b0a2af762e22082a351a4d8139aaa48bc791e88
2017-05-20 13:20:41 -07:00
Sandeep Patil
c5f4e9aa59 Merge "properties: do not fail in the absence of vendor properties" into oc-dev
am: f80c5595aa

Change-Id: I5207895e7c85e9179be16caffdbe894bf1f111df
2017-05-18 18:57:08 +00:00
Sandeep Patil
03ed4afec4 properties: do not fail in the absence of vendor properties
/vendor is not mounted in recovery and so the property initialization
must not fail if the vendor property context is not found.

Bug: 38212419
Test: boot into recovery, mount system and run adb shell getprop

Change-Id: I9f7c2fe2b20da86194eff8e7bf94b2352e50bf27
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-05-17 16:26:59 -07:00
Christopher Ferris
a1c0d2fd4c Add support for modifying decay timer.
Add the mallopt function, and only a single option so far.

Bug: 36401135

Test: Built and booted bullhead.
Test: Ran jemalloc unit tests.
Test: Ran bionic unit tests.
Test: Ran a test that allocated and free'd a large piece of memory,
Test: and verified that after changing the parameter, the PSS
Test: sticks around (decay timer set to 1), the PSS is purged (decay
Test: timer set to 0).
Change-Id: I6927929b0c539c1023d34772d9e26bb6a8a45877
2017-05-15 16:59:16 -07:00
Elliott Hughes
dfcb82d92d Clean up __isthreaded.
__isthreaded is annoying for ARC++ and useless for everyone. Just hard-code
the value in ndk_cruft for LP32 and be done with it.

Bug: N/A
Test: builds
Change-Id: I08f11a404bbec55ed57cb1e18b5116163c7d7d13
2017-05-11 15:29:03 -07:00
Josh Gao
d9a741c028 Make raise/abort work with stale cached pid/tid values.
Switch raise to using tgkill with direct syscalls of getpid/gettid,
and switch abort to use raise(SIGABRT).

Bug: http://b/37769298
Test: debuggerd_test
Change-Id: If6f9d17fd8ae6177e742dc9f2f44bd78539431ba
(cherry picked from commit bf2af69fb2)
2017-05-10 16:42:04 -07:00
Elliott Hughes
9ae23720aa Cope with AT_SYSINFO not being set on x86.
Bug: http://b/38034461
Test: ran dexdump under valgrind on x86
Change-Id: I6a54c7ed4fe4e68731e099d9569ab788379820f8
2017-05-09 14:26:30 -07:00
Josh Gao
bf2af69fb2 Make raise/abort work with stale cached pid/tid values.
Switch raise to using tgkill with direct syscalls of getpid/gettid,
and switch abort to use raise(SIGABRT).

Bug: http://b/37769298
Test: debuggerd_test
Change-Id: If6f9d17fd8ae6177e742dc9f2f44bd78539431ba
2017-05-05 14:25:24 -07:00
Christopher Ferris
7a3681e5b6 Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.

Change the names of the functions to reflect the new name of the library.

Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.

Bug: 31919199

Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
2017-05-03 08:50:43 -07:00
Elliott Hughes
7ba2bed0b2 Make unified headers' SIGRTMIN/SIGRTMAX usable before API 21.
Bug: https://github.com/android-ndk/ndk/issues/352
Test: built new NDK test
Change-Id: Iacebe574bbf693701949e038005a40ba6520d592
2017-04-26 14:34:36 -07:00
Treehugger Robot
7b37fa9384 Merge "Move bionic_systrace.cpp over to CachedProperty." 2017-04-18 17:56:07 +00:00
Elliott Hughes
a0e5d06c80 Un-deprecated __system_property_find_nth.
Netflix was using this, and looking the header file, although
__system_property_find_nth has been available since the beginning of time,
__system_property_foreach only appeared in 16. So anyone who wants to run
on pre-JellyBean devices would want to use __system_property_find_nth.

It's pretty much a one-liner in terms of __system_property_foreach anyway,
so it doesn't cost us anything to keep it.

Also restore slightly better tests than we originally removed.

Bug: http://b/36566667
Test: ran tests

(cherry picked from commit 438e01940b)

Change-Id: I639f2142ad4ba049b990b13ccccd255be4b4f479
2017-04-17 17:16:44 -07:00
Treehugger Robot
57e7a0d853 Merge "Un-deprecated __system_property_find_nth." 2017-04-17 23:45:57 +00:00
Elliott Hughes
438e01940b Un-deprecated __system_property_find_nth.
Netflix was using this, and looking the header file, although
__system_property_find_nth has been available since the beginning of time,
__system_property_foreach only appeared in 16. So anyone who wants to run
on pre-JellyBean devices would want to use __system_property_find_nth.

It's pretty much a one-liner in terms of __system_property_foreach anyway,
so it doesn't cost us anything to keep it.

Also restore slightly better tests than we originally removed.

Bug: http://b/36566667
Test: ran tests
Change-Id: Id268c2c2e848da17bb0a5a5420af234d9dcb829a
2017-04-17 14:53:07 -07:00
Elliott Hughes
e4ddb3c587 Move bionic_systrace.cpp over to CachedProperty.
This is the last bionic caller that was manually trying to cache
property values.

Bug: N/A
Test: builds and boots
Change-Id: Id66c0a05d8448f08c39dbf7189241e75615d44b4
2017-04-17 14:12:25 -07:00
Elliott Hughes
ef2b2fe99e Link to the public post about clang FORTIFY.
Bug: N/A
Test: builds
Change-Id: I1c2040fdd3c3bbe61a8adfc1f414fce50087a1b8
2017-04-16 08:50:58 -07:00
Tom Cherry
be4232be84 Report the right error code from PropertyServiceConnection()
We're currently reporting errno from the clean up call to close(),
which is much less interesting than the failing connect() call that
precedes it.  This change reports errno from the connect() call
instead.

Bug: 36249702
Test: Boot bullhead, bionic unit tests
Test: Fake bad end point and see relevant error returned
Change-Id: Icadec463f50cd0a2a2faa08f049a7996cd32786f
2017-04-14 14:41:10 -07:00
Treehugger Robot
2be8013027 Merge "Move libc_logging.cpp over to CachedProperty." 2017-04-12 19:02:14 +00:00
Elliott Hughes
a7afa0285b Don't let missing Treble property context files affect errno.
User code on a non-treble device was starting with errno == ENOENT rather
than 0 because of this treble support:

  openat(AT_FDCWD, "/property_contexts", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
  faccessat(AT_FDCWD, "/system/etc/selinux/plat_property_contexts", R_OK) = -1 ENOENT (No such file or directory)

This caused us to fail some toybox tests by reporting bogus errno values
where errno should have been left unset:

  PASS: date -d @0
  FAIL: date -d @0x123
  echo -ne '' | TZ=UTC date -d @0x123 2>&1
  --- expected
  +++ actual
  @@ -1 +1 @@
  -date: bad date '@0x123'
  +date: bad date '@0x123': No such file or directory
  PASS: date -d 06021234
  PASS: date -d 060212341982
  FAIL: date -d 123
  echo -ne '' | TZ=UTC date -d 123 2>&1
  --- expected
  +++ actual
  @@ -1 +1 @@
  -date: bad date '123'
  +date: bad date '123': No such file or directory
  PASS: date -d 1110143115.30
  PASS: date -d 111014312015.30
  PASS: date Unix time missing @

Bug: http://b/37248982
Test: ran tests

(cherry picked from commit 7ade61cae2)

Change-Id: I4c680da14f3df16dc5a9884071e48f3221ad3b3b
2017-04-11 17:05:01 -07:00
Elliott Hughes
87ff82466c Move libc_logging.cpp over to CachedProperty.
Bug: N/A
Test: ran tests
Change-Id: I50f9065799e783df961e1275a4cda671fcf0fd32
2017-04-11 15:18:38 -07:00
Elliott Hughes
7ade61cae2 Don't let missing Treble property context files affect errno.
User code on a non-treble device was starting with errno == ENOENT rather
than 0 because of this treble support:

  openat(AT_FDCWD, "/property_contexts", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
  faccessat(AT_FDCWD, "/system/etc/selinux/plat_property_contexts", R_OK) = -1 ENOENT (No such file or directory)

This caused us to fail some toybox tests by reporting bogus errno values
where errno should have been left unset:

  PASS: date -d @0
  FAIL: date -d @0x123
  echo -ne '' | TZ=UTC date -d @0x123 2>&1
  --- expected
  +++ actual
  @@ -1 +1 @@
  -date: bad date '@0x123'
  +date: bad date '@0x123': No such file or directory
  PASS: date -d 06021234
  PASS: date -d 060212341982
  FAIL: date -d 123
  echo -ne '' | TZ=UTC date -d 123 2>&1
  --- expected
  +++ actual
  @@ -1 +1 @@
  -date: bad date '123'
  +date: bad date '123': No such file or directory
  PASS: date -d 1110143115.30
  PASS: date -d 111014312015.30
  PASS: date Unix time missing @

Bug: http://b/37248982
Test: ran tests
Change-Id: Iacf08c89dbe207ec53a7837e6ac7f78f5541ef35
2017-04-11 13:38:36 -07:00
George Burgess IV
bd3d2088d9 libc: add const-correct string.h overloads
libcxx provides const-correct overloads for a few string.h functions.
These overloads use clang's enable_if attribute, so they're preferred
over our FORTIFY'ed equivalents.

This weakens _FORTIFY_SOURCE=2 when used with some of these functions,
since clang needs to see __pass_object_size in order to pass an accurate
result for __builtin_object_size(s, 1) at a callsite. Since those
functions don't have __pass_object_size on their params, clang can't do
that. This makes LLVM lower the __builtin_object_size calls, which means
we get the same result as __builtin_object_size(s, 0).

We have to provide all of the overloads in Bionic, since enable_if is
only used to disambiguate overloads with (otherwise) the same type. In
other words:

// overload 1
char *strchr(const char *, int s) __attribute__((enable_if(1, "")));
// overload 2
char *strchr(char *, int s);

void foo() {
  char cs[1] = {};
  strchr(static_cast<const char *>(cs), '\0'); // calls overload #1.
  strchr(cs, '\0'); // calls overload #2.
}

Bug: 34747525
Test: m checkbuild on bullhead internal master + AOSP. vts -m
BionicUnitTests passes on both. Surprisingly, the only code that this
seems to break is contained in Bionic.

Change-Id: Ie406f42fb3d1c5bf940dc857889876fc39b57c90
2017-04-05 13:17:07 -07:00
Josh Gao
01e04f515e Break android_set_abort_message out of libc_logging.
libc_logging is getting statically linked into the crash handler
library, resulting in two copies of the abort message code existing in
processes, one in the linker, and one in the crash handler.

Move android_set_abort_message to its own file to solve this.

Bug: http://b/36862204
Test: /data/nativetest/debuggerd_test/debuggerd_test32
Change-Id: Ie198c5a3bb07645aa43296915c9a6752693f14a9
(cherry picked from commit 10ec9286ae)
2017-04-03 17:47:51 -07:00
Josh Gao
10ec9286ae Break android_set_abort_message out of libc_logging.
libc_logging is getting statically linked into the crash handler
library, resulting in two copies of the abort message code existing in
processes, one in the linker, and one in the crash handler.

Move android_set_abort_message to its own file to solve this.

Bug: http://b/36862204
Test: /data/nativetest/debuggerd_test/debuggerd_test32
Change-Id: Ie198c5a3bb07645aa43296915c9a6752693f14a9
2017-04-03 16:00:10 -07:00
Nick Kralevich
62c03a4ff4 Cleanup ANDROID_DNS_MODE and BIONIC_DNSCACHE
For security reasons, when a binary is executed which causes a security
transition (eg, a setuid binary, setgid binary, filesystem capabilities,
or SELinux domain transition), the AT_SECURE flag is set. This causes
certain blacklisted environment variables to be stripped before the
process is executed. The list of blacklisted environment variables is
stored in UNSAFE_VARIABLE_NAMES. Generally speaking, most environment
variables used internally by libc show up in this list.

Add ANDROID_DNS_MODE to the list of unsafe variables.
Similar to RESOLV_HOST_CONF and RES_OPTIONS (which are already
blacklisted), this variable controls how name resolution requests are
handled. Allowing ANDROID_DNS_MODE to be set across a security
boundary could induce resolution failures or otherwise impact
name resolution.

Remove BIONIC_DNSCACHE. This does not appear to be used, and setting
this variable across a security boundary could cause name resolution
problems.

Test: Android compiles and runs with no obvious problems.
Change-Id: I835a7b42d6afbc9c67866594c7951cfd9b355d81
2017-04-03 08:44:38 -07:00
Elliott Hughes
842423911f Fix x86 system calls made from ELF preinit.
Used by CFI, so broke cfi_test#early_init@x86, but I've added a specific
test for this (and a similar test for getauxval from preinit, which this
patch does not fix).

Bug: http://b/35885875
Test: ran tests

(cherry picked from commit eb04ed506f)

Change-Id: Ie9da1bf4c2dcc23be7d75c739ae8549309813f88
2017-03-29 16:15:08 -07:00
Elliott Hughes
12a07044db Merge "Fix x86 system calls made from ELF preinit." 2017-03-29 23:08:18 +00:00
Elliott Hughes
eb04ed506f Fix x86 system calls made from ELF preinit.
Used by CFI, so broke cfi_test#early_init@x86, but I've added a specific
test for this (and a similar test for getauxval from preinit, which this
patch does not fix).

Bug: http://b/35885875
Test: ran tests
Change-Id: I43885bedfb88c0a26b4474bd3c27a87dec7bbc97
2017-03-29 13:48:02 -07:00
Dimitry Ivanov
2a4a5e72f1 Add end() method to bionic's ScopedTrace class
Bug: http://b/27195126
Test: make
Change-Id: I8243629200606ca87b11cbd479ca093add42eb56
2017-03-20 12:45:55 -07:00
Josh Gao
cf96f35dd1 Merge changes from topic 'debuggerd_fallback'
* changes:
  linker_memory: allow fallback allocator to be turned on and off.
  Increase signal stack size on 32-bit to 16kB.
2017-03-09 22:03:31 +00:00
Treehugger Robot
b3b11edda1 Merge "Prefer property_contexts from /system & /vendor" 2017-03-09 19:20:55 +00:00
Josh Gao
415daa8cca Increase signal stack size on 32-bit to 16kB.
snprintf to a buffer of length PATH_MAX consumes about 7kB of stack.

Bug: http://b/35858739
Test: bionic-unit-tests --gtest_filter="*big_enough*"
Change-Id: I34a7f42c1fd2582ca0d0a9b7e7a5290bc1cc19b1
2017-03-08 16:43:59 -08:00
Alex Klyubin
176cf1f65b Prefer property_contexts from /system & /vendor
This changes system_properties' initialize_properties to prefer
loading property_contexts from /system/etc/selinux &
/vendor/etc/selinux, while falling back to the pre-existing behavior
of loading from /.

Test: Device with *_property_contexts in / boots up fine, no denials
      to do with properties, getprop -Z lists correct labels.
Test: Device with *_property_contexts in /system & /vendor, but not
      in /, boots up fine, no denials to do with properties,
      getprop -Z lists correct labels.
Test: Device with *_property_contexts in /system & vendor and with
      empty *_property_contexts in / boots up fine, no denials to do
      with properties, getprop -Z lists correct labels.
Bug: 36002573

Change-Id: I15174acdf89ee8f5a96acf1e38a54d4214df51ef
2017-03-08 15:28:29 -08:00
Josh Gao
5450f86b31 Fix leak of bionic TLS when threads are detached.
__pthread_internal_free doesn't happen on threads that are detached,
causing the bionic TLS allocation (and guard pages) to be leaked.

Fix the leak, and name the allocations to make things apparent if this
ever happens again.

Bug: http://b/36045112
Test: manually ran a program that detached empty threads
Change-Id: Id1c7852b7384474244f7bf5a0f7da54ff962e0a1
2017-03-07 23:24:50 -08:00
Victor Khimenko
4a92ffd302 Stop using __system_property_area__
Apparently that "backdoor" is no longer needed - the proper way is
to reinitialize properties:
    https://android-review.googlesource.com/#/c/181794/24/tests/system_properties_test.cpp

Also removes mentions of libnativehelper test (it no longer uses
__system_property_area__) and removes useless "extern" declaration
(actual use was removed long ago).

Test: refactoring CL, existsing tests still pass

BUG=21852512
BUG=34114501

Change-Id: I2223cab2fcb671ea180ad4470a7aba5c9cd20bd8
2017-03-01 20:43:42 +01:00
Dimitry Ivanov
6391e1a44d libc: __system_property_set uses writev to write atomically
__system_property_set sometimes produces broken_pipe error
when trying to write a property.

This change improves error messages and uses writev() instead
of sequence of send() calls.

Bug: http://b/35381074
Test: bionic-unit-tests --gtest_filter=prop*
Change-Id: I7a5b169c015db4e6b720370e58662de8206d1086
2017-02-24 14:00:04 -08:00
Hans Boehm
5d0c1fcc8b Merge "Replace cxa_guard fences with acquire loads" 2017-02-24 18:50:35 +00:00
Hans Boehm
963daed780 Replace cxa_guard fences with acquire loads
This seemed to be the only place in bionic where a fence on a
performance-critical path could be easily replaced by a stronger
load/store order constraint. Do so.

On x86 this should generate the same code either way. Based on
microbenchmarks of the relevant ARM instructions, this is currently
performance-neutral in this kind of context. But in the future, the
newly generated acquire loads should give us a performance benefit.

Test: Booted AOSP
Change-Id: I7823e11d6ae4fd58e0425244c293262e2320fd81
2017-02-23 11:50:58 -08:00
Josh Gao
5e2285d3cc Allocate thread local buffers in __init_tls.
Thread local buffers were using pthread_setspecific for storage with
lazy initialization. pthread_setspecific shares TLS slots between the
linker and libc.so, so thread local buffers being initialized in a
different order between libc.so and the linker meant that bad things
would happen (manifesting as snprintf not working because the
locale was mangled)

Bug: http://b/20464031
Test: /data/nativetest64/bionic-unit-tests/bionic-unit-tests
      everything passes
Test: /data/nativetest/bionic-unit-tests/bionic-unit-tests
      thread_local tests are failing both before and after (KUSER_HELPERS?)
Test: /data/nativetest64/bionic-unit-tests-static/bionic-unit-tests-static
      no additional failures
Change-Id: I9f445a77c6e86979f3fa49c4a5feecf6ec2b0c3f
2017-02-22 16:05:03 -08:00
Treehugger Robot
c9a840ac76 Merge "Add timeout support to __system_property_wait." 2017-02-22 01:43:31 +00:00
Elliott Hughes
40c885a4d1 Add timeout support to __system_property_wait.
Bug: http://b/35201172
Test: ran tests
Change-Id: I3a78813bf3cd50d1b308ecb3c742f923606c0cc4
2017-02-21 14:36:24 -08:00
Elliott Hughes
6ce686c48b Downgrade the special case of pthread_t(0) to a warning.
So far this is the only issue we've hit in vendor code, and we've hit
it several times already. Rather than try to fix bullhead (the current
problem), let's just admit that the special case of 0 is a lot less
worrying.

Also fix the test expectations to correspond to the new abort message.

Bug: http://b/35455349 (crashes on 0)
Bug: http://b/35622944 (tests)
Test: ran tests
Change-Id: Iec57011fa699a954ebeaec151db2193e36d1ef35
2017-02-21 14:21:43 -08:00
Elliott Hughes
b66a0038ca Fix a comment in the pthread_cond_t implementation.
Bug: http://b/34592766
Test: N/A
Change-Id: I341f837dca52865ae5f8fe9ff50ba8999e297179
2017-02-18 16:35:36 -08:00
Elliott Hughes
3fed6ff847 Include the pthread_t in the "bad pthread_t" fatal abort.
Also reword the message to be stronger.

Bug: http://b/35455349
Test: manual
Change-Id: I8f34fd42f3b635c95a7b921645a016fb303ce3ad
2017-02-17 10:27:45 -08:00
Josh Gao
fec0e015ce Merge "Add __libc_format_buffer_va_list." 2017-02-16 03:42:53 +00:00
Josh Gao
273991cead Add __libc_format_buffer_va_list.
Bug: http://b/35367169
Test: m
Change-Id: I133f231d3b93bdef56d06497679320a89c7188a9
2017-02-15 16:10:37 -08:00
Treehugger Robot
c54937b972 Merge "add fortified implementations of send/sendto" 2017-02-15 18:26:50 +00:00
Daniel Micay
95b59c520b add fortified implementations of send/sendto
Bug: None
Test: Bullhead builds+boots; CtsBionicTestCases passes.
Change-Id: I2f137a100f679f7f2145d84b2f29ddd3e96a36ae
2017-02-14 15:50:28 -08:00
Nick Kralevich
125f1c0f22 Add details on why AT_SYMLINK_NOFOLLOW is dangerous
The comment isn't helpful as-is. Provide some clarifying information.

Test: code compiles. No functional changes.
Change-Id: I5267e0bc68857fdc8a4b3384a2a1b0d37693ee6e
2017-02-14 12:55:15 -08:00
Elliott Hughes
0370905502 Merge "Be more strict about using invalid pthread_ts." 2017-02-14 18:32:18 +00:00
Elliott Hughes
11859d467c Be more strict about using invalid pthread_ts.
Another release, another attempt to remove the global thread list.

But this time, let's admit that it's not going away. We can switch to using
a read/write lock for the global thread list, and to aborting rather than
quietly returning ESRCH if we're given an invalid pthread_t.

This change affects pthread_detach, pthread_getcpuclockid,
pthread_getschedparam/pthread_setschedparam, pthread_join, and pthread_kill:
instead of returning ESRCH when passed an invalid pthread_t, if you're
targeting O or above, they'll abort with the message "attempt to use
invalid pthread_t".

Note that this doesn't change behavior as much as you might think: the old
lookup only held the global thread list lock for the duration of the lookup,
so there was still a race between that and the dereference in the caller,
given that callers actually need the tid to pass to some syscall or other,
and sometimes update fields in the pthread_internal_t struct too.

(This patch replaces such users with calls to pthread_gettid_np, which
at least makes the TOCTOU window smaller.)

We can't check thread->tid against 0 to see whether a pthread_t is still
valid because a dead thread gets its thread struct unmapped along with its
stack, so the dereference isn't safe.

Taking the affected functions one by one:

    * pthread_getcpuclockid and pthread_getschedparam/pthread_setschedparam
      should be fine. Unsafe calls to those seem highly unlikely.

    * Unsafe pthread_detach callers probably want to switch to
      pthread_attr_setdetachstate instead, or using
      pthread_detach(pthread_self()) from the new thread's start routine
      rather than doing the detach in the parent.

    * pthread_join calls should be safe anyway, because a joinable thread
      won't actually exit and unmap until it's joined. If you're joining an
      unjoinable thread, the fix is to stop marking it detached. If you're
      joining an already-joined thread, you need to rethink your design.

    * Unsafe pthread_kill calls aren't portably fixable. (And are obviously
      inherently non-portable as-is.) The best alternative on Android is to
      use pthread_gettid_np at some point that you know the thread to be
      alive, and then call kill/tgkill directly.

      That's still not completely safe because if you're too late, the tid
      may have been reused, but then your code is inherently unsafe anyway.

Bug: http://b/19636317
Test: ran tests
Change-Id: I0372c4428e8a7f1c3af5c9334f5d9c25f2c73f21
2017-02-13 17:59:29 -08:00
Elliott Hughes
a0d374d587 Add __system_property_wait and return the serial in __system_property_read_callback.
In order to implement android::base::WaitForProperty well, we need a way to
wait not for *any* property to change (__system_property_wait_any), but to
specifically wait for the property represented by a given `prop_info` to
change.

The android::base::WaitForProperty implementation, like attempts to cache
system properties in the past, also needs a way to keep serials and values
in sync, but the existing functions don't provide a cheap way to get a
consistent snapshot. Change the __system_property_read_callback callback's
type to include the serial corresponding to the given value.

Add a test, slightly clean up some of the existing tests (and name them to
include the names of the functions they're testing, in our usual style).

Bug: http://b/35201172
Test: ran tests
Change-Id: Ibc8ebe2e88eef1e333a1bd3dd7f68135f1ba7fb5
2017-02-13 13:30:10 -08:00
George Burgess IV
7cc779f15c libc: add clang FORTIFY support
This patch adds clang-style FORTIFY to Bionic. For more information on
FORTIFY, please see https://goo.gl/8HS2dW . This implementation works
for versions of clang that don't support diagnose_if, so please see the
"without diagnose_if" sections. We plan to swap to a diagnose_if-based
FORTIFY later this year (since it doesn't really add any features; it
just simplifies the implementation a lot, and it gives us much prettier
diagnostics)

Bug: 32073964
Test: Builds on angler, bullhead, marlin, sailfish. Bionic CTS tests
pass on Angler and Bullhead.

Change-Id: I607aecbeee81529709b1eee7bef5b0836151eb2b
2017-02-09 15:49:32 -08:00
Elliott Hughes
f201c704d6 Merge "Revert "Stop checking the global thread list in several trivial cases."" 2017-02-07 21:12:23 +00:00
Elliott Hughes
bcb152903a Revert "Stop checking the global thread list in several trivial cases."
This reverts commit f5a4992b71.

Breaks OMX_ImgEnc in cameraserver (http://b/35088254).

Change-Id: I6dcf12706a184b0b8b72451584567a42dfa1bb4f
2017-02-07 21:05:30 +00:00
Elliott Hughes
a1fa522927 Merge "Improve a comment." 2017-02-07 17:01:16 +00:00
Elliott Hughes
f5a4992b71 Stop checking the global thread list in several trivial cases.
Since removing the global thread is hard, let's take the different
groups of functions individually.

The existing code was racy anyway, because the thread might still be
on the list but have exited (leaving tid == 0).

Bug: http://b/19636317
Test: ran tests
Change-Id: Icc0986ff124d5f9b8a653edf718c549d1563973b
2017-02-06 14:09:53 -08:00
Elliott Hughes
5e6cf05aab Improve a comment.
Bug: http://b/23675822
Test: builds
Change-Id: Ia58ffabf38012035076e4c682faa4c93f3690e24
2017-02-06 10:26:20 -08:00
David James
a187a6f12e Merge "Revert "Remove the global thread list."" 2017-02-02 02:46:40 +00:00
Elliott Hughes
7484c21c4c Revert "Remove the global thread list."
This reverts commit b0e8c565a6.

Breaks swiftshader (http:/b/34883464).

Change-Id: I7b21193ba8a78f07d7ac65e41d0fe8516940a83b
2017-02-02 02:41:38 +00:00
Elliott Hughes
9b9d4ebc8b Merge "Remove the global thread list." 2017-02-01 16:16:41 +00:00
Elliott Hughes
8e7396c9d7 s/NULL/nullptr/ in system properties code.
gerrit still hasn't sent out the mail asking for this in an earlier code
review...

Bug: http://b/33926793
Test: builds and boots.
Change-Id: I080de633e50e47f9a052211d47da96b971b16424
2017-01-31 08:24:43 -08:00
Elliott Hughes
9160ed9bb7 clang-format system_properties.cpp.
Asked for on a previous code review.

Bug: http://b/33926793
Test: builds and boots.
Change-Id: Idf34804896149db5edbddf4ed88396a5df7f708a
2017-01-30 17:54:57 -08:00
Sandeep Patil
93e272d00a Merge "property_contexts: split into platform and non-platform components" 2017-01-30 19:16:17 +00:00
Elliott Hughes
f8562c5f8f Remove backwards compatibility for old system properties.
No-one is directly upgrading from pre-K to O...

Also move more implementation details out of the header file.

Bug: http://b/33926793
Test: boots
Change-Id: I7a0936acbb1cea8a3b2cd6797ec53ba7e4a050f3
2017-01-27 16:19:59 -08:00
Sandeep Patil
34f0cfa3a8 property_contexts: split into platform and non-platform components
Bug: 33746484
Bug: 34370523
Test: Successfully boot with original service and property contexts.
Test: Successfully boot with split serivce and property contexts.
Test: Incremental build works on sailfish (reported in b/34370523)
Test: adb sideload works with aosp updater (reported in b/34370523)

Change-Id: Idf24856193032a8bc89ec384a72451e578a9d5ac
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-01-27 13:12:32 -08:00
Dimitry Ivanov
cafd355375 Do not send 0 byte string content.
Trying to send even 0 bytes to closed socket leads to
broken pipe error. Sometimes property service is just
quick enough and closes the socket between send(valuelen)
and send(value) in the case where valuelen is 0.

Bug: http://b/34670529
Test: adb reboot 20 times and make sure phone service did not fail
Test: run bionic-unit-tests --gtest_filter=prop*
Change-Id: I96f90ca6fe1790614e7efd3015bffed1ef1e9040
2017-01-24 14:19:03 -08:00
Dimitry Ivanov
16b2a4de14 Revert "Revert "Remove limit of system property name length""
This reverts commit 489f58b5ea.
Bug: http://b/33926793
Bug: http://b/34670529
Test: Run bionic-unit-tests --gtest_filter=prop*

Change-Id: Id4e94652dc2310a21f5b7bd3af098bf79df3f380
2017-01-24 12:58:18 -08:00
Dimitry Ivanov
489f58b5ea Revert "Remove limit of system property name length"
This reverts commit 5c1ce278f3.
Bug: http://b/33926793
Bug: http://b/34670529

Change-Id: I0dc4a8ae55576c69b34b2958d8e664f7066b9c54
2017-01-24 18:39:04 +00:00
Dimitry Ivanov
5c1ce278f3 Remove limit of system property name length
This change introduces new __system_property_read_callback
method to use in place of deprecated __system_property_read
__system_property_set() and get() should just work but now
do not have limit on system property names.

Bug: http://b/33926793
Test: boot device, run adb shell propget
Test: boot device with old version of init (protocol v1)
Test: run bionic-unit-tests --gtest_filter=prop*
Change-Id: I619fb5a7e27a272aac30011579665f6160888bc7
2017-01-23 11:21:18 -08:00
Josh Gao
f8a6d4745d Reserve a realtime signal for debuggerd.
Allocate __SIGRTMIN + 3 for triggering native stack dumps (like SIGQUIT
for Java processes).

Bug: http://b/30705528
Test: debuggerd_test
Change-Id: I81d622fba32a651555268a8a2ba6721c61c93a58
2017-01-17 13:55:18 -08:00
Treehugger Robot
907fcc98b2 Merge "Hide __system_property_add/update, deprecate find_nth" 2017-01-11 01:57:56 +00:00
Dimitry Ivanov
581b9f661b Hide __system_property_add/update, deprecate find_nth
These functions are supposed to be used only by the
property service.

__system_property_find_nth is deprecated and no longer part
of NDK. Call to this function will result in abort for apps
targeting Android O.

Bug: http://b/34114501
Test: bionic-unit-tests --gtest_filter=prop*
Change-Id: I9846965bf248e2ddf45cd7b293618245bbd87145
2017-01-10 13:41:27 -08:00
Elliott Hughes
940d460f59 Merge "Revert "Revert "move android_ids into bionic""" 2017-01-10 01:15:30 +00:00
Elliott Hughes
b0e8c565a6 Remove the global thread list.
Another release, another attempt to fix this bug.

This change affects pthread_detach, pthread_getcpuclockid,
pthread_getschedparam/pthread_setschedparam, pthread_join, and pthread_kill:
instead of returning ESRCH when passed an invalid pthread_t, they'll now SEGV.

Note that this doesn't change behavior as much as you might think: the old
lookup only held the global thread list lock for the duration of the lookup,
so there was still a race between that and the dereference in the caller,
given that callers actually need the tid to pass to some syscall or other,
and sometimes update fields in the pthread_internal_t struct too.

We can't check thread->tid against 0 to see whether a pthread_t is still
valid because a dead thread gets its thread struct unmapped along with its
stack, so the dereference isn't safe.

Taking the affected functions one by one:

* pthread_getcpuclockid and pthread_getschedparam/pthread_setschedparam
  should be fine. Unsafe calls to those seem highly unlikely.

* Unsafe pthread_detach callers probably want to switch to
  pthread_attr_setdetachstate instead, or using pthread_detach(pthread_self())
  from the new thread's start routine rather than doing the detach in the
  parent.

* pthread_join calls should be safe anyway, because a joinable thread won't
  actually exit and unmap until it's joined. If you're joining an
  unjoinable thread, the fix is to stop marking it detached. If you're
  joining an already-joined thread, you need to rethink your design.

* Unsafe pthread_kill calls aren't portably fixable. (And are obviously
  inherently non-portable as-is.) The best alternative on Android is to
  use pthread_gettid_np at some point that you know the thread to be alive,
  and then call kill/tgkill directly. That's still not completely safe
  because if you're too late, the tid may have been reused, but then your
  code is inherently unsafe anyway.

If we find too much code is still broken, we can come back and disable
the global thread list lookups for anything targeting >= O and then have
another go at really removing this in P...

Bug: http://b/19636317
Test: N6P boots, bionic tests pass
Change-Id: Ia92641212f509344b99ee2a9bfab5383147fcba6
2017-01-07 14:16:46 -08:00
Nick Kralevich
bb59d47249 Make /dev/__properties__ 0711
Don't allow processes to read the contents of the directory
/dev/__properties__. This is an implementation detail of the properties
system that processes shouldn't be concerned with.

Test: Device boots and no problems reading individual properties.
Test: ls -la /dev/__properties__ fails
Change-Id: I00130fe4529525935654bff91e3cc59253b86e26
2017-01-06 12:07:20 -08:00
Josh Gao
d3cfd26872 Add declaration of tgkill to signal.h.
Expose a useful function that we've had since Jelly Bean.

Bug: http://b/34111810
Test: TreeHugger
Change-Id: Iaf3097f224c09b533f36050cf21394ba148007ad
2017-01-05 15:15:12 -08:00
Jeff Sharkey
54891837a0 Merge "Define range of GIDs for cached app data." 2016-12-15 21:46:30 +00:00
Elliott Hughes
0ff61f6d19 Make the __stack_chk_fail message more searchable on the internets.
Noticed while writing documentation:

  https://source.android.com/devices/tech/debug/

Bug: http://b/28746168
Test: crasher
Change-Id: Ied1c1b1c75a85a899f07e6927134b9bf91316fe4
2016-12-14 17:30:07 -08:00