Commit graph

1388 commits

Author SHA1 Message Date
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
Elliott Hughes
3f6eee9793 Revert "Revert "move android_ids into bionic""
This reverts commit 77cb68d9f2.

Change-Id: Ibc9f775c4cd418be90fd8a6f192dd72ca5dff09a
2016-12-13 23:47:25 +00:00
Jeff Sharkey
934bc86df3 Define range of GIDs for cached app data.
To support upcoming disk usage calculation optimizations, this change
creates a new GID for each app that will be used to mark its cached
data.  We're allocating these unique GIDs so that we can use
quotactl() to track cached data on a per-app basis.

Test: builds, boots, tests pass
Bug: 27948817
Change-Id: Ic00c39ccedc23d5d43988029e9921679126f8f2d
2016-12-13 14:22:55 -07:00
Treehugger Robot
50ae6dde5b Merge "Revert "move android_ids into bionic"" 2016-12-13 00:31:25 +00:00
Elliott Hughes
77cb68d9f2 Revert "move android_ids into bionic"
This reverts commit 1a13db5b26.

Change-Id: I7f571b3a9d542694d16fb9cf1131ef9e59d330ea
2016-12-12 22:11:37 +00:00
Elliott Hughes
ded6c91acc Merge "move android_ids into bionic" 2016-12-10 00:13:05 +00:00
Elliott Hughes
722d01a991 Fix icu4c calling on x86.
Some of the function pointer types were wrong, and x86 cares if you
say `int` when you meant `int8_t` (because it feels at liberty to
leave the top bits dirty and ignore them, both sides need to agree
which they're dealing with).

Also slightly improve the wcstoimax and wcstoumax tests, since my
investigation started there.

Bug: http://b/33451822
Test: tests pass on x86, arm, and arm64
Change-Id: I553193962f0cb993666f9f8e415990bba5b669e1
2016-12-08 15:16:37 -08:00
Dan Albert
f634655e64 Fix wcsto* where strings begin with whitespace.
The libc++ tests caught this.

Test: adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
Bug: None
Change-Id: I14864e006f6cf9de3f96acac6aa3eb235894f2b1
2016-12-02 13:03:30 -08:00
Elliott Hughes
cf922ff804 Merge "Clean up <sys/limits.h> a bit." 2016-12-01 03:08:44 +00:00
Elliott Hughes
68ddf5cad3 Merge "Abort harder." 2016-11-30 23:06:26 +00:00
Evgenii Stepanov
f347046f2d Merge changes Iade6a185,Iab3050bd
* changes:
  Cleanup: replace sanitize:never with address:false.
  Add __libc_arc4random_unlimited_entropy.
2016-11-30 21:34:05 +00:00
William Roberts
1a13db5b26 move android_ids into bionic
Generate the android_ids array and include into the
build.

Test: The bionic is built and that core AIDs work as
expected with commands like chown, mkdir and init services
and builtins.
Bug: 27999086
Change-Id: Ib575bf85326c91801c5674db475dcb9cf44c00dc
Signed-off-by: William Roberts <william.c.roberts@intel.com>
2016-11-30 12:54:08 -08:00
Elliott Hughes
9af74907d1 Clean up <sys/limits.h> a bit.
<sys/limits.h> shouldn't even exist, but leave it in for backwards
compatibility.

Everything that seems legit moves to <limits.h>, though it still seems
like a lot of that ought to come from the compiler instead (there's even
an angry rant in the clang header to that effect).

Unfortunately, we've long exposed [a copy and paste of] the contents
of <float.h> from <limits.h> and <sys/limits.h>. This patch preserves
that for backwards compatibility, but at least switches us over to
using the real <float.h> instead.

Bug: http://b/32776472
Test: builds
Change-Id: I2d5b3b5237b3a0442195e99bb967c076ce484f35
2016-11-30 09:06:53 -08:00
Elliott Hughes
4bf5522662 Abort harder.
Some PoS internal system can't cope with more than 4 stack frames,
so the fact that our abort(3) implementation takes 4 frames by itself
makes it useless.

Re-reading POSIX, it only says "behaves as if", so the previous
implementation chain wasn't mandatory and we can just go straight to
calling tgkill...

Before:

     #00 pc 0000000000069be4  /system/lib64/libc.so (tgkill+8)
     #01 pc 0000000000066d50  /system/lib64/libc.so (pthread_kill+64)
     #02 pc 0000000000028110  /system/lib64/libc.so (raise+24)
     #03 pc 000000000001d4ec  /system/lib64/libc.so (abort+52)

After:

     #00 pc 0000000000069bc8  /system/lib64/libc.so (tgkill+8)
     #01 pc 000000000001d4c8  /system/lib64/libc.so (abort+80)
     #02 pc 0000000000001494  /system/xbin/crasher64 (_ZL9do_actionPKc+872)
     #03 pc 00000000000010e0  /system/xbin/crasher64 (main+88)

This is less useful on 32-bit ARM because there there's an extra trampoline
from an assembler abort(3) implementation, so you'll still only get one
meaningful stack frame. But every other architecture will now get two!

But wait!

It turns out that the assembler hack isn't needed any more. Here we are
unwinding just fine all the way through the 32-bit ARM crasher:

Before (with direct call to tgkill but still using the assembler):

     #00 pc 00049e7c  /system/lib/libc.so (tgkill+12)
     #01 pc 00019c6f  /system/lib/libc.so (__libc_android_abort+50)
     #02 pc 000181f8  /system/lib/libc.so (abort+4)
     #03 pc 00001025  /system/xbin/crasher (_ZL9do_actionPKc+656)
     #04 pc 00017721  /system/lib/libc.so (__libc_init+48)
     #05 pc 00000b38  /system/xbin/crasher (_start+96)

After:

     #00 pc 00049e6c  /system/lib/libc.so (tgkill+12)
     #01 pc 00019c5f  /system/lib/libc.so (abort+50)
     #02 pc 00001025  /system/xbin/crasher (_ZL9do_actionPKc+656)
     #03 pc 00017721  /system/lib/libc.so (__libc_init+48)
     #04 pc 00000b38  /system/xbin/crasher (_start+96)

(As you can see, the fact that we see __libc_init rather than main was true
with the assembler stub too, so that's not a regression even if it does seem
odd...)

Bug: N/A
Test: ran crasher64
Change-Id: I9dd5b214c495604c8b502c7ec0de3631080d8c29
2016-11-29 22:02:25 -08:00
Treehugger Robot
609880c12f Merge "Fix getpriority/setpriority types." 2016-11-30 05:49:03 +00:00
Josh Gao
585fc3e554 Add __libc_arc4random_unlimited_entropy.
Let the caller know when libc has an entropy source and arc4random is safe.
This is useful for the callers that want entropy, but don't absolutely need it.

Bug: http://b/27729263
Test: booted angler-userdebug w/ safestack
Change-Id: Iab3050bd19f23518e1676629573eebc656ba1090
2016-11-29 15:26:08 -08:00
Elliott Hughes
8f0e42fda6 Fix getpriority/setpriority types.
Bug: N/A
Test: builds
Change-Id: Ica099bae04a0260871783452811a54672094ba4a
2016-11-29 15:14:11 -08:00
Elliott Hughes
bd734f0716 Merge "Use icu4c to implement <wctype.h>." 2016-11-29 23:05:31 +00:00
Elliott Hughes
a57ca0da69 Use icu4c to implement <wctype.h>.
Pretty useless, because the POSIX APIs are useless for actually
internationalization, but it lets us put this to bed for good.

Bug: http://b/18492914
Test: bionic tests
Change-Id: I4dd0aff66c44b5547039be3ffea806c865b9014a
2016-11-29 19:19:30 +00:00
Elliott Hughes
86841573ed Merge "Implement <langinfo.h>." 2016-11-29 19:16:09 +00:00
Wei Wang
ae693ad06c bionic: make NONBLOCK call to getrandom
By default getrandom() blocks if the entropy pool has not yet been initialized.
This will be an issue when init was first executed in some kernels.

This CL makes a check of getrandom readyness, by adding the GRND_NONBLOCK flag.
In such case, getrandom() does not block returns -1 with errno set to EAGAIN.

Test: on M/S devices
Bug: 33059407
Change-Id: I2a2ba8372a5e1c336852ba2ab77cdaac03c90389
2016-11-23 15:10:52 -08:00
Elliott Hughes
fc8e688c32 Implement <langinfo.h>.
POSIX locale only, as usual.

The GNU YESSTR and NOSTR extensions return the empty string in the C locale,
so I haven't bothered supporting them.

Bug: http://b/1401872
Test: bionic tests
Change-Id: I6846839e4f9f1812344ed5dce0b93f83c0c20eb3
2016-11-19 11:46:54 -08:00
Christopher Ferris
c2395be74a Merge "Enable malloc debug using environment variables" 2016-11-18 21:33:18 +00:00
Tamas Berghammer
ac81fe8657 Enable malloc debug using environment variables
Previously malloc debug can be enabled only using global settings
accessible to the root user only. This CL adds a new option to enable
it using environment variables making it possible to use it with pure
native (shell) applications on production builds (from shell user) and
prepares it for using it from logwrapper on production devices.

Remove the old environment variable and property since they are not
necessary.

Test: Enable malloc debug using environment variable and verify
Test: that it only affects the commands launched from the shell.
Test: Enable malloc debug using the property variable and verify
Test: that it affects all commands.
Test: Run all unit tests in 32 bit and 64 bit.
Change-Id: Iecb75a3471552f619f196ad550c5f41fcd9ce8e5
2016-11-17 13:13:27 -08:00
Christopher Ferris
a5c16983a6 Merge "Fix iswlower/iswupper." 2016-11-17 20:06:05 +00:00
Elliott Hughes
5bc78c8bcd Add and use constants for the Android API levels.
Test: bionic tests still pass
Change-Id: If1b619cfc9db1d3f5d91f14f2ace71058dca0c4a
2016-11-16 16:55:42 -08:00
Elliott Hughes
f76a21a185 Fix iswlower/iswupper.
The previous conditions were just plain wrong.

Test: bionic tests
Change-Id: Ia6d98207b1ff98ea4c6f619912e4bcdb8a7fdd24
2016-11-16 15:19:08 -08:00
Wei Wang
0741d8d82d Fix getrandom syscall checking
Test: angler
Bug: 32838381
(cherry-picked from commit 46289b4c0211fc48d8719b385a7e56d765510ebd)

Change-Id: I102ffa26d7f39a8d3572b31f04b66ae31a9e752c
2016-11-15 16:53:37 -08:00
Elliott Hughes
f97b27a9c0 Merge "Differentiate the wctype functions we need to improve." 2016-11-15 19:04:25 +00:00
Elliott Hughes
98c6688d64 Differentiate the wctype functions we need to improve.
Some of these are genuinely fine as-is.

Test: bionic tests still pass
Change-Id: Iab6d86d818dcc5857e7932a9effa04001195386f
2016-11-14 12:55:59 -08:00
Treehugger Robot
cd9ce19e9c Merge changes I7f32dc9f,I9d88ddb1
* changes:
  Revert "Revert "Attempt to use arc4random where getauxval(AT_RANDOM) is used.""
  Revert "Revert "Update getentropy_linux.c from upstream.""
2016-11-11 22:20:18 +00:00
Josh Gao
a170d9bfc5 Revert "Revert "Attempt to use arc4random where getauxval(AT_RANDOM) is used.""
This reverts commit 60d052dda6.

Bug: http://b/27729263
Change-Id: I7f32dc9f9a1f21fda3213f10da940821e1bdd63f
2016-11-10 17:02:45 -08:00
Josh Gao
98d655ce96 Revert "Revert "Update getentropy_linux.c from upstream.""
This reverts commit b3fbee449c.

Bug: http://b/27729263
Change-Id: I9d88ddb11466d203514ae805f4681c92e4b63c24
2016-11-10 17:02:37 -08:00
Dimitry Ivanov
8bfaac0f8a Merge "Eliminate deadlock in forked child due to delayed resetting mutex lock" 2016-11-08 20:59:42 +00:00
Mingwei Shi
f6a21bfac5 Eliminate deadlock in forked child due to delayed resetting mutex lock
For some program implementation, the pattern like below, calling 
pthread_atfork to register atfork interfaces.

    pthread_atfork(&atfork_prepare, &atfork_parent, &atfork_child);

When the program is expected to reopen the shared library's handle 
inherited from parent in child process. Maybe, dlclose is called in 
atfork_child to release the shared library handle before reopen it. 
Then, dlclose will indrectly call _cxa_finalize and finaly call 
__unregister_atfork when dso is not NULL.

    atfork_child() -> dlclose() -> __on_dlclose() 
    	-> __cxa_finalize() -> __unregister_atfork(dso)

In __unregister_atfork, firstly, it try to hold the g_atfork_list_mutex 
lock to operate the g_atfork_list. Due to the registered atfork_child is
executed before resetting g_atfork_list_mutex lock in child, the child 
process will be blocked here because of deadlock.

Test: bionic-unit-tests32 --gtest_filter=pthread.pthread_atfork_child_with_dlclose 
without the fixing, the test will be timeout.

Change-Id: I35d3001682c836e0955d6d681bc5f9297fad0c7b
Signed-off-by: Mingwei Shi <mingwei.shi@intel.com>
Signed-off-by: Qiming Shi <qiming.shi@intel.com>
Signed-off-by: Chao Xie <chao.xie@intel.com>
2016-11-07 03:32:57 +00:00
Robert Sesek
e462117087 Set __get_thread()->tid as part of clone().
This was previously done only in fork() and pthread_create(), but this left raw
clone() with an invalid cached tid. Since the tid is used for pthread routines,
this led to unstable behavior after clone().

Test: ltp clone01 (see bug for more)
Test: mmma bionic/tests
Test: bionic-unit-tests-static --gtest_filter=*fork*:*clone*

Bug: 32612735
Bug: 32305649
Change-Id: I30eae5a8024b4c5da65476fcadfe14c6db35bb79
2016-11-04 16:57:20 -04:00
Treehugger Robot
8c22ff76e2 Merge "Fix gettid() after clone()." 2016-10-29 02:09:56 +00:00
Robert Sesek
a4edf7a57c Fix gettid() after clone().
The tid is cached in the pthread_internal_t and is properly re-set after fork()
and pthread_create(). But after a plain clone() the value is stale from the
parent.

Test: mmma bionic/tests
Test: bionic-unit-tests-static --gtest_filter=*fork*:*clone*
Test: m checkbuild tests
Test: angler boots

Bug: 32305649
Change-Id: I026d416d1537484cd3e05c8493a35e5ed2acc8ed
2016-10-28 12:14:23 -04:00
Elliott Hughes
53de874c3c The default locale "" should be a UTF-8 locale.
"ls -q" (or "adb shell -tt ls") was mangling non-ASCII because mbrtowc
was returning multibyte characters as their individual bytes. This was
because toybox asks for "" rather than "C.UTF-8", and for some reason
we were interpreting that as "C" rather than "C.UTF-8".

Test: bionic tests, ls
Change-Id: Ic60e3b90cd5fe689e5489fad0d5d91062b9594ed
2016-10-24 14:50:31 -07:00
Elliott Hughes
22950687ee Fix ifaddrs error handling.
An NLMSG_ERROR packet includes an errno value that we should use. Also report
failures to create a socket immediately, rather than falling through to the
send and reporting EBADF.

Bug: http://b/32145516
Bug: http://b/31038971
Test: bionic ifaddr tests on ryu (with broken kernel) and flounder
Change-Id: I84c480c5b75077eb90d40426a9d66d7bffbd3d51
2016-10-14 14:35:26 -07:00
Josh Gao
59bde2e8f4 Use STDERR_FILENO instead of opening /dev/stderr.
/dev/stderr is a symlink to /proc/self/fd/2, so this only has different
behavior when we're out of file descriptors, or when STDERR_FILENO is in
a different state (it's not at the end, it's not writable, etc.).

Test: mma
Change-Id: Ie99688d810218eca8482ff060373e88c4e001824
2016-10-07 13:21:03 -07:00
Elliott Hughes
89e29ee485 Fix mbsnrtowcs where dst is null.
POSIX is its usual unintelligible self
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/mbsrtowcs.html),
but the ISO C11 standard (7.29.6.4.1 paragraph 2) is pretty clear: *src
should change if and only if dst is non-null.

