History log of /bionic/libc/bionic/libc_init_common.cpp
Revision Date Author Comments
642182341018b282148280a7bdb771493e15bd7d 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>

(cherry picked from commit 57b7a6110e7e8b446fc23cce4765ff625ee0a105)

Change-Id: I87e679ee1c0db8092f2d1221c8e7c1461545c5a4
3002131da33401cf1b45abbdbec58b7c751fc43a 16-Jul-2014 Elliott Hughes <enh@google.com> Use VDSO for clock_gettime(2) and gettimeofday(2).

Bug: 15387103

(cherry picked from commit 625993dfbb085a3cde7492eda8ec1cdc1ee39a78)

Change-Id: I0e156d7049ba1495902259071a96936592e74025
38778e3b6c89689bbdd01f4a52ac88f02bf59783 11-Jul-2014 Dmitriy Ivanov <dimitry@google.com> Upstream atexit

Change-Id: Ia454a2181b5058ed9783dc02b6b1805d0e4d2715
(cherry picked from commit 53c3c271dc9927dd280981fc23409af60f460007)
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
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
cef3faec0ea40fdfe58e425fd0be64f00de6a26d 20-Nov-2013 Elliott Hughes <enh@google.com> Clean up pthread_internal_t.

Bug: 11755300
Change-Id: Ib509e8c5ec6b23513aa78b5ac5141d7c34ce2dc8
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
70b24b1cc2a1a4436b1fea3f8b76616fdcb27224 15-Nov-2013 Elliott Hughes <enh@google.com> Switch pthread_create over to __bionic_clone.

Bug: 8206355
Bug: 11693195
Change-Id: I04aadbc36c87e1b7e33324b9a930a1e441fbfed6
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>
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
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>
50af69e8f326b2762a44d5fea2b118e7616e5d20 14-Sep-2013 Brian Carlstrom <bdc@google.com> Simplify main thread stack size initialization

Change-Id: Iec09433d9de501031cce09dc75848a5e8f3d96bf
322e7bce235ec6e3f82f65669423a1d9e997b51e 13-Sep-2013 Brian Carlstrom <bdc@google.com> Use kernel default for initial thread size

Bug: 10697851

Change-Id: I8d980f5e0b584799536f6e6b891056c968d26cdf
7751d9158f2dede814be920f80f5ff0b60856d1a 13-Sep-2013 Brian Carlstrom <bdc@google.com> Use kernel default for initial thread size

Bug: 10697851

Change-Id: I8d980f5e0b584799536f6e6b891056c968d26cdf
9a74e36f4810ca22cb12f8eafe4f929edfa57e58 13-Sep-2013 Brian Carlstrom <bdc@google.com> Use kernel default for initial thread size

Bug: 10697851

Change-Id: I8d980f5e0b584799536f6e6b891056c968d26cdf
7b4d77e400d321ccc7cdadd1cd225ebb1a69d358 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

(cherry picked from commit 0d787c1fa18c6a1f29ef9840e28a68cf077be1de)

Change-Id: I5daeeaa36c1fc23f7f437d73a19808d9d558dd4d
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
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
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
6d339182070b035ca94f19bc37c94f4d9813c374 13-Feb-2013 Elliott Hughes <enh@google.com> Simplify pthread_create, using more public API.

Change-Id: I08e65ba88ed01436223e4e528631c9e41ec0e7f4
d3920b3a996b358e48232f417aa0a1e44a60f155 08-Feb-2013 Elliott Hughes <enh@google.com> Switch to using AT_RANDOM for the stack guards.

Bug: 7959813
Change-Id: I8db4b8912ba649bfe668c6f22aa44690ddd401a2
e4ccf5a138a9c6387ee2e4b8e41d628e0a2cc336 07-Feb-2013 Elliott Hughes <enh@google.com> __progname should be const char*, not char*.

Change-Id: I8e846872c30a712fbc05c8da59ffa1cec1be31a4
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