aboutsummaryrefslogtreecommitdiffstats
path: root/libc/private/bionic_tls.h
Commit message (Collapse)AuthorAgeFilesLines
* Update the number of jemalloc reserved keys.Christopher Ferris2015-04-151-8/+2
| | | | | | | jemalloc now uses a single key pointing to a structure rather than multiple keys. Change-Id: Ib76185a594ab2cd4dc400d9a7a5bc0a57a7ac92d
* Make ThreadLocalBuffer a class rather than a macro.Elliott Hughes2015-03-311-13/+17
| | | | | Bug: 19995392 Change-Id: I497c512648fbe66257da3fb3bcd5c9911f983705
* Use pthread_once for g_uselocale_key creation.Yabin Cui2015-03-051-2/+2
| | | | | Bug: 19625804 Change-Id: I57ec4c965067dc0c157c795c1f7217a3ca403286
* Better control of pthread keys used in bionic.Yabin Cui2015-03-041-2/+2
| | | | Change-Id: I1e1bc77c0e7879baead6c3417282ce549a1153b5
* Refactor pthread_key.cpp to be lock-free.Yabin Cui2015-03-031-17/+18
| | | | Change-Id: I20dfb9d3cdc40eed10ea12ac34f03caaa94f7a49
* Split the shared group data from the shared passwd data.Elliott Hughes2014-12-181-2/+3
| | | | | | | | | | | | | | 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
* Fix pthread key num calculation.Yabin Cui2014-12-121-5/+23
| | | | | Bug: 18723085 Change-Id: Iba2c834b350e4cdba0b2d771b221560a3e5df952
* Fix ptsname(3) and ttyname(3) to use TLS.Elliott Hughes2014-12-091-1/+1
| | | | | | Be safe by default. Change-Id: I6c4a3f1fd4eee3a651b3162ce95b7e873de57521
* Move common macros into bionic_macros.h.Christopher Ferris2014-06-181-2/+1
| | | | | Bug: 15590152 Change-Id: I730636613ef3653f68c5ab1d43b53beaf8e0dc25
* Revert "Revert "Lose the hand-written futex assembler.""Elliott Hughes2014-05-281-15/+10
| | | | | | | | | | | | | | | | | | | | | | 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
* Support for jemalloc to replace dlmalloc.Christopher Ferris2014-05-201-1/+8
| | | | | | | | | | | | 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
* Make uselocale(3) claim its pthread key in an ELF constructor.Elliott Hughes2014-04-181-1/+1
| | | | | | | | | | 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
* PTHREAD_KEYS_MAX cleanup.Elliott Hughes2013-12-121-7/+8
| | | | | | | | I fixed this bug a while back, but didn't remove it from the list, could have added a better test, and could have written clearer code that didn't require a comment. Change-Id: Iebdf0f9a54537a7d5cbca254a5967b1543061f3d
* Fix pthread_join.Elliott Hughes2013-11-181-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Switch pthread_create over to __bionic_clone.Elliott Hughes2013-11-151-0/+3
| | | | | | Bug: 8206355 Bug: 11693195 Change-Id: I04aadbc36c87e1b7e33324b9a930a1e441fbfed6
* Fix __errno for LP64 and clean up __get_tls.Elliott Hughes2013-10-091-36/+5
| | | | | | | | | | | 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
* Fix MIPS build.Elliott Hughes2013-10-061-1/+1
| | | | | | | | Although 'register' is deprecated, we need to use v1, and there's no way to do that through register constraints on the assembler fragment itself. Change-Id: Ib5b12c4c3652513d10cc61d4a4b11314ece25663
* libc: Remove deprecated registersynergydev2013-10-061-4/+4
| | | | | | | | | | | | | | In c++11, register has been deprecated, and libc is now built as gnu++11 From the documentation: A register specifier is a hint to the implementation that the variable so declared will be heavily used. [ Note: The hint can be ignored and in most implementations it will be ignored if the address of the variable is taken. This use is deprecated (see D.2) Change-Id: I459dc3f5f9de63fc09eeda3bc6700f31bdf20f6f
* x86_64: Fix get_tls and statvfsPavel Chupin2013-10-031-0/+6
| | | | | | | | | * 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>
* Fix mismatch between declaration and forward declarationBernhard Rosenkraenzer2013-09-181-1/+1
| | | | | | | | | | | | 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>
* Define PTHREAD_KEYS_MAX and _POSIX_THREAD_KEYS_MAX in a POSIX-compliant way.Elliott Hughes2013-07-291-1/+6
| | | | | | | | Also make sysconf use PTHREAD_STACK_MIN rather than redefining its own, different, constant. Bug: 9997352 Change-Id: I9a8e7d2b18e691439abfb45533e82c36eee9e81d
* Bump the number of TLS slots to 128.Elliott Hughes2013-07-251-1/+1
| | | | | Bug: 9997352 Change-Id: I7bde7228d803e9d4bb83309c5891d54a07e3b025
* Clean up __builtin_expect usage.Elliott Hughes2013-07-161-3/+0
| | | | | | | Also remove some dead code; our malloc debugging doesn't use this any more. Change-Id: Id69cf182371f5f37d40b5bbd08f2744ade286e66
* Always use v1 for MIPS TLS access.Elliott Hughes2013-06-181-1/+2
| | | | Change-Id: Ic2850b90185cfbc5b0eff804c8b74a1c553c0852
* don't hardcode register r0/v1 when reading the TLSMathias Agopian2013-06-171-12/+9
| | | | | | this leads to much improved code when calling __get_tls() Change-Id: I21d870fb33c33a921ca55c4e100772e0f7a8d1e4
* Hide various symbols that shouldn't be exposed.Elliott Hughes2013-03-151-1/+1
| | | | | | | A mangled symbol in libc.so is a symbol that shouldn't be exported by libc.so. Change-Id: Id92d1e1968b3d11d111a5d9ef692adb1ac7694a1
* Fix the pthread_setname_np test.Elliott Hughes2013-02-151-3/+0
| | | | | | | | | | | | | | | 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
* Everyone has a TLS register.Elliott Hughes2013-02-121-42/+12
| | | | Change-Id: Id7cdf67087aa7d5074c9c59b7e595bc391d9f146
* Revert "Revert "More pthreads cleanup.""Elliott Hughes2013-02-121-8/+20
| | | | | | | | | 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
* Revert "More pthreads cleanup."Elliott Hughes2013-02-121-20/+8
| | | | | | This reverts commit 2a1bb4e64677b9abbc17173c79768ed494565047 Change-Id: Ia443d0748015c8e9fc3121e40e68258616767b51
* More pthreads cleanup.Elliott Hughes2013-02-111-8/+20
| | | | | | | | | | | | | | | | | | | | 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
* Revert "Revert "Pull the pthread_key_t functions out of pthread.c.""Elliott Hughes2013-02-111-14/+12
| | | | | | | | This reverts commit 6260553d48f6fd87ca220270bea8bafdde5726ec (Removing the accidental libm/Android.mk change.) Change-Id: I6cddd9857c31facc05636e8221505b3d2344cb75
* Revert "Pull the pthread_key_t functions out of pthread.c."Elliott Hughes2013-02-111-12/+14
| | | | | | | | This reverts commit ad59322ae432d11ff36dcf046016af8cfe45fbe4 somehow my unfinished libm/Android.mk change got into here. Change-Id: I46be626c5269d60fb1ced9862f2ebaa380b4e0af
* Pull the pthread_key_t functions out of pthread.c.Elliott Hughes2013-02-111-14/+12
| | | | | | | | | | | | 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
* Switch to using AT_RANDOM for the stack guards.Elliott Hughes2013-02-081-3/+5
| | | | | Bug: 7959813 Change-Id: I8db4b8912ba649bfe668c6f22aa44690ddd401a2
* Clean up the argc/argv/envp/auxv handling.Elliott Hughes2013-02-071-1/+1
| | | | | | | | 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
* Revert "stack protector: use AT_RANDOM"Nick Kralevich2013-01-161-2/+1
| | | | | | | | | | | | | | | | | | 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
* stack protector: use AT_RANDOMNick Kralevich2013-01-161-1/+2
| | | | | | | | | | | 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
* Per-thread -fstack-protector guards for x86.Elliott Hughes2012-10-251-10/+5
| | | | | | | | | | | | | | | | | 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
* Make dlerror(3) thread-safe.Elliott Hughes2012-10-161-14/+7
| | | | | | | | | | | | | 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
* [MIPS] Support for TLS registerRaghu Gandham2012-08-021-2/+13
| | | | | Change-Id: I6b5194e5e379b573e3b1203d8015e20fb3edd647 Signed-off-by: Chris Dearman <chris@mips.com>
* Initialize TLS before any application code is run.Evgeniy Stepanov2012-04-131-0/+3
| | | | | | | | | | | | | | | 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
* Fix __get_tls() in static C library to use kernel helpers.David 'Digit' Turner2010-08-271-9/+35
| | | | | | | This is needed to fix gdbserver's handling of threaded programs, among other things. Change-Id: I823387c602cef9891532da946a01db14be780ab0
* resolved conflicts for merge of 4a05d12c to eclair-plus-aospDavid 'Digit' Turner2009-09-221-3/+13
|\
| * Fix TLS access for ARMv6 and beyond.David 'Digit' Turner2009-09-221-1/+12
| | | | | | | | | | | | | | | | | | | | For performance reasons, we don't call the kernel helper. Instead, we directly access the TLS register on ARMv6 and higher. For ARMv5TE, keep using the hard-coded address populated by the kernel on each task switch. NOTE: Since we don't call the kernel helper, this must precisely match your kernel configuration. This is controlled by setting the ARCH_ARM_HAVE_TLS_REGISTER variable to 'true' in your board configuration file.
* | Linux kernel helpers support is provided to android for its TLS ↵vinay harugop2009-09-161-1/+3
|/ | | | | | | | implementation. This fix addresses this by modifying the TLS access functions to use the kernel helper. This Fix is verified on ST Ericsson's U8500 platform and Submitted on behalf of a third-party: Surinder-pal SINGH from STMicroelectronics.
* Pass the elfdata pointer in a slot of the temporary TLS area.David 'Digit' Turner2009-07-171-0/+7
| | | | | | | | | | | | | | | | This is needed to properly initialize the C runtime when libc.so is loaded by the dynamic linker. Move the temporary TLS setup before the first system call, just in case something really horrible happens, we won't crash when trying to write an error code in 'errno' Remove the broken TLS_SLOT_THREAD_ID setup. First, this slot should normally receive the address of a pthread_internal_t, not a kernel thread identifier. Second, it is never used by the linker anyway. Also remove an obsolete comment.
* auto import from //depot/cupcake/@135843The Android Open Source Project2009-03-031-0/+94
|
* auto import from //depot/cupcake/@135843The Android Open Source Project2009-03-031-94/+0
|
* auto import from //branches/cupcake/...@126645The Android Open Source Project2009-01-151-0/+94