Bug: https://code.google.com/p/android/issues/detail?id=166381
Test: bionic tests
Change-Id: Ibc631cfa5b1bf4a6f56963feba9f0eea27b07984
2016-09-29 17:26:13 -07:00
Dan Albert
3103f6d39e Add strtof_l and strtod_l.
libc++ needs these now. Add shims to match the others.

Test: make checkbuild tests
Bug: http://b/31639993
Change-Id: Ifec6c32099145d8d3d1a5639a4809e5e9f553c33
2016-09-22 00:44:37 -07:00
Josh Gao
cb728e6f63 Fix instances of '#if __i386__'.
Triggers -Wundef, which is on in -Weverything.

Bug: http://b/31496165
Change-Id: Ie2241b19abd6257bebf68baa3ecc4de8066c722e
2016-09-15 14:21:28 -07:00
Josh Gao
b36efa4343 Fix instances of '#if __LP64__'.
Triggers -Wundef, which is on in -Weverything.

Bug: http://b/31496165
Change-Id: Ib06107073f7dd1d584c19c222d0430da9d35630b
2016-09-15 14:21:28 -07:00
Josh Gao
5622837301 Merge "Initialize main thread TLS before the global stack guard." 2016-09-15 19:28:56 +00:00
Nikola Veljkovic
23f088cd74 [mips64] Fix ipc syscalls
Mips defines CONFIG_ARCH_WANT_IPC_PARSE_VERSION for both 32 and 64-bit.
See arch/mips/Kconfig. Other supported arches do it for 32-bit only.
This translates in having to pass IPC_64 flag for mips32 and mips64.
We use __mips__ to pass the flag, which is also defined for both 32 and
64-bit.

