History log of /bionic/libc/bionic/
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
9ce09e423f24823d52f19ab8247e078977100132 12-Nov-2015 Mingwei Shi <mingwei.shi@intel.com> libc: implement kernel vdso syscalls for i386

This patch uses __kernel_vsyscall instead of "int 0x80"
as the syscall entry point. AT_SYSINFO points to
an adapter to mask the arch specific difference and gives a
performance boost on i386 architecture.

Bug: http://b/27533895
Change-ID: Ib340c604d02c6c25714a95793737e3cfdc3fc5d7
Signed-off-by: Mingwei Shi <mingwei.shi@intel.com>

(cherry picked from commit be910529322b461148debefd50b9e0d67ae84f8e)
_libc_init_main_thread.cpp
ibc_init_common.cpp
c1f182894990ea76f3f3c0ab41cc104637532e71 11-Mar-2016 Christopher Ferris <cferris@google.com> Init functions after debug malloc succeeds.

Do not initialize all of the global function pointers associated with
debug malloc until the initialization has completed correctly.

Bug: 27600760

(cherry picked from commit 20f2c1ebd5b5860e69772b228ccda756eafc1398)

Change-Id: Ibc45213f55be9c8e95fb838b583353cd090c8b88
alloc_common.cpp
12393862e55b9ab28dd29ae16fbdf498371726a7 04-Mar-2016 Elliott Hughes <enh@google.com> Improve and fix the stack-protector tests.

Bug: http://b/26888853

(cherry picked from commit fc69a8ad5f0d9b63de48e3858fb4811ede7ac64e)

Change-Id: Ibc431076000b9a8db46f68f858480045b03b6e79
_libc_init_main_thread.cpp
ibc_init_common.cpp
bf4c113cad4d1f4464867a057d5c703505ef32b2 05-Mar-2016 Josh Gao <jmgao@google.com> forkpty: set the output fd to -1 on the slave side.

glibc, FreeBSD, OpenBSD, and Darwin all just leave the fd unchanged and
possibly uninitialized. Setting it to -1 seems friendlier, though.

Bug: http://b/27506278
Change-Id: I7acdc8eecbea4404d5fb4ba0b4d572245a323886
ty.cpp
8dd7c611ea9889b316c02861d463edee83c6a207 05-Mar-2016 Elliott Hughes <enh@google.com> Don't call clock_getres in sysconf.

There are a hundred other reasons why we can't run on kernels old enough
to not have all the clocks covered by sysconf.

This was causing trouble for jemalloc 4.1.0 in a seccomp-constrained process
because jemalloc 4.1.0 introduced a call to sysconf that caused us to make
clock_getres syscalls for the first time, leading to SIGSYS.

Bug: http://b/27408522

(cherry picked from commit d2b8de2cd16ecd86c830d98c58bcf392475bd0b3)

Change-Id: Id46a0f2c2804c597a8c9091690a8a1fc4a65f4cd
ysconf.cpp
54f1339d1c745d9d30f0200c332dc76661e75214 03-Mar-2016 Josh Gao <jmgao@google.com> Add a checksum to jmp_buf on ARM.

Make it easier to diagnose applications mucking with the contents of
jmp_buf by checksumming its contents.

Bug: http://b/27417786
Change-Id: I9989e2ea3979a36ae0bc4c9e1bacafddbacc731b
(cherry picked from commit a4c69137c693c45fce4010ba61d69d7147f5dd9a)
etjmp_cookie.cpp
fbdffcc34b757c267c736f5fde9c631ae4815247 02-Mar-2016 Elliott Hughes <enh@google.com> Fix getifaddrs' handling of point-to-point interfaces.

Also remove an if that implied that IFA_BROADCAST is a possibility for
AF_INET6.

The existing tests fail if you have a point-to-point interface configured,
so no new test necessary.

Bug: http://b/27442503

(cherry picked from commit ef925e50d38fe6f5499c1d0d24cca98bf88e5256)

Change-Id: I19c19d83a86d0a8004a6b45dea7febe9d6fb6a2e
faddrs.cpp
6deb3042df87f8569fb430dbf5f140f6a694ddfd 06-Feb-2016 Colin Cross <ccross@android.com> Add backtrace_string and export to libmemunreachable

Add backtrace_string to convert a malloc_debug backtrace to a string.
Also move the backtrace functions to libc_malloc_debug_backtrace so that
libmemunreachable can reuse them.

Bug: 27208635
(cherry picked from commit 2c75991359df165ca7cc7a6213fb227c0b5ed87c)

Change-Id: Ia93aaf010fbce1ace058439427066ea2dfd8bd13
ibc_logging.cpp
d6c9b44091a8865a3b61ada247dd9abf4d6b8705 02-Feb-2016 Colin Cross <ccross@android.com> Export malloc_backtrace

Bug: 27208635
(cherry picked from commit 2d4721c0c57fe2f7c1e1b40df4763a561b3cf856)

Change-Id: Ida926cabb706dfd962b692ba1775da332f68488f
alloc_common.cpp
c40577f740ae4f66cdba4b2137668fb3114bb99d 29-Jan-2016 Colin Cross <ccross@android.com> Export malloc_iterate and friends

Export malloc_iterate, malloc_enable, and malloc_disable to be used by
libmemunreachable.

Bug: 27208635
(cherry picked from commit 869691c6f7691dd5bf343617aa185c32e0d3d160)

Change-Id: Ifa44421a84ac3be6a57fac28c4da501febe88c28
emalloc.h
alloc_common.cpp
31e4472dc7779f4de13975090fc88b1e5dfb52b2 17-Feb-2016 Elliott Hughes <enh@google.com> Fix scope ids for link-local IPv6 addresses from getifaddrs(3).

Bug: http://b/27219454

(cherry picked from commit 7dac8b8aabadbf2dcff20d3646e701728ba3777d)

Change-Id: I006ae68b928b5836d064c020a6db43dcc05add9e
faddrs.cpp
9c212fc43617aeef5b1828407dd5d8daee506923 06-Feb-2016 Mike Frysinger <vapier@google.com> Merge "define pw_gecos to pw_passwd for LP32 systems"
ca6af7f4a81c4f8d1acf1ecbdcdae8c44bb0a092 03-Feb-2016 Mike Frysinger <vapier@google.com> define pw_gecos to pw_passwd for LP32 systems

Since we set both fields to NULL all the time, we can alias the two
fields together on LP32 to provide build-time compatibility.

BUG=24918750
TEST=python now builds for Brillo boards

Change-Id: I3394aea80c9a5288669389f71d0e4132f2157e3c
tubs.cpp
b90837c3d316c6ea8d6f0b0b6a3643d0d3245a0e 05-Feb-2016 Dimitry Ivanov <dimitry@google.com> Merge "Add check for pthread_self() when looking up a thread"
4bc739a54c4ba9063e91bef06ff226dab118792d 05-Feb-2016 Dimitry Ivanov <dimitry@google.com> Add check for pthread_self() when looking up a thread

Check if thread_id is in fact pthread_self before
locking on g_thread_list_lock in __pthread_internal_find.

The main reason for doing this is not performance but to allow
the linker use raise() which was not working because pthread_kill()
couldn't find pthread_self() thread because the global thread
list is initialized in libc.so and the linker's version of this
list is empty.

Bug: http://b/25867917
Change-Id: I18fe620e8cd465b30f0e1ff45fff32958f3c5c00
thread_internal.cpp
0c485dae707fac45f5d8baff7da1a469e25c2261 03-Feb-2016 Elliott Hughes <enh@google.com> Add in6addr_any and in6addr_loopback symbols.

Change-Id: I3a90fa448b6bd43321672ba74b84a4e9e8a67738
indresvport.c
etinet_in.cpp
f226ee59e0effedeabed09e2d65be7fa7499cc25 03-Feb-2016 Elliott Hughes <enh@google.com> Add fopen64/freopen64/tmpfile64 aliases.

Our fopen/freopen/tmpfile are already always O_LARGEFILE, but let's add
the aliases for _LARGEFILE_SOURCE compatibility.

Bug: http://b/24807045
Change-Id: I5d99b3ef3c9f27ce70f13313f6a92e96c7f21f80
mpfile.cpp
2fc7f9db3df70b33e1cdf6faa445ec57e81b05df 27-Jan-2016 Christopher Ferris <cferris@google.com> Remove unused file.

This file should have been deleted with the malloc debug rewrite, but
popped back into existence due to a merge conflict.

Change-Id: I74e53daaf3febf650b20e3da5329558ac84c5bcd
alloc_debug_common.cpp
194860a9e638b1d093857f08b8fad37c9ec0e113 27-Jan-2016 Tom Cherry <tomcherry@google.com> Merge "Replace snprintf() with __libc_format_buffer()"
8352475c756663fb22fce851a5ff9b9d8320f4de 27-Jan-2016 Tom Cherry <tomcherry@google.com> Replace snprintf() with __libc_format_buffer()

If snprintf() is called from the linker, it may erroneously return a
null string. The libc internal __libc_format_buffer() does not have
this problem, so it is now used instead.

Bug: 26756577

Change-Id: I37a97e27f59b3c0a087f54a6603cc3aff7f07522
ystem_properties.cpp
d4ae54f668632e47f080ab60f2dc540560e98989 26-Jan-2016 Elliott Hughes <enh@google.com> Fix lockf for LP32.

Bug: http://b/13077650
Change-Id: Ibbe2d907d23791c908475e0875a5c745ac948813
ockf.cpp
d9bb70857577808c197030e7f5422ee1f976f3ac 26-Jan-2016 Elliott Hughes <enh@google.com> Merge "Implement POSIX lockf."
5704c423c81790195161c1757ae79da188590c51 26-Jan-2016 Elliott Hughes <enh@google.com> Implement POSIX lockf.

This has been requested a few times over the years. This is basically
a very late rebase of https://android-review.googlesource.com/45470
which was abandoned years ago. One addition is that this version has
_FILE_OFFSET_BITS=64 support.

POSIX puts this in <unistd.h>. glibc also has it in <fcntl.h>.

Bug: http://b/13077650
Change-Id: I5862b1dc326e326c01ad92438ecc1578d19ba739
ockf.cpp
ca482742985a22dbf5ee4a0afdf8525300f7785d 26-Jan-2016 Yabin Cui <yabinc@google.com> Revert "Revert "Make sem_wait able to return errno EINTR for sdk > 23.""

This reverts commit 6d5108520225fd2c4b10ca63565545ec120aab4a.
And add missing bionic_sdk_version.h.

Change-Id: I24cc738b1fd1d26234c52afbc787f5b3c4a9c9cb
ibc_init_dynamic.cpp
ibc_init_static.cpp
emaphore.cpp
ac67b4eb7c70ea668abb32298b0cb16920a32a66 26-Jan-2016 Elliott Hughes <enh@google.com> Merge "Revert "Make sem_wait able to return errno EINTR for sdk > 23.""
6d5108520225fd2c4b10ca63565545ec120aab4a 26-Jan-2016 Dan Albert <danalbert@google.com> Revert "Make sem_wait able to return errno EINTR for sdk > 23."

Broke the build. There's no such file as bionic_sdk_version.h anywhere in the tree.

This reverts commit 892b61d3409e8cdf0e121c688737eb058d57f7ab.

Change-Id: Iec3f4588edfb1d1524bb5f16451fd05dc6ebe44a
ibc_init_dynamic.cpp
ibc_init_static.cpp
emaphore.cpp
c96b6e1747c5b5ca154bada84ec0a3868540e96f 26-Jan-2016 Yabin Cui <yabinc@google.com> Merge "Make sem_wait able to return errno EINTR for sdk > 23."
892b61d3409e8cdf0e121c688737eb058d57f7ab 25-Jan-2016 Yabin Cui <yabinc@google.com> Make sem_wait able to return errno EINTR for sdk > 23.

Posix standards says sem_wait is interruptible by the delivery
of a signal. To keep compatiblity with old apps, only fix that
in newer sdk versions.

Bug: 26743454

Change-Id: I924cbb436658e3e0f397c922d866ece99b8241a3
ibc_init_dynamic.cpp
ibc_init_static.cpp
emaphore.cpp
63860cb8fd1adf3f679b9b4ad876323a8d65cd9d 17-Nov-2015 Christopher Ferris <cferris@google.com> Malloc debug rewrite.

The major components of the rewrite:

- Completely remove the qemu shared library code. Nobody was using it
and it appears to have broken at some point.
- Adds the ability to enable/disable different options independently.
- Adds a new option that can enable the backtrace on alloc/free when
a process gets a specific signal.
- Adds a new way to enable malloc debug. If a special property is
set, and the process has an environment variable set, then debug
malloc will be enabled. This allows something that might be
a derivative of app_process to be started with an environment variable
being enabled.
- get_malloc_leak_info() used to return one element for each pointer that
had the exact same backtrace. The new version returns information for
every one of the pointers with same backtrace. It turns out ddms already
automatically coalesces these, so the old method simply hid the fact
that there where multiple pointers with the same amount of backtrace.
- Moved all of the malloc debug specific code into the library.
Nothing related to the malloc debug data structures remains in libc.
- Removed the calls to the debug malloc cleanup routine. Instead, I
added an atexit call with the debug malloc cleanup routine. This gets
around most problems related to the timing of doing the cleanup.

The new properties and environment variables:

libc.debug.malloc.options
Set by option name (such as "backtrace"). Setting this to a bad value
will cause a usage statement to be printed to the log.

libc.debug.malloc.program
Same as before. If this is set, then only the program named will
be launched with malloc debug enabled. This is not a complete match,
but if any part of the property is in the program name, malloc debug is
enabled.

libc.debug.malloc.env_enabled
If set, then malloc debug is only enabled if the running process has the
environment variable LIBC_DEBUG_MALLOC_ENABLE set.

Bug: 19145921

Change-Id: I7b0e58cc85cc6d4118173fe1f8627a391b64c0d7
ebug_backtrace.cpp
ebug_backtrace.h
ebug_mapinfo.cpp
ebug_mapinfo.h
ibc_init_common.cpp
ibc_init_dynamic.cpp
alloc_common.cpp
alloc_debug_backtrace.h
alloc_debug_check.cpp
alloc_debug_common.h
alloc_debug_disable.h
alloc_debug_leak.cpp
alloc_debug_qemu.cpp
0ac0cee0d1ab60a92103a5021e76ec31da2e3234 07-Jan-2016 Josh Gao <jmgao@google.com> Remove dlmalloc.

Bug: http://b/17207577
Change-Id: Ie009badca6deb1f91b27a4340b70cdd6bedff893
lmalloc.c
lmalloc.h
alloc_debug_common.cpp
dk_cruft.cpp
bba395492a0bb6ee72d0ad8e4d468e852392220e 21-Jan-2016 Dimitry Ivanov <dimitry@google.com> Revert "Temporary apply LIBC version to __pthread_gettid"

This reverts commit 0ef1d121b5e4845f4ef3b59ae9a1f99ceb531186.

Bug: http://b/26392296
Bug: http://b/26391427
Change-Id: I7bbb555de3a43813e7623ff6ad4e17874d283eca
dk_cruft.cpp
d1293faba6dbb9aa8a6253d565f8276e819c1453 19-Jan-2016 Elliott Hughes <enh@google.com> Fix GCC build breakage.

Change-Id: I0339f525c68af942fb97f4bffc771717e67e0e07
et_if.cpp
ed57b98758176f0cccdec16cbed524e444039fe7 16-Jan-2016 Elliott Hughes <enh@google.com> Implement if_nameindex(3)/if_freenameindex(3).

This is just a subset of the recently-implemented getifaddrs(3), though if
we want to handle interfaces (such as "rmnet_*") that don't have an address,
we need to either expose ifaddrs_storage and keep track of which interfaces
we've already seen (which is pretty messy), or refactor the netlink code so
we can reuse it and just extract the information we need for if_nameindex(3).
This patch goes the latter route.

Also clean up if_nametoindex(3) and if_indextoname(3).

Change-Id: I5ffc5df0bab62286cdda2e7af06f032c767119a8
ionic_netlink.cpp
ionic_netlink.h
f_indextoname.c
f_nametoindex.c
faddrs.cpp
et_if.cpp
fdb2963e0a65ececa89837eff64ffd8aca8027d2 22-Dec-2015 Yi Kong <yikong@google.com> Handle AF_PACKET in getifaddr(3).

Also fix a bug where we were mutating the address/broadcast address
of an existing entry rather than the new entry, and use 'const' to
ensure we don't make that mistake again.

Change-Id: I31c127a5d21879b52c85cd0f7ed2e66554a21e39
faddrs.cpp
42d949ff9d2956e25f84e537f43a8f93ecb37baf 07-Jan-2016 Elliott Hughes <enh@google.com> Defend against -fstack-protector in libc startup.

Exactly which functions get a stack protector is up to the compiler, so
let's separate the code that sets up the environment stack protection
requires and explicitly build it with -fno-stack-protector.

Bug: http://b/26276517
Change-Id: I8719e23ead1f1e81715c32c1335da868f68369b5
_cxa_thread_atexit_impl.cpp
_libc_init_main_thread.cpp
ibc_init_common.cpp
ibc_init_dynamic.cpp
ibc_init_static.cpp
thread_internal.h
9353089262b21f88a2dca6516f03a4dd39a5dbd1 06-Jan-2016 Tom Cherry <tomcherry@google.com> Merge "Revert "system_properties.cpp: special case ro.* properties""
e97ce31fe768f6383234d809eef144f049210a5e 06-Jan-2016 Tom Cherry <tomcherry@google.com> Revert "system_properties.cpp: special case ro.* properties"

This reverts commit c5fd81ab2524a06be907d9c5234e79346bbbbd7c.

Bug: 26416032

Change-Id: Id2d6761fdf55efa28c0b08b597daaa5cd381d758
ystem_properties.cpp
031dfe198b53753bc852961e915fedb78c5f42df 06-Jan-2016 Elliott Hughes <enh@google.com> Merge "Fix a broken link in a comment."
40c2bf6cf6d9fa423d36128823451ae1cc1f7662 06-Jan-2016 Elliott Hughes <enh@google.com> Fix a broken link in a comment.

Bug: https://code.google.com/p/android/issues/detail?id=197784
Change-Id: I2f9e5bc2dd2b8a6992c7c55bc856e4a323c7c8a8
ibc_init_common.cpp
c5fd81ab2524a06be907d9c5234e79346bbbbd7c 06-Jan-2016 Nick Kralevich <nnk@google.com> system_properties.cpp: special case ro.* properties

Currently, reads of ro.* properties are treated differently than
writes of ro.* properties. When writing an ro.* property, we ignore
the "ro." portion of the property, and base the security decision
on the label of the remaining portion.

See https://android.googlesource.com/platform/system/core/+/e7a9e52740c952c623f7842ffa1d09b58b45e552/init/property_service.cpp
line 120-126

For example, for writing, the label associated with
"ro.build.fingerprint" comes from the /property_contexts file
entry:

# ro.build.fingerprint is either set in /system/build.prop, or is
# set at runtime by system_server.
build.fingerprint u:object_r:fingerprint_prop:s0

However, we fail to follow this same special case when sorting
properties into files. Instead, ro.build.fingerprint is assigned
u:object_r:default_prop:s0 instead of u:object_r:fingerprint_prop:s0

Ignore the "ro." portion when sorting properties into files.
This will make reads and writes of properties use the same label.

Bug: 21852512
Change-Id: Ie88ffc6b78b31fc8ddf370ae27c218546fb25a83
ystem_properties.cpp
0ef1d121b5e4845f4ef3b59ae9a1f99ceb531186 05-Jan-2016 Dimitry Ivanov <dimitry@google.com> Temporary apply LIBC version to __pthread_gettid

This is workaround for http://b/26391427

Bug: http://b/26391427
Change-Id: Ibf5c611cf4c04dfa595644225e6d9503089a18da
dk_cruft.cpp
c8bb96a163ac4e4f47f305df9e4dc1252f6a938d 05-Jan-2016 Dimitry Ivanov <dimitry@google.com> Revert "Temporary apply LIBC version to __pthread_gettid"

This reverts commit eb90e91cb5872f6aac7008b0c83e103d396be196.

Change-Id: I63450087b6d3c23218b77d5eee37965f254a82d6
dk_cruft.cpp
eb90e91cb5872f6aac7008b0c83e103d396be196 05-Jan-2016 Dimitry Ivanov <dimitry@google.com> Temporary apply LIBC version to __pthread_gettid

This is workaround for http://b/26391427

Bug: http://b/26391427
Change-Id: I4ccc56e8b1bd2597f267df9706a33bb635abcfcb
dk_cruft.cpp
9cddb482b498abd134f7ccfc9933747e8bcb9cc7 04-Jan-2016 Elliott Hughes <enh@google.com> Revert "Revert "Implement getifaddrs(3)/freeifaddrs(3).""

This reverts commit 76814a8250fd5e1502909ef5e10e4d166cc96c0e.

This differs from the original in fixing the GCC -Werror build:

bionic/libc/bionic/ifaddrs.cpp: In function 'void __handle_netlink_response(ifaddrs**, nlmsghdr*)':
bionic/libc/bionic/ifaddrs.cpp:113:62: error: use of old-style cast [-Werror=old-style-cast]
ifinfomsg* ifi = reinterpret_cast<ifinfomsg*>(NLMSG_DATA(hdr));

This appears to be a GCC bug; the GCC command-line correctly uses -isystem,
and manually adding #pragma GCC system_header doesn't help. So just turn the
warning off for GCC for now. We won't need to worry about building with GCC
soon anyway.

Bug: http://b/26238832
Change-Id: I01615bd335edf11baf487b1c83a9157cd780f4a1
faddrs.cpp
76814a8250fd5e1502909ef5e10e4d166cc96c0e 22-Dec-2015 Yi Kong <yikong@google.com> Revert "Implement getifaddrs(3)/freeifaddrs(3)."

Werror build broken. Revert while working on a fix.

This reverts commit 0945ed5cc5921243724fed4465d20881f4891a8d.

Change-Id: I67edab7a7a3b9aa673ce9d14aa95380f947838a1
faddrs.cpp
0945ed5cc5921243724fed4465d20881f4891a8d 19-Dec-2015 Elliott Hughes <enh@google.com> Implement getifaddrs(3)/freeifaddrs(3).

Time to dust off the old libcore implementation from gingerbread and add it
to bionic. Unlike the original, this actually looks at both RTM_NEWLINK and
RTM_NEWADDR.

Bug: http://b/26238832
Change-Id: I7bb4b432deb766065b66b9c9ff36ed68249aba82
faddrs.cpp
dd57119ced4670de2ea18fc84a59f20ccec353a7 17-Dec-2015 Tom Cherry <tomcherry@google.com> Merge "Reset access to system properties on reinitialization"
dd586f2ebd0c42904e699f3634568a38c97d4da7 17-Dec-2015 Elliott Hughes <enh@google.com> sem_timedwait with a null timeout doesn't mean "forever".

It actually means "crash immediately". Well, it's an error. And callers are
much more likely to realize their mistake if we crash immediately rather
than return EINVAL. Historically, glibc has crashed and bionic -- before
the recent changes -- returned EINVAL, so this is a behavior change.

Change-Id: I0c2373a6703b20b8a97aacc1e66368a5885e8c51
thread_cond.cpp
thread_mutex.cpp
thread_rwlock.cpp
emaphore.cpp
bc2e88a85d5fd3e59c041a667283378c1503a16c 16-Dec-2015 Dimitry Ivanov <dimitry@google.com> Revert "Revert "Remove remaining ndk_cruft from LP64 platforms""

This reverts commit 23af25b747b5e7b0ca513a87b32f1f6a3cb99698.

Bug: http://b/26164862
Change-Id: I201bf49530f33f8ba6a1a35b79723afb9e84c7a5
dk_cruft.cpp
23af25b747b5e7b0ca513a87b32f1f6a3cb99698 15-Dec-2015 Dimitry Ivanov <dimitry@google.com> Revert "Remove remaining ndk_cruft from LP64 platforms"

This reverts commit b1d0a2ae7790f882d8f1ab24d7ef15e2b90c8ca2.

Change-Id: I1da06be0b78a4f2a4cad7e4a19a3ee755f55a813
dk_cruft.cpp
b1d0a2ae7790f882d8f1ab24d7ef15e2b90c8ca2 15-Dec-2015 Dimitry Ivanov <dimitry@google.com> Remove remaining ndk_cruft from LP64 platforms

This change removes endpwent, dlmalloc_inspect_all, dlmalloc_trim
from lp64 libc.so. It also removed necessety of having brillo
version scripts for lp64 platforms.

Bug: http://b/26164862
Change-Id: I4e9b38907bb1dc410f0eb6d2f5d5944fe713da51
dk_cruft.cpp
b417169d80cdf975c71b03de247ea2365e83c229 10-Dec-2015 Tom Cherry <tomcherry@google.com> Reset access to system properties on reinitialization

Treat subsequent calls to __system_properties_init() as a
reinitialization of system properties and revoke access to prop files
that have been previously mapped but that the process's current context
does not have access to. Additionally reset the no_access_ flag in
case permissions have loosened and previously unaccessible files can now
be accessed.

This is meant to work around an issue that setcon() does not revoke
mmap() mappings, so we must manually revoke them after a successful
setcon() call.

Bug 26114086

Change-Id: I4d690abb6817283ca64ac26ea4c1dad398a98fbc
ystem_properties.cpp
e46ded5ce1582202cb809c907128e423e58ce7ed 11-Dec-2015 Tom Cherry <tomcherry@google.com> Merge "Do not set properties in bionic_systrace"
46e2eadad24b9d11f5319efd393066ae8c35cd54 10-Dec-2015 Tom Cherry <tomcherry@google.com> Do not set properties in bionic_systrace

Currently, if the debug.atrace.tags.enableflags property is not found,
it is set to a safe value such that a pointer to this property can be
stored for later access. This may result in selinux denials because not
all processes write permissions for this property or permission to
connect to the property write socket at all.

Change I6d953c0c281fd72ad3eba8a479fd258023579b5b writes this property to
a safe value upon boot, which greatly decreases the cases in which this
property will not be accessible and removes the need to write it here.
This commit removes this write.

Bug 26115803

Change-Id: Ief72c5f731d3a1231b5080eb531fa0a491a8b1d1
ionic_systrace.cpp
9d8632e1a76de6bd6abc853c0fbd6a2c9dc32cdc 10-Dec-2015 Dimitry Ivanov <dimitry@google.com> Merge "constexpr constructor for atfork_list_t"
6500f51c0e3ef37dbda889dbd1125c03c787ae50 10-Dec-2015 Elliott Hughes <enh@google.com> Merge "Fix -fstack-protector-strong for x86."
9da687e2f49c2a67135bf30d074de445728e109d 08-Dec-2015 Mark Salyzyn <salyzyn@google.com> bionic: Build Breakage

Bug: 23668800
Change-Id: Ic7cf5864d3f5881e6f7105a49ecf62b1bc4a604c
ibc_logging.cpp
6c54ddd20f663de9e383fcd7b4cff93471369d87 08-Dec-2015 Elliott Hughes <enh@google.com> Fix -fstack-protector-strong for x86.

We need to ensure %gs:20 is set up early enough for -fstack-protector-strong
on x86, and that __set_tls doesn't get stack protector checks because it's a
prerequisite for them. x86 devices/emulators won't boot without this.

Bug: http://b/26073874
Change-Id: Icf0d34294648cc0c8cb406a3617befe0d45c525a
ibc_init_common.cpp
89a50fe1ebfa09f6a5e82566e27f80708a50db4d 08-Dec-2015 Dimitry Ivanov <dimitry@google.com> constexpr constructor for atfork_list_t

Bug: http://b/26026986
Change-Id: Iad95383a23f81eea776bebce641c555d26547b77
thread_atfork.cpp
eaccfde0759c6df6011c2a1e69ca275f2e24d909 08-Dec-2015 Mark Salyzyn <salyzyn@google.com> Merge "Add monotonic logging for bionic"
d51a0b0f9da767d5d67c9f3565c34afcaab1a908 05-Dec-2015 Rohit Agrawal <rohitagr@google.com> Base bcopy on memmove rather than memcpy.

POSIX defined bcopy to handle overlapping memory akin to memmove and
bionic appears to have always done so.

Change-Id: I2599113411e3532913270ba1c1b49e35cbc5f106
dk_cruft.cpp
cfd5a46b092536905ffe45a19cfe1b9e35aa8d10 05-Dec-2015 Elliott Hughes <enh@google.com> Make all of ndk_cruft.cpp one big extern "C".

Change-Id: Iddd9b5f36e661e443fa13d12326e72df8c0d209c
dk_cruft.cpp
bb46afd6c44a847efe96e30d72708fd2d0906e8c 05-Dec-2015 Elliott Hughes <enh@google.com> Revert "Revert "Remove __sinit and __sdidinit.""

This reverts commit c8bae05f3ff9f1c736f7be70fa17d02795d748bb.

We were breaking init (ueventd) because we initialize system properties
before we initialize stdio. The new system property implementation uses
stdio to read from /property_contexts, so we end up touching stdio data
structures before they've been initialized.

This second attempt takes things further by removing the stdio initialization
function altogether. The data structures for stdin/stdout/stderr can be
statically initialized as data, and -- since we already had to give the
atexit implementation a backdoor for stdio -- we can just admit that we
need to clean up stdio, and that we always do so last.

This patch also removes the 17 statically pre-allocated file structures,
so the first fopen will now allocate a block of 10 (the usual overflow
behavior). I did this just to make my life simpler, but it's not actually
necessary to remove it if we want it back.

Change-Id: I936b2eb5e88e4ebaf5516121872b71fc88e5609c
lockfile.cpp
ibc_init_common.cpp
dk_cruft.cpp
c8bae05f3ff9f1c736f7be70fa17d02795d748bb 05-Dec-2015 Elliott Hughes <enh@google.com> Revert "Remove __sinit and __sdidinit."

This reverts commit 4371961e00ad83fca033992c8a19c7d262fe6f84.

This broke booting; ueventd crashes with a null pointer dereference
somewhere in __sfp (but the kernel doesn't unwind, so I don't know
what was calling __sfp).

Change-Id: I65375fdfdf1d339a06558b4057b580cacd6324e2
lockfile.cpp
ibc_init_common.cpp
dk_cruft.cpp
4ade5195f188b84ce3599c71ef058d040b141da4 05-Dec-2015 Tom Cherry <tomcherry@google.com> Merge "Do not create prop files for ctl.* properties"
21eadee6e97c08485c9ec52a8f44cabd4261bf4a 05-Dec-2015 Tom Cherry <tomcherry@google.com> Do not create prop files for ctl.* properties

Change-Id: Ia6660c68c9e0cb89938751dbc0747ee038394778
ystem_properties.cpp
8766edc098304436a8b2b1b01ef01b9401918d54 05-Dec-2015 Elliott Hughes <enh@google.com> Fix GCC build.

error: '__sdidinit' initialized and declared 'extern' [-Werror]

Change-Id: I97d9c174da6a99ca61b72572dfb4694813372a60
dk_cruft.cpp
2558b112300e0a27590b9e31f627fe94594fa6a0 05-Dec-2015 Elliott Hughes <enh@google.com> Merge "Remove __sinit and __sdidinit."
870f165ceb3348d79499d40ce8b629f62a15ff2b 01-Dec-2015 Mark Salyzyn <salyzyn@google.com> Add monotonic logging for bionic

Primarily a debug feature that can be switched at runtime to permit
developer to have the option of high-resolution Android logs with
either CLOCK_REALTIME (default) or CLOCK_MONOTONIC to correlate with
other system activities like kernel logs or systrace.

Bug: 23668800
Change-Id: Ib29024899540f51a72cad5dde25517a7134d68f7
ibc_logging.cpp
6ed51c0e8542922f8ceb2659a7921e0af096d734 04-Dec-2015 Tom Cherry <tomcherry@google.com> add checks for initialization for system properties

If a __system_property* function is called before
__system_properties_init() then the app will will abort. This commit
returns either an error code or a safe return value instead.

Bug 26027140

Change-Id: I95ffd143e9563658ab67a397991e84fb4c46ab77
ystem_properties.cpp
2452cf3c332fdfdae6b6b27b57acaa6786a91c87 04-Dec-2015 Yabin Cui <yabinc@google.com> Merge "Clear pthread_internal_t allocated on user provided stack."
304348af197f30b3bf0e0764b97eb9699a376c68 03-Dec-2015 Yabin Cui <yabinc@google.com> Clear pthread_internal_t allocated on user provided stack.

Several parts in pthread_internal_t should be initialized
to zero, like tls, key_data and thread_local_dtors. So
just clear the whole pthread_internal_t is more convenient.

Bug: 25990348
Change-Id: Ibb6d1200ea5e6e1afbc77971f179197e8239f6ea
thread_create.cpp
845e24a05e56003d0ac35d904bfc02f5dac762f1 04-Dec-2015 Tom Cherry <tomcherry@google.com> Remove c++14'isms from system_properties

Change-Id: If78e7d2770e8f8321f0d1824c3c52f93820dd325
ystem_properties.cpp
4371961e00ad83fca033992c8a19c7d262fe6f84 03-Dec-2015 Elliott Hughes <enh@google.com> Remove __sinit and __sdidinit.

We're eagerly initializing stdio now, so this can all be simplified.

Change-Id: Icb288f8dd0ee08f02bea0d23670f75e78bed6b99
lockfile.cpp
ibc_init_common.cpp
dk_cruft.cpp
49a309ff6a8349cbd1625711497743463638bebf 24-Sep-2015 Tom Cherry <tomcherry@google.com> Separate properties by selabel

The purpose of this change is to add read access control to the property
space.

In the current design, a process either has access to the single
/dev/__properties__ file and therefore all properties that it contains
or it has access to no properties. This change separates properties
into multiple property files based on their selabel, which allows
creation of sepolicies that allow read access of only specific sets of
properties to specific domains.

Bug 21852512

Change-Id: Ice265db79201ca811c6b6cf6d851703f53224f03
ystem_properties.cpp
6bef152af2c622ee0c57f9c374b76f3dd352e52b 01-Dec-2015 Yabin Cui <yabinc@google.com> Merge "Init stdio in __libc_init_common."
d68c9e5906917f1528fe16c2c657e3a34c16e536 25-Nov-2015 Yabin Cui <yabinc@google.com> Init stdio in __libc_init_common.

Previously we call __sinit() lazily. But it is likely to cause data
races like in https://android-review.googlesource.com/#/c/183237/. So
we prefer to call __sinit() explicitly at libc initialization.

Bug: 25392375

Change-Id: I181ea7a4b2e4c7350b45f2e6c86886ea023e80b8
ibc_init_common.cpp
952e9eb0866bc2061b671e8d6c90cae275eda6bd 25-Nov-2015 Yabin Cui <yabinc@google.com> Don't use __thread in __cxa_thread_finalize().

Currently we use __thread variable to store thread_local_dtors,
which makes tsan test fork_atexit.cc hang. The problem is as below:
The main thread creates a worker thread, the worker thread calls
pthread_exit() -> __cxa_thread_finalize() -> __emutls_get_address()
-> pthread_once(emutls_init) -> emutls_init().
Then the main thread calls fork(), the child process cals
exit() -> __cxa_thread_finalize() -> __emutls_get_address()
-> pthread_once(emutls_init).
So the child process is waiting for pthread_once(emutls_init)
to finish which will never occur.

It might be the test's fault because POSIX standard says if a
multi-threaded process calls fork(), the new process may only
execute async-signal-safe operations until exec functions are
called. And exit() is not async-signal-safe. But we can make
bionic more reliable by not using __thread in
__cxa_thread_finalize().

Bug: 25392375
Change-Id: Ife403dd7379dad8ddf1859c348c1c0adea07afb3
_cxa_thread_atexit_impl.cpp
thread_internal.h
17554356cc865908e5cbd7814c8be7e47c9c4ec5 23-Nov-2015 Yabin Cui <yabinc@google.com> Merge "Change _stdio_handles_locking into _caller_handles_locking."
74ed96d59731aa3661494330804d866e825209d3 21-Nov-2015 Yabin Cui <yabinc@google.com> Merge "Use FUTEX_WAIT_BITSET to avoid converting timeouts."
76144aaa6397fe9e16893882cf59c5c9c0684a66 19-Nov-2015 Yabin Cui <yabinc@google.com> Change _stdio_handles_locking into _caller_handles_locking.

It is reported by tsan that funlockfile() can unlock an unlocked mutex.
It happens when printf() is called before fopen() or other stdio stuff.
As FLOCKFILE(fp) is called before __sinit(), _stdio_handles_locking is false,
and _FLOCK(fp) will not be locked. But then cantwrite(fp) in __vfprintf()
calls__sinit(), which makes _stdio_handles_locking become true, and
FUNLOCKFILE(fp) unlocks _FLOCK(fp).

Change _stdio_handles_locking into _caller_handles_locking,
so __sinit() won't change its value. Add test due to my previous fault.

Bug: 25392375
Change-Id: I483e3c3cdb28da65e62f1fd9615bf58c5403b4dd
lockfile.cpp
ee67dd75e215f88e5632c05c7e7e7c7d30910359 24-Sep-2015 Vitaly Vul <vitaly.vul@sonymobile.com> mmap: fix calculation of is_private_anonymous variable

Currently is_private_anonymous is calculated as true if _either_
MAP_PRIVATE or MAP_ANONYMOUS is set, which is a mistake.
According to Documentation/vm/ksm.txt, "KSM only merges anonymous
(private) pages, never pagecache (file) pages". MAP_PRIVATE can
still be set on file cache pages so in order to not redundantly
set MADV_MERGEABLE on pages that are not fitted for it, both
MAP_PRIVATE and MAP_ANONYMOUS should be set.

Along with this fix, add an extra check that the mapped page is
not a stack page before setting MADV_MERGEABLE for it. Stack pages
change too quickly and always end up in KSM 'page_volatile' list.

Change-Id: If4954142852f17cc61f02985ea1cb625a7f3dec6
map.cpp
f30170dfa514266a0bf007091aa54a866920208c 20-Nov-2015 Josh Gao <jmgao@google.com> Merge changes I73a39c6d,Iab2af242

* changes:
Fix test build break.
extend the PTRDIFF_MAX size check to mremap
284068f44fd1ad2d22980ea39f49d2c1b74014c7 19-Nov-2015 Yabin Cui <yabinc@google.com> Fix tsan abort for lake of __libc_auxv initialization.

If tsan is used, the following callchain can happen:
__libc_preinit() -> __libc_init_globals() ->
__libc_init_vdso() -> strcmp() -> __tsan_init()
-> sysconf(_SC_PAGE_SIZE) -> getauxval().
But __libc_auxv is initialized in __libc_init_common(),
after __libc_init_globals(). One simple way to fix
this is to initialize __libc_auxv at __libc_init_globals().

Bug: 25392375
Change-Id: I3893b1f567d5f3b7a8c881c0c1b8234b06b7751b
ibc_init_common.cpp
c9a659c57b256001fd63f9825bde69e660c2655b 06-Nov-2015 Yabin Cui <yabinc@google.com> Use FUTEX_WAIT_BITSET to avoid converting timeouts.

Add unittests for pthread APIs with timeout parameter.

Bug: 17569991

Change-Id: I6b3b9b2feae03680654cd64c3112ce7644632c87
_cxa_guard.cpp
ionic_time_conversions.cpp
thread_barrier.cpp
thread_cond.cpp
thread_mutex.cpp
thread_once.cpp
thread_rwlock.cpp
emaphore.cpp
c22a7de798c4c0da30ad095a0c61a8f905eb9613 07-Nov-2015 Daniel Micay <danielmicay@gmail.com> extend the PTRDIFF_MAX size check to mremap

This removes another way to obtain objects larger than PTRDIFF_MAX. The
only known remaining hole is now jemalloc's merging of virtual memory
spans.

Technically this could be wrapped in an __LP64__ ifndef since it can't
occur on 64-bit due to the 1:1 split. It doesn't really matter either
way.

Change-Id: Iab2af242b775bc98a59421994d87aca0433215bd
map.cpp
remap.cpp
2c09e5de299ca87a9e68807e2b4af41ba61710f3 19-Nov-2015 Yabin Cui <yabinc@google.com> Merge "Implement pthread spin."
fe3a83a9343f0e4ff654f09ef8ffc8a773c7c105 18-Nov-2015 Yabin Cui <yabinc@google.com> Implement pthread spin.

In order to run tsan unit tests, we need to support pthread spin APIs.

Bug: 18623621
Bug: 25392375
Change-Id: Icbb4a74e72e467824b3715982a01600031868e29
thread_spinlock.cpp
0307eee293e90e8584104a3c55bf2f270b1149b6 17-Nov-2015 Yabin Cui <yabinc@google.com> Avoid tsan warning about pthread_mutex_destroy.

If calling pthread_mutex_trylock from pthread_mutex_destroy, tsan
warns about an attempt to destroy a locked mutex.

Bug: 25392375
Change-Id: I5feee20e7a0d0915adad24da874ec1ccce241381
thread_mutex.cpp
b804b9d67b9e3a8c63471ff9892f6abea2a58684 17-Nov-2015 Yabin Cui <yabinc@google.com> Merge "Implement pthread barrier."
e7c2fffa16eccecfd43d99516751a43776f5f609 06-Nov-2015 Yabin Cui <yabinc@google.com> Implement pthread barrier.

Bug: 24341262
Change-Id: I5472549e5d7545c1c3f0bef78235f545557b9630
thread_barrier.cpp
2fb02651c894866c220bd64cbcd5fbd14e086b85 11-Nov-2015 Nick Kralevich <nnk@google.com> libc_init_common.cpp: Clarify when environment stripping occurs

The current comment implies that we only strip sensitive
environment variables on executing a setuid program. This is
true but incomplete. The AT_SECURE flag is set whenever a
security transition occurs, such as executing a setuid program,
SELinux security transition, executing a file with file capabilities,
etc...

Fixup the comments.

Change-Id: I30a73992adfde14d6e5f642b3a1ead2ee56726be
ibc_init_common.cpp
926ebe109424baa407b2cd938ba053b5c0b8ce7c 24-Sep-2015 Tom Cherry <tomcherry@google.com> Refactor prop_area into a class

Bug 21852512

Change-Id: I432bf592f1a71a046c32616fc334ad77c220f0ca
ystem_properties.cpp
4200e260d266fd0c176e71fbd720d0bab04b02db 03-Nov-2015 Daniel Micay <danielmicay@gmail.com> fix the mremap signature

The mremap definition was incorrect (unsigned long instead of int) and
it was missing the optional new_address parameter.

Change-Id: Ib9d0675aaa098c21617cedc9b2b8cf267be3aec4
octl.c
octl.cpp
remap.cpp
706186d266d45c161f9dad3ec1851c78017bc1de 03-Nov-2015 Daniel Micay <danielmicay@gmail.com> fix PTRDIFF_MAX check in the 32-bit mmap wrapper

It wasn't making use of the page-rounded size.

Change-Id: I911345fcfd6419a4dbc18a4622b42e1b76729abb
map.cpp
1721cd6a74996104d07bcdfd8581da4189cb1a6e 31-Oct-2015 Christopher Ferris <cferris@google.com> Make _signal hidden in all cases.

_signal was static in 64 bit, and hidden on 32 bit. There is no
reason to have this distinction, so make it hidden in all cases.

Change-Id: I09d5d93ac8cab4fe14dc7bdfeb25aa46a3b7413d
ignal.cpp
c36be975ce4525b452435f43beb1fb9fc26a7fdc 31-Oct-2015 Elliott Hughes <enh@google.com> Merge "Add prlimit to LP32."
9978a9a82e3b883b32a7a0bcd5cac18f31e7a68d 30-Oct-2015 Christopher Ferris <cferris@google.com> Move __set_errno to ndk_cruft.cpp.

Change-Id: I5caa1cc161961d2e4629429c0d406875b93cdbd0
_set_errno.cpp
dk_cruft.cpp
4151db5f997cd91d3505ac6594bede0b50184855 29-Oct-2015 Elliott Hughes <enh@google.com> Add prlimit to LP32.

Bug: http://b/24918750
Change-Id: I0151cd66ccf79a6169610de35bb9c288c0fa4917
egacy_32_bit_support.cpp
d7c7daada276276e77446c099a67dd3ea15ea72e 28-Oct-2015 Elliott Hughes <enh@google.com> Remove the legacy endusershell/getusershell/setusershell stubs.

These don't work, aren't thread-safe, aren't in POSIX (or our header
files), and are only used by one app (whose developers I've contacted).
But the presence of these symbols causes configure to be confused, which
is a pain for Brillo.

Bug: http://b/24812426
Change-Id: I7fa6ef82864d5563929d9b8a7f8fcacb30b26d45
dk_cruft.cpp
6331e806de41d98083f1bfa3661addfae4682c37 27-Oct-2015 Elliott Hughes <enh@google.com> Implement scandirat and scandirat64.

Bug: http://b/12612339
Change-Id: Id3b249a884fe08964b26a017ae9574961f0cb441
candir.cpp
a8184456229ace2b0255468e6b15aeb6509e27f7 23-Oct-2015 Christopher Ferris <cferris@google.com> Rename LIBC64_HIDDEN to LIBC32_LEGACY_PUBLIC.

Change-Id: If4da9e46398ca5524f6f0680d70588e3dc7e80b4
ibgen.cpp
d26e780df66b9add4cf7e7ebb2f6c6749d1c5050 23-Oct-2015 Yabin Cui <yabinc@google.com> Use bionic lock in pthread_internal_t.

It removes calling to pthread_mutex_lock() at the beginning of new
thread, which helps to support thread sanitizer.

Change-Id: Ia3601c476de7976a9177b792bd74bb200cee0e13
thread_create.cpp
thread_internal.h
d29ba555130f1e61164cf6186cd6a29c7aa14719 17-Oct-2015 Elliott Hughes <enh@google.com> Merge "Opt Brillo out of the ndk cruft."
c433a36fb5fb8a1050e8ecbd94d215123b829e07 15-Oct-2015 Josh Gao <jmgao@google.com> Merge "Move malloc dispatch table to __libc_globals."
198d13e8c25e69f7dbda3f5e1a3258b13fe8db5d 14-Oct-2015 Josh Gao <jmgao@google.com> Merge "make mmap fail on requests larger than PTRDIFF_MAX"
3c8fc2fea9dac044f4903b0c315b5cda1c1f5301 08-Oct-2015 Josh Gao <jmgao@google.com> Move malloc dispatch table to __libc_globals.

Change-Id: Ic20b980d1e8b6c2d4b773ebe336658fd17c737cb
ibc_init_dynamic.cpp
alloc_debug_common.cpp
alloc_debug_common.h
fb8fd5076ea7ccc77960346e52b81134ccbb9ea3 13-Oct-2015 Elliott Hughes <enh@google.com> Opt Brillo out of the ndk cruft.

Bug: http://b/24812426
Change-Id: I6a858d8ceebce9e2285e5b12de9fd89d2b42b352
dk_cruft.cpp
1ab3f303d2e7c8cc498a28fc3c8d9ded1fc46994 10-Oct-2015 Elliott Hughes <enh@google.com> Merge "Fix inet_aton on LP32."
7b77cb35aff34ff56a0b63517267c6203f9d1119 10-Oct-2015 Elliott Hughes <enh@google.com> Fix inet_aton on LP32.

I wasn't checking for overflow. Luckily, I had a test that overflows on LP32.

Change-Id: If2cf33d88f459eb26d0ce75f3c5ed192f516ab7a
rpa_inet.cpp
fe9d0ed6cb10d5403e54d2dd12628a0ec345ae6e 07-Oct-2015 Josh Gao <jmgao@google.com> Move setjmp cookie to a shared globals struct.

Change-Id: I59a4c187d61524c4e48655c4c6376dba0d41eee2
ibc_init_common.cpp
etjmp_cookie.cpp
93c0f5ee00d1357247fda333c9d49c8673c9c83b 06-Oct-2015 Josh Gao <jmgao@google.com> Move VDSO pointers to a shared globals struct.

Change-Id: I01cbc9cf0917dc1fac52d9205bda2c68529d12ef
ibc_init_common.cpp
ibc_init_common.h
ibc_init_dynamic.cpp
ibc_init_static.cpp
dso.cpp
047866672c66e51b557721cf50ba101305c252d2 09-Oct-2015 Elliott Hughes <enh@google.com> Fix inet_addr/inet_aton/inet_network.

Rewrite inet_addr and inet_network in terms of inet_aton, and reimplement
that to include all the missing error checks.

Bug: http://b/24754503
Change-Id: I5dfa971c87201968985a0894df419f0fbf54768a
rpa_inet.cpp
a5d5d16c3c5679afd26e6bbc24215b7c20025ade 02-Oct-2015 Josh Gao <jmgao@google.com> Use foreach loop to match setuid unsafe env vars.

Change-Id: I1e94daefac8e601281f38c7ce29ba3172a4a60bb
ibc_init_common.cpp
4a65557d0ebd167e557958687f50510742cb238a 01-Oct-2015 Stephen Hines <srhines@google.com> Merge "Remove invalid left shifts of -1."
cb6f599c44b144db26c13507dbd89805b8fe03be 30-Sep-2015 Yabin Cui <yabinc@google.com> Fix the way to count online cpus.

Read /proc/stat to count online cpus is not correct for all android
kernels. Change to reading /sys/devices/system/cpu/online instead.

Bug: 24376925
Change-Id: I3785a6c7aa15a467022a9a261b457194d688fb38
ysinfo.cpp
23360cc4980213d375718b7c124ecc0a21a1b1b7 29-Sep-2015 Stephen Hines <srhines@google.com> Remove invalid left shifts of -1.

Bug: 24492248

Shifting sign bits left is considered undefined behavior, so we need to
switch these uses to unsigned equivalents. The time_t-related code is
updated relative to upstream sources.

Change-Id: I226e5a929a10f5c57dfcb90c748fdac34eb377c2
emaphore.cpp
9e3a24915241c07d8ea886533c8de6a85744a734 23-Sep-2015 Elliott Hughes <enh@google.com> Merge "Clean up /proc/<pid>/maps sscanfs."
0dec2289211dd75e2dd99e4aad84ece845e69864 23-Sep-2015 Elliott Hughes <enh@google.com> Clean up /proc/<pid>/maps sscanfs.

sscanf will swallow whitespace for us.

Change-Id: I59931cbad00f0144fd33ed4749ac0aaad15e6de6
ebug_mapinfo.cpp
dd51453904f609347ce7951661eff8bc12a1c0a4 22-Sep-2015 Jorge Lucangeli Obes <jorgelo@google.com> Merge "Add preliminary OEM UID/GID support."
a39e30141d46c268ca66d6ad786d244275c4e827 22-Sep-2015 Jorge Lucangeli Obes <jorgelo@google.com> Add preliminary OEM UID/GID support.

Until we implement full support for passwd/group files, add a simple
way to use the new OEM UID/GID range (5000-5999).

oem_XXX -> 5000 + XXX iff 0 <= XXX < 1000.

Bug: 23225475

Change-Id: If48b88135d5df538313414f747d6c4c63bf0a103
tubs.cpp
33ac04a215a70d2f39f1ddec1bba5a42c0fd8bee 22-Sep-2015 Yabin Cui <yabinc@google.com> Increase alternative signal stack size on 64-bit devices.

Bug: 23041777
Bug: 24187462
Change-Id: I7d84c0cc775a74753a3e8e101169c0fb5dbf7437
thread_internal.h
7fda8d2aa4d24ab400f6f0cb9f792488b634afae 11-Sep-2015 Josh Gao <jmgao@google.com> Implement setjmp cookies on ARM.

Reuse the top bits of _JB_SIGFLAG field previously used to store a
boolean to store a cookie that's validated by [sig]longjmp to make it
harder to use as a ROP gadget. Additionally, encrypt saved registers
with the cookie so that an attacker can't modify a register's value to
a specific value without knowing the cookie.

Bug: http://b/23942752
Change-Id: Id0eb8d06916e89d5d776bfcaa9458f8826717ba3
ibc_init_common.cpp
etjmp_cookie.cpp
569333293aeefbe792826cd59140dc23704018c4 11-Sep-2015 Mor-sarid, Nitzan <nitzan.mor-sarid@intel.com> Fix the way to get main thread stack start address.

For previous way to get the stack using the [stack] string from
/proc/self/task/<pid>/maps is not enough. On x86/x86_64, if an
alternative signal stack is used while a task switch happens,
the [stack] indicator may no longer be correct.

Instead, stack_start from /proc/self/stat which is always inside
the main stack, is used to find the main stack in /proc/self/maps.

Change-Id: Ieb010e71518b57560d541cd3b3563e5aa9660750
Signed-off-by: Nitzan Mor-sarid <nitzan.mor-sarid@intel.com>
Signed-off-by: Mingwei Shi <mingwei.shi@intel.com>
thread_attr.cpp
5ca66528c5e02655d79b9930456e31aab887989e 04-Aug-2015 Daniel Micay <danielmicay@gmail.com> make mmap fail on requests larger than PTRDIFF_MAX

Allocations larger than PTRDIFF_MAX can be successfully created on
32-bit with a 3:1 split, or in 32-bit processes running on 64-bit.

Allowing these allocations to succeed is dangerous, as it introduces
overflows for `end - start` and isn't compatible with APIs (mis)using
ssize_t to report either the size or an error. POSIX is guilty of this,
as are many other Android APIs. LLVM even considers the `ptr + size`
case to be undefined, as all pointer arithmetic compiles down to signed
operations and overflow is treated as undefined for standard C pointer
arithmetic (GNU C `void *` arithmetic works differently).

This also prevents dlmalloc from allocating > PTRDIFF_MAX as it doesn't
merge mappings like jemalloc. A similar check will need to be added in
jemalloc's code path for huge allocations.

The musl libc implementation also performs this sanity check.

Change-Id: I5f849543f94a39719f5d27b00cef3079bb5933e9
map.cpp
efc134dba34baa942fd698e842ee2c6a8f57252e 04-Sep-2015 Christopher Ferris <cferris@google.com> Only close stdin/stdout/stderr for debug malloc.

The debug malloc code unconditionally closes stdin/stdout/stderr,
which means that other atexit functions cannot use them. Only
close these if there is a debug malloc final function to call.

This doesn't appear to be a problem on most normal applications or the
atexit_exit bionic unit test would be failing. However, if you
enable stat dumping in jemalloc, nothing prints. Most likely trying
to add an atexit function from within libc is causing that atexit
to run after the debug malloc atexit function.

Change-Id: I963720d4ccaaa511e44af07a7461f17eb3f84e8e
alloc_debug_common.cpp
32bf43f44a4c0ccf04c6a60094aff574d50ecfe7 02-Sep-2015 Elliott Hughes <enh@google.com> Rename debug_stacktrace to debug_backtrace.

All the functions say "backtrace", so it's weird that the filename
says "stacktrace".

Change-Id: I1c88a56c1f9adb1bae4615edc8af3e73db270a8c
ebug_backtrace.cpp
ebug_backtrace.h
ebug_stacktrace.cpp
ebug_stacktrace.h
alloc_debug_check.cpp
alloc_debug_leak.cpp
848808c660ec4811f4ff5a2748b6f754b008cd21 27-Aug-2015 Elliott Hughes <enh@google.com> Merge "Add preadv/pwritev."
6f4594d5dc61bb67978c44cd6eeb0e7bfb621c9b 26-Aug-2015 Elliott Hughes <enh@google.com> Add preadv/pwritev.

Bug: http://b/12612572
Change-Id: I38ff2684d69bd0fe3f21b1d371b88fa60d5421cb
egacy_32_bit_support.cpp
d518a6d3bccc82cffb61fb7615b8ba09a564dec0 26-Aug-2015 Christopher Ferris <cferris@google.com> Merge "Fix the 16 bit/32 bit instruction check for arm."
b72c9d80ab760eb2f33a6667b0f0acfb779d9439 26-Aug-2015 Christopher Ferris <cferris@google.com> Fix the 16 bit/32 bit instruction check for arm.

The current code only looks for a branch, instead make this more
general.

Change-Id: Ib442d6f2f04074e274b320ca0cf04734cc78e5d2
ebug_stacktrace.cpp
7ac3c128bb5df83cb001cb50b6a5ee4da9a0b0e0 26-Aug-2015 Elliott Hughes <enh@google.com> Add strchrnul.

Bug: http://b/18374026
Change-Id: Iea923309c090a51a2d41c5a83320ab3789f40f1c
trchrnul.cpp
62c26ed93e76ca9b3dd265f41eb3685ed2e72808 21-Aug-2015 Yabin Cui <yabinc@google.com> Merge "add fortified implementations of write/pwrite{,64}"
afdd15456ad0c7223c690731f5eb0af54cdb0024 21-Jul-2015 Daniel Micay <danielmicay@gmail.com> add fortified implementations of write/pwrite{,64}

These are just based on the read/pread{,64} implementations with the
function calls and error messages adjusted as appropriate. The only
difference is that the buffer parameters are const.

Change-Id: Ida1597a903807f583f230d74bcedffdb7b24fcf6
_pwrite64_chk.cpp
_pwrite_chk.cpp
_write_chk.cpp
224bef8ec492e8c2a88f17f05ab7982495b43d6a 19-Aug-2015 Christopher Ferris <cferris@google.com> Modify ip to get the instr being executed.

The ip values being reported are always pointing at the next
instruction to execute, not the currently executing instruction.
Change the ip address to point at the currently executing instruction.

This fixes a problem where the next instruction is not actually
part of the same function, so if an addr2line is used, it reports
the wrong value.

This does not modify the ip for mips.

Bug: 22565486
Change-Id: Ie0df4c9727f62ce06948b9a2b0e4b7956eb6e752
ebug_stacktrace.cpp
9101b00400cfb20b96112682169c5da67e065ff2 20-May-2015 Daniel Micay <danielmicay@gmail.com> add a fortified implementation of getcwd

Change-Id: Ice3e6d3e1ff07788305dc85f8ee4059baad5fac4
_getcwd_chk.cpp
etcwd.cpp
36443fd542a96d2ed71fc294f70fed08c115af55 29-Jul-2015 Elliott Hughes <enh@google.com> Remove PAGE_SIZE from <limits.h>.

It turns out that everyone's still getting PAGE_SIZE from <sys/user.h> via
<sys/ucontext.h> via <signal.h> anyway.

glibc has PAGE_SIZE in <sys/user.h> rather than <limits.h> so this part is
good. The bad part is that we have such wide transitive inclusion of
<sys/user.h>!

Bug: http://b/22735893
Change-Id: I363adffe4a27b4ca1eedf695ea621f5dd2d5ca10
ysinfo.cpp
820a86f2df90419d4b0e7ae6004eb73bb804fc7e 29-Jul-2015 Elliott Hughes <enh@google.com> Remove PAGESIZE.

This was pretty much unused, and isn't in glibc.

Bug: http://b/22735893
Change-Id: If17f0dcd931c90ef1ccb134a3950c3b0011a03f4
alloc_debug_qemu.cpp
ysconf.cpp
afab3ffcce1054ec887fb347700819d69a9c8151 28-Jul-2015 Elliott Hughes <enh@google.com> Move PAGE_MASK into <sys/user.h>.

I'm removing the TODO on the assumption that being compatible with glibc
is more useful than BSD. The new internal "bionic_page.h" header factors
out some duplication between libc and the linker.

Bug: http://b/22735893
Change-Id: I4aec4dcba5886fb6f6b9290a8f85660643261321
ibc_init_static.cpp
667dc75ee1c7c922f8610ccc6b70002642141f08 28-Jul-2015 Mark Salyzyn <salyzyn@google.com> deprecate TARGET_USES_LOGD

This is not the kernel logger you are looking for

Bug: 22787659
Change-Id: I340d8bb5cdaa73be9565521681ee238b7033934b
ibc_logging.cpp
8af32633498184e58e6f8d5d75b9f9cdbef5b6be 28-Jul-2015 Yabin Cui <yabinc@google.com> Merge "add fortified implementations of fread/fwrite"
189394b885e4b11e9f009fd2e434e6dc6696277b 25-Jul-2015 Elliott Hughes <enh@google.com> Use AT_PAGESZ for sysconf(_SC_PAGE_SIZE).

Bug: http://b/18342333
Change-Id: Id12ed4e85a0f35d7d27202f7792df42a65a74b4e
ysconf.cpp
fed2659869ec41a93f655be8058568ddab419e01 18-Jul-2015 Daniel Micay <danielmicay@gmail.com> add fortified implementations of fread/fwrite

A __size_mul_overflow utility is used to take advantage of the checked
overflow intrinsics in Clang and GCC (>= 5). The fallback for older
compilers is the optimized but less than ideal overflow checking pattern
used in OpenBSD.

Change-Id: Ibb0d4fd9b5acb67983e6a9f46844c2fd444f7e69
_fread_chk.cpp
_fwrite_chk.cpp
166112531558a1d4ea179c29147f27db7045db22 22-Jul-2015 Yabin Cui <yabinc@google.com> Don't abort when failed to write tracing message.

Also make the code thread-safe with lock.

Bug: 20666100
Change-Id: I0f331a617b75280f36179c187418450230d713ef
ionic_systrace.cpp
2565492db0d67b95348cd1c3026ed338ca59aa37 22-Jul-2015 Yabin Cui <yabinc@google.com> Merge "Add getgrgid_r/getgrnam_r."
c4786d366b11ed81165d43ee7f23e0d4965fc00f 21-Jul-2015 Yabin Cui <yabinc@google.com> Add getgrgid_r/getgrnam_r.

Bug: 22568551
Change-Id: I3c0772d119d6041063c6be53f5bcc5ea1768f0d5
tubs.cpp
3b49d61ac2f7a02d5e7f25a24836b060f922f079 22-Jul-2015 Elliott Hughes <enh@google.com> Merge "libc: arch-x86: implement kernel vdso time functions"
10726d52ac3a7b34a6e2d9c40532037ca1108485 15-Jul-2015 Robert Jarzmik <robert.jarzmik@intel.com> libc: arch-x86: implement kernel vdso time functions

This patch give the possibility of time vdso support on 32bit kernel.
If the 32bit x86 kernel provides gettimeofday() and clock_gettime()
primitives in vdso. In this case make bionic use them. If the kernel
doesn't provide them, fallback to the legacy system call versions.

Change-Id: I87b772a9486fa356903e1f98f486ab9eb0b6f6f7
Signed-off-by: Robert Jarzmik <robert.jarzmik@intel.com>
Signed-off-by: Mingwei Shi <mingwei.shi@intel.com>
dso.cpp
d29486343a66cae37fc4fc74ed206fd29f25476b 21-Jul-2015 Elliott Hughes <enh@google.com> Use a less misleading name for the code that sets up the main thread.

Change-Id: I50c1b0a3b633cf8bc40a6bd86f12adb6b91e2888
ibc_init_common.cpp
ibc_init_static.cpp
c99fabb7a097e9aeed49ce03584cce113d086905 21-Jul-2015 Christopher Ferris <cferris@google.com> Merge "Add support for non-zero vaddr in maps."
613f8145087a763e128d58e638bc85799fb06989 21-Jul-2015 Elliott Hughes <enh@google.com> Revert "Revert "make vdso function pointers read-only at runtime""

This reverts commit 1946856b1f18a27c51ba30bb9e304f25b722ee05.

This goes back to the original scheme of PROT_NONEing a page within
libc. Allocating a new page didn't fail safe for cases where these
functions are called from the dynamic linker.

Bug: http://b/22568628
Change-Id: I3e7241c8b54c27ea4a898bc952375c1e9ae38c80
dso.cpp
1946856b1f18a27c51ba30bb9e304f25b722ee05 20-Jul-2015 Elliott Hughes <enh@google.com> Revert "make vdso function pointers read-only at runtime"

This reverts commit df1a3c6d21702e3e96cfcddadee4a50bfac82110.

This change prevented N9 from booting (http://b/22568628).

Change-Id: I071d6d6a0ae7881d65641839e665acdcf58462b4
dso.cpp
df1a3c6d21702e3e96cfcddadee4a50bfac82110 17-Jul-2015 Daniel Micay <danielmicay@gmail.com> make vdso function pointers read-only at runtime

Global, writable function pointers are low-hanging fruit for hijacking
control flow with an overflow from a global buffer or an arbitrary write
vulnerability. This moves the function pointer table into a dedicated
page and makes it read-only at runtime, similar to RELRO.

This increases the memory usage of the library by just under one page.
This could be avoided by having the linker load the vdso by replacing
weak symbols. It's not significant within the Zygote spawning model
though because it's read-only after early init.

Change-Id: Id7a49c96c1b15c2e1926528304b3c54a81e78caf
dso.cpp
70b6e1daffd58ebce006d4b504cd0fb9672b6d07 16-Jul-2015 Christopher Ferris <cferris@google.com> Add support for non-zero vaddr in maps.

If a map has a non-zero vaddr then it needs to be added to the
computed relative offset.

Bug: 22532054
Change-Id: If55015165d25ecc4b530f674b481c8c7ef760a23
ebug_mapinfo.cpp
ebug_mapinfo.h
3a40a0000a2051bab284a220ed5dfa6d2978a744 12-Jul-2015 Christopher Ferris <cferris@google.com> Do not hold hash table lock while backtracing.

There is a deadlock if holding the hash table lock while trying to do
a backtrace. Change the code so that the hash table lock is only held
while actually modifying either g_hash_table, or while modifying an
entry from g_hash_table.

Bug: 22423683
(cherry picked from commit 9fee99b06013787054a312449b94115038e2ad7c)

Change-Id: I72173bfe6f824ceaceea625c24e7851b87467135
alloc_debug_leak.cpp
a20a35fdda5aa4ae3c244bf7f46cdd60ab580429 11-Jul-2015 Elliott Hughes <enh@google.com> Prevent user-defined basename_r from breaking basename(3).

LP64 is immune because basename_r is hidden there, but on LP32 a basename_r
defined in the executable breaks basename because its call to basename_r
will resolve to that one rather than the one in libc.

Bug: http://b/22415484
Change-Id: Ied3ca7ad3fb0e744eb705fc924743f893b4ad490
ibgen.cpp
eeb6b57e750220edc0b489fae11837bc73fa7a45 02-Jul-2015 Elliott Hughes <enh@google.com> Name the thread stack and signal stack guard pages.

Bug: http://b/22228722
Change-Id: I1dae672e386e404fb304a34496a29fe21134c784
thread_create.cpp
c2247478d5bcd6e8fe4d2b58f0bdeff73daa4c80 01-Jul-2015 Dmitriy Ivanov <dimitry@google.com> Improve personality initialization

1. Personality parameter should be unsigned int (not long)
2. Do not reset bits outside of PER_MASK when setting
personality value.
3. Set personality for static executables.

Bug: http://b/21900686
Change-Id: I4c7e34079cbd59b818ce221eed325c05b9bb2303
(cherry picked from commit f643eb38c36eb63f612e20dea09fd43ac6a6b360)
ibc_init_common.cpp
b1304935b64ffcd59cd787cc9ac83a2d14dc587b 16-Jun-2015 Elliott Hughes <enh@google.com> Hide accidentally-exposed __clock_nanosleep.

Bug: http://b/21858067
Change-Id: Iaa83a5e17cfff796aed4f641d0d14427614d9399
lock_nanosleep.cpp
ba1d40a3f16525e70e4b68c5a82e7cc9f8a4b76a 11-Jun-2015 Elliott Hughes <enh@google.com> Merge "Statically linked executables should honor AT_SECURE."
60907c7f4ec788def8741e4efb933eafb6560eaa 10-Jun-2015 Christopher Ferris <cferris@google.com> Allow NULL in pthread_mutex_lock/unlock.

The pthread_mutex_lock and pthread_mutex_unlock were allowed to
fail silently on L 32 bit devices when passed a NULL. We changed
this to a crash on 32 bit devices, but there are still games that make
these calls and are not likely to be updated. Therefore, once again
allow NULL to be passed in on 32 bit devices.

Bug: 19995172
(cherry picked from commit 511cfd9dc8cb41bca4920687c7d816ee916ee8e5)

Change-Id: I159a99a941cff94297ef3fffda7075f8ef1ae252
thread_mutex.cpp
1801db3d3fe17df543e721b9fb355e5c882dc6cc 09-Jun-2015 Elliott Hughes <enh@google.com> Statically linked executables should honor AT_SECURE.

Bug: http://b/19647373
Change-Id: I10e7682d9cec26a523f1a3597ca5326c3ca42ebe
ibc_init_common.cpp
ibc_init_common.h
ibc_init_static.cpp
12fb28bbd85cea72bd951d8263b05e54415780e7 08-Jun-2015 Nick Kralevich <nnk@google.com> Merge "Add O_PATH support for flistxattr()"
e1d0810cd7e2aa045d5cc1e7d2b8697acd8467be 06-Jun-2015 Nick Kralevich <nnk@google.com> Add O_PATH support for flistxattr()

A continuation of commit 2825f10b7f61558c264231a536cf3affc0d84204.

Add O_PATH compatibility support for flistxattr(). This allows
a process to list out all the extended attributes associated with
O_PATH file descriptors.

Change-Id: Ie2285ac7ad2e4eac427ddba6c2d182d41b130f75
listxattr.cpp
f9554a17765fd91d97d1f74913a626f01e880cee 06-Jun-2015 Christopher Ferris <cferris@google.com> Export two dlmalloc functions everywhere.

The functions dlmalloc_inspect_all and dlmalloc_trim get
exported on devices that use dlmalloc, so be consistent and
export them everywhere.

Bug: 21640784
Change-Id: I5b8796cd03c8f401d37d9c22823144f766f9c4c7
lmalloc.h
dk_cruft.cpp
c062218a9b9ae150e0c63ac2e1e5285fd5e1c476 04-Jun-2015 Christopher Ferris <cferris@google.com> Reorder DIR structure due to bad apps.

It turns out that apportable apps expect that the DIR structure is
the same as in L and below. Modify the structure to have the same
order, and move the new variable to the end of the structure.

Bug: 21037208
(cherry picked from commit 5edb0f40f654c804d38f1bff43f91719e189c892)

Change-Id: I0c1ab5e295ec8bef638daa4cfea5830aeea602e6
irent.cpp
2825f10b7f61558c264231a536cf3affc0d84204 31-May-2015 Nick Kralevich <nnk@google.com> libc: Add O_PATH support for fgetxattr / fsetxattr

Support O_PATH file descriptors when handling fgetxattr and fsetxattr.
This avoids requiring file read access to pull extended attributes.

This is needed to support O_PATH file descriptors when calling
SELinux's fgetfilecon() call. In particular, this allows the querying
and setting of SELinux file context by using something like the following
code:

int dirfd = open("/path/to/dir", O_DIRECTORY);
int fd = openat(dirfd, "file", O_PATH | O_NOFOLLOW);
char *context;
fgetfilecon(fd, &context);

This change was motivated by a comment in
https://android-review.googlesource.com/#/c/152680/1/toys/posix/ls.c

Change-Id: Ic0cdf9f9dd0e35a63b44a4c4a08400020041eddf
getxattr.cpp
setxattr.cpp
9d476a02e9a14e847669a6683c585028175aa322 01-Jun-2015 Dan Albert <danalbert@google.com> Cleanup ftruncate negative test.

Addresses post-submit comments from
I54692ab8105dd09db6af7a2c0894a17bdd118aa0.

Bug: http://b/21309901
Change-Id: Ie19ee8cdcc4055a65fe7dfc103156e54eafe8977
truncate.cpp
c05554ec5c9aff5e0f1e83de9bb62c3569eecca2 20-May-2015 Dan Albert <danalbert@google.com> Fix error handling for negative size in ftruncate.

Bug: 21309901
Change-Id: I54692ab8105dd09db6af7a2c0894a17bdd118aa0
truncate.cpp
40a8f214a5264efe5feaaffd55cea67fb87d097b 18-May-2015 Yabin Cui <yabinc@google.com> Hide rt_sigqueueinfo.

Bug: 19358804
Change-Id: I38a53ad64c81d0eefdd1d24599e769fd8a477a56
igqueue.cpp
11331f60dd735613eee902b43a02b646ae873032 28-Apr-2015 Jeff Brown <jeffbrown@google.com> Add float support to binary event log.

Bug: 20664753
Change-Id: I6e43c07daa727c19d87f5192bb719af63dd93654
ibc_logging.cpp
bfd65279a5a9018b01f71773270e462f1b9a7768 24-Apr-2015 Mark Salyzyn <salyzyn@google.com> bionic: add __system_property_area_serial()

Adds a new _internal_ function. Provide a global serial number to
support more efficient private caching algorithms. This allows
to skip re-running the __system_property_find() call on misses until
there is a global change in the properties. This call is a read
barrier, the property data to be read following this call will be
read sequentially and up to date.

Bug: 19544788
Change-Id: I58e6a92baa0f3e8e7b9ec79b10af6d56407dab48
ystem_properties.cpp
42502d702e1625c9f3337f7a18ea5fc4cfc6090c 25-Apr-2015 Nick Kralevich <nnk@google.com> Merge "add fortified memchr/memrchr implementations"
9a2744df301c509ea48361016ab441c792ec6d5a 25-Apr-2015 Elliott Hughes <enh@google.com> Merge "Fix POSIX timer thread naming."
d1aea30b2ade504550f7bb7996c808b9af1c415d 25-Apr-2015 Elliott Hughes <enh@google.com> Fix POSIX timer thread naming.

Spencer Low points out that we never actually set a name because the constant
part of the string was longer than the kernel's maximum, and the kernel
rejects long names rather than truncate.

Shorten the fixed part of the string while still keeping it meaningful. 9999
POSIX timers should be enough for any process...

Bug: https://code.google.com/p/android/issues/detail?id=170089
Change-Id: Ic05f07584c1eac160743519091a540ebbf8d7eb1
osix_timers.cpp
ea295f68f1fae7c701baaa717f67296659d567ac 21-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Unregister pthread_atfork handlers on dlclose()

Bug: http://b/20339788
Change-Id: I874c87faa377645fa9e0752f4fc166d81fd9ef7e
thread_atfork.cpp
6c63ee41ac5a246fb46c51753cd4d50ccae0dd8f 24-Apr-2015 Dimitry Ivanov <dimitry@google.com> Merge "Revert "Unregister pthread_atfork handlers on dlclose()""
094f58fb2a57d1ed5736ae3588bf0355618f915b 24-Apr-2015 Dimitry Ivanov <dimitry@google.com> Revert "Unregister pthread_atfork handlers on dlclose()"

The visibility control in pthread_atfork.h is incorrect.
It breaks 64bit libc.so by hiding pthread_atfork.

This reverts commit 6df122f8528f9b9fcf7dfea14ae98b0ef66274e1.

Change-Id: I21e4b344d500c6f6de0ccb7420b916c4e233dd34
thread_atfork.cpp
3da9373fe0ada19d13c6c3f9831dee93ec0ba7a6 23-Apr-2015 Elliott Hughes <enh@google.com> Merge "Simplify close(2) EINTR handling."
3391a9ff139d57fe4f8a2ff2d81a5ddc230a6208 23-Apr-2015 Elliott Hughes <enh@google.com> Simplify close(2) EINTR handling.

This doesn't affect code like Chrome that correctly ignores EINTR on
close, makes code that tries TEMP_FAILURE_RETRY work (where before it might
have closed a different fd and appeared to succeed, or had a bogus EBADF),
and makes "goto fail" code work (instead of mistakenly assuming that EINTR
means that the close failed).

Who loses? Anyone actively trying to detect that they caught a signal while
in close(2). I don't think those people exist, and I think they have better
alternatives available.

Bug: https://code.google.com/p/chromium/issues/detail?id=269623
Bug: http://b/20501816
Change-Id: I11e2f66532fe5d1b0082b2433212e24bdda8219b
lose.cpp
6df122f8528f9b9fcf7dfea14ae98b0ef66274e1 21-Nov-2014 Dmitriy Ivanov <dimitry@google.com> Unregister pthread_atfork handlers on dlclose()

Change-Id: I326fdf6bb06bed12743f08980b5c69d849c015b8
thread_atfork.cpp
72a6fdcdc71df623f8876cf0681dc9364e78b35a 18-Apr-2015 Yabin Cui <yabinc@google.com> Fix bug in app_id_from_name in stubs.cpp.

It seems that a break statement is missing.

Bug: 19872411
Change-Id: I9362783ab726d01f6eb27418563e716dd95688dc
tubs.cpp
4ae773633aac9ceba5ec62bb8e1aa22c3c56ebde 18-Apr-2015 Daniel Micay <danielmicay@gmail.com> add fortified memchr/memrchr implementations

Change-Id: I38c473cc0c608b08f971409a95eb8b853cb2ba1c
_memchr_chk.cpp
_memrchr_chk.cpp
42281880a8ac8614832ff918a14e4b950f35d05d 17-Apr-2015 Daniel Micay <danielmicay@gmail.com> add fortified readlink/readlinkat implementations

Change-Id: Ia4b1824d20cad3a072b9162047492dade8576779
_readlink_chk.cpp
_readlinkat_chk.cpp
eadlink.cpp
a9325133aad79c079bf34aafa85c0544ef940f8c 17-Apr-2015 Elliott Hughes <enh@google.com> Fix clang build.

Change-Id: I70a9ebe806cb4f7e23a7d8e486157ddd70ae3008
egacy_32_bit_support.cpp
e7e1c875b0f8eefb1d771f200a58f54e64c39d55 16-Apr-2015 Daniel Micay <danielmicay@gmail.com> add fortified implementations of pread/pread64

Change-Id: Iec39c3917e0bc94371bd81541619392f5abe29b9
_pread64_chk.cpp
_pread_chk.cpp
2587c6a2f0f946bd7c1e526c20b2623c01accd60 16-Apr-2015 Yabin Cui <yabinc@google.com> Merge "Change on handling of SIGEV_THREAD timers."
95f1ee235ae257802a94d7e94d476ea0aaea5cd8 14-Jan-2015 Yabin Cui <yabinc@google.com> Change on handling of SIGEV_THREAD timers.

1. Don't prevent calling callback when SIGEV_THREAD timers are disarmed by timer_settime.
As in POSIX standard: The effect of disarming or resetting a timer with pending
expiration notifications is unspecified. And glibc didn't prevent in this situation, so I
think it is fine to remove the support.
2. Still prevent calling callback when SIGEV_THREAD timers are deleted by timer_delete.
As in POSIX standard: The disposition of pending signals for the deleted timer is unspecified.
However, glibc handles this (although that is not perfect). And some of our tests in
time_test.cpp depend on this feature as described in b/18039727. so I retain the support.
3. Fix some flaky test in time_test.cpp, and make "time*" test pass on bionic-unit-tests-glibcxx.

Bug: 18263854

Change-Id: I8ced184eacdbfcf433fd81b0c69c38824beb8ebc
osix_timers.cpp
66aa0b61f736678e97a0cfaf975052881a23651b 15-Apr-2015 Dmitriy Ivanov <dimitry@google.com> Hide emutls* symbols in libc.so

Also make thread_local in test static to avoid ld.bfd
warning for arm64.

Change-Id: I09a3f2aa9b73a4fafa3f3bbc64ddc2a128ad50ee
_cxa_thread_atexit_impl.cpp
8f3f04184a5772b421867b59acd3d0dfbc6fa4eb 14-Apr-2015 Yabin Cui <yabinc@google.com> Merge "Prevent using static-allocated pthread keys before creation."
5ddbb3f936ee44555a46020239e49ab45109a806 06-Mar-2015 Yabin Cui <yabinc@google.com> Prevent using static-allocated pthread keys before creation.

Bug: 19993460

Change-Id: I244dea7f5df3c8384f88aa48d635348fafc9cbaf
thread_key.cpp
76615dae93c18ac890e167c547a08c0228709a33 17-Mar-2015 Yabin Cui <yabinc@google.com> Provide writer preference option in rwlock.

Previous implementation of rwlock contains four atomic variables, which
is hard to maintain and change. So I make following changes in this CL:

1. Add pending flags in rwlock.state, so we don't need to synchronize
between different atomic variables. Using compare_and_swap operations
on rwlock.state is enough for all state change.

2. Add pending_lock to protect readers/writers waiting and wake up
operations. As waiting/wakeup is not performance critical, using a
lock is easier to maintain.

3. Add writer preference option.

4. Add unit tests for rwlock.

Bug: 19109156

Change-Id: Idcaa58d695ea401d64445610b465ac5cff23ec7c
thread_rwlock.cpp
f796985923e2d8308e00ed9567f36546dafb98d7 03-Apr-2015 Yabin Cui <yabinc@google.com> Fix bug for recursive/errorcheck mutex on 32-bit devices.

Bug: 19216648
Change-Id: I3b43b2d18d25b9bde352da1e35f9568133dec7cf
thread_mutex.cpp
00d1101cc170ce786f26143a897b4a3e3363b55f 02-Apr-2015 Yabin Cui <yabinc@google.com> Merge "Refactor pthread_mutex to support 32-bit owner_tid on 64-bit devices."
e69c24543db577d8b219ab74b0ba7566e0f13b38 14-Feb-2015 Yabin Cui <yabinc@google.com> Refactor pthread_mutex to support 32-bit owner_tid on 64-bit devices.

Bug: 19216648
Change-Id: I765ecacc9036659c766f5d1f6600e1a65364199b
thread_mutex.cpp
8f41142cd631bdd8bf02dcfbb599e5edbfcbd67e 01-Apr-2015 Mark Salyzyn <salyzyn@google.com> Merge "stubs missing include for string.h"
56b276817690f09305b9657a10f4ae4e1d79a0da 01-Apr-2015 Mark Salyzyn <salyzyn@google.com> stubs missing include for string.h

stubs.cpp gets string.h inherited from private/android_filesystem_config.h
it should not rely on this in the future. The intent is to move fs_config
function into libcutils and thus deprecate any need for string.h in this
include file.

Change-Id: I946ec1979ef5bbb34fbcb4a99bf2cd79280bb2a3
tubs.cpp
6170693e28dd72a1517c267f3f62b3f37477b8bb 31-Mar-2015 Elliott Hughes <enh@google.com> Make ThreadLocalBuffer a class rather than a macro.

Bug: 19995392
Change-Id: I497c512648fbe66257da3fb3bcd5c9911f983705
ibgen.cpp
ntent.cpp
ty.cpp
trerror.cpp
trsignal.cpp
tubs.cpp
ef115003012f61cf5539fdfeb201b98e4a92f610 31-Mar-2015 Yabin Cui <yabinc@google.com> Revert "Revert "add guard pages to the internal signal stacks""

This reverts commit a3125fd1396a09a7fc4872dc4653f342150a3deb.
And Fix the prctl() problem that cause system crash.

Change-Id: Icc8d12d848cfba881a7984ca2827fd81be41f9fd
thread_create.cpp
thread_exit.cpp
thread_internal.h
a3125fd1396a09a7fc4872dc4653f342150a3deb 31-Mar-2015 Elliott Hughes <enh@google.com> Revert "add guard pages to the internal signal stacks"

This reverts commit 595752f623ae88f7e4193a6e531a0805f1c6c4dc.

Change-Id: Iefa66e9049ca0424e53cd5fc320d161b93556dcb
thread_create.cpp
thread_exit.cpp
thread_internal.h
595752f623ae88f7e4193a6e531a0805f1c6c4dc 29-Mar-2015 Daniel Micay <danielmicay@gmail.com> add guard pages to the internal signal stacks

Signal handlers tend to be lean, but can still overflow the (tiny)
stack.

Change-Id: Ia21c6453d92a9f8d1536ad01ff26a1a84c05f8fb
thread_create.cpp
thread_exit.cpp
thread_internal.h
8f3eb5a4e5dbbac1fb431e40e25eec07ecc24ee8 26-Mar-2015 Yabin Cui <yabinc@google.com> Merge "Revert "Cause Fatal error when invalid pthread_id is detected.""
220b99bdc1c5f51825ac2a87062bc05fe3e0d722 26-Mar-2015 Yabin Cui <yabinc@google.com> Revert "Cause Fatal error when invalid pthread_id is detected."

Some code like in https://buganizer.corp.google.com/u/0/issues/19942911 need to change first.

This reverts commit 03324780aae9ff28c8acf52debf0ea39120e5ab8.

Change-Id: I13ff1e5b3d0672bae9cde234ffba32fbbf33d338
thread_internal.cpp
f2d153f836e529892854b91452fabd2c2fa79c05 26-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Merge "Initial implementation of __cxa_thread_atexit_impl"
df79c330d895af31f39ee301dee62731fa586168 26-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Initial implementation of __cxa_thread_atexit_impl

This is initial implementations; does not yet handle
dlclose - undefined behavior, needs linker support to
handle it right.

Bug: 19800080
Bug: 16696563
Change-Id: I7a3e21ed7f7ec01e62ea1b7cb2ab253590ea0686
_cxa_thread_atexit_impl.cpp
thread_exit.cpp
17393b06bab9cb3e95d0f466a56c746de19b8eee 21-Mar-2015 Yabin Cui <yabinc@google.com> Hide internal of pthread_mutex_t.

Bug: 19249079
Change-Id: Iffb79c8d861b698d474f212dc80c638fc2cf1620
thread_mutex.cpp
fa3dcecc0fd7bbbf04234e41be690a5d33277870 26-Mar-2015 Yabin Cui <yabinc@google.com> Merge "Fix in error handling in pthread_create.cpp."
799cb35f45a161de96b272de38724f77e988f5f3 26-Mar-2015 Yabin Cui <yabinc@google.com> Fix in error handling in pthread_create.cpp.

It is due to a previous change "Let g_thread_list_lock only protect g_thread_list".
We need to add the newly created thread to thread_list even if
__init_thread fails, so the thread can exit successfully.

Change-Id: I0332df11acfdd181350bcc092b12d90d679057a4
thread_create.cpp
03324780aae9ff28c8acf52debf0ea39120e5ab8 25-Mar-2015 Yabin Cui <yabinc@google.com> Cause Fatal error when invalid pthread_id is detected.

This is a patch testing whether we can use abort() instead of
returning ESRCH for invalid pthread ids. It is an intermediate
step to remove g_thread_list/g_thread_list_lock.

Bug: 19636317
Change-Id: Idd8e4a346c7ce91e1be0c2ebcb78ce51c0d0a31d
thread_internal.cpp
28e69f75088684b41d30b051799d7687d33f2205 25-Mar-2015 Yabin Cui <yabinc@google.com> Add O_APPEND flag for __libc_write_stderr.

For DeathTests, we are testing the output of stderr to check if it is the
death we are expecting. To collect the output, Gtest redirects stderr to
a temporary file. But in __libc_write_stderr in libc_logging.cpp, we are
writing to stderr without a O_APPEND flag, so a new message will overwrite
a previous message.
The above situation makes almost all the DeathTests fail on host. Because
the expected message are always overwritten in host DeathTests. So I add
O_APPEND flag in __libc_write_stderr, which makes all host DeathTests pass.

Change-Id: Ic2f6044fdb181eebe132a6f170b57db43c5c3289
ibc_logging.cpp
93d44ff2a6e0febe18d42d5690e85023545318b4 24-Mar-2015 Yabin Cui <yabinc@google.com> Merge "Let g_thread_list_lock only protect g_thread_list."
673b15e4ee2c6d99b150aedddc0f389e29f98e1b 19-Mar-2015 Yabin Cui <yabinc@google.com> Let g_thread_list_lock only protect g_thread_list.

As glibc/netbsd don't protect access to thread struct members by a global
lock, we don't want to do it either. This change reduces the
responsibility of g_thread_list_lock to only protect g_thread_list.

Bug: 19636317
Change-Id: I897890710653dac165d8fa4452c7ecf74abdbf2b
ibc_init_common.cpp
thread_accessor.h
thread_create.cpp
thread_detach.cpp
thread_exit.cpp
thread_getcpuclockid.cpp
thread_getschedparam.cpp
thread_internal.cpp
thread_internal.h
thread_internals.cpp
thread_join.cpp
thread_kill.cpp
thread_setname_np.cpp
thread_setschedparam.cpp
32b039e46eee4d40b9979eab873a957e86fbf969 24-Mar-2015 Dmitriy Ivanov <dimitry@google.com> Merge "RTLD_LAZY is not supported, use RTLD_NOW instead."
f8246ac65f1985e23023df12112a6ce47057a4dd 24-Mar-2015 Yabin Cui <yabinc@google.com> Merge "Add test for pthread types alignment check."
84c10c2e7928cf2128f2495b9d5ed916088b2f2b 23-Mar-2015 Dmitriy Ivanov <dimitry@google.com> RTLD_LAZY is not supported, use RTLD_NOW instead.

Change-Id: Ia08ed6416aef686435224b50b3e58955d09f04e2
etdClient.cpp
alloc_debug_common.cpp
b58457221364eaad039c2c49a42626b725e980d5 17-Mar-2015 Yabin Cui <yabinc@google.com> Add test for pthread types alignment check.

Bug: 19249079
Change-Id: I83c4f0d11ec5d82a346ae0057d02a92bb1d519e8
thread_cond.cpp
thread_rwlock.cpp
a2db50d5d7fa67b297eddd1c0549f08ea4b6a950 20-Mar-2015 Yabin Cui <yabinc@google.com> Fix alignment error for pthread_internal_t/pthread stack.

aligned attribute can only control compiler's behavior, but we
are manually allocating pthread_internal_t. So we need to make
sure of alignment manually.

Change-Id: Iea4c46eadf10dfd15dc955c5f41cf6063cfd8536
thread_create.cpp
thread_internal.h
bbb0432a33787f1a627abb396fe343a7943ac7bc 19-Mar-2015 Yabin Cui <yabinc@google.com> Return EINVAL when calling pthread_detach for joined thread.

Change-Id: I717015132187e087e0ad485284a13c8801e25e77
thread_detach.cpp
aec2bb5ec67637ec4b5374287e9bc0d572632054 20-Mar-2015 Yabin Cui <yabinc@google.com> Fix two errors in pthread_detach.cpp.

The errors are introduced in "Make pthread join_state not protected by g_thread_list_lock".

Bug: 19636317
Change-Id: I58ae9711da94bfbac809abfd81311eeb70301a4b
thread_detach.cpp
thread_internal.h
6943f2968cb6054f8874e30b309985b41a37e2e0 19-Mar-2015 Yabin Cui <yabinc@google.com> Merge "Make __get_thread inlined."
2f836d4989845c0c82a1e4f99206fb0ff0d137a2 18-Mar-2015 Yabin Cui <yabinc@google.com> Make __get_thread inlined.

Bug: 19825434

Change-Id: Ifb672a45a5776b83625a25654ed0d6f7fc368ae3
dk_cruft.cpp
thread_internal.h
thread_internals.cpp
fa495d51b02e1575088ed358614d3baa442f455f 18-Mar-2015 Elliott Hughes <enh@google.com> Hide statfs/fstatfs' ST_VALID flag from userspace.

Spotted while debugging the strace 4.10 upgrade.

Change-Id: I1af1be9c9440151f55f74a835e1df71529b0e4fe
egacy_32_bit_support.cpp
tatvfs.cpp
ee7649c5ac5f1e56cc8193cd4cee73004c04893d 16-Mar-2015 Daniel Micay <danielmicay@gmail.com> set errno to ENOENT in getauxval per glibc 2.19

Bionic's getauxval(...) implementation returns zero when entries are
missing. Zero can be a valid value, so there is no unambiguous way of
detecting an error. Since glibc 2.19, errno is set to ENOENT when an
entry is missing to make it possible to detect this. Bionic should match
this behavior as code in the Linux ecosystem will start relying on it to
check for the presence of newly added entries.

Change-Id: Ic1efe29bc45fc87489274c96c4d2193f3a7b8854
Signed-off-by: Daniel Micay <danielmicay@gmail.com>
etauxval.cpp
ecbfb25c504b7360d250c849ab47890ad54b6125 17-Mar-2015 Yabin Cui <yabinc@google.com> Fix build: pthread_mutex/pthread_detach.

Change-Id: I9c7b6297d3bf3ab8004d05d44cc4c95159315c9e
thread_detach.cpp
thread_mutex.cpp
94babaee1b6598b15bd807461055d4dcaaa52f10 17-Mar-2015 Yabin Cui <yabinc@google.com> Merge "Make pthread join_state not protected by g_thread_list_lock."
5490bebd7cdd4406780358f590391b75ab8a7d84 17-Mar-2015 Yabin Cui <yabinc@google.com> Merge "Remove duplication in pthread_mutex.cpp."
9e6c7bc61838476d749d9bc4801777d35fd46a63 16-Mar-2015 Yabin Cui <yabinc@google.com> Fix atomic_load on const variable in pthread_cond_t.

Change-Id: I60f55a53294a09332a3fbec669ed793359d1bdf5
thread_cond.cpp
32651b8e8e453391c7aaca47cd885e94d54d0bf4 14-Mar-2015 Yabin Cui <yabinc@google.com> Hide content of pthread_cond_t in pthread_cond_internal_t.

Bug: 19249079
Change-Id: I6f55af30bcd6211ce71630c6cacbef0e1663dcee
thread_cond.cpp
2fabea47ac9475bcc52aff0715819d18aa5bdf1d 13-Mar-2015 Yabin Cui <yabinc@google.com> Hide content of pthread_rwlock_t in pthread_rwlock_internal_t.

Bug: 19249079
Change-Id: Ifbe634c716b6793bef897ec5134b55eb44c6b8d5
thread_rwlock.cpp
5b8e7cd957f9380e93c3aee84962d157fe0bc526 05-Mar-2015 Yabin Cui <yabinc@google.com> Remove duplication in pthread_mutex.cpp.

Also add unit tests about thread woken up by pthread_mutex_unlock.

Bug: 19216648

Change-Id: I8bde8105b00186c52a2f41d92458ae4a5eb90426
thread_mutex.cpp
58cf31b50699ed9f523de38c8e943f3bbd1ced9e 07-Mar-2015 Yabin Cui <yabinc@google.com> Make pthread join_state not protected by g_thread_list_lock.

1. Move the representation of thread join_state from pthread.attr.flag
to pthread.join_state. This clarifies thread state change.
2. Use atomic operations for pthread.join_state. So we don't need to
protect it by g_thread_list_lock. g_thread_list_lock will be reduced
to only protect g_thread_list or even removed in further changes.

Bug: 19636317
Change-Id: I31fb143a7c69508c7287307dd3b0776993ec0f43
thread_attr.cpp
thread_create.cpp
thread_detach.cpp
thread_exit.cpp
thread_internal.h
thread_join.cpp
9d0c79304d2413028aa5c213f7a567f00feccde5 06-Mar-2015 Yabin Cui <yabinc@google.com> Remove PTHREAD_ATTR_FLAG_MAIN_THREAD.

Make this change because I think it is more reasonable to check stack info
in pthread_getattr_np. I believe pthread_attr_t is not tied with any thread,
and can't have a flag saying who using it is the main thread.
This change also helps refactor of g_thread_list_lock.

Bug: 19636317
Change-Id: Iedbb85a391ac3e1849dd036d01445dac4bc63db9
ibc_init_common.cpp
thread_attr.cpp
thread_internal.h
f7e3b3e48ab3ffbf7bbce5102ce1739c200093cb 06-Mar-2015 Yabin Cui <yabinc@google.com> Use pthread_once for g_uselocale_key creation.

Bug: 19625804
Change-Id: I57ec4c965067dc0c157c795c1f7217a3ca403286
ocale.cpp
c3307dc43b2526c4031837738b139d22831c5d09 05-Mar-2015 Yabin Cui <yabinc@google.com> Merge "Better control of pthread keys used in bionic."
e1c0213be3f0c2c4e310cbc262da88835a2e5d86 05-Mar-2015 Yabin Cui <yabinc@google.com> Merge "Switch pthread_rwlock_t to stdatomic."
08ee8d2030fbc73c4c144e819dd68806b0351cbe 12-Feb-2015 Yabin Cui <yabinc@google.com> Switch pthread_rwlock_t to stdatomic.

Bug: 19099838
Change-Id: Ie82967a60b5cec61a8bdd1e0e4a03738d01944f8
thread_rwlock.cpp
4a2891d8c8f09a64ea9e1479518b0cc969bd5969 05-Mar-2015 Yabin Cui <yabinc@google.com> Better control of pthread keys used in bionic.

Change-Id: I1e1bc77c0e7879baead6c3417282ce549a1153b5
ocale.cpp
e1edd301d2a722e0a0687a7a3a87081c8cb956d3 04-Mar-2015 Yabin Cui <yabinc@google.com> Merge "Refactor pthread_key.cpp to be lock-free."
5e2bd719d7dd19afe55f8d4f24366c0230e0e6c7 21-Feb-2015 Yabin Cui <yabinc@google.com> Refactor pthread_key.cpp to be lock-free.

Change-Id: I20dfb9d3cdc40eed10ea12ac34f03caaa94f7a49
thread_create.cpp
thread_internal.h
thread_key.cpp
52d7f1a94fd6ccb87dabd21c682f68d31810aca9 25-Feb-2015 Yabin Cui <yabinc@google.com> Move endpwent to ndk_cruft.cpp.

Bug: 19109159
Change-Id: I3683a247643006ea6d6bcf3845f57d1908d457d7
dk_cruft.cpp
tubs.cpp
448a85968da1e4622e829bb48fd888a38f9f6c49 25-Feb-2015 Yabin Cui <yabinc@google.com> Merge "Switch system_properties.cpp from bionic atomic operations to stdatomic."
8c41eae6fcdb6cad1f6c46ae01708ead6b734060 25-Feb-2015 Yabin Cui <yabinc@google.com> Merge "Move getusershell/endusershell/setusershell to ndk_cruft.cpp."
7fb680bfda059746c9bb8939ffaed600eecc3a29 24-Feb-2015 Yabin Cui <yabinc@google.com> Move getusershell/endusershell/setusershell to ndk_cruft.cpp.

Bug: 19108648
Change-Id: I65134040345398dde612c4325d902db58f3bd2be
dk_cruft.cpp
tubs.cpp
35778253a5ed71e87a608ca590b63729d9f88567 24-Feb-2015 Nick Kralevich <nnk@google.com> Fix "faccessat ignores flags"

The kernel system call faccessat() does not have any flags arguments,
so passing flags to the kernel is currently ignored.

Fix the kernel system call so that no flags argument is passed in.

Ensure that we don't support AT_SYMLINK_NOFOLLOW. This non-POSIX
(http://pubs.opengroup.org/onlinepubs/9699919799/functions/access.html)
flag is a glibc extension, and has non-intuitive, error prone behavior.

For example, consider the following code:

symlink("foo.is.dangling", "foo");
if (faccessat(AT_FDCWD, "foo", R_OK, AT_SYMLINK_NOFOLLOW) == 0) {
int fd = openat(AT_FDCWD, "foo", O_RDONLY | O_NOFOLLOW);
}

The faccessat() call in glibc will return true, but an attempt to
open the dangling symlink will end up failing. GLIBC documents this
as returning the access mode of the symlink itself, which will
always return true for any symlink on Linux.

Some further discussions of this are at:

* http://lists.landley.net/pipermail/toybox-landley.net/2014-September/003617.html
* http://permalink.gmane.org/gmane.linux.lib.musl.general/6952

AT_SYMLINK_NOFOLLOW seems broken by design. I suspect this is why this
function was never added to POSIX. (note that "access" is pretty much
broken by design too, since it introduces a race condition between
check and action). We shouldn't support this until it's clearly
documented by POSIX or we can have it produce intuitive results.

Don't support AT_EACCESS for now. Implementing it is complicated, and
pretty much useless on Android, since we don't have setuid binaries.
See http://git.musl-libc.org/cgit/musl/commit/?id=0a05eace163cee9b08571d2ff9d90f5e82d9c228
for how an implementation might look.

Bug: 18867827
Change-Id: I25b86c5020f3152ffa3ac3047f6c4152908d0e04
accessat.cpp
b8ce47421727f7621f3e00043d535e35cd904852 11-Feb-2015 Yabin Cui <yabinc@google.com> Switch system_properties.cpp from bionic atomic operations to stdatomic.

Bug: 17177189
Change-Id: I42e05ad1c490cc7a8040138151afc0ee72a9b63f
ystem_properties.cpp
be52e658171edf6651895c40d1563289bafa52f7 24-Feb-2015 Elliott Hughes <enh@google.com> Fix dup2 in the case where the two fds are equal.

dup3's behavior differs from dup2 in this case, so we need to paper
over that in the C library.

Change-Id: I313cd6f226db5e237f61866f324c5ecdd12bf762
up2.cpp
4c5891d93dc151e2f07fc87ae967f23e6c3d6e0c 20-Feb-2015 Elliott Hughes <enh@google.com> valgrind can't find syscall because we didn't put it in <unistd.h>.

Change-Id: I1e47291d4476bd2816138a8cf58f29d4986d39e3
dk_cruft.cpp
3cfb52aab2548df635e9672218cc433e14922fd3 19-Feb-2015 Elliott Hughes <enh@google.com> Add GNU extensions mempcpy and wmemcpy.

Used by elfutils. On the bright side, they stopped using __mempcpy.

Bug: 18374026
Change-Id: Id29bbe6ef1c5ed5a171bb6c32182f129d8332abb
empcpy.cpp
mempcpy.cpp
be6a44566a7085470b96bc41d371e37b5b12ff87 17-Feb-2015 Elliott Hughes <enh@google.com> Fix sysconf for _SC_CHILD_MAX and _SC_OPEN_MAX.

Change-Id: I656f613166bd604f35b31e5ec042a5230c6b82b8
ysconf.cpp
fb48c68221afb1f9e7c63a15a20cca0857d1b9f9 17-Feb-2015 Elliott Hughes <enh@google.com> Merge "Fix memchr overflow."
41ef902379ba24bd8a3ca6d7733b8376efb55ebd 14-Feb-2015 Elliott Hughes <enh@google.com> Fix memchr overflow.

The overflow's actually in the generic C implementation of memchr.

While I'm here, let's switch our generic memrchr to the OpenBSD version too.

Bug: https://code.google.com/p/android/issues/detail?id=147048
Change-Id: I296ae06a1ee196d2c77c95a22f11ee4d658962da
emchr.c
emrchr.c
e09ab2cc2ff41ce7519c143d448371ddd62afc59 13-Feb-2015 Colin Cross <ccross@android.com> Make .note.android.ident section type SH_NOTE

The .note.android.ident section is only used by GDB, which doesn't
care what section type the section is, but it would be convenient
for readelf -n to be able to find the section too.

The old way of getting the .note.android.ident section to be of type
SH_NOTE involved compiling from .c to .s using gcc, running sed to
change progbits to note, and then compiling from .s to .o using gcc.
Since crtbrand.c only contains a section containing data, a
crtbrand.S can be checked in that will compile on all platforms,
avoiding the need for sed.

Also add crtbrand.o to crtbegin_so.o so that libraries also get
the note, and to the crt workaround in arm libc.so.

Change-Id: Ica71942a6af4553b56978ceaa288b3f4c15ebfa2
rtbrand.c
24958ae4efd70d5ef36d93d2d2bcca38ad340395 12-Feb-2015 Colin Cross <ccross@android.com> Remove no-op sed step when compiling crtbrand.o

crtbrand.c was compiled to a .s file, run through a sed script
to translate a %progbits to %note, and the compiled to .o.
However, when the sed command was copied from the original source
it was not updated to use the new name of the section (.note.ABI-tag
to .note.android.ident), so it didn't modify the file. Since the
section has been generated with type %progbits instead of %note for
two years, just delete the whole sed step.

Change-Id: Id78582e9b43b628afec4eed22a088283132f0742
rtbrand.c
e375ecaa39213ec01464dac9d0ffebaac70b4e9d 10-Feb-2015 Yabin Cui <yabinc@google.com> Merge "Switch pthread_cond_t to <stdatomic.h>."
e5f816c01780220880ee59a29f727c48b51365d3 29-Jan-2015 Yabin Cui <yabinc@google.com> Switch pthread_cond_t to <stdatomic.h>.

Bug: 17574458
Change-Id: Ic7f79861df4fe751cfa6c6b20b71123cc31e7114
thread_cond.cpp
421608550dff76d12886021250919cbebf419bd8 09-Feb-2015 Narayan Kamath <narayan@google.com> Remove stray log line.

Change-Id: Id948ae37a91dadd9d40e91de97f18774bdccfc78
_poll_chk.cpp
9dfb00c1d48545a2627c2aded62d3a79749351fb 05-Feb-2015 Elliott Hughes <enh@google.com> Merge "Use the libcxxabi __cxa_demangle."
6e54c3e519892ca13f15bdcea0d431befbadac25 05-Feb-2015 Elliott Hughes <enh@google.com> Use the libcxxabi __cxa_demangle.

Bug: 18930951
Change-Id: If2ea3633ac6dfd4ec975c0f16bdf3dd58e05c614
ebug_stacktrace.cpp
aba6f712d46577c45a89fd0626dc251885d7989d 05-Feb-2015 Elliott Hughes <enh@google.com> Apparently, logd does need the NULs.

Change-Id: I04b834e65c26c5821b952f78a0de7f92527cbdba
ibc_logging.cpp
7e1b3d3e68f7430322a88be06f6b53c358fd14bf 04-Feb-2015 Yabin Cui <yabinc@google.com> Merge "Switch sem_t from bionic atomics to stdatomic.h."
a3d97da4c5c96f2c224485928154bad111cd635f 30-Jan-2015 Yabin Cui <yabinc@google.com> Switch sem_t from bionic atomics to stdatomic.h.

Bug: 17572887
Change-Id: If66851ba9b831cdd698b9f1303289bb14448bd03
emaphore.cpp
11829be3e1a9e9e2271ba64a78c327bde6e044eb 03-Feb-2015 Yabin Cui <yabinc@google.com> Merge "Add test about pthread_mutex_t owner tid limit."
140f3678f0f21eeda5916e9b8de87b93fd660a61 03-Feb-2015 Yabin Cui <yabinc@google.com> Add test about pthread_mutex_t owner tid limit.

Bug: 19216648
Change-Id: I7b12955bdcad31c13bf8ec2740ff88ba15223ec0
thread_mutex.cpp
00490ae3f351e07ed4cc2a94b11cba6a22f37311 03-Feb-2015 Nick Kralevich <nnk@google.com> Ensure raw fchmod/fchmodat syscalls are hidden.

In https://android-review.googlesource.com/#/c/127908/5/libc/SYSCALLS.TXT@116
Elliott said:

for LP64 these will be hidden. for LP32 we were cowards and left
them all public for compatibility (though i don't think we ever
dremeled to see whether it was needed). we don't have an easy
way to recognize additions, though, so we can't prevent adding
new turds.

Add a mechanism to prevent the adding of new turds, and use that
mechanism on the fchmod/fchmodat system calls.

Bug: 19233951
Change-Id: I98f98345970b631a379f348df57858f9fc3d57c0
chmod.cpp
chmodat.cpp
d57bf449fe6c2dcf35d90d6e4098038ac8a24ecb 03-Feb-2015 Hans Boehm <hboehm@google.com> Merge "Switch pthread_mutex_t from bionic atomics to <stdatomic.h>."
86fc96f73311f43980df770f4ff8022f1e9b296a 30-Jan-2015 Yabin Cui <yabinc@google.com> Switch pthread_mutex_t from bionic atomics to <stdatomic.h>.

Bug: 17574456
Change-Id: I5ce3d3dc07e804e9ce55c42920f47531b56e04de
thread_mutex.cpp
d80ec66121b5af96c6b3d07ba34353b3d517f5b3 02-Feb-2015 Nick Kralevich <nnk@google.com> Merge "Add fchmodat(AT_SYMLINK_NOFOLLOW) and fchmod O_PATH support"
3cbc6c627fe57c9a9783c52d148078f8d52f7b96 01-Feb-2015 Nick Kralevich <nnk@google.com> Add fchmodat(AT_SYMLINK_NOFOLLOW) and fchmod O_PATH support

Many libc functions have an option to not follow symbolic
links. This is useful to avoid security sensitive code
from inadvertantly following attacker supplied symlinks
and taking inappropriate action on files it shouldn't.
For example, open() has O_NOFOLLOW, chown() has
lchown(), stat() has lstat(), etc.

There is no such equivalent function for chmod(), such as lchmod().
To address this, POSIX introduced fchmodat(AT_SYMLINK_NOFOLLOW),
which is intended to provide a way to perform a chmod operation
which doesn't follow symlinks.

Currently, the Linux kernel doesn't implement AT_SYMLINK_NOFOLLOW.
In GLIBC, attempting to use the AT_SYMLINK_NOFOLLOW flag causes
fchmodat to return ENOTSUP. Details are in "man fchmodat".

Bionic currently differs from GLIBC in that AT_SYMLINK_NOFOLLOW
is silently ignored and treated as if the flag wasn't present.

This patch provides a userspace implementation of
AT_SYMLINK_NOFOLLOW for bionic. Using open(O_PATH | O_NOFOLLOW),
we can provide a way to atomically change the permissions on
files without worrying about race conditions.

As part of this change, we add support for fchmod on O_PATH
file descriptors, because it's relatively straight forward
and could be useful in the future.

The basic idea behind this implementation comes from
https://sourceware.org/bugzilla/show_bug.cgi?id=14578 , specifically
comment #10.

Change-Id: I1eba0cdb2c509d9193ceecf28f13118188a3cfa7
chmod.cpp
chmodat.cpp
42084a265329538a9e696e41971fb5d6abe3c14f 02-Feb-2015 Elliott Hughes <enh@google.com> Small logging cleanup.

Don't send the trailing NUL bytes to the logger, call strlen if we already
know the length, or cast more specifically than we need to.

Change-Id: I68c9388a22bddea49120a1022dda8db8991360c1
ibc_logging.cpp
30fbf5f44c3d2f2f2d11f92e106294c41497af5f 02-Feb-2015 Elliott Hughes <enh@google.com> Fix clang build.

Change-Id: I863137b5d35602267b4ef3a74399cf394c9994d6
oll.cpp
4674e3899afcc6b3ac8a48cdb716695d5489d26b 02-Feb-2015 Elliott Hughes <enh@google.com> Fortify poll and ppoll.

And remove the test for FD_ZERO fortification, which never made much
sense anyway.

Change-Id: Id1009c5298d461fa4722189e8ecaf22f0c529536
_poll_chk.cpp
cb0e70389ee1c4a957a842deb601666f1930d4ee 31-Jan-2015 Elliott Hughes <enh@google.com> Include <malloc.h> for struct mallinfo.

GCC doesn't seem to care, but clang does.

Change-Id: I9884820339a9e6f142862928c357f1a538184ae0
emalloc.h
6a3ff01cd4f063556cf25706ddc9dff82c351aba 29-Jan-2015 Yabin Cui <yabinc@google.com> Rewrite __cxa_guard.cpp with <stdatomic.h>.

Bug: 19180923
Change-Id: If4912d01db43c72ef12f4b04270ddb5d76d09462
_cxa_guard.cpp
05fc1d7050d5451aea08dc5f504d2670287b2d43 29-Jan-2015 Elliott Hughes <enh@google.com> Add missing includes.

Change-Id: Ibf549266a19a67eb9158d341a69dddfb654be669
ionic_systrace.cpp
ebug_stacktrace.cpp
irent.cpp
etcwd.cpp
alloc_debug_common.cpp
alloc_debug_qemu.cpp
osix_timers.cpp
thread_create.cpp
thread_setname_np.cpp
dso.cpp
80e6d6d825df4616808b22b5639114566c27af0e 24-Jan-2015 Yabin Cui <yabinc@google.com> Switch pthread_once_t to stdatomic.h.

Bug: 17574610

Change-Id: I653f2aa4b5b38dbdaffe4a6c3deccfe6ad3b0e74
thread_once.cpp
e6099098a5fcf92c4205718ff505e784aeeaae70 27-Jan-2015 Elliott Hughes <enh@google.com> Fix mips build.

Move various mips-only things into the arch-mips directory. As soon as mips
writes assembler replacements, we can remove these.

Change-Id: Ia7308559bc361f5c8df3e1d456b381865e060b93
emcmp.c
emset.c
1edfd9e36acff1824c5e8dcfbdc0580dcc74e1bb 27-Jan-2015 Elliott Hughes <enh@google.com> x86 has an assembler bcopy implementation.

Change-Id: I4ed7af3c5b104f86550120401f773150c460f37b
dk_cruft.cpp
76f8916b904db14facf811ae44e1265261349702 26-Jan-2015 Elliott Hughes <enh@google.com> Clean up <stdlib.h> slightly.

Interestingly, this mostly involves cleaning up our implementation of
various <string.h> functions.

Change-Id: Ifaef49b5cb997134f7bc0cc31bdac844bdb9e089
rror.cpp
emcpy.cpp
emmove.c
dk_cruft.cpp
candir.cpp
yslog.cpp
b8a8cf0d1a333401eae9c9e1d70b9c1b154ff9c9 25-Jan-2015 Elliott Hughes <enh@google.com> Add <error.h>.

Bug: https://code.google.com/p/android/issues/detail?id=79170
Change-Id: Id91765fac45124545e2674a5b2c814707c1a448b
rror.cpp
6466292a7e47f3adfeb6721cf16e6b78b1c76625 24-Jan-2015 Elliott Hughes <enh@google.com> Reduce <signal.h> namespace pollution.

<signal.h> shouldn't drag in all of <string.h>.

Change-Id: I57aea36dad5e89ea2f9541c35594ca6225e532be
igemptyset.cpp
igfillset.cpp
c56af08c21fd93c50303370015071527e110e05d 22-Jan-2015 Elliott Hughes <enh@google.com> Use a more specific return type for app_id_from_name.

I suspect we can simplify this code, but I don't know enough about it
to get involved now.

Change-Id: I1c39761ae31beb70d41ffa6f0e396a4f17529d46
tubs.cpp
8b5df3920f2843c9cdf04160517c1e8b77c992f5 22-Jan-2015 Elliott Hughes <enh@google.com> Turn on -Wold-style-cast and fix the errors.

A couple of dodgy cases where we cast away const, but otherwise pretty boring.

Change-Id: Ibc39ebd525377792b5911464be842121c20f03b9
ibc_init_common.cpp
pen.cpp
thread_create.cpp
candir.cpp
igaddset.cpp
igdelset.cpp
igismember.cpp
ignal.cpp
tubs.cpp
ysinfo.cpp
destroy.cpp
dso.cpp
19e246dda6772ffc532b1762cd7870d6c3b01c12 18-Dec-2014 Yabin Cui <yabinc@google.com> Fix possible leak in pthread_detach.

If pthread_detach() is called while the thread is in pthread_exit(),
it takes the risk that no one can free the pthread_internal_t.
So I add PTHREAD_ATTR_FLAG_ZOMBIE to detect this, maybe very rare, but
both glibc and netbsd libpthread have similar function.

Change-Id: Iaa15f651903b8ca07aaa7bd4de46ff14a2f93835
thread_detach.cpp
thread_exit.cpp
thread_internal.h
917d390510e442b9b030d54992ebf41cc1e7f853 08-Jan-2015 Yabin Cui <yabinc@google.com> Make pthread stack size match real range.

Bug: 18908062
Change-Id: I7037ac8273ebe54dd19b1561c7a376819049124c
thread_create.cpp
ac8f2810297cd6c104aad38686627fcc13591347 07-Jan-2015 Elliott Hughes <enh@google.com> Merge "_Unwind_Context is a struct."
30e59c4c691d493fda7da35307db69ced61e7cf4 07-Jan-2015 Elliott Hughes <enh@google.com> _Unwind_Context is a struct.

Change-Id: Iff2c52dc630eb83b931a78fdebc4494d69462db7
ebug_stacktrace.cpp
ba8dfc2669d658dc340eb8f9c9b40ca074f05047 06-Jan-2015 Yabin Cui <yabinc@google.com> Remove PTHREAD_ATTR_FLAG_USER_ALLOCATED_STACK.

Patch for https://android-review.googlesource.com/#/c/120844/.

Change-Id: Idca5ccd7b28e8f07f1d2d1b6e3bba6781b62f0e0
ibc_init_common.cpp
thread_create.cpp
thread_exit.cpp
thread_internal.h
thread_internals.cpp
541b0b187dd91684efdcebf72c8830e976ca04a6 02-Jan-2015 Yabin Cui <yabinc@google.com> Merge "Reserve enough user request stack space in pthread_create."
6a7aaf46759db32c6ed0eb953a4a230dc96af0d9 23-Dec-2014 Yabin Cui <yabinc@google.com> Reserve enough user request stack space in pthread_create.

Bug: 18830897
Change-Id: I1ba4aaeaf66a7ff99c5d82ad45469011171b0a3b
thread_create.cpp
thread_exit.cpp
thread_internal.h
thread_internals.cpp
40360b379cee07574493f5a450cf1c6e531bdde0 29-Dec-2014 Elliott Hughes <enh@google.com> Remove bogus transitive includes.

<signal.h> shouldn't get you the contents of <errno.h>, and <fcntl.h>
shouldn't get you the contents of <unistd.h>.

Change-Id: I347499cd8671bfee98e6b8e875a97cab3a3655d3
ionic_systrace.cpp
hown.cpp
chown.cpp
oll.cpp
aise.cpp
eadlink.cpp
igaddset.cpp
igdelset.cpp
igemptyset.cpp
igfillset.cpp
igismember.cpp
ermios.cpp
times.cpp
246bcb10b64d4b02a40f5d4c744640c1fb7183e5 20-Dec-2014 Yabin Cui <yabinc@google.com> Remove t->tls==NULL check in pthread_key_delete.

Change-Id: I6c0c71d30fe9d5b888752a4204abd95d5149bb96
thread_key.cpp
8cf1b305670123aed7638d984ca39bfd22388440 04-Dec-2014 Yabin Cui <yabinc@google.com> Use mmap to create the pthread_internal_t

Add name to mmaped regions.
Add pthread benchmark code.
Allocate pthread_internal_t on regular stack.

Bug: 16847284
Change-Id: Id60835163bb0d68092241f1a118015b5a8f85069
ibc_init_common.cpp
thread_create.cpp
thread_detach.cpp
thread_exit.cpp
thread_internal.h
thread_internals.cpp
thread_join.cpp
7874f1d7182d80eb72c699eaa9ab8cc4cfec95ab 18-Dec-2014 Elliott Hughes <enh@google.com> Split the shared group data from the shared passwd data.

Found by the toybox id(1) which calls both getpwuid(3) and getgrgid(3) before
looking at either result. The use of a shared buffer in this code meant that
even on a single thread, the data for any of the passwd functions would be
clobbered by the data for any of the group functions (or vice versa).

This might seem like an insufficient fix, but POSIX explicitly says (for
getpwnam) that the result "might be overwritten by a subsequent call to
getpwent(), getpwnam(), or getpwuid()" and likewise for other members of
that group, plus equivalent text for the group-related functions.

Change-Id: I2272f47e91f72e043fdaf7c169fa9f6978ff4370
tubs.cpp
6c238f2926e69a950f0671ae5519584c20d84196 12-Dec-2014 Yabin Cui <yabinc@google.com> Fix pthread key num calculation.

Bug: 18723085
Change-Id: Iba2c834b350e4cdba0b2d771b221560a3e5df952
thread_create.cpp
a381fe8ebcd196614a00f4dca3539e0860ef9e84 10-Dec-2014 Elliott Hughes <enh@google.com> Fix ptsname(3) and ttyname(3) to use TLS.

Be safe by default.

Change-Id: I6c4a3f1fd4eee3a651b3162ce95b7e873de57521
ty.cpp
94926f8cfa0adf37c4e19256ade7261a97f72e51 09-Dec-2014 Yabin Cui <yabinc@google.com> Merge "support _POSIX_REALTIME_SIGNALS"
725756045e03ea6f7ef00d02e883ef2914d06dde 08-Dec-2014 Yabin Cui <yabinc@google.com> Change _POSIX_CPUTIME macro to make it compitable with glibc.

Change-Id: I7a8dbb74bd622693c9fef60bd779687207517b7d
ysconf.cpp
634816055f51c536d24dea30dfe930b7fe2fa603 02-Dec-2014 Yabin Cui <yabinc@google.com> support _POSIX_REALTIME_SIGNALS

Bug: 18489947
Change-Id: I2e834d68bc10ca5fc7ebde047b517a3074179475
igqueue.cpp
igtimedwait.cpp
igwaitinfo.cpp
2421406711e0b2e214234add79c842bbb2c07ca1 05-Dec-2014 Tao Bao <tbao@google.com> Merge "Add cache related sysconf queries"
1f40be97b16ff895a50f48ae8dd1745f57688b6b 05-Dec-2014 Tao Bao <tbao@google.com> Add cache related sysconf queries

Several cache related queries are added, such as
_SC_LEVEL1_DCACHE_LINESIZE, _SC_LEVEL1_DCACHE_SIZE and etc. For the
moment, we always return 0 for these queries.

Change-Id: I36f67af8128672d8c1eef49d6f2431cca5a94719
ysconf.cpp
5afae64a1bac56638c6348f0c8f5e9d61b654029 26-Nov-2014 Yabin Cui <yabinc@google.com> implement posix_madvise

Bug: 18472477
Change-Id: I8183de6c281acf69ed5f7f88351b056b9827b162
osix_madvise.cpp
65f0df78730fb0d6994f9d4d0a16dc0241081d94 03-Dec-2014 Elliott Hughes <enh@google.com> Implement <pty.h>.

Based on the package/apps/Terminal implementation. I'll switch them over
shortly. This also lets us build the toybox version of netcat.

Change-Id: Ia922a100141a67409264b43b937eeca07b21f344
ty.cpp
8574a0670bf698b8d2f817098f9d825c4be03a68 02-Dec-2014 Yabin Cui <yabinc@google.com> Use mmap to create the pthread_internal_t.

Bug: 16847284
Change-Id: I488fa236f57aa3acb29b4ffbbab2fab51b0653be
thread_create.cpp
thread_exit.cpp
thread_internal.h
thread_internals.cpp
212e0e38248860b151b28877225629a988d95b58 02-Dec-2014 Elliott Hughes <enh@google.com> Build our benchmarks against glibc too.

Bug: 18556607
Change-Id: I455ac8b93c0835836180e549486bc52d393ee6a6
thread_atfork.cpp
d5c652756bb1a52959cd5c62447b62462f90f983 26-Nov-2014 Yabin Cui <yabinc@google.com> support _POSIX_CPUTIME

Bug: 18490039
Change-Id: I01fa83b48e1b908de1f227b6e4f98e280bcd50ee
lock_getcpuclockid.cpp
5b8ceff5f87889e781c13305767e140afd28eb76 26-Nov-2014 Nicolas Geoffray <ngeoffray@google.com> Revert "Use mmap to create the pthread_internal_t."

Unfortunately, this change provokes random crashes for ART, and
I have seen libc crashes on the device that might be related to it.

Reverting it fixes the ART crashes. there is unfortunately no
stack trace for the crashes, but just a "Segmentation fault" message.


This reverts commit cc5f6543e3f91385b9a912438965b7e8265df54a.

Change-Id: I68dca8e1e9b9edcce7eb84596e8db619e40e8052
thread_create.cpp
thread_exit.cpp
thread_internal.h
thread_internals.cpp
cc5f6543e3f91385b9a912438965b7e8265df54a 25-Nov-2014 Yabin Cui <yabinc@google.com> Use mmap to create the pthread_internal_t.

Bug: 16847284
Change-Id: Ic8c85f95afac1d8422ecb69674c688d1fecb6a44
thread_create.cpp
thread_exit.cpp
thread_internal.h
thread_internals.cpp
eb3a5e026e65ea80b17580a71f4451f5cf5d6612 24-Nov-2014 Yabin Cui <yabinc@google.com> Merge "flesh out sysconf(3) and the _POSIX_* constants"
95a02366f2697ed65c4a2849a9cbde3d403142e3 23-Nov-2014 Elliott Hughes <enh@google.com> Merge "Sync with upstream OpenBSD fts.c."
2818279ace22fb854b00e668c224492c4dd072a4 22-Nov-2014 Elliott Hughes <enh@google.com> Sync with upstream OpenBSD fts.c.

Change-Id: Ia7e26b603f6461095b5a8d7e8a6cdf4f8279fa84
ts.c
1c19194c9d2518dbe86973cd313a277ecb70d75c 20-Nov-2014 Yabin Cui <yabinc@google.com> flesh out sysconf(3) and the _POSIX_* constants

Bug: 17571891
Change-Id: I81036615486bde65969ae5662587fcc88348474e
ysconf.cpp
75ef63d6cf83787233d1c45489c4ec03b0a67d16 21-Nov-2014 Dan Albert <danalbert@google.com> Move some pthread functions to signal.h.

POSIX specifies that pthread_kill(3) and pthread_sigmask(3) are
supposed to live in signal.h rather than pthread.h.

Since signal.h now needs pthread_t and pthread_attr_t, I've moved
those defintions into include/machine/pthread_types.h to keep the
namespace clean. I also sorted some includes. The combination of these
two things seems to have exploded into a cascade of missing includes,
so this patch also cleans up all those.

Change-Id: Icfa92a39432fe83f542a797e5a113289d7e4ad0c
ocale.cpp
ntent.cpp
thread_atfork.cpp
thread_internals.cpp
thread_key.cpp
aise.cpp
5313c3ff89db33dc0af3fabfe142a7219adce0aa 20-Nov-2014 Elliott Hughes <enh@google.com> Merge "Fix flockfile(3) and friends for stdin/stdout/stderr too."
c48c3e4bb3d1665f3e9fa2785daafa72dfe59399 20-Nov-2014 Elliott Hughes <enh@google.com> Fix flockfile(3) and friends for stdin/stdout/stderr too.

stdin/stdout/stderr are special; their mutexes are initialized by
__sinit. There's no unit test for this, because __sinit has already
been called by the time the first unit test runs, but you could
reproduce this failure with a trivial main() that calls flockfile
or ftrylockfile on one of the standard streams before otherwise
using stdio.

Bug: 18208568
Change-Id: I28d232cf05a9f198a2bed61854d8047b23d2091d
lockfile.cpp
a04c79b9d38cf9c8d3c79f4bbbfc45c9da9c0143 19-Nov-2014 Yabin Cui <yabinc@google.com> fix shared gid support in getpwnam/getgrnam

Bug: 18374693
Change-Id: I5353403cbbead6f6abac87bee2cf53a60dba408c
tubs.cpp
9d93986481b67a8135e57fc6400ca8c59f7375f6 15-Nov-2014 Yabin Cui <yabinc@google.com> Add functions in sysinfo.h.

Bug: 17703902

Change-Id: I699d12d76a8fc483c919be730c2ac63641b71a1d
ysconf.cpp
ysinfo.cpp
661423a453b2692d592df56307a876dfc35c50f2 15-Nov-2014 Yabin Cui <yabinc@google.com> Merge "Increase support of pathconf options."
b5e581abfe28de8ed6c8c8af1c265bb4e36f97bb 08-Nov-2014 Yabin Cui <yabinc@google.com> Increase support of pathconf options.

Bug: 18206366
Change-Id: Ie770e49f5af3631eb9fbd2cd5174edf004c81e00
athconf.cpp
60d84af1726225320b26683b726e5e735d9d76e8 15-Nov-2014 Elliott Hughes <enh@google.com> sysconf(3) returns long.

On LP32, this makes no difference. Not an ABI change.

On LP64, results are going to be in %rax or x0 whether they're 32- or 64-bit,
and the only difference is going to be whether the top bits are clobbered.

Bug: 18390956
Change-Id: I0bd4496231bdded34c1fa03e895021ac0df7f8e1
ysconf.cpp
e3c4acf1e3ef36c2ab1f48b1261dec9a1d8330a4 13-Nov-2014 Elliott Hughes <enh@google.com> Fix our <mntent.h> implementation.

Used by toybox.

Change-Id: I36a5053423e5cc54ae02a68f4fe110d75134accd
ntent.cpp
68d98d832b7935ed5be23836c481a14f00b19ef1 13-Nov-2014 Elliott Hughes <enh@google.com> Assume glibc >= 2.15.

This catches one trivial difference between us and glibc --- the error
returned by pthread_setname_np for an invalid pthread_t.

Change-Id: If4c21e22107c6488333d11184f8005f8669096c2
thread_setname_np.cpp
e5cabca516252addb5e305c8e1e0f35cafbcafbe 12-Nov-2014 Yabin Cui <yabinc@google.com> Merge "implement missing seekdir and telldir"
2f954bab2d524f6afed8a443c2a7ee32876db0fa 30-Oct-2014 Yongqin Liu <yongqin.liu@linaro.org> gethostname.c: change to report ENAMETOOLONG error when buflen is less

change to behaviour the same as glibc for the check about buflen

Change-Id: I98265a8fe441df6fed2527686f89b087364ca53d
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
ethostname.c
ethostname.cpp
5ca4a9e2da46db30ad6d8556b61679d138aaf88d 07-Nov-2014 Yabin Cui <yabinc@google.com> implement missing seekdir and telldir

Bug: 18266863
Change-Id: I189ee949d4f7ccee099f3341e349cd969d25480f
irent.cpp
b20c24456e43df430ec5626a68e5dc0dc6929344 07-Nov-2014 Elliott Hughes <enh@google.com> Implement all the POSIX _l functions.

Strictly speaking, this only implements the _l variants of the functions
we actually have. We're still missing nl_langinfo_l, for example, but we
don't have nl_langinfo either.

Change-Id: Ie711c7b04e7b9100932a13f5a5d5b28847eb4c12
ocale.cpp
trcoll_l.cpp
trftime_l.cpp
trtold_l.cpp
trtoll_l.cpp
trtoull_l.cpp
trxfrm_l.cpp
7e0d0f8572152c47a993e7bc8407690556754bd4 05-Nov-2014 Elliott Hughes <enh@google.com> Fix newlocale with a NULL locale name.

Bug: https://code.google.com/p/android/issues/detail?id=78567
Change-Id: I272dabc12ab186b44a525c7e8ac1846e62334e85
ocale.cpp
5b1111a6949b6751ce72bd0b034b7bbe6246a6b6 25-Oct-2014 Elliott Hughes <enh@google.com> POSIX says pthread_mutex_trylock returns EBUSY, not EDEADLK.

Found by unit test.

Change-Id: Iffbd2f04213616927fbd7b5419460031f7a078e9
thread_mutex.cpp
ca8e84c6ff55640aef94d25a86a25778a542bfc2 24-Oct-2014 Elliott Hughes <enh@google.com> Add mkfifoat(3).

Looks like I missed one of the *at functions when I added the rest.

Change-Id: If16de82dbf6f9a3ea7bfdcba406ca1c74a3f2279
kfifo.cpp
62d84b19359a8ddd3df5b6293d1b05ef5281f532 21-Oct-2014 Christopher Ferris <cferris@google.com> Fix race condition in timer disarm/delete.

When setting a repeat timer using the SIGEV_THREAD mechanism, it's possible
that the callback can be called after the timer is disarmed or deleted.
This happens because the kernel can generate signals that the timer thread
will continue to handle even after the timer is supposed to be off.

Add two new tests to verify that disarming/deleting doesn't continue to
call the callback.

Modify the repeat test to finish more quickly than before.

Refactor the Counter implementation a bit.

Bug: 18039727

(cherry pick from commit 0724132c3263145f2a667f453a199d313a5b3d9f)

Change-Id: I135726ea4038a47920a6c511708813b1a9996c42
osix_timers.cpp
18160256840e9bb097f17422ea47d54fabbc9f3f 12-Oct-2014 Haruki Hasegawa <h6a.h4i.0@gmail.com> Add clock_settime and clock_nanosleep.

Add the missing prototypes, fix the existing prototypes to use clockid_t
rather than int, fix clock_nanosleep's failure behavior, and add simple
tests.

Bug: 17644443
Bug: https://code.google.com/p/android/issues/detail?id=77372
Change-Id: I03fba369939403918abcabae9551a7123953d780
Signed-off-by: Haruki Hasegawa <h6a.h4i.0@gmail.com>
lock_nanosleep.cpp
9afb2f2106a5d659854c175c574c1c31e0e205a2 09-Oct-2014 Elliott Hughes <enh@google.com> Fix pthread_attr_getstack under valgrind.

valgrind seems to mess with the stack enough that the kernel will
report "[stack:pid]" rather than "[stack]" in /proc/self/maps, so
switch to the task-specific file instead to force "[stack]". (There
are two conditions in the kernel code that decides which form to
output.)

Bug: 17897476
Change-Id: Iff85ceb6d52e8716251fab4e45d95a27184c5529
thread_attr.cpp
f183f95946c699924d8ce6c0ee723bf7f4fdfe85 09-Oct-2014 Christopher Ferris <cferris@google.com> Re-add dlmalloc for 32 bit.

It turns out that appportable has a version that calls dlmalloc directly.
Re-add the dlmalloc symbol for 32 bit only as a compatibility shim that
calls malloc.

Bug: 17881362

(cherry pick commit from c9734d24d92f4737f5ab3808c77d816a1b084582)

Change-Id: Iee9a777f66a1edb407d7563a60792b767ac4f83a
lmalloc.h
dk_cruft.cpp
75129ae9f3448905bf837d774a94ff973efd812e 09-Oct-2014 Elliott Hughes <enh@google.com> Don't silently return EINVAL for a NULL sem_t*.

Bug: 17571197
Change-Id: Ied31d8de87fc10d20dc338be0457e9a4ddb9a0a5
emaphore.cpp
5a3ca374583f7605672d9e8f9098011de240f7c4 08-Oct-2014 Elliott Hughes <enh@google.com> Merge "Revert "Work around a bug in Immersion's libImmEmulatorJ.so.""
c9e4f2de0a92ebf6dec336f383ba172efe1bb366 08-Oct-2014 Dan Albert <danalbert@google.com> Merge "Inline helpers need to be exported unmangled."
658727e111ed6dee7be5239494f0764f7b1b02f8 07-Oct-2014 Dan Albert <danalbert@google.com> Inline helpers need to be exported unmangled.

__open_2() is used by the fortify implementation of open(2) in
fcntl.h, and as such needs an unmangled C name. For some reason
(inlining?), this doesn't cause problems at the default optimization
level, but does for -O0.

The rest of these didn't cause build failures, but they look suspect
and probably will, we just haven't caught them yet.

Bug: 17784968
Change-Id: I7391a7a8999ee204eaf6abd14a3d5373ea419d5b
_fgets_chk.cpp
_recvfrom_chk.cpp
3d773274ad6caaf7e0431c3d5eeb31f727b53d1a 08-Oct-2014 Elliott Hughes <enh@google.com> Revert "Work around a bug in Immersion's libImmEmulatorJ.so."

This reverts commit 7d3f553f989f830976efa92ddc3c84661d4d42aa.

Change-Id: I8909b6aa1d97e9a61dbe95a2d91b9fbe336b58f0
thread_mutex.cpp
7d3f553f989f830976efa92ddc3c84661d4d42aa 08-Oct-2014 Elliott Hughes <enh@google.com> Work around a bug in Immersion's libImmEmulatorJ.so.

This library calls pthread_mutex_lock and pthread_mutex_unlock with a NULL
pthread_mutex_t*. This gives them (and their users) one release to fix things.

Bug: 17443936
Change-Id: I3b63c9a3dd63db0833f21073e323b3236a13b47a
thread_mutex.cpp
b0fd55608e707b3e9b5c2937537414be7d098afd 07-Oct-2014 Dan Albert <danalbert@google.com> Use snprintf instead of sprintf.

At -O0, the attribute warning on sprintf is actually triggered (why
doesn't this happen with -Os?!) and promoted to an error by -Werror.
asctime64_r() is a non-standard function, but the IBM docs state that
the buffer is assumed to be at least 26 characters wide, and the
format string does limit to that (assuming a 4 digit year, also
defined by the IBM docs).

http://www-01.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxbd00/asctimer.htm

Change-Id: I1c884474a769aa16c53e985c3d8d694c478c1189
ime64.c
8d0b2dbf2154d5da17ff09b1d4f864d281362ad2 26-Sep-2014 Alex Van Brunt <avanbrunt@nvidia.com> Reimplement clock(3) using clock_gettime(3)

Unlike times(), clock_gettime() is implemented as a vDSO on many architectures.
So, using clock_gettime() will return a more accurate time and do so with less
overhead because it does have the overhead of calling into the kernel.

It is also significantly more accurate because it measures the actual time in
nanoseconds rather than the number of ticks (typically 1 millisecond or more).

Bug: 17814435
Change-Id: Id4945d9f387330518f78669809639952e9227ed9
lock.cpp
fc5a93f7a2ea2be740f2c909e8a6a192fa65adc8 24-Sep-2014 Dan Albert <danalbert@google.com> Merge "Fix incorrect parameter types for locale funcs."
31165edf5733dae8fbe79551b18cbc0e56c8d808 24-Sep-2014 Elliott Hughes <enh@google.com> CLOEXEC support in fdopen, freopen, and mkostemp/mkostemps.

Change-Id: I74ea88e0d4973d6ab3c57da7d8bb643c31592b14
fs64_support.cpp
3c5037f1b3b747e79d17a5f717d9f9c365132d33 24-Sep-2014 Dan Albert <danalbert@google.com> Fix incorrect parameter types for locale funcs.

strtoll(3), strtoull(3), wcstoll(3), and wcstoull(3) all take an _int_
as a base, not a size_t. This is an ABI compatibility issue.

Bug: 17628622
Change-Id: I17f8eead34ce2112005899fc30162067573023ec
trtoll_l.cpp
trtoull_l.cpp
char.cpp
0dc39f9952c5e3a3121ea77357bb264ef0f8ded7 23-Sep-2014 Elliott Hughes <enh@google.com> Fix a couple more cases of missing CLOEXEC.

The debuggerd case can probably never happen, because you're crashing at this
point anyway. The system property one seems possible though.

Change-Id: Idba6a4f1d68587ec5b320d1e25f0b6a987ea32a0
ystem_properties.cpp
a186b2e0ca19620a52b4a49c17835532d13eb30a 22-Sep-2014 Elliott Hughes <enh@google.com> Clean up fpathconf(3)/pathconf(3).

fpathconf(3) and pathconf(3) can share code. There's no such
header file as <pathconf.h>. glibc/POSIX and BSD disagree about where
the _POSIX_* definitions should go.

Change-Id: I4a67f1595c9f5fbb26700a131178eedebd6bf712
athconf.c
athconf.cpp
ysconf.cpp
413de5b0d4ddcf039aaef8b40a5f02d41dbb06e6 20-Sep-2014 Elliott Hughes <enh@google.com> Merge "Add semaphore tests, fix sem_destroy."
04303f5a8ab9a992f3671d46b6ee2171582cbd61 19-Sep-2014 Elliott Hughes <enh@google.com> Add semaphore tests, fix sem_destroy.

Bug: https://code.google.com/p/android/issues/detail?id=76088
Change-Id: I4a0561b23e90312384d40a1c804ca64ee98f4066
ionic_time_conversions.cpp
thread_cond.cpp
thread_internal.h
thread_internals.cpp
thread_mutex.cpp
thread_rwlock.cpp
emaphore.c
emaphore.cpp
ysconf.cpp
6fe376d3925a788f60fd44280b00008af60b9334 19-Sep-2014 Christopher Ferris <cferris@google.com> Remove references to MALLOC_LEAK_CHECK.

This define isn't really used any more.

Bug: 17378595
Change-Id: I39722b83cd98955a3a2514577de34a239524617f
alloc_debug_common.cpp
alloc_debug_leak.cpp
1cff9a89645a8f362a9ce19c7f9544e98c1fd9e7 17-Sep-2014 Elliott Hughes <enh@google.com> Use the kernel's sa_restorer for aarch64.

gdb was happy with what we had, but libgcc and libunwind weren't.
libgcc is happy with the kernel's restorer (because of the extra nop),
though libunwind looks like it's going to need code changes regardless.

We could make our restorer more like the kernel's one, but why bother
when we can just let the kernel supply the canonical one?

Bug: 17436734
Change-Id: I330fa5e68f23b1cf8133aa552896657b0b873ed3
igaction.cpp
36f451a6d93b6807944d99fa23396e039c47e845 11-Sep-2014 Elliott Hughes <enh@google.com> Fix signal trampolines.

* LP32 should use sa_restorer too. gdb expects this, and future (>= 3.15) x86
kernels will apparently stop supporting the case where SA_RESTORER isn't
set.

* gdb and libunwind care about the exact instruction sequences, so we need to
modify the code slightly in a few cases to match what they're looking for.

* gdb also cares about the exact function names (for some architectures),
so we need to use __restore and __restore_rt rather than __sigreturn and
__rt_sigreturn.

* It's possible that we don't have a VDSO; dl_iterate_phdr shouldn't assume
that getauxval(AT_SYSINFO_EHDR) will return a non-null pointer.

This fixes unwinding through a signal handler in gdb for all architectures.
It doesn't fix libunwind for arm and arm64. I'll keep investigating that...

Bug: 17436734
Change-Id: Ic1ea1184db6655c5d96180dc07bcc09628e647cb
l_iterate_phdr_static.cpp
igaction.cpp
5681fe8eaea08a9c95b48291bb94a21ab0f7e24a 13-Sep-2014 Elliott Hughes <enh@google.com> Remove an unused file.

Also remove a reference to it and two other files that have already
been removed in a script --- these files were problematic because they
weren't UTF-8.

Change-Id: Ibf597bac1903c34d8d0fe0a09615c42f24d4f23d
ash.h
f83c208b82c78dad07f4065f63bdd354f5ef9951 13-Sep-2014 Elliott Hughes <enh@google.com> Explain why clock(3) isn't broken.

Bug: 17441123
Change-Id: I6ee9b7f54bab55b1a8760ce9bcaaa6eab1dcc492
lock.cpp
0f001b67fea27f8d60afc4677e8970d32a4e3792 12-Sep-2014 Elliott Hughes <enh@google.com> Remove "private/bionic_pthread.h".

Bug: 17476168
Change-Id: Id642987e641de81e914a28daea4ffe9d11e090ed
dk_cruft.cpp
thread_gettid_np.cpp
a4831cb4a3f44b93788488db8ff9ea76613f0355 12-Sep-2014 Elliott Hughes <enh@google.com> Add pthread_gettid_np and re-expose __get_thread for LP32.

A lot of third-party code calls the private __get_thread symbol,
often as part of a backport of bionic's pthread_rwlock implementation.
Hopefully this will go away for LP64 (since you're guaranteed the
real implementation there), but there are still APIs that take a tid
and no way to convert between a pthread_t and a tid. pthread_gettid_np
is a public API for that. To aid the transition, make __get_thread
available again for LP32.

(cherry-pick of 27efc48814b8153c55cbcd0af5d9add824816e69.)

Bug: 14079438
Change-Id: I43fabc7f1918250d31d4665ffa4ca352d0dbeac1
osix_timers.cpp
thread_gettid_np.cpp
thread_internal.h
thread_internals.cpp
b587f339db269abf08a2c311a7263dd218cb23d3 11-Sep-2014 Elliott Hughes <enh@google.com> Add posix_fadvise(3).

(cherry-pick of 00008263782e484020420c606f7d145fe7d0a4d8.)

Bug: 12449798
Change-Id: I07cbf3f670a0d1304b68148325a774f266b5c433
osix_fadvise.cpp
011e111d299284b65af07add523a9dccac356244 09-Sep-2014 Elliott Hughes <enh@google.com> Ensure __set_errno is still visible on LP32.

The use of the .hidden directive to avoid going via the PLT for
__set_errno had the side-effect of actually making __set_errno
hidden (which is odd because assembler directives don't usually
affect symbols defined in a different file --- you can't even
create a weak reference to a symbol that's defined in a different
file).

This change switches the system call stubs over to a new always-hidden
__set_errno_internal and has a visible __set_errno on LP32 just for
binary compatibility with old NDK apps.

(cherry-pick of 7efad83d430f4d824f2aaa75edea5106f6ff8aae.)

Bug: 17423135
Change-Id: I6b6d7a05dda85f923d22e5ffd169a91e23499b7b
_set_errno.cpp
cf5fc80c3eb710cb5a1985837156cb2758c87a5b 06-Sep-2014 Elliott Hughes <enh@google.com> Don't expose non-standard basename_r and dirname_r in LP64.

(cherry-pick of f0e9458ea596227720fa745df15f5357f6c0c8f6.)

Bug: 17407423
Change-Id: I47fe499a4c396bf09d7b78fd828728d04777398b
ibgen.cpp
fc829736e1f399a2b82058b24bb94f6bdab22469 08-Sep-2014 Elliott Hughes <enh@google.com> Add arc4random_addrandom binary compatibility.

This was in <stdlib.h> in older releases. It's no longer used, but we can
preserve backwards compatibility by making it a no-op.

(cherry-pick of 51c8355d5cf4b83ccd2ad250ca4c61a616356c2b.)

Bug: 16205834
Change-Id: Idde7b46df4f253e39675600bcf82352879a716e7
dk_cruft.cpp
f90355844663b85dd57c3adcd9e92c2ee6850412 06-Sep-2014 Christopher Ferris <cferris@google.com> Add dlmalloc_usable_size for 32 bit arches.

Bug: 17337831

(cherry picked from commit 1c365cb494d8cab1b639ecef21514425647e606b)

Change-Id: Ice100e42eeac4b9c3b77737a546ec33174adcb2f
lmalloc.h
dk_cruft.cpp
44352f5f7f06ff9383d695b0a7d4243f5268f430 04-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Merge "Revert "Register __libc_fini as early as possible.""
4b41555ba5439025cee9cf3f9ff45db43b1865da 04-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Revert "Register __libc_fini as early as possible."

This reverts commit e880c736d6c1d947f6309d5f1f63c74e8345c6a6.

Change-Id: Ide83e442eb5dbfef5298a15bc602c3fe1dda1862
ibc_init_common.h
ibc_init_dynamic.cpp
ibc_init_static.cpp
afe58ad9892de27a7acb0aaded6312ee0f958314 04-Sep-2014 Elliott Hughes <enh@google.com> Don't mask out SA_RESTORER from sa_flags.

glibc doesn't do this, and we probably shouldn't either.

Bug: 16703540
Change-Id: Id5b93c3782e34024a9916463348e8f3caff191bf
igaction.cpp
5dea47221a116aa87b0c286230c944ed6b629636 04-Sep-2014 Elliott Hughes <enh@google.com> Add back a dummy arc4random_stir for compatibility.

The current arc4random implementation stirs itself as needed, but we
need to keep an arc4random_stir symbol around for binary compatibility.

(cherry-pick of 1e010d60397db706cd3d1c4d5701a2bced441aa8.)

Bug: 17291075
Change-Id: Iaf6171c3ec65c39c1868364d5b35ea280e29a363
dk_cruft.cpp
e880c736d6c1d947f6309d5f1f63c74e8345c6a6 03-Sep-2014 Dmitriy Ivanov <dimitry@google.com> Register __libc_fini as early as possible.

We want __libc_fini to be called after all the destructors.

Bug: 14611536
Change-Id: Ibb83a94436795ec178fd605fa531ac29608f4a3e
ibc_init_common.h
ibc_init_dynamic.cpp
ibc_init_static.cpp
416d7ddaff0946d480b6aa945a741b3eeaca5569 19-Aug-2014 Elliott Hughes <enh@google.com> Add GNU-compatible strerror_r.

We already had the POSIX strerror_r, but some third-party code defines
_GNU_SOURCE and expects to get the GNU strerror_r instead.

This exposed a bug in the libc internal logging functions where unlike
their standard brethren they wouldn't return the number of bytes they'd
have liked to have written.

Bug: 16243479
Change-Id: I1745752ccbdc569646d34f5071f6df2be066d5f4
ibc_logging.cpp
trerror_r.cpp
9e4ffa7032eaab308876b8e3da86b05c3c613878 28-Aug-2014 Elliott Hughes <enh@google.com> Have pthread_attr_getstack for the main thread report RLIMIT_STACK...

...rather than just what's already mapped in. This seems somewhat
contrary to POSIX's "All pages within the stack described by stackaddr
and stacksize shall be both readable and writable by the thread", but
it's what glibc does.

Bug: 17111575
Change-Id: If9e2dfad9a603c0d0615a8123aacda4946e95b2c
thread_attr.cpp
cc7e5f489f02ceee46e315af4f78559d3ad6c962 27-Aug-2014 Elliott Hughes <enh@google.com> Switch to OpenBSD <err.h> implementation.

Change-Id: Ia950d88871a30f68e74f9ac7dbd87788e128e02f
rr.c
07401c7136af113304a22f4a8245ef3fc1b6929b 27-Aug-2014 Elliott Hughes <enh@google.com> Merge "Switch to OpenBSD daemon(3)."
e5055179fd92ae243741d778426e1da03539165f 27-Aug-2014 Elliott Hughes <enh@google.com> Switch to OpenBSD daemon(3).

Change-Id: I1fd0be09fdb24aa6f1d945410eba5987f8a949b4
aemon.c
f73183f1a34df22b62a3d0bbf82e18d5797c9cde 27-Aug-2014 Elliott Hughes <enh@google.com> More cases where libc should use O_CLOEXEC.

Change-Id: Idfa111aeebc5deca2399dae919e8b72eb54c23c0
ionic_systrace.cpp
irent.cpp
alloc_debug_qemu.cpp
thread_setname_np.cpp
ystem_properties.cpp
c674edbf27450bbb2396b1434421b1db5325d8f4 27-Aug-2014 Elliott Hughes <enh@google.com> libc should use O_CLOEXEC when opening files for its own use.

Change-Id: I159f1d57e0ca090d837f57854fcef5879b8b8248
ebug_mapinfo.cpp
ututline.c
ysconf.cpp
c764fb24ccb47e05d8e140cde5b4111225790ef1 26-Aug-2014 Elliott Hughes <enh@google.com> Merge "Fix pthread_getattr_np for the main thread."
57b7a6110e7e8b446fc23cce4765ff625ee0a105 26-Aug-2014 Elliott Hughes <enh@google.com> Fix pthread_getattr_np for the main thread.

On most architectures the kernel subtracts a random offset to the stack
pointer in create_elf_tables by calling arch_align_stack before writing
the auxval table and so on. On all but x86 this doesn't cause a problem
because the random offset is less than a page, but on x86 it's up to two
pages. This means that our old technique of rounding the stack pointer
doesn't work. (Our old implementation of that technique was wrong too.)

It's also incorrect to assume that the main thread's stack base and size
are constant. Likewise to assume that the main thread has a guard page.
The main thread is not like other threads.

This patch switches to reading /proc/self/maps (and checking RLIMIT_STACK)
whenever we're asked.

Bug: 17111575
Signed-off-by: Fengwei Yin <fengwei.yin@intel.com>
Change-Id: I1d4dbffe7bc7bda1d353c3a295dbf68d29f63158
ibc_init_common.cpp
thread_attr.cpp
ae558d6b4bcee740f7e61434982eb5f2c999fb97 25-Aug-2014 Chih-Hung Hsieh <chh@google.com> Add standard throw() spec to delete operators.

Without these specs, clang will reports mismatch between standard definitions and these declarations/definitions. These specs are ignored when compiled with -fno-exceptions.

BUG: 17136236
Change-Id: I386c712a61dc4fc74dfde45f9ec2d3d037f2e9f1
ew.cpp
ef619cc083fc3aa4f58dd101b25cc97ad1d37570 22-Aug-2014 Dan Albert <danalbert@google.com> Fix dlmalloc build.

Change-Id: Ied542c40867ab443cdd2076bd2e535b00c4854e4
lmalloc.c
4caa1f09770ea3e5ca22afbe8aa0900810a0dbfe 20-Aug-2014 Dan Albert <danalbert@google.com> Implement malloc_info(3).

Expose jemalloc stats through the malloc_info(3) interface.

Bug: 16874689
Change-Id: I4358ac283002e60ff161107028d1a3fb1e9afb0a
lmalloc.c
alloc_info.cpp
alloc_info.h
b61c50647b85b3c33af8ca155e88ec098d9e8cb0 20-Aug-2014 Hans Boehm <hboehm@google.com> Merge "Work around atomic_load(const T*) issues."
1e8587a479fd8b1ce9b594298a93f517816e8f15 19-Aug-2014 Hans Boehm <hboehm@google.com> Work around atomic_load(const T*) issues.

Bug:17067219
Change-Id: I78e753bcf03464f5f05c3f37e394f2727d282589
ystem_properties.cpp
09c39d6df0e952620f8c1751377b559a04e023aa 19-Aug-2014 Elliott Hughes <enh@google.com> Implement the GNU basename(3) in addition to the POSIX one.

Code like perf(1) needs this.

Bug: 11860789
Change-Id: I907eb448052a7b165e4012d74303330d32328cb2
_gnu_basename.cpp
934c8015d515f96c1f97255b48357da922cf626a 19-Aug-2014 Dan Albert <danalbert@google.com> Merge "Expose android_set_abort_message()."
ce6b1abbb1da797e716d8ec03da4e3b6304fd11d 18-Aug-2014 Dan Albert <danalbert@google.com> Expose android_set_abort_message().

Removes the leading underscores from __android_set_abort_message() and
moves its declaration into a public header file.

Bug: 17059126
Change-Id: I470c79db47ec783ea7a54b800f8b78ecbe7479ab
ibc_logging.cpp
6d40d34908137c8d45e9bc303b4317b8303961ee 16-Aug-2014 Christopher Ferris <cferris@google.com> Fix leak_realloc, copy entire allocation.

Bug: 16874447

(cherry picked from commit 5df0839cea98bd8c37d8dba5b94b98e99c681a94)

Change-Id: I9280505c0c1c3b5da24ba590448dcd6e7a230406
alloc_debug_leak.cpp
5d9e145c62cc6f6b39409032af529a60cb7bf479 14-Aug-2014 Christopher Ferris <cferris@google.com> malloc_usable_size returns the original size.

Bug: 16874447

(cherry picked from commit 59c1ee44d0a560a754513fab12641c8a57a20d9e)

Change-Id: I70839632974367c8b9893fb1f9c5ee4364608470
alloc_debug_leak.cpp
5f5cc45cf0e027f6ca503dc229a4890fc7164b66 19-Aug-2014 Elliott Hughes <enh@google.com> Fix <features.h> (_BSD_SOURCE and _GNU_SOURCE).

<features.h> is supposed to take user-settable stuff like _GNU_SOURCE
and _BSD_SOURCE and turn them into __USE_GNU and __USE_BSD for use in
the C library headers. Instead, bionic used to unconditionally define
_BSD_SOURCE and _GNU_SOURCE, and then test _GNU_SOURCE in the header
files (which makes no sense whatsoever).

Bug: 14659579
Change-Id: Ice4cf21a364ea2e559071dc8329e995277d5b987
lone.cpp
0d4ccee35101c6bcd6cc28c23fe79d7b48a98dd0 14-Aug-2014 Dan Albert <danalbert@google.com> Merge "Change name of MB_CUR_MAX implementation function."
224ff048efc782bd60047a3ae53eb66941f73125 14-Aug-2014 Dan Albert <danalbert@google.com> Change name of MB_CUR_MAX implementation function.

Glibc calls theirs __ctype_get_mb_cur_max. Make ours match to cut down
on differences between bionic and glibc.

Bug: 11156955
Change-Id: Ib7231f01aa9676dff30aea0af25d597bfe07bc73
ocale.cpp
b3aaf398e1d6af5362e0f30f11ab7c11890644c2 13-Aug-2014 Dan Albert <danalbert@google.com> Hide __libc_init_vdso().

Bug: 11156955
Change-Id: I7ee31e1ee2ce479c5746b374a239637d582815fe
ibc_init_common.cpp
4f85c6ffd31d1f8cc000ab326edd8edb7ecd55a9 14-Aug-2014 Hans Boehm <hboehm@google.com> Merge "Add memory ordering constraint, convert to C11 atomics"
edd81faff0b61fc458dc27b9c91f358d3313ce7a 13-Aug-2014 Dan Albert <danalbert@google.com> Hide __libc_malloc_dispatch.

Now that -Bsymbolic is fixed, we can hide __libc_malloc_dispatch without
breaking ASAN.

Bug: 11156955
Change-Id: Ia2fc9b046a74e666b33aa6c6c5435f70a63b8021
alloc_debug_common.cpp
51a22a12ab370933a35463f5c81223132ec64dcb 09-Aug-2014 Dmitriy Ivanov <dimitry@google.com> Label pages mapped by linker_allocator

Change-Id: I7e0bf29bc1a480e9be0d1ae573ca1063d90d82ff
lmalloc.c
30214b901e8dbec9ec11230187a8e71fc8a04014 01-Aug-2014 Hans Boehm <hboehm@google.com> Add memory ordering constraint, convert to C11 atomics

Add an ordering constraint/fence to __system_property_serial.
This slows down a read on a Nexus 5 from about 50 to about 70 ns,
but avoids the possibility of seeing an inconsistent property value.
Use C11 atomic operations where easy and appropriate.
This code remains not fully C++11 memory model conformant, but
I would now expect the generated code to now be correct with current compilers.

Bug:14970171
Change-Id: I0891ff1d0f914ae5c3857e3d76b6a7c8a4a07d83
ystem_properties.cpp
88a1f520d2d54d362dc2f29a0fad2cf0029c8918 08-Aug-2014 Christopher Ferris <cferris@google.com> Add a way to disable backtracing in malloc debug.

The property libc.debug.malloc.nobacktrace set to non-zero disables
getting backtracing when using mode 1 or mode 10.

Bug: 16874447

(cherry picked from 49de01a5be7bfb07baaea7415647d838383e1b59)

Change-Id: I6bbefe5420b14991fe84c2f849222dcd7cb592bf
alloc_debug_backtrace.h
alloc_debug_check.cpp
alloc_debug_leak.cpp
e380960813bbb6e05d820eb75885556a1c4bf6ac 06-Aug-2014 Christopher Ferris <cferris@google.com> Do a second key cleanup in pthread_exit.

During pthread_exit, the keys are cleaned. Unfortunately, a call to
free occurs after the cleanup and the memory for some of the keys
is recreated when using jemalloc. The solution is to do the key
cleanup twice.

Also, modify the pthread_detach__leak test to be less flaky
when run on a jemalloc system.

Bug: 16513133

(cherry picked from commit 18d93f2793fad393b6aa6eae6afe1054958339d5)

Change-Id: Idb32e7f9b09e2c088d256ed9eb881df80c81ff8e
thread_exit.cpp
8b91980e4c139558f9cca4e9a0980dad07c06e68 06-Aug-2014 Elliott Hughes <enh@google.com> Merge "Explain how wcswcs ended up in ndk_cruft.cpp."
1628eb1d43008c52b00ec98d10c4fd9e8b6fc7c5 06-Aug-2014 Elliott Hughes <enh@google.com> Explain how wcswcs ended up in ndk_cruft.cpp.

Change-Id: Ie45148095b2d5c3896c0df623d5d06a700c33c70
dk_cruft.cpp
6a918870bab1a55a5f57dd7954abd9a8a27c1bc2 05-Aug-2014 Dan Albert <danalbert@google.com> Revert "Replaces vfork() implementation with fork()"

We're getting cold feet on this one... let's put it back.

This reverts commit 210331d9762037afb9b5ed8413079c6f65872df9.

Change-Id: I6b0d3c2b1dbf7f1dc9566979a91b7504c2189269
fork.cpp
b6cc8e00cd562bd0f81fe44a6bc646540a862f32 31-Jul-2014 Dan Albert <danalbert@google.com> Fix mbsrtowcs(3) src param for finished string.

A mistake I made while cleaning this up the first time through.
mbstrtowcs(3) sets the src param to null if it finishes the string.

Change-Id: I6263646e25d9537043b7025fd1dd6ae195f365e2
char.cpp
1aec7c1a35b2d03038b194967d5ebdc8e2c24b80 30-Jul-2014 Dan Albert <danalbert@google.com> Proper MB_CUR_MAX.

Previously this was hard coded to 4. This is only the case for UTF-8
locales.

As a side effect, this properly reports C.UTF-8 as the default locale
instead of C.

Change-Id: I7c73cc8fe6ffac61d211cd5f75287e36de06f4fc
ocale.cpp
861c0ef37bcfcae56d88572cb01c18bcfe1faded 25-Jul-2014 Christopher Ferris <cferris@google.com> Use libunwindbacktrace for debug malloc code.

Create a method of disabling the debug allocation code paths so that
it's possible to use the libunwindbacktrace library without any
modifications.

Use this path to create and destroy the maps for the process. It's not
stricly necessary in the init code since the symbols are not modified
until after the initialize calls.

Also, remove the debug_XXX source files that doesn't need to be in libc.so.

Fix the maps reading code since it was completely broken for 64 bit.

Bug: 16408686

Change-Id: I6b02ef6ce26fdb7a59ad1029e7cbba9accceb704
ebug_mapinfo.cpp
ebug_mapinfo.h
ebug_stacktrace.cpp
alloc_debug_check.cpp
alloc_debug_disable.h
alloc_debug_leak.cpp
a7dc7600fe1be1f3fd61856b407bb7065307e711 29-Jul-2014 Elliott Hughes <enh@google.com> Merge "Fix linkage of grantpt(3)."
4916706cfe590eb06c9b5bd4bd402ce056034d51 26-Jul-2014 Elliott Hughes <enh@google.com> Fix linkage of grantpt(3).

Also clean up the implementation of all the pty functions, add tests,
and fix the stub implementations of ttyname(3) and ttyname_r(3).

Bug: https://code.google.com/p/android/issues/detail?id=58888
Change-Id: I0fb36438cd1abf8d4e87c29415f03db9ba13c3c2
etpt.c
tsname.c
tsname_r.c
ty.cpp
tubs.cpp
nlockpt.c
a406ee6d5f616192e9a13afad6ac6a9969814fc1 22-Jul-2014 Brigid Smith <brigidsmith@google.com> Added a bionic systrace class and tracing to pthread_mutex.cpp.

bionic_systrace.h contains an implementation of tracing that
can be used with systrace.py and its associated viewer. pthread_mutex
now uses this tracing to track pthread_mutex contention, which can be
enabled by using the "bionic" command line option to systrace.

Bug: 15116468
Change-Id: I30ed5b377c91ca4c36568a0e647ddf95d4e4a61a
ionic_systrace.cpp
thread_mutex.cpp
1abb8bd21d64c2bd21258469b688483f821974d5 25-Jul-2014 Dan Albert <danalbert@google.com> en_US.UTF-8 is also supported.

Change-Id: Ic35fad3596dc5e24ee8ae35543a274a471f27bb2
ocale.cpp
40a521744825b6060960c296d5fb3da4c6593d94 30-Jul-2014 Elliott Hughes <enh@google.com> Only wipe TLS for user-supplied stacks.

Bug: 16667988
Change-Id: Id180ab2bc6713e1612386120a306db5bbf1d6046
thread_create.cpp
thread_exit.cpp
thread_internal.h
d6f614a4e16b0fcf4a4fba748bf21fc0017d3619 25-Jul-2014 Elliott Hughes <enh@google.com> Merge "Implement twalk(3), add unit tests."
3e424d0a241f8ae5194514dabc4ad899f5a5416d 24-Jul-2014 Elliott Hughes <enh@google.com> Implement twalk(3), add unit tests.

I've also added insque(3) and remque(3) (from NetBSD because the OpenBSD
ones are currently broken for non-circular lists).

I've not added the three hash table functions that should be in this header
because they operate on a single global hash table and thus aren't likely
to be useful.

Bug: https://code.google.com/p/android/issues/detail?id=73719
Change-Id: I97397a7b921e2e860fd9c8032cafd9097380498a
destroy.cpp
f1e83cc34a58761fc7bc5178c6f283db85d6057a 26-Jul-2014 Elliott Hughes <enh@google.com> Use vsnprintf(3) in syslog(3).

It seemed like a clever trick to use the internal log message formatting
code in syslog(3), but on reflection that means you can't (for example)
format floating point numbers. This patch switches us over to using good
old vsnprintf(3), even though that requires us to jump through a few hoops.

There's no obvious way to unit test this, so I wrote a little program and
ran that.

(cherry-pick of b1b60c30bf321c0fc02264b953b5c16c49d34457.)

Bug: 14292866
Change-Id: I9c83500ba9cbb209b6f496067a91bf69434eeef5
ibc_logging.cpp
yslog.cpp
afe6360627ef3f0e9bc8f45535fbfae3354f3ae0 23-Jul-2014 Elliott Hughes <enh@google.com> Fix belated review comments on syslog change.

Bug: 14292866
Change-Id: I3cd92084cb55b5673f6ba62d51952941b79deb51
ibc_logging.cpp
yslog.cpp
4d421901e587fd1563da94baf59b015017c01b91 22-Jul-2014 Elliott Hughes <enh@google.com> Merge "Use upstream OpenBSD's arc4random."
2b67d7dee09852789d9ac7d8972ed6cdb2c18430 19-Jul-2014 Elliott Hughes <enh@google.com> Use upstream OpenBSD's arc4random.

The getentropy_linux.c is lightly modified to build on Android, but we're now
completely in sync with upstream OpenBSD's arc4random implementation.

Change-Id: If32229fc28aba908035fb38703190d41ddcabc95
rc4random.c
etentropy_linux.c
3ad8ecb64e9dd5614169232b84a93eb3b8aa32d7 22-Jul-2014 Elliott Hughes <enh@google.com> Rewrite syslog(3) to use Android logging.

Since we don't have syslogd on Android and you can't run one on a non-rooted
device, it's more useful if syslog output just goes to the regular Android
logging system.

Bug: 14292866
Change-Id: Icee7f088b97f88ccbdaf471b98cbac7f19f9210a
ibc_logging.cpp
yslog.cpp
1fb90a8aa0086f7e4f7960a5b916b8605a9a3c96 21-Jul-2014 Dan Albert <danalbert@google.com> Merge "Fix mbsrtowcs(3)'s handling of len parameter."
6b55ba54eff4657cffe053b71e1c9cce2944a8a9 20-Jul-2014 Dan Albert <danalbert@google.com> Fix mbsrtowcs(3)'s handling of len parameter.

The len parameter is a _maximum_ length. The previous code was treating
it as an exact length, causing the following typical call to fail:

mbsrtowcs(out, &in, sizeof(out), state); // sizeof(out) > strlen(in)

Change-Id: I48e474fd54ea5f122bc168a4d74bfe08704f28cc
char.cpp
97e31dedf056b07bcfcd46c49b60bf0798c60843 20-Jul-2014 Dan Albert <danalbert@google.com> __libc_fatal should print a newline to stderr.

Change-Id: I088dc880d7488a65beac8cda95f530f3db41f112
ibc_logging.cpp
6425327c3278137d153b8a7505f97d2f5f058d49 18-Jul-2014 Christopher Ferris <cferris@google.com> Use the mmap/munmap for allocation routines.

To avoid any issues calling malloc related routines, use mmap/munmap.
Specifically, this avoids any problems when this is compiled into a
malloc debug shared library.

Change-Id: Iae2d197145da43dc103ad6024357d8cc2374378f
ebug_mapinfo.cpp
2f9c6e38b8f59ea6e53e95e062e04dc987ac67f3 18-Jul-2014 Elliott Hughes <enh@google.com> Fix private/bionic_name_mem.h build breakage.

Change-Id: I8fe9c63dbbb5911721ca56791c0bff4bdf403314
lmalloc.c
d7453860a6b06e7d4a960c20792ce6f0b6cc5f3a 17-Jul-2014 Elliott Hughes <enh@google.com> Remove non-standard prctl constants from <sys/prctl.h>.

Also remove __bionic_name_mem which has exactly one caller, and is only
ever expected to be used in this one place.

Change-Id: I833744f91e887639f5b2d1269f966ee9032af207
_bionic_name_mem.cpp
lmalloc.c
98b088dce70a2625d5cfa1872e427af5f06bfd99 17-Jul-2014 Elliott Hughes <enh@google.com> ptrace(3) should be varargs.

Bug: 16352070
Change-Id: Ied72e6e79eaf912fc93fc49ae7637af321a31a59
trace.cpp
625993dfbb085a3cde7492eda8ec1cdc1ee39a78 16-Jul-2014 Elliott Hughes <enh@google.com> Use VDSO for clock_gettime(2) and gettimeofday(2).

Bug: 15387103
Change-Id: Ifc3608ea65060c1dc38120b10b6e79874f182a36
l_iterate_phdr_static.cpp
ibc_init_common.cpp
dso.cpp
e612add0516b1b6dd83f3ea1a1446cd6b8c2f7e5 15-Jul-2014 Dan Albert <danalbert@google.com> Remove isascii_l(3).

Had intended to remove this one before submitting the locale changes,
but forgot. It isn't a standard ctype function, so we don't need it.

Change-Id: Ie9c09fa6c61b1101b5992fa06da30e373a0c6bf7
type.cpp
673bff01aed0c08991b98841ed0bfad78a589672 14-Jul-2014 Elliott Hughes <enh@google.com> Merge "Implement rand/srand in terms of random/srandom."
76c241b091b4d9d9a9237d40e814e52ce2917f47 14-Jul-2014 Elliott Hughes <enh@google.com> Implement rand/srand in terms of random/srandom.

Code developed for glibc or older versions of bionic might expect more
randomness than the BSD implementation provides.

Bug: 15829381
Change-Id: Ia5a908a816e0a5f0639f514107a6384a51ec157e
and.cpp
53c3c271dc9927dd280981fc23409af60f460007 11-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Upstream atexit

Change-Id: Ia454a2181b5058ed9783dc02b6b1805d0e4d2715
bort.cpp
ibc_init_common.cpp
ibc_init_dynamic.cpp
ibc_init_static.cpp
dfb5ce42bcc5a275af49211c0bbe64c5ec3d2668 10-Jul-2014 Dan Albert <danalbert@google.com> Revert "Revert "Add locale aware APIs.""

This reverts commit 063e20c26943ec82ef1d53a544545e79054e93d3.

Change-Id: Ib8c9004efefe75a5346b3af50dfe37952d91eb21
type.cpp
trcoll_l.cpp
trftime_l.cpp
trtold_l.cpp
trtoll_l.cpp
trtoull_l.cpp
trxfrm_l.cpp
char.cpp
ctype.cpp
91570ce987ef93f9ba2fa663a5fee1bd2525a2ba 10-Jul-2014 Elliott Hughes <enh@google.com> Slim down static binaries by avoiding stdio.

It's okay for a program to choose to drag in stdio, but it's unfortunate
if even the minimal "int main() { return 42; }" drags in stdio...

This brings the minimal static binary on ARM down from 78KiB to 46KiB.

Given that we don't have a separate -lpthread it's not obvious to me that
we can shave this down any further. I'm not sure whether this is a worthwhile
change for that reason. (And the fact that dynamic binaries, the usual case,
are unaffected either way.)

Change-Id: I02f91dcff37d14354314a30b72fed2563f431c88
lmalloc.h
emalloc_wrapper.cpp
alloc_debug_check.cpp
alloc_debug_leak.cpp
alloc_debug_qemu.cpp
trerror_r.cpp
tubs.cpp
e959a3b3157e38ebda4ce6f86efb5644faa4988b 10-Jul-2014 Elliott Hughes <enh@google.com> Remove the global lock around thread stack creation.

This lock has been here since the original commits, but as far as I can tell
it never served any purpose. We've never had a free list of cached stacks or
anything like that.

Change-Id: I9d665c7eaa9c699ce0659ffb111402a0239fe1f5
thread_create.cpp
cd23370ca737dffc49166f8aacd19a025e72266f 10-Jul-2014 Elliott Hughes <enh@google.com> Merge "Remove the obsolete _thread_created_hook."
e0f25dda3f38a70e5689e785597c5cf2b68bdcf8 10-Jul-2014 Elliott Hughes <enh@google.com> Remove the obsolete _thread_created_hook.

gdb won't even try to use this on Android because it knows we don't
support old enough kernels to need it.

Bug: 15470251
Change-Id: Ia6d54585d888bbab8ee0490a148a1586b25437b9
thread_create.cpp
f8408c58fa61540d8b6b5afec4246284482d89c2 10-Jul-2014 Calin Juravle <calin@google.com> Move __cmsg_nxthdr to its proper file.

Change-Id: I095fb6bc5318f2d256baa97658bdfe679d235aec
_cmsg_nxthdr.cpp
msg_nxthdr.cpp
e95d0fc34cc3f6ef658c6470ffe4b59fbbc978b5 07-Jul-2014 Calin Juravle <calin@google.com> Removed obsolete symbol cmsg_nxthdr.

Bug: 15822452
Change-Id: I5322fb29522fc58e9c3489ff86216e25a12ef970
msg_nxthdr.cpp
dda1c6c466c4f31de31d76c8be7e46c16b4b4209 10-Jul-2014 Christopher Ferris <cferris@google.com> Do not include libc_common in malloc debug code.

The inclusion of the static libc_common library in the malloc_debug_XXX.so
shared libraries causes constructors to be called twice. This doesn't seem
to have caused any issues when setting the libc.debug.malloc property.
However, jemalloc crashes because there are two jemalloc implementations,
one in the static libc_common library and one in the shared library. Each
implementation has created overlapping thread keys that are not the same.
The crash comes because one of the jemalloc keys is actually used by the
locale setting code. Thus if someone sets the locale, the jemalloc code
crashes trying to access the same key.

Change-Id: Iaac650a82d69064db148a6333e9403744f68b4a4
alloc_debug_check.cpp
alloc_debug_common.cpp
alloc_debug_common.h
alloc_debug_leak.cpp
alloc_debug_qemu.cpp
063e20c26943ec82ef1d53a544545e79054e93d3 10-Jul-2014 Dan Albert <danalbert@google.com> Revert "Add locale aware APIs."

Accidentally verified against a dirty tree. Needs the companion change to libc++ to land upstream before I can submit this.

This reverts commit e087eac404b0e30de427392065e2750acf92bd4a.

Change-Id: I317ecd0923114f415eaad7603002f77feffb5e3f
type.cpp
trcoll_l.cpp
trftime_l.cpp
trtold_l.cpp
trtoll_l.cpp
trtoull_l.cpp
trxfrm_l.cpp
char.cpp
ctype.cpp
e087eac404b0e30de427392065e2750acf92bd4a 09-Jul-2014 Dan Albert <danalbert@google.com> Add locale aware APIs.

Since we only support the C locale, we can just forward all of these to
their non-locale equivalents for correct behavior.

Change-Id: Ib7be71b7f636309c0cc3be1096a4c1f693f04fbb
type.cpp
trcoll_l.cpp
trftime_l.cpp
trtold_l.cpp
trtoll_l.cpp
trtoull_l.cpp
trxfrm_l.cpp
char.cpp
ctype.cpp
2b2916d15458671babed9e250b4d98f1980a976d 07-Jul-2014 Elliott Hughes <enh@google.com> Merge "Remove some dead data."
920d831ba15a4d9707e70e834df1be12613413c3 07-Jul-2014 Elliott Hughes <enh@google.com> Remove some dead data.

Clang doesn't like dead data, and this is just an LP32 compatibility turd.

Change-Id: I3832748a4e773b254877f4438b5340e7d4c1ce70
ime64.c
6917e6c2aed624aea146c68c35c6148c136e3dcc 03-Jul-2014 Elliott Hughes <enh@google.com> Fix recv.cpp so it can build with clang.

Change-Id: Iac3e676aa256837333240219bcadbdc31985b5dd
ecv.cpp
4d763df3243f81041269015d0ac3fbd2912d5f3d 07-Jul-2014 Elliott Hughes <enh@google.com> Merge "Fix a broken boolean test found by clang."
29edbfd64ff636b40309d350ca038a7fdb114ad8 07-Jul-2014 Elliott Hughes <enh@google.com> Fix a broken boolean test found by clang.

This was only on the failure case, so this probably never caused
any real trouble.

Change-Id: Id983689772102cbb9171693b927e544fb0b584fb
alloc_debug_common.cpp
1ee1bfdeeca74d71f3e7de7ac3a7e45c9a7d0f53 07-Jul-2014 Elliott Hughes <enh@google.com> Merge "Use __unused rather than self assignment for unused parameters."
668da74ef1d4558f699374cb28a9df1a011db122 07-Jul-2014 Elliott Hughes <enh@google.com> Use __unused rather than self assignment for unused parameters.

Clang, reasonably enough, doesn't like self assignment.

Change-Id: Ie5843287802949dad148a1a815231035678e1306
emaphore.c
bae5b1dbd8dfe7318e208be917f4c9b9e8abced6 03-Jul-2014 Nick Kralevich <nnk@google.com> libc_logging: Set SOCK_CLOEXEC on socket

Socket file descriptors remain open across exec unless
SOCK_CLOEXEC is set. Enable this option, to avoid leaking
file descriptors.

In practice, this isn't a big deal, since the socket only remains
open for a very short period to write a message. However, this
socket might leak for for multithreaded programs if an exec occurs
between the open and close.

Change-Id: Ica2e71fe28657c32d56de1431c8f7f1f5c7b7c58
ibc_logging.cpp
e9975987900e5713c5b8b13e1817a243e92f79d9 02-Jul-2014 Elliott Hughes <enh@google.com> Merge "Quiten warnings in semaphore.c."
95d3cd0b85724d3702cfb71942f9aa0a5ee27c74 02-Jul-2014 Elliott Hughes <enh@google.com> Quiten warnings in semaphore.c.

Change-Id: I30aff82174f789ab407d2282c07e6207123d4d5b
emaphore.c
ec67cded1d2969b5ba21028f0dd1560827947f3d 02-Jul-2014 Elliott Hughes <enh@google.com> Quiten warnings in fts.c.

Also bring us closer to upstream. Sadly the Linux and BSD dirent
structs don't match, so we'll never be completely in sync (and I don't
think we can hide the difference with macro trickery).

Change-Id: Ief4275856116cd1d5b5e0f9166db1ead9439515c
ts.c
12bf3bcdeeaa0dcdc7a4f4e4d11bc2fc3bf6bd7a 01-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Write message to stderr on __libc_fatal()

Change-Id: Ia8d6e256768fa51786d0139d3f3b6e9e4bebe027
ibc_logging.cpp
49eb7613068297a1f2181ad39a24f27cd87d89b1 01-Jul-2014 Elliott Hughes <enh@google.com> Fix a warning in if_indextoname.c.

Change-Id: Ib6afe2a5452022f5c98ec28fd110d6b910dccdad
f_indextoname.c
066eb0b06d51e7ccbaea92e11de9c747314b03d6 01-Jul-2014 Elliott Hughes <enh@google.com> Silence time64.c build warnings.

Change-Id: Ibc5672480ee5e72eedf2bc29e420315b5346b0df
ime64.c
52f9b051c8bcb3d723b023a74d7d89ee45cf754c 24-Jun-2014 Elliott Hughes <enh@google.com> Merge "Sync to current upstream arc4random."
0468feb28696751efcddada8de69a622afffdba8 21-Jun-2014 Elliott Hughes <enh@google.com> Sync to current upstream arc4random.

This is actually revision 1.33, which is no longer the latest, but it's
as close to head as we can currently reasonably get. I've also switched
to the OpenBSD getentropy_linux.c implementation of getentropy, lightly
modified to try to report an error on failure.

Bug: 14499627
Change-Id: Ia7c561184b1f366c9bf66f248aa60f0d53535fcb
rc4random.c
hread_atexit.cpp
hread_private.cpp
598f4b3ac1be3c6ef3af613ac4b0694841e165fe 24-Jun-2014 Elliott Hughes <enh@google.com> Merge "Fix getpid caching across a clone."
096b4eb752aa7a5392875cb2f2faf0d67c676ac1 19-Jun-2014 Calin Juravle <calin@google.com> Prefix cmsg_nxthdr with "__".

This brings us on par with glibc.

To avoid breaking clients, temporary keep cmsg_nxthdr until the next NDK
refresh.

Bug: 15822452
Change-Id: I24c24e68c31f4f2b8f3d2df7acd575cb75174173
msg_nxthdr.cpp
fa9e16efaf0e885f6044e725eb759ef6de10f7ef 24-Jun-2014 Elliott Hughes <enh@google.com> Fix getpid caching across a clone.

If you make clone, fork, or vfork system calls directly, you're still
on your own, but we now do the right thing for the clone wrapper.
With this implementation, children lose the getpid caching, but we've
no reason to think that that covers any significant use cases.

Bug: 15387103
Change-Id: Icfab6b63c708fea830960742ec92aeba8ce7680d
lone.cpp
7086ad6919feb2415c6027163f5c63323bcca27c 20-Jun-2014 Elliott Hughes <enh@google.com> Cache getpid.

In practice, with this implementation we never need to make a system call.
We get the main thread's tid (which is the same as our pid) back from
the set_tid_address system call we have to make during initialization.
A new pthread will have the same pid as its parent, and a fork child's
main (and only) thread will have a pid equal to its tid, which we get for
free from the kernel before clone returns.

The only time we'd actually have to make a getpid system call now is if
we take a signal during fork and the signal handler calls getpid. (That,
or we call getpid in the dynamic linker while it's still dealing with its
own relocations and hasn't even set up the main thread yet.)

Bug: 15387103
Change-Id: I6d4718ed0a5c912fc75b5f738c49a023dbed5189
ork.cpp
etpid.cpp
ibc_init_common.cpp
thread_create.cpp
thread_internal.h
03eebcb6e8762e668a0d3af6bb303cccb88c5b81 13-Jun-2014 Christopher Ferris <cferris@google.com> Move common macros into bionic_macros.h.

Bug: 15590152
Change-Id: I730636613ef3653f68c5ab1d43b53beaf8e0dc25
emalloc_wrapper.cpp
alloc_debug_check.cpp
alloc_debug_leak.cpp
alloc_debug_qemu.cpp
thread_create.cpp
ystem_properties.cpp
b656410a73c4dfa2a3f8deba0a673080320f8605 17-Jun-2014 Christopher Ferris <cferris@google.com> Merge "Use a separate config.h for config like defines."
636196438180fd37027bf7b7119a436169b6923e 17-Jun-2014 Christopher Ferris <cferris@google.com> Use a separate config.h for config like defines.

This allows an easier way to share config parameters between unit tests
and the bionic code.

It also fixes a problem where the 32 bit bionic tests based on glibc, or
the cts list executable did not have the pvalloc,valloc tests.

Change-Id: Ib47942cb8a278252faa7498a6ef23e9578db544f
alloc_debug_common.h
3a37576d4b9714989b0618f6d1a2d2b2df77ed2b 17-Jun-2014 Christopher Ferris <cferris@google.com> Move jemalloc due to whole_static_library bug.

Rename jemalloc.cpp to jemalloc_wrapper.cpp to avoid problems with
the libc library having two jemalloc.o files that clobber each other.

Change-Id: I9a2d966dbf414b1367ee0ef1f0d73fca6f25b518
emalloc.cpp
emalloc_wrapper.cpp
891dedb935b50f1abb39eedfe33049a1e49283cb 13-Jun-2014 David 'Digit' Turner <digit@google.com> libc: Fix 'index' symbol export.

The C library didn't export the 'index' symbol, but its C++ name-mangling
instead, which broke the ABI and prevented some applications from loading
properly.

The main reason was that the implementation under bionic/index.cpp relied
on the declaration to specify that the function has C linkage.

However, the declaration for index() was removed from both <string.h>
and <strings.h> in a recent patch, which made the compiler think it was
ok to compile the function with C++ linkage instead!

This patch does the following:

- Move index() definition to bionic/ndk_cruft.cpp and ensure it uses
C linkage.

Note that this removes index() from the 64-bit library entirely, this
is intentional and will break source compatibility. Simply replacing
an index() call with the equivalent strchr() should be enough to fix
this in third-party code.

- Remove bionic/index.cpp from the tree and build files.

- Remove x86 assembly implementation from arch-x86/ to avoid conflict
with the one in ndk_cruft.cpp

BUG=15606653

Change-Id: I816b589f69c8f8a6511f6be6195d20cf1c4e8123
ndex.cpp
dk_cruft.cpp
ac6467587e864d199377f14281da4641f979a68a 05-Jun-2014 Dan Albert <danalbert@google.com> Revert "Revert "Remove ftime from bionic LP64""

This reverts commit 0921204660b9597de795065d0350a787035ad589.

Change-Id: I749af8d7d429cda9f9d09a75bd30df54e6b1dd65
time.c
dk_cruft.cpp
462abab12b074c62c0999859e65d5a32ebb41951 14-Jun-2014 Dan Albert <danalbert@google.com> Removes getdtablesize(3) from LP64.

getdtablesize(3) was removed fro POSIX 2004. Keep the symbol around in LP32 for
binary compatibility, but remove the declaration from unistd.h.

Bug: 13935372
Change-Id: I1f96cd290bf9176f922dad58bd5a7ab2cae7ef0f
etdtablesize.c
dk_cruft.cpp
72dc1c22dc6a92dea925398c9e3880364ab29c1c 14-Jun-2014 Dan Albert <danalbert@google.com> Merge "Revert "Backing this one out since the counterpart needs to be sent upstream.""
e5fdaa4f9d102461a4d8a865e6ca84666893b9e7 14-Jun-2014 Dan Albert <danalbert@google.com> Revert "Backing this one out since the counterpart needs to be sent upstream."

This reverts commit a04d2bc28e7d7fcaf34ad71e4a6608a13cf84197.

Change-Id: I1b49165ca5d4bafdba7948818256a6167a363aca
alloc_debug_common.cpp
alloc_debug_common.h
a04d2bc28e7d7fcaf34ad71e4a6608a13cf84197 14-Jun-2014 Dan Albert <danalbert@google.com> Backing this one out since the counterpart needs to be sent upstream.

This reverts commit 5ee320dd35fafc11eaf90c62198e08c6670e35b4.

Change-Id: I1a9c6b06c3aca595f01c629f7649be743dc48e77
alloc_debug_common.cpp
alloc_debug_common.h
5ee320dd35fafc11eaf90c62198e08c6670e35b4 12-Jun-2014 Dan Albert <danalbert@google.com> Hides valloc(3)/pvalloc(3) on LP64.

These were removed from POSIX 2004. Hides the header declarations for all
targets, and hides the symbols for LP64.

Bug: 13935372
Change-Id: Id592f67e9b7051517a05f536e1373b30162e669c
alloc_debug_common.cpp
alloc_debug_common.h
b84783ecaa71f9450152f8d9b5f97e1b07f05ef6 14-Jun-2014 Dan Albert <danalbert@google.com> Merge "Backing this one out since the counterpart needs to be sent upstream."
65b1c90a32036cbb06ff610fbae545b65ae8b72d 14-Jun-2014 Dan Albert <danalbert@google.com> Merge "Hides valloc(3)/pvalloc(3) on LP64."
2ba734d8cd370d9cdb544f4d3afecc9a13e35116 13-Jun-2014 Christopher Ferris <cferris@google.com> Merge "Fix %u format that should have been %zu."
580b6e09febc967b5039ef5d148be883089d0eff 13-Jun-2014 Christopher Ferris <cferris@google.com> Fix %u format that should have been %zu.

Change-Id: Icedacf6783d6b0cf4783c838b3c4622d2e67f073
alloc_debug_qemu.cpp
a403780538ac9d1a260e064df6599663f8cc4166 10-Jun-2014 Christopher Ferris <cferris@google.com> Put all allocation functions into dispatch table.

Implement these new functions for all of the debug malloc types.

Fix a number of bugs in the debug malloc functions related to overflow
conditions.
Fix a bug in dlpvalloc due to an overflow condition.

Fix various other bugs in the debug malloc functions.

Add new tests for malloc functions.

Bug: 11225066

Change-Id: Idf50f389603e2157645565bc15cd9365eec2e9dd
alloc_debug_check.cpp
alloc_debug_common.cpp
alloc_debug_common.h
alloc_debug_leak.cpp
alloc_debug_qemu.cpp
8229ae46f4fb165a18da4dca1be74c4c099c3ee7 14-Jun-2014 Dan Albert <danalbert@google.com> Removes wait3(2) from LP64.

wait3(2) was removed from POSIX 2004. Keep the symbol around in LP32 for binary
compatibility, but remove the declaration in sys/wait.h.

Bug: 13935372
Change-Id: Ic715fce6781aae43b4ac6d745dc6d1e6b9914e71
dk_cruft.cpp
ait.cpp
5d25d5480ab1e02d8f1e39f5936a3180e84a842c 13-Jun-2014 Elliott Hughes <enh@google.com> Merge "Remove __memcmp16 from bionic."
24614b4729a4c8665193f5793b93019b37f779b1 13-Jun-2014 Elliott Hughes <enh@google.com> Remove __memcmp16 from bionic.

Change-Id: I2486d667d96c8900dd368d855f37c1327161efb7
_memcmp16.cpp
29ddd78c21b15117bc7d4fc196f3a503f3aab3e2 13-Jun-2014 Christopher Ferris <cferris@google.com> Merge "Put all allocation functions into dispatch table."
80664231b8a17fc6a1bf2f4881c9353a47b74ab6 11-Jun-2014 Elliott Hughes <enh@google.com> Merge "Revert "Temporarily expose dlmalloc_usable_size.""
440bd6bcc308f78b32fcbc4a3ba312dd1343559b 11-Jun-2014 Dan Albert <danalbert@google.com> Merge "Replaces vfork() implementation with fork()"
210331d9762037afb9b5ed8413079c6f65872df9 06-Jun-2014 Dan Albert <danalbert@google.com> Replaces vfork() implementation with fork()

vfork() was removed from POSIX 2008, so this replaces its implementation
with a call to fork().

Bug: 13935372
Change-Id: I6d99ac9e52a2efc5ee9bda1cab908774b830cedc
fork.cpp
87d4233c7224201b1199179b11c5c5f854ab36a3 10-Jun-2014 Elliott Hughes <enh@google.com> Merge "Remove the MD5 implementation that was only used by toolbox."
67401638a92abd52e5896183e851b1b097da07ac 10-Jun-2014 Elliott Hughes <enh@google.com> Remove the MD5 implementation that was only used by toolbox.

I've already moved toolbox over to openssl.

Change-Id: Ia75fba5b5e3335a975b97787f653bf4df78e1b4e
d5.c
d5.h
bffbfeed7a595dcbe5843a77d84c409a0225b4e1 07-Jun-2014 Elliott Hughes <enh@google.com> Add the missing issetugid binary compatibility stub.

Bug: 14569474
Change-Id: I3bedc1a0acf356af76424ceaf62ae7e85239f617
dk_cruft.cpp
47ba295b0679148970bbffc9b76a3651efea9502 07-Jun-2014 Elliott Hughes <enh@google.com> Rewrite and hide longjmperror.

This shouldn't be public API, isn't supported on x86/x86_64, and it's
unlikely anyone would have actually seen the message before anyway.
Using __libc_fatal makes it much more likely to be seen.

Bug: 11156955
Change-Id: Icf7f654b22a7dacd89668b60c11e5705c7215c08
ssert.cpp
6fa47ca484aa37b0a2a5734a9def32973d110cc6 07-Jun-2014 Elliott Hughes <enh@google.com> Merge "Fix ndk_cruft.cpp __getdents64 build failure."
1c60f8080acaf0f1794689886e94e54d15d43a7b 07-Jun-2014 Elliott Hughes <enh@google.com> Merge "Rename __bionic_clone_entry to __start_thread."
d1ead2af8bf2f6bb801da272e3778f89efefe613 07-Jun-2014 Elliott Hughes <enh@google.com> Fix ndk_cruft.cpp __getdents64 build failure.

Change-Id: Ia463113da0575b36b5a9935d8d45e7bd2c801357
irent.cpp
dk_cruft.cpp
ebc8cd117a562f387c52ed4e1aeba0fb21f33194 07-Jun-2014 Elliott Hughes <enh@google.com> Rename __bionic_clone_entry to __start_thread.

This seems a bit less obscure.

Change-Id: I7dc528c253b73c861694f67556ad8f919bf92136
lone.cpp
3d5cb30d23cfc6a72f01c00246e69a2c614c8228 06-Jun-2014 Elliott Hughes <enh@google.com> Remove getdents from bionic.

Bug: 11156955
Change-Id: I6c306989801be552d85fba8a50dcdc79282fb9d2
irent.cpp
dk_cruft.cpp
205dd7d9b3ba314ef8601e4613823c2d62a0605b 04-Jun-2014 Dan Albert <danalbert@google.com> Remove bsd_signal and sysv_signal from bionic LP64.

bsd_signal was removed in POSIX 2008, sysv_signal was never POSIX.

Bug: 13935372
Change-Id: I7688e5cc317247ff075dcf99b598f515fb4f15c4
dk_cruft.cpp
ignal.cpp
1f29665f1507f866da4fc4c0ee094c22d6181966 05-Jun-2014 Elliott Hughes <enh@google.com> Hide __libc_fini.

Bug: 11156955
Change-Id: Id5af3540c6ec4d9ef969d62a230144fe8bb76b0b
ibc_init_common.h
67c437b2315a0b01ca4031192879f8eba966b1a7 05-Jun-2014 Elliott Hughes <enh@google.com> Revert "Temporarily expose dlmalloc_usable_size."

This reverts commit 6403cc48707b67b3400bdaf720f3e4777a1b48de.

Change-Id: Id1ce4088be1e6c83271c6317eb3e5f7fc11c7b95
lmalloc.h
6403cc48707b67b3400bdaf720f3e4777a1b48de 05-Jun-2014 Elliott Hughes <enh@google.com> Temporarily expose dlmalloc_usable_size.

Bug: 15425694
Change-Id: I47e1ca598817359260c372fec8072e76886054f0
lmalloc.h
14442bb22955f704091f23e670ed9f8bdcda1ce9 05-Jun-2014 Elliott Hughes <enh@google.com> Temporary fix for asan_malloc_linux.cc build failure.

Bug: 15432753
Change-Id: I02a3a2c826e6d01e6809c51588a9670dcd179123
alloc_debug_common.cpp
38732aa9ea28b54d55c46b6b1f9367cb8fa147f1 04-Jun-2014 Elliott Hughes <enh@google.com> Merge "Fix debug malloc."
8e52e8fe83632c667521c1c8e4f640e94c09baed 04-Jun-2014 Elliott Hughes <enh@google.com> Fix debug malloc.

Previously the dynamically-loaded part of the debug malloc implementation
wanted to access hidden symbols in libc itself.

Bug: 15426546
Change-Id: I6a366ef626854d1af1d705ca24842817b1c02a19
alloc_debug_check.cpp
alloc_debug_common.cpp
alloc_debug_common.h
alloc_debug_leak.cpp
alloc_debug_qemu.cpp
001f8f041bf21c53d4a0b919ef2c859b047bac0a 04-Jun-2014 Dan Albert <danalbert@google.com> Removes wcswcs from bionic for LP64.

Bug: 13935372
Change-Id: I0deb15e769da4fa81bb65a87f3c86db5163a5796
dk_cruft.cpp
452e09130010b641904e7411e0c539590a654022 04-Jun-2014 Dan Albert <danalbert@google.com> Merge "Adds functionality specified by uchar.h"
7a7f9952c12b216fbf91fc4cdbb97045e8861115 02-Jun-2014 Dan Albert <danalbert@google.com> Adds functionality specified by uchar.h

mbrtoc32 and c32rtomb get their implementations from mbrtowc and wcrtomb. The
wc functions now simply call the c32 functions.

Bug: 14646575
Change-Id: I49d4b95fed0f9d790260c996c4d0f8bfd1686324
16rtomb.cpp
32rtomb.cpp
brtoc16.cpp
brtoc32.cpp
bstate.cpp
char.cpp
38ed337c1343af1aa55487777ed80de6b0d33638 04-Jun-2014 Elliott Hughes <enh@google.com> Merge "Hide dlmalloc symbols."
9b5235d74e794d29fa912fe95ca3d5ec488dd371 04-Jun-2014 Elliott Hughes <enh@google.com> Hide dlmalloc symbols.

We need to leave dlmalloc_trim and dlmalloc_inspect_all exposed for
the VM, but if we're seriously looking at other malloc implementations,
that's something we're going to have to fix.

Bug: 11156955
Change-Id: If85156c280044f1616c09a3c50ba674aaf0e8d3a
lmalloc.c
lmalloc.h
c380189410b66dcaca5936b2fabceab4c492dd53 04-Jun-2014 Dan Albert <danalbert@google.com> Merge "Removes bcopy and bzero from bionic."
ce9ce28e5d760e32ab6c894dfaf7b8dad6de7ff6 03-Jun-2014 Dan Albert <danalbert@google.com> Removes bcopy and bzero from bionic.

These symbols are still defined for LP32 for binary compatibility, but
the declarations have been replaced with the POSIX recommended #defines.

Bug: 13935372
Change-Id: Ief7e6ca012db374588ba5839f11e8f3a13a20467
emmove.c
d286796fce1e6fff407b719a53eb2afbeb96c327 04-Jun-2014 Elliott Hughes <enh@google.com> Turn on -Wunused and fix the mistakes it uncovers.

Change-Id: I023d2d8b547fbc21d4124bb7510d42b06a0dc501
ibc_init_dynamic.cpp
ibc_init_static.cpp
2f9400b679ffe08f7190781e64edda5edf0f7297 03-Jun-2014 Dan Albert <danalbert@google.com> Merge "Use __libc_fatal() for failed malloc in new"
989725940e765f0065b2bc06b881cde864b62595 31-May-2014 Dan Albert <danalbert@google.com> Use __libc_fatal() for failed malloc in new

This way we can print a useful message to the log isntead of just dying
mysteriously.

Change-Id: Ib660c2fd8ce8bb9aa0d0bb634ae08c645d3901e5
ew.cpp
5d9a7ba0dc9c24ed4e4efa9cac0e796fd524b308 31-May-2014 Elliott Hughes <enh@google.com> Avoid a system call in 'gettid'.

System calls can be pretty slow. This is mako, which has one of our
lowest latencies:

iterations ns/op
BM_unistd_getpid 10000000 209
BM_unistd_gettid 200000000 8

Bug: 15297299 (kernel panic from too many gettid calls)
Bug: 15315766 (excessive gettid overhead in liblogd)
Change-Id: I49656c0fc5b5d092390264a59e4f2c0d8a8b1aeb
ettid.cpp
6203e7b853a587fbd70cea2e58b63ae38a71a13e 30-May-2014 Elliott Hughes <enh@google.com> Add some missing __noreturn attributes.

This is more honest, and lets us remove a hack.

Change-Id: I309f064743ded5248573ccafc379f78d417db08d
lone.cpp
thread_exit.cpp
b4e099c6f741835b11ecb6f8fd0861b1892ff182 30-May-2014 Elliott Hughes <enh@google.com> Remove issetugid.

Bug: 14569474
Change-Id: I752c77ed53c724f144f0b618443eb95e87f2929a
ssetugid.c
1a57de713adfb81842cb2ebdfc051ecb9afa55f1 29-May-2014 Christopher Ferris <cferris@google.com> Merge "Fix overflow testing in sbrk."
738b0cc5e95a9a650e9621603f4dd8dd16b07568 22-May-2014 Christopher Ferris <cferris@google.com> Fix overflow testing in sbrk.

Modify the overflow testing for sbrk.

Bug: 15188366

Change-Id: Ia83f85f7c1789454d872279bd41f38f1ce6b8a34
rk.cpp
624996026b844ff2eba2283f4dc83ec363d85a11 29-May-2014 Elliott Hughes <enh@google.com> Minor style cleanup of some code I had to look at.

(It turns out that this is the only place we're saying __inline in C++.)

Change-Id: I8095e67a385087817c47caab9a621f82f8e0cfc8
thread_mutex.cpp
fae42a837ae7f880de9561c7b3c2b18e4a531e90 29-May-2014 Elliott Hughes <enh@google.com> Merge "Revert "Revert "Lose the hand-written futex assembler."""
b30aff405a220495941f1673b0a5e66c4fa8b84c 28-May-2014 Elliott Hughes <enh@google.com> Revert "Revert "Lose the hand-written futex assembler.""

The problem with the original patch was that using syscall(3) means that
errno can be set, but pthread_create(3) was abusing the TLS errno slot as
a pthread_mutex_t for the thread startup handshake.

There was also a mistake in the check for syscall failures --- it should
have checked against -1 instead of 0 (not just because that's the default
idiom, but also here because futex(2) can legitimately return values > 0).

This patch stops abusing the TLS errno slot and adds a pthread_mutex_t to
pthread_internal_t instead. (Note that for LP64 sizeof(pthread_mutex_t) >
sizeof(uintptr_t), so we could potentially clobber other TLS slots too.)

I've also rewritten the LP32 compatibility stubs to directly reuse the
code from the .h file.

This reverts commit 75c55ff84ebfa686c7ae2cc8ee431c6a33bd46b4.

Bug: 15195455
Change-Id: I6ffb13e5cf6a35d8f59f692d94192aae9ab4593d
dk_cruft.cpp
thread_create.cpp
thread_internal.h
ff03a7aaade5826e3708f6e320d0612d4cdbdb72 28-May-2014 Brigid Smith <brigidsmith@google.com> Updated ambiguous comment in pthread_mutex_lock.

The comment used the phrase "normal case" when it more specifically refers to the "recursive case," so I changed it to that.

Change-Id: I8335cce4dee933c6a463aee653b28bd986b5b5e4
thread_mutex.cpp
001707363ddee680d466c88dd330900683dadf63 24-May-2014 Anthony King <anthonydking@slimroms.net> Restore tkill for LP32.

libmono from Unity still requires tkill(2).

Change-Id: I37a1994b08086c7fedb5c78ea0dadf2d72bc1463
Signed-off-by: Anthony King <anthonydking@slimroms.net>
dk_cruft.cpp
bd3a98c6b9850a8e55fb0e0ed9f045212c494881 25-May-2014 Elliott Hughes <enh@google.com> Restore __futex_wake and __futex_wait for LP32.

Should fix Skype:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__futex_wake" referenced by "libsliq.so"...

Bug: 15196718
Change-Id: I8a18e18d830f0436e820cbde577121bd92710803
dk_cruft.cpp
1b676ea5fba4af0f3a11ca0c31a40825f2157601 23-May-2014 Calin Juravle <calin@google.com> Migrate pthread_rwlock implementation away from sys/atomics

Bug: 8133149
Bug: 14903517
Change-Id: Ib85987f53d7aeaec12a980ccb645c4a449c48503
thread_rwlock.cpp
92687e41bcf108957944dafa80a9bfda219bfb0f 22-May-2014 Calin Juravle <calin@google.com> Cleaned up pthread rwlocks implementation.

- used underscore_style_for_vars
- extracted time related functionality into a function
- cleaned up style
- removed unused fields from pthread_rwlock_t on LP64
- changed reservation in pthread_rwlock_t so that the size of the
structure equals glibc version

Bug: 8133149

Change-Id: I84ad3918678dc7f5e6b3db9b7e9b0899d3abe9cd
thread_rwlock.cpp
2ea60ff0b415ad5b135f498a38c4b56ea75215aa 22-May-2014 Elliott Hughes <enh@google.com> Remove unnecessary #includes of <sys/atomics.h>.

Bug: 14903517
Change-Id: I7b5bcebe58774a441da986cc02376dd88e00ea0e
thread_cond.cpp
thread_mutex.cpp
emaphore.c
254fa8857f5d88a4140cea2ee05056eae7f102b1 22-May-2014 Calin Juravle <calin@google.com> Merge "Switch to POSIX dprintf/vdprintf."
fcac8ff97f6b6cced6546e0096cadc1039b68b5e 22-May-2014 Elliott Hughes <enh@google.com> Switch to POSIX dprintf/vdprintf.

Bug: 11156955
Change-Id: I734bd02db514367ab119a48304aae9767958e367
dprintf.c
dk_cruft.cpp
172167163af5412c316a8be2f29ca8622984df32 22-May-2014 Calin Juravle <calin@google.com> Merge "Mutex-free implementation of pthread_rwlock"
76f352eec12d8938101e5ae33429c72797c3aa23 19-May-2014 Calin Juravle <calin@google.com> Mutex-free implementation of pthread_rwlock

Bug: 8133149
Change-Id: Id6775010d95f2634b173daa55d87a59a3cf4131b
thread_rwlock.cpp
d5ed63a6a8290de88802172ce178656fbafe70c6 22-May-2014 Elliott Hughes <enh@google.com> Hide most of the private futex functions.

Also hide part of the system properties compatibility code, since
we needed to touch that to keep it building.

I'll remove __futex_syscall4 and futex in a later patch.

Bug: 11156955
Change-Id: Ibbf42414c5bb07fb9f1c4a169922844778e4eeae
thread_internals.cpp
ystem_properties.cpp
ystem_properties_compat.c
72bbd423579bb971dc06cdd3c06201faf3fe95e6 08-May-2014 Christopher Ferris <cferris@google.com> Support for jemalloc to replace dlmalloc.

To use jemalloc, add MALLOC_IMPL = jemalloc in a board config file
and you get the new version automatically.

Update the pthread_create_key tests since jemalloc uses a few keys.
Add a new test to verify memalign works as expected.

Bug: 981363

Change-Id: I16eb152b291a95bd2499e90492fc6b4bd7053836
ebug_mapinfo.cpp
emalloc.cpp
emalloc.h
alloc_debug_check.cpp
alloc_debug_common.cpp
alloc_debug_common.h
alloc_debug_leak.cpp
alloc_debug_qemu.cpp
ysconf.cpp
94a9ba2b4a4d8be7e3520e34bfc7bd47ff7af0ce 20-May-2014 Dan Albert <danalbert@google.com> Merge "Removes RTTI support from libc"
903b78873a744d3fba187e4bd22008ba21162e51 19-May-2014 Sreeram Ramachandran <sreeram@google.com> Mark sockets on creation (socket()) and accept4().

Remove the separate syscall for accept() and implement it as accept4(..., 0).

Change-Id: Ib0b8f5d7c5013b91eae6bbc3847852eb355c7714
etdClient.cpp
etdClientDispatch.cpp
ccept.cpp
ccept4.cpp
ocket.cpp
5240b562e7e9de2f31ba70f71c394c5529aadf0f 15-May-2014 Paul Jensen <pauljensen@google.com> Query libnetd_client for the appropriate netId for host resolution.

If libnetd_client can't be found, operate as before and use the default netId
potentially overriden by a more specific netId passed in to
android_get*fornet().

(cherry picked from commit 559c7842cc6862568d9b5799fc0bcf74d58b596b)

Change-Id: I42ef3293172651870fb46d2de22464c4f03e8e0b
etdClient.cpp
etdClientDispatch.cpp
48ee47ce25fa9c99df49855ebf77ae1758d58d47 19-May-2014 Dan Albert <danalbert@google.com> Removes RTTI support from libc

Our type_info stub implementation is incompatible with the libc++ headers. Since
we don't need this support internally and anyone that wants RTTI support will
have to use libc++ anyway, this can be safely removed.

Change-Id: Ied8b67a0d86a4eb0e31191a50cceba0e39a16a6d
ypeinfo.cpp
72c53933f852be6d1cd6c09c86176fbc6d609dac 19-May-2014 Sreeram Ramachandran <sreeram@google.com> Cosmetic changes to netd client files.

+ Name the dispatch header correctly (NetdClientDispatch.h).
+ Hide the global dispatch variable (__netdClientDispatch).
+ Explain why it's okay to read the variable without locking.
+ Use quotes instead of angle-brackets for non-system includes.
+ Add necessary declarations for C compiles (and not just C++).

Change-Id: Id0932165e71d81da5fce77a684f40c2263f58e61
etdClient.cpp
etdClientDispatch.cpp
ccept.cpp
onnect.cpp
7c9923d05f03a78f70ee886878ac1dda9e84aa1d 17-May-2014 Elliott Hughes <enh@google.com> Export get_malloc_leak_info and free_malloc_leak_info, used by ddms.

Bug: 11156955
Change-Id: I84043f7b2c0ea0e336f6e2af3b7adb2f8488bd53
alloc_debug_common.cpp
aafa3d0e4623f3c57c7abe66f6afa726b9cde348 17-May-2014 Elliott Hughes <enh@google.com> Merge "Hide various debug malloc implementation details."
58b52fb133ee4f8a82d3da5c439ca7b9d2caa2bf 17-May-2014 Elliott Hughes <enh@google.com> Merge "Remove dead code."
7222b1b594a8fab4b9e744d764b70e4c17767794 17-May-2014 Elliott Hughes <enh@google.com> Hide __signalfd4, used to implement signalfd(3).

Bug: 11156955
Change-Id: I50842279cb5b32ec8bd45193435574e415cd806e
ignalfd.cpp
6b7987cca3e28381a3471804811210cdc5617cc3 17-May-2014 Elliott Hughes <enh@google.com> Hide various debug malloc implementation details.

Bug: 11156955
Change-Id: Ib9d69d49ecec8eff4f12392bde94d843ae53d442
alloc_debug_common.cpp
bd27a8b4af59e4078144f25953828061b6fead8b 16-May-2014 Elliott Hughes <enh@google.com> Remove dead code.

This doesn't exist upstream.

Really we should upgrade to the current arc4random, but that's a bigger
job for another day.

Bug: 11156955
Change-Id: If6cd41b79139c64c17e81999e246cf4f00882ce8
rc4random.c
2a60227223da700e4ae1b5436f61aea99fc7a5aa 16-May-2014 Elliott Hughes <enh@google.com> Merge "Move libstdc++ into libc."
623b0d05bd924e7fa3c155492695123c87c3a2b1 15-May-2014 Dmitriy Ivanov <dimitry@google.com> Register _cleanup function with atexit

* Register cleanup function with atexit
instead of calling it explicitly on
exit()
* abort() no longer calls _cleanup:
Flushing stdio buffers on abort is no
longer required by POSIX.
* dlmalloc no longer need to reset cleanup
(see above)
* Upstream findfp.c makebuf.c setvbuf.cexit.c
to openbsd versions.

Bug: 14415367
Change-Id: I277058852485a9d3dbb13e5c232db5f9948d78ac
bort.cpp
lmalloc.c
15b641a26731a7e42455c3ed22e1e9bdf31ea79c 15-May-2014 Elliott Hughes <enh@google.com> Move libstdc++ into libc.

The Android build system always links against libstdc++.so anyway. Having
operator new and operator delete in a separate library means we can't use
constructors and destructors on heap-allocated objects inside the C library,
which is quite an unfortunate limitation.

This will be cheaper too; on LP64 we can stop linking against the [now empty]
libstdc++.so giving the dynamic linker one less library to worry about for
every process.

There's precedent too --- we already have no libpthread or librt.

For now I'm leaving the include files where they are, and I'm generating a
dummy libstdc++.so and libstdc++.a. We can come back and clean that up later
if all goes well.

Bug: 13367666
Change-Id: I6f3e27ea7c30d03d6394965d0400c9dc87fa83db
_cxa_guard.cpp
_cxa_pure_virtual.cpp
ew.cpp
ypeinfo.cpp
3e786987b5fb3272b37dd955fe13fc67a8ddc880 15-May-2014 Elliott Hughes <enh@google.com> Remove the unused __system_property_wait.

This isn't declared in any header file.

Bug: 14970171
Change-Id: Ib9fce61343dfb6b6ccd7e1430e1a6e34e4e869df
ystem_properties.cpp
49ec2a0cdc56fcd6bdd1b0feea127acfabc076f9 14-May-2014 Sreeram Ramachandran <sreeram@google.com> Merge "Mark sockets on accept()."
07f1ded1399805fa9367f4db2936832b0c22b7a5 14-May-2014 Elliott Hughes <enh@google.com> Remove the broken pthread deadlock prediction.

This hasn't built in over one release cycle and no one even noticed.
art does this the right way and other projects should do the same.

Change-Id: I7d1fb84c4080e008f329ee73e209ce85a36e6d55
ibc_init_dynamic.cpp
thread_debug.cpp
thread_mutex.cpp
8f0cd8aa22906c3e678738eeba20fc1a5c399b6c 14-May-2014 Sreeram Ramachandran <sreeram@google.com> Mark sockets on accept().

(cherry picked from commit 58b1f3f6a30a660ad81637c2b50382c3d279243b)

Change-Id: I5d09be413cf720fbed905f96313b007997ada76c
etdClient.cpp
etdClientDispatch.cpp
ccept.cpp
cd46104cf81aef14f9554bb4d9bced534a121471 14-May-2014 Elliott Hughes <enh@google.com> Fix a typo in the big g_ search/replace.

Change-Id: I79261de70d225236d0eadff288220258d697437f
thread_create.cpp
1728b2396591853345507a063ed6075dfd251706 14-May-2014 Elliott Hughes <enh@google.com> Switch to g_ for globals.

That's what the Google style guide recommends, and we're starting
to get a mix.

Change-Id: Ib0c53a890bb5deed5c679e887541a715faea91fc
ebug_stacktrace.cpp
ibc_init_common.cpp
ibc_logging.cpp
ocale.cpp
alloc_debug_check.cpp
alloc_debug_common.cpp
alloc_debug_leak.cpp
thread_accessor.h
thread_atfork.cpp
thread_create.cpp
thread_debug.cpp
thread_exit.cpp
thread_internal.h
thread_internals.cpp
thread_key.cpp
hread_atexit.cpp
8205a61248973ac13716ae80e712c80e126b0541 14-May-2014 Sreeram Ramachandran <sreeram@google.com> Fix build (take two).

Make sure __netdClientDispatch is defined in the same set of libraries that
refer to it (e.g.: with connect.cpp).

Change-Id: I86d7bf2df5bde09f75a35b204eac0e1361747e22
etdClient.cpp
etdClientDispatch.cpp
ceb5bd787c8ce281e5f4343c5d4f77b41c3e2919 12-May-2014 Sreeram Ramachandran <sreeram@google.com> Introduce netd_client, a dynamic library that talks to netd.

The library exists outside bionic. It is dynamically loaded, to replace selected
standard socket syscalls with versions that talk to netd.

Change connect() to use the library if available.

(cherry picked from commit 3a6b627a14df8111b03e452f2df4b5f4938e0e49)

Change-Id: Ib6198e19dbc306521a26fcecfdf6e8424d163fc9
etdClient.cpp
onnect.cpp
ibc_init_dynamic.cpp
eb664e24c074b88539b743668109d8b4eaa925bd 13-May-2014 Elliott Hughes <enh@google.com> Add getmntent_r to our collection of <mntent.h> compatibility stubs.

This helps build 'external/flo' out of the box.

Bug: 14841211
Change-Id: I30dde77239cceaf1f5743163744eb3604d27a266
ntent.cpp
tubs.cpp
dbcba8f5f9a59fac3d22dfc17a14d3d5cfb4f4b0 13-May-2014 Elliott Hughes <enh@google.com> Merge "Reduce stack usage of tmpfile(3)."
b6943186ce78105155ba67ab261a970859b190df 13-May-2014 Elliott Hughes <enh@google.com> Reduce stack usage of tmpfile(3).

Also ensure that none of our home-grown code uses more than 2KiB per frame.

Change-Id: I8987a17d72f4b7f082bb7fa25e137c8433664c14
mpfile.cpp
15a6310e4b745add324b07a5d3d297aa95a56f59 08-May-2014 Calin Juravle <calin@google.com> Support mb sequences across calls to mb*to*wcs* functions

Bug: 13077905
Change-Id: I5abdc7cc3c27c109b7900c94b112f18a95c35763
char.cpp
4d695bf5606f2cf4029a7ff4e6dd61073407d3b0 12-May-2014 Calin Juravle <calin@google.com> Merge "Align struct passwd definition with other variations of libc"
8eac9af24ea7e570e0b297bcd6ac8a46ba3ecc39 10-May-2014 Elliott Hughes <enh@google.com> Bring in google3-style DISALLOW_* macros.

I've been meaning to do this for a very long time...

Change-Id: Ia8c16eee7c026c3c9505399948485fb778fb0152
thread_accessor.h
candir.cpp
ystem_properties.cpp
0d236aa3f1e6d31b0c729448ae9d3ed1cad23fb4 09-May-2014 Elliott Hughes <enh@google.com> Align the child stack in clone(2).

Also let clone(2) set the TLS for x86.

Also ensure we initialize the TLS before we clone(2) for all architectures.

Change-Id: Ie5fa4466e1c9ee116a281dfedef574c5ba60c0b5
lone.cpp
thread_create.cpp
c768874c667794bee278b9fbf207b5ca5df4e7a6 09-May-2014 Calin Juravle <calin@google.com> Align struct passwd definition with other variations of libc

Add pg_gecos ("real name") field to struct passwd.

Bug: 14679430
Bug: 12875898
Change-Id: I833ec2c46f6a6259b7232a8e3f7942968ef0b50d
tubs.cpp
954cf0d4e2669f91194b45f484152e47efa4f6c7 09-May-2014 Elliott Hughes <enh@google.com> Hide the __bionic_clone and __bionic_clone_entry implementation details.

clone(2) is the public symbol.

Also switch a test from __bionic_clone to clone; testing public API
means the test now works on glibc too.

Change-Id: If59def26a00c3afadb8a6cf9442094c35a59ffde
lone.cpp
011101905d91b770893e8a2fb6c09552d1c63652 08-May-2014 Elliott Hughes <enh@google.com> Send bionic's fatal logging to the crash log.

Bug: 14159417
Change-Id: I7aa986fb8e11660035221f9bb4fe0bc40ac36c58
ibc_logging.cpp
c78368f04faa4ee17f546985809e7550f3f88636 07-May-2014 Elliott Hughes <enh@google.com> Change the interface for fatal logging.

This more general interface lets liblog give us any fatal log message,
regardless of source. This means we can remove the special case for
LOG_ALWAYS_FATAL with a simpler scheme that automatically works for
the VM too.

Change-Id: Ia6dbf7c3dbabf223081bd5159294835d954bb067
ibc_logging.cpp
c42f5c6fe6f52c9a7082d2a43d0af42326a9c6d1 03-May-2014 Elliott Hughes <enh@google.com> Fix iswctype.

This doesn't matter until we fix the other isw* functions, of course.

Change-Id: I0baed1c933259cf22444da391bc4a56446d66773
ctype.cpp
efaa461bd67cfdfcbc2b4c6b69805bc5b929ae05 03-May-2014 Elliott Hughes <enh@google.com> Use the OpenBSD wcsftime.

Change-Id: I81929355d245ba1e58b4a464ca6cf45915e0238e
ctype.cpp
0d0ccfe2ce32e3669c66fe7575fedbd5ab0db410 02-May-2014 Elliott Hughes <enh@google.com> Fix wchar_t signedness problems found on x86-64.

The existing tests caught this.

Change-Id: I6269844ae4301fd2c596241a59e97eb67ef166fa
char.cpp
568c86a48955fd5479db53b68d59be04df633ec5 02-May-2014 Elliott Hughes <enh@google.com> Fix wchar.cpp signed/unsigned comparison build failure.

Change-Id: Id20b91f3d57c4430987b5cc88ac99c245801d73b
char.cpp
5a0aa3dee247a313f04252cf45608097695d5953 01-May-2014 Elliott Hughes <enh@google.com> Switch to a working UTF-8 mb/wc implementation.

Although glibc gets by with an 8-byte mbstate_t, OpenBSD uses 12 bytes (of
the 128 bytes it reserves!).

We can actually implement UTF-8 encoding/decoding with a 0-byte mbstate_t
which means we can make things work on LP32 too, as long as we accept the
limitation that the caller needs to present us with a complete sequence
before we'll process it.

Our behavior is fine when going from characters to bytes; we just
update the source wchar_t** to say how far through the input we got.

I'll come back and use the 4 bytes we do have to cope with byte sequences
split across multiple input buffers. The fact that we don't support
UTF-8 sequences longer than 4 bytes plus the fact that the first byte of
a UTF-8 sequence encodes the length means we shouldn't need the other
fields OpenBSD used (at the cost of some recomputation in cases where a
sequence is split across buffers).

This patch also makes the minimal changes necessary to setlocale(3) to
make us behave like glibc when an app requests UTF-8. (The difference
being that our "C" locale is the same as our "C.UTF-8" locale.)

Change-Id: Ied327a8c4643744b3611bf6bb005a9b389ba4c2f
ocale.cpp
char.cpp
ctype.cpp
0990d4fda898ada86e557f872f5cb7d16b138e3c 30-Apr-2014 Elliott Hughes <enh@google.com> Make SIGRTMIN hide the real-time signals we use internally.

__SIGRTMIN will continue to tell the truth. This matches glibc's
behavior (as evidenced by the fact that we don't need a special case
in the strsignal test now).

Change-Id: I1abe1681d516577afa8cd39c837ef12467f68dd2
_libc_current_sigrtmax.cpp
_libc_current_sigrtmin.cpp
osix_timers.cpp
77473e408504a7e298816b4071cd6902065b03d8 30-Apr-2014 Calin Juravle <calin@google.com> Merge "Fix cpu_set_t"
b743790ccabd9b0b93355ff693066478d10dae0d 29-Apr-2014 Calin Juravle <calin@google.com> Fix cpu_set_t

- extend CPU_SETSIZE for LP64
- fix CPU_(AND|OR|XOR) macros
- fix CPU_OP_S macro
- fix __sched_cpucount
- tidy up the code

Change-Id: I741afff4d0c473e8a1ee6b4141981dc24467e0d4
ched_cpucount.c
94336d8ecf795cfdde874a1e15977d68cfc7afc1 30-Apr-2014 Elliott Hughes <enh@google.com> Switch to OpenBSD stdio wide printf functions.

Change-Id: Icf4f8685d021ec6b7482ca1cc021ce8184098e4a
char.cpp
c932225e1061dc57fc4bf2d6203d9737f4f989fa 30-Apr-2014 Elliott Hughes <enh@google.com> Switch to OpenBSD stdio wide get/put functions.

Change-Id: I71f8769cdea874e55d397ca7682d9d4e659d3dcb
char.cpp
01ae00f3170ad0e36c1657f6ff8c89dfa730fd37 30-Apr-2014 Elliott Hughes <enh@google.com> Switch to the OpenBSD implementations of the wide scanf functions.

This also gets us the C99 wcstoimax and wcstoumax, and a working fgetwc and
ungetwc, all of which are needed in the implementation.

This also brings several other files closer to upstream.

Change-Id: I23b025a8237a6dbb9aa50d2a96765ea729a85579
lockfile.cpp
char.cpp
770491fb4ff85891bbe71aaf4dcec7f22e53abdb 30-Apr-2014 Elliott Hughes <enh@google.com> Fix build (signed char issue).

Change-Id: I05d78f4c1599ed9a0c1285f9eb1e89bc2f55c24d
char.cpp
3d7a0d9b08ecab054b2dff8332507644de3690b0 29-Apr-2014 Elliott Hughes <enh@google.com> Switch to the OpenBSD wcsto* functions.

This replaces a partial set of non-functional functions with a complete
set of functions, all of which actually work.

This requires us to implement mbsnrtowcs and wcsnrtombs which completes
the set of what we need for libc++.

The mbsnrtowcs is basically a copy & paste of wcsnrtombs, but I'm going
to go straight to looking at using the OpenBSD UTF-8 implementation rather
than keep polishing our home-grown turd.

(This patch also opportunistically switches us over to upstream btowc,
mbrlen, and wctob, since they're all trivially expressed in terms of
other functions.)

Change-Id: I0f81443840de0f1aa73b96f0b51988976793a323
char.cpp
0a5e26da1eae6b75a89695faf2e057c5c4717721 29-Apr-2014 Elliott Hughes <enh@google.com> Add mbtowc and fix mbrtowc.

Change-Id: I48786cd82587e61188d40f6fd6e11ac05e857ae9
char.cpp
d299bcfdad959a3a0adf1683605b15a1c3b3ab66 29-Apr-2014 Elliott Hughes <enh@google.com> Replace our broken wcswcs with the working upstream one.

Change-Id: I2952684df5674d10f0564d92c2cd42597725c0e3
char.cpp
533dde4dbf87d6615952be3654fc74e5ff2e1003 26-Apr-2014 Elliott Hughes <enh@google.com> Fix brk/sbrk error checking.

Note that the kernel returns the current break on error or if the requested
break is smaller than the minimum break, or the new break. I don't know where
we got the idea that the kernel could return -1.

Also optimizes the query case.

Also hides an accidentally-exported symbol for LP64.

Change-Id: I0fd6b8b14ddf1ae82935c0c3fc610da5cc74932e
rk.cpp
brk.cpp
08bfcff0d4a931a4ed5e2a46541dc8d223482f34 24-Apr-2014 Elliott Hughes <enh@google.com> Merge "Allow liblog to pass failure reasons to debuggerd."
ae77f74bcf51cb4199c9f7e87ec9c751fdd1842b 24-Apr-2014 Calin Juravle <calin@google.com> Merge "Clean-up _fpmath and fake_long_doubles"
2e3b7108b5b3d3f3a4a0fb369016e854bcf92212 23-Apr-2014 Elliott Hughes <enh@google.com> Allow liblog to pass failure reasons to debuggerd.

assert(3) already does this, but LOG_ALWAYS_FATAL and LOG_ALWAYS_FATAL_IF
have been missing out.

Change-Id: I1d6214c4f792fa0d4ba3c14eded3fc9c332bd3c5
ibc_logging.cpp
a64d76895dde584434824037f216dcade1cfb5c6 23-Apr-2014 Elliott Hughes <enh@google.com> Remove two dead files.

I forgot to remove these in the change that stopped building them
(eae5902e73dc4381811e08fd2334bf4a9300a928).

Change-Id: I4665fa9f6b9b80c51778d5e82b49406fe56db9a6
trntoimax.c
trntoumax.c
1abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407f 17-Apr-2014 Calin Juravle <calin@google.com> Clean-up _fpmath and fake_long_doubles

- promoted IEEEld2bits to fpmath since most of the where the same for
diffrent archs
- removed _fpmath
- reinstated weak_references
- moved isfinite and isnormal to libc
- clean up fake_long_doubles
- clean up some useless ifdefs
- added missing nexttoward* tests

Bug: 14134235
Change-Id: I95639c4885653fe47fd7dc0570ee5bb3389bbc6b
pclassify.cpp
532ad903d2febc400e23d66c5f4d836d1e5f11fc 23-Apr-2014 Elliott Hughes <enh@google.com> Merge "Switch to the upstream OpenBSD getenv/putenv/setenv implementation."
eae5902e73dc4381811e08fd2334bf4a9300a928 23-Apr-2014 Elliott Hughes <enh@google.com> Remove strntoimax and strntoumax from the future.

Where do these turds come from?

Change-Id: Id9ad2cc85c6128aa63b5d56ff2aa455bde39a5eb
dk_cruft.cpp
58d9e280d459225aa8dc4533e883182b08215f7d 23-Apr-2014 Elliott Hughes <enh@google.com> Switch to the upstream OpenBSD getenv/putenv/setenv implementation.

This fixes all the bugs found by the new tests.

Change-Id: Id5a5f9f39a0620208bafa053f871a044725b4795
learenv.c
learenv.cpp
8d77bce185d04c531bd9bf34d38e5cbbe644d3a3 22-Apr-2014 Elliott Hughes <enh@google.com> LP64 shouldn't include the non-standard <time64.h> cruft.

This patch includes just enough to keep external/chromium_org building
until they switch 64-bit Android over to using the regular non-Android code.

Change-Id: Iecaf274efa46ae18a42d5e3439c5aa4f909177c1
ime64.c
d3679c815e010c2e67bf07420b6ab3a74f27a2ed 21-Apr-2014 Elliott Hughes <enh@google.com> clang is >= 3.4 now; remove a hack.

Change-Id: I8d976ee0fd88eca9779c87b5d7e27f46b4b1b489
ebug_stacktrace.cpp
9b22c21ceec0a65875081525218315d08bbd36b5 19-Apr-2014 Elliott Hughes <enh@google.com> Merge "Make uselocale(3) claim its pthread key in an ELF constructor."
2f68866f371faa8ef727fc91e59e1e93326a3949 18-Apr-2014 Elliott Hughes <enh@google.com> Make uselocale(3) claim its pthread key in an ELF constructor.

pthread_once is nice for decoupling, but it makes resource availability less
predictable, which is a bad thing.

This fixes a test failure if uselocale(3) is called before
pthread.pthread_key_create_lots runs.

Change-Id: Ie2634f986a50e7965582d4bd6e5aaf48cf0d55c8
ocale.cpp
1b836ee6f8e5c0f61d67c1f014819a066366ab6f 18-Apr-2014 Elliott Hughes <enh@google.com> Fix a wchar.wcstombs_wcrtombs test failure.

Looks like I screwed up a last-minute refactor and didn't re-run the tests.

Change-Id: I90a710ae66a313a9812859650aa0b4e8c6bc57f9
char.cpp
0549371bd74ba7c7a5a16c2a7d6cc17dbe0e6f97 18-Apr-2014 Elliott Hughes <enh@google.com> Upgrade to current vfprintf.

This gets us various bug fixes and missing C99 functionality.

Bug: https://code.google.com/p/android/issues/detail?id=64886
Change-Id: Ie9f8ac569e9b5eec1e4a1faacfe2c21662eaf895
char.cpp
8da69a25b7840db23846d4bb303ef84a1775c1e1 17-Apr-2014 Elliott Hughes <enh@google.com> Merge "Switch fpclassify over to ieee_ext."
f081e139feb56ae0cde4af6ea8176a41f2fc80d7 17-Apr-2014 Elliott Hughes <enh@google.com> Switch fpclassify over to ieee_ext.

Change-Id: I441bb7f715da24e1c04b0386ad9dcde0ea8c797c
pclassify.cpp
20828db758f05fc4a98a45adaeb4700cfe780112 17-Apr-2014 Elliott Hughes <enh@google.com> Use FLT_ROUNDS in LP64 strtold.

Change-Id: I75323be6e1cadb00770fcdd08422836b03737416
trtold.cpp
4bd97cee28dd815fff54fc97560be60d566c1fa5 11-Apr-2014 Elliott Hughes <enh@google.com> Switch to gdtoa.

This gives us a real strtold for LP64 and fixes various LP64
bugs.

Bug: 13563801
Change-Id: I277858d718ee746e136b6b6308a495ba50dfa488
trtof.cpp
trtold.cpp
40b05791278f9ac6ff842670e80899c7cd15276f 15-Apr-2014 Elliott Hughes <enh@google.com> Add iswblank for libcxx.

We have similar degenerate implementations for all the other isw* functions,
so it's weird to exclude just one.

Change-Id: I659b97930e68598826c4882bb59f4146870fb6a0
char.cpp
02c78a386739a8a2b3007efeb00a9ca04132100a 12-Apr-2014 Elliott Hughes <enh@google.com> Reimplement isinf/isnan/fpclassify.

Also move isinf and isnan into libc like everyone else.

Also move fpclassify to libc like the BSDs (but unlike glibc). We need
this to be able to upgrade our float/double/long double parsing to gdtoa.

Also add some missing aliases. We now have all of:

isnan, __isnan, isnanf, __isnanf, isnanl, __isnanl,
isinf, __isinf, isinff, __isinff, isinfl, __isinfl,
__fpclassify, __fpclassifyd, __fpclassifyf, __fpclassifyl.

Bug: 13469877
Change-Id: I407ffbac06c765a6c5fffda8106c37d7db04f27d
pclassify.cpp
b676aafad04f88e36658d4468054375158dbd3c1 11-Apr-2014 Elliott Hughes <enh@google.com> Remove unnecessary #includes.

Change-Id: Ie7e0c9ea03f35517c7dcf09fc808c12e55262bc1
thread_cond.cpp
thread_create.cpp
thread_mutex.cpp
a5d83312bdeae2062a45160f54ce86c4b7b164e0 09-Apr-2014 Calin Juravle <calin@google.com> Merge "Use glibc structure for __cmsg_nxthdr."
c4936e20a3a8772cc393423037be36091e68acc2 09-Apr-2014 Elliott Hughes <enh@google.com> Flesh out <locale.h>.

This is a trivial implementation that only supports the C/POSIX locale.

Change-Id: Ib11cea4249e1862aca96a8b94d58ea9a418cbe75
ocale.cpp
ff64831b0965c16c95c9f81a148f30a6ef3a6c64 07-Apr-2014 Calin Juravle <calin@google.com> Use glibc structure for __cmsg_nxthdr.

Bug: 13418328
Change-Id: I7e656b373e53e80d708325321e48dcedacf5086d
msg_nxthdr.cpp
5363a45f2b6d4eeb054710d0886bbadea8a15273 08-Apr-2014 Elliott Hughes <enh@google.com> Clean up localeconv(3).

The OpenBSD doesn't support C99, and the extent to which we support
locales is trivial, so just do it ourselves.

Change-Id: If0a06e627ecc593f7b8ea3e9389365782e49b00e
ocale.cpp
etlocale.cpp
41059d764f347baa28b8da653a88c772daa9b738 08-Apr-2014 Christopher Ferris <cferris@google.com> Merge "Add stpcpy/stpncpy."
950a58e24d1019eb9d814dbb16f111a6b61e3f23 04-Apr-2014 Christopher Ferris <cferris@google.com> Add stpcpy/stpncpy.

Add tests for the above.

Add the fortify implementations of __stpcpy_chk and __stpncpy_chk.

Modify the strncpy test to cover more cases and use this template for
stpncpy.

Add all of the fortify test cases.

Bug: 13746695
Change-Id: I8c0f0d4991a878b8e8734fff12c8b73b07fdd344
_stpcpy_chk.cpp
_stpncpy_chk.cpp
_strcpy_chk.cpp
efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4 08-Apr-2014 Elliott Hughes <enh@google.com> Remove a non-standard turd: strtotimeval.

Change-Id: I1b1e40746cb573e3fb73a5276969b40c5da36d15
dk_cruft.cpp
trtotimeval.c
77e944fd46728075fe632bcb5211da9daf5b7e68 05-Apr-2014 Elliott Hughes <enh@google.com> Implement wctomb(3) for ltrace.

This is an implementation in the style of the rest: char == byte.

We might want to come back and implement UTF-8, but this is enough for ltrace.

Bug: 13747066
Change-Id: Ib2b63609c9014fdef9a8491e067467c4fc5ae3cc
char.cpp
473d06707bccf0dd707905dcbe74ba91c4d1e8a5 02-Apr-2014 Elliott Hughes <enh@google.com> Fix the POSIX timers fix.

If we're not going to wait for the timer threads to exit, we need
another way to ensure that we don't free the data they're using
prematurely. The easiest way to ensure that is to let them free the
data themselves.

Change-Id: Icee17c87bbcb9c3aac5868973f595d08569f33aa
osix_timers.cpp
64b2963224bdd139caf667b6263e3b75e99dd20a 01-Apr-2014 Elliott Hughes <enh@google.com> Fix debug malloc for LP64.

Change-Id: I5de2097b6589c0d6750b2a3bc3cbb06227de6d5f
alloc_debug_common.cpp
f1d7536dcfffadc91aabd0a14ec07334a334eea2 26-Mar-2014 Weichuan Yan <wchyan@marvell.com> Fix and clean up strtotimeval

- parsing of fractional part was wrong (always parsed as 0)
- return value was also wrong in the presence of fractional parts
- general style clean up

Change-Id: I1935a63db938dbed7cacb4b5646e993a52c27f1a
Signed-off-by: Weichuan Yan <wchyan@marvell.com>
trtotimeval.c
9e8a8dc18cb3162858feef2d4baaf3fa357aa3d2 24-Mar-2014 Calin Juravle <calin@google.com> Merge "Remove ALIGNBYTES and ALIGN from <sys/param.h>"
cce6c380d7c9574f823f5e038c28c793fdb55c58 21-Mar-2014 Mark Salyzyn <salyzyn@google.com> Merge "libc: Thread IDs missing from logcat -v thread"
c20de902875dcaebde0ccd0b7a8351598f254d4c 20-Mar-2014 Calin Juravle <calin@google.com> Remove ALIGNBYTES and ALIGN from <sys/param.h>

There are only three users of bionic definition of ALIGN and keeping it
in sys/param.h polutes the namespace.

I inline the definition in the the three places that's used.

Bug: 13400663
Change-Id: I565008e8426c38ffb07422f42cd8e547d53044e9
ts.c
753ad778bc1c3aecc4cd82b8387a7dc8a9b44d34 21-Mar-2014 Christopher Ferris <cferris@google.com> Fix deadlock in timer_delete.

If the callback function for a timer did a timer_delete, the function
would never return. The problem was that the timer_delete function would try
to wait until the timer thread has finished. Waiting for yourself to finish
doesn't work very well.

Bug: 13397340
Change-Id: Ica123a5bafbc8660c8a4a909e5c2dead55ca429d
osix_timers.cpp
8664be583a4556e5ca132288e989d307d2df92ce 21-Mar-2014 Mark Salyzyn <salyzyn@google.com> libc: Thread IDs missing from logcat -v thread

- stuff caller's thread id into the packet.

Bug: 13568206
Change-Id: If8b318ef75c7dcdddb05da8ac3038860f0fda5ec
ibc_logging.cpp
f2cea021ab2c6d7d7feeb40cca098aa132605876 13-Mar-2014 Elliott Hughes <enh@google.com> Clean up <stdio.h> macros.

Also neuter __isthreaded.

We should come back to try to hide struct FILE's internals for LP64.

Bug: 3453512
Bug: 3453550
Change-Id: I7e115329fb4579246a72fea367b9fc8cb6055d18
thread_create.cpp
879d33049946fa2293a61dbdb20addace953922b 13-Mar-2014 jiaguo <jiaguo@marvell.com> property: fix getting dirty serial value

__system_property_serial just returned serial value without
checking if it is dirty, so check and wait until serial
value is not dirty before return

Change-Id: If485b6251b5555b004912c66c7c2cb455a7fdbdc
Signed-off-by: jiaguo <jiaguo@marvell.com>
ystem_properties.cpp
5a8173860d65182af022be88fed0c5d8d5dcb69d 13-Mar-2014 Elliott Hughes <enh@google.com> Ensure we always have symbols for atof, strtof, strtold.

We'll need a better implementation of strtold for LP64, but all our
long double functions are currently broken for LP64 anyway so this
isn't a regression.

Change-Id: I2bdebac11245d31521d5fa09a16331c03dc4339c
tof.cpp
trtof.cpp
trtold.cpp
8d4b5849f21dc4115ad66944dc11df838b3faa52 12-Mar-2014 Elliott Hughes <enh@google.com> Clean up our termios implementation.

It's safe to fix our constant definitions because we know we never
had symbols before, so can't be passing the bad old constants to the new
functions, or the correct new constants to the old inlines.

Change-Id: I858fc680df39bdd3ba471e867833bdfa71f6224e
cgetpgrp.c
csetpgrp.c
ermios.cpp
cccfe1e17c47799deee67fa23f48d8c860390ac8 11-Mar-2014 Elliott Hughes <enh@google.com> Reimplement clock(3) and switch to OpenBSD time(3).

The new implementation is a better approximation to the processor time used
by the process because it's actually based on resource usage rather than just
elapsed wall clock time.

Change-Id: I9e13b69c1d3048cadf0eb9dec1e3ebc78225596a
lock.cpp
a0ca209ac0deef086c0e69b59168dd75df2a3f52 10-Mar-2014 Calin Juravle <calin@google.com> Sysconfig fixes

Remove _POSIX_THREAD_ATTR_STACKADDR and _POSIX_THREAD_ATTR_STACKSIZE
since they don't exists. Return -1 for their corresponding values but
don't set errno.

Bug: 13281069
Change-Id: Ice29b4dfebe2b474212e40ee726d86782a3064b9
ysconf.cpp
a4eafa6dbc98378f3fa759fec8590871e2b5ae29 10-Mar-2014 Calin Juravle <calin@google.com> Removed pthread_attr_getstackaddr/pthread_attr_setstackaddr

Moved existing definitions to ndk_cruft to preserve NDK compatibility.

Bug: 13281069
Change-Id: I6f260de69afa55a6274f0d13145c19ac6517b9d5
dk_cruft.cpp
thread_attr.cpp
247dc91889ffc8b71fc3371edba9d834afab96ab 11-Mar-2014 Elliott Hughes <enh@google.com> Take ownership of various simple syscall wrappers.

None of these trivial functions is something we're going to get from BSD.

Change-Id: Iee1d1281b73db67da5ec303da7a49748121464bf
etpgrp.c
etpgrp.cpp
ecv.c
ecv.cpp
end.c
end.cpp
etpgrp.c
etpgrp.cpp
mount.c
mount.cpp
19f58efa22357bfaa6a63a0940928830e95c5123 11-Mar-2014 Elliott Hughes <enh@google.com> Switch to NetBSD utmp.c.

Change-Id: Ibe94888aa48b5b28fea97fd5719a1ed7a23ddeb3
tmp.c
57a883640f3b43bf5e332d64489b3eab67a5ac3f 11-Mar-2014 Elliott Hughes <enh@google.com> Switch to upstream FreeBSD ldexp.c.

(Yes, this should be in libm, but it isn't. For once, this mistake predates
bionic!)

Change-Id: I1340407acbcdc0151dee969a38ba490bdd5e6767
dexp.c
7aef27468ee7683a0ce436f5453e6eb6ca12103b 11-Mar-2014 Elliott Hughes <enh@google.com> Merge "Switch to OpenBSD wcscoll."
c8937eadf4a45afebe586dcea7a8ed882f3bec3b 11-Mar-2014 Elliott Hughes <enh@google.com> Switch to OpenBSD wcscoll.

Change-Id: I1050ef728e18124656e76f32b42ac9a4688f252d
cscoll.c
152b9de19ade833ada124390ef153e53d3d3e2ed 10-Mar-2014 Elliott Hughes <enh@google.com> Remove non-standard memswap.

Change-Id: I06548dda339987b755ef7139c590ca3e1f9fe0a9
emswap.c
dk_cruft.cpp
04620a3cd7bdea0d1b421c8772ba3f06839bbe9c 08-Mar-2014 Elliott Hughes <enh@google.com> Fix pthread_detach for already-exited threads.

Change-Id: I2bf7f41234d93b226132a4c51705f4186f4961c3
Reported-by: Paresh Nakhe <pnakhe@codeaurora.org>
thread_detach.cpp
4d46c940315af2d93efb44e751b69ea6880a5d65 08-Mar-2014 Elliott Hughes <enh@google.com> Merge "Rewrite the POSIX timer functions."
4b558f50a42c97d461f1dede5aaaae490ea99e2e 05-Mar-2014 Elliott Hughes <enh@google.com> Rewrite the POSIX timer functions.

This is a much simpler implementation that lets the kernel
do as much as possible.

Co-authored-by: Jörgen Strand <jorgen.strand@sonymobile.com>
Co-authored-by: Snild Dolkow <snild.dolkow@sonymobile.com>
Change-Id: Iad19f155de977667aea09410266d54e63e8a26bf
ork.cpp
osix_timers.cpp
thread_atfork.cpp
thread_internal.h
imer.cpp
d40eb1594dff0103247292967f8a801ef8c0ff12 07-Mar-2014 Elliott Hughes <enh@google.com> Merge "Fix some pthread symbols build as C++ symbol under x64 lunch."
9fc76027f3e1e02193f3dd98063c55918e1b4066 05-Mar-2014 Mark Salyzyn <salyzyn@google.com> libc: libc_logging 64bit compile issue

- user space logger wire format for time

Change-Id: I4840653e3a6ae151a02584311d1227d2fe536d0f
ibc_logging.cpp
f0870c3bfeba99482392fafe6d5f49615393c2b1 21-Feb-2014 Halton Huo <halton.huo@intel.com> Fix some pthread symbols build as C++ symbol under x64 lunch.

Functions protected with !defined(__LP64__) will be get build as C++
symbols for X64 build. This is not the desired work. So protect the
implementation with !defined(__LP64__) as well.

Change-Id: I4ef50ec36e46289ab308063e24f6c5ac61a6ca8d
thread_attr.cpp
thread_cond.cpp
39b644a0e270df453c53d6060cd364391bb1c512 04-Mar-2014 Elliott Hughes <enh@google.com> Remove dead NULL checks from pthread code.

GCC is removing these checks anyway because it knows the arguments
must be non-null, so leaving this code around is just confusing.

We know from experience that people were shipping code with locking
bugs because they weren't checking for error returns. Failing hard
like glibc does seems the better choice. (And it's what the checked
in code was already doing; this patch doesn't change that. It just
makes it more obvious that that's what's going on.)

Change-Id: I167c6d7c0a296822baf0cb9b43b97821eba7ab35
thread_cond.cpp
thread_mutex.cpp
thread_rwlock.cpp
thread_setname_np.cpp
0e714a5b41451e84c5ded93a42c9a4b0a9440691 04-Mar-2014 Elliott Hughes <enh@google.com> Implement POSIX pthread_mutex_timedlock.

This replaces the non-standard pthread_mutex_lock_timeout_np, which we have
to keep around on LP32 for binary compatibility.

Change-Id: I098dc7cd38369f0c1bec1fac35687fbd27392e00
thread_cond.cpp
thread_internal.h
thread_internals.cpp
thread_mutex.cpp
51e6cb33e3d7c2f44864d356a2a8e66317688f55 03-Mar-2014 Narayan Kamath <narayan@google.com> Implement pthread_condattr_{get,set}clock.

We only support CLOCK_REALTIME and CLOCK_MONOTONIC for now,
so we us a single bit from pthread_cond_t->value to denote
the clock type. Note that this reduces the width of the counter
to 30 bits, but this should be large enough for all practical
purposes.

bug: 13232338

Change-Id: I857e7da64b3ecbb23eeac7c9f3fbd460f60231bd
thread_cond.cpp
9bd9b7dd205e79577f5cd1d9488aabe0f213ce35 03-Mar-2014 Elliott Hughes <enh@google.com> If the kernel doesn't have MADV_MERGEABLE, stop asking for it.

Note that a dynamically-linked binary will still probably see two attempts ---
one by the dynamic linker (which will set its copy of the flag so it won't try
again) and then one by the executable itself (which gets a new uninitialized
copy of the flag).

Change-Id: Id6b7e47780f0f24d2ca0384a75373f4824fa8f12
map.cpp
0336e35368aa161f1fed04ccde39553db4740b97 08-Nov-2013 Mark Salyzyn <salyzyn@google.com> libc: Make calls to new user-space logger

* libc (fatal) logging now makes socket connection to the
user-space logging service.
* Add a TARGET_USES_LOGD make flag for BoardConfig.mk to manage
whether logd is enabled for use or not.

Change-Id: I96ab598c76d6eec86f9d0bc81094c1fb3fb0d9b4
ibc_logging.cpp
ba76572789740ec1a04da30dd89121ef5cb0bf44 26-Feb-2014 Elliott Hughes <enh@google.com> Fix log_backtrace assertion failure caused by LP64 fix.

When libc.debug.malloc is enabled, stack backtraces fail with:

bionic/libc/bionic/libc_logging.cpp:378: assertion "conversion
specifier unsupported" failed

The cause was a change to the format specifier from "%08x" to
"%0*x" to pass the field width as an additional parameter.
Unfortunately this modifier isn't supported by out_vformat() in
libc_logging.cpp.

Changed to use "%016x" if __LP64__ is defined; "%08x" otherwise.

Bug: 13177507
Change-Id: Ibf07263acf14da086d3c3788872f4b5477bd5708
ebug_stacktrace.cpp
b6208836cb9d3254a5e2046a71ac4ec30a0efdf5 26-Feb-2014 Elliott Hughes <enh@google.com> Fix LP64 builds after OpenBSD string changes.

Change-Id: I07202f6484e716d153d0387fcfc023e119438251
_memcmp16.cpp
emcpy.c
emcpy.cpp
5c7816f425cb70ca6920e816aba33ce3d691ef10 25-Feb-2014 Elliott Hughes <enh@google.com> Merge "More OpenBSD cleanup (primarily string)."
a92b57c7f8230661d911f2fd6dd67a81e9a90cef 25-Feb-2014 Calin Juravle <calin@google.com> Merge "Added ftw64, nftw64"
7c1efffc249283b47309846abba8795f3fb91555 25-Feb-2014 Calin Juravle <calin@google.com> Merge "Added mkstemp64"
53e43292aac91bf62995788cd5ca2ceb7caea283 25-Feb-2014 Elliott Hughes <enh@google.com> More OpenBSD cleanup (primarily string).

This patch removes the string/ and wchar/ directories.

Change-Id: Ia489904bc67047e4bc79acb1f3eec21aa3fe5f0d
_memcmp16.cpp
_strrchr_chk.cpp
lockfile.c
lockfile.cpp
ndex.cpp
trchr.cpp
trrchr.cpp
0e44bc3baeb1677e5fbdda87a737b9c508c95132 25-Feb-2014 Elliott Hughes <enh@google.com> Remove <asm/page.h>.

If we have PAGE_SIZE/PAGESIZE, POSIX says they should be in <limits.h>.

Change-Id: I3c2d574ea2aea81f524874a156361411a4ffa18e
dk_cruft.cpp
tubs.cpp
ysconf.cpp
d4934a70e69365c97b1378820152e134a0089b5e 24-Feb-2014 Calin Juravle <calin@google.com> Added ftw64, nftw64

Bug: 13076637
Change-Id: I5b926526f935b00bba14c2807b61d85f95089c33
fs64_support.cpp
fe317a3775e16d466bb884a8e054fd77f7087bb3 21-Feb-2014 Calin Juravle <calin@google.com> Added mkstemp64

Bug: 13076637
Change-Id: I41bf28ab3e6c7325470781e9323eeec023483df5
fs64_support.cpp
37e9570bce0ec5c08eab53935905f1e3a133dea2 24-Feb-2014 Narayan Kamath <narayan@google.com> Fix 64-bit build.

A warning about signed vs unsigned comparison was converted
into an error here :

...
struct stat st;
if (st.st_size > sizeof(prop_area) {
...

st_size is either an off64_t, which is a signed type. It's
worth investigating why this didn't trigger a warning on 32 bit,
where it's signed as well.

Change-Id: Ib2622bd5c444ddcfa7fb2141f00332cbb4a0818b
ystem_properties.cpp
c9ae21a5c3b2e1baafe50f752e2e07e343d39530 19-Feb-2014 Narayan Kamath <narayan@google.com> Move system_properties over to C++.

This change constitutes the minimum amount of
work required to move the code over to C++, address
compiler warnings, and to make it const correct and
idiomatic (within the constraints of being called
from C code).

bug: 13058886

Change-Id: Ic78cf91b7c8e8f07b4ab0781333a9e243763298c
ystem_properties.c
ystem_properties.cpp
0133944b09d1c0a35041f7a41eb6bfb660144f4f 21-Feb-2014 Elliott Hughes <enh@google.com> Clean up our OpenBSD usage.

Also undo some of the mess where we have OpenBSD <stdio.h> but a mix of
different BSD's implementations.

In this first pass, I've only moved easy OpenBSD stuff.

Change-Id: Iae67b02cde6dba9d8d06fedeb53efbfdac0a8cf6
toi.c
tol.c
toll.c
tok.c
error.c
trndup.c
db1ea3474899ebbd783aba872d3005f95a816d0f 18-Jan-2014 Elliott Hughes <enh@google.com> Implement some of the missing LFS64 support.

This gives us:

* <dirent.h>
struct dirent64
readdir64, readdir64_r, alphasort64, scandir64

* <fcntl.h>
creat64, openat64, open64.

* <sys/stat.h>
struct stat64
fstat64, fstatat64, lstat64, stat64.

* <sys/statvfs.h>
struct statvfs64
statvfs64, fstatvfs64.

* <sys/vfs.h>
struct statfs64
statfs64, fstatfs64.

This also removes some of the incorrect #define hacks we've had in the
past (for stat64, for example, which we promised to clean up way back
in bug 8472078).

Bug: 11865851
Bug: 8472078
Change-Id: Ia46443521918519f2dfa64d4621027dfd13ac566
irent.cpp
egacy_32_bit_support.cpp
stat.cpp
pen.cpp
candir.cpp
tat.cpp
tatvfs.cpp
ffe026680edaba268330bc67dd986d2c900ecfc7 18-Feb-2014 Elliott Hughes <enh@google.com> Merge "bionic: fix __set_errno for arm64 syscalls that return a 64-bit value"
3d19a8319b9c27af8aa5cfbf495da0fe7fa62d3e 15-Feb-2014 Colin Cross <ccross@android.com> bionic: fix __set_errno for arm64 syscalls that return a 64-bit value

bionic/libc/arch-arm64/syscalls/read.S ends with:
b.hi __set_errno
ret
END(read)

If __set_errno returns int, it will set w0 to 0xFFFFFFFF, which means
x0 is 0x00000000FFFFFFFF. When interpreted as a ssize_t that is
INT_MAX, not -1.

Change __set_errno to return long, which will cause x0 to be set instead
of w0.

Change-Id: I9f9ea0f2995928d2ea240eb2ff7758ecdf0ff412
_set_errno.cpp
a38cb088619d3e2f2194247038c10897d1c5036e 17-Feb-2014 Elliott Hughes <enh@google.com> Clean up various warnings in bionic.

Change-Id: Ic57541d0a567fd4ae79f0ad59b2ffde1130eb7d2
_bionic_name_mem.cpp
ame_mem.c
eboot.c
eboot.cpp
cfbfe7059ca4e44291d065ccd4da436aedff5a73 17-Feb-2014 Elliott Hughes <enh@google.com> Remove duplicate definitions of MIN and MAX.

These were needed when bionic's header files were missing these macros (though
it would have made a lot more sense to just fix the header files!) but cause
warnings now.

Change-Id: I65a677122f4f6bd07dffc3f37a0c4c0e823d1bb0
ts.c
671e236d5fd2cae169c2a31d0a35e66c4fcc5556 13-Feb-2014 Elliott Hughes <enh@google.com> Restore sys_signame for LP64.

mksh is using this, and we probably build as much BSD source as glibc source.

Change-Id: I400d255a67f9614ca9e57090e3a2e49d2b10cba4
ys_signame.c
aa0ebdafc71e1ceac78e0929b94f3bb117d0c8e9 12-Feb-2014 Elliott Hughes <enh@google.com> Clean up sys_signame and sys_siglist a little.

We don't need quite so much duplication because we already have a way
to get the signal number from its name, and that already copes with the
fact that the mips/mips64 numbers are different from everyone else's.

Also remove sys_signame from LP64. glibc doesn't have this BSD-ism.

Change-Id: I6dc411a3d73589383c85d3b07d9d648311492a10
iglist.c
igname.c
trerror_r.cpp
ys_siglist.c
ys_signame.c
0266ae5f884d72da58f33a072e865ba131234a5e 11-Feb-2014 Elliott Hughes <enh@google.com> Switch <elf.h> over to linux uapi under the covers.

Remove the linker's reliance on BSD cruft and use the glibc-style
ElfW macro. (Other code too, but the linker contains the majority
of the code that needs to work for Elf32 and Elf64.)

All platforms need dl_iterate_phdr_static, so it doesn't make sense
to have that part of the per-architecture configuration.

Bug: 12476126
Change-Id: I1d7f918f1303a392794a6cd8b3512ff56bd6e487
l_iterate_phdr_static.c
l_iterate_phdr_static.cpp
etauxval.cpp
ibc_init_static.cpp
f64b8ea09db3bdd84eed59f7721301743332b3fe 04-Feb-2014 Elliott Hughes <enh@google.com> Add fallocate/fallocate64/posix_fallocate/posix_fallocate64.

Bug: 5287571
Bug: 12612860
Change-Id: I4501b9c6cdf9a830336ce0b3afc4ea716b6a0f6f
egacy_32_bit_support.cpp
osix_fallocate.cpp
46f3db6bb81b3368783ea3748df46c2d7d2f7b2f 31-Jan-2014 Chris Dearman <chris.dearman@imgtec.com> [MIPS] SA_RESTORER support is not needed for MIPS

Change-Id: I1c000c94973e811193c80c9770da4f3157594f90
Signed-off-by: Chris Dearman <chris.dearman@imgtec.com>
Signed-off-by: Duane Sand <duane.sand@imgtec.com>
igaction.cpp
431166d99519f6794f10c48694913d2fe864b841 28-Jan-2014 Elliott Hughes <enh@google.com> Fix 32-bit mmap/mmap64 handling of negative offsets.

We don't actually need to worry about sign extension if we reject
negative values ourselves. Previously it was possible to come up
with negative but aligned values that we would pass to the kernel;
in the case of mmap (as opposed to mmap64) we'd incorrectly turn
those into large positive offsets.

Change-Id: I2aa583e0f892d59bb77429aea8730b72db32dcb0
map.cpp
af8aebebb52d73ea38c604525a6a5857618861cf 15-Jan-2014 Elliott Hughes <enh@google.com> Move _thread_created_hook to where it belongs.

Change-Id: I643d761c78ccaae25270aeffa2afb811c4e2fcd7
thread_create.cpp
trace.cpp
4e9cb032d1eab7ceaef47f4d5104d2c42d556ce2 09-Jan-2014 JP Abgrall <jpa@google.com> Add extra libc stubs for mntent related functions.

This adds stubs for setmntent() and endmntent().

Change-Id: I6ccaa044145405cd7226c1c54a25d435c96a2308
tubs.cpp
0f461e35f63200641fc53bba222845a84589c024 09-Jan-2014 Elliott Hughes <enh@google.com> Fix <sys/resource.h>.

The situation here is a bit confusing. On 64-bit, rlimit and rlimit64 are
the same, and so getrlimit/getrlimit64, setrlimit/setrlimit64,
and prlimit/prlimit64 are all the same. On 32-bit, rlimit and rlimit64 are
different. 32-bit architectures other than MIPS go one step further by having
an even more limited getrlimit system call, so arm and x86 need to use
ugetrlimit instead of getrlimit. Worse, the 32-bit architectures don't have
64-bit getrlimit- and setrlimit-equivalent system calls, and you have to use
prlimit64 instead. There's no 32-bit prlimit system call, so there's no
easy implementation of that --- what should we do if the result of prlimit64
won't fit in a struct rlimit? Since 32-bit survived without prlimit/prlimit64
for this long, I'm not going to bother implementing prlimit for 32-bit.

We need the rlimit64 functions to be able to build strace 4.8 out of the box.

Change-Id: I1903d913b23016a2fc3b9f452885ac730d71e001
egacy_32_bit_support.cpp
887e1140fe7596fa1239a0bc802d2cdb51c57d3c 02-Jan-2014 Elliott Hughes <enh@google.com> Clean up <sched.h>.

This patch switches to using the uapi constants. It also adds the missing
setns system call, fixes sched_getcpu's error behavior, and fixes the
gensyscalls script now ARM is uapi-only too.

Change-Id: I8e16b1693d6d32cd9b8499e46b5d8b0a50bc4f1d
ched_getcpu.c
ched_getcpu.cpp
2aace21a19b6be8f6a427fc664d4175f0bf832c9 22-Dec-2013 Elliott Hughes <enh@google.com> Remove the bogus exit status from _exit_with_stack_teardown.

It should always be 0, and there's no reason to pass a constant in as
an argument.

Change-Id: I92ac59b718a18e298bd7c52821af447f9181ca2a
thread_exit.cpp
99868904feeac944a0d482a2994f9d7b6828bff2 21-Dec-2013 Elliott Hughes <enh@google.com> Avoid sign extension in 32-bit mmap.

Change-Id: I2a77925f62f381a0b34648c3db8154a55dd80c46
map.cpp
5eccb9646dd94438911706d3ebf52775caa7f41e 21-Dec-2013 Elliott Hughes <enh@google.com> Fix aarch64 futex assembly routines.

Also make the other architectures more similar to one another,
use NULL instead of 0 in calling code, and remove an unused #define.

Change-Id: I52b874afb6a351c802f201a0625e484df6d093bb
ystem_properties.c
ystem_properties_compat.c
5e26221a1da6bc0f11819078e74f1f6e0b76f642 20-Dec-2013 Greg Hackmann <ghackmann@google.com> Merge "Fix backwards compatible system property structure"
17cabe15d52528255829c9cff53a26bf4b3db61e 20-Dec-2013 Elliott Hughes <enh@google.com> Don't force O_LARGEFILE on LP64.

aarch64's strace is confused by this, and it isn't necessary anyway.

Change-Id: Ib07b649eb1c38ff0296003874f73af78c47bc276
pen.cpp
9a42eef8b19005757db1cd5f39e25c27b664667b 19-Dec-2013 Elliott Hughes <enh@google.com> Revert "Add C linkage for __open_2 and __openat_2."

This reverts commit c13d89b829a83a248130184583cf0332515a05df.

Change-Id: I40a3c6b926e920b65dd054353a2db8d314d5b300
pen.cpp
c13d89b829a83a248130184583cf0332515a05df 19-Dec-2013 Ben Cheng <bccheng@google.com> Add C linkage for __open_2 and __openat_2.

Otherwise Clang mangle them with C++ names.

Change-Id: I844e28d834df8b0752b32d2aadd2013fc8804a43
pen.cpp
e4c6b08c4e81f640afc502804d1226a3e79dc26d 19-Dec-2013 Nick Kralevich <nnk@google.com> Clean up more recursive FORTIFY_SOURCE calls

Don't use FORTIFY_SOURCE on functions which implement
FORTIFY_SOURCE, to avoid infinite recursion problems.

The previous patch only addressed one of the problems.

Bug: 12216860
Change-Id: I6f30ae7cb5b481be9942add18182ea4839d348a6
_fgets_chk.cpp
_memmove_chk.cpp
_memset_chk.cpp
_strlcat_chk.cpp
_strlcpy_chk.cpp
_strncpy_chk.cpp
_vsnprintf_chk.cpp
_vsprintf_chk.cpp
ddea38343311b66ae023473a342c11824f6a8f65 19-Dec-2013 Nick Kralevich <nnk@google.com> __strnlen_chk: avoid recursive strlen calls

Don't use FORTIFY_SOURCE on functions which implement
FORTIFY_SOURCE.

Bug: 12216860
Change-Id: I61db1b47ccdd6bdcf41eab3303f4806494016199
_strlen_chk.cpp
9e79af3b61b5a617c537862ebe72248beff58f19 18-Dec-2013 Elliott Hughes <enh@google.com> Small style cleanup.

Change-Id: Ib45a4a2296232968296f9bd7cc3592ba46fd412d
thread_cond.cpp
thread_mutex.cpp
611b903ca7ba9d604a9e2ebc1efa5a66f7ccc049 18-Dec-2013 Elliott Hughes <enh@google.com> Merge "Properly detect timeout in pthread_mutex_lock_timeout_np_impl"
e7c59f9e2041812c597ff1c8689d47d1bfd32883 18-Dec-2013 Elliott Hughes <enh@google.com> Fix compilation of crtbegin.c and pthread_debug.cpp.

Because there was no default := for the aarch64 libc_crt_target_cflags,
the += was causing libc_crt_target_cflags to be recursively-defined
variable, which meant that when we were compiling crtbegin.c LOCAL_PATH
would be bionic/tests/ and we'd have -Ibionic/tests/include/ and find
none of our include files.

Also fix linking of pthread_debug.cpp, at least in the disabled mode.
The enabled mode was already broken for all architectures, and continues
to be broken after this change. It's been broken for long enough that
we might want to just remove it...

(aarch64 is using the FSF linker where arm uses the gold linker.)

Change-Id: I7db2e386694f6933db043138e6e97e5ae54d4174
thread_debug.cpp
4fae14f3335375714be3104742fa69fe65b02001 17-Dec-2013 Ken Mixter <kmixter@google.com> Properly detect timeout in pthread_mutex_lock_timeout_np_impl

Previously we were checking against a positive errno which
would not be returned from a system call.

Change-Id: I8e3a36f6fbf5ccc2191a152a1def37e2d6f93124
thread_mutex.cpp
063a572e6bc958746031ad5cc4d4f9622c5d6ad3 13-Dec-2013 Joshua J. Drake <android-open-source@qoop.org> Fix backwards compatible system property structure

The original structure included four reserved 32-bit values. This
change adds these back into the structure so that the
__system_property_find_compat function will (again) process the system
properties correctly.
ystem_properties_compat.c
dff7203ee99ccac446b9a1c4371753a5216c6db4 11-Dec-2013 Elliott Hughes <enh@google.com> Remove harmful attempts to be helpful in pthread_mutex functions.

Most callers won't check for EINVAL, so it's best to fail early.
GCC takes the nonnull attribute as a guarantee that an argument
won't be NULL, so these hacks were already ineffective, which is
how we found that at least one commercial game was using NULL
as if it's a mutex, but actually getting no-op behavior.

Bug: 11971278
Change-Id: I89646e043d931778805a8b692e07a34d076ee6bf
thread_mutex.cpp
960ee37f2aaf52bbec2f6265fd6e30fb2b41fef3 11-Dec-2013 Elliott Hughes <enh@google.com> Clarify a comment.

Change-Id: Iad2e33fb059170f808023ce3d17e9b8c13191f42
thread_exit.cpp
101fb7d963ed362c4e351d95e55cbd70dc59eac3 07-Dec-2013 Christopher Ferris <cferris@google.com> Do not clear tids on detached threads.

Make sure that the kernel isn't going to try and clear the tid of
freed memory.

Bug: 11963327
Change-Id: I95d02340bfbe92f56036d2cc58dbf0e3079eb7c3
thread_exit.cpp
80906141f79be8be63fc915bfab467029b442ca1 26-Nov-2013 Elliott Hughes <enh@google.com> Work around CLONE_SETTLS being weird on x86.

Unlike other architectures, on x86 (but not x86-64), CLONE_SETTLS
takes a pointer to a struct user_desc instead of a pointer to the
TLS itself. Rather than have to deal with this here, let's just use
the old __set_tls mechanism we used to use (and still use for the
main thread on all architectures, so it's not going away any time
soon).

Bug: 11826724
Change-Id: I02a27939a73ae6cea1134a3f4c1dd7eafea479da
thread_create.cpp
f00c938c7f5887981d724bf2dd9989ee0af08332 22-Nov-2013 The Android Open Source Project <initial-contribution@android.com> Merge commit '811b0cdb2d6e4a697dbc63a678712759dd0db242' into HEAD

Change-Id: I786944f80fb1a2d502fed51dc2c391ed5db66761
ab61eb366ac48addf2bca6093a34455193f5c8df 21-Nov-2013 Elliott Hughes <enh@google.com> Switch to upstream sleep(3) and usleep(3).

Also fix the signature of usleep, and the definition of useconds_t which
should be unsigned, as the 'u' in its name implies.

This patch also cleans up the existing FreeBSD hacks by moving the libm
stuff from <sys/cdefs.h> to a libm-private header, and adding comments
about the hacks we use to build FreeBSD source.

Change-Id: Ibe5067a380502df94a0a3a7901969b35411085b6
leep.c
sleep.c
cef3faec0ea40fdfe58e425fd0be64f00de6a26d 20-Nov-2013 Elliott Hughes <enh@google.com> Clean up pthread_internal_t.

Bug: 11755300
Change-Id: Ib509e8c5ec6b23513aa78b5ac5141d7c34ce2dc8
ibc_init_common.cpp
thread_create.cpp
thread_internal.h
thread_internals.cpp
36d6188f8cd8b948fb797f11d9620d63d0c2215a 19-Nov-2013 Elliott Hughes <enh@google.com> Clean up forking and cloning.

The kernel now maintains the pthread_internal_t::tid field for us,
and __clone was only used in one place so let's inline it so we don't
have to leave such a dangerous function lying around. Also rename
files to match their content and remove some useless #includes.

Change-Id: I24299fb4a940e394de75f864ee36fdabbd9438f9
ionic_clone.c
lone.cpp
ork.cpp
thread_cond.cpp
thread_internal.h
thread_internals.cpp
thread_mutex.cpp
877ec6d90418ff1d6597147d355a2229fdffae7e 16-Nov-2013 Elliott Hughes <enh@google.com> Fix pthread_join.

Let the kernel keep pthread_internal_t::tid updated, including
across forks and for the main thread. This then lets us fix
pthread_join to only return after the thread has really exited.

Also fix the thread attributes of the main thread so we don't
unmap the main thread's stack (which is really owned by the
dynamic linker and contains things like environment variables),
which fixes crashes when joining with an exited main thread
and also fixes problems reported publicly with accessing environment
variables after the main thread exits (for which I've added a new
unit test).

In passing I also fixed a bug where if the clone(2) inside
pthread_create(3) fails, we'd unmap the child's stack and TLS (which
contains the mutex) and then try to unlock the mutex. Boom! It wasn't
until after I'd uploaded the fix for this that I came across a new
public bug reporting this exact failure.

Bug: 8206355
Bug: 11693195
Bug: https://code.google.com/p/android/issues/detail?id=57421
Bug: https://code.google.com/p/android/issues/detail?id=62392
Change-Id: I2af9cf6e8ae510a67256ad93cad891794ed0580b
ork.cpp
ibc_init_common.cpp
thread_create.cpp
thread_exit.cpp
thread_internal.h
thread_join.cpp
thread_key.cpp
e48b68570d872ef7ece1d873c0ea298ea76393f3 15-Nov-2013 Elliott Hughes <enh@google.com> Clean up the pthread_create trampoline.

Bug: 8206355
Bug: 11693195
Change-Id: I35cc024d5b6ebd19d1d2e45610db185addaf45df
_thread_entry.cpp
thread_create.cpp
thread_internal.h
thread_key.cpp
70b24b1cc2a1a4436b1fea3f8b76616fdcb27224 15-Nov-2013 Elliott Hughes <enh@google.com> Switch pthread_create over to __bionic_clone.

Bug: 8206355
Bug: 11693195
Change-Id: I04aadbc36c87e1b7e33324b9a930a1e441fbfed6
_thread_entry.cpp
ionic_clone.c
ibc_init_common.cpp
thread_create.cpp
thread_internal.h
61fb3fc770566c7bafe7af8fb93590bcad387fbb 07-Nov-2013 Elliott Hughes <enh@google.com> Prepare to switch to the uapi <linux/signal.h>.

<time.h> didn't need to copy the cruft from <signal.h>, and
<signal.h> only needs the uid_t hack when it's not using
uapi headers.

pthread_exit.cpp should include what it uses.

Change-Id: I836c36abe0f0a781d41fc425b249d1c7686bb124
thread_exit.cpp
7250d2e5b4cd4af7cd802ae04b9b77d97f3a5a45 07-Nov-2013 Elliott Hughes <enh@google.com> Remove pathconf's dependencies on non-uapi header files.

Change-Id: I597996e4b141b009916f7ad2866dd100e08aa4d3
athconf.c
062092543fdbd6fa2676e4f5b37a15f7bba94332 07-Nov-2013 Elliott Hughes <enh@google.com> Clean up the 32-bit kernel support, fix LP64 fcntl declaration.

In practice, thanks to all the registers the stubs don't actually change,
but it's confusing to have an incorrect declaration.

I suspect that fcntl remains broken for aarch64; it happens to work for
x86_64 because the first vararg argument gets placed in the right register
anyway, but I have no reason to believe that's true for aarch64.

This patch adds a unit test, though, so we'll be able to tell when we get
as far as running the unit tests.

Change-Id: I58dd0054fe99d7d51d04c22781d8965dff1afbf3
_get_tls.cpp
cntl.c
statfs.c
egacy_32_bit_support.cpp
seek64.c
dk_cruft.cpp
read.c
write.c
tatfs.c
6fa79c5cf57a3a7bc37849d0d510bf8cb043b531 05-Nov-2013 Elliott Hughes <enh@google.com> Remove unnecessary #include.

Change-Id: I99dade0b3803272ee29eba2ad36b0311f8a24c31
imer.cpp
66759d6041b33706c3a92dde48492ba4f2bbab2f 31-Oct-2013 Elliott Hughes <enh@google.com> Move the pthread debugging flags to the right place.

Change-Id: Ie805bd837d1f72cdf1818e056c0baeb0857e4e84
thread_mutex.cpp
c3f114037dbf028896310609fd28cf2b3da99c4d 30-Oct-2013 Elliott Hughes <enh@google.com> <pthread.h> fixes and pthread cleanup.

<pthread.h> was missing nonnull attributes, noreturn on pthread_exit,
and had incorrect cv qualifiers for several standard functions.

I've also marked the non-standard stuff (where I count glibc rather
than POSIX as "standard") so we can revisit this cruft for LP64 and
try to ensure we're compatible with glibc.

I've also broken out the pthread_cond* functions into a new file.

I've made the remaining pthread files (plus ptrace) part of the bionic code
and fixed all the warnings.

I've added a few more smoke tests for chunks of untested pthread functionality.

We no longer need the libc_static_common_src_files hack for any of the
pthread implementation because we long since stripped out the rest of
the armv5 support, and this hack was just to ensure that __get_tls in libc.a
went via the kernel if necessary.

This patch also finishes the job of breaking up the pthread.c monolith, and
adds a handful of new tests.

Change-Id: Idc0ae7f5d8aa65989598acd4c01a874fe21582c7
thread-atfork.c
thread-rwlocks.c
thread-timers.c
thread.c
thread_atfork.cpp
thread_attr.cpp
thread_cond.cpp
thread_create.cpp
thread_exit.cpp
thread_internal.h
thread_internals.cpp
thread_mutex.cpp
thread_once.cpp
thread_rwlock.cpp
thread_setschedparam.cpp
trace.c
trace.cpp
hread_atexit.c
hread_atexit.cpp
imer.cpp
2b6e43e00ece68b3aba26d8f95f07cd9d9294ab4 30-Oct-2013 Elliott Hughes <enh@google.com> Explain the sigprocmask in pthread_exit.

Also remove the SIGSEGV special case, which was probably because
hand-written __exit_with_stack_teardown stubs used to try to cause
SIGSEGV if the exit system call returned (which it never does, so
that dead code disappeared).

Also move the sigprocmask into the only case where it's necessary ---
the one where we unmap the stack that would be used by a signal
handler.

Change-Id: Ie40d20c1ae2f5e7125131b6b492cba7a2c6d08e9
thread.c
thread_create.cpp
thread_internal.h
27586ebe1a7f2f45651b855a26b3203d63d015d6 28-Oct-2013 Elliott Hughes <enh@google.com> Fix utime/utimes when passed a NULL pointer.

Bug: 11383777
Change-Id: If944a42f3adfa8a6ce91c167c249e009ed63300a
times.cpp
6b53c2349a5a3fc70a475de6a66131b615e88e48 25-Oct-2013 Elliott Hughes <enh@google.com> Fix the exit syscall stub's name.

I've left the exit_group syscall as _exit because otherwise we'd have to
convince the compiler that our _exit (which just calls __exit_group) is
actually "noreturn", and it seems like that would be less clean than just
cutting out the middleman.

We'll just have to trust ourselves not to add anything to SYSCALLS.TXT
that ought to be private but that only has a single leading underscore.
Hopefully we can manage that.

Change-Id: Iac47faea9f516186e1774381846c54cafabc4354
ionic_clone.c
thread.c
567a8de3ca5b4c4f033bfbcdd339a3fd59a76227 25-Oct-2013 Elliott Hughes <enh@google.com> Start moving 32-bit cruft somewhere it won't pollute 64-bit.

Change-Id: I03a6a50a5243f29e50fb58a3cf8b5e7198640baa
dk_cruft.cpp
tubs.cpp
ait.cpp
bf425680e484486803bf21e4c4cd1e3f36614a3c 25-Oct-2013 Elliott Hughes <enh@google.com> Let the compiler worry about implementing ffs(3).

It does at least as good a job as our old hand-written assembly anyway.

Change-Id: If7c4a1ac508bace0b71ee7b67808caa6eabf11d2
fs.cpp
11952073af22568bba0b661f7a9d4402c443a888 25-Oct-2013 Elliott Hughes <enh@google.com> Remove dependencies on obsolete __ARCH_WANT_SYSCALL_DEPRECATED system calls.

(aarch64 kernels don't have these system calls.)

Change-Id: I6f64075aa412f71520f2df71c3d69b647f91c1ca
ionic_time_conversions.cpp
poll_pwait.cpp
poll_wait.cpp
ork.cpp
ause.cpp
oll.cpp
select.c
thread.c
times.cpp
ait.cpp
cac7b9d6ec1a09814bc028e2f768db732f018891 23-Oct-2013 Elliott Hughes <enh@google.com> Remove dependencies on obsolete __ARCH_WANT_SYSCALL_NO_FLAGS syscalls.

(aarch64 kernels only have the newer system calls.)

Also expose the new functionality that's exposed by glibc in our header files.

Change-Id: I45d2d168a03f88723d1f7fbf634701006a4843c5
up2.cpp
poll_create.cpp
notify_init.cpp
ipe.cpp
f8fcfbc85a3ce3e195626b90736d3a484331494b 22-Oct-2013 Elliott Hughes <enh@google.com> Move away from the __ARCH_WANT_SYSCALL_NO_AT system calls.

Modern architectures only get the *at(2) system calls. For example,
aarch64 doesn't have open(2), and expects userspace to use openat(2)
instead.

Change-Id: I87b4ed79790cb8a80844f5544ac1a13fda26c7b5
ccess.cpp
hmod.cpp
hown.cpp
chown.cpp
ink.cpp
stat.cpp
kdir.cpp
knod.cpp
pen.c
pen.cpp
penat.c
eadlink.cpp
ename.cpp
mdir.cpp
tat.cpp
ymlink.cpp
nlink.cpp
times.cpp
8c39e58b6a6744c5e7ae08424a6281d75af23072 22-Oct-2013 Elliott Hughes <enh@google.com> Merge "Make sure we have a mkfifo symbol."
594b1a4af204aa9de2b4913182f4556e38d71648 22-Oct-2013 Elliott Hughes <enh@google.com> Make sure we have a mkfifo symbol.

Bug: https://code.google.com/p/android/issues/detail?id=58888
Change-Id: Ic0a883a5f30beb82cb7be3c4e81b6d693d5fbb4d
kfifo.cpp
7f70c9b64eec4a4a86a3948966187ff8ee9fa720 13-Oct-2013 Serban Constantinescu <serban.constantinescu@arm.com> AArch64: Fix uses of stack size for 32/64bit libc builds

This patch fixes stack size uses to size_t.

Change-Id: I0671c85ddb1c1aceaf9440a7c73c21fe528653fa
Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
ibc_init_common.cpp
thread.c
c7e9b2331771e5e87c34a8ee3dc6cc41d35b02fe 17-Oct-2013 Elliott Hughes <enh@google.com> Fix sigaction(3) for 64-bit.

Also clean up <signal.h> and revert the hacks that were necessary
for 64-bit in linker/debugger.cpp until now.

Change-Id: I3b0554ca8a49ee1c97cda086ce2c1954ebc11892
igaction.cpp
igaddset.cpp
igdelset.cpp
igemptyset.cpp
igfillset.cpp
igismember.cpp
ignal.c
ignal.cpp
6b9321b85875dd8938d0a5064ea3e9fdebe5c623 17-Oct-2013 Elliott Hughes <enh@google.com> am d6e117b6: am 1f29c2f5: Merge "Switch sigpending over to rt_sigpending."

* commit 'd6e117b64bdfbf8d793eb59ea9604b806608ec75':
Switch sigpending over to rt_sigpending.
40d105ccb3e6283566ce54b693b3088f31aa4f26 16-Oct-2013 Elliott Hughes <enh@google.com> Switch sigpending over to rt_sigpending.

Change-Id: I7b28984796b5fb343cfbcc47e0afc3a84293d417
igpending.cpp
afaebc3fefe93cbfbaead60212dab7b99bae9d7a 16-Oct-2013 Elliott Hughes <enh@google.com> am 87fc78de: am 608c65f6: Merge "Fix sigsuspend to use rt_sigsuspend on all platforms."

* commit '87fc78de6c869d0403ccdd2e756ec1f5d456f3d3':
Fix sigsuspend to use rt_sigsuspend on all platforms.
1f5af926fa626734981d6b4dcc0ab54e520032a9 16-Oct-2013 Elliott Hughes <enh@google.com> Fix sigsuspend to use rt_sigsuspend on all platforms.

Change-Id: I981c1a66d35480d4457a0a08a1b042dac94daa5b
ignalfd.cpp
igsuspend.c
igsuspend.cpp
igwait.cpp
f2a760dca7e728bd6f7942dece1bb6aefe4821ed 16-Oct-2013 Elliott Hughes <enh@google.com> am a85606e1: am c100a100: Merge "\'Avoid confusing "read prevented write" log messages\' 2."

* commit 'a85606e1563c2153bea3c73dfe4ca1588e778f22':
'Avoid confusing "read prevented write" log messages' 2.
68b67113a44311b3568027af5893e316f63ec556 16-Oct-2013 Elliott Hughes <enh@google.com> 'Avoid confusing "read prevented write" log messages' 2.

This time it's assembler.

Change-Id: Iae6369833b8046b8eda70238bb4ed0cae64269ea
_vsnprintf_chk.cpp
_vsprintf_chk.cpp
cbfa1afda32e290ddc9c9bea866c27ae93d040d2 16-Oct-2013 Elliott Hughes <enh@google.com> am 0287db52: am d9913b0b: Merge "Make pthread_create report sched_setscheduler failures on LP64."

* commit '0287db52ed93df39ab45c7f60a241ae621866b90':
Make pthread_create report sched_setscheduler failures on LP64.
d9913b0b0dfad473bd1cb81463ac0d6b68a0deb6 16-Oct-2013 Elliott Hughes <enh@google.com> Merge "Make pthread_create report sched_setscheduler failures on LP64."
df17ce7858f8df22a14412fa18ee5b80fa6b283e 16-Oct-2013 Elliott Hughes <enh@google.com> am 26491483: am 76725214: Merge "Avoid confusing "read prevented write" log messages."

* commit '264914838d1c22c15ed0069d1217a780835c6d1c':
Avoid confusing "read prevented write" log messages.
b01ebe6d4e76cd57dac09e6bdb581f8f964cd75f 16-Oct-2013 Elliott Hughes <enh@google.com> am 14e7482c: am d16391bb: Merge "Fix indentation in sched_getaffinity."

* commit '14e7482c556820d8ad3b77f025dfc465d55c7262':
Fix indentation in sched_getaffinity.
7672521440c8b7f98795c3fb4295227398e3e296 16-Oct-2013 Elliott Hughes <enh@google.com> Merge "Avoid confusing "read prevented write" log messages."
98624c374646a050556bdc402b55b792fefa7e55 16-Oct-2013 Elliott Hughes <enh@google.com> Make pthread_create report sched_setscheduler failures on LP64.

We couldn't fix this for 32-bit because there's too much broken
code out there. (Pretty much everyone asks for real-time
scheduling for all their threads, and the kernel says "don't be
stupid".)

Change-Id: I43c5271e6b6bb91278b9a19eec08cbf05391e3c4
thread_create.cpp
0cfc95e0106acf6e3bff35e28e9addc76b3e0aaa 16-Oct-2013 Elliott Hughes <enh@google.com> Fix indentation in sched_getaffinity.

Change-Id: I966852149a0255ca132cd7a15f135a875ce400d0
ched_getaffinity.cpp
d1eda33f012e46083b91e087fb79d14a5ce70f0e 16-Oct-2013 Elliott Hughes <enh@google.com> Avoid confusing "read prevented write" log messages.

Moving to a "function: message" style avoids ambiguity.

Change-Id: If9d590e50265c61725d3673bd03796e65edd2d5e
_FD_chk.cpp
_fgets_chk.cpp
_memcpy_chk.cpp
_memmove_chk.cpp
_memset_chk.cpp
_read_chk.cpp
_recvfrom_chk.cpp
_strcat_chk.cpp
_strchr_chk.cpp
_strcpy_chk.cpp
_strlcat_chk.cpp
_strlcpy_chk.cpp
_strlen_chk.cpp
_strncat_chk.cpp
_strncpy_chk.cpp
_strrchr_chk.cpp
_umask_chk.cpp
_vsnprintf_chk.cpp
_vsprintf_chk.cpp
ibc_logging.cpp
pen.c
penat.c
4681f8244ee6fd3aec5a5c62e604e2a429d0d00f 15-Oct-2013 Elliott Hughes <enh@google.com> am 5b3f1d8b: am 22b83da4: Merge "Clean up the sigprocmask/pthread_sigmask implementation."

* commit '5b3f1d8b3a6a1caf059dc376e4967a27ddd57dac':
Clean up the sigprocmask/pthread_sigmask implementation.
19e62325c268a668692e2b65fde2284079f369aa 15-Oct-2013 Elliott Hughes <enh@google.com> Clean up the sigprocmask/pthread_sigmask implementation.

Let's have both use rt_sigprocmask, like in glibc. The 64-bit ABIs
can share the same code as the 32-bit ABIs.

Also, let's test the return side of these calls, not just the
setting.

Bug: 11069919
Change-Id: I11da99f85b5b481870943c520d05ec929b15eddb
thread_sigmask.cpp
igprocmask.cpp
49bb53c8e20ff37a1965ba4af645464ea4b8f8fa 10-Oct-2013 Nick Kralevich <nnk@google.com> am 95de0df8: am eda2679e: Merge "FORTIFY_SOURCE: fortify read()"

* commit '95de0df8c2daeefca358010f2d15c3346a5284f1':
FORTIFY_SOURCE: fortify read()
2d38f0c1c7ccb123a9a71dcabeb3650d8f5832b7 10-Oct-2013 Elliott Hughes <enh@google.com> am 21d70d5f: am 39385aa7: Merge "Clean up the cpuacct cruft."

* commit '21d70d5fd8ff2823a6879d59c7d5a8d6c3e0ce8b':
Clean up the cpuacct cruft.
eda2679e30b997d036e0ec572cda054adc2ac3a6 10-Oct-2013 Nick Kralevich <nnk@google.com> Merge "FORTIFY_SOURCE: fortify read()"
b036b5ca36c1e12b075909b3eca6eab73ee611cf 10-Oct-2013 Nick Kralevich <nnk@google.com> FORTIFY_SOURCE: fortify read()

Change-Id: Ic7de163fe121db13e00560adb257331bc709814d
_read_chk.cpp
232163cf70712fe00436b70dd495f4cf405e9eab 10-Oct-2013 Elliott Hughes <enh@google.com> Clean up the cpuacct cruft.

Change-Id: I6ed63af8dfc2368e211420389fa8af4d5dc0908f
puacct.c
puacct.h
ork.c
ork.cpp
etegid.c
etegid.cpp
eteuid.c
eteuid.cpp
etresuid.c
etreuid.c
etuid.c
b8771d9fd844fd28b6e5e6fe429ef40c097b32a6 10-Oct-2013 Nick Kralevich <nnk@google.com> am b35ebe3d: am 848efa9d: Merge "Revert "FORTIFY_SOURCE: fortify read()""

* commit 'b35ebe3d7097899fd4498ebb2b93e48fd836ebcf':
Revert "FORTIFY_SOURCE: fortify read()"
8d2532763981d132b02df157e4cc363c39330090 10-Oct-2013 Nick Kralevich <nnk@google.com> Revert "FORTIFY_SOURCE: fortify read()"

This change reverts
* fb3f956d075676c0438f2ee2bf3a5be659dfc04b.
* 65c99de2cb7a569ea17ca35e2f8f1e033421864b

Change-Id: Id5774eeede41130579115cf67a72ee914f2b47d5
_read_chk.cpp
6b6c5791a00ff2b5577e906a070d1d69e8b52f4b 10-Oct-2013 Elliott Hughes <enh@google.com> am aa3c17e8: am 37953ee3: Merge "Fix build."

* commit 'aa3c17e8f8b9b3b5b8dc3c7c0fbe85b774f83722':
Fix build.
1cdc9fe6d58b477385de0f60725a355de2151706 10-Oct-2013 Elliott Hughes <enh@google.com> am 8826ba8a: am bc545e8a: Merge "Fix x86_64 build, clean up intermediate libraries."

* commit '8826ba8ab6922927bdac2466d2903916d5806a06':
Fix x86_64 build, clean up intermediate libraries.
45e3076cdc03efe7d37178fbd4366d5632d50cba 10-Oct-2013 Nick Kralevich <nnk@google.com> am 731ced6b: am c147478c: Merge "FORTIFY_SOURCE: fortify read()"

* commit '731ced6b289629a552b5841561fdcccf08d8c43a':
FORTIFY_SOURCE: fortify read()
fb3f956d075676c0438f2ee2bf3a5be659dfc04b 10-Oct-2013 Elliott Hughes <enh@google.com> Fix build.

'private' is no longer on the default include path inside bionic.

Change-Id: I9bfab213a496fac585787118603af3aa2a1f9951
_read_chk.cpp
bc545e8a98dd4e1148e8b9c9ca491d1a481ee94d 10-Oct-2013 Elliott Hughes <enh@google.com> Merge "Fix x86_64 build, clean up intermediate libraries."
c147478cb75cfaa2aadc67fd920e8765503d97cc 10-Oct-2013 Nick Kralevich <nnk@google.com> Merge "FORTIFY_SOURCE: fortify read()"
eb847bc8666842a3cfc9c06e8458ad1abebebaf0 10-Oct-2013 Elliott Hughes <enh@google.com> Fix x86_64 build, clean up intermediate libraries.

The x86_64 build was failing because clone.S had a call to __thread_entry which
was being added to a different intermediate .a on the way to making libc.so,
and the linker couldn't guarantee statically that such a relocation would be
possible.

ld: error: out/target/product/generic_x86_64/obj/STATIC_LIBRARIES/libc_common_intermediates/libc_common.a(clone.o): requires dynamic R_X86_64_PC32 reloc against '__thread_entry' which may overflow at runtime; recompile with -fPIC

This patch addresses that by ensuring that the caller and callee end up in the
same intermediate .a. While I'm here, I've tried to clean up some of the mess
that led to this situation too. In particular, this removes libc/private/ from
the default include path (except for the DNS code), and splits out the DNS
code into its own library (since it's a weird special case of upstream NetBSD
code that's diverged so heavily it's unlikely ever to get back in sync).

There's more cleanup of the DNS situation possible, but this is definitely a
step in the right direction, and it's more than enough to get x86_64 building
cleanly.

Change-Id: I00425a7245b7a2573df16cc38798187d0729e7c4
_FD_chk.cpp
_errno.cpp
_fgets_chk.cpp
_memcpy_chk.cpp
_memmove_chk.cpp
_memset_chk.cpp
_recvfrom_chk.cpp
_stack_chk_fail.cpp
_strcat_chk.cpp
_strchr_chk.cpp
_strcpy_chk.cpp
_strlcat_chk.cpp
_strlcpy_chk.cpp
_strlen_chk.cpp
_strncat_chk.cpp
_strncpy_chk.cpp
_strrchr_chk.cpp
_thread_entry.cpp
_umask_chk.cpp
_vsnprintf_chk.cpp
_vsprintf_chk.cpp
rc4random.c
ssert.cpp
puacct.h
ebug_stacktrace.cpp
ork.c
ibc_init_common.cpp
ibc_init_dynamic.cpp
ibc_init_static.cpp
ibc_logging.cpp
ibgen.cpp
alloc_debug_check.cpp
alloc_debug_common.cpp
alloc_debug_common.h
alloc_debug_leak.cpp
alloc_debug_qemu.cpp
pen.c
penat.c
thread.c
thread_create.cpp
thread_debug.cpp
thread_getschedparam.cpp
thread_internal.h
thread_internals.cpp
thread_key.cpp
thread_kill.cpp
thread_setschedparam.cpp
emaphore.c
trerror.cpp
trsignal.cpp
ysconf.cpp
ystem_properties.c
ac045c32d067d61cb48370eaa10118e827ebf586 09-Oct-2013 Elliott Hughes <enh@google.com> am f83148af: am 0c17099a: Merge "Fix __errno for LP64 and clean up __get_tls."

* commit 'f83148af74704c574ad1bf60082f2f56bcb29706':
Fix __errno for LP64 and clean up __get_tls.
65c99de2cb7a569ea17ca35e2f8f1e033421864b 09-Oct-2013 Nick Kralevich <nnk@google.com> FORTIFY_SOURCE: fortify read()

Change-Id: I3d7b4ec86d04efb865117ce7629a2e26917f3331
_read_chk.cpp
2a0b873065edb304fa2d1c54f8de663ea638b8ab 09-Oct-2013 Elliott Hughes <enh@google.com> Fix __errno for LP64 and clean up __get_tls.

If __get_tls has the right type, a lot of confusing casting can disappear.

It was probably a mistake that __get_tls was exposed as a function for mips
and x86 (but not arm), so let's (a) ensure that the __get_tls function
always matches the macro, (b) that we have the function for arm too, and
(c) that we don't have the function for any 64-bit architecture.

Change-Id: Ie9cb989b66e2006524ad7733eb6e1a65055463be
_errno.c
_errno.cpp
_get_tls.cpp
ibc_init_dynamic.cpp
thread_create.cpp
thread_internals.cpp
thread_key.cpp
e17457fbf5d02ca152692f3da8d10d1243fadb11 09-Oct-2013 Elliott Hughes <enh@google.com> am 3c13dade: am 14b66bff: Merge "Fix malloc debugging for LP64."

* commit '3c13daded375cad5fc77613872a85639cd09f54f':
Fix malloc debugging for LP64.
8cc98f0b1e15d9668cfb4eaff10f97e465a2fc21 09-Oct-2013 Elliott Hughes <enh@google.com> am 54c7ef7f: am 7027841d: Merge "Fix bionic\'s built-in stack trace dumping for LP64."

* commit '54c7ef7fbd1f79ae490eb737f558fccf3c1dbd55':
Fix bionic's built-in stack trace dumping for LP64.
14b66bffb08d23ad16d69b62d1fbfda769db1c12 09-Oct-2013 Elliott Hughes <enh@google.com> Merge "Fix malloc debugging for LP64."
c7c5f85ead6a58eadd511c728a9020a493bc128f 09-Oct-2013 Elliott Hughes <enh@google.com> Fix bionic's built-in stack trace dumping for LP64.

Change-Id: I967c5789d7bb2d3d248d94d81a40d5ec4e1bf26d
ebug_stacktrace.cpp
ef0696d46ac76b1a9eb9038027ef5872fe1f3507 09-Oct-2013 Elliott Hughes <enh@google.com> Fix malloc debugging for LP64.

Change-Id: Idd0b239f5c66d45de315d556271a5d13b8eb907c
alloc_debug_check.cpp
alloc_debug_qemu.cpp
42b618cffef4b91bd11633c3ee95659d4fc41943 09-Oct-2013 Elliott Hughes <enh@google.com> am 58b8f225: am 5cf1f229: Merge "pthread_exit should call __NR_exit with status 0."

* commit '58b8f2256637c5b1e24b568b699fb3aa6cf0ca96':
pthread_exit should call __NR_exit with status 0.
5cf1f229620d02c0ca266c9e03418fdeefd85191 09-Oct-2013 Elliott Hughes <enh@google.com> Merge "pthread_exit should call __NR_exit with status 0."
c4c6e192ac045c06f4aad3afc8e437baf67227b7 08-Oct-2013 Elliott Hughes <enh@google.com> pthread_exit should call __NR_exit with status 0.

We shouldn't have been passing the bottom 32 bits of the address used
for pthread_join to the kernel.

Change-Id: I487e5002d60c27adba51173719213abbee0f183f
ionic_clone.c
thread.c
6260fa5025fa4173700a6db70a244748acc5388a 08-Oct-2013 Elliott Hughes <enh@google.com> am ee9da565: am 58522099: Merge "Make logging fall back to /dev/stderr if we\'re on the host."

* commit 'ee9da5653361f0171e417a4bcb1958a2b91f886d':
Make logging fall back to /dev/stderr if we're on the host.
0f395b7ba056ccec3915737cfece81ca2161e980 08-Oct-2013 Elliott Hughes <enh@google.com> Make logging fall back to /dev/stderr if we're on the host.

Otherwise you get no logging, which sucks.

Change-Id: Iea1e8f996461afbb217a55711b7967005c39cfcb
ibc_logging.cpp
3fc57ce6fd6c412d019bd757733c9d4e7bb28d90 07-Oct-2013 Elliott Hughes <enh@google.com> am d8d60a92: am 04cdfa67: Merge "Clean up the x86 and x86_64 _exit_with_stack_teardown implementations."

* commit 'd8d60a92e7029ff8eeae5cbe62db94972e6cc06d':
Clean up the x86 and x86_64 _exit_with_stack_teardown implementations.
a97cc5b458048ddaa034489e4a4e55e9064aca2f 07-Oct-2013 Elliott Hughes <enh@google.com> Clean up the x86 and x86_64 _exit_with_stack_teardown implementations.

Change-Id: I4bcbbc53893612bd94643ef07722becb00f91792
thread.c
7909bd19ab471a087fc802a15ac11cc4e3bdc68e 04-Oct-2013 Nick Kralevich <nnk@google.com> am 9da8b682: am c417d0a5: Merge "Make error messages even better!"

* commit '9da8b6829cb8febb70af46761b7f2ca19e6498ce':
Make error messages even better!
6861c6f85e6563695c4763e56756398c9d5f6e14 04-Oct-2013 Nick Kralevich <nnk@google.com> Make error messages even better!

Change-Id: I72bd1eb1d526dc59833e5bc3c636171f7f9545af
_fgets_chk.cpp
_memcpy_chk.cpp
_memmove_chk.cpp
_memset_chk.cpp
_recvfrom_chk.cpp
_strcat_chk.cpp
_strchr_chk.cpp
_strcpy_chk.cpp
_strlcat_chk.cpp
_strlcpy_chk.cpp
_strlen_chk.cpp
_strncat_chk.cpp
_strncpy_chk.cpp
_strrchr_chk.cpp
_vsnprintf_chk.cpp
_vsprintf_chk.cpp
e0a14e7573892015181b9b7ae9be2ce13a5b3ca8 04-Oct-2013 Nick Kralevich <nnk@google.com> am ed1f8ea0: am bf452313: Merge "FORTIFY_SOURCE: emphasize prevention in error messages."

* commit 'ed1f8ea0369195aa0c3aa9926a94efa26fd14639':
FORTIFY_SOURCE: emphasize prevention in error messages.
9d3b4b48d87cb1f8a2ab41d3f5c431ce50418f94 04-Oct-2013 Elliott Hughes <enh@google.com> am 71e0b240: am 41ba05e2: Merge "x86_64: Fix get_tls and statvfs"

* commit '71e0b240ed980e77f736be2a27d255d64747b388':
x86_64: Fix get_tls and statvfs
e2617290fca2ebbc4d64cae5a8d8d9e9f8e6c701 04-Oct-2013 Nick Kralevich <nnk@google.com> FORTIFY_SOURCE: emphasize prevention in error messages.

FORTIFY_SOURCE prevents buffer overflows from occurring.
However, the error message often implies that we only
detect it, not prevent it.

Bring more clarity to the error messages by emphasizing
prevention over detection.

Change-Id: I5f3e1478673bdfc589e6cc4199fce8e52e197a24
_fgets_chk.cpp
_memcpy_chk.cpp
_memmove_chk.cpp
_memset_chk.cpp
_recvfrom_chk.cpp
_strcat_chk.cpp
_strchr_chk.cpp
_strcpy_chk.cpp
_strlcat_chk.cpp
_strlcpy_chk.cpp
_strlen_chk.cpp
_strncat_chk.cpp
_strncpy_chk.cpp
_strrchr_chk.cpp
_vsnprintf_chk.cpp
_vsprintf_chk.cpp
1e52a54a47c00af689b7d8d503c4d69e53ae26fc 20-Sep-2013 Pavel Chupin <pavel.v.chupin@intel.com> x86_64: Fix get_tls and statvfs

* bionic_tls.h - Add x86_64 version of get_tls macro;
* statvfs.h - 64-bit kernels don't have __statfs64/__fstatfs64, applying
workaround;

Change-Id: I20d7ddad74c7b7243866373d0142da6627c08280
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
tatvfs.cpp
2837f830685bfc52d1a843882bf6d04420213ed5 04-Oct-2013 Nick Kralevich <nnk@google.com> am 687c7e3e: am e8dc673c: Merge "Don\'t export unnecessary symbol."

* commit '687c7e3ece0f485c79654ca0c4da15b86b1f8a7f':
Don't export unnecessary symbol.
6f103689268a8f6c6177b9c17d72436776a27b22 04-Oct-2013 Nick Kralevich <nnk@google.com> am 2e819c58: am 2ff3c746: Merge "Check memory size on FD_* functions"

* commit '2e819c58c9396eec3e4311ef2c9bdcadd107f001':
Check memory size on FD_* functions
e8dc673ca56556389ad06ce1bb55e6624b4db721 04-Oct-2013 Nick Kralevich <nnk@google.com> Merge "Don't export unnecessary symbol."
7943df62f70f686b0c77532f6617b47255d75763 03-Oct-2013 Nick Kralevich <nnk@google.com> Check memory size on FD_* functions

Make sure the buffer we're dealing with has enough room.
Might as well check for memory issues while we're here,
even though I don't imagine they'll happen in practice.

Change-Id: I0ae1f0f06aca9ceb91e58c70183bb14e275b92b5
_FD_chk.cpp
35c1862cdfcd87b5ef6c59128b9993efffafe88b 03-Oct-2013 Nick Kralevich <nnk@google.com> Don't export unnecessary symbol.

Change-Id: I8b1d75a08476c41dd8e3f09fc93a3df617928f88
alloc_debug_common.cpp
5634373320d7dac30fa68feeb4d3b883566461ac 03-Oct-2013 Nick Kralevich <nnk@google.com> am 8598cd68: am f741e1c2: Merge "FORTIFY_SOURCE: Add __FD_* checks"

* commit '8598cd6888366008033286113bd633b44c70b7dd':
FORTIFY_SOURCE: Add __FD_* checks
90201d5eca050414d50a433866ccb580415bb0d4 03-Oct-2013 Nick Kralevich <nnk@google.com> FORTIFY_SOURCE: Add __FD_* checks

Add FORTIFY_SOURCE checks for the following macros:

* FD_CLR
* FD_ISSET
* FD_SET

Bug: 11047121
Change-Id: I3c5952136aec9eff3288b91b1318677ff971525c
_FD_chk.cpp
9218adc3909ee4d549526bba546203c8e1a16344 02-Oct-2013 Stephen Hines <srhines@google.com> am 62f95981: am 70e1730c: Merge "Remove _FORTIFY_SOURCE in implementation files."

* commit '62f95981df783575efd44cb4206be7b2cbdfcf1c':
Remove _FORTIFY_SOURCE in implementation files.
95fa896206b82f2d8c2c26681511caf5d6c896f6 02-Oct-2013 Stephen Hines <srhines@google.com> am dcffa999: am e0e6409c: Merge "Add simple implementation _Unwind_GetIP() for clang compiles."

* commit 'dcffa9998e95dc0fb89d0c9e0ae51a0557d5b2b4':
Add simple implementation _Unwind_GetIP() for clang compiles.
70e1730c38ad91cf65425e29732b5c041dd0cf43 02-Oct-2013 Stephen Hines <srhines@google.com> Merge "Remove _FORTIFY_SOURCE in implementation files."
e0e6409c12d21cf1f0390c435fd76e74b5c4580d 02-Oct-2013 Stephen Hines <srhines@google.com> Merge "Add simple implementation _Unwind_GetIP() for clang compiles."
5f6cfce4f6608f2e450266814543e70b1ed2e02c 02-Oct-2013 Stephen Hines <srhines@google.com> Add simple implementation _Unwind_GetIP() for clang compiles.

Clang (prior to 3.4) does not actually provide a declaration (or definition)
of _Unwind_GetIP() for ARM. We can work around this by writing our own
basic implementation using the available primitive operations.

Change-Id: If6c66846952d8545849ad32d2b55daa4599cfe2c
ebug_stacktrace.cpp
a1de7e503355eda6910eaea1c06a2c1080d48dff 02-Oct-2013 Elliott Hughes <enh@google.com> am f1c534ce: am 6892a29b: Merge "Remove more assumptions that pointers are 32-bit."

* commit 'f1c534ce222de66bdeac06f2dca62fbd84f629f9':
Remove more assumptions that pointers are 32-bit.
405f8553cf19c583158d59ab44a5d668eade360d 02-Oct-2013 Elliott Hughes <enh@google.com> Remove more assumptions that pointers are 32-bit.

Change-Id: I2157e2fc4db7692b746c697982c3d028a056462a
alloc_debug_qemu.cpp
thread_attr.cpp
thread_key.cpp
35d937e4eb7b8e0a4e9a113d2f7434d55c0bc056 02-Oct-2013 Stephen Hines <srhines@google.com> Remove _FORTIFY_SOURCE in implementation files.

This was causing conflicting declarations for the library definitions of
common functions like sprintf(), snprintf(), and strchr().

Change-Id: I5daaa8a58183aa0d4d0fae8a7cb799671810f576
trchr.cpp
a08be021ccaf81bcbc53553c2f822730124c3d5e 01-Oct-2013 Elliott Hughes <enh@google.com> am 57e55fe3: am fd152c31: Merge "Clean up some comments."

* commit '57e55fe3b32465023071a19e368d91f4804ade3b':
Clean up some comments.
c0af6954262675856d6833ce7c256f0838326fd0 01-Oct-2013 Elliott Hughes <enh@google.com> Clean up some comments.

Copyright headers shouldn't contain the filename (and especially
shouldn't contain a different file's filename).

Change-Id: I82690a3bf371265402bc16f5d2fbb9299c3a1926
cgetpgrp.c
csetpgrp.c
d4e6961041942c6c01e6205db7d81368b39a4d1e 01-Oct-2013 Elliott Hughes <enh@google.com> am 1a46de67: am f281fd02: Merge "Better statfs/fstatfs glibc compatibility."

* commit '1a46de67b3f78ce44ddf622bcf5918fe758dd4d4':
Better statfs/fstatfs glibc compatibility.
58413fe73561e8f230092a2b83db64e58fcb061d 01-Oct-2013 Elliott Hughes <enh@google.com> am 4b5a0e1a: am 693bd73f: Merge "Remove 32-bit assumptions from the ELF code."

* commit '4b5a0e1ad76d76d6a8793f61e3c0902ea4628ce7':
Remove 32-bit assumptions from the ELF code.
f281fd02e9eebea3de9c07412c5b66647ca0c290 01-Oct-2013 Elliott Hughes <enh@google.com> Merge "Better statfs/fstatfs glibc compatibility."
693bd73fcdf1504e84aef314d1933f5efc2c817d 01-Oct-2013 Elliott Hughes <enh@google.com> Merge "Remove 32-bit assumptions from the ELF code."
01a700e5d2ee9b5bd61546faffcb453fd1d6325c 01-Oct-2013 Elliott Hughes <enh@google.com> Better statfs/fstatfs glibc compatibility.

Change-Id: I069d169c96cd71b75a045ec911fb4bd484c6b2c9
tatvfs.cpp
6c8dc464068816986278d152a7c39d477924b360 01-Oct-2013 Elliott Hughes <enh@google.com> am 28317d3a: am f5ea738b: Merge "Fix x86 build."

* commit '28317d3a161c88f88e85d97d584d656ffbe63a19':
Fix x86 build.
3456a1f5f486ebca7389bfd3eb942cb107eee0e6 01-Oct-2013 Elliott Hughes <enh@google.com> Fix x86 build.

Change-Id: I1f2d8189bec3d0e25d21ca7d7bd73fd02f8678e2
tatvfs.cpp
c620059479c47a78d57086d73726c9adc2f337ad 01-Oct-2013 Elliott Hughes <enh@google.com> Remove 32-bit assumptions from the ELF code.

Change-Id: I2c1f3d34c33685799aade8866eec44479ff9f963
l_iterate_phdr_static.c
etauxval.cpp
ibc_init_static.cpp
9a622f874ceb90431623af140ca9a78eadc96dcb 27-Sep-2013 Nick Kralevich <nnk@google.com> am cc362291: am 8427b745: Merge "libc: fortify recvfrom()"

* commit 'cc362291362f8183431eccb19267c8a625f36006':
libc: fortify recvfrom()
60f4f9a5b99a0a66817f50edfc2194a49f8b5146 25-Sep-2013 Nick Kralevich <nnk@google.com> libc: fortify recvfrom()

Fortify calls to recv() and recvfrom().

We use __bos0 to match glibc's behavior, and because I haven't
tested using __bos.

Change-Id: Iad6ae96551a89af17a9c347b80cdefcf2020c505
_recvfrom_chk.cpp
e74f77f92d80f11616da699ac908fd5d1913e996 20-Sep-2013 Elliott Hughes <enh@google.com> am 48a909c9: am aad3c52e: Merge "Ensure we have the off64_t variant of every function that takes an off_t."

* commit '48a909c9fd6dbe9be5655ad172d1083fa69c4107':
Ensure we have the off64_t variant of every function that takes an off_t.
b4f7616fd618875768b8fffc122b58bdb84a9969 20-Sep-2013 Elliott Hughes <enh@google.com> Ensure we have the off64_t variant of every function that takes an off_t.

Change-Id: Ib2eee0cf13162be3b62559b84e90c6dcf5aab1c3
seek64.c
a5a508a9b6c51259950bab3e628355632ad17fee 19-Sep-2013 Elliott Hughes <enh@google.com> am 35cfcc11: am f8e71bac: Merge "Add mmap64()"

* commit '35cfcc11fa923c75ead9356c71466ecabfafcc42':
Add mmap64()
afcc0cccdafef0c67600cbbc72cee0e7a41f3f04 18-Sep-2013 Daniel Leung <daniel.leung@intel.com> Add mmap64()

This adds mmap64() to bionic so that it is possible to have
large offset passed to kernel. However, the syscall mechanism
only passes 32-bit number to kernel. So effectively, the
largest offset that can be passed is about 43 bits (since
offset is signed, and the number passed to kernel is number
of pages (page size == 4K => 12 bits)).

Change-Id: Ib54f4e9b54acb6ef8b0324f3b89c9bc810b07281
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
map.cpp
44fd0d92d6e65d0d003103d402240d28d26ae639 19-Sep-2013 Elliott Hughes <enh@google.com> am 94c325fb: am 269851bf: Merge "Declare __page_shift and __page_size with C linkage."

* commit '94c325fb3bd8844dcc58640afb8f33668b684bc1':
Declare __page_shift and __page_size with C linkage.
9ae59c02ca68da5bb45152c85c4cab6fd6f7aba2 18-Sep-2013 Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> Declare __page_shift and __page_size with C linkage.

__page_shift and __page_size were accidentally declared in unistd.h with
C linkage - their implementation needs to use the same linkage.

Going forward, though, let's stop the inlining madness and let's kill
the non-standard __getpageshift(). This patch takes getpagesize(3) out
of line and removes __getpageshift but fixes __page_shift and __page_size
for backwards binary compatibility.

Change-Id: I35ed66a08989ced1db422eb03e4d154a5d6b5bda
Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
ibc_init_common.cpp
tubs.cpp
a3285dc9143a8175ff82bf1074720d04bed81faa 19-Sep-2013 Elliott Hughes <enh@google.com> am 8ff879a5: am a259472c: Merge "Fix mismatch between declaration and forward declaration"

* commit '8ff879a528b8876db811f5abd4dbf0640e3a0408':
Fix mismatch between declaration and forward declaration
edad1e1558bf5a561ffb33c5bf5ca0553711e1ee 18-Sep-2013 Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org> Fix mismatch between declaration and forward declaration

KernelArgumentBlock is defined as a class in KernelArgumentBlock.h, but
forward declarations refer to it as a struct.

While this is essentially the same, the mismatch causes a compiler
warning in clang (and may cause warnings in future versions of gcc) in
code that is supposed to be compiled with -Werror.

Change-Id: I4ba49d364c44d0a42c276aff3a8098300dbdcdf0
Signed-off-by: Bernhard Rosenkraenzer <Bernhard.Rosenkranzer@linaro.org>
ibc_init_common.h
4105fcdb3cbc820ec560740f02f3061d30e42419 14-Sep-2013 Brian Carlstrom <bdc@google.com> am 059f5c3f: am 8512992f: Merge "Simplify main thread stack size initialization"

* commit '059f5c3f6ce2a1783b5d96b4059df1b9104101d5':
Simplify main thread stack size initialization
50af69e8f326b2762a44d5fea2b118e7616e5d20 14-Sep-2013 Brian Carlstrom <bdc@google.com> Simplify main thread stack size initialization

Change-Id: Iec09433d9de501031cce09dc75848a5e8f3d96bf
ibc_init_common.cpp
thread_attr.cpp
thread_internal.h
322e7bce235ec6e3f82f65669423a1d9e997b51e 13-Sep-2013 Brian Carlstrom <bdc@google.com> Use kernel default for initial thread size

Bug: 10697851

Change-Id: I8d980f5e0b584799536f6e6b891056c968d26cdf
ibc_init_common.cpp
0890436da9ad6e9281f507d515a4158f241c3bd1 13-Sep-2013 Brian Carlstrom <bdc@google.com> am 9a74e36f: Use kernel default for initial thread size

* commit '9a74e36f4810ca22cb12f8eafe4f929edfa57e58':
Use kernel default for initial thread size
9a74e36f4810ca22cb12f8eafe4f929edfa57e58 13-Sep-2013 Brian Carlstrom <bdc@google.com> Use kernel default for initial thread size

Bug: 10697851

Change-Id: I8d980f5e0b584799536f6e6b891056c968d26cdf
ibc_init_common.cpp
a015800e731b3cc9a8c76d80d2a9f9eb451bf19f 03-Sep-2013 Elliott Hughes <enh@google.com> am 5d094c40: am df7436e7: Merge "Avoid segfaults if properties are not initialized"

* commit '5d094c408841370e4a6f2846ae3408d2e6d12f94':
Avoid segfaults if properties are not initialized
a21e696d905d12ee17481c5fe2ccbb67571c0572 09-Aug-2013 Pavel Chupin <pavel.v.chupin@intel.com> Avoid segfaults if properties are not initialized

Null or constant dereferencing occurs if properties are not initialized.
On Android devices it shouldn't happen but can be faced if testing bionic
libc.so on Linux host.

Change-Id: I8f047cbe17d0e7bcde40ace000a8aa53789c16cb
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
ystem_properties.c
2c87c3ff021571e82684a865609a1146830338fb 28-Aug-2013 Nick Kralevich <nnk@google.com> am cfd0d72d: am eb8f3622: Merge "FORTIFY_SOURCE: introduce __strncpy_chk2"

* commit 'cfd0d72da8641087f9c4015ee586614da9f7320a':
FORTIFY_SOURCE: introduce __strncpy_chk2
93501d3ab81156bcef251bb817a49e9ca46a6ec1 28-Aug-2013 Nick Kralevich <nnk@google.com> FORTIFY_SOURCE: introduce __strncpy_chk2

This change detects programs reading beyond the end of "src" when
calling strncpy.

Change-Id: Ie1b42de923385d62552b22c27b2d4713ab77ee03
_strncpy_chk.cpp
e9e10c13ff3fdb7104aafd0707b2c851851c9d1f 15-Aug-2013 Jeff Hao <jeffhao@google.com> Fix pthread_getcpuclockid.

clock_gettime was returning EINVAL for the values
produced by pthread_getcpuclockid.

Bug: 10346183

(cherry picked from commit 9b06cc3c1b2c4e2b08582f3fc9393a05aa589766)

Change-Id: Ib81a7024c218a4502f256c3002b9030e2aaa278d
thread_getcpuclockid.cpp
e714eb157ea92f3166b6292ed54138f3e092d5da 16-Aug-2013 Elliott Hughes <enh@google.com> am 6b6aaec8: am 4eacb341: Merge "Fix pthread_getcpuclockid."

* commit '6b6aaec892b1f256787fbbf106449f7d7e5888a2':
Fix pthread_getcpuclockid.
9b06cc3c1b2c4e2b08582f3fc9393a05aa589766 15-Aug-2013 Jeff Hao <jeffhao@google.com> Fix pthread_getcpuclockid.

clock_gettime was returning EINVAL for the values
produced by pthread_getcpuclockid.

Bug: 10346183
Change-Id: Iabe643d7d46110bb311a0367aa0fc737f653208e
thread_getcpuclockid.cpp
59a13c122ebc4191583b67c846a95d690dcda5cf 01-Aug-2013 Christopher Ferris <cferris@google.com> Optimize __memset_chk, __memcpy_chk. DO NOT MERGE.

This change creates assembler versions of __memcpy_chk/__memset_chk
that is implemented in the memcpy/memset assembler code. This change
avoids an extra call to memcpy/memset, instead allowing a simple fall
through to occur from the chk code into the body of the real
implementation.

Testing:

- Ran the libc_test on __memcpy_chk/__memset_chk on all nexus devices.
- Wrote a small test executable that has three calls to __memcpy_chk and
three calls to __memset_chk. First call dest_len is length + 1. Second
call dest_len is length. Third call dest_len is length - 1.
Verified that the first two calls pass, and the third fails. Examined
the logcat output on all nexus devices to verify that the fortify
error message was sent properly.
- I benchmarked the new __memcpy_chk and __memset_chk on all systems. For
__memcpy_chk and large copies, the savings is relatively small (about 1%).
For small copies, the savings is large on cortex-a15/krait devices
(between 5% to 30%).
For cortex-a9 and small copies, the speed up is present, but relatively
small (about 3% to 5%).
For __memset_chk and large copies, the savings is also small (about 1%).
However, all processors show larger speed-ups on small copies (about 30% to
100%).

Bug: 9293744

Merge from internal master.

(cherry-picked from 7c860db0747f6276a6e43984d43f8fa5181ea936)

Change-Id: I916ad305e4001269460ca6ebd38aaa0be8ac7f52
_strrchr_chk.cpp
840a114eb12773c5af39c0c97675b27aa6dee78c 09-Aug-2013 Elliott Hughes <enh@google.com> Add futimens.

(cherry picked from commit d0be7c8f9a06b3ca8ea7647ea35c8f9dc63f0fe1)

Bug: 10239370
Change-Id: I0087e85a94d83b6ce68ec6a0768c44cbe4bd0132
utimens.cpp
d0be7c8f9a06b3ca8ea7647ea35c8f9dc63f0fe1 09-Aug-2013 Elliott Hughes <enh@google.com> Add futimens.

Bug: 10239370
Change-Id: I518340084103dc339ef8a065d4837d6258a1381d
utimens.cpp
7f4074d17d0e22e5e18e472c7e099490df8efaf2 08-Aug-2013 Colin Cross <ccross@android.com> bionic: name malloc'd regions

Use the new __bionic_name_mem function to name malloc'd memory as
"libc_malloc" on kernels that support it.

Change-Id: I7235eae6918fa107010039b9ab8b7cb362212272
lmalloc.c
6771b9cef635f0da98932a1f0f877a07257ca088 07-Aug-2013 Colin Cross <ccross@android.com> bionic: add function to name memory

Only works on some kernels, and only on page-aligned regions of
anonymous memory. It will show up in /proc/pid/maps as
[anon:<name>] and in /proc/pid/smaps as Name: <name>

Change-Id: If31667cf45ff41cc2a79a140ff68707526def80e
ame_mem.c
7c860db0747f6276a6e43984d43f8fa5181ea936 01-Aug-2013 Christopher Ferris <cferris@google.com> Optimize __memset_chk, __memcpy_chk.

This change creates assembler versions of __memcpy_chk/__memset_chk
that is implemented in the memcpy/memset assembler code. This change
avoids an extra call to memcpy/memset, instead allowing a simple fall
through to occur from the chk code into the body of the real
implementation.

Testing:

- Ran the libc_test on __memcpy_chk/__memset_chk on all nexus devices.
- Wrote a small test executable that has three calls to __memcpy_chk and
three calls to __memset_chk. First call dest_len is length + 1. Second
call dest_len is length. Third call dest_len is length - 1.
Verified that the first two calls pass, and the third fails. Examined
the logcat output on all nexus devices to verify that the fortify
error message was sent properly.
- I benchmarked the new __memcpy_chk and __memset_chk on all systems. For
__memcpy_chk and large copies, the savings is relatively small (about 1%).
For small copies, the savings is large on cortex-a15/krait devices
(between 5% to 30%).
For cortex-a9 and small copies, the speed up is present, but relatively
small (about 3% to 5%).
For __memset_chk and large copies, the savings is also small (about 1%).
However, all processors show larger speed-ups on small copies (about 30% to
100%).

Bug: 9293744

Change-Id: I8926d59fe2673e36e8a27629e02a7b7059ebbc98
_strrchr_chk.cpp
c03e1e74390c1b8a30341399cd85cc869d0842b0 30-Jul-2013 Elliott Hughes <enh@google.com> Define PTHREAD_KEYS_MAX and _POSIX_THREAD_KEYS_MAX in a POSIX-compliant way.

Also make sysconf use PTHREAD_STACK_MIN rather than redefining its
own, different, constant.

Bug: 9997352
Change-Id: I9a8e7d2b18e691439abfb45533e82c36eee9e81d
ysconf.cpp
e320a8c7802eb54f80693db03bb2a201580875e7 25-Jul-2013 Elliott Hughes <enh@google.com> Avoid sign extension of the mmap offset.

off_t is signed to support seeking backwards, but that's a liability
when using off_t to represent a subset of a file.

Change-Id: I2a3615166eb16212347eb47f1242e3bfb93c2022
map.cpp
d0f2a6014c138945f78108b21b54a813c7a055db 23-Jul-2013 Rom Lemarchand <romlem@google.com> Restore dlmalloc mmap threshold to 64k

Restoring DEFAULT_MMAP_THRESHOLD to 64k, the way it was before
999089181ef60bb67e1a49f2cf6f4ec608a7caf8.

This forces allocations in the 64k-256k range to be mmaped.

Change-Id: Iace55ed638edd272b3e94fa6cd2ddd349042be84
Signed-off-by: Rom Lemarchand <romlem@google.com>
lmalloc.h
4cf13952175a793fed4646d7d7396364874b0909 20-Jul-2013 Elliott Hughes <enh@google.com> Move stuff only needed by pthread-timers.c into pthread-timers.c.

Change-Id: I4915b3fff9c4f5a36b4f51027fb22019c11607b0
thread-timers.c
thread_internal.h
84114c8dd5b17efecf7988f263ce431208d7be5a 17-Jul-2013 Elliott Hughes <enh@google.com> Improve stack overflow diagnostics (take 2).

This reverts commits eb1b07469f2b5a392dc1bfd8adc211aea8c72bc5 and
d14dc3b87fbf80553f1cafa453816b7f11366627, and fixes the bug where
we were calling mmap (which might cause errno to be set) before
__set_tls (which is required to implement errno).

Bug: 8557703
Change-Id: I2c36d00240c56e156e1bb430d8c22a73a068b70c
thread.c
thread_attr.cpp
thread_create.cpp
thread_internal.h
107cdd406b8e404af4d552498076cfe2dfe5efbf 17-Jul-2013 Elliott Hughes <enh@google.com> Prevent the madvise(MADV_MERGEABLE) mmap hack from affecting errno.

Bug: 9889616
Change-Id: I4a7323e0ae5aeb5cbe0da1b2bc7501d83b3a2aa4
map.c
map.cpp
e459bba398e8a9eee0958d418e9b16dfabdb1515 18-May-2013 Rom Lemarchand <romlem@google.com> mmap: Reinstate passing MADV_MERGEABLE on private anonymous maps

Reinstate mmap calling madvise(MADV_MERGEABLE) removed in
635df850e5037be5093f64a87ec2e0a23bf7a50b

(cherry-pick of c702a904679a36511bead29c51eeac15d81f4fd2.)

Change-Id: I18803fb54701b2b3d8186dff5c678211ee3efa1f
map.c
d14dc3b87fbf80553f1cafa453816b7f11366627 17-Jul-2013 Guang Zhu <guangzhu@google.com> Revert "Improve stack overflow diagnostics."

This reverts commit aa754dca90487356cabf07ade0e8d88c2630b784.

Change-Id: Ifa76eee31f7f44075eb3a48554315b2693062f44
thread_attr.cpp
thread_create.cpp
aa754dca90487356cabf07ade0e8d88c2630b784 16-Jul-2013 Elliott Hughes <enh@google.com> Improve stack overflow diagnostics.

We notify debuggerd of problems by installing signal handlers. That's
fine except for when the signal is caused by us running off the end of
a thread's stack and into the guard page.

Bug: 8557703
Change-Id: I1ef65b4bb3bbca7e9a9743056177094921e60ed3
thread_attr.cpp
thread_create.cpp
d4e753fea9345c24dcce89531dff9019bef14eb3 16-Jul-2013 Elliott Hughes <enh@google.com> Clean up __builtin_expect usage.

Also remove some dead code; our malloc debugging doesn't use this
any more.

Change-Id: Id69cf182371f5f37d40b5bbd08f2744ade286e66
thread-rwlocks.c
thread-timers.c
thread.c
b95cf0d23a1db3b7c37bd98b0c86196796c9b029 15-Jul-2013 Elliott Hughes <enh@google.com> Fix pthread_getattr_np, pthread_attr_setguardsize, and pthread_attr_setstacksize.

pthread_getattr_np was reporting the values supplied to us, not the values we
actually used, which is kinda the whole point of pthread_getattr_np.

pthread_attr_setguardsize and pthread_attr_setstacksize were reporting EINVAL
for any size that wasn't a multiple of the system page size. This is
unnecessary. We can just round like POSIX suggests and glibc already does.

Also improve the error reporting for pthread_create failures.

Change-Id: I7ebc518628a8a1161ec72e111def911d500bba71
thread_attr.cpp
thread_create.cpp
6184c1feaaecd161d9e53fb2ebe9c9a9ff4610cf 09-Jul-2013 Elliott Hughes <enh@google.com> Fix MIPS build.

Change-Id: I583b1794dbc12fcded8c4f57f367593a742ab33f
tatvfs.cpp
06040fd75c1edff9e5ffb2b3d3e2a6e66d57c11d 09-Jul-2013 Elliott Hughes <enh@google.com> Add <sys/statvfs.h>.

Bug: 2512019
Change-Id: I6e7fd3fa281977cc4bc270481a95416b5b2dc351
tatvfs.cpp
5e9a086145764d64c0f7fbce5489d820aa7fdcd4 25-Jun-2013 Colin Cross <ccross@android.com> bionic: add compatibility mode for properties

Allow a new bionic to work with an old init property area by supporting
the old format.

(cherry picked from commit ad76c85b9ca587084089d086f954158bc0eae905)

Change-Id: Ib496e818a62a5834d40c71eb4745783d998be893
ystem_properties.c
ystem_properties_compat.c
1ec20a086cb1da1d7455a36ea5d2ea4856426ea0 25-Jun-2013 Colin Cross <ccross@android.com> bionic: use the size of the file to determine property area size

On the reader size, don't assume that the property size is PA_SIZE,
read it from the size of the file. Allows init to use a different
property size without recompiling statically linked executables.

(cherry picked from commit 285b42a04cbe8e627a75c9bfb3c7cb3f7b539267)

Change-Id: I074204e9e6591b35faf7c1c58fb11ec162aff7bf
ystem_properties.c
c45087bffa528c0809f0df2e0a3708eba7018b33 25-Jan-2013 Sergey Melnikov <sergey.melnikov@intel.com> Kernel dso support for 'dl_iterate_phdr' function

Kernel provides virtual DSO for stack unwinding/exception handlind info for
signal usage case. Stack unwinding routines use 'dl_iterate_phdr' function
for additional DWARF info gathering from DSOs. Patch enables virtual DSO
enumeration via dl_iterate_phdr function.

Signed-off-by: Sergey Melnikov <sergey.melnikov@intel.com>
Change-Id: Ic2882b28f40b456a088bc1e63c50cbfda7e4a102
l_iterate_phdr_static.c
836dbf65e4370df38cddc170229a7b0bdf882c8c 21-Jun-2013 Greg Hackmann <ghackmann@google.com> bionic: store property names as variable-length strings

Names are immutable, so the fixed-sized arrays can be replaced with
variable-length ones to save memory (especially on internal tree nodes).

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit 492ce95d9f6149137cb5b63c55cf2b3cdbe51e5e)

Change-Id: Ib074192d1b71150233d78c58e9ffcf7ecf688b6b
ystem_properties.c
1d36ee1a6e69ec529a7c43a4fe6268f85bc5134a 16-Jun-2013 Colin Cross <ccross@android.com> bionic: prevent root processes from calling __system_property_add

If a root process other than init calls __system_property_add, which
it should never do, it will break the design assumption that there is
only one mutator.

Pass O_EXCL to open() in map_prop_region_rw to ensure that only one
process ever has the property pages open for write.

(cherry picked from commit fb9b7b436f3ef94385f1b0c55ab81f246f0d96b8)

Change-Id: I6df3afedbfb5d07891b095aa24b78278381a5aaf
ystem_properties.c
1540f601be32bdd4af8e8c13bdf2bc06bdaa76f1 19-Jun-2013 Greg Hackmann <ghackmann@google.com> bionic: revert to a single (larger) property area

d329697 is too complicated. Change the multiple property pages back to
a single 128K property area that's mapped in entirely at initialization
(the memory will not get allocated until the pages are touched).

d329697 has other changes useful for testing (moving property area
initialization inside bionic and adding __system_property_set_filename)
so undo the change manually rather than with git revert.

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit 5f05348c18286a2cea46eae8acf94ed5b7932fac)

Change-Id: I690704552afc07a4dd410277893ca9c40bc13e5f
ystem_properties.c
996cdc4b1a7fcae89650bee0a44b6cb7900a4a3c 20-Jun-2013 Greg Hackmann <ghackmann@google.com> bionic: reimplement property area as hybrid trie/binary tree

See the comments for an explanation of how properties are stored.

The trie structure is designed to scale better than the previous
array-based implementation. Searching an array with n properties
required average O(n) string compares of the entire key; searching the
trie requires average O(log n) string compares of each token (substrings
between '.' characters).

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit 6ac8e6a46d71a51bec16938efa89f275fa89cf7d)

Change-Id: Icbe31908572f33b4d9b85d5b62ac837cbd0f85e0
ystem_properties.c
f7511e3bc932f9f4d025a62871c29bf1e0ac0ea7 20-Jun-2013 Greg Hackmann <ghackmann@google.com> bionic: add missing memory barriers to system properties

1) Reading the value must finish before checking whether it's intact

2) Setting the serial's dirty bit must visible before modifying the
value

3) The modified value must be visible before clearing the serial's dirty
bit

4) New properties and their TOC entries must be visible before updating
the property count

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit 5bfa3ee8b37ef162154559575193018a6235acba)

Change-Id: Id3fa45261fc2df2ae493ab5194bc2b6bff04e966
ystem_properties.c
cb215a7e9ecec9feb5aae9d9a5b1c89f392208e7 13-Feb-2013 Greg Hackmann <ghackmann@google.com> bionic: make property area expandable

The property area is initially one 4K region, automatically expanding as
needed up to 64 regions.

To avoid duplicating code, __system_property_area_init() now allocates
and initializes the first region (previously it was allocated in init's
init_property_area() and initialized in bionic). For testing purposes,
__system_property_set_filename() may be used to override the file used
to map in regions.

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit d32969701be070c0161c2643ee3c3df16066bbb8)

Change-Id: I038d451fe8849b0c4863663eec6f57f6521bf4a7
ystem_properties.c
17fc25d20f4d61f7fc3dfb3de095719ada89e38b 21-Jun-2013 Nick Kralevich <nnk@google.com> libc_logging: don't keep file descriptors open forever

Avoid keeping unnecessary file descriptors around when they're not
needed. Libc doesn't log so much that opening / closing overhead
matters.

Change-Id: I590ec5c27562db9bac025f781c48ec9a7724ce77
ibc_logging.cpp
c6ff844d75dddfb19fc804b8add2d6a79947b101 13-Feb-2013 Greg Hackmann <ghackmann@google.com> bionic: add __system_property_foreach

find_nth() will be inefficient on a trie. Since find_nth() is only used
internally and only for enumerating properties, we can add a foreach()
function to do this directly.

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit 577418403d68e663fb33c7b0c8a90d862d9c00cf)

Change-Id: Iaca97d1182ce2c28863ba85241cbb5cf6185eb2f
ystem_properties.c
5cf32de7a0fea0b10959b598300babc6e4f54d95 24-Jan-2013 Colin Cross <ccross@android.com> bionic: move system property writing from init to bionic

Move the implementation of writing to the system property area
from init to bionic, next to the reader implementation. This
will allow full property testing to be added to bionic tests.

Add new accessor and waiting functions to hide the implementation
from watchprops and various bionic users.

Also hide some of the implementation details of the property area
from init by moving them into _system_properties.h, and other details
from everybody by moving them into system_properties.h.

(cherry picked from commit dc1038b7900acb664e99643d2974e1a0f4703781)

Change-Id: I192d3825ee276c5047bc751039fe6cfe226a7cca
ystem_properties.c
0f020d18b138e24b1fe34074808e07ac412f35a4 06-Jun-2013 msg555 <msg555@gmail.com> Handles spurious wake-ups in pthread_join()

Removed 'join_count' from pthread_internal_t and switched to using the flag
PTHREAD_ATTR_FLAG_JOINED to indicate if a thread is being joined. Combined with
a switch to a while loop in pthread_join, this fixes spurious wake-ups but
prevents a thread from being joined multiple times. This is fine for
two reasons:

1) The pthread_join specification allows for undefined behavior when multiple
threads try to join a single thread.

2) There is no thread safe way to allow multiple threads to join a single
thread with the pthread interface. The second thread calling pthread_join
could be pre-empted until the thread is destroyed and its handle reused for
a different thread. Therefore multi-join is always an error.

Bug: https://code.google.com/p/android/issues/detail?id=52255
Change-Id: I8b6784d47620ffdcdbfb14524e7402e21d46c5f7
thread.c
thread_create.cpp
thread_detach.cpp
thread_internal.h
thread_join.cpp
thread_key.cpp
61e699a133a4807fe878a6cb0d7190d7c96e21f8 12-Jun-2013 Elliott Hughes <enh@google.com> Clean up abort.

* A dlmalloc usage error shouldn't call abort(3) because we want to
cause a SIGSEGV by writing the address dlmalloc didn't like to an
address the kernel won't like, so that debuggerd will dump the
memory around the address that upset dlmalloc.

* Switch to the simpler FreeBSD/NetBSD style of registering stdio
cleanup. Hopefully this will let us simplify more of the stdio
implementation.

* Clear the stdio cleanup handler before we abort because of a dlmalloc
corruption error. This fixes the reported bug, where we'd hang inside
dlmalloc because the stdio cleanup reentered dlmalloc.

Bug: 9301265
Change-Id: Ief31b389455d6876e5a68f0f5429567d37277dbc
bort.cpp
lmalloc.c
ibc_logging.cpp
2fbc9dda345486005569be4ec586c6aae9d51650 08-Jun-2013 Elliott Hughes <enh@google.com> Merge "bionic/x86: Optimization for string routines"
885f3b9cad01b8158aadc55c159c17dbf34f622c 22-May-2013 Christopher Ferris <cferris@google.com> Implement malloc_usable_size for debug impls.

- Implemented chk_memalign.
- Fixed a few bugs in leak_memalign.
- Implemented {leak,fill,check,qemu}_malloc_usable_size.
- Make malloc_usable_size update at run time.
- Add malloc_test.cpp as a small set of tests for the
malloc debug routines.
- Fix the qemu routines since it's been broken since it moved to C++.
- Add support for the %u format to the out_vformat in libc_logging.cpp.
This is used by the emulator code.

Tested using the bionic-unit-tests with setprop libc.debug.malloc
set to 1, 5, and 10.

I tested as much as possible on the emulator, but tracing doesn't appear
to be working properly.

Bug: 6143477

Merge change from internal master.

(cherry-picked from commit 3d594c258045783fc9e1956ce7a4d91e302f011e)

Change-Id: I4ae00fffba82315a8c283f35893fd554460722fb
ibc_logging.cpp
alloc_debug_check.cpp
alloc_debug_common.cpp
alloc_debug_common.h
alloc_debug_leak.cpp
alloc_debug_qemu.cpp
36fa67bcdd90f18a3c68f8637ae836762407fa51 06-Jun-2013 Elliott Hughes <enh@google.com> Ensure header files using __BEGIN_DECLS include sys/cdefs.h.

We keep fixing these one-by-one; let's fix them all at once.

Found thus:

find . -name *.h | xargs grep -L sys/cdefs.h | xargs grep -l BEGIN_DECL | xargs grep -L sys/types

Change-Id: I188842aa2484dc6176e96556d57c38a0f785b59b
thread_internal.h
4c001859feeda27727917c5bd00338e90b801742 05-Jun-2013 Elliott Hughes <enh@google.com> Merge "Fix declaration of malloc_usable_size()"
cf870199d576bdfc339b7fb016c9f6fe7f2c87ed 31-May-2013 Nick Kralevich <nnk@google.com> FORTIFY_SOURCE: strcat / strncat optimize

__strcat_chk and __strncat_chk are slightly inefficient,
because they end up traversing over the same memory region
two times.

This change optimizes __strcat_chk / __strncat_chk so they
only access the memory once. Although I haven't benchmarked these
changes, it should improve the performance of these functions.

__strlen_chk - expose this function, even if -D_FORTIFY_SOURCE
isn't defined. This is needed to compile libc itself without
-D_FORTIFY_SOURCE.

Change-Id: Id2c70dff55a276b47c59db27a03734d659f84b74
_strcat_chk.cpp
_strncat_chk.cpp
0a490665a3a287cd3aee1e7327f2381222c387c4 16-Jan-2012 Liubov Dmitrieva <liubov.dmitrieva@intel.com> bionic/x86: Optimization for string routines

Optimized strcpy, strcat,
strncpy, strncat, strlcpy, strlcat,
memchr, memrchr, strchr, strrchr, index,
strnlen, strlen, wcslen, wmemcmp, wcscmp,
wcschr, wcsrchr, wcscpy, wcscat

Change-Id: I82b29132edf9a2e144e0bb3ee4ff5217df8d2a6d
Signed-off-by: Liubov Dmitrieva <liubov.dmitrieva@intel.com>
_strchr_chk.cpp
trchr.cpp
25a87f7641f066437d15c6d3148d08a6ab9be231 23-May-2013 David 'Digit' Turner <digit@android.com> Fix declaration of malloc_usable_size()

The function should take a 'const void*' parameter, instead of 'void*'.
Note that the implementation in upstream-dlmalloc/malloc.c already does
this.

For context, see http://b.android.com/55725

Change-Id: Iefd55cdb8996699189e0545f9195972490306227
alloc_debug_common.cpp
d35106fd557e054d1ffe388df6a3b3cb51cc5021 15-May-2013 Elliott Hughes <enh@google.com> Fix sysconf(3) for _SC_GETGR_R_SIZE_MAX and _SC_GETPW_R_SIZE_MAX.

Change-Id: Ie16cb21c1a5a2bdce8502b5974e2c4dbb1d679ce
ysconf.cpp
63dd03ccedc316724c40e140067e612932e4420e 08-May-2013 Ben Cheng <bccheng@google.com> Remove a spurious FIXME and unnecessary type cast.

Change-Id: I05dcefdec7f047bef7eef5c5ceb7453992d56c24
ebug_stacktrace.cpp
52171b9bdcb2aa1efe9c4deab37c029699fe763d 07-May-2013 Ben Cheng <bccheng@google.com> Adjust PC value in ARM stack trace.

-2 for Thumb BLX(2) or -4 for the rest.

Change-Id: I804fdabfa1db4709bede222d4b432e8d42d53167
ebug_stacktrace.cpp
532d6f09b1e7bfe995c1dba6594d1fc2c1ea77cf 02-May-2013 Nick Kralevich <nnk@google.com> Use __predict_false on some fortify methods.

Give the compiler some hints that these error conditions
are unlikely to occur in practice.

Change-Id: Ifaf7322a12120ef663c8315c1a18c2dcbe4bda23
_memcpy_chk.cpp
_memmove_chk.cpp
_memset_chk.cpp
_strcpy_chk.cpp
_strlcat_chk.cpp
_strlcpy_chk.cpp
_strlen_chk.cpp
_strncpy_chk.cpp
_umask_chk.cpp
_vsnprintf_chk.cpp
pen.c
4f40e511b0612ea099ab5b0843977fe7a49372fd 20-Apr-2013 Nick Kralevich <nnk@google.com> libc: cleanup strchr

Move strchr to a .cpp file, and change to bionic directory.

Change-Id: I64ade7df326c0a9a714aca4caf5647b6833b1c97
trchr.cpp
ea489745dcc7c116259b63f0353dc482aa4fe2cd 12-Apr-2013 Kito Cheng <kito@0xlab.org> Use hidden visibility for internal-use-only functions

- malloc_debug_init and malloc_debug_fini

Change-Id: I4261ff428a50d8f0371415cda71bcc0a9487ce67
alloc_debug_common.cpp
4ca685e36e9d7f53c135eba2b4b8ece152129dbe 09-Apr-2013 Kito Cheng <kito@0xlab.org> Add missing include and function prototype for sched_getaffinity.

Change-Id: I649633c8d074def5d05bd0c8b92fb680d9d11d51
ched_getaffinity.c
ched_getaffinity.cpp
0d787c1fa18c6a1f29ef9840e28a68cf077be1de 04-Apr-2013 Elliott Hughes <enh@google.com> Make abort messages available to debuggerd.

This adds __libc_fatal, cleans up the internal logging code a bit more,
and switches suitable callers over to __libc_fatal. In addition to logging,
__libc_fatal stashes the message somewhere that the debuggerd signal handler
can find it before calling abort.

In the debuggerd signal handler, we pass this address to debuggerd so that
it can come back with ptrace to read the message and present it to the user.

Bug: 8531731
Change-Id: I416ec1da38a8a1b0d0a582ccd7c8aaa681ed4a29
_stack_chk_fail.cpp
ssert.cpp
lmalloc.c
ibc_init_common.cpp
ibc_logging.cpp
alloc_debug_qemu.cpp
ystem_properties.c
8baa929d5d3bcf63381cf78ba76168c80c303f5e 03-Apr-2013 Kito Cheng <kito@0xlab.org> Prevent name conflict for eventfd.cpp and eventfd.s when building libc.a

- eventfd.cpp and eventfd.s will output to the same file when building libc.a
out/target/product/*/obj/STATIC_LIBRARIES/libc_intermediates/WHOLE/libc_common_objs/eventfd.o
- And then `eventfd` will undefined when statically linked to libc.

Also add a unit test.

Change-Id: Ib310ade3256712ca617a90539e8eb07459c98505
ventfd.cpp
ventfd_read.cpp
ventfd_write.cpp
4ace92c62ada583b220836d76de2cfcb78d4d48d 03-Apr-2013 Elliott Hughes <enh@google.com> Stop using unreasonable numbers of map entries.

Bug: 8460659
Change-Id: Ib0ee71e3cf61e122d0449c9d8a4e4670a7d7129a
lmalloc.c
cfa089df23ff50fcd5ed3854c54991d30be5fc7e 30-Mar-2013 Elliott Hughes <enh@google.com> Extra logging in pthread_create.

pthread_create returns EAGAIN when it can't allocate a pthread_internal_t,
when it can't allocate a stack for the new thread, or when clone(2) fails
because there are too many threads. It's useful to be able to know why your
pthread_create just failed, so add some logging.

Bug: 8470684
Change-Id: I1bb4497d4f7528eacce0db35c2014771cba64569
thread_create.cpp
65a8eb606f2104f4b14514fa2a89d2867167793b 25-Mar-2013 Elliott Hughes <enh@google.com> Clarify the dlmalloc USAGE_ERROR.

Bug: 8468088
Change-Id: I1ff6d51ec17fc74ef56229aa76d2986cbd662874
lmalloc.c
3198850ea125f746efabd1a81e3bd7cfa58cc600 23-Mar-2013 Elliott Hughes <enh@google.com> Unhide __set_errno for backwards compatibility.

This was in <errno.h>, and people called it :-(

Change-Id: I038490be77eb9372b3f31305ec580fa7b09c983e
_set_errno.cpp
8794ece296dd62cbeb3d00fe57c831c90a1bef77 22-Mar-2013 Elliott Hughes <enh@google.com> Replace unnecessary ARM uses of <sys/linux-syscalls.h> with <asm/unistd.h>.

For some reason, socketcalls.c was only being compiled for ARM, where
it makes no sense. For x86 we generate stubs for the socket functions
that use __NR_socketcall directly.

Change-Id: I84181e6183fae2314ae3ed862276eba82ad21e8e
ocketcalls.c
a41ba2f0bfc4fce1ce8f06a9c289102c440c929d 22-Mar-2013 Elliott Hughes <enh@google.com> Fix pthread_setname_np's behavior on invalid pthread_ts.

Change-Id: I0a154beaab4d164ac812f2564d12e4d79b80a8e8
thread_setname_np.cpp
17a8b0db63d54e9d79bf11112ace0c4fe9606289 21-Mar-2013 Elliott Hughes <enh@google.com> Expose wait4 as wait4 rather than __wait4.

This helps strace(1) compile with one fewer hack.

Change-Id: I5296d0cfec5546709cda990abd705ad33d7c4626
ait.c
ait.cpp
ce532721aaf61d4b6a171903c851ac82adf08aa8 16-Mar-2013 Elliott Hughes <enh@google.com> Hide various symbols that shouldn't be exposed.

A mangled symbol in libc.so is a symbol that shouldn't be exported
by libc.so.

Change-Id: Id92d1e1968b3d11d111a5d9ef692adb1ac7694a1
ibc_init_common.h
ibc_init_dynamic.cpp
thread_key.cpp
8f2a5a0b40fc82126c691d5c30131d908772aab7 15-Mar-2013 Elliott Hughes <enh@google.com> Clean up internal libc logging.

We only need one logging API, and I prefer the one that does no
allocation and is thus safe to use in any context.

Also use O_CLOEXEC when opening the /dev/log files.

Move everything logging-related into one header file.

Change-Id: Ic1e3ea8e9b910dc29df351bff6c0aa4db26fbb58
_fgets_chk.cpp
_memcpy_chk.cpp
_memmove_chk.cpp
_memset_chk.cpp
_stack_chk_fail.cpp
_strcat_chk.cpp
_strcpy_chk.cpp
_strlcat_chk.cpp
_strlcpy_chk.cpp
_strlen_chk.cpp
_strncat_chk.cpp
_strncpy_chk.cpp
_umask_chk.cpp
_vsnprintf_chk.cpp
_vsprintf_chk.cpp
ssert.cpp
ebug_format.cpp
ebug_stacktrace.cpp
lmalloc.c
ibc_logging.cpp
ogd_write.c
alloc_debug_check.cpp
alloc_debug_common.cpp
alloc_debug_common.h
alloc_debug_leak.cpp
alloc_debug_qemu.cpp
pen.c
penat.c
thread_create.cpp
thread_debug.cpp
tubs.cpp
2eb44c5aa49f69b6ff0d3f9665d7728757b9ca93 15-Mar-2013 Elliott Hughes <enh@google.com> Remove useless workaround for HTC RIL bugs.

HTC's RIL uses the liblog logging, not ours.

Change-Id: I56f9304e833ccb329df4ee55042012d7ad5f73ed
ogd_write.c
9aceab50155b17741faded1fb22e2daa51a07fb1 12-Mar-2013 Elliott Hughes <enh@google.com> Use the kernel's MAX_ERRNO in the syscall stubs.

Bug: http://code.google.com/p/android/issues/detail?id=53104
Change-Id: Iaabf7025b153e96dc5eca231a33a32d4cb7d8116
_set_errno.cpp
cb2069bf69b14f0e76593e1ec4d1deb6fa15232c 12-Mar-2013 Elliott Hughes <enh@google.com> Support large errno values on ARM.

Bug: http://code.google.com/p/android/issues/detail?id=53104
Change-Id: Ic6c40be2dc50f0644a3d8b09ceae59c38f2d5b53
_set_errno.cpp
642331b5dd5647e7d196ac4f44406fd435478a56 07-Mar-2013 Elliott Hughes <enh@google.com> Fix debug malloc.

This was broken by the change to use AT_RANDOM for the stack guards.

Bug: 7959813
Bug: 8330764
Change-Id: I791900092b72a9a900f16585237fa7ad82aaed9f
_stack_chk_guard.cpp
ibc_init_common.cpp
f0777843c03deb26b1f78c8edd17c557041696e9 02-Mar-2013 Elliott Hughes <enh@google.com> Move realpath.c to upstream-freebsd.

This is actually a slightly newer upstream version than the one I
originally pulled. Hopefully now it's in upstream-freebsd it will
be easier to track upstream, though I still need to sit down and
write the necessary scripts at some point.

Bug: 5110679
Change-Id: I87e563f0f95aa8e68b45578e2a8f448bbf827a33
ealpath.c
701bec2af33feaa9dddf12ccf8e4c714441b7f2e 25-Feb-2013 Elliott Hughes <enh@google.com> Reimplement scandir(3).

The old scandir implementation didn't take into account the varying
size of directory entries, and didn't correctly clean up on its
error exits.

Bug: 7339844
Change-Id: Ib40e3564709752241a3119a496cbb2192e3f9abe
irent.cpp
candir.cpp
ysconf.cpp
fae89fc4042ee4c360842234dfda7831c313bd44 21-Feb-2013 Elliott Hughes <enh@google.com> Fix raise(3) so it works in signal handlers.

We could special-case raise(3) in non-threaded programs, but the more
conservative course is to make pthread_kill(3) work in signal handlers
at the cost of a race shared by other C libraries.

Change-Id: I59fb23d03bdabf403435e731704b33acdf3e0234
thread_accessor.h
thread_kill.cpp
9d23e04c43dbb8480bea8be28b8a2f37423bec49 16-Feb-2013 Elliott Hughes <enh@google.com> Fix pthreads functions that should return ESRCH.

imgtec pointed out that pthread_kill(3) was broken, but most of the
other functions that ought to return ESRCH for invalid/exited threads
were equally broken.

Change-Id: I96347f6195549aee0c72dc39063e6c5d06d2e01f
thread.c
thread_accessor.h
thread_detach.cpp
thread_equal.cpp
thread_getcpuclockid.cpp
thread_getschedparam.cpp
thread_internal.h
thread_internals.cpp
thread_join.cpp
thread_kill.cpp
thread_self.cpp
thread_setschedparam.cpp
081318e3550b1a8d8384d98d7c94527681691120 15-Feb-2013 Elliott Hughes <enh@google.com> dalvik is big enough and ugly enough to handle System.arraycopy itself.

Change-Id: I4b54a15ea101c0c6bab06cfb11e4178f5a57fc05
emmove_words.c
40eabe24e4e3ae8ebe437f1f4e43cf39cbba2e9e 15-Feb-2013 Elliott Hughes <enh@google.com> Fix the pthread_setname_np test.

Fix the pthread_setname_np test to take into account that emulator kernels are
so old that they don't support setting the name of other threads.

The CLONE_DETACHED thread is obsolete since 2.5 kernels.

Rename kernel_id to tid.

Fix the signature of __pthread_clone.

Clean up the clone and pthread_setname_np implementations slightly.

Change-Id: I16c2ff8845b67530544bbda9aa6618058603066d
ionic_clone.c
ork.c
ibc_init_common.cpp
thread-rwlocks.c
thread.c
thread_create.cpp
thread_internal.h
thread_setname_np.cpp
fb7eb5e07f43587c2bedf2aaa53b21fa002417bb 14-Feb-2013 Elliott Hughes <enh@google.com> Simplify __stack_chk_fail, and fix it so we get debuggerd stack traces.

Bug: 2487269
Change-Id: Iec5e470fc22cd9108404f634a9d4baa2c7b7f58f
_stack_chk_fail.cpp
_stack_chk_guard.cpp
thread.c
sp.cpp
a261afb7c9de7c59dd078fa88f40b7818f79a098 14-Feb-2013 Nick Kralevich <nnk@google.com> fix compiler warning.

bionic/libc/bionic/ssp.cpp:41:31: warning: converting to non-pointer type 'uintptr_t {aka unsigned int}' from NULL [-Wconversion-null]

Change-Id: Id154ed4a99520cca64ffd3dbe4d743db6e2da28a
sp.cpp
4b4a8824289c48c823cd38bc63289d121aae3d67 13-Feb-2013 Elliott Hughes <enh@google.com> Clean up pthread_create.

Bug: 3461078
Change-Id: I082122a86d7692cd58f4145539241be026258ee0
thread.c
thread_create.cpp
6d339182070b035ca94f19bc37c94f4d9813c374 13-Feb-2013 Elliott Hughes <enh@google.com> Simplify pthread_create, using more public API.

Change-Id: I08e65ba88ed01436223e4e528631c9e41ec0e7f4
ibc_init_common.cpp
thread.c
thread_attr.cpp
thread_internal.h
3e898476c7230b60a0f76968e64ff25f475b48c0 12-Feb-2013 Elliott Hughes <enh@google.com> Revert "Revert "More pthreads cleanup.""

This reverts commit 6f94de3ca49e4ea147b1c59e5818fa175846518f

(Doesn't try to increase the number of TLS slots; that leads to
an inability to boot. Adds more tests.)

Change-Id: Ia7d25ba3995219ed6e686463dbba80c95cc831ca
irent.cpp
thread.c
thread_attr.cpp
thread_internal.h
thread_key.cpp
thread_setname_np.cpp
thread_sigmask.cpp
trerror_r.cpp
tubs.cpp
ysconf.cpp
mpfile.cpp
6f94de3ca49e4ea147b1c59e5818fa175846518f 12-Feb-2013 Elliott Hughes <enh@google.com> Revert "More pthreads cleanup."

This reverts commit 2a1bb4e64677b9abbc17173c79768ed494565047

Change-Id: Ia443d0748015c8e9fc3121e40e68258616767b51
irent.cpp
thread.c
thread_attr.cpp
thread_internal.h
thread_key.cpp
thread_setname_np.cpp
thread_sigmask.cpp
trerror_r.cpp
tubs.cpp
ysconf.cpp
mpfile.cpp
2a1bb4e64677b9abbc17173c79768ed494565047 11-Feb-2013 Elliott Hughes <enh@google.com> More pthreads cleanup.

POSIX says pthread_create returns EAGAIN, not ENOMEM.

Also pull pthread_attr_t functions into their own file.

Also pull pthread_setname_np into its own file.

Also remove unnecessary #includes from pthread_key.cpp.

Also account for those pthread keys used internally by bionic,
so they don't count against the number of keys available to user
code. (They do with glibc, but glibc's limit is the much more
generous 1024.)

Also factor out the common errno-restoring idiom to reduce gotos.

Bug: 6702535
Change-Id: I555e66efffcf2c1b5a2873569e91489156efca42
irent.cpp
thread.c
thread_attr.cpp
thread_internal.h
thread_key.cpp
thread_setname_np.cpp
thread_sigmask.cpp
trerror_r.cpp
tubs.cpp
ysconf.cpp
mpfile.cpp
44b53ad6818de344e0b499ad8fdbb21fcb0ff2b6 11-Feb-2013 Elliott Hughes <enh@google.com> Revert "Revert "Pull the pthread_key_t functions out of pthread.c.""

This reverts commit 6260553d48f6fd87ca220270bea8bafdde5726ec

(Removing the accidental libm/Android.mk change.)

Change-Id: I6cddd9857c31facc05636e8221505b3d2344cb75
thread.c
thread_internal.h
thread_key.cpp
ysconf.cpp
6260553d48f6fd87ca220270bea8bafdde5726ec 11-Feb-2013 Elliott Hughes <enh@google.com> Revert "Pull the pthread_key_t functions out of pthread.c."

This reverts commit ad59322ae432d11ff36dcf046016af8cfe45fbe4

somehow my unfinished libm/Android.mk change got into here.

Change-Id: I46be626c5269d60fb1ced9862f2ebaa380b4e0af
thread.c
thread_internal.h
thread_key.cpp
ysconf.cpp
ad59322ae432d11ff36dcf046016af8cfe45fbe4 09-Feb-2013 Elliott Hughes <enh@google.com> Pull the pthread_key_t functions out of pthread.c.

This was originally motivated by noticing that we were setting the
wrong bits for the well-known tls entries. That was a harmless bug
because none of the well-known tls entries has a destructor, but
it's best not to leave land mines lying around.

Also add some missing POSIX constants, a new test, and fix
pthread_key_create's return value when we hit the limit.

Change-Id: Ife26ea2f4b40865308e8410ec803b20bcc3e0ed1
thread.c
thread_internal.h
thread_key.cpp
ysconf.cpp
d3920b3a996b358e48232f417aa0a1e44a60f155 08-Feb-2013 Elliott Hughes <enh@google.com> Switch to using AT_RANDOM for the stack guards.

Bug: 7959813
Change-Id: I8db4b8912ba649bfe668c6f22aa44690ddd401a2
ibc_init_common.cpp
ibc_init_static.cpp
thread.c
sp.cpp
e4ccf5a138a9c6387ee2e4b8e41d628e0a2cc336 07-Feb-2013 Elliott Hughes <enh@google.com> __progname should be const char*, not char*.

Change-Id: I8e846872c30a712fbc05c8da59ffa1cec1be31a4
rr.c
ibc_init_common.cpp
alloc_debug_common.cpp
thread_debug.cpp
42b2c6a5eed5e4ef35315b8cd32d1355f12a69b6 07-Feb-2013 Elliott Hughes <enh@google.com> Clean up the argc/argv/envp/auxv handling.

There's now only one place where we deal with this stuff, it only needs to
be parsed once by the dynamic linker (rather than by each recipient), and it's
now easier for us to get hold of auxv data early on.

Change-Id: I6314224257c736547aac2e2a650e66f2ea53bef5
etauxval.cpp
ibc_init_common.c
ibc_init_common.cpp
ibc_init_common.h
ibc_init_dynamic.c
ibc_init_dynamic.cpp
ibc_init_static.c
ibc_init_static.cpp
428f5567be25b8090e3dd72e2d3d337c305b514e 06-Feb-2013 Elliott Hughes <enh@google.com> Remove bogus extra alignment from sbrk.

Bug: https://code.google.com/p/android/issues/detail?id=37349
Change-Id: I970c7b6be7bb7fbe6bbbe2c332f05816aeb0e09f
rk.c
rk.cpp
brk.c
brk.cpp
9c81892c2e8c684e0da12028e389bf6d9b5253b7 02-Feb-2013 Elliott Hughes <enh@google.com> Don't claim there were no leaks if we weren't even checking.

Bug: 8107016
Change-Id: I9059f1f8374ebcdf00dfc6ac74d3709f501292c9
alloc_debug_check.cpp
alloc_debug_common.cpp
1d12d574169cedd68185196e4957597d00fd4681 30-Jan-2013 Elliott Hughes <enh@google.com> Say explicitly if there were no leaks.

Otherwise people trying to use this are left wondering "did I not leak, or did
the leak checking code not get called when I exited?".

Change-Id: If79b225f8a2e24dd69aba1fb836bf9e81bb00efe
alloc_debug_check.cpp
d070df4c74c654d8c37c807e7e77db616f91ecbd 30-Jan-2013 Elliott Hughes <enh@google.com> Fix x86 build to use <elf.h>.

Change-Id: I7b697d5eae69dc08eb31471a42cb8bbe5360be76
l_iterate_phdr_static.c
35b621c5f4c79959cd36fec0153c2c9c43ebe5f0 29-Jan-2013 Elliott Hughes <enh@google.com> Don't collect useless stack frames; do demangle C++ symbols.

Previously, we'd collect every stack frame and then throw some away
when we came to log them. This meant that stack traces were effectively
shorter than the buffers that had been allocated for them. This patch
only stores frames we'll actually output.

Also dynamically call the C++ demangler so we don't have to try to
read mangled names. Because no one knows the mangling of operator new[]
for int arrays off the top of their head.

Bug: 7291287
Change-Id: I42b022fd7cd61675d05171de4c3b2704d058ef2a
ebug_mapinfo.cpp
ebug_mapinfo.h
ebug_stacktrace.cpp
ebug_stacktrace.h
alloc_debug_check.cpp
thread_debug.cpp
41b3179c9ef03ebb447cac7f5e8405dce399cb17 28-Jan-2013 Elliott Hughes <enh@google.com> Unit tests for formatting code, fix %%.

Also fix <signal.h> and <stdio.h> so they don't cause compiler warnings.

Change-Id: Ib1a746bf01de22d47dbd964de0e6af80a7c96303
ebug_format.cpp
239e7a0756fddf3698bf72cab10d7f382421090b 26-Jan-2013 Elliott Hughes <enh@google.com> More debug malloc fixes.

Include the leaky executable's name in the log output. Fix the "sh" test.
Use uintptr_t instead of intptr_t.

Also fix debug formatting of NULL with %s.

Bug: 7291287
Change-Id: I015bf341cd48d43a247173612e6ccb1bf1243d53
ebug_format.cpp
ebug_stacktrace.cpp
ebug_stacktrace.h
alloc_debug_check.cpp
alloc_debug_common.cpp
alloc_debug_common.h
alloc_debug_leak.cpp
thread_debug.cpp
c16961b8c3b932716b2e576c5877d39411b453cc 25-Jan-2013 Nick Kralevich <nnk@google.com> system_properties: do more checking of file

Check that the permissions on the properties file
are exactly as we expect them to be.

Make sure we close the fd if fstat fails.

Refactor the code slightly.

Change-Id: I5503fd58c3b8093ce7e6d05920748ed70eaf8e2c
ystem_properties.c
32417fb37642a1f975ec107e6b449ba71196db56 23-Jan-2013 Nick Kralevich <nnk@google.com> libc: use more secure system properties if available

Currently, system properties are passed via the environment
variable ANDROID_PROPERTY_WORKSPACE and a file descriptor passed
from parent to child. This is insecure for setuid executables,
as the environment variable can be changed by the caller.

Modify system property handling so that we get the properties
from a root owned properties file, rather than using an
environment variable. Fall back to the environment variable
if the file doesn't exist.

Bug: 8045561
Change-Id: I54f3efa98cf7d63d88788da5ce0d19e34fd7851a
ystem_properties.c
778a68e1e57408be04806b5bfc3150aade44bcbf 23-Jan-2013 Elliott Hughes <enh@google.com> Merge "Don't free anything when reporting leaks."
848247a972038e30e12b0c9f7f049aa97c73b9c7 23-Jan-2013 Elliott Hughes <enh@google.com> Don't free anything when reporting leaks.

We don't know that they're not going to be cleaned up by a
C++ global destructor that runs after us. This is the case with
bootanimation, for example.

Bug: 7291287
Change-Id: Iba402514d1735fdc2ae4bc95b65396d816be46c0
alloc_debug_check.cpp
84f8b5f4013c5df372ad97f3f98ea27ac6064a97 23-Jan-2013 Elliott Hughes <enh@google.com> Disable leak checking for mksh; it's way too leaky.

When each shell leaks ~240 allocations, you can't see the leaks from
the program you ran with "adb shell".

Bug: 7291287
Change-Id: Ib8780db72ba0114ebdb24768537da74bbb61f354
alloc_debug_common.cpp
2b473070126345e323d0694b87f88264cc9a77cc 23-Jan-2013 Elliott Hughes <enh@google.com> Our strcoll(3) is no different from NetBSD's, so take exactly theirs.

Change-Id: I45251047202a229f9175735ecc23c0ebcda71e8d
trcoll.c
c51cd764a2d0897234762abd4dbd21420cb9f17d 22-Jan-2013 Elliott Hughes <enh@google.com> Avoid overflow in memccpy.

Just take the upstream NetBSD code.

Bug: http://code.google.com/p/android/issues/detail?id=43078
Change-Id: Ibbbde9d00e8bc6a09c9503aab2b04b4e3d1f98b0
emccpy.c
ce4cf90d7993ec7b9abc79bc86ede4d8758a49ab 22-Jan-2013 Elliott Hughes <enh@google.com> Use the new non-allocating logging for dlmalloc failures.

Change-Id: I88afe0201ee5766a295fc5a9e710fba9d6e0d363
lmalloc.c
f90b95ea1a46b0685d1051c41a02a9abc25f3f35 22-Jan-2013 Elliott Hughes <enh@google.com> Add missing extern "C".

Change-Id: Idbf24ce8482ff03f24caa89bafb08677b1c5cec3
thread_debug.cpp
1e980b6bc8315d00a07312b25486531247abd98c 18-Jan-2013 Elliott Hughes <enh@google.com> Fix the duplication in the debugging code.

We had two copies of the backtrace code, and two copies of the
libcorkscrew /proc/pid/maps code. This patch gets us down to one.

We also had hacks so we could log in the malloc debugging code.
This patch pulls the non-allocating "printf" code out of the
dynamic linker so everyone can share.

This patch also makes the leak diagnostics easier to read, and
makes it possible to paste them directly into the 'stack' tool (by
using relative PCs).

This patch also fixes the stdio standard stream leak that was
causing a leak warning every time tf_daemon ran.

Bug: 7291287
Change-Id: I66e4083ac2c5606c8d2737cb45c8ac8a32c7cfe8
ssert.cpp
ebug_format.cpp
ebug_mapinfo.cpp
ebug_mapinfo.h
ebug_stacktrace.cpp
ebug_stacktrace.h
ogd_write.c
alloc_debug_check.cpp
alloc_debug_check_mapinfo.cpp
alloc_debug_check_mapinfo.h
alloc_debug_common.cpp
alloc_debug_common.h
alloc_debug_leak.cpp
alloc_debug_qemu.cpp
alloc_debug_stacktrace.cpp
thread.c
thread_debug.c
thread_debug.cpp
sp.cpp
tubs.cpp
36bd371e26c716cbc18e11801b13eff0352d91b0 16-Jan-2013 Nick Kralevich <nnk@google.com> Revert "stack protector: use AT_RANDOM"

The AT_RANDOM changes broke setuid / setgid executables
such as "ping". When the linker executes a setuid program,
it cleans the environment, removing any invalid environment
entries, and adding "NULL"s to the end of the environment
array for each removed variable. Later on, we try to determine
the location of the aux environment variable, and get tripped
up by these extra NULLs.

Reverting this patch will get setuid executables working again,
but getauxval() is still broken for setuid programs because of
this bug.

This reverts commit e3a49a8661125f24aec8a1453e54b3b78005e21e.

Change-Id: I05c58a896b1fe32cfb5d95d43b096045cda0aa4a
ibc_init_common.c
ibc_init_static.c
e3a49a8661125f24aec8a1453e54b3b78005e21e 14-Jan-2013 Nick Kralevich <nnk@google.com> stack protector: use AT_RANDOM

Populate the stack canaries from the kernel supplied
AT_RANDOM value, which doesn't involve any system calls.
This is slightly faster (6 fewer syscalls) and avoids
unnecessarily reading /dev/urandom, which depletes entropy.

Bug: 7959813

Change-Id: If2b43100a2a9929666df3de56b6139fed969e0f1
ibc_init_common.c
ibc_init_static.c
68fa57f000285af20100c00db3d2bc143ad32294 14-Jan-2013 Ian Rogers <irogers@google.com> Merge "Name anonymous mmap mallocs."
9fb48ac257d9a01ba99c6c9ced497b24512a86b7 12-Jan-2013 Nick Kralevich <nnk@google.com> libc_init_static: apply relro earlier.

The dynamic linker applies relro before the preinit and init
arrays are executed, so we should be consistent for statically
linked executables.

Change-Id: Ia0a49d0e981a6e8791f74eed00280edf576ba139
ibc_init_static.c
8921060253f95fa77dbfe96ddaab5a39c446a49e 12-Jan-2013 Ian Rogers <irogers@google.com> Name anonymous mmap mallocs.

Change-Id: Icc53ba1eecb8445210623826d8e99a611d686f7f
lmalloc.c
2c5153b043b44e9935a334ae9b2d5a4bc5258b40 11-Jan-2013 Nick Kralevich <nnk@google.com> libc: add getauxval()

Add support for getauxval(). This method allows a program an easy way
to retrieve information from the kernel auxiliary vector, and will
hopefully replace other clumsy ways of accessing this same information.

This particular function was also added to glibc in glibc 2.16.
See the following URLs for more details.

* http://lwn.net/Articles/519085/
* http://www.gnu.org/software/libc/manual/html_node/Auxiliary-Vector.html

This change is a prerequisite for bug 7959813.

Bug: http://code.google.com/p/android/issues/detail?id=38441
Change-Id: Iba19d899df334bddc6f4899077ece2fc87564ea8
etauxval.cpp
ibc_init_common.c
ibc_init_static.c
a12c54454f3a6132988b68873903f6e9eed7f384 09-Jan-2013 Wink Saville <wink@google.com> Fix unused warnings in pthread.c

Change-Id: I0287aadb825fd8cda29dc976bce55d75a1279fc5
thread.c
e6e60065ff093ff8c859ab146cf543531cb1967c 11-Jan-2013 Elliott Hughes <enh@google.com> glibc 2.15 treats errno as signed in strerror(3).

And the only reason I hadn't done that in bionic is because I wanted to behave
the same as glibc.

Change-Id: I2cf1bf0aac82a748cd6305a2cabbac0790058570
trerror_r.cpp
c5d028fc913de84a781bd61084bf7ae2182fd48e 10-Jan-2013 Elliott Hughes <enh@google.com> Only have one copy of the kernel_sigset_t hack, and add more tests.

Change-Id: I377522fcba6fb4b5fd2754ab15b091014bd7c16f
thread.c
thread_sigmask.cpp
ignalfd.cpp
igwait.c
igwait.cpp
a4b2dc016fa62bd172a73c3f8971c805700ffb0f 10-Jan-2013 Rom Lemarchand <romlem@google.com> Add signalfd call to bionic

Add signalfd() call to bionic.

Adding the signalfd call was done in 3 steps:
- add signalfd4 system call (function name and syscall
number) to libc/SYSCALLS.TXT
- generate all necessary headers by calling
libc/tools/gensyscalls.py. This patch is adding
the generated files since the build system
does not call gensyscalls.py.
- create the signalfd wrapper in signalfd.cpp and add
the function prototype to sys/signalfd.h

(cherry-pick of 0c11611c11f4dc1b6d43587b72c3ccbe8c51a51c, modified to
work with older versions of GCC still in use on some branches.)

Change-Id: I4c6c3f12199559af8be63f93a5336851b7e63355
ignalfd.cpp
db492b3ca753c4ef688d0daf648294de0c89145e 04-Jan-2013 Elliott Hughes <enh@google.com> Fix debug malloc.

...which has been broken since the linker data structures went read-only.

Bug: 7941716
Change-Id: If28f6bac0fcb13e371e4d85b064544f561c8d692
alloc_debug_common.cpp
7cbff41ba3d89e98980fdc61ebbf6058d1c94d05 03-Jan-2013 Elliott Hughes <enh@google.com> sysconf.c was renamed to sysconf.cpp (and modified)...

...but sysconf.c still lingers on due to some git/repo accident. Kill it.

Change-Id: Iae354ecb21abf03a3f718cc45cfdddb7a9347778
ysconf.c
a55f63083fb16b2595f517a3260083e5f8cddd02 02-Jan-2013 Elliott Hughes <enh@google.com> Define _POSIX_MONOTONIC_CLOCK and implement sysconf(_SC_MONOTONIC_CLOCK).

Bug: http://code.google.com/p/android/issues/detail?id=39680
Change-Id: I11cf10a66f9d305868a725f04f581099fb88bbfc
ysconf.cpp
d8a5a6f513c6fa99229e9c82c5c308c7cd6b3d54 08-Dec-2012 Chris Dearman <chris@mips.com> Use pthread_kill() in raise()

raise() should use pthread_kill() in a pthreads environment.
For bionic this means it should always be used.

Change-Id: Ic679272b664d2b8a7068b628fb83a9f7395c441f
aise.c
aise.cpp
8b6fea59ac89147297c770f5dc298e0d5a99984f 06-Dec-2012 Nick Kralevich <nnk@google.com> FORTIFY_SOURCE: fix up previous commit

I forgot two files in 326ea5413d18ea019cd1bda415ce428f7bdcafd2.

Change-Id: I30430f65bfafad4274193fc5b973959eac0791a7
pen.c
penat.c
326ea5413d18ea019cd1bda415ce428f7bdcafd2 04-Dec-2012 Nick Kralevich <nnk@google.com> clean up FORTIFY_SOURCE handling.

Avoid duplicating huge chunks of code.

Change-Id: Id6145cdfce781c5ffba2abaaa79681d25a7ab28f
_fgets_chk.cpp
_memcpy_chk.cpp
_memmove_chk.cpp
_memset_chk.cpp
_strcat_chk.cpp
_strcpy_chk.cpp
_strlcat_chk.cpp
_strlcpy_chk.cpp
_strlen_chk.cpp
_strncat_chk.cpp
_strncpy_chk.cpp
_umask_chk.cpp
_vsnprintf_chk.cpp
_vsprintf_chk.cpp
ogd_write.c
60fb68338b7541b6022fc343857b90c088c399cd 03-Dec-2012 Elliott Hughes <enh@google.com> Merge "mmap: Remove madvise() workaround"
4a9e837840fda3aaea48aeba85c7c7a8782d2586 30-Nov-2012 Elliott Hughes <enh@google.com> Reduce the exposure of the __set_errno implementation detail.

Change-Id: I395e1b46a9491e34fc53e71853e932ea90b3d1cc
_set_errno.c
_set_errno.cpp
thread.c
635df850e5037be5093f64a87ec2e0a23bf7a50b 19-Nov-2012 Nick Kralevich <nnk@google.com> mmap: Remove madvise() workaround

Remove mmap() calling madvise(MADV_MERGEABLE) added
in b8e1e9685efc82d6ac112b9aa316e7f6bf5186ca

Change-Id: I80dbf6afe750348964d83097f993ea6cb8a065d5
map.c
ac3de8d080745e62c77fdf03e3923726d0a6b50d 10-Nov-2012 Nick Kralevich <nnk@google.com> Support GNU_RELRO for static executables.

In 9ec0f03a0d0b17bbb94ac0b9fef6add28a133c3a, we added dynamic
linker support for GNU_RELRO protections. These protections
make certain regions of memory read-only, helping protect certain
data structures from accidental or deliberate modifications.

This change adds GNU_RELRO support to STATIC executables. We can
determine if we're compiled with relro protections by examining
our own program headers, which is passed to us by the kernel
in the AT_PHDR and AT_PHNUM auxiliary vectors.

Parts of this code were stolen from the dynamic linker.

Change-Id: Ic17eb5f932218538ec25347ece314d4dc7549de1
ibc_init_static.c
4f251bee5d51228217c1bf4dfc9219f3058bd3ed 02-Nov-2012 Elliott Hughes <enh@google.com> Don't corrupt the thread list if the main thread exits.

...and don't pass a non-heap pointer to free(3), either.

This patch replaces the "node** prev" with the clearer "node* prev"
style and fixes the null pointer dereference in the old code. That's
not sufficient to fix the reporter's bug, though. The pthread_internal_t*
for the main thread isn't heap-allocated --- __libc_init_tls causes a
pointer to a statically-allocated pthread_internal_t to be added to
the thread list.

Bug: http://code.google.com/p/android/issues/detail?id=37410
Change-Id: I112b7f22782fc789d58f9c783f7b323bda8fb8b7
ibc_init_common.c
thread.c
thread_internal.h
06b596104a9ed3ac089abd00186a5698d7e8544f 30-Oct-2012 Elliott Hughes <enh@google.com> Merge "Fix bug in pthread_join, pthread_exit, pthread_detach"
58b575485c446f9d76ee00f67516ed42cf017769 29-Oct-2012 Elliott Hughes <enh@google.com> Clean up the <libgen.h> implementation a little, bring in tests.

Most of these tests were in system/extras, but I've added more to cover other
cases explicitly mentioned by POSIX.

Change-Id: I5e8d77e4179028d77306935cceadbb505515dcde
asename.c
asename_r.c
irname.c
irname_r.c
ibgen.cpp
10ce96944eaea4c459392952652fdb24742c9c29 26-Oct-2012 Sergey Melnikov <sergey.melnikov@intel.com> Fix bug in pthread_join, pthread_exit, pthread_detach

pthread_no_op_detach_after_join test from bionic-unit-tests hangs
on x86 emulator. There is a race in the pthread_join, pthread_exit,
pthread_detach functions:
- pthread_join waits for the non-detached thread
- pthread_detach sets the detached flag on that thread
- the thread executes pthread_exit which just kills the now-detached
thread, without sending the join notification.

This patch improves the test so it fails on ARM too, and modifies
pthread_detach to behave more like glibc, not setting the detach state if
called on a thread that's already being joined (but not returning an error).

Change-Id: I87dc688221ce979ef5178753dd63d01ac0b108e6
Signed-off-by: Sergey Melnikov <sergey.melnikov@intel.com>
thread.c
14f19592ae7c819855052bcebc79de87069c2954 29-Oct-2012 Elliott Hughes <enh@google.com> Fix the pthread_join on self error case.

We should return EDEADLK, not deadlock the calling thread.

Change-Id: I1243483f709c11b2a60e41142725c54c7dbfcbc9
thread.c
ae8eb74675722b57ab66a51f1d6f4f250137bb23 27-Oct-2012 Xi Wang <xi.wang@gmail.com> Fix a potential NULL pointer dereference in _init_thread().

The first NULL pointer check against `attr' suggests that `attr' can
be NULL. Then later `attr' is directly dereferenced, suggesting the
opposite.

if (attr == NULL) {
...
} else {
...
}
...
if (attr->stack_base == ...) { ... }

The public API pthread_create(3) allows NULL, and interprets it as "default".
Our implementation actually swaps in a pointer to the global default
pthread_attr_t, so we don't need any NULL checks in _init_thread. (The other
internal caller passes its own pthread_attr_t.)

Change-Id: I0a4e79b83f5989249556a07eed1f2887e96c915e
Signed-off-by: Xi Wang <xi.wang@gmail.com>
thread.c
thread_internal.h
c30396f5f225e0b5a83a35432e2d82a7063cfdb9 29-Oct-2012 David 'Digit' Turner <digit@android.com> libc: Fix alphasort() signature (and implementation).

The declaration for alphasort() in <dirent.h> used the deprecated:

int alphasort(const void*, const void*);

while both Posix and GLibc use instead:

int alphasort(const struct dirent** a, const struct dirent** b);

See: http://pubs.opengroup.org/onlinepubs/9699919799/functions/alphasort.html

This patch does the following:

- Update the declaration to match Posix/GLibc
- Get rid of the upstream BSD code which isn't compatible with the new
signature.
- Implement a new trivial alphasort() with the right signature, and
ensure that it uses strcoll() instead of strcmp().
- Remove Bionic-specific #ifdef .. #else .. #endif block in
dirent_test.cpp which uses alphasort().

Even through strcoll() currently uses strcmp(), this does the right
thing in the case where we decide to update strcoll() to properly
implement locale-specific ordered comparison.

Change-Id: I4fd45604d8a940aaf2eb0ecd7d73e2f11c9bca96
irent.cpp
pendir.cpp
063cfb2084ea4b12d3c85b2d2c44e888f0857eb4 26-Oct-2012 Elliott Hughes <enh@google.com> Clean up the implementation of the <dirent.h> functions.

Change-Id: I3c647cc9588525afc41fee90ee468d58cd13503a
pendir.c
pendir.cpp
ysconf.c
ad88a0863110798cef5169dcf917e18b967a7cf6 25-Oct-2012 Elliott Hughes <enh@google.com> Per-thread -fstack-protector guards for x86.

Based on a pair of patches from Intel:

https://android-review.googlesource.com/#/c/43909/
https://android-review.googlesource.com/#/c/44903/

For x86, this patch supports _both_ the global that ARM/MIPS use
and the per-thread TLS entry (%gs:20) that GCC uses by default. This
lets us support binaries built with any x86 toolchain (right now,
the NDK is emitting x86 code that uses the global).

I've also extended the original tests to cover ARM/MIPS too, and
be a little more thorough for x86.

Change-Id: I02f279a80c6b626aecad449771dec91df235ad01
thread.c
sp.c
sp.cpp
ab44f52202878cdf2bf22457aeae33ec24089556 24-Oct-2012 Elliott Hughes <enh@google.com> More upstream NetBSD upgrades.

Change-Id: Idb781d37de3b05585271d7d258ecffd5ba87d0b8
ssert.cpp
ventfd.c
ventfd.cpp
e8bcca3a2ca4a70156c72239d62bb68eeb2929fd 23-Oct-2012 Elliott Hughes <enh@google.com> Upgrade more functions to the current upstream NetBSD copy.

Change-Id: Ie0b3f8b3fccef28609eb210434413ebd51d6ef45
ha1.c
destroy.c
destroy.cpp
time.c
29c7f0b4d18f812267c2194b85204e19e41d0387 23-Oct-2012 Elliott Hughes <enh@google.com> Move setlocale(3) and the wchar stubs over to .cpp.

Also separate out the C++ files so we can use -Werror on them. I'd
rather wait for LOCAL_CPPFLAGS to be in AOSP, but this also lets us
see which files still need to be sorted into one bucket or the other.

Change-Id: I6acc1f7c043935c70a3b089f705d218b9aaaba0a
ocale.c
etlocale.cpp
char.c
char.cpp
6fa26e21bc69e777222148fc0441fb461ba95c6a 23-Oct-2012 Elliott Hughes <enh@google.com> Clean up warnings in stubs.cpp.

Change-Id: Ie0792846de7cf5f5c72737494bf78ab8dcb8cc3e
tubs.cpp
4035b7a32155eac46f3f3782774deb5967ea2b54 23-Oct-2012 Elliott Hughes <enh@google.com> Move the FORTIFY_SOURCE helpers over to .cpp.

Change-Id: Ib5067d51b983cac7760c975becce7fe2408ead04
_fgets_chk.c
_fgets_chk.cpp
_memcpy_chk.c
_memcpy_chk.cpp
_memmove_chk.c
_memmove_chk.cpp
_memset_chk.c
_memset_chk.cpp
_snprintf_chk.c
_sprintf_chk.c
_strcat_chk.c
_strcat_chk.cpp
_strcpy_chk.c
_strcpy_chk.cpp
_strlcat_chk.c
_strlcat_chk.cpp
_strlcpy_chk.c
_strlcpy_chk.cpp
_strlen_chk.c
_strlen_chk.cpp
_strncat_chk.c
_strncat_chk.cpp
_strncpy_chk.c
_strncpy_chk.cpp
_umask_chk.c
_umask_chk.cpp
_vsnprintf_chk.c
_vsnprintf_chk.cpp
_vsprintf_chk.c
_vsprintf_chk.cpp
5419b9474753d25dff947c7740532f86d130c0be 17-Oct-2012 Elliott Hughes <enh@google.com> Make dlerror(3) thread-safe.

I gave up trying to use the usual thread-local buffer idiom; calls to
calloc(3) and free(3) from any of the "dl" functions -- which live in
the dynamic linker -- end up resolving to the dynamic linker's stubs.
I tried to work around that, but was just making things more complicated.
This alternative costs us a well-known TLS slot (instead of the
dynamically-allocated TLS slot we'd have used otherwise, so no difference
there), plus an extra buffer inside every pthread_internal_t.

Bug: 5404023
Change-Id: Ie9614edd05b6d1eeaf7bf9172792d616c6361767
hreadLocalBuffer.h
thread.c
thread_internal.h
trerror.cpp
trsignal.cpp
e7e274b13a44a63023f22630ac282ee2e919ffb7 13-Oct-2012 Elliott Hughes <enh@google.com> Fix realloc(3) when chk_malloc debugging is on.

The tests for a NULL pointer and size 0 were the wrong way round.

From Intel's patch 9cae4f2ffc4778ed82be04711d8775a84092d4e2.

Change-Id: I118aff3358aa5f34126d74bfaa43f6e2f1a89055
alloc_debug_check.cpp
3b297c40794b23d50cb5240f9b03f6ef25fd98db 12-Oct-2012 Elliott Hughes <enh@google.com> Fix dlerror(3).

Add unit tests for dlerror(3) in various situations. I think We're at least
as good as glibc now.

Also factor out the ScopedPthreadMutexLock and use it here too.

Bug: http://code.google.com/p/android/issues/detail?id=38398
Change-Id: I040938b4366ab836e3df46d1d8055b92f4ea6ed8
alloc_debug_check.cpp
alloc_debug_common.cpp
alloc_debug_common.h
alloc_debug_leak.cpp
1ceb9824ab39501e98300bc87f7984ee6b455ce8 10-Oct-2012 Elliott Hughes <enh@google.com> Merge "Fix a getcwd(3) bug and make our tests run correctly under valgrind."
e5d5f7f0d8262178f9f69e78e3a4fbd71a34853c 10-Oct-2012 Elliott Hughes <enh@google.com> Fix two comment typos.

Change-Id: Icb2d6f7fa97ef5a4409a7606875e416cfab0a4b3
alloc_debug_common.cpp
alloc_debug_leak.cpp
156da966214957c5616a0b83cc84686eedfc4e31 10-Oct-2012 Elliott Hughes <enh@google.com> Fix a getcwd(3) bug and make our tests run correctly under valgrind.

The getcwd(3) bug was found by valgrind.

Bug: 7291287
Change-Id: I59f3bff1c1392a408b905934eebcd5d894d37492
etcwd.cpp
a89864a20b818621a1da10e88fda815334062f9f 02-Oct-2012 Elliott Hughes <enh@google.com> Move non-upstream code into the libc/bionic directory.

I'll need at least one more pass, because there's some upstream code
lurking in libc/bionic, but this is still a step in the right direction.

Change-Id: I55927315972da8327ae01c5240ed587db17e8462
_fgets_chk.c
_memcpy_chk.c
_memmove_chk.c
_memset_chk.c
_snprintf_chk.c
_sprintf_chk.c
_strcat_chk.c
_strcpy_chk.c
_strlcat_chk.c
_strlcpy_chk.c
_strlen_chk.c
_strncat_chk.c
_strncpy_chk.c
_vsnprintf_chk.c
_vsprintf_chk.c
toi.c
tol.c
toll.c
indresvport.c
rk.c
aemon.c
ther_aton.c
ther_ntoa.c
ventfd.c
cntl.c
lockfile.c
statfs.c
time.c
tok.c
etdtablesize.c
ethostname.c
etpgrp.c
etpriority.c
etpt.c
nitgroups.c
satty.c
ssetugid.c
ocale.c
seek64.c
emccpy.c
emchr.c
emcmp.c
emcpy.c
emmem.c
emmove.c
emrchr.c
emset.c
emswap.c
map.c
pen.c
penat.c
pendir.c
athconf.c
error.c
read.c
select.c
tsname.c
tsname_r.c
write.c
aise.c
eboot.c
ecv.c
brk.c
end.c
etegid.c
eteuid.c
etpgrp.c
etresuid.c
etreuid.c
etuid.c
igblock.c
iginterrupt.c
iglist.c
ignal.c
igname.c
igsetmask.c
igsuspend.c
igwait.c
leep.c
ocketcalls.c
tatfs.c
trcoll.c
trndup.c
trnlen.c
trntoimax.c
trntoumax.c
trtotimeval.c
ysconf.c
cgetpgrp.c
csetpgrp.c
mount.c
nlockpt.c
sleep.c
ait.c
char.c
cscoll.c
774c7f54ff375d71106283d42779b0cc5f238f87 01-Oct-2012 Elliott Hughes <enh@google.com> Upgrade to the current NetBSD rand implementation.

Also add basic unit tests.

Change-Id: I7fc7ef61d47c1e8fdf8b8eff67a635220c3afd56
rand48.c
rand48.c
ac184b21425a0681c51ef152f0567168b575da49 26-Sep-2012 Elliott Hughes <enh@google.com> Fix several compiler warnings.

Change-Id: I55caa50a5937442734f4fcbdb4edf1c70f335bf8
mpfile.cpp
855dde44266e3c8384ea419f51f9a5c748253eda 26-Sep-2012 Elliott Hughes <enh@google.com> Merge "Fix tmpfile(3)."
91875dcd6e17b7f3b251efe9b236b905ef414dde 25-Sep-2012 Elliott Hughes <enh@google.com> Fix tmpfile(3).

This could be better, but at least now it works.

Change-Id: I88b7cf3f7ce8e5fa0b3fe678b7d1679a68ffffc9
mpfile.cpp
cd587701c8590fb34bb69804b5d3b3c14d3d2508 26-Sep-2012 Nick Kralevich <nnk@google.com> FORTIFY_SOURCE: add umask check

Verify that the call to umask makes sense. While this wouldn't
have detected bug 7094213 (because the low order bits were all zero),
it might detect other similar bugs.

References: https://code.google.com/p/android-source-browsing/source/detail?r=acba45cc4b1f98f67fcdeda2f7c13ed57659b92a&repo=platform--libcore

Change-Id: I966a531d6b3cf8e1c5eacd69bd3cbec475b5fa58
_umask_chk.c
95a7a64ac8b242f278f515b06bdb6057ecca4396 22-Sep-2012 Elliott Hughes <enh@google.com> Use hidden visibility for several internal-use-only functions.

Change-Id: Ibeea6963ff0cc06479d0a3ed7e868eeece8c55a0
trerror_r.cpp
88f1ea8f82e1fcef0d472577f00cd889b796e944 18-Sep-2012 Dave Burke <daveburke@google.com> Make pthread_create more forgiving of invalid sched_policy.
Bug: 7005326

(cherry-pick of e58303249b9e799a4fe84c5a2dfe71518441a6ec.)

Change-Id: Ie81494e0f6a71caa6fd9fabbcfc47a23077554d6
thread.c
4198fa4c23fc8a1895808a597bb153530f6ea515 18-Sep-2012 Elliott Hughes <enh@google.com> Don't copy strerror(3) or strsignal(3) strings if we can share.

Change-Id: Ic405269f63b945c6fb347e7c4346cd6f104aff35
trerror.cpp
trerror_r.cpp
trsignal.cpp
8a05a01de75d78a45d646115b20b2a3e3c12ba9e 13-Sep-2012 Kenny Root <kroot@google.com> Print out shared app gids correctly

For applications that share resources across users such as
forward-locked applications, print out their group name correctly.

Change-Id: I06ee0b67e4325cfa415ffd7a03e301700399a66d
tubs.cpp
2a54e5ecd0a96398e8d7d9b1629ecf8fb1633a2b 13-Sep-2012 Kenny Root <kroot@google.com> Add tests for Android-specific stubs

Also fix problem with multi-user IDs that the home directory was
returned as "/data" instead of "/" unlike all the other uids.

Change-Id: I914d22052e5a86552989f8969b85aadbc748c65d
tubs.cpp
b5f053b5a7deb084e7a052d527e0aa41339ae05c 08-Sep-2012 Irina Tirdea <irina.tirdea@intel.com> Make strerror(3) and strsignal(3) thread-safe, and add psignal(3) and psiginfo(3).

Change-Id: I426109db25e907980d6cb3a7a695796e45783b78
hreadLocalBuffer.h
trerror.cpp
trerror_r.cpp
trsignal.cpp
bfeab1bbe7e8d0c08b7e3f46aedab64e3b2bf706 06-Sep-2012 Elliott Hughes <enh@google.com> Don't corrupt the thread list in static executables.

Several previous changes conspired to make a mess of the thread list
in static binaries. This was most obvious when trying to call
pthread_key_delete(3) on the main thread.

Bug: http://code.google.com/p/android/issues/detail?id=36893
Change-Id: I2a2f553114d8fb40533c481252b410c10656da2e
ibc_init_common.c
ibc_init_static.c
thread.c
thread_internal.h
3e2d2936b0447ed2f0b0aab3625494b2533cd422 31-Aug-2012 Kirill Artamonov <kartamonov@nvidia.com> Avoid malloc lock while calling pthread_atfork.

Expecting the memory in a forked child process to be sane wrt threading
is a bad idea. An example of a problem is when the parent process has
the malloc lock and a child process is forked. The malloc lock in the
child will appear locked by a thread that doesn't exist.

This change aims to make bionic more compatible with glibc by reseting
the malloc lock in the child forked process, as well as holding it
during the fork. This is a feature in dlmalloc 2.8.6 called
LOCK_AT_FORK. In general this feature isn't necessary as a forked
process will then exec. Some bad applications rely on being able to use
features like malloc before the exec and having multiple threads running
in the parent program. This isn't a problem with glibc and this patch
makes it not a problem for bionic.

Unfortunately for use in bionic, LOCK_AT_FORK has an issue as internally
it uses pthread_atfork that in bionic uses malloc. This leads to the
LOCK_AT_FORK initialization deadlocking with pthread_atfork's call to
malloc due to the malloc lock. This change moves the pthread_atfork logic
in LOCK_AT_FORK to be called without the malloc lock held.

Change-Id: Id68175a564a6abb936ee4488b44d9479f7311f69
lmalloc.h
6fe901ef38898d9cb6007720940e915f7180fc11 31-Aug-2012 Ian Rogers <irogers@google.com> Merge "Upgrade to dlmalloc 2.8.6."
c6d95add30dc24674bdcb39f69812c115e4205fd 29-Aug-2012 Ian Rogers <irogers@google.com> Upgrade to dlmalloc 2.8.6.

This fixes a bug and enables the use of MORECORE_CONTIGUOUS.

Change-Id: Ia7c5d32bdc46e99b3ecb92ee94d1f702c4385d5d
lmalloc.h
0d7177c0d47517514c81713427fc28e04dc3cd37 29-Aug-2012 Elliott Hughes <enh@google.com> Merge "Clean up warnings in the malloc_debug_* files."
c4d1fecc105063e68a5090a6900b63d1b9a24287 28-Aug-2012 Elliott Hughes <enh@google.com> Clean up warnings in the malloc_debug_* files.

Also clean up cpplint.py-detected lint.

Change-Id: Ia18e89c4c6878764f8d7ed34b8247e7a8d8fe88b
etcwd.cpp
alloc_debug_check.c
alloc_debug_check.cpp
alloc_debug_check_mapinfo.c
alloc_debug_check_mapinfo.cpp
alloc_debug_check_mapinfo.h
alloc_debug_common.c
alloc_debug_common.cpp
alloc_debug_common.h
alloc_debug_leak.c
alloc_debug_leak.cpp
alloc_debug_qemu.c
alloc_debug_qemu.cpp
alloc_debug_stacktrace.c
alloc_debug_stacktrace.cpp
tubs.cpp
0a150ead18019c0e4e59417ae3c5e8e0d7d2e4f4 21-Aug-2012 Ard Biesheuvel <ard.biesheuvel@gmail.com> libc: remove ctors/dtors sections

None of the supported ARCHs actually populate these sections,
so there is no point in keeping them in the binaries.

Change-Id: I21a364f510118ac1114e1b49c53ec8c895c6bc6b
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
ibc_init_common.h
ibc_init_static.c
bfc1d97531fa611ad2705c7179134b60e652ead4 21-Aug-2012 Brian Carlstrom <bdc@google.com> Restore posix_memalign

Change-Id: I24e31bcb8b1d8be9375852e76964f09becd11938
alloc_debug_common.c
999089181ef60bb67e1a49f2cf6f4ec608a7caf8 18-Aug-2012 Ian Rogers <irogers@google.com> Upgrade to dlmalloc 2.8.5.

Move dlmalloc code to upstream-dlmalloc to make pulling upstream changes
easier.
Declare pvalloc and malloc_usable_size routines present in malloc.h but with
missing implementations. Remove other functions from malloc.h that have
no implementation nor use in Android.

Change-Id: Ia6472ec6cbebc9ad1ef99f4669de9d33fcc2efb4
lmalloc.c
lmalloc.h
alloc_debug_common.c
2932f048327965731c7e1ab9f2968a2ddb1854f5 05-Jul-2012 Jurijs Oniscuks <jurijs.oniscuks@sonymobile.com> Fix race condition in pthread_create()

Save thread id to *thread_out before new
thread is allowed to run else there's a
risk that the thread has finished and
been deleted when *thread_out is assigned.

Change-Id: I6b84c61a8df06840877d4ab036f26feace3192d8
thread.c
b7beb6907599b36809effe1b4db76039ac649518 16-Aug-2012 Pavel Chupin <pavel.v.chupin@intel.com> Add link.h for all platforms with dl_phdr_info

This header is used on bionic build and should be propagated into
sysroot on toolchain rebuild. Discussion re. this header is here:
http://gcc.gnu.org/ml/gcc-patches/2012-08/msg00936.html

It is available already in mips NDK platforms:
development/ndk/platforms/android-9/arch-mips/include/link.h

Change-Id: I39ff467cdac9f448e31c11ee3e14a6200e82ab57
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
l_iterate_phdr_static.c
04a83a48ed89f433c78e31106ed50059764797a0 17-Aug-2012 Elliott Hughes <enh@google.com> Enhance getcwd(3) to handle NULL like glibc.

Bug: http://code.google.com/p/android/issues/detail?id=36085
Change-Id: I960a1b585887eb66176c61d29c5c61c239a4003f
etcwd.cpp
9862f5e08bcbf51c80542fb148fc505df140cb95 01-Aug-2012 Jin Wei <wei.a.jin@intel.com> bionic: add macro protection for MALLOC_ALIGNMENT

In previous commit: 2fd81ef7, .mk file has been modified to
configure MALLOC_ALIGNMENT dynamicly according to board config.
Add the missing macor protection here.

Change-Id: I703cca2ce0504ab3e11aab226b2c61fcc0c6afa1
Author: Jin Wei <wei.a.jin@intel.com>
Signed-off-by: Xiaokang Qin <xiaokang.qin@intel.com>
Signed-off-by: Beare, Bruce J <bruce.j.beare@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
alloc_debug_leak.c
22d366cc09383956dc264ed4641572e609392eee 08-Aug-2012 Jin Wei <wei.a.jin@intel.com> enable clone system call for x86

Add __bionic_clone function for x86, which will be
used for clone system call.

Change-Id: I889dc9bf4b7ebb4358476e17e6f3233e26491f4d
Signed-off-by: Jin Wei <wei.a.jin@intel.com>
Signed-off-by: Xiaokang Qin <xiaokang.qin@intel.com>
Signed-off-by: Beare, Bruce J <bruce.j.beare@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Author-tracking-BZ: 51414
ionic_clone.c
409302f0f9fce73ea4c82bbfd439041cd7923d34 14-Aug-2012 Elliott Hughes <enh@google.com> Switch to upstream NetBSD tdelete/tfind/tsearch.

tdestroy is a GNU extension, so that stays.

Change-Id: Iedebaff25ea7e92b1ab1dd4440da12b67b99aa40
delete.c
destroy.c
find.c
search.c
de727caee24df86c3052508aa213f7165168913a 14-Aug-2012 Elliott Hughes <enh@google.com> Clean up warnings in stubs.cpp.

Switch to C++ to get extra warnings, and format the code Google style.

Change-Id: Ifc0131bf297a6ee8a8a6b8d049a02518b0b1a4b7
tubs.c
tubs.cpp
bf9441efb8dae6c26ee649f70b8dbb6116932828 13-Aug-2012 Amith Yamasani <yamasani@google.com> Handle naming for system uids running as secondary users

Allow naming such as u1_system, u2_radio, u2_media.
Forward and reverse mapping for the above.

(cherry-pick of c60a0027b1ef3bc4929d2023e7083fbce12fafe7.)

Change-Id: I46eeb23fee4f57b2907640570504123d3ce99985
tubs.c
a5542129923d9c313fe9c3b97ab9bc822ca5c5f6 09-Aug-2012 Elliott Hughes <enh@google.com> Remove the last .jam file.

How did I miss this before?

Change-Id: I2e582133fc4800656fdd81104f8dfc7ee8f5b580
ules.jam
7e248be76441daa0ee27cc461c806e6010405c25 08-Aug-2012 Jean-Baptiste Queru <jbq@google.com> Merge "Add a .note.android.ident section to Android ELF binaries."
405b8029a6888f386adf3512113a33546141d1c8 26-Jul-2012 Raghu Gandham <raghu@mips.com> MIPS support for libc.

Change-Id: I2864dea04b3faf2d919165dcaa600af5b16c41c8
Signed-off-by: Chris Dearman <chris@mips.com>
Signed-off-by: Raghu Gandham <raghu@mips.com>
l_iterate_phdr_static.c
ea8fad11d980d55ebd2bcf2302f3f1f742b6351c 31-Jul-2012 Michael Hope <michael.hope@linaro.org> Add a .note.android.ident section to Android ELF binaries.

This allows debugging tools to know they are working with Android
binaries and adapt accordingly.

Signed-off-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Signed-off-by: Michael Hope <michael.hope@linaro.org>

Change-Id: Ic906992fcad61c028bb765821637a3e1333bf52b
rtbrand.c
52d6233296ec84eb5b58fcbf7bc9da4b96a943aa 28-Jul-2012 Elliott Hughes <enh@google.com> Report errors to the log, not just stderr.

In particular this affects assert(3) and __cxa_pure_virtual, both of
which have managed to confuse people this week by apparently aborting
without reason. (Because stderr goes nowhere, normally.)

Bug: 6852995
Bug: 6840813
Change-Id: I7f5d17d5ddda439e217b7932096702dc013b9142
tubs.c
c20d0f3993ebb0d3dec958a306a68ebb48bfeadd 19-Jul-2012 Jens Gulin <jens.gulin@sonymobile.com> Correction to use of TEMP_FAILURE_RETRY in send_prop_msg

RETRY macro may retry command if result is -1. In this
case the command was "connect < 0" instead of just
connect. The comparison will not return -1 and thus
retry is never done. This is now corrected so that
interrupts will cause retry instead of fail.

(There was no other negative side effect of the bug.
The result code from RETRY was used in an if-statement
and it would be true for all negative connect results.
This was according to expectations.)

Change-Id: Ie206b39878e9befea4e3be9a4061ee39eb232d80
ystem_properties.c
f2ba5c9afa750cc5b7cd4737071b73ce1f01f252 19-Jun-2012 Andy McFadden <fadden@android.com> am 63c4179f: am 4d0128f1: Merge "Minor tweak to get memory around corrupted heap chunks dumped." into jb-dev

* commit '63c4179f5951edc2d68700fe75659fbd34febe63':
Minor tweak to get memory around corrupted heap chunks dumped.
63c4179f5951edc2d68700fe75659fbd34febe63 19-Jun-2012 Andy McFadden <fadden@android.com> am 4d0128f1: Merge "Minor tweak to get memory around corrupted heap chunks dumped." into jb-dev

* commit '4d0128f13a3ca9f7a0c81b6e69f7e20d28e9e6e3':
Minor tweak to get memory around corrupted heap chunks dumped.
ec2ab73b87bb0c6da24cfc86dbc2d79b9c923da1 19-Jun-2012 Ben Cheng <bccheng@google.com> Minor tweak to get memory around corrupted heap chunks dumped.

Change-Id: I8f72c5c7e23960b13fc53e2354cd74aca8aac3c0
lmalloc.c
8b11c4cec21dc8eedd153866ce738614cfae57e6 08-Jun-2012 Geremy Condra <gcondra@google.com> Adding event logging to libc.

I've basically just copied the relevant bits out of liblog and
EventLog.cpp. While this will let us do the uid logging we want
to address the concerns in 245c07027f78565858dd489eb0d94c3d48743e9d
it doesn't give us much else.

Change-Id: Icac6ff20bc0a3ade5927f6f76fedffe1ae6f8522
ogd_write.c
3069270d8641c7bb57aa308d8f90b4d2dcbf66fc 06-Jun-2012 Elliott Hughes <enh@google.com> am c2bba24d: Merge "Give the timer_create SIGEV_THREAD helper threads sensible names."

* commit 'c2bba24d0a6b906f00d7b9f20ac9d32d63bb2e9d':
Give the timer_create SIGEV_THREAD helper threads sensible names.
470631ed79538ce912edb94505dee3e24af8db89 06-Jun-2012 Elliott Hughes <enh@google.com> Give the timer_create SIGEV_THREAD helper threads sensible names.

Bug: 6609676
Change-Id: I286b197c75beee4d9930b0973f2d7dd47c14e91c
thread-timers.c
252a5c854a08e89fc7337ea679220161fe4ea98f 02-Jun-2012 Iliyan Malchev <malchev@google.com> resolved conflicts for merge of e1dd3c28 to jb-dev-plus-aosp

Change-Id: I58b9c13d20771aa39b703ec05cbff8aeaad38fe8
f0ddaa2fac00ac20059c0b2c142da9de2838a7b6 02-Jun-2012 Iliyan Malchev <malchev@google.com> am 7d2e24eb: bionic: introduce libc.debug.malloc.program

* commit '7d2e24eb167b6257f7935c7bd2023a708704ca1a':
bionic: introduce libc.debug.malloc.program
e1dd3c287ba836281de0197670018bd9bbfbd62b 29-May-2012 Iliyan Malchev <malchev@google.com> bionic: import heaptracker as chk_malloc

This patch is a rewrite of libc.debug.malloc = 10 (chk_malloc). It provides
the same features as the original (poison freed memory, detect heap overruns
and underruns), except that it provides more debugging information whenever it
detects a problem.

In addition to the original features, the new chk_malloc() implementation
detects multiple frees within a given range of the last N allocations, N being
configurable via the system property libc.debug.malloc.backlog.

Finally, this patch keeps track of all outstanding memory allocations. On
program exit, we walk that list and report each outstanding allocation.

(There is support (not enabled) for a scanner thread periodically walks over
the list of outstanding allocations as well as the backlog of recently-freed
allocations, checking for heap-usage errors.)

Feature overview:

1) memory leaks
2) multiple frees
3) use after free
4) overrun

Implementation:

-- for each allocation, there is a:
1) stack trace at the time the allocation is made
2) if the memory is freed, there is also a stack trace at the point
3) a front and rear guard (fence)
4) the stack traces are kept together with the allocation

-- the following lists and maintained

1) all outstanding memory allocations
3) a backlog of allocations what are freed; when you call free(), instead of
actually freed, the allocation is moved to this backlog;
4) when the backlog of allocations gets full, the oldest entry gets evicted
from it; at that point, the allocation is checked for overruns or
use-after-free errors, and then actually freed.
5) when the program exits, the list of outstanding allocations and the
backlog are inspected for errors, then freed;

To use this, set the following system properties before running the process or
processes you want to inspect:

libc.malloc.debug.backlog # defaults to 100
libc.malloc.debug 10

When a problem is detected, you will see the following on logcat for a multiple
free:

E/libc ( 7233): +++ ALLOCATION 0x404b9278 SIZE 10 BYTES MULTIPLY FREED!
E/libc ( 7233): +++ ALLOCATION 0x404b9278 SIZE 10 ALLOCATED HERE:
E/libc ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc ( 7233): #00 pc 0000c35a /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #01 pc 0000c658 /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #02 pc 00016d80 /system/lib/libc.so
E/libc ( 7233): #03 pc 4009647c /system/bin/malloctest
E/libc ( 7233): #04 pc 00016f24 /system/lib/libc.so
E/libc ( 7233): +++ ALLOCATION 0x404b9278 SIZE 10 FIRST FREED HERE:
E/libc ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc ( 7233): #00 pc 0000c35a /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #01 pc 0000c7d2 /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #02 pc 00016d94 /system/lib/libc.so
E/libc ( 7233): #03 pc 40096490 /system/bin/malloctest
E/libc ( 7233): #04 pc 00016f24 /system/lib/libc.so
E/libc ( 7233): +++ ALLOCATION 0x404b9278 SIZE 10 NOW BEING FREED HERE:
E/libc ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc ( 7233): #00 pc 0000c35a /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #01 pc 0000c6ac /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #02 pc 00016d94 /system/lib/libc.so
E/libc ( 7233): #03 pc 400964a0 /system/bin/malloctest
E/libc ( 7233): #04 pc 00016f24 /system/lib/libc.so

The following for a heap overrun and underrun:

E/libc ( 7233): +++ REAR GUARD MISMATCH [10, 11)
E/libc ( 7233): +++ ALLOCATION 0x404b9198 SIZE 10 HAS A CORRUPTED REAR GUARD
E/libc ( 7233): +++ ALLOCATION 0x404b9198 SIZE 10 ALLOCATED HERE:
E/libc ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc ( 7233): #00 pc 0000c35a /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #01 pc 0000c658 /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #02 pc 00016d80 /system/lib/libc.so
E/libc ( 7233): #03 pc 40096438 /system/bin/malloctest
E/libc ( 7233): #04 pc 00016f24 /system/lib/libc.so
E/libc ( 7233): +++ ALLOCATION 0x404b9198 SIZE 10 FREED HERE:
E/libc ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc ( 7233): #00 pc 0000c35a /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #01 pc 0000c7d2 /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #02 pc 00016d94 /system/lib/libc.so
E/libc ( 7233): #03 pc 40096462 /system/bin/malloctest
E/libc ( 7233): #04 pc 00016f24 /system/lib/libc.so
E/libc ( 7233): +++ ALLOCATION 0x404b9358 SIZE 10 HAS A CORRUPTED FRONT GUARD
E/libc ( 7233): +++ ALLOCATION 0x404b9358 SIZE 10 ALLOCATED HERE:
E/libc ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc ( 7233): #00 pc 0000c35a /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #01 pc 0000c658 /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #02 pc 00016d80 /system/lib/libc.so
E/libc ( 7233): #03 pc 400964ba /system/bin/malloctest
E/libc ( 7233): #04 pc 00016f24 /system/lib/libc.so
E/libc ( 7233): +++ ALLOCATION 0x404b9358 SIZE 10 FREED HERE:
E/libc ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc ( 7233): #00 pc 0000c35a /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #01 pc 0000c7d2 /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #02 pc 00016d94 /system/lib/libc.so
E/libc ( 7233): #03 pc 400964e4 /system/bin/malloctest
E/libc ( 7233): #04 pc 00016f24 /system/lib/libc.so

The following for a memory leak:

E/libc ( 7233): +++ THERE ARE 1 LEAKED ALLOCATIONS
E/libc ( 7233): +++ DELETING 4096 BYTES OF LEAKED MEMORY AT 0x404b95e8 (1 REMAINING)
E/libc ( 7233): +++ ALLOCATION 0x404b95e8 SIZE 4096 ALLOCATED HERE:
E/libc ( 7233): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
E/libc ( 7233): #00 pc 0000c35a /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #01 pc 0000c658 /system/lib/libc_malloc_debug_leak.so
E/libc ( 7233): #02 pc 00016d80 /system/lib/libc.so
E/libc ( 7233): #03 pc 0001bc94 /system/lib/libc.so
E/libc ( 7233): #04 pc 0001edf6 /system/lib/libc.so
E/libc ( 7233): #05 pc 0001b80a /system/lib/libc.so
E/libc ( 7233): #06 pc 0001c086 /system/lib/libc.so
E/libc ( 7233): #07 pc 40096402 /system/bin/malloctest
E/libc ( 7233): #08 pc 00016f24 /system/lib/libc.so

Change-Id: Ic440e9d05a01e2ea86b25e8998714e88bc2d16e0
Signed-off-by: Iliyan Malchev <malchev@google.com>
ibc_init_common.c
ibc_init_dynamic.c
alloc_debug_check.c
alloc_debug_check_mapinfo.c
alloc_debug_check_mapinfo.h
alloc_debug_common.c
alloc_debug_common.h
alloc_debug_leak.c
alloc_debug_qemu.c
alloc_debug_stacktrace.c
7d2e24eb167b6257f7935c7bd2023a708704ca1a 30-May-2012 Iliyan Malchev <malchev@google.com> bionic: introduce libc.debug.malloc.program

libc.debug.malloc.program provides an additional level of control over which
processes to enable libc.debug.malloc functionality for. The string value of
libc.debug.malloc.program is matched against the program name; if the value of
libc.debug.malloc.program is a substring of the program name, then malloc debug
is applied to that program at whatever level libc.debug.malloc specifies.

If lib.debug.malloc.program is not specified, then libc.debug.malloc has the
same effect as before.

For example, to enable libc.deubug.malloc = 10 only to the mediaserver, do the
following:

adb root # necessary for setprop
adb setprop libc.debug.malloc.program mediaserver
adb setprop libc.debug.malloc 10
adb kill -9 $(pid mediaserver)

Change-Id: I6f01c12f033c8e2e015d73025369d7f1685ba200
Signed-off-by: Iliyan Malchev <malchev@google.com>
alloc_debug_common.c
d7b60b207be79513b99faf2ef576db333f9c7a78 25-May-2012 Ben Cheng <bccheng@google.com> am c84ff11d: Print the corrupted address passed to free().

* commit 'c84ff11dad26435dc5760bceda18e8f1175a6061':
Print the corrupted address passed to free().
c84ff11dad26435dc5760bceda18e8f1175a6061 25-May-2012 Ben Cheng <bccheng@google.com> Print the corrupted address passed to free().

For example:

@@@ ABORTING: INVALID HEAP ADDRESS IN dlfree addr=0x5c3bfbd0
Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 2942

The addr=0x5c3bfbd0 part is new.

Change-Id: I8670144b2b0a3a6182384150d762c97dfee5452f
lmalloc.c
eab2889e66d4fe03f3c5590d7e8b14e3777179ec 09-May-2012 Elliott Hughes <enh@google.com> am fd955033: Merge "pthread: Invalidate stale stack pointers on pthread_exit()"

* commit 'fd95503347acba5c52d669a186ad2b161338a8a7':
pthread: Invalidate stale stack pointers on pthread_exit()
0753dc653eb3b84d3490212437e7490975d4c020 04-May-2012 Bjorn Andersson <bjorn.andersson@sonymobile.com> pthread: Invalidate stale stack pointers on pthread_exit()

A call to pthread_key_delete() after pthread_exit() have unmapped the stack of a thread
but before the ongoing pthread_join() have finished executing will result in an access
to unmapped memory.
Avoid this by invalidating the stack_base and tls pointers during pthread_exit().

This is based on the investigation and proprosed solution by
Srinavasa Nagaraju <srinavasa.x.nagaraju@sonyericsson.com>

Change-Id: I145fb5d57930e91b00f1609d7b2cd16a55d5b3a9
thread.c
9c3eca7bcee694e6a477a7d50065f11cf1e805bb 08-May-2012 Elliott Hughes <enh@google.com> resolved conflicts for merge of 6cf3c7c5 to jb-dev-plus-aosp

Change-Id: Ib22a8ae1ef63bf9b9c82ce6e22afd188ba7c2806
d0c884d3595ecca03c3e70de9909c090cd5f9cae 22-Feb-2012 Pierre Peiffer <pierre.peiffer@stericsson.com> Let pthread_create fail if schedparam can't be set

The creation of a thread succeeds even if the requested scheduling
parameters can not be set. This is not POSIX compliant, and even
worse, it leads to a wrong behavior. Let pthread_create() fail in this
case.

Change-Id: Ice66e2a720975c6bde9fe86c2cf8f649533a169c
Signed-off-by: Christian Bejram <christian.bejram@stericsson.com>
thread.c
thread_internal.h
ff0d1ce4dfceb35a65440259c3f325106fc9e39b 07-May-2012 Elliott Hughes <enh@google.com> am e3bc7192: Merge "bionic: fix integer overflows in chk_malloc(), leak_malloc(), and leak_memalign()"

* commit 'e3bc7192ec4254bed00eb8b352735665c6072995':
bionic: fix integer overflows in chk_malloc(), leak_malloc(), and leak_memalign()
7f5aa4f35e23fd37425b3a5041737cdf58f87385 14-Mar-2012 Xi Wang <xi.wang@gmail.com> bionic: fix integer overflows in chk_malloc(), leak_malloc(), and leak_memalign()

The allocation size in chk_malloc(), leak_malloc(), and leak_memalign()
functions may be rounded up to a small value, leading to buffer overflows.
The code only runs in debugging mode.

This patch complements commit 6f04a0f4 (CVE-2009-0607).

Change-Id: Id899bcd2bcd2ea2205e5753c433390710032dc83
Signed-off-by: Xi Wang <xi.wang@gmail.com>
alloc_debug_leak.c
6baffed252d0efbce5a79f356c2f156f4f818996 15-Dec-2011 Ken Sumrall <ksumrall@android.com> Add the posix_memalign(3) function to bionic

The posix_memalign(3) function is very similar to the traditional
memalign(3) function, but with better error reporting and a guarantee
that the memory it allocates can be freed. In bionic, memalign(3)
allocated memory can be freed, so posix_memalign(3) is just a wrapper
around memalign(3).

Change-Id: I62ee908aa5ba6b887d8446a00d8298d080a6a299
lmalloc.c
1a78fbb5c8228e4aea2a516818828b76044310f2 22-Mar-2012 Evgeniy Stepanov <eugenis@google.com> Initialize TLS before any application code is run.

Since e19d702b8e33, dlsym and friends use recursive mutexes that
require the current thread id, which is not available before the libc
constructor. This prevents us from using dlsym() in .preinit_array.

This change moves TLS initialization from libc constructor to the earliest
possible point - immediately after linker itself is relocated. As a result,
pthread_internal_t for the initial thread is available from the start.

As a bonus, values stored in TLS in .preinit_array are not lost when libc is
initialized.

Change-Id: Iee5a710ee000173bff63e924adeb4a4c600c1e2d
ibc_init_common.c
ibc_init_static.c
thread.c
thread_internal.h
faca92f2f17cea192c5fbde4d869aa7620315196 27-Mar-2012 Jean-Baptiste Queru <jbq@google.com> Handle pthread-related changes (mutex/atfork)

First commit:

Revert "Revert "am be741d47: am 2f460fbe: am 73b5cad9: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()"""

This reverts commit 06823da2f0c8b4a4ce4c45113032f03df85c94b8.

Second commit:

bionic: fix atfork hanlder_mutex deadlock

This cherry-picks commit 34e89c232dd5645fe3b5f9b40856d8e3e4cae57a

After applying the kernel_id fix, the system refused to boot up and we
got following crash log:
I/DEBUG ( 113): pid: 618, tid: 618 >>> org.simalliance.openmobileapi.service:remote <<<
I/DEBUG ( 113): signal 16 (SIGSTKFLT), code -6 (?), fault addr --------
I/DEBUG ( 113): eax fffffe00 ebx b77de994 ecx 00000080 edx 00724002
I/DEBUG ( 113): esi 00000000 edi 00004000
I/DEBUG ( 113): xcs 00000073 xds 0000007b xes 0000007b xfs 00000000 xss 0000007b
I/DEBUG ( 113): eip b7761351 ebp bfdf3de8 esp bfdf3dc4 flags 00000202
I/DEBUG ( 113): #00 eip: 00015351 /system/lib/libc.so
I/DEBUG ( 113): #01 eip: 0000d13c /system/lib/libc.so (pthread_mutex_lock)
I/DEBUG ( 113): #02 eip: 00077b48 /system/lib/libc.so (__bionic_atfork_run_prepare)
I/DEBUG ( 113): #03 eip: 00052cdb /system/lib/libc.so (fork)
I/DEBUG ( 113): #04 eip: 0009ae91 /system/lib/libdvm.so (_Z18dvmOptimizeDexFileillPKcjjb)
I/DEBUG ( 113): #05 eip: 000819d6 /system/lib/libdvm.so (_Z14dvmJarFileOpenPKcS0_PP7JarFileb)
I/DEBUG ( 113): #06 eip: 000b175e /system/lib/libdvm.so (_ZL40Dalvik_dalvik_system_DexFile_openDexFilePKjP6JValue)
I/DEBUG ( 113): #07 eip: 0011fb94 /system/lib/libdvm.so

Root cause:
The atfork uses the mutex handler_mutex to protect the atfork_head. The
parent will call __bionic_atfork_run_prepare() to lock the handler_mutex,
and need both the parent and child to unlock their own copy of handler_mutex
after fork. At that time, the owner of hanlder_mutex is set as the parent.
If we apply the kernel_id fix, then the child's kernel_id will be set as
child's tid.
The handler_mutex is a recursive lock, and pthread_mutex_unlock(&hander_mutex)
will fail because the mutex owner is the parent, while the current tid
(__get_thread()->kernel_id) is child, not matched with the mutex owner.
At that time, the handler_mutex is left in lock state.If the child wants to
fork other process after than, then it will try to lock handler_mutex, and
then be deadlocked.

Fix:
Since the child has its own copy of vm space from the the parent, the
child space's handler_mutex should be reset to the initialized state.

Change-Id: I3907dd9a153418fb78862f2aa6d0302c375d9e27
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Chenyang Du <chenyang.du@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>

Change-Id: Ic8072f366a877443a60fe215f3c00b3df5a259c8
ork.c
thread-atfork.c
thread.c
eaae81082cb76efa43a2c3fb57997b28ca270634 21-Mar-2012 Ben Cheng <bccheng@google.com> Initialize mspace->least_addr properly in the mmap path.

BUG: 6206963
Change-Id: Id2ab580246de50a4511b56a734a7bece98fb945c
lmalloc.c
21eab513e7eec280a7a8bcb9482a1a8b61e59442 14-Mar-2012 Ben Cheng <bccheng@google.com> New additions/bug fixes required/found when porting perf.

New functions:
tfind
tsearch
tdelete
twalk
tdestroy (GNU extension)

Bug fix: the current implementation for realpath would crash
if the second argument (resolved_path) is NULL.

New headers:
ar.h
search.h

Change-Id: Ib6c1e42fc186a6d597a6e5a9692b16acaa155804
ealpath.c
delete.c
destroy.c
find.c
search.c
34e89c232dd5645fe3b5f9b40856d8e3e4cae57a 16-Mar-2012 Jack Ren <jack.ren@intel.com> bionic: fix atfork hanlder_mutex deadlock

After applying the kernel_id fix, the system refused to boot up and we
got following crash log:
I/DEBUG ( 113): pid: 618, tid: 618 >>> org.simalliance.openmobileapi.service:remote <<<
I/DEBUG ( 113): signal 16 (SIGSTKFLT), code -6 (?), fault addr --------
I/DEBUG ( 113): eax fffffe00 ebx b77de994 ecx 00000080 edx 00724002
I/DEBUG ( 113): esi 00000000 edi 00004000
I/DEBUG ( 113): xcs 00000073 xds 0000007b xes 0000007b xfs 00000000 xss 0000007b
I/DEBUG ( 113): eip b7761351 ebp bfdf3de8 esp bfdf3dc4 flags 00000202
I/DEBUG ( 113): #00 eip: 00015351 /system/lib/libc.so
I/DEBUG ( 113): #01 eip: 0000d13c /system/lib/libc.so (pthread_mutex_lock)
I/DEBUG ( 113): #02 eip: 00077b48 /system/lib/libc.so (__bionic_atfork_run_prepare)
I/DEBUG ( 113): #03 eip: 00052cdb /system/lib/libc.so (fork)
I/DEBUG ( 113): #04 eip: 0009ae91 /system/lib/libdvm.so (_Z18dvmOptimizeDexFileillPKcjjb)
I/DEBUG ( 113): #05 eip: 000819d6 /system/lib/libdvm.so (_Z14dvmJarFileOpenPKcS0_PP7JarFileb)
I/DEBUG ( 113): #06 eip: 000b175e /system/lib/libdvm.so (_ZL40Dalvik_dalvik_system_DexFile_openDexFilePKjP6JValue)
I/DEBUG ( 113): #07 eip: 0011fb94 /system/lib/libdvm.so

Root cause:
The atfork uses the mutex handler_mutex to protect the atfork_head. The
parent will call __bionic_atfork_run_prepare() to lock the handler_mutex,
and need both the parent and child to unlock their own copy of handler_mutex
after fork. At that time, the owner of hanlder_mutex is set as the parent.
If we apply the kernel_id fix, then the child's kernel_id will be set as
child's tid.
The handler_mutex is a recursive lock, and pthread_mutex_unlock(&hander_mutex)
will fail because the mutex owner is the parent, while the current tid
(__get_thread()->kernel_id) is child, not matched with the mutex owner.
At that time, the handler_mutex is left in lock state.If the child wants to
fork other process after than, then it will try to lock handler_mutex, and
then be deadlocked.

Fix:
Since the child has its own copy of vm space from the the parent, the
child space's handler_mutex should be reset to the initialized state.

Change-Id: I3907dd9a153418fb78862f2aa6d0302c375d9e27
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Chenyang Du <chenyang.du@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
thread-atfork.c
06823da2f0c8b4a4ce4c45113032f03df85c94b8 13-Mar-2012 Guang Zhu <guangzhu@google.com> Revert "am be741d47: am 2f460fbe: am 73b5cad9: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()""

This reverts commit 76d56cf4a94e875a8b621025e2780775247adb6e, reversing
changes made to c59ba4595be25a1213955233fcf9bcd1afe6438e.

Bug: 6157577
ork.c
thread.c
76d56cf4a94e875a8b621025e2780775247adb6e 13-Mar-2012 Elliott Hughes <enh@google.com> am be741d47: am 2f460fbe: am 73b5cad9: Merge "bionic: Fix wrong kernel_id in pthread descriptor after fork()"

* commit 'be741d472868a8ffcb455588f18cda889b0f465c':
bionic: Fix wrong kernel_id in pthread descriptor after fork()
d8bc6e7119450f263afcf89c8b581f6aaa23d186 17-Jan-2012 Jack Ren <jack.ren@intel.com> bionic: Fix wrong kernel_id in pthread descriptor after fork()

After forking, the kernel_id field in the phtread_internal_t returned by pthread_self()
is incorrect --- it's the tid from the parent, not the new tid of the
child.

The root cause is that: currently the kernel_id is set by
_init_thread(), which is called in 2 cases:
(1) called by __libc_init_common(). That happens when the execv( ) is
called after fork( ). But when the zygote tries to fork the android
application, the child application doesn't call execv( ), instread, it
tries to call the Java main method directly.
(2) called by pthread_create(). That happens when a new thread is
created.

For the lead thread which is the thread created by fork(), it should
call execv() but it doesn't, as described in (1) above. So its kernel_id
will inherit the parent's kernel_id.

Fixed it in this patch.

Change-Id: I63513e82af40ec5fe51fbb69456b1843e4bc0fc7
Signed-off-by: Chenyang Du <chenyang.du@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
ork.c
thread.c
058d6d88b959efc00d7ba9777e447bc55c409569 10-Feb-2012 Dianne Hackborn <hackbod@google.com> Update bionic to know users and isolated uids for uid string representation.

Change-Id: I6681bacd69299a7f9837ef8025a80c5562081bad
tubs.c
e1414aa96bb62057b1a25c6a9ea1797dd38dce59 24-Jan-2012 David 'Digit' Turner <digit@google.com> libc: remove global lock from recursive mutex implementation.

This optimization improves the performance of recursive locks
drastically. When running the thread_stress program on a Xoom,
the total time to perform all operations goes from 1500 ms to
500 ms on average after this change is pushed to the device.

Change-Id: I5d9407a9191bdefdaccff7e7edefc096ebba9a9d
thread.c
b57db7581cabb98651c4d8940d65c5c404b914ad 24-Jan-2012 David 'Digit' Turner <digit@google.com> libc: Fix recursive mutex lock implementation.

This fixes a bug that was introduced in the latest pthread optimization.
It happens when a recursive lock is contented by several threads. The main
issue was that the atomic counter increment in _recursive_increment() could
be annihilated by a non-conditional write in pthread_mutex_lock() used to
update the value's lower bits to indicate contention.

This patch re-introduces the use of the global recursive lock in
_recursive_increment(). This will hit performance, but a future patch
will be provided to remove it from the source code.

Change-Id: Ie22069d376cebf2e7d613ba00b6871567f333544
thread.c
68d03fdbd8eb4d0e40dcdfbfa5e6c6dd931b467a 05-Jan-2012 Mathias Agopian <mathias@google.com> Merge "implement pthread mutex deadlock detection"
85aad909560508410101c18c6ecc6633df39c596 15-Dec-2011 Ken Sumrall <ksumrall@android.com> Add the posix_memalign(3) function to bionic

The posix_memalign(3) function is very similar to the traditional
memalign(3) function, but with better error reporting and a guarantee
that the memory it allocates can be freed. In bionic, memalign(3)
allocated memory can be freed, so posix_memalign(3) is just a wrapper
around memalign(3).

Change-Id: I62ee908aa5ba6b887d8446a00d8298d080a6a299
lmalloc.c
7c0c3793722aea293c45921ef50e4adcdf9645ce 06-Sep-2011 Mathias Agopian <mathias.agopian@gmail.com> implement pthread mutex deadlock detection

this works by building a directed graph of acquired
pthread mutexes and making sure there are no loops in
that graph.

this feature is enabled with:

setprop debug.libc.pthread 1

when a potential deadlock is detected, a large warning is
output to the log with appropriate back traces.

currently disabled at compile-time. set PTHREAD_DEBUG_ENABLED=1
to enable.

Change-Id: I916eed2319599e8aaf8f229d3f18a8ddbec3aa8a
ibc_init_dynamic.c
thread.c
thread_debug.c
022d303116f742cd337852d37547e2ea24d97a25 07-Dec-2011 David 'Digit' Turner <digit@google.com> libc: optimize pthread mutex lock/unlock operations (1/2)

This patch provides several small optimizations to the
implementation of mutex locking and unlocking. Note that
a following patch will get rid of the global recursion
lock, and provide a few more aggressive changes, I
though it'd be simpler to split this change in two parts.

+ New behaviour: pthread_mutex_lock et al now detect
recursive mutex overflows and will return EAGAIN in
this case, as suggested by POSIX. Before, the counter
would just wrap to 0.

- Remove un-necessary reloads of the mutex value from memory
by storing it in a local variable (mvalue)

- Remove un-necessary reload of the mutex value by passing
the 'shared' local variable to _normal_lock / _normal_unlock

- Remove un-necessary reload of the mutex value by using a
new macro (MUTEX_VALUE_OWNER()) to compare the thread id
for recursive/errorcheck mutexes

- Use a common inlined function to increment the counter
of a recursive mutex. Also do not use the global
recursion lock in this case to speed it up.

Change-Id: I106934ec3a8718f8f852ef547f3f0e9d9435c816
thread.c
6c6de44f0479b202c39555f5c22ef8c494837d3c 07-Dec-2011 David 'Digit' Turner <digit@google.com> libc: optimize pthread_once() implementation.

This patch changes the implementation of pthread_once()
to avoid the use of a single global recursive mutex. This
should also slightly speed up the non-common case where
we have to call the init function, or wait for another
thread to finish the call.

Change-Id: I8a93f4386c56fb89b5d0eb716689c2ce43bdcad9
thread.c
6e9d51701eabe26d2132a214e07b10384ea60a8c 07-Dec-2011 Rabin Vincent <rabin.vincent@stericsson.com> am a73de44b: am 177ba8cb: Prevent deadlock when using fork

* commit 'a73de44b7c0a50908ea8afe16134316cfc6cfbbe':
Prevent deadlock when using fork
177ba8cb42ed6d232e7c8bcad5e6ee21fc51a0e8 08-Apr-2011 Rabin Vincent <rabin.vincent@stericsson.com> Prevent deadlock when using fork

When forking of a new process in bionic, it is critical that it
does not allocate any memory according to the comment in
java_lang_ProcessManager.c:
"Note: We cannot malloc() or free() after this point!
A no-longer-running thread may be holding on to the heap lock, and
an attempt to malloc() or free() would result in deadlock."
However, as fork is using standard lib calls when tracing it a bit,
they might allocate memory, and thus causing the deadlock.
This is a rewrite so that the function cpuacct_add, that fork calls,
will use system calls instead of standard lib calls.

Signed-off-by: christian bejram <christian.bejram@stericsson.com>

Change-Id: Iff22ea6b424ce9f9bf0ac8e9c76593f689e0cc86
puacct.c
c5819d427de4186780391d7e067850a9e4a09ec7 06-Dec-2011 Jean-Baptiste Queru <jbq@google.com> Merge 35765066 from ics-mr1-plus-aosp

Change-Id: Ibaeb49dc20f3c736417d5cb68769e7b501a61632
e4a21c89a8b24b32f7a2637b45522dfa59f2aaa4 05-Dec-2011 Bruce Beare <bruce.j.beare@intel.com> signal: Align the sigset_t size passed to from user space to kernel.

Pass kernel space sigset_t size to __rt_sigprocmask to workaround
the miss-match of NSIG/sigset_t definition between kernel and bionic.

Note: Patch originally from Google...
Change-Id: I4840fdc56d0b90d7ce2334250f04a84caffcba2a
Signed-off-by: Chenyang Du <chenyang.du@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
thread.c
aed4a4c90b46f9e91ef2a52a3360a990cca957e7 06-Dec-2011 Bruce Beare <bruce.j.beare@intel.com> am 75039baf: am 89d3fdca: MALLOC_DEBUG: enable the option libc.debug.malloc = 10

* commit '75039bafde8e6f03caffa9d6aa7142a09ba50952':
MALLOC_DEBUG: enable the option libc.debug.malloc = 10
89d3fdcae26980bf81a4622c3c83e48ead4c1c3a 21-Sep-2011 Bruce Beare <bruce.j.beare@intel.com> MALLOC_DEBUG: enable the option libc.debug.malloc = 10

Fix the compile warning to let the libc.debug.malloc=10 works well
Due to unsuitable value comparison, which cause compiler optimize the
code of comparing two digits.

Change-Id: I0bedd596c9ca2ba308fb008da20ecb328d8548f5
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
Author: liu chuansheng <chuansheng.liu@intel.com>
alloc_debug_leak.c
bec5dec947b1ad097c200888365a3ec61f9e7a28 30-Nov-2011 Jack Ren <jack.ren@intel.com> am 0c3d21e6: am e480fc83: bionic: fix pthread_{create, exit}/signal race condition

* commit '0c3d21e63c6e75ae73aaf2b8d64af0bd8caa6beb':
bionic: fix pthread_{create, exit}/signal race condition
e480fc83b2887388d469eb3bf58c86c610f5b082 21-Sep-2011 Jack Ren <jack.ren@intel.com> bionic: fix pthread_{create, exit}/signal race condition

(1) in pthread_create:
If the one signal is received before esp is subtracted by 16 and
__thread_entry( ) is called, the stack will be cleared by kernel
when it tries to contruct the signal stack frame. That will cause
that __thread_entry will get a wrong tls pointer from the stack
which leads to the segment fault when trying to access tls content.

(2) in pthread_exit
After pthread_exit called system call unmap(), its stack will be
freed. If one signal is received at that time, there is no stack
available for it.

Fixed by subtracting the child's esp by 16 before the clone system
call and by blocking signal handling before pthread_exit is started.

Author: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
thread.c
95a17848d3a96000f90cdbfc7ff922182f0003b3 21-Nov-2011 Jeff Brown <jeffbrown@google.com> Merge "Add tgkill syscall."
10c8ce59a40a1d8ae8f49145eca365b364aabe58 19-Nov-2011 Jeff Brown <jeffbrown@google.com> Add tgkill syscall.

Use tgkill instead of tkill to implement pthread_kill.
This is safer in the event that the thread has already terminated
and its id has been reused by a different process.

Change-Id: Ied715e11d7eadeceead79f33db5e2b5722954ac9
thread.c
5f64df4bc3bc281f661d520773894c729c2b4835 17-Nov-2011 Nick Kralevich <nnk@google.com> ASLR: enable pthread stack location randomization

Allow the kernel to choose a memory location to put the
thread stack, rather than hard coding 0x10000000

Change-Id: Ib1f37cf0273d4977e8d274fbdab9431ec1b7cb4f
thread.c
e31bfae2baa96742f998155ee26e56c826a8ce3a 15-Nov-2011 David 'Digit' Turner <digit@android.com> bionic: Do not use <sys/atomics.h> for platform code.

We're going to modify the __atomic_xxx implementation to provide
full memory barriers, to avoid problems for NDK machine code that
link to these functions.

First step is to remove their usage from our platform code.
We now use inlined versions of the same functions for a slight
performance boost.

+ remove obsolete atomics_x86.c (was never compiled)

NOTE: This improvement was benchmarked on various devices.
Comparing a pthread mutex lock + atomic increment + unlock
we get:

- ARMv7 emulator, running on a 2.4 GHz Xeon:
before: 396 ns after: 288 ns

- x86 emulator in KVM mode on same machine:
before: 27 ns after: 27 ns

- Google Nexus S, in ARMv7 mode (single-core):
before: 82 ns after: 76 ns

- Motorola Xoom, in ARMv7 mode (multi-core):
before: 121 ns after: 120 ns

The code has also been rebuilt in ARMv5TE mode for correctness.

Change-Id: Ic1dc72b173d59b2e7af901dd70d6a72fb2f64b17
tomics_x86.c
thread.c
emaphore.c
9bf330b5676d0f60b3e4c3b8985494bcb1134e8b 14-Nov-2011 David 'Digit' Turner <digit@google.com> libc: fix the pthread_sigmask implementation

The old code didn't work because the kernel expects a 64-bit sigset_t
while the one provided by our ABI is only 32-bit. This is originally
due to the fact that the kernel headers themselves define sigset_t
as a 32-bit type when __KERNEL__ is not defined (apparently to cater
to libc5 or some similarly old C library).

We can't modify the size of sigset_t without breaking the NDK ABI,
so instead perform runtime translation during the call.

Change-Id: Ibfdc3cbceaff864af7a05ca193aa050047b4773f
thread.c
d53cae0e45dafdb3a83ccc3675051c0aee532111 12-Jul-2011 Glenn Kasten <gkasten@google.com> Add non-NDK internal API __pthread_gettid

Tracking bugs 5267571 and 5090073 (for deadlock detection logs).

Change-Id: Icb90f91ec1525607551c2234ef921bf88296484f
thread.c
30e30acf106166bf65ad781bb4a63eead1d2c3a6 13-Jul-2011 David 'Digit' Turner <digit@google.com> am 6b6ebeca: am 3a131026: resolved conflicts for merge of 50a83255 to gingerbread-plus-aosp

* commit '6b6ebeca985fb3843b56b507ac4ac1be44080a9c':
enable support for large files (> 2G)
Enable functional DSO object destruction
x86: Enable -fstack-protector
Update X86 Bionic CRT files for unwind/exceptions
bionic, libthread_db x86 fixes
Updated gcc 4.4.3 IA toolchain doesn't require the .ctors list
Remove an extra register move.
Replace __atomic_XXX with GCC __sync_XXX intrinsics.
move some typedefs to procfs.h required by gdbserver build
use consistent guards for off_t and size_t defines for IA
Simplify variable typing for IA builds
sigsetmask.c was not processing the "mask" argument.
Add defines for CAIF support
Remove extra/unneeded copy of fenv.h
Use proper variable typing
Update ATOM string routines to latest
Fix undefined reference to dl_iterate_phdr for x86
Fix missing NL
ptrace.c Fix source file format to unix from dos
6b6ebeca985fb3843b56b507ac4ac1be44080a9c 11-Jul-2011 David 'Digit' Turner <digit@google.com> am 3a131026: resolved conflicts for merge of 50a83255 to gingerbread-plus-aosp

* commit '3a13102637c8be53edf28f96598ac11aaa3e14df':
enable support for large files (> 2G)
Enable functional DSO object destruction
x86: Enable -fstack-protector
Update X86 Bionic CRT files for unwind/exceptions
bionic, libthread_db x86 fixes
Updated gcc 4.4.3 IA toolchain doesn't require the .ctors list
Remove an extra register move.
Replace __atomic_XXX with GCC __sync_XXX intrinsics.
move some typedefs to procfs.h required by gdbserver build
use consistent guards for off_t and size_t defines for IA
Simplify variable typing for IA builds
sigsetmask.c was not processing the "mask" argument.
Add defines for CAIF support
Remove extra/unneeded copy of fenv.h
Use proper variable typing
Update ATOM string routines to latest
Fix undefined reference to dl_iterate_phdr for x86
Fix missing NL
ptrace.c Fix source file format to unix from dos
3a13102637c8be53edf28f96598ac11aaa3e14df 11-Jul-2011 David 'Digit' Turner <digit@google.com> resolved conflicts for merge of 50a83255 to gingerbread-plus-aosp

Change-Id: Idf1971120bbdd52676f95aa3aa69f62342dc012e
3435fc600d8d78b63a355b519667c23f56d6611b 31-May-2011 James Rose <james.rose@intel.com> bionic, libthread_db x86 fixes

Orig-Change-Id: I3be997f5f1f6a894a3c200d4f325cf3bfd428c66
Author: James Rose <james.rose@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
thread.c
trace.c
bf296479646e97108174a13b74a6eb11f1bea713 27-Jan-2011 Bruce Beare <bruce.j.beare@intel.com> Updated gcc 4.4.3 IA toolchain doesn't require the .ctors list

Orig-Change-Id: Ia840a19a45257128eccdcf25d105f500f2d90741
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
ibc_init_common.h
ibc_init_static.c
0f2dc2b60cf684f58eefda51b7442c44c10aa492 31-May-2011 Bruce Beare <bruce.j.beare@intel.com> ptrace.c Fix source file format to unix from dos

Orig-Change-Id: Ia771b457eec7f9575d4631fb1c12a7062ebcc7de
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
trace.c
681c4bd782369e0d42bd02d3ac38a8031270ad7e 06-Jul-2011 Jean-Baptiste Queru <jbq@google.com> Merge b3773e9c

Change-Id: I5787d9ac5e745a08e1c891e9ce9efc4e7f97ace8
cb5529efd80bc9ae78a8ea5f16f062adda4ec368 06-Jul-2011 Jean-Baptiste Queru <jbq@google.com> Merge 784515ad

Change-Id: I3e5b691d008e9548f43339635bafdd95bc2f56fe
c99376836021e6623516cf38d42259d38e1a480f 06-Jul-2011 Jean-Baptiste Queru <jbq@google.com> Revert "Revert "libc: Add logcat error message for memory corruption""

This reverts commit 368ee1e4d65c555fdb0fa4b3a91d75a397936908.
lmalloc.c
ogd_write.c
b3773e9cc84630fced2117bb57224f0e766c5a26 06-Jul-2011 David 'Digit' Turner <digit@android.com> am 9c95cbf7: Merge "Really fix the build."

* commit '9c95cbf75094c15d251bb3d57a55ce47d7c6c2c8':
Really fix the build.
c51871d4b22425b32ec40c060c39d6b6fa4406f6 06-Jul-2011 David 'Digit' Turner <digit@android.com> Really fix the build.

libcutils/mspace.c includes libc/bionic/dlmalloc.c, we need to
take care of the fact that any internal C library function cannot
be used from it.

Change-Id: I0bc81ae090b7ac2d464f26b97fc6b94a08cdad9c
lmalloc.c
784515ad93c63ce9b7add4830946f30a2792b97d 06-Jul-2011 David 'Digit' Turner <digit@android.com> am 01eb7f72: Merge "Fix broken build"

* commit '01eb7f72434830bb14cec906d885d2b7ee40d53b':
Fix broken build
a4824467c33c5a59317f777a54c60e3b339e4966 06-Jul-2011 David 'Digit' Turner <digit@android.com> Fix broken build

Change-Id: Ia46b50aec51a55434c8828a73e07f4732f8f6c1c
lmalloc.c
368ee1e4d65c555fdb0fa4b3a91d75a397936908 06-Jul-2011 Mathew Inwood <mathewi@google.com> Revert "libc: Add logcat error message for memory corruption"

This fixes the build.

This reverts commit 7708a89c60e7b024d31c48c8034932c5e9f0aceb.
lmalloc.c
ogd_write.c
877923d369c953d601afd461a04854a27ec720fd 06-Jul-2011 David 'Digit' Turner <digit@android.com> am d25ea49e: am b73b6783: Merge "libc: Add logcat error message for memory corruption"

* commit 'd25ea49e632c00d57d893563dac3f6dae5493b7e':
libc: Add logcat error message for memory corruption
d25ea49e632c00d57d893563dac3f6dae5493b7e 06-Jul-2011 David 'Digit' Turner <digit@android.com> am b73b6783: Merge "libc: Add logcat error message for memory corruption"

* commit 'b73b6783a595cf4b1cef6463c23317a8b417f1e9':
libc: Add logcat error message for memory corruption
7708a89c60e7b024d31c48c8034932c5e9f0aceb 30-Jun-2011 David 'Digit' Turner <digit@android.com> libc: Add logcat error message for memory corruption

Our dlmalloc implementation currently calls abort() when it detects
that the heap is corrupted, or that an invalid pointer is passed to
one of its functions.

The only way to detect this is because abort() will force-fully
crash the current program with a magic fault address of '0xdeadbaad'.

However, this is not really well documented, and a frequent topic
on the android-ndk forum (among others).

This change makes our dlmalloc code dump a simple message to the
log just before the abort() call (and hence before the stack trace)
to better help identify the problem.

Change-Id: Iebf7eb7fe26463ecadfaca8f247d237edb441e3c
lmalloc.c
ogd_write.c
1f8e2672a8f261d5bb08e3ab26f026b30f5ff77b 27-May-2011 Brian Carlstrom <bdc@google.com> Implement getpwnam_r(3) and getpwuid_r(3).

These functions were already declared in <pwd.h>, but hadn't been implemented
yet.

git cherry-pick --no-commit 081504af74826bad7035669ad34d457b4b439e8f

Change-Id: I316acf4cffb9f2c6788e8e342aa620f9a00886d5
tubs.c
54e494d909fff343ed0c612506fe68294a3936d0 11-May-2011 David Turner <digit@android.com> am add0a45a: am e8f7e30b: Merge "bionic, libthread_db x86 fixes"

* commit 'add0a45a117f00553e79e7137d023416f9c0a54f':
bionic, libthread_db x86 fixes
add0a45a117f00553e79e7137d023416f9c0a54f 11-May-2011 David Turner <digit@android.com> am e8f7e30b: Merge "bionic, libthread_db x86 fixes"

* commit 'e8f7e30b05c6ba103d64c1fb3cd5ef2b17be7aab':
bionic, libthread_db x86 fixes
8e551a6319e45dd5c8d03864f3330b45cf8551b7 28-Mar-2011 Bruce Beare <bruce.j.beare@intel.com> bionic, libthread_db x86 fixes

Change-Id: I3be997f5f1f6a894a3c200d4f325cf3bfd428c66
Author: James Rose <james.rose@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
thread.c
trace.c
3be409a38c18c75690b74bca5d81ca95c8f0f5b9 11-Apr-2011 David Turner <digit@android.com> am 70245736: am aad685ce: am 4c090434: Merge "removing shadowing redeclaration of result"

* commit '702457363c2b1b01f0d9cb0093a48ce28753e275':
removing shadowing redeclaration of result
702457363c2b1b01f0d9cb0093a48ce28753e275 11-Apr-2011 David Turner <digit@android.com> am aad685ce: am 4c090434: Merge "removing shadowing redeclaration of result"

* commit 'aad685ce001495260a3ce0c9d9284a6ee3ca09c0':
removing shadowing redeclaration of result
5f133f3c4ddd6d43d8da6b3bcccb9a7477dd20b3 01-Apr-2011 Brad Fitzpatrick <bradfitz@android.com> am 31e2feee: am 2dc801f9: am 8da75ab8: Ignore property set timeouts.

* commit '31e2feeef3dffb49ce742a6ae1c9280c792c7c49':
Ignore property set timeouts.
2dc801f9fce57c35c00a3366f86bc38fe3e38c25 01-Apr-2011 Brad Fitzpatrick <bradfitz@android.com> am 8da75ab8: Ignore property set timeouts.

* commit '8da75ab8936b0b7fcf8dd9a3befeb696ee6aa39d':
Ignore property set timeouts.
8da75ab8936b0b7fcf8dd9a3befeb696ee6aa39d 01-Apr-2011 Brad Fitzpatrick <bradfitz@android.com> Ignore property set timeouts.

Change-Id: Ic3f6119398368ba047736370336d0260905abd40
ystem_properties.c
099423ba1c68d960888905ce5de093ea8cb7ad39 31-Mar-2011 Brad Fitzpatrick <bradfitz@android.com> am 23bc3ff7: Don\'t futex_wait spin when setting properties. Wait for socket close.

* commit '23bc3ff71dffdfec208aee05938e544c7cb3bc37':
Don't futex_wait spin when setting properties. Wait for socket close.
23bc3ff71dffdfec208aee05938e544c7cb3bc37 30-Mar-2011 Brad Fitzpatrick <bradfitz@android.com> Don't futex_wait spin when setting properties. Wait for socket close.

Depends on init change I8dd685ea

Bug: 4185486
Change-Id: I5a2dbc3b7be1759212d4a3988d9033b9b947a1db
ystem_properties.c
bf90b57b442760b85a0af38792e6e2f8aa9e7826 30-Mar-2011 Brad Fitzpatrick <bradfitz@android.com> Don't futex_wait spin when setting properties. Wait for socket close.

Depends on init change I8dd685ea

Bug: 4185486
Change-Id: I3e80cecfad8e072973003ec6f93146c5cad369ac
ystem_properties.c
0f5587097bf2b27e13434b23f61a562816fe7649 22-Mar-2011 Christopher Schwardt <nookieman@gmx.de> removing shadowing redeclaration of result

Change-Id: Ic1f86962dfb8620cf5c63ff4913b2f0bf908abb5
alloc_debug_common.c
2cc2b2be692f1d559a09d2066e56e450249cc9c0 22-Mar-2011 Carl Shapiro <cshapiro@google.com> Add some missing includes.

Change-Id: Ieec623c06bc32ec78334f628af25b00c2bccd2e7
emmove_words.c
0b3c5c50f7bed92282783995bf6a7cc777fa9392 15-Mar-2011 satok <satok@google.com> do not merge. Move property setting from libcutils to bionic.

Backport I110b653a58f3

All the other property stuff is already here. Property setting was
only in libcutils previously to leverage a utility function / constant
or two.

Unfortunately in the process of fixing a race condition we would've
had to do break abstraction boundaries and put some libc-internal
details into libcutils so instead of that we'll just move this
into bionic.

Along with Iee1ca9b7, this now passes:

$ adb shell am instrument -w -e class android.os.SystemPropertiesTest \
com.android.frameworks.coretests.systemproperties/android.test.InstrumentationTestRunner

Bug: 3511230

Change-Id: I1b588db3344169621e1279ecc0b660cf4e1015d7
ystem_properties.c
ec7e8cc9dddafc624cd28939c1a38ea336c89455 15-Mar-2011 satok <satok@google.com> do not merge. Move property setting from libcutils to bionic.

Backport I110b653a58f3

All the other property stuff is already here. Property setting was
only in libcutils previously to leverage a utility function / constant
or two.

Unfortunately in the process of fixing a race condition we would've
had to do break abstraction boundaries and put some libc-internal
details into libcutils so instead of that we'll just move this
into bionic.

Along with Iee1ca9b7, this now passes:

$ adb shell am instrument -w -e class android.os.SystemPropertiesTest \
com.android.frameworks.coretests.systemproperties/android.test.InstrumentationTestRunner

Bug: 3511230

Change-Id: I1b588db3344169621e1279ecc0b660cf4e1015d7
ystem_properties.c
4399df8f2ebd797e45bec81e6f22e4911b2c5686 11-Mar-2011 Brad Fitzpatrick <bradfitz@android.com> Move property setting from libcutils to bionic.

All the other property stuff is already here. Property setting was
only in libcutils previously to leverage a utility function / constant
or two.

Unfortunately in the process of fixing a race condition we would've
had to do break abstraction boundaries and put some libc-internal
details into libcutils so instead of that we'll just move this
into bionic.

Along with Iee1ca9b7, this now passes:

$ adb shell am instrument -w -e class android.os.SystemPropertiesTest \
com.android.frameworks.coretests.systemproperties/android.test.InstrumentationTestRunner

Bug: 3511230
Change-Id: I110b653a58f312fbe069dca59892a877ae9bc911
ystem_properties.c
f9316d37b462d523438c621f75c47f52a12e4087 14-Mar-2011 Brad Fitzpatrick <bradfitz@android.com> am 08a4ce98: am 0c398985: Merge "[ENDIAN] Build md5 code correctly for bigendian targets"

* commit '08a4ce983ba14cef394e5198c9561349ec7fef44':
[ENDIAN] Build md5 code correctly for bigendian targets
865e3789dd222ca2ec4f173f43085851165a0ecb 10-Mar-2011 Paul Lind <plind@mips.com> [ENDIAN] Build md5 code correctly for bigendian targets

Signed-off-by: Raghu Gandham <raghu@mips.com>
d5.c
81d79f9fb38d9ae8a5711f5774aa5a1516f6cc26 10-Mar-2011 David 'Digit' Turner <digit@android.com> am 962dcb22: am fed58049: Merge "libc: Fix PTHREAD_RWLOCK_INITIALIZER"

* commit '962dcb22218a1a6d4ebd05e4fc4a69875d037234':
libc: Fix PTHREAD_RWLOCK_INITIALIZER
Proxy getnameinfo through netd
Updated gcc 4.4.3 IA toolchain doesn't require the .ctors list
Convert cname lenght before use
48e1feaa9d7d7f36b5eba25baccd99a56adf9b64 27-Jan-2011 Bruce Beare <bruce.j.beare@intel.com> Updated gcc 4.4.3 IA toolchain doesn't require the .ctors list

Change-Id: Ia840a19a45257128eccdcf25d105f500f2d90741
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
ibc_init_common.h
ibc_init_static.c
4ce737f5df6bda362b45ca2a9d72d0aad2d5a58f 04-Feb-2011 Andy McFadden <fadden@android.com> Added _memmove_words

Added a memmove() variant for Dalvik's System.arraycopy()
implementation. It guarantees 16-bit or 32-bit atomicity depending
on the alignment of the arguments.

Bug 3398352

Change-Id: Ie7bd246305ef0ff8290513663327c5b81680368d
emmove_words.c
a37cf34eded8a84227e9cbb53befaf4b58cf60c0 09-Jan-2011 Glenn Kasten <gkasten@google.com> Bug 3330205 Reentrant MD5

Change-Id: I4c8e4a8f3ef4cdaac50f32d9e55accb16133ab35
d5.c
5c8c00a95a6cdcd74ac32dadedf0cea2b1661169 20-Dec-2010 David 'Digit' Turner <digit@google.com> libc: Fix the definition of SIGRTMAX

After this change, SIGRTMAX will be set to 64 (instead of 32 currently).
Note that this doesn't change the fact that our sigset_t is still defined
as a 32-bit unsigned integer, so most functions that deal with this type
won't support real-time signals though.

Change-Id: Ie1e2f97d646f1664f05a0ac9cac4a43278c3cfa8
thread.c
72e6fd42421dca80fb2776a9185c186d4a04e5f7 03-Dec-2010 David 'Digit' Turner <digit@google.com> <sched.h>: Add sched_getcpu() and cpu_set_t

This adds the cpu_set_t type definition and related functions
and macros used to handle CPU thread affinity.

sched_getcpu()
sched_setaffinity()
sched_getaffinity()

Change-Id: If382ecafde8926341a88478062b275553645065b
ched_cpualloc.c
ched_cpucount.c
ched_getaffinity.c
ched_getcpu.c
6481b91520150e9664a3c4abc5d2aebdce422f93 06-Dec-2010 David 'Digit' Turner <digit@google.com> <time.h>: Add timegm(), timelocal() and others.

Add timegm(), timelocal(), time2posix() and posix2time() to the
C library.

Change-Id: I34d5771ed83dd994870a5ca58a511d01898b1ffb
ime64_config.h
ff590cadc269aea03d0f66ddec31ba35053cafa9 05-Nov-2010 Elliott Hughes <enh@google.com> Use a modern chdir(2)-free realpath(3) implementation.

(This is the current OpenBSD implementation.)

Bug: 3055824, 2281992
Change-Id: Iafa8f78e8d6e44c036a547c7210a13d559b7483a
ealpath.c
fa8fef9506a8d4cbfcbbdc9821c985038b698380 26-Oct-2010 Jean-Baptiste Queru <jbq@google.com> am f2c05baa: am 96c03c7d: Merge "Remove duplicated _rand48 implementation. Use stdlib version instead"

Merge commit 'f2c05baac40bceb754ac69a38b83250c3a5aaddd'

* commit 'f2c05baac40bceb754ac69a38b83250c3a5aaddd':
Remove duplicated _rand48 implementation. Use stdlib version instead
f2c05baac40bceb754ac69a38b83250c3a5aaddd 26-Oct-2010 Jean-Baptiste Queru <jbq@google.com> am 96c03c7d: Merge "Remove duplicated _rand48 implementation. Use stdlib version instead"

Merge commit '96c03c7dcc8cad59f2b8f3e6fef6a77a43750756' into gingerbread-plus-aosp

* commit '96c03c7dcc8cad59f2b8f3e6fef6a77a43750756':
Remove duplicated _rand48 implementation. Use stdlib version instead
70478100d5967f528e6514a42f98a76bb85b7e28 27-Sep-2010 Jim Huang <jserv@0xlab.org> Remove duplicated _rand48 implementation. Use stdlib version instead

Originally, there are _rand48 (in libc/bionic/_rand48.c) and __rand48
(in libc/stdlib/_rand48.c) implemented in bionic. Besides the naming,
the functionality is identical. This patch removes the duplicated
_rand48. Also, drand48 and erand48 are modified accordingly.

Change-Id: Ie5761a0a97f45df8538222a77edacb7c3e0125d7
rand48.c
rand48.c
rand48.c
and48.h
209cf825932d5caf1e0985cfc75671785c528635 21-Oct-2010 David 'Digit' Turner <digit@google.com> am f7ad13b0: am 1df986c2: libc: fix executable destruction support.

Merge commit 'f7ad13b0ce5ad2d2f0340c066b09eb8174877739'

* commit 'f7ad13b0ce5ad2d2f0340c066b09eb8174877739':
libc: fix executable destruction support.
51a4f7872acbb26a678940c3bc49b9a3d3a516ac 21-Oct-2010 Jean-Baptiste Queru <jbq@google.com> am 001a3218: am 4afe0f47: Merge "time64: make helper functions static"

Merge commit '001a321897d0f053b87799dafe17a39036b72470'

* commit '001a321897d0f053b87799dafe17a39036b72470':
time64: make helper functions static
f97ce8cb7b9ccec18471fca5c275581c342cc3cb 21-Oct-2010 Jean-Baptiste Queru <jbq@google.com> am 6ac5660e: am ade2a929: Merge "bionic: stubs: Make internal symbol static"

Merge commit '6ac5660e1c8fc9934d11ed675771063624ac1b4b'

* commit '6ac5660e1c8fc9934d11ed675771063624ac1b4b':
bionic: stubs: Make internal symbol static
d3ecb3cd05bb135bf7cd4ab4d1572e2fb9745a8a 21-Oct-2010 Jean-Baptiste Queru <jbq@google.com> am 1203671b: am 2215c113: Merge "pthread-timers: Hide internal symbol __timer_table_start_stop"

Merge commit '1203671b47246efd20279a39ab9bd7ea934ae8dc'

* commit '1203671b47246efd20279a39ab9bd7ea934ae8dc':
pthread-timers: Hide internal symbol __timer_table_start_stop
d445a2b27588a3e87eec22c38f997f2613c120b8 21-Oct-2010 Jean-Baptiste Queru <jbq@google.com> am bcd94044: am 847223de: Merge "__set_errno: Hide internal symbol __set_syscall_errno"

Merge commit 'bcd940444513a24268d5f9c9a6186274cf09c8dd'

* commit 'bcd940444513a24268d5f9c9a6186274cf09c8dd':
__set_errno: Hide internal symbol __set_syscall_errno
f7ad13b0ce5ad2d2f0340c066b09eb8174877739 21-Oct-2010 David 'Digit' Turner <digit@google.com> am 1df986c2: libc: fix executable destruction support.

Merge commit '1df986c21ee52c6756846b4a5e45cb316f772112' into gingerbread-plus-aosp

* commit '1df986c21ee52c6756846b4a5e45cb316f772112':
libc: fix executable destruction support.
1df986c21ee52c6756846b4a5e45cb316f772112 21-Oct-2010 David 'Digit' Turner <digit@google.com> libc: fix executable destruction support.

This change allows an executable to call its destructor functions
(declared with __attribute__((destructor))) to be properly called
when it normally exits.

Note that this is different from calling the destructors of a shared
library when it is unloaded with dlclose() or through program exit,
which are already supported.

Bug: 3106500
Change-Id: I1412ef5407f13b613fc6cb6103e0a691dbee4b1a
ibc_init_common.c
ibc_init_common.h
ibc_init_dynamic.c
ibc_init_static.c
001a321897d0f053b87799dafe17a39036b72470 21-Oct-2010 Jean-Baptiste Queru <jbq@google.com> am 4afe0f47: Merge "time64: make helper functions static"

Merge commit '4afe0f4724b3d7180d67eae29bfdad5f815857cb' into gingerbread-plus-aosp

* commit '4afe0f4724b3d7180d67eae29bfdad5f815857cb':
time64: make helper functions static
6ac5660e1c8fc9934d11ed675771063624ac1b4b 21-Oct-2010 Jean-Baptiste Queru <jbq@google.com> am ade2a929: Merge "bionic: stubs: Make internal symbol static"

Merge commit 'ade2a92991d1c7edc32c4a300bd83d622fa1567d' into gingerbread-plus-aosp

* commit 'ade2a92991d1c7edc32c4a300bd83d622fa1567d':
bionic: stubs: Make internal symbol static
1203671b47246efd20279a39ab9bd7ea934ae8dc 21-Oct-2010 Jean-Baptiste Queru <jbq@google.com> am 2215c113: Merge "pthread-timers: Hide internal symbol __timer_table_start_stop"

Merge commit '2215c11325d0af07cde67bfee7bafa09ee5556a7' into gingerbread-plus-aosp

* commit '2215c11325d0af07cde67bfee7bafa09ee5556a7':
pthread-timers: Hide internal symbol __timer_table_start_stop
4afe0f4724b3d7180d67eae29bfdad5f815857cb 21-Oct-2010 Jean-Baptiste Queru <jbq@google.com> Merge "time64: make helper functions static"
ade2a92991d1c7edc32c4a300bd83d622fa1567d 21-Oct-2010 Jean-Baptiste Queru <jbq@google.com> Merge "bionic: stubs: Make internal symbol static"
2215c11325d0af07cde67bfee7bafa09ee5556a7 21-Oct-2010 Jean-Baptiste Queru <jbq@google.com> Merge "pthread-timers: Hide internal symbol __timer_table_start_stop"
bcd940444513a24268d5f9c9a6186274cf09c8dd 20-Oct-2010 Jean-Baptiste Queru <jbq@google.com> am 847223de: Merge "__set_errno: Hide internal symbol __set_syscall_errno"

Merge commit '847223de9ceff6db468a8246792542517a12d39f' into gingerbread-plus-aosp

* commit '847223de9ceff6db468a8246792542517a12d39f':
__set_errno: Hide internal symbol __set_syscall_errno
cd9c98dfda3e54fd7191e446079295cf4885f24e 14-Oct-2010 Jim Huang <jserv@0xlab.org> __set_errno: Hide internal symbol __set_syscall_errno

Change-Id: I21e7ef6bf0bca288069275add43bd53294c0760d
_set_errno.c
c9a41a69971b10186f0c9947fd9868d4d570884f 14-Oct-2010 Jim Huang <jserv@0xlab.org> pthread-timers: Hide internal symbol __timer_table_start_stop

Change-Id: If99c5816fe6fa9107aa6bef4697048fabf92283f
thread-timers.c
c940945155fa8bf92e23bd1e8bd843cc41e9628d 14-Oct-2010 Jim Huang <jserv@0xlab.org> bionic: stubs: Make internal symbol static

Thread-specific state for the stubs functions should not be exposed to
applications.

Change-Id: I4d35dab6009dab8db7781671ac5cc9b5f6904e84
tubs.c
8b2707a6a074e64a36ced73b45f5c5fbe774b63b 14-Oct-2010 Jim Huang <jserv@0xlab.org> time64: make helper functions static

Change-Id: I98d9a5f736482e52904228c171a1bdefd2f5b213
ime64.c
9d8be5485c366b4f579bef0b88a4c99b899f21e1 05-Oct-2010 tedbo <tedbo@google.com> get_malloc_leak_info: Fix assumption that totalMemory out parameter was initialized to zero.

The get_malloc_leak_info() currently asssumes that the totalMemory out parameter
was pre-initialized to zero before the routine is called. If it is not then the
accumulated totalMemory value will be incorrect. It is likely that many callers
will simply allocate totalMemory on the stack with no initialization and assume
that get_malloc_leak_info will set the proper value.

As an example, the caller in frameworks/base/core/jni/android_os_Debug.cpp
calls get_malloc_leak_info() with the address uninitiazed stack variable
for totalMemory. It is probably best to fix this in get_malloc_leak_info.

Change-Id: I84c927c3781419585794726115b7d34d8fdd24ae
alloc_debug_common.c
b1c9cc2f2d1b0478b07278cdef885cabf1cd2798 23-Sep-2010 Andy McFadden <fadden@android.com> Add memory barriers to pthread_once.

The implementation was using a double-checked locking approach that
could break on SMP.

In addition to the barriers I also switched to a volatile pointer. I
don't think this will matter unless gcc can conclude that _normal_lock
can't affect *once_control, but I figured it was better to be safe.
(It seems to have no impact whatsoever on the generated code.)

Bug 3022795.

Change-Id: Ib91da25d57ff5bee4288526e39d457153ef6aacd
thread.c
6dbfddfe4e76790ee57ddc0a77b64a9457ec08fb 23-Sep-2010 Wink Saville <wink@google.com> am b9e49ad5: Use a recursive lock for pthread_once. DO NOT MERGE.

Merge commit 'b9e49ad56e5776ace7c6eab2e997d5b7acb16792' into gingerbread-plus-aosp

* commit 'b9e49ad56e5776ace7c6eab2e997d5b7acb16792':
Use a recursive lock for pthread_once. DO NOT MERGE.
b9e49ad56e5776ace7c6eab2e997d5b7acb16792 22-Sep-2010 Wink Saville <wink@google.com> Use a recursive lock for pthread_once. DO NOT MERGE.

Backport change I9fc8b790 from Master to Gingerbread

Change-Id: I5cf48fcd4efb7991ed82f87d9365c19655dc9b7f
thread.c
e2ac89869f9b459faa22640fb1bb41e818c1dd55 02-Sep-2010 Andy McFadden <fadden@android.com> Add a memory barrier to cond var signaling.

This adds an explicit memory barrier to condition variable signaling.
It's a little murky as to whether it's strictly required, but it seems
like a wise thing to do.

Change-Id: Id0faa542d61e4b8ffa775e4adf68e4d7471f4fb7
thread.c
caaf7ecd1c93e03b81bbe3fbf479969d0562de74 10-Aug-2010 Christopher Tate <ctate@google.com> am 1ff91085: am 52e7d3d9: Bulletproof leak dump against null hash entries

Merge commit '1ff910858c8ae5863761101c673a196a6a16bca3'

* commit '1ff910858c8ae5863761101c673a196a6a16bca3':
Bulletproof leak dump against null hash entries
1ff910858c8ae5863761101c673a196a6a16bca3 10-Aug-2010 Christopher Tate <ctate@google.com> am 52e7d3d9: Bulletproof leak dump against null hash entries

Merge commit '52e7d3d91ab6a5bab77c5dfb1ed47381fd52f9ba' into gingerbread-plus-aosp

* commit '52e7d3d91ab6a5bab77c5dfb1ed47381fd52f9ba':
Bulletproof leak dump against null hash entries
52e7d3d91ab6a5bab77c5dfb1ed47381fd52f9ba 09-Aug-2010 Christopher Tate <ctate@google.com> Bulletproof leak dump against null hash entries

Previously, the malloc leak checking code would crash in qsort()
if null entries existed in its bookkeeping table. This change
makes the comparison function detect null entries and sort them
to the end safely.

Change-Id: I88244a7df1e289dd9d7992ce29606d505bd63079
alloc_debug_common.c
6b9d2d6839fcb6f2049ae67214dbbc711fc399fd 24-Jul-2010 Jean-Baptiste Queru <jbq@google.com> am 6d4d8cb7: resolved conflicts for merge of 4f086aeb to gingerbread-plus-aosp

Merge commit '6d4d8cb79c5578d33ab17806d67b1e53a730fbc3'

* commit '6d4d8cb79c5578d33ab17806d67b1e53a730fbc3':
Implemented pthread_atfork()
6d4d8cb79c5578d33ab17806d67b1e53a730fbc3 23-Jul-2010 Jean-Baptiste Queru <jbq@google.com> resolved conflicts for merge of 4f086aeb to gingerbread-plus-aosp

Change-Id: Ice2a6d41a7e9d04eca02e15ed189d648d61b5801
4f086aeb4aa06e13079b7fec71a8178ceeacf318 25-Jun-2010 Matt Fischer <matt.fischer@garmin.com> Implemented pthread_atfork()

Change-Id: Ie6c0bf593315d3507b3c4a6c8903a74a1fa053db
ork.c
thread-atfork.c
thread_internal.h
fb6907d39c7ffda90049cb73001ade59e7931a64 09-Jul-2010 The Android Open Source Project <initial-contribution@android.com> am 0e78f786: merge from open-source master

Merge commit '0e78f786777a04af498b43564a8d6ed8e15e8940'

* commit '0e78f786777a04af498b43564a8d6ed8e15e8940':
Change-Id: I68cc462aeb2460345a53bdb9941ce4bfc10456fb
0e78f786777a04af498b43564a8d6ed8e15e8940 09-Jul-2010 The Android Open Source Project <initial-contribution@android.com> merge from open-source master

Change-Id: Id84ff747889d6f2c15c0510263e32fdfdd18dbed
fc6d95b10e7629f61013d221cbc1cdbff0190ac0 09-Jul-2010 Jean-Baptiste Queru <jbq@google.com> Merge "Change-Id: I68cc462aeb2460345a53bdb9941ce4bfc10456fb bionic: fix clearenv() compiler warning and related comment typos"
cf385317417af76f20d2d579da05c0a336691e40 03-Jul-2010 David 'Digit' Turner <digit@google.com> resolved conflicts for merge of 2576abf0 to master

Change-Id: Ibd3ed11f3cc27ff12c0464b0f56d7057be6a7b85
519763265ec0b634bd9c264a0aca034882458ecc 28-Jun-2010 David 'Digit' Turner <digit@google.com> libc: Fix sem_post() implementation to wake up all waiting threads.

This also allows us to optimize the case where we increment an
uncontended semaphore (no need to call futex_wake() then).

Change-Id: Iad48efe8551dc66dc89d3e3f18c001e5a6c1939f
emaphore.c
3b43f87d2949a340e2c19cb735af7727157d8274 02-Jul-2010 David 'Digit' Turner <digit@android.com> Allow dlclose() to properly call static C++ destructors.

With this patch _and_ an upcoming build/ patch, the destruction
of static C++ objects contained in shared libraries will happen
properly when dlclose() is called.

Note that this change introduces crtbegin_so.S and crtend_so.S which
are currently ignored by the build system.

+ move definition of __dso_handle to the right place
(before that, all shared libraries used the __dso_handle
global variable from the C library).

Note that we keep a 'weak' __dso_handle in aeabi.c to avoid
breaking the build until the next patch to build/core/combo/
appears. We will be able to remove that later.

+ move bionic/aeabi.c to arch-arm/bionic/ (its proper location)

NOTE: The NDK will need to be modified to enable this feature in
the shared libraries that are generated through it.

Change-Id: I99cd801375bbaef0581175893d1aa0943211b9bc
abi.c
4e6043a355ccc04b3e931edd7616d35ef5691278 29-Jun-2010 David 'Digit' Turner <digit@google.com> am 7d1d98b9: am a02b93bd: libc: add sanity checks to pthread_mutex_destroy()

Merge commit '7d1d98b97e947de22aff4c0b67eec7ae68c822ee'

* commit '7d1d98b97e947de22aff4c0b67eec7ae68c822ee':
libc: add sanity checks to pthread_mutex_destroy()
a02b93bd75a9d156117264d88069566e447397e2 28-Jun-2010 David 'Digit' Turner <digit@google.com> libc: add sanity checks to pthread_mutex_destroy()

Change-Id: Iddb2204fa792fa9aca5f19838926dddbb09b74a2
thread.c
ccc3d1eea124cbeb1ec2d711d5892db1dd4445d3 28-Jun-2010 Wink Saville <wink@google.com> Use a recursive lock for pthread_once.

bug: 2292366
Change-Id: I9fc8b790dcfcb30ca94a0beb340d43fe5cd6c22e
thread.c
2bf607d599b703604cb1caf5beeb2e70c44682fb 28-Jun-2010 Chris Peterson <cpeterso@cpeterso.com> Change-Id: I68cc462aeb2460345a53bdb9941ce4bfc10456fb
bionic: fix clearenv() compiler warning and related comment typos
learenv.c
ibc_init_common.c
ibc_init_dynamic.c
50ace4fec5e8cb5afcbc656a4556fa528adfd760 17-Jun-2010 David 'Digit' Turner <digit@google.com> Remove compiler warnings when building Bionic.

Also add missing declarations to misc. functions.
Fix clearerr() implementation (previous was broken).
Handle feature test macros like _POSIX_C_SOURCE properly.

Change-Id: Icdc973a6b9d550a166fc2545f727ea837fe800c4
learenv.c
puacct.c
ork.c
ts.c
thread.c
ystem_properties.c
6a9b888d7c4b246f6f66360789c72b754ff85021 18-Jun-2010 David 'Digit' Turner <digit@google.com> Allow static C++ destructors to be properly called on dlclose().

With this patch, _and_ an upcoming build/ patch, the destruction
of static C++ objects contained in shared libraries will happen
properly when dlclose() is called.

Note that this change introduces crtbegin_so.S and crtend_so.S which
are currently ignored by the build system.

+ move definition of __dso_handle to the right place
(before that, all shared libraries used the __dso_handle
global variable from the C library).

Note that we keep a 'weak' __dso_handle in aeabi.c to avoid
breaking the build until the next patch to build/core/combo/
appears. We will be able to remove that later.

+ move bionic/aeabi.c to arch-arm/bionic/ (its proper location)

Change-Id: Ie771aa204e3acbdf02fd30ebd4150373a1398f39
NOTE: The NDK will need to be modified to enable this feature in
the shared libraries that are generated through it.
abi.c
6c8a2f2a5bc8d612ee953f528f2b5eb35983656a 11-Jun-2010 David 'Digit' Turner <digit@google.com> libc: remove cutils dependencies

We simply copy the stuff we need from cutils headers.

A future patch will change cutils to include the private <bionic_atomic_inline.h>

Change-Id: Ib6fd9a03bc9e337ce867bd606dc94c2b4438480a
ogd_write.c
thread.c
emaphore.c
6304d8b21891fd0cb7b5a4c25159a3d3b1709d62 03-Jun-2010 David 'Digit' Turner <digit@google.com> Use private futexes for semaphores, unless they are initialized with pshared != 0.

Change-Id: I534e36a7171cd37037ae03b910ba71ea6968286d
Note: previously, sem_init() would return an error if pshared != 0.
thread.c
emaphore.c
a8a21488630980c1d2a2152d0ac39bd7978879e2 04-Jun-2010 Jean-Baptiste Queru <jbq@google.com> resolved conflicts for merge of 7b6e6fa5 to kraken

Change-Id: I2b9b80a7fa32c56be2b85ff8be0d6e7ac1848afe
7b6e6fa57240466c2728d553be136f800600dd71 03-Jun-2010 The Android Open Source Project <initial-contribution@android.com> merge from open-source master

Change-Id: Ib7fc9c6f79f9b13e2175da137005d8968ea85eaf
fcd00ebbdf3e7f4e1e7782a65ae10fb0fc03a1aa 28-May-2010 Andy McFadden <fadden@android.com> Atomic/SMP update, part 3.

Update ARM atomic ops to use LDREX/STREX. Stripped out #if 0 chunk.

Insert explicit memory barriers in pthread and semaphore code.

For bug 2721865.

Change-Id: I0f153b797753a655702d8be41679273d1d5d6ae7
thread.c
emaphore.c
78c1c04ced772298be8bdb5a94b6ce491bb9b3e1 20-May-2010 André Goddard Rosa <andre.goddard@gmail.com> pthread: introduce pthread_setname_np() as a mean to give names to threads

... so that each cloned process at the kernel level can be named
independently. Tools like 'top' can display the CPU/memory statistics
for each process's thread if "Show Threads" mode is on.

With this function in place, we can convert dalvik/Thread.c setThreadName()
function over this function. This feature ought to be provided by the
underlying C library and not coded directly in Dalvik.

Change-Id: Ifa997665dbaa114e0b126f8c667708be9a4137fd
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
thread.c
8a1d2cf1422e35257c160ac5bb12dd3ee481c433 12-May-2010 David 'Digit' Turner <digit@google.com> Add pthread_rwlock_t implementation to the C library (DO NOT MERGE)

Change-Id: I756d8c26afc37cd7b71117ddbaa02a2cb40fdecb
thread-rwlocks.c
f450fa5f991af3c0814f96265cb3b2aafdce2309 04-May-2010 The Android Open Source Project <initial-contribution@android.com> merge from open-source master

Change-Id: If02d33af51017dbd85e91c79ac2e848eda6cf253
0be7eda75a14815aaa3e5cd5d5d4e5d25dc35d1c 02-May-2010 David Turner <digit@android.com> Merge "Fix log channel initialization at bionic/logd_write.c."
5751c54bf1c84ad9b1e23a6909c59431c973deae 05-Feb-2010 André Goddard Rosa <andre.goddard@gmail.com> bionic: add missing NULL check from memory allocation on record_backtrace()

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>

Change-Id: I739c63c5a7344fff1775580044dc647edf246ebf
alloc_leak.c
95faecefdea0f55edafdba09052a904df7cd2405 08-Apr-2010 The Android Open Source Project <initial-contribution@android.com> merge from open-source master

Change-Id: If77618a329fc7b497c44c2585e644bc50e7e1406
350bb359fa5e31e3dfae8be6b1ce7ee3495f0da7 05-Feb-2010 André Goddard Rosa <andre.goddard@gmail.com> bionic: fix memory leak in get_malloc_leak_info() error path

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
alloc_leak.c
3f6121278194404f89ea7b22f098e9389e954587 29-Mar-2010 André Goddard Rosa <andre.goddard@gmail.com> bionic: clear only the part of the buffer which is not overwritten afterward

Change-Id: I5ddd93f0557e5a7401460dc9fc8a55b330a79c3a
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
alloc_leak.c
5207d78c321571b4b5ef3dd405198267a0d940b1 23-Mar-2010 David 'Digit' Turner <digit@google.com> Fix typo that broke recursive mutexes implementation.

Change-Id: I832901604b487c6a50304c311b5ba135e153530d
thread.c
b5e4a416060aa7f0a1e2a9ad5b8e318d59986852 20-Mar-2010 David 'Digit' Turner <digit@google.com> pthread: Use private futexes by default in condition variables

Now that the system properly uses shared condvars when needed, we
can enable the use of private futexes for them too.

Change-Id: Icf8351fc0a2309f764cba45c65bc3af047720cdf
thread.c
377d4c979dee3dcb5929e8f7a68a53c2407259ab 22-Mar-2010 The Android Open Source Project <initial-contribution@android.com> merge from open-source master

Change-Id: I70266ee8c520b216773f267e46c8273d2334c31d
88f06cd84a70f8a5212cb03272ec2c7cf0017afa 19-Mar-2010 David 'Digit' Turner <digit@google.com> Use private futexes for pthread_mutex_t.

This does not change the implementation of conditional variables
since we're waiting for other system components to properly use
pthread_condattr_init/setpshared before that.

Also remove an obsolete x86 source file.

Change-Id: Ia3e3fbac35b87a534fb04d4381c3c66b975bc8f7
thread.c
1825fb5d5f214849e39d95660795a0d3633f8eeb 19-Mar-2010 David Turner <digit@android.com> Merge "bionic: on pthread_join(), avoid extra check in case we find the thread"
c0e464268d381a5575897e6c2de397167d0985db 19-Mar-2010 David Turner <digit@android.com> Merge "bionic: ftell() returns a long, not an int"
ee7b077abf1d99503b986489ad93374a057cb354 18-Mar-2010 David 'Digit' Turner <digit@google.com> Add pthread_condattr_init/destroy/setpshared/getpshared

Note that this does not change the implementation of conditional variables
which still use shared futexes, independent on the flags being selected.

This will be fixed in a later patch, once our system is modified to use
pthread_condattr_setpshared(attr, PTHREAD_PROCESS_SHARED) properly.

Change-Id: I935de50964cd41f97a13dbfd6626d3407b0406c3
thread.c
40e6b822866ee59f7823000384321bb899416cb1 17-Mar-2010 David 'Digit' Turner <digit@google.com> Fix indentation in pthread mutex implementation.

This is preliminary work to simplify later changes to support
private futexes.

Change-Id: I06750936a93747a5e3f5a10228cbdc29e39c528c
thread.c
a9c41a8e0a62f70a37f7040740a9b1ef06a66612 17-Mar-2010 David Turner <digit@android.com> Merge "bionic: remove unneeded variable from chk_realloc()"
8641833b62e3b319796dc80ea16eb1592c05edf6 11-Mar-2010 Fabrice Di Meglio <fdimeglio@google.com> Revert "bionic: pthread: use private futexes by default for mutexes and condvars"

This reverts commit ba9c6f0989ae94778ba2b9f597adc827c9dc81e8.
thread.c
ba9c6f0989ae94778ba2b9f597adc827c9dc81e8 11-Mar-2010 David 'Digit' Turner <digit@google.com> bionic: pthread: use private futexes by default for mutexes and condvars

Private futexes are a recent kernel addition: faster futexes that cannot be
shared between processes. This patch uses them by default, unless the PROCESS_SHARED
attribute flag is used when creating a mutex and/or conditional variable.

Also introduces pthread_condattr_init/destroy/setpshared/getpshared.

Change-Id: I3a0e2116f467072b046524cb5babc00e41057a53
thread.c
9f6915631b918a56e0e6be958fb14d274cbab322 02-Mar-2010 Mike Chan <mike@android.com> bonic: libc: cpuacct support for setuid functions

Any of the setuid functions now updates /acct/uid/ with its own tid
before changing users. This is so we can properly account for cpu time
per uid.

Change-Id: I34186cf4d5228cac8439e582a9e26c01ef3011e4
Signed-off-by: Mike Chan <mike@android.com>
puacct.c
ork.c
8f8b5310d2c3fe8782377bd66b65ed14dc6511a4 01-Mar-2010 David 'Digit' Turner <digit@google.com> Fix pthread_sigmask() to return correct error values.

Before that, it returned -1 on error and set errno (not Posix)
After the patch, it returns the error code and leaves errno untouched.
thread.c
b55462328f7f7468bb8c0cb44ad1069af30415a3 17-Feb-2010 Vladimir Chtchetkine <vchtchetkine@google.com> Merge "Merge memory checking functionality from sandbox"
75fba6888a1e5738f8255f3511c4ad40cbcc0eda 12-Feb-2010 Vladimir Chtchetkine <vchtchetkine@google.com> Merge memory checking functionality from sandbox

Change-Id: I304c789a752c9f4af4944ca14b9bf1e7644da15a
alloc_debug_common.c
alloc_debug_common.h
alloc_debug_leak.c
alloc_debug_qemu.c
4f920f685bb4af8400c70383eecf347a35353778 12-Feb-2010 David 'Digit' Turner <digit@google.com> Fix sem_post() behaviour to wake up multiple waiting threads.
emaphore.c
294dd0b86b1484aec7549663aff5b19c98a4b7fd 12-Feb-2010 David 'Digit' Turner <digit@google.com> Fix sem_trywait() implementation + update changelog.
emaphore.c
1dcf07a84c93a0095875f2d2087bfe7bfb66a413 12-Feb-2010 David 'Digit' Turner <digit@google.com> Fix android_id_from_name to accept "app_0" as a valid ID.

This fixes getpwnam and getpwgrp which returned NULL for "app_0".
"app_0" corresponds to uid/gid 10000 and is perfectly valid.
tubs.c
699237baf54af3395311ad71ebedce20745c4cb2 05-Feb-2010 André Goddard Rosa <andre.goddard@gmail.com> bionic: equalize the <unknown> program name between ssp.c and libc_init_common.c

... for the consistency sake.

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
sp.c
291100c795fc98f4a1320e7de0dbef2615cd8fb9 05-Feb-2010 André Goddard Rosa <andre.goddard@gmail.com> bionic: remove unneeded variable from chk_realloc()

... and simplify the generated code.

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
alloc_leak.c
a28336c73542f5df1c03de4c142070f408e8d5aa 05-Feb-2010 André Goddard Rosa <andre.goddard@gmail.com> bionic: on pthread_join(), avoid extra check in case we find the thread

... by using similar logic as used in pthread_detach().

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
thread.c
3b06c128cf2799cec8f7524dc11c4e6c320fe4c7 05-Feb-2010 André Goddard Rosa <andre.goddard@gmail.com> bionic: ftell() returns a long, not an int

Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
ututline.c
97cf7f3394780d524038fc083e2c134031b54728 23-Jan-2010 David 'Digit' Turner <digit@google.com> Implement clone() C library function properly.

Only provide an implementation for ARM at the moment, since
it requires specific assembly fragments (the standard syscall
stubs cannot be used because the child returns in a different
stack).
ionic_clone.c
fc10b24accd082fb33c8f92ff8b92481c22fe3dc 14-Jan-2010 Colin Cross <ccross@android.com> Add implementation of fdprintf, clearenv, and stubs for ttyname_r, *usershell

Change-Id: I5fe7e8b6ee5edbb49e707c3b6737a58563781fa3
learenv.c
dprintf.c
tubs.c
64ceac3f493e3063a289aec4a12c74787be974e4 14-Jan-2010 Colin Cross <ccross@android.com> Add fts, err, and sys/queue for grep

Change-Id: Id47514a1812d828e95efa2fab0e9c15c5b682b58
rr.c
ts.c
c22da7ed32f8b537b8e4653fd777056e8315ebdf 03-Dec-2009 Alexey Tarasov <tarasov@dodologics.com> Fix log channel initialization at bionic/logd_write.c.

log_channel_t contains fd member, which is file descriptor for
exact logging channel. change cc05d1271680d6a7804bc89d3b1fe14c40b32396
lacks initialization of this member in __write_to_log_init(), thus
logging code is not working, although not crashable.

Additional details may be found in comments here:
http://review.source.android.com/5617
ogd_write.c
5cdb2b73d269580b66297c84d9395f5f9b62d963 01-Dec-2009 Andy McFadden <fadden@android.com> Fix libc logging implementation.

The file descriptor wasn't getting set, so the writev() call was
silently failing.

There's a parallel implementation over in system/core/liblog, but it's
still using the old approach and didn't have this problem.
ogd_write.c
fdfa16776ca8f33f671cbac5dd9fa8bd761e16a8 19-Nov-2009 Vladimir Chtchetkine <vchtchetkine@google.com> am 362b2aab: Merge change Ib4550a04 into eclair-mr2

Merge commit '362b2aabee2dd04e04a3ad9c09f0ad0212569be4' into eclair-mr2-plus-aosp

* commit '362b2aabee2dd04e04a3ad9c09f0ad0212569be4':
Split libc_debug.so into two .so modules loaded on demand from libc.so
b74ceb25aae555570df64fa4d4076272733a9a20 17-Nov-2009 Vladimir Chtchetkine <vchtchetkine@google.com> Split libc_debug.so into two .so modules loaded on demand from libc.so

This change is intended to eliminate need to replace libc.so with libc_debug.so in order to enablememory allocation debugging.
This is also the first step towards implementing extended memoryallocation debugging using emulator's capabilities in monitoring memory access.
lmalloc.c
lmalloc.h
ibc_init_dynamic.c
ibc_init_static.c
alloc_debug_common.c
alloc_debug_common.h
alloc_debug_leak.c
alloc_debug_qemu.c
alloc_leak.c
95604529ec25fe7923ba88312c590f38aa5e3d9e 15-Nov-2009 Jean-Baptiste Queru <jbq@google.com> merge from eclair
194d3fa048cf909ca592dd56fa538dc9cd3f5ddb 13-Nov-2009 Jean-Baptiste Queru <jbq@google.com> eclair snapshot
lmalloc.c
lmalloc.h
thread.c
7e5e9f42706da2f487645a522e907b38fc387910 24-Sep-2009 David 'Digit' Turner <digit@google.com> am bc10cd29: Fix a typo that resulted in a crash in the boot sequence

Merge commit 'bc10cd2900cdb7fed077163b6a33e0f8572b2b19' into eclair-plus-aosp

* commit 'bc10cd2900cdb7fed077163b6a33e0f8572b2b19':
Fix a typo that resulted in a crash in the boot sequence
bc10cd2900cdb7fed077163b6a33e0f8572b2b19 24-Sep-2009 David 'Digit' Turner <digit@google.com> Fix a typo that resulted in a crash in the boot sequence
thread.c
9641805419d30e8bfa4624cf54f823b7a3a9e320 23-Sep-2009 David 'Digit' Turner <digit@google.com> am d154954f: Merge change 26419 into eclair

Merge commit 'd154954f02691618fdf73a5a97336e64cad37af0' into eclair-plus-aosp

* commit 'd154954f02691618fdf73a5a97336e64cad37af0':
Add pthread_mutex_lock_timeout_np
3f56b7f65adb9ee35cd0f878ca00b92011eec427 22-Sep-2009 David 'Digit' Turner <digit@google.com> Add pthread_mutex_lock_timeout_np

This is used to perform a mutex lock for a given amount of
milliseconds before giving up. Using the _np prefix since this
is absolutely not portable.

Also remove a compiler warning in pthread_attr_getstackaddr
thread.c
895244b2ab91b34ab03efc78417ee1eb73f3e7ba 17-Sep-2009 Jean-Baptiste Queru <jbq@google.com> merge from open-source master
a4e67f4512e2609c13a67d569bff14001413a042 27-Dec-2008 Matthieu CASTET <matthieu.castet@gmail.com> Remove code duplication for pthread_cond_timeout_np : use __pthread_cond_timedwait_relative helper
thread.c
00fb8b45d9d3fdf3db0dfb93df9a94a89f94f68d 01-Sep-2009 Jean-Baptiste Queru <jbq@google.com> merge from open-source master
cc05d1271680d6a7804bc89d3b1fe14c40b32396 12-Dec-2008 Alexey Tarasov <tarasov@dodologics.com> Changed logging functions in bionic/logd_write.c.

Main differences from original code:
1. now log channel for LOG_ID_MAIN may exist even if LOG_ID_RADIO
facility failed.
2. __write_to_log_null() now acts as always successful function.
3. it's more simplier to add new logging channels now

ammended commit fixes my typo on line 130
ogd_write.c
44ac5d5d9353b74a9782e6ee9e4cf432c03800e1 08-Aug-2009 Jean-Baptiste Queru <jbq@google.com> merge from open-source master
bb08537104e8a753deb6109b5fb696882c59be84 08-Aug-2009 Android Code Review <code-review@android.com> Merge change 10057

* changes:
Add mspace_merge_objects
e40fb3d68f7855647fe4fa13912f421bf9bf6c14 22-Jul-2009 Andy McFadden <fadden@android.com> am 39f3745c: Restore malloc debug.

Merge commit '39f3745cf30efe38482ffead1c32f4e62f6fe32e'

* commit '39f3745cf30efe38482ffead1c32f4e62f6fe32e':
Restore malloc debug.
39f3745cf30efe38482ffead1c32f4e62f6fe32e 22-Jul-2009 Andy McFadden <fadden@android.com> Restore malloc debug.

Some libc changes were preventing the initialization call from being made.
The basic problem appears to be that libc_init_common.c is only built once,
and it's only built for the non-debug libc.
ibc_init_common.c
ibc_init_dynamic.c
ibc_init_static.c
alloc_leak.c
d5b3513cca5ae93fa2b8a936c1ce1b46d2525966 20-Jul-2009 David 'Digit' Turner <digit@google.com> am b56b5659: Fix the C library runtime initialization order.

Merge commit 'b56b5659b3996e98c2060f168d1cff1474e77d2a'

* commit 'b56b5659b3996e98c2060f168d1cff1474e77d2a':
Fix the C library runtime initialization order.
b56b5659b3996e98c2060f168d1cff1474e77d2a 18-Jul-2009 David 'Digit' Turner <digit@google.com> Fix the C library runtime initialization order.

This allows libc.so to run the C runtime initializer as soon as the
dynamic linker loads the shared library, i.e. before any other initializers
(e.g. static C++ constructors in other shared libraries the executable depends
on).

This also removes the bug where the initializers from the executable itself
were run twice: once by the dynamic linker, and another time by __libc_init
as defined by libc_init_dynamic.c
ibc_init_common.c
ibc_init_common.h
ibc_init_dynamic.c
ibc_init_static.c
b7681167cbe91c2bb95cccdc08f75184ed1fb839 14-Jul-2009 Mathias Agopian <mathias@google.com> allow pthread_mutexattr_setpshared to accept SHARED mutexes, since our current impl actually uses shared mutexes
thread.c
a2f5e212448f36f0b35cf695d13bb4defdb4472e 14-Jul-2009 Mathias Agopian <mathias@google.com> added pthread_cond_timedwait_relative_np()
thread.c
c4eee3765bf9dd81ff055e70ff7daa83a3926d2a 08-Jul-2009 David 'Digit' Turner <digit@google.com> Prevent a crash in the memory leak checker (which happened in chk_free())

Simplify the code a little, removing un-necessary mutex locks/unlocks.
Provide slightly better diagnostic message in case of corruption.
Use snprintf/strlcat instead of sprintf/strcat
ogd_write.c
alloc_leak.c
3a654b1e04d4275ae315cfe1b196998acf10052c 03-Jun-2009 David 'Digit' Turner <digit@google.com> Revert "Fix the C library initialization to avoid calling static C++ constructors twice."

This reverts commit 03eabfe65e1e2c36f4d26c78a730fa19a3bdada3.
ibc_init_common.c
ibc_init_dynamic.c
ibc_init_static.c
thread_internal.h
f30dae9cf452e4308a34450b2a48eb6602936976 26-May-2009 Barry Hayes <bhayes@google.com> Add mspace_merge_objects
lmalloc.c
lmalloc.h
03eabfe65e1e2c36f4d26c78a730fa19a3bdada3 28-May-2009 David 'Digit' Turner <digit@google.com> Fix the C library initialization to avoid calling static C++ constructors twice.

The problem was due to the fact that, in the case of dynamic executables,
the dynamic linker calls the DT_PREINIT_ARRAY, DT_INIT and DT_INIT_ARRAY
constructors when loading shared libraries and dynamic executables,
*before* calling the executable's entry point (i.e. arch-$ARCH/bionic/crtbegin_dynamic.c)
which in turns call __libc_init() in libc.so, as defined by bionic/libc_init_dynamic.c

The latter did call these constructors array again, mistakenly.

The patch also updates the documentation of many related functions.

Also adds a new section to linker/README.TXT explaining restrictions on
C library usage.

The patch has been tested on a Dream for stability issues with
proprietary blobs:

- H264 decoding works
- Camera + Video recording works
- GPS works
- Sensors work

The tests in system/extra/tests/bionic/libc/common/test_static_cpp_mutex.cpp has been
run and shows the static C++ constructor being called only once.
ibc_init_common.c
ibc_init_dynamic.c
ibc_init_static.c
thread_internal.h
0ba91ed3ca9e7340a2c55303034c3378967e2327 20-May-2009 David 'Digit' Turner <digit@google.com> Fix __eabi_atexit() implementation, as well as a bug in the BSD-originated __cxa_finalize() implementation
This patch uses "#if ANDROID" instead of "#if 1" in the __cxa_finalize() fix
abi.c
d386afcc41e92c96778d9b1a498199f48fa2d4aa 15-May-2009 David 'Digit' Turner <digit@google.com> revert to previous implementation of __aeabi_atexit() since the new one seems to crash a static ICU String destructor.
I don't have the time to investigate why right now, so a revert is preferred. Damn...
abi.c
3e16f84fcad103c97a2df4a58948835277043569 14-May-2009 David 'Digit' Turner <digit@google.com> Fix __aeabi_atexit to call __cxa_atexit properly. This function is defined by the C++ ABI for ARM document.
abi.c
1dc9e472e19acfe6dc7f41e429236e7eef7ceda1 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
_errno.c
_set_errno.c
rand48.c
rc4random.c
tomics_x86.c
asename.c
asename_r.c
irname.c
irname_r.c
lmalloc.c
lmalloc.h
rand48.c
abi.c
rand48.c
ork.c
ash.h
f_indextoname.c
f_nametoindex.c
octl.c
dexp.c
ibc_init_common.c
ibc_init_common.h
ibc_init_dynamic.c
ibc_init_static.c
ogd_write.c
alloc_leak.c
d5.c
d5.h
thread-timers.c
thread.c
thread_internal.h
trace.c
ututline.c
and48.h
ealpath.c
ules.jam
emaphore.c
ha1.c
sp.c
tubs.c
ystem_properties.c
hread_atexit.c
ime64.c
ime64_config.h
time.c
tmp.c
1767f908af327fa388b1c66883760ad851267013 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
_errno.c
_set_errno.c
rand48.c
rc4random.c
tomics_x86.c
asename.c
asename_r.c
irname.c
irname_r.c
lmalloc.c
lmalloc.h
rand48.c
abi.c
rand48.c
ork.c
ash.h
f_indextoname.c
f_nametoindex.c
octl.c
dexp.c
ibc_init_common.c
ibc_init_common.h
ibc_init_dynamic.c
ibc_init_static.c
ogd_write.c
alloc_leak.c
d5.c
d5.h
thread-timers.c
thread.c
thread_internal.h
trace.c
ututline.c
and48.h
ealpath.c
ules.jam
emaphore.c
ha1.c
sp.c
tubs.c
ystem_properties.c
hread_atexit.c
ime64.c
ime64_config.h
time.c
tmp.c
a799b53f10e5a6fd51fef4436cfb7ec99836a516 03-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@132589
thread-timers.c
fe5745033a4f397c62a4e00efd9257ac9f83755c 03-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@137055
thread-timers.c
6f04a0f4c72acff80dad04828cb69ef67fa609d1 19-Feb-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@132276
ogd.h
alloc_leak.c
thread-timers.c
2489551343aa89fc539f369f7689c941b78c08d1 13-Feb-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@131421
ogd_write.c
9f65adf2ba3bb15feb8b7a7b3eef788df3fd270e 11-Feb-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@130745
abi.c
thread.c
tubs.c
ime64.c
ime64_config.h
d37527501c85edcb3a6a7c8a0b6297d52d434897 20-Jan-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@127101
thread-timers.c
emaphore.c
e5cc1f386b167b9f7bfdebc7219e89aa9b71e4b2 16-Jan-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@126645
_errno.c
ibc_init_common.c
ibc_init_static.c
thread.c
4e468ed2eb86a2406e14f1eca82072ee501d05fd 18-Dec-2008 The Android Open Source Project <initial-contribution@android.com> Code drop from //branches/cupcake/...@124589
ork.c
f_indextoname.c
alloc_leak.c
thread-timers.c
thread.c
thread_internal.h
a27d2baa0c1a2ec70f47ea9199b1dd6762c8a349 21-Oct-2008 The Android Open Source Project <initial-contribution@android.com> Initial Contribution
_errno.c
_set_errno.c
rand48.c
rc4random.c
tomics_x86.c
asename.c
asename_r.c
irname.c
irname_r.c
lmalloc.c
lmalloc.h
rand48.c
abi.c
rand48.c
ash.h
f_nametoindex.c
octl.c
dexp.c
ibc_init_common.c
ibc_init_common.h
ibc_init_dynamic.c
ibc_init_static.c
ogd.h
ogd_write.c
alloc_leak.c
d5.c
d5.h
thread.c
thread_internal.h
trace.c
ututline.c
and48.h
ealpath.c
ules.jam
emaphore.c
ha1.c
sp.c
tubs.c
ystem_properties.c
hread_atexit.c
time.c
tmp.c