Commit graph

43 commits

Author SHA1 Message Date
Colin Cross
048f24ed2a Export fts as a static library for use with musl
musl libc doesn't provide fts, but elfutils and libabigail need it.
Export bionic's fts as a staic library that can be linked into elfutils
and libabigail when compiling against musl.

fts uses recallocarray, which musl doesn't provide, so also include
recallocarray.c in libfts.a.

Requires minor tweaks to fts.c and a wrapper around fts.h to make them
compatible with musl, primarily by providing local definitions of macros
provided in bionic's sys/cdefs.h.

Bug: 190084016
Test: m libfts
Change-Id: Ifac9a59e7504c0c1f5f8a3a5bd3c19a13980b83c
2021-09-08 15:53:10 -07:00
Elliott Hughes
e1dc4f62eb Fewer copies of ALIGN()/ALIGNBYTES.
Noticed while updating fts.c.

Bug: http://b/177003648
Test: treehugger
Change-Id: Ic3625c1c3af47c4dafb8ad686bbbddbc82b69b70
2021-01-11 11:51:29 -08:00
Elliott Hughes
26b06073f6 Sync with upstream OpenBSD.
Test: treehugger
Change-Id: I1fc649ba5d79a3d95242c6b2240dbb05c85d30e9
2020-07-31 13:01:38 -07:00
Elliott Hughes
cdb4a26d29 Update upstream OpenBSD gdtoa.
Also add a test for the bug that this fixes.

Bug: http://b/152588929
Test: treehugger
Change-Id: I58055b3ebaef457721bb4f5d8a8710025122b2e7
2020-06-11 12:57:37 -07:00
Elliott Hughes
bb575d93c4 arc4random.h: remove some cruft.
This hasn't been used since the code was rewritten years ago.

Test: builds
Change-Id: I2c4bccb3fffb15115083afbb178519bd133c64de
2020-04-16 23:14:38 +00:00
Elliott Hughes
9a4b68e20d Take a bunch of trivial patches from upstream OpenBSD.
Test: treehugger
Change-Id: Ie18a94cddada926eff23b53ac9e4d5e5cabd91ed
2019-11-20 14:57:01 -08:00
Elliott Hughes
5c5152bff5 Clean up some obsolete OpenBSD portability cruft.
Test: treehugger
Change-Id: Ic76a55cf28b862d51fa3f96549eb99e992e72954
2019-10-29 19:59:28 -07:00
Elliott Hughes
1c8a2a99a7 Optimize tolower(3)/toupper(3) from <ctype.h>.
The tables in the BSD tolower/toupper are slower for ASCII than just
doing the bit twiddling.

We can't actually remove the tables on LP32, so move them into the
"cruft" we keep around for backwards compatibility (but remove them for
LP64 where they were never exposed).

I noticed that the new bit-twiddling tolower(3) was performing better
on arm64 than toupper(3). The 0xdf constant was requiring an extra MOV,
and there isn't a BIC that takes an immediate value. Since we've already
done the comparison to check that we're in the right range (where the
bit is always set), though, we can EOR 0x20 to get the same result as
the missing BIC 0x20 in just one instruction.

I've applied that same optimization to towupper(3) too.

Before:

  BM_ctype_tolower_n                 3.30 ns         3.30 ns    212353035
  BM_ctype_tolower_y                 3.31 ns         3.30 ns    211234204
  BM_ctype_toupper_n                 3.30 ns         3.29 ns    214161246
  BM_ctype_toupper_y                 3.29 ns         3.28 ns    207643473

  BM_wctype_towupper_ascii_n         3.53 ns         3.53 ns    195944444
  BM_wctype_towupper_ascii_y         3.48 ns         3.48 ns    199233248

After:

  BM_ctype_tolower_n                 2.93 ns         2.92 ns    242373703
  BM_ctype_tolower_y                 2.88 ns         2.87 ns    245365309
  BM_ctype_toupper_n                 2.93 ns         2.93 ns    243049353
  BM_ctype_toupper_y                 2.89 ns         2.89 ns    245072521

  BM_wctype_towupper_ascii_n         3.34 ns         3.33 ns    212951912
  BM_wctype_towupper_ascii_y         3.29 ns         3.29 ns    214651254