Change fixes bionic smoke tests (sys_msg, sys_sem, sys_shm) for mips64.

Test: bionic-unit-tests --gtest_filter="sys_*.smoke"
Change-Id: I918e4ffafd2002bb3e62ee252406746778100031
2016-09-09 12:24:04 +02:00
Elliott Hughes
7f0849fd11 Fix sscanf/wcstod parsing of NaNs.
The parsefloat routines -- which let us pass NaNs and infinities on to
strto(f|d|ld) -- come from NetBSD.

Also fix LP64's strtold to return a NaN, and fix all the architectures
to return quiet NaNs.

Also fix wcstof/wcstod/wcstold to use parsefloat so they support hex
floats.

Lots of new tests.

Bug: http://b/31101647
Change-Id: Id7d46ac2d8acb8770b5e8c445e87cfabfde6f111
2016-09-07 15:01:54 -07:00
Josh Gao
4159e866ab Initialize main thread TLS before the global stack guard.
The GCE breakage caused by 78a52f19bb was
due to TLS_SLOT_SELF being uninitialized before the use of errno by
syscall. Separate stack guard initialization from TLS initialization so
that stack guard initialization can make syscalls.

Bug: http://b/29622562
Bug: http://b/31251721
Change-Id: Id0e4379e0efb7194a2df7bd16211ff11c6598033
2016-09-06 12:12:19 -07:00
Josh Gao
b3fbee449c Revert "Update getentropy_linux.c from upstream."
This reverts commit 5faef47e43.

