summaryrefslogtreecommitdiff
path: root/libc/stdlib
AgeCommit message (Collapse)Author
2020-06-10Move exit.c from stdlib to bionic subdirectory.Victor Khimenko
Test: make Change-Id: I2182d5a7c97abc0335e88d2d9dd9f77bc7e7f633
2020-03-06Rewrite __cxa_atexit / __cxa_finalizeRyan Prichard
Simplify: - Use a single memory-mapped region to hold the table of destructors. Double its capacity each time it is expanded. - Add a recompaction pass at the end of __cxa_finalize that shifts entries forward and uses madvise to clean pages. Bug: http://b/148055738 Test: bionic-unit-tests Change-Id: Ieb9da2b88640a8a5277d217b43826b5b7e246781
2019-05-04Revert fwalk/sfp locking to fix concurrent readsRyan Prichard
The locking can fail in a couple of ways: - A concurrent fread from an unbuffered or line-buffered file flushes the output of other line-buffered files, and if _fwalk locks every file, then the fread blocks until other file reads have completed. - __sfp can initialize a file lock while _fwalk is locking/unlocking it. For now, revert to the behavior Bionic had in previous releases. This commit reverts the file locking parts of commit 468efc80da2504f4ae7de8b5e137426d44dda9d7. Bug: http://b/131251441 Bug: http://b/130189834 Test: bionic unit tests Change-Id: I9e20b9cd8ccd14e7962f7308e174f08af72b56c6
2019-04-25__cxa_finalize: skip fflush call on dlcloseRyan Prichard
In __cxa_finalize, only call fflush(NULL) when the program is exiting, not when a library is unloaded with dlclose. This change restores behavior from 2015. Flushing output is needed when the program exits, but flushing everything is hazardous at other times because it can block -- fflush(NULL) locks every file, so it also blocks on read operations. Bug: http://b/130655235 Test: manual Change-Id: I2f5ecffa6724bfd98a93d145ab5313c793c01ae6
2018-08-22Add PR_SET_VMA and PR_SET_VMA_ANON_NAME to <sys/prctl.h>.Elliott Hughes
We've copied & pasted these to too many places. And if we're going to have another go at upstreaming these, that's probably yet another reason to have the *values* in just one place. (Even if upstream wants different names, we'll likely keep the legacy names around for a while for source compatibility.) Bug: http://b/111903542 Test: ran tests Change-Id: I8ccc557453d69530e5b74f865cbe0b458c84e3ba
2018-07-11Reimplement popen(3)/pclose(3).Elliott Hughes
pclose(3) is now an alias for fclose(3). We could add a FORTIFY check that you use pclose(3) if and only if you used popen(3), but there seems little value to that when we can just do the right thing. This patch also adds the missing locking to _fwalk --- we need to lock both the global list of FILE*s and also each FILE* we touch. POSIX says that "The popen() function shall ensure that any streams from previous popen() calls that remain open in the parent process are closed in the new child process", which we implement via _fwalk(fclose) in the child, but we might want to just make *all* popen(3) file descriptors O_CLOEXEC in all cases. Ignore fewer errors in popen(3) failure cases. Improve popen(3) test coverage. Bug: http://b/72470344 Test: ran tests Change-Id: Ic937594bf28ec88b375f7e5825b9c05f500af438
2017-10-27Mark __BIONIC_WEAK_FOR_NATIVE_BRIDGE symbolsdimitry
To make it easier for Native Bridge implementations to override these symbols. Bug: http://b/67993967 Test: make Change-Id: I4c53e53af494bca365dd2b3305ab0ccc2b23ba44
2017-05-11Clean up __isthreaded.Elliott Hughes
__isthreaded is annoying for ARC++ and useless for everyone. Just hard-code the value in ndk_cruft for LP32 and be done with it. Bug: N/A Test: builds Change-Id: I08f11a404bbec55ed57cb1e18b5116163c7d7d13
2015-12-05Revert "Revert "Remove __sinit and __sdidinit.""Elliott Hughes
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
2015-07-27name the atexit handler pagesDaniel Micay
Change-Id: I1718ddee7415a673b5818bc1455b8d90f1e8f9c6
2015-06-04Hide __atexitDmitriy Ivanov
Bug: http://b/21640806 Change-Id: I778b35c8c7538859179e97fcf5a82db2fcd9e50f
2015-04-24Unregister pthread_atfork handlers on dlclose()Dmitriy Ivanov
Bug: http://b/20339788 Change-Id: I874c87faa377645fa9e0752f4fc166d81fd9ef7e
2015-04-24Revert "Unregister pthread_atfork handlers on dlclose()"Dimitry Ivanov
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
2015-04-22Unregister pthread_atfork handlers on dlclose()Dmitriy Ivanov
Change-Id: I326fdf6bb06bed12743f08980b5c69d849c015b8
2015-04-15Call __cxa_thread_finalize for the main thread.Dmitriy Ivanov
Bug: http://b/20231984 Bug: http://b/16696563 Change-Id: I71cfddd0d404d1d4a593ec8d3bca9741de8cb90f
2014-07-14Upstream atexitDmitriy Ivanov
Change-Id: Ia454a2181b5058ed9783dc02b6b1805d0e4d2715
2014-07-10Slim down static binaries by avoiding stdio.Elliott Hughes
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
2014-06-18Hide __atexit and remove __atexit_invalid.Dan Albert
Bug: 11156955 Change-Id: I8c72edee8ecb92b75a282384277253bae19f7455
2014-05-15Register _cleanup function with atexitDmitriy Ivanov
* 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
2014-05-05Fixes for __cxa_finalizeDmitriy Ivanov
* Ability to register atexit handler from atexit handler * Correct way to handle both forms of atexit handler Bug: https://code.google.com/p/android/issues/detail?id=66595 Bug: 4998315 Change-Id: I39529afaef97b6e1469c21389d54c0d7d175da28
2014-04-22Switch to the upstream OpenBSD getenv/putenv/setenv implementation.Elliott Hughes
This fixes all the bugs found by the new tests. Change-Id: Id5a5f9f39a0620208bafa053f871a044725b4795
2014-04-18Upgrade our <ctype.h> implementation to OpenBSD head.Elliott Hughes
Adding the perfunctory <ctype.h> tests showed that we'd accidentally dropped several symbols. This puts everything back in its proper place and switches us to upstream head at the same time. Change-Id: Ib527ad280c9baded81e667fa598698526d93e66f
2014-04-18Merge "Changes our ctype identifiers to match the BSDs"Dan Albert
2014-04-18Changes our ctype identifiers to match the BSDsDan Albert
This is to make it possible to adopt the BSDs' implementations for a few locale APIs in libc++ rather than writing our own, nearly identical, code. Change-Id: I482acd4ece83aa4ec9eb0c7acf48f3686794bcc3
2014-04-16Switch to gdtoa.Elliott Hughes
This gives us a real strtold for LP64 and fixes various LP64 bugs. Bug: 13563801 Change-Id: I277858d718ee746e136b6b6308a495ba50dfa488
2014-04-08Clean up localeconv(3).Elliott Hughes
The OpenBSD doesn't support C99, and the extent to which we support locales is trivial, so just do it ourselves. Change-Id: If0a06e627ecc593f7b8ea3e9389365782e49b00e
2014-03-28Add lconv declaration and localeconv(3)Pavel Chupin
lconv is taken from ndk/sources/android/support/include/locale.h and matches bsd/glibc upstream. Keep old declaration for 32-bits for compatibility. localeconv.c and deps are taken from openbsd upstream. Changed strtod.c accordingly. Change-Id: I9fcc4d15f5674d192950d80edf26f36006cd31b4 Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2014-03-13Clean up reentrancy cruft.Elliott Hughes
The DNS copy of reentrant.h was unused, so remove it. The strtod implementation can use the upstream-netbsd reentrant.h and get a little closer to what was then upstream. (It's since been replaced by gdtoa, and we'll have to follow at some point, but for now this doesn't make anything any worse.) ANDROID_CHANGES is (now) only used in the DNS code, so push the -D down. The <locale.h> change prevents an LP32 hack from leaking into LP64. Change-Id: Idf30b98a59d7ca8f7c6cd6d07020b512057911ef
2014-02-21Clean up our OpenBSD usage.Elliott Hughes
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
2013-11-19bionic: call stdio cleanup on exitPawit Pornkitprasan
As of 61e699a133a4807fe878a6cb0d7190d7c96e21f8, stdio clean up functions are no longer registered in atexit and must be called manually via __cleanup. The issue this fixes is some static binaries linked against bionic cannot output properly when piped or redirected because the buffer is not flushed before closing. This is done by pulling in exit.c (and other dependencies) from netbsd. Change-Id: I193e54a6d08900f291550029fe75ce76394d9e22
2013-10-28AArch64: Add support for AArch64 to stdlib/strtod.cSerban Constantinescu
This patch adds support for AArch64 to strtod.c definitions. Change-Id: I9491c4371d921c00e73ae169877a9a71225731fb Signed-off-by: Serban Constantinescu <serban.constantinescu@arm.com>
2013-10-09Fix x86_64 build, clean up intermediate libraries.Elliott Hughes
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
2013-08-13Make ctype.h a little less unhygienic.Elliott Hughes
This caused trouble for stlport. Change-Id: Id40787c5a2b7a3a4e12fb557efe549778a01cbbd
2013-06-12Clean up abort.Elliott Hughes
* 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
2013-04-11Switch to current FreeBSD qsort.Elliott Hughes
Change-Id: Ic46cd0b663dc5fa78c99dd38db0bfe849a25e789
2013-02-16stdlib: atexit: include <sys/cdefs.h>Chirayu Desai
Change-Id: Ib9eb167710a021e0a2b5c77a06a9338cdc748e6d
2013-02-07Clean up the argc/argv/envp/auxv handling.Elliott Hughes
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
2012-10-23More upstream NetBSD upgrades.Elliott Hughes
Change-Id: Idb781d37de3b05585271d7d258ecffd5ba87d0b8
2012-10-01Move non-upstream code into the libc/bionic directory.Elliott Hughes
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
2012-10-01Upgrade seed48 too.Elliott Hughes
Missed this in 774c7f54ff375d71106283d42779b0cc5f238f87. Change-Id: Ic24fd67f003d0e2d192cfb08f96f63024ca817eb
2012-10-01Upgrade to the current NetBSD rand implementation.Elliott Hughes
Also add basic unit tests. Change-Id: I7fc7ef61d47c1e8fdf8b8eff67a635220c3afd56
2012-08-28ARM: make CRT_LEGACY_WORKAROUND work as intendedArd Biesheuvel
To properly support legacy ARM shared libraries, libc.so needs to export the symbols __dso_handle and atexit, even though these are now supplied by the crt startup code. This patch reshuffles the existing CRT_LEGACY_WORKAROUND conditionally compiled code slightly so it works as the original author likely intended. Change-Id: Id6c0e94dc65b7928324a5f0bad7eba6eb2f464b9 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
2012-07-31fix __cxa_finalize() implementation to be thread safe.Srinavasa Nagaraju
__cxa_finalize() modifies the access permissions of __atexit global variable without acquiring _ATEXIT_LOCK(). Fix it prevent any possible races. Change-Id: I11939d0ebcbf6f360c14163222d40a449d96948e
2012-07-27Report errors to the log, not just stderr.Elliott Hughes
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
2011-06-23am 1c0a0381: Merge "Enable functional DSO object destruction"David Turner
* commit '1c0a0381dfb3648ffadef9537ec9383d63d62473': Enable functional DSO object destruction
2011-06-20Enable functional DSO object destructionBruce Beare
Unfortunately, legacy .so files for ARM don't have a correct crtbegin file. Consequently, we have to grandfather the old __dso_handle behaviour. Add some ifdefs for ARM to allow it to use the old code until we can work out a transition. Change-Id: I6a28f368267d792c94e1d985d8344023bc632f6f Author: H.J. Lu <hongjiu.lu@intel.com> Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-01-17Bug 3330205 Thread safety for bignum powers of 5Glenn Kasten
Change-Id: I739a06f9037a9fb643276f61601f0f3e192581b8
2010-12-20libc: remove obsolete sha1hash.c source fileDavid 'Digit' Turner
The source file is not part of the C library build, so the Android.mk is unaffected. In other words, this source file was never compiled. Change-Id: Idec3d5b6ec30dc9ee38296d12dc6e522997df29a
2010-10-21am 958214aa: am 8ad63d74: Merge "stdlib: strtod: Hide internal symbol __dtoa"Jean-Baptiste Queru
Merge commit '958214aa998d9378e7d70c7c08ffab4c5f9d3fde' * commit '958214aa998d9378e7d70c7c08ffab4c5f9d3fde': stdlib: strtod: Hide internal symbol __dtoa
2010-10-19am 8ad63d74: Merge "stdlib: strtod: Hide internal symbol __dtoa"Jean-Baptiste Queru
Merge commit '8ad63d745d4ec1edea0bbd04fd0644983ad77bf5' into gingerbread-plus-aosp * commit '8ad63d745d4ec1edea0bbd04fd0644983ad77bf5': stdlib: strtod: Hide internal symbol __dtoa