(Why do both the "y" and "n" variants speed up with the EOR
change? Because the compiler transforms the code so that we
unconditionally do the bit twiddling and then use CSEL to decide whether
or not to actually use the result.)

We also save 1028 bytes of data in the LP64 libc.so.

Test: ran the bionic benchmarks and tests
Change-Id: I7829339f8cb89a58efe539c2a01c51807413aa2d
2019-09-27 14:42:39 -07:00
Elliott Hughes
b177085ce7 Add reallocarray(3).
Originally a BSD extension, now in glibc too. We've used it internally
for a while.

(cherry-pick of e4b13f7e3ca68edfcc5faedc5e7d4e13c4e8edb9.)

Bug: http://b/112163459
Test: ran tests
Change-Id: I813c3a62b13ddb91ba41e32a5a853d09207ea6bc
Merged-In: I813c3a62b13ddb91ba41e32a5a853d09207ea6bc
2018-09-26 14:24:18 -07:00
Elliott Hughes
99d54656bd Add PR_SET_VMA and PR_SET_VMA_ANON_NAME to <sys/prctl.h>.
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-08-22 10:36:23 -07:00
Dan Albert
1c78cb0fee Add missing includes.
Test: mma
Bug: None
Change-Id: I0221b213e08d07cc5ac0b704a86e98ae8c0f456f
2017-10-11 11:25:52 -07:00
Elliott Hughes
8465e968a8 Add <sys/random.h>.
iOS 10 has <sys/random.h> with getentropy, glibc >= 2.25 has
<sys/random.h> with getentropy and getrandom. (glibc also pollutes
<unistd.h>, but that seems like a bad idea.)

Also, all supported devices now have kernels with the getrandom system
call.

We've had these available internally for a while, but it seems like the
time is ripe to expose them.

Bug: http://b/67014255
Test: ran tests
Change-Id: I76dde1e3a2d0bc82777eea437ac193f96964f138
2017-09-29 05:31:35 +00:00
Elliott Hughes
7b0af7ad82 Always log errno when aborting.
(Where errno is relevant.)