Bug: http://b/31251721
Change-Id: I20a091f385fb77ccc68b8d9fb1d2aee3dec0d0ff
2016-09-02 08:39:29 +00:00
Josh Gao
5faef47e43 Update getentropy_linux.c from upstream.
Bug: http://b/29622562
Change-Id: Ia65c038effa6e806c325a8e93c1fe80c50a9f2c9
2016-08-31 18:00:47 -07:00
Dimitry Ivanov
864f3ec186 Initialize __abort_message_ptr in linker's copy of libc
The linker calls to __libc_fatal resulted in tombstones
with missing abort message. This commit fixes it by
initializing __abort_message_ptr for the linker's copy
of libc.

Bug: http://b/31095185
Change-Id: I883d654d7fd0ef309c80f8021202b6bfd5d5cea5
2016-08-26 17:03:01 -07:00
Elliott Hughes
63615066d9 Fix execvp/execvpe behavior with absolute paths and ENOEXEC.
Bug: http://b/31091962
Change-Id: Id0b3d41868f5e3ed1ccf618bfefb46609367bc9a
2016-08-25 17:40:27 -07:00
Elliott Hughes
3c1159024c Fix execvpe ENOEXEC behavior.
The special case for absolute paths wasn't handling ENOEXEC.

Also add more extensive tests for execvpe.

Also switch to manually doing the fork in ExecTestHelper::Run because
ASSERT_EXIT doesn't actually return, meaning we were only running the
first part of each test.

Bug: http://b/31073104
Change-Id: I7a4640afc6d290c51ba2e66fc1b9bb6b0fc174f7
2016-08-24 22:56:52 -07:00
Treehugger Robot
fac56897f8 Merge "Rewrite the exec family." 2016-08-24 21:21:43 +00:00
Elliott Hughes
1b40aafe3f Rewrite the exec family.
* Removes duplication.
* Removes fixed PATH_MAX limit.
* Adds basic tests.

Bug: http://b/30032507
Change-Id: I4087a9de3e53884ac3297ebafbec4e6f8a9871b6
2016-08-24 13:03:04 -07:00
Elliott Hughes
1878ea08de Fix mips build.
Tests still pass on arm/aarch64/x86/x86-64.

Change-Id: I6a17b5bca356dbc7273b5427c68d538c0dd6deed
2016-08-18 18:25:07 -07:00
Elliott Hughes
7c59f3f6f3 Flesh out <sys/msg.h>, <sys/sem.h>, <sys/shm.h>.
Also fix <sys/ipc.h>.

Not useful except to systems/bringup folks for testing. Trivial tests
added, and double-checked under strace to see that things look right.

x86 -- which works differently to everything else -- tested on the host.

Bug: http://b/27952303
Change-Id: I328534e994ae9e90755f545478fba03038c0bb94
2016-08-18 15:23:38 -07:00
Elliott Hughes
cae33ade6c Fix memmem behavior with empty needles.
Change-Id: I8b893d80c27b548652d843af9520d7adc8ba8902
2016-08-16 12:28:58 -07:00
Elliott Hughes
51b3b44585 Merge "Fix sysconf(_SC_ARG_MAX)." 2016-08-12 19:53:46 +00:00
Treehugger Robot
4a77fa3dcd Merge "Fix recvfrom prototype." 2016-08-12 19:48:38 +00:00
Treehugger Robot
f8f2949744 Merge "Fix pthread_barrierattr_getpshared prototype." 2016-08-12 19:13:37 +00:00
Treehugger Robot
a1858a7f59 Merge "POSIX says IPPORT_RESERVED is in <netdb.h>." 2016-08-12 18:52:58 +00:00
Elliott Hughes
e43778880e POSIX says IPPORT_RESERVED is in <netdb.h>.
In <netdb.h>:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netdb.h.html

Not in <netinet/in.h>:

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html

Change-Id: Ie34cdb80eeb1443cf292944f3c68d8383aee2295
2016-08-12 10:38:35 -07:00
Treehugger Robot
b17d845d9b Merge "Use sysinfo(2) to implement more of <sys/sysinfo.h>." 2016-08-12 17:07:41 +00:00
Elliott Hughes
8197aca7f2 Fix recvfrom prototype.
http://pubs.opengroup.org/onlinepubs/9699919799/functions/recvfrom.html

Change-Id: Iba203c74045c88e53e28c2e0c8bc1f9ac63ce23e
2016-08-12 09:20:07 -07:00
Elliott Hughes
02ac028bf7 Fix pthread_barrierattr_getpshared prototype.
As http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_barrierattr_getpshared.html
is my witness, there's a missing `const` here.

Change-Id: Ifd68188fb952460b64d144bdc21a53bc40ed82a7
2016-08-11 23:18:13 -07:00
Elliott Hughes
c508de0e41 Use sysinfo(2) to implement more of <sys/sysinfo.h>.
We already had implementations of some of the functions, and I didn't
bother rewriting them when we added sysinfo(2). Ross Anderson said in
https://www.lightbluetouchpaper.org/2016/07/29/yet-another-android-side-channel/
that we should "simply disable access to all procfs files", which made
me curious how many places we use /proc in bionic. This is the one that's
obviously unnecessary. The others I'm not aware of alternative APIs for.

Change-Id: Ia64f36b76f29a7a1dd67845270a5472e121aae10
2016-08-11 14:51:31 -07:00
Treehugger Robot
299e501419 Merge "Move brillo closer to Android." 2016-08-10 23:59:19 +00:00
Elliott Hughes
38dba2e7e1 Fix sysconf(_SC_ARG_MAX).
ARG_MAX hasn't been a constant since Linux 2.6.23.

Bug: http://lists.landley.net/pipermail/toybox-landley.net/2016-August/008592.html
Change-Id: I1eddb562751604c75b89fa610d79be0655c53693
Test: ran the bionic tests on device and against glibc
2016-08-10 15:51:06 -07:00
Elliott Hughes
5ffed9b856 Move brillo closer to Android.
Hiding our legacy cruft seemed like a good idea, but in practice it will only
mean worse interoperability.

Plus we got it wrong, as the recent `putw` example showed.

Change-Id: I167c7168eff133889028089c22a7a0dfb8d6d0cf
2016-08-10 14:08:31 -07:00
Elliott Hughes
fb3873d4db Fortify vsnprintf in more cases.
Bug: http://b/30445072
Change-Id: I1893890f0e3b56533eef053eda1bd96a0b9a5119
2016-08-10 11:50:12 -07:00
Elliott Hughes
53cf348c82 Remove more stdio copy/paste.
Change-Id: Ia92629b75d2c153ecf1cec711e2f9575eef604ab
2016-08-09 16:27:23 -07:00
Elliott Hughes
0a610d00fe Upgrade to tzcode-2016f.
No significant changes other than a default implementation of strftime_l.

Change-Id: I6edd2c03e5e7559f012c0c87d43f7109d641d3ca
2016-07-29 14:04:17 -07:00
Treehugger Robot
4f62c5b311 Merge changes I7718b1ba,I648adc35
* changes:
  Only initialize the global stack protector once.
  Make getpid work before TLS has been initialized.
2016-07-22 19:20:58 +00:00
Evgenii Stepanov
d13e9a603f Align-up and randomize shared libraries.
This change implements the following property:
  Any 2**N aligned memory region on size 2**N contains no more than one DSO.

The value N can be configured, with 16 or 18 looking like a good choice.
Additionally, DSOs are loaded at random page-aligned address inside these large
regions.

This change has dual purpose:
1. Larger values of N allow a lot more compact CFI shadow implementation.
   See change I14dfea630de468eb5620e7f55f92b1397ba06217.
   For example, CFI shadow for the system_server process has the following size (RSS, KB):
   152 for N = 12, 32 for N = 16, 16 for N = 18.
2. Extra randomization is good for security.

This change does not result in extra RAM usage, because everything is still page-aligned.
It does result in a bit more VM fragmentation because of the gaps between shared libraries.
As it turns out, this fragmentation is barely noticeable because the kernel creates new mapping
at the highest possible address, and we do enough small mappings to almost completely fill the
gaps (ex. in the Zygote the gaps are filled with .ttf file mappings and thread stacks).