Also consistently use -1 as the fd for anonymous mmaps. (It doesn't matter,
but it's more common, and potentially more intention-revealing.)

Bug: http://b/65608572
Test: ran tests
Change-Id: Ie9a207632d8242f42086ba3ca862519014c3c102
2017-09-15 16:18:49 -07:00
Sandeep Patil
9b1ca569db libc: Add support to allow library calls to find appropriate shell executable for a process
Library calls like system() and popen() invoke the shell executable
pointed to by '_PATH_BSHELL' in order to run the command passed into the
function. The _PATH_BSHELL points to /system/bin/sh by default and thus
breaks any vendor process trying to use system() / popen(), as they are
denied access to system shell by selinux.

This CL make necessary changes, so the implmentations of system() and popen()
can use the appropriate shell (e.g. /vendor/bin/sh for processes running
out of /vendor partition). Also, changes the implementation of system()
and popen().

Bug: 64832610
Test: Manual, Using a test program running from /system/bin and
      /vendor/bin to ensure correct shell is being used.

Change-Id: Ie7168d69decb1ae98284446ae7db34dec930dc33
Merged-In: Ie7168d69decb1ae98284446ae7db34dec930dc33
Signed-off-by: Sandeep Patil <sspatil@google.com>
(cherry picked from commit aa3e32422c)
2017-08-22 10:17:28 -07:00
Elliott Hughes
f826a37b95 Apply recent strto* fix, add new tests.
The behavior with "0xy" was wrong: we'd swallow the 'x'.

Bug: N/A
Test: ran tests
Change-Id: I2464d22a2408e99880303876306f18a25c390ad9
2017-07-13 09:35:15 -07:00
Elliott Hughes
b364683ea6 Sync with upstream OpenBSD: trivial stuff.
No active ingredient to any of these changes.

Bug: N/A
Test: builds
Change-Id: Ib1191a5c2826da024245d03dfc57557c8903a6cc
2017-07-11 12:34:19 -07:00
Elliott Hughes
dfcb82d92d Clean up __isthreaded.
__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
2017-05-11 15:29:03 -07:00
Christopher Ferris
7a3681e5b6 Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.

Change the names of the functions to reflect the new name of the library.

Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.

Bug: 31919199

Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
2017-05-03 08:50:43 -07:00
Elliott Hughes
da01fa620c Allocate all arc4random data on the same page.
Saves one dirty page per process.

Test: bionic unit tests, reboot, manual check of /proc/*/maps
Change-Id: Ibbcafa955d60e43f4cb735fa484c6868aa357cd5
2016-10-11 13:07:44 -07:00
Josh Gao
b36efa4343 Fix instances of '#if __LP64__'.
Triggers -Wundef, which is on in -Weverything.

Bug: http://b/31496165
Change-Id: Ib06107073f7dd1d584c19c222d0430da9d35630b
2016-09-15 14:21:28 -07:00
Elliott Hughes
7f0849fd11 Fix sscanf/wcstod parsing of NaNs.
The parsefloat routines -- which let us pass NaNs and infinities on to
strto(f|d|ld) -- come from NetBSD.

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

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

Lots of new tests.

Bug: http://b/31101647
Change-Id: Id7d46ac2d8acb8770b5e8c445e87cfabfde6f111
2016-09-07 15:01:54 -07:00
Josh Gao
c80ffece02 Defer registration of the arc4random fork-detect handler.
Previously, arc4random would register a fork-detecting pthread_atfork
handler to not have to call getpid() after a fork. pthread_atfork uses
pthread_mutex_lock, which requires the current thread to be initialized,
preventing the use of arc4random for initializing the global stack guard,
which needs to happen before the main thread has been initialized.

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

Bug: http://b/29622562
Change-Id: I98c9329fa0e489c3f78cad52747eaaf2f5226b80
2016-06-28 15:52:59 -07:00
Elliott Hughes
b0da5760dc Move the IEEE fp header out of the public headers.
Bug: http://b/28519060
Change-Id: I9f1a1a9ac1f22462bf86991b57c51824cb42eefd
2016-05-02 12:44:41 -07:00
Elliott Hughes
506c6deff7 Sync with upstream OpenBSD.
Also some minor build cleanup.

Change-Id: Ibd20602d7ea45685f0c47fceb00ffd6c7ae35954
2016-01-15 16:30:18 -08:00
Christopher Ferris
a818445622 Rename LIBC64_HIDDEN to LIBC32_LEGACY_PUBLIC.
Change-Id: If4da9e46398ca5524f6f0680d70588e3dc7e80b4
2015-10-23 12:32:52 -07:00
Daniel Micay
516fcb28f2 name the arc4random structure mappings
Change-Id: I6e150e526f6ceee31aa9bd219fa45317d5a729cb
2015-08-02 19:22:26 -04:00
Dmitriy Ivanov
9cf6fc304b Hide __atexit
Bug: http://b/21640806
Change-Id: I778b35c8c7538859179e97fcf5a82db2fcd9e50f
2015-06-04 14:33:18 -07:00
Yabin Cui
3471fcbb6a Clean up paths.h.
Bug: 18905946
Change-Id: I02cd1ddd5c0b0af165685413bc1fb12ca6bf5f33
2015-01-09 20:04:04 -08:00
Elliott Hughes
998f2d5a50 Remove more BSD cruft from the public headers.
Change-Id: I1e3097f745b526db448bf72fbc05fb2ba23929a0
2014-12-19 19:30:11 -08:00
Elliott Hughes
2818279ace Sync with upstream OpenBSD fts.c.
Change-Id: Ia7e26b603f6461095b5a8d7e8a6cdf4f8279fa84
2014-11-21 19:27:28 -08:00
Elliott Hughes
c08c25b4c9 Sync with upstream findfp.c.
Change-Id: Ib298f46de0c4d0fd4ce0a9b456c163e8b8b06342
2014-09-24 10:32:30 -07:00
Chih-Hung Hsieh
b6b5cb5389 Ignore all __weak_alias in OpenBSD libC.
GCC assembler allows xyz to be redeclared as weak,
by __weak_alias(xyz, _xyz), while _xyz is undefined.
Clang does not like that but silently generates no code.
It will reject its own .s file if the assembly code is saved first.
Since we have no reason to define xyz or _xyz as weak symbol now,
and _xyz is a macro to xyz, we simplify libC to have only
xyz defined as global.

BUG: 17186746
Change-Id: I24b154425838683cae69248cc750c59e26fd5467
2014-08-28 15:10:01 -07:00
Elliott Hughes
cc7e5f489f Switch to OpenBSD <err.h> implementation.
Change-Id: Ia950d88871a30f68e74f9ac7dbd87788e128e02f
2014-08-26 17:00:37 -07:00
Elliott Hughes
b810462028 Fix _BSD_SOURCE/__USE_BSD.
Bug: 14659579
Change-Id: I80ec9584f054c02d1078828f6bca759c42bc1d4c
2014-08-19 09:18:03 -07:00
Elliott Hughes
2b67d7dee0 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
2014-07-21 14:38:16 -07:00
Elliott Hughes
a167eef548 Fix visibility for a bunch more symbols.
Bug: 11156955
Bug: 15291317
Change-Id: I664f25cce7c17085a101d6593d8e01525a1f6a90
2014-07-14 15:13:30 -07:00
Dmitriy Ivanov
53c3c271dc Upstream atexit
Change-Id: Ia454a2181b5058ed9783dc02b6b1805d0e4d2715
2014-07-14 12:05:16 -07:00
Dan Albert
f79ee064b6 Revert "Revert "Hide _tolower_tab_ and _toupper_tab_ on LP64.""
This reverts commit 715242fd0f.

Change-Id: Ia9892fa3b03287129aa72a49974cef9fd94ae735
2014-07-01 22:41:50 +00:00
Dan Albert
715242fd0f Revert "Hide _tolower_tab_ and _toupper_tab_ on LP64."
This reverts commit dd4ad5c463.

Change-Id: If3c9771825e460ce68604082f4feb0ca783e56c6
2014-06-19 03:57:05 +00:00
Dan Albert
dd4ad5c463 Hide _tolower_tab_ and _toupper_tab_ on LP64.
We can't hide them on LP32 because they appeared in NDK headers.

Bug: 11156955
Change-Id: I22bf5a0f4d330c04b49565bc598cd0568128d4fc
2014-06-18 13:11:07 -07:00
Elliott Hughes
b4e099c6f7 Remove issetugid.
Bug: 14569474
Change-Id: I752c77ed53c724f144f0b618443eb95e87f2929a
2014-05-29 16:43:01 -07:00
Elliott Hughes
9a5a3e8e74 Fix <math.h> to quieten most of our warnings.
I've reported the wcsftime bug upstream, but we really just want to use -D
to ensure the buggy code isn't built. (I've also brought our strftime a bit
closer to upstream now we have the right define.)

I don't think upstream is likely to fix all their sign-compare and
uninitialized warnings, so let's just silence them.

As for libm, again upstream isn't likely to fix all their warnings, and
silencing those made the ones that were our fault stand out. I've fixed
our <math.h> to fix the warnings caused by our lack of definitions for
the non-imprecise long-double functions. I checked the C99 standard, and
all these functions are there.

Change-Id: Iee8e1182c1db375058fb2c451eceb212bab47a37
2014-05-05 21:19:47 -07:00
Elliott Hughes
d39f3f2c2e Clean up and document our hacks for building BSD source.
Change-Id: Ic591e22fa5b363bb68376b9f25814c0e5bd83fbf
2014-04-21 17:13:46 -07:00