I've measured VM fragmentation as the sum of all VM gaps (unmapped regions) that are larger
than 1MB according to /proc/$PID/maps. On aosp_angler-userdebug, the numbers are (in GB):

                |   N = 12  |  N = 18
system_server   |   521.9   |  521.1
zygote64        |   522.1   |  521.3
zygote32        |   2.55    |  2.55
mediaserver     |   4.00    |  4.00

Change-Id: Ia6df840dd409c82837efd1f263be420d9723c84a
2016-07-19 18:18:22 -07:00
Yabin Cui
a24a2476d0 Merge "Force pthread_cond_timedwait_relative_np using CLOCK_MONOTONIC." 2016-07-15 01:29:28 +00:00
Yabin Cui
fe4a4d8f67 Force pthread_cond_timedwait_relative_np using CLOCK_MONOTONIC.
Previous patch changed pthread_cond_timedwait_relative_np to use
CLOCK_REALTIME, which causes app compatibility problem. So change
it back to CLOCK_MONOTONIC.

Bug: 30106240
Change-Id: I8e04058e92ede098f4f9f8d133f094001921441e
2016-07-13 16:08:48 -07:00
Elliott Hughes
4ce902c30e Support 32-bit ARM vdso.
Linux 4.1 added this.

Bug: http://b/19198045
Change-Id: I28be802ff403a61dd6733a001411b3ff05fef5a5
2016-07-12 13:55:51 -07:00
Josh Gao
b6453c52ac Only initialize the global stack protector once.
Before, dynamic executables would initialize the global stack protector
twice, once for the linker, and once for the executable. This worked
because the result was the same for both initializations, because it
used getauxval(AT_RANDOM), which won't be the case once arc4random gets
used for it.

Bug: http://b/29622562
Change-Id: I7718b1ba8ee8fac7127ab2360cb1088e510fef5c
Test: ran the stack protector tests on angler (32/64bit, static/dynamic)
2016-06-30 12:58:32 -07:00
Josh Gao
1089afb744 Make getpid work before TLS has been initialized.
Bug: http://b/29622562
Change-Id: I648adc35c04604a7e8bc649c425f07a723e96d3a
Test: code dependent on this change no longer crashes
2016-06-30 12:58:32 -07:00
Josh Gao
c80ffece02 Defer registration of the arc4random fork-detect handler.
Previously, arc4random would register a fork-detecting pthread_atfork
handler to not have to call getpid() after a fork. pthread_atfork uses
pthread_mutex_lock, which requires the current thread to be initialized,
preventing the use of arc4random for initializing the global stack guard,
which needs to happen before the main thread has been initialized.

Extract the arc4random fork-detection flag and use the existing
arc4random fork handler to set it.

Bug: http://b/29622562
Change-Id: I98c9329fa0e489c3f78cad52747eaaf2f5226b80
2016-06-28 15:52:59 -07:00
Josh Gao
3e45901439 Make getpid work before the main thread is initialized.
Bug: http://b/29622562
Test: code dependent on this change no longer crashes
Change-Id: I40936f7b35d9e58182aeb2e34e52f54088700825
2016-06-28 15:52:59 -07:00
Josh Gao
250667aaf6 Take the arc4random lock before forking.
Bug: http://b/24675038
Test: stepped through a fork call in gdb
Change-Id: I09d20ff1d103d0c005f2a0cdd9b0a8710ab2392c
2016-06-28 15:52:59 -07:00
Elliott Hughes
213584bb9d Remove obsolete GCC workaround.
bionic is no longer built with GCC.

Change-Id: If01c53d8f6ec7e801bfcdc61775cc24356eb8434
2016-06-10 12:49:04 -07:00
Elliott Hughes
449eff02d2 Add futimes, futimesat, and lutimes.
Spotted these while cleaning up <sys/cdefs.h> --- if we remove __USE_XOPEN2K8,
libchrome decides you "must" have futimes. Adding the missing functions (all
just alternative interfaces to utimensat(2) system call) lets us clean up
without breaking anything.

Change-Id: If44fab08ee3de0e31066d650d128a3c96323529b
2016-06-08 19:51:20 -07:00
Treehugger Robot
e20730ca0b Merge "Remove declaration for __brk." 2016-06-02 02:25:59 +00:00
Josh Gao
6e9c1f61d8 Remove declaration for __brk.
Bug: http://b/28178111
Change-Id: I972789cd5da552000c32fd107b9df98330323d89
2016-06-01 18:21:06 -07:00
Treehugger Robot
676f6e3c7f Merge "Remove libstdc++ include files." 2016-05-27 23:36:18 +00:00
Elliott Hughes
f44b232d85 Remove libstdc++ include files.
We still need <new> for bionic, and to build libstdc++.

Change-Id: Ic7b26340576a5355007a06db9c1bec395be49ae1
2016-05-27 15:49:31 -07:00
Elliott Hughes
bdd8f896dd Improve diagnostics from the assembler __strcpy_chk routines.
Change-Id: Ib95b598f7f8338cc1a618c00232a4259dc4a6319
2016-05-26 16:38:34 -07:00
Elliott Hughes
c75da09f4f Improve diagnostics from the assembler __strcat_chk routines.
Change-Id: I44cbe5389c66de6618e581a6e302eea22c39d6fb
2016-05-26 14:55:00 -07:00
Elliott Hughes
8963dd337e Make all rt_sigtimedwait signatures match.
There's no change to the generated stubs, because the script only cares
that this is a pointer type, not what it's a pointer to.

Change-Id: I766720965f0f3d201fc90677a076b26870485377
2016-05-23 11:20:19 -07:00
Elliott Hughes
f6324d540a Fix our *ether* headers mess.
Move everything to where it should be.

Along the way, we lose <net/ethertypes.h>. glibc only has a handful of these
types, and they're all in <net/ethernet.h>, not <net/ethertypes.h>. I've taken
the liberty of not including the AppleTalk ones, since it is 2016.

Also, <net/if_ether.h> should be <netinet/if_ether.h> (though with different
contents).

Bug: http://b/28519060
Change-Id: Ia41c3fc136fd3e6b008c8d08018e0629134ea6fc
2016-05-13 11:00:22 -07:00
Elliott Hughes
e104a2edf3 Generalize the clone function slightly.
* Allow clone where both the child function and stack are null. It's
obviously wrong to ask to call a function without a stack, but it's not
necessarily wrong to supply no stack if you're also not supplying a
function.

* Reimplement fork in terms of the clone function, rather than using the
clone system call directly.

This is intended as a step towards enabling use of pid namespaces.

Change-Id: I03c89bd1dc540d8b4ed1c8fdf6644290744b9e91
2016-05-06 16:37:00 -07:00
Dan Albert
baa2a973bd Use clang's nullability instead of nonnull.
http://clang.llvm.org/docs/AttributeReference.html#nonnull

_Nonnull is similar to the nonnull attribute in that it will instruct
compilers to warn the user if it can prove that a null argument is
being passed. Unlike the nonnull attribute, this annotation indicated
that a value *should not* be null, not that it *cannot* be null, or
even that the behavior is undefined. The important distinction is that
the optimizer will perform surprising optimizations like the
following:

    void foo(void*) __attribute__(nonnull, 1);

    int bar(int* p) {
      foo(p);

      // The following null check will be elided because nonnull
      // attribute means that, since we call foo with p, p can be
      // assumed to not be null. Thus this will crash if we are called
      // with a null pointer.
      if (src != NULL) {
        return *p;
      }
      return 0;
    }

    int main() {
      return bar(NULL);
    }

Note that by doing this we are no longer attaching any sort of
attribute for GCC (GCC doesn't support attaching nonnull directly to a
parameter, only to the function and naming the arguments
positionally). This means we won't be getting a warning for this case
from GCC any more. People that listen to warnings tend to use clang
anyway, and we're quickly moving toward that as the default, so this
seems to be an acceptable tradeoff.

Change-Id: Ie05fe7cec2f19a082c1defb303f82bcf9241b88d
2016-05-05 17:11:54 -07:00
Chih-Hung Hsieh
62e3a078aa Fix google-explicit-constructor warnings.
Bug: 28341362
Change-Id: I84effbdfa1b9b39328a909b7f70fe17e7ee316c8
2016-05-03 12:08:05 -07:00
Elliott Hughes
b0da5760dc Move the IEEE fp header out of the public headers.
Bug: http://b/28519060
Change-Id: I9f1a1a9ac1f22462bf86991b57c51824cb42eefd
2016-05-02 12:44:41 -07:00
Elliott Hughes
7ba106c784 Fix <wctype.h>.
* Fix the return type of towlower_l/towupper_l.
* Implement wctrans/wctrans_l/towctrans/towctrans_l.
* Move declarations that POSIX says are available from both <wchar.h> and
  <wctype.h> to <bits/wctype.h> and include from both POSIX headers.
* Write the missing tests.

Change-Id: I3221da5f3d7e8a2fb0a7619dc724de45f7b55398
2016-04-28 18:22:06 -07:00
Elliott Hughes
6f6f9058fa Implement mblen(3).
Change-Id: I65948ea5b9ecd63f966ba767ad6db4a2effc4700
2016-04-28 16:41:29 -07:00