summaryrefslogtreecommitdiff
path: root/libc/upstream-openbsd
AgeCommit message (Collapse)Author
2021-01-11Fewer copies of ALIGN()/ALIGNBYTES.Elliott Hughes
Noticed while updating fts.c. Bug: http://b/177003648 Test: treehugger Change-Id: Ic3625c1c3af47c4dafb8ad686bbbddbc82b69b70
2020-12-08Simplify and improve tempnam() and tmpnam().Elliott Hughes
They're both obsolescent in POSIX.1-2008, and you really shouldn't be using them, but since we can't actually delete them... This change makes them both obey $TMPDIR if set, and fall back to /data/local/tmp otherwise. That's as good as we've managed for anything else such as tmpfile(3). Also add some tests. Bug: http://b/174682340 Test: treehugger Change-Id: Ieef99dcc2062f84b2b7cbae046787fdfe975e772
2020-08-06Switch to musl memmem (via OpenBSD).Elliott Hughes
Similar to the musl strstr. This patch also increases test coverage for memmem, again similar to the strstr tests. Test: treehugger Change-Id: I7f4a2ab93a610cb692994d06d2512976e657ae9f
2020-07-31Sync with upstream OpenBSD.Elliott Hughes
Test: treehugger Change-Id: I1fc649ba5d79a3d95242c6b2240dbb05c85d30e9
2020-06-11Update upstream OpenBSD gdtoa.Elliott Hughes
Also add a test for the bug that this fixes. Bug: http://b/152588929 Test: treehugger Change-Id: I58055b3ebaef457721bb4f5d8a8710025122b2e7
2020-04-16arc4random.h: remove some cruft.Elliott Hughes
This hasn't been used since the code was rewritten years ago. Test: builds Change-Id: I2c4bccb3fffb15115083afbb178519bd133c64de
2020-01-30Fully disable clang format where needed.Christopher Ferris
Even with formatting off, clang still tries to rearrange the include files or the using statements, so disable that too. Test: Verified that the include directories are not rearranged. Change-Id: I991a1b2bfa94a8202c5a486664658d654f1c7811
2020-01-29Link .clang-format file to system/core one.Christopher Ferris
Use the .clang-format-2 found in system/core instead of this which is not actually being used. Also, enable clang-format running by default. All upstream directories are marked as ignoring formatting so that their source files are not modified. Test: NA Change-Id: Icee6030f373fa5f072df162f97e6f34320e3d89a
2019-11-22Sync with upstream OpenBSD strstr().Elliott Hughes
Bug: http://b/124855136 Test: treehugger Change-Id: I6cbeb82bc0e418f50e6c171ac4e38e335c448db8
2019-11-20Take a bunch of trivial patches from upstream OpenBSD.Elliott Hughes
Test: treehugger Change-Id: Ie18a94cddada926eff23b53ac9e4d5e5cabd91ed
2019-10-30Merge "Clean up some obsolete OpenBSD portability cruft."Elliott Hughes
2019-10-29Clean up some obsolete OpenBSD portability cruft.Elliott Hughes
Test: treehugger Change-Id: Ic76a55cf28b862d51fa3f96549eb99e992e72954
2019-10-29Add arm64 string.h function implementations for use with hardware supporting ↵Peter Collingbourne
MTE. As it turns out, our "generic" arm64 implementations of certain string.h functions are not actually generic, since they will eagerly read memory possibly outside of the bounds of an MTE granule, which may lead to a segfault on MTE-enabled hardware. Therefore, move the implementations into a "default" directory and use ifuncs to select between them and a new set of "mte" implementations, conditional on whether the hardware and kernel support MTE. The MTE implementations are currently naive implementations written in C but will later be replaced with a set of optimized assembly implementations. Bug: 135772972 Change-Id: Ife37c4e0e6fd60ff20a34594cc09c541af4d1dd7
2019-10-08Reimplement the <ctype.h> is* functions.Elliott Hughes
Following on from the towlower()/towupper() changes, add benchmarks for most of <ctype.h>, rewrite the tests to cover the entire defined range for all of these functions, and then reimplement most of the functions. The old table-based implementation is mostly a bad idea on modern hardware, with only ispunct() showing a significant benefit compared to any other way I could think of writing it, and isalnum() a marginal but still convincingly genuine benefit. My new benchmarks make an effort to test an example from each relevant range of characters to avoid, say, accidentally optimizing the behavior of `isalnum('0')` at the expense of `isalnum('z')`. Interestingly, clang is able to generate what I believe to be the optimal implementations from the most readable code, which is impressive. It certainly matched or beat all my attempts to be clever! The BSD table-based implementations made a special case of EOF despite having a `_ctype_` table that's offset by 1 to include EOF at index 0. I'm not sure why they didn't take advantage of that, but removing the explicit check for EOF measurably improves the generated code on arm and arm64, so even the two functions that still use the table benefit from this rewrite. Here are the benchmark results: arm64 before: BM_ctype_isalnum_n 3.73 ns 3.73 ns 183727137 BM_ctype_isalnum_y1 3.82 ns 3.81 ns 186383058 BM_ctype_isalnum_y2 3.73 ns 3.72 ns 187809830 BM_ctype_isalnum_y3 3.78 ns 3.77 ns 181383055 BM_ctype_isalpha_n 3.75 ns 3.75 ns 189453927 BM_ctype_isalpha_y1 3.76 ns 3.75 ns 184854043 BM_ctype_isalpha_y2 4.32 ns 3.78 ns 186326931 BM_ctype_isascii_n 2.49 ns 2.48 ns 275583822 BM_ctype_isascii_y 2.51 ns 2.51 ns 282123915 BM_ctype_isblank_n 3.11 ns 3.10 ns 220472044 BM_ctype_isblank_y1 3.20 ns 3.19 ns 226088868 BM_ctype_isblank_y2 3.11 ns 3.11 ns 220809122 BM_ctype_iscntrl_n 3.79 ns 3.78 ns 188719938 BM_ctype_iscntrl_y1 3.72 ns 3.71 ns 186209237 BM_ctype_iscntrl_y2 3.80 ns 3.80 ns 184315749 BM_ctype_isdigit_n 3.76 ns 3.74 ns 188334682 BM_ctype_isdigit_y 3.78 ns 3.77 ns 186249335 BM_ctype_isgraph_n 3.99 ns 3.98 ns 177814143 BM_ctype_isgraph_y1 3.98 ns 3.95 ns 175140090 BM_ctype_isgraph_y2 4.01 ns 4.00 ns 178320453 BM_ctype_isgraph_y3 3.96 ns 3.95 ns 175412814 BM_ctype_isgraph_y4 4.01 ns 4.00 ns 175711174 BM_ctype_islower_n 3.75 ns 3.74 ns 188604818 BM_ctype_islower_y 3.79 ns 3.78 ns 154738238 BM_ctype_isprint_n 3.96 ns 3.95 ns 177607734 BM_ctype_isprint_y1 3.94 ns 3.93 ns 174877244 BM_ctype_isprint_y2 4.02 ns 4.01 ns 178206135 BM_ctype_isprint_y3 3.94 ns 3.93 ns 175959069 BM_ctype_isprint_y4 4.03 ns 4.02 ns 176158314 BM_ctype_isprint_y5 3.95 ns 3.94 ns 178745462 BM_ctype_ispunct_n 3.78 ns 3.77 ns 184727184 BM_ctype_ispunct_y 3.76 ns 3.75 ns 187947503 BM_ctype_isspace_n 3.74 ns 3.74 ns 185300285 BM_ctype_isspace_y1 3.77 ns 3.76 ns 187202066 BM_ctype_isspace_y2 3.73 ns 3.73 ns 184105959 BM_ctype_isupper_n 3.81 ns 3.80 ns 185038761 BM_ctype_isupper_y 3.71 ns 3.71 ns 185885793 BM_ctype_isxdigit_n 3.79 ns 3.79 ns 184965673 BM_ctype_isxdigit_y1 3.76 ns 3.75 ns 188251672 BM_ctype_isxdigit_y2 3.79 ns 3.78 ns 184187481 BM_ctype_isxdigit_y3 3.77 ns 3.76 ns 187635540 arm64 after: BM_ctype_isalnum_n 3.37 ns 3.37 ns 205613810 BM_ctype_isalnum_y1 3.40 ns 3.39 ns 204806361 BM_ctype_isalnum_y2 3.43 ns 3.43 ns 205066077 BM_ctype_isalnum_y3 3.50 ns 3.50 ns 200057128 BM_ctype_isalpha_n 2.97 ns 2.97 ns 236084076 BM_ctype_isalpha_y1 2.97 ns 2.97 ns 236083626 BM_ctype_isalpha_y2 2.97 ns 2.97 ns 236084246 BM_ctype_isascii_n 2.55 ns 2.55 ns 272879994 BM_ctype_isascii_y 2.46 ns 2.45 ns 286522323 BM_ctype_isblank_n 3.18 ns 3.18 ns 220431175 BM_ctype_isblank_y1 3.18 ns 3.18 ns 220345602 BM_ctype_isblank_y2 3.18 ns 3.18 ns 220308509 BM_ctype_iscntrl_n 3.10 ns 3.10 ns 220344270 BM_ctype_iscntrl_y1 3.10 ns 3.07 ns 228973615 BM_ctype_iscntrl_y2 3.07 ns 3.07 ns 229192626 BM_ctype_isdigit_n 3.07 ns 3.07 ns 228925676 BM_ctype_isdigit_y 3.07 ns 3.07 ns 229182934 BM_ctype_isgraph_n 2.66 ns 2.66 ns 264268737 BM_ctype_isgraph_y1 2.66 ns 2.66 ns 264445277 BM_ctype_isgraph_y2 2.66 ns 2.66 ns 264327427 BM_ctype_isgraph_y3 2.66 ns 2.66 ns 264427480 BM_ctype_isgraph_y4 2.66 ns 2.66 ns 264155250 BM_ctype_islower_n 2.66 ns 2.66 ns 264421600 BM_ctype_islower_y 2.66 ns 2.66 ns 264341148 BM_ctype_isprint_n 2.66 ns 2.66 ns 264415198 BM_ctype_isprint_y1 2.66 ns 2.66 ns 264268793 BM_ctype_isprint_y2 2.66 ns 2.66 ns 264419205 BM_ctype_isprint_y3 2.66 ns 2.66 ns 264205886 BM_ctype_isprint_y4 2.66 ns 2.66 ns 264440797 BM_ctype_isprint_y5 2.72 ns 2.72 ns 264333293 BM_ctype_ispunct_n 3.52 ns 3.51 ns 198956572 BM_ctype_ispunct_y 3.38 ns 3.38 ns 201661792 BM_ctype_isspace_n 3.39 ns 3.39 ns 206896620 BM_ctype_isspace_y1 3.39 ns 3.39 ns 206569020 BM_ctype_isspace_y2 3.39 ns 3.39 ns 206564415 BM_ctype_isupper_n 2.76 ns 2.75 ns 254227134 BM_ctype_isupper_y 2.76 ns 2.75 ns 254235314 BM_ctype_isxdigit_n 3.60 ns 3.60 ns 194418653 BM_ctype_isxdigit_y1 2.97 ns 2.97 ns 236082424 BM_ctype_isxdigit_y2 3.48 ns 3.48 ns 200390011 BM_ctype_isxdigit_y3 3.48 ns 3.48 ns 202255815 arm32 before: BM_ctype_isalnum_n 4.77 ns 4.76 ns 129230464 BM_ctype_isalnum_y1 4.88 ns 4.87 ns 147939321 BM_ctype_isalnum_y2 4.74 ns 4.73 ns 145508054 BM_ctype_isalnum_y3 4.81 ns 4.80 ns 144968914 BM_ctype_isalpha_n 4.80 ns 4.79 ns 148262579 BM_ctype_isalpha_y1 4.74 ns 4.73 ns 145061326 BM_ctype_isalpha_y2 4.83 ns 4.82 ns 147642546 BM_ctype_isascii_n 3.74 ns 3.72 ns 186711139 BM_ctype_isascii_y 3.79 ns 3.78 ns 183654780 BM_ctype_isblank_n 4.20 ns 4.19 ns 169733252 BM_ctype_isblank_y1 4.19 ns 4.18 ns 165713363 BM_ctype_isblank_y2 4.22 ns 4.21 ns 168776265 BM_ctype_iscntrl_n 4.75 ns 4.74 ns 145417484 BM_ctype_iscntrl_y1 4.82 ns 4.81 ns 146283250 BM_ctype_iscntrl_y2 4.79 ns 4.78 ns 148662453 BM_ctype_isdigit_n 4.77 ns 4.76 ns 145789210 BM_ctype_isdigit_y 4.84 ns 4.84 ns 146909458 BM_ctype_isgraph_n 4.72 ns 4.71 ns 145874663 BM_ctype_isgraph_y1 4.86 ns 4.85 ns 142037606 BM_ctype_isgraph_y2 4.79 ns 4.78 ns 145109612 BM_ctype_isgraph_y3 4.75 ns 4.75 ns 144829039 BM_ctype_isgraph_y4 4.86 ns 4.85 ns 146769899 BM_ctype_islower_n 4.76 ns 4.75 ns 147537637 BM_ctype_islower_y 4.79 ns 4.78 ns 145648017 BM_ctype_isprint_n 4.82 ns 4.81 ns 147154780 BM_ctype_isprint_y1 4.76 ns 4.76 ns 145117604 BM_ctype_isprint_y2 4.87 ns 4.86 ns 145801406 BM_ctype_isprint_y3 4.79 ns 4.78 ns 148043446 BM_ctype_isprint_y4 4.77 ns 4.76 ns 145157619 BM_ctype_isprint_y5 4.91 ns 4.90 ns 147810800 BM_ctype_ispunct_n 4.74 ns 4.73 ns 145588611 BM_ctype_ispunct_y 4.82 ns 4.81 ns 144065436 BM_ctype_isspace_n 4.78 ns 4.77 ns 147153712 BM_ctype_isspace_y1 4.73 ns 4.72 ns 145252863 BM_ctype_isspace_y2 4.84 ns 4.83 ns 148615797 BM_ctype_isupper_n 4.75 ns 4.74 ns 148276631 BM_ctype_isupper_y 4.80 ns 4.79 ns 145529893 BM_ctype_isxdigit_n 4.78 ns 4.77 ns 147271646 BM_ctype_isxdigit_y1 4.74 ns 4.74 ns 145142209 BM_ctype_isxdigit_y2 4.83 ns 4.82 ns 146398497 BM_ctype_isxdigit_y3 4.78 ns 4.77 ns 147617686 arm32 after: BM_ctype_isalnum_n 4.35 ns 4.35 ns 161086146 BM_ctype_isalnum_y1 4.36 ns 4.35 ns 160961111 BM_ctype_isalnum_y2 4.36 ns 4.36 ns 160733210 BM_ctype_isalnum_y3 4.35 ns 4.35 ns 160897524 BM_ctype_isalpha_n 3.67 ns 3.67 ns 189377208 BM_ctype_isalpha_y1 3.68 ns 3.67 ns 189438146 BM_ctype_isalpha_y2 3.75 ns 3.69 ns 190971186 BM_ctype_isascii_n 3.69 ns 3.68 ns 191029191 BM_ctype_isascii_y 3.68 ns 3.68 ns 191011817 BM_ctype_isblank_n 4.09 ns 4.09 ns 171887541 BM_ctype_isblank_y1 4.09 ns 4.09 ns 171829345 BM_ctype_isblank_y2 4.08 ns 4.07 ns 170585590 BM_ctype_iscntrl_n 4.08 ns 4.07 ns 170614383 BM_ctype_iscntrl_y1 4.13 ns 4.11 ns 171495899 BM_ctype_iscntrl_y2 4.19 ns 4.18 ns 165255578 BM_ctype_isdigit_n 4.25 ns 4.24 ns 165237008 BM_ctype_isdigit_y 4.24 ns 4.24 ns 165256149 BM_ctype_isgraph_n 3.82 ns 3.81 ns 183610114 BM_ctype_isgraph_y1 3.82 ns 3.81 ns 183614131 BM_ctype_isgraph_y2 3.82 ns 3.81 ns 183616840 BM_ctype_isgraph_y3 3.79 ns 3.79 ns 183620182 BM_ctype_isgraph_y4 3.82 ns 3.81 ns 185740009 BM_ctype_islower_n 3.75 ns 3.74 ns 183619502 BM_ctype_islower_y 3.68 ns 3.68 ns 190999901 BM_ctype_isprint_n 3.69 ns 3.68 ns 190899544 BM_ctype_isprint_y1 3.68 ns 3.67 ns 190192384 BM_ctype_isprint_y2 3.67 ns 3.67 ns 189351466 BM_ctype_isprint_y3 3.67 ns 3.67 ns 189430348 BM_ctype_isprint_y4 3.68 ns 3.68 ns 189430161 BM_ctype_isprint_y5 3.69 ns 3.68 ns 190962419 BM_ctype_ispunct_n 4.14 ns 4.14 ns 171034861 BM_ctype_ispunct_y 4.19 ns 4.19 ns 168308152 BM_ctype_isspace_n 4.50 ns 4.50 ns 156250887 BM_ctype_isspace_y1 4.48 ns 4.48 ns 155124476 BM_ctype_isspace_y2 4.50 ns 4.50 ns 155077504 BM_ctype_isupper_n 3.68 ns 3.68 ns 191020583 BM_ctype_isupper_y 3.68 ns 3.68 ns 191015669 BM_ctype_isxdigit_n 4.50 ns 4.50 ns 156276745 BM_ctype_isxdigit_y1 3.28 ns 3.27 ns 214729725 BM_ctype_isxdigit_y2 4.48 ns 4.48 ns 155265129 BM_ctype_isxdigit_y3 4.48 ns 4.48 ns 155216846 I've also corrected a small mistake in the documentation for isxdigit(). Test: tests and benchmarks Change-Id: I4a77859f826c3fc8f0e327e847886882f29ec4a3
2019-09-27Optimize tolower(3)/toupper(3) from <ctype.h>.Elliott Hughes
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-02-05Switch to OpenBSD div/ldiv/lldiv.Elliott Hughes
Test: ran tests Change-Id: I6ecf5878162d7cee81af40edd4b44406196f49be
2019-02-05Move NetBSD string routines to OpenBSD.Elliott Hughes
NetBSD seems to be the least well maintained of our three BSD upstreams, and it's already the one we use the least. Let's push a little further in that direction... Test: new smoke tests Change-Id: Idfebd11794445fe14cbfa07177a7392a7b36a5e4
2018-09-26Add reallocarray(3).Elliott Hughes
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-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
2018-05-24Add generic arm non-neon memmove.Elliott Hughes
From OpenBSD. Bug: http://b/63992911 Test: ran tests Change-Id: If7d9166922776cdc9333ff04205f9c6312a812b3
2018-03-05Rewrite system(3) to use posix_spawn(3).Elliott Hughes
We saw crashes from pthread_exit+debuggerd on LP32 (https://issuetracker.google.com/72291624), and it seems like the equivalent problem should exist with system(3). I fixed posix_spawn(3) as part of that bug, so the easiest fix is probably to reuse that. Bug: http://b/72470344 Test: ran tests Change-Id: I05f838706f2b4a14ac3ee21292833e6c8579b0d4
2018-02-06Remove __overloadable/__RENAME_CLANGGeorge Burgess IV
Now that we have a clang that supports transparent overloads, we can kill all of this cruft, and restore our upstream sources to their untouched glory. Woohoo! Bug: 12231437 Test: Built aosp_marlin; no obvious patch-related aosp_mips issues. Change-Id: I520a19d014f12137f80e43f973dccd6711c571cd
2018-01-12Clean up the time(2) implementation.Elliott Hughes
This is also slightly faster for the no VDSO case (56ns vs 66ns). Bug: N/A Test: ran tests, benchmarks Change-Id: I2b0edd06ee6942eb57c32678279278a53ca5ee9b
2018-01-11bionic: add vdso time()Mark Salyzyn
time() can be a hot call, and it currently uses __vdso_gettimeofday, which is already pretty fast (~3 times faster than the syscall), but with a __vdso_time call it is ~3 times even faster, in part because __vdso_time does not require interlocking with updates, and the read for just the seconds is atomic. __vdso_time is always available, whereas __vdso_gettimeofday is gated on access to the physical timers. arm improvement is compelling (x10), x86 improvement is even more pronounced (x100). [TL;DR] w/vdso32 kernel patches, locked cores to MAX, little cores only. BEFORE: hikey960 vdso (aarch64): ---------------------------------------------------------------------- Benchmark Time CPU Iterations ---------------------------------------------------------------------- BM_time_clock_gettime 48 ns 48 ns 15414753 BM_time_clock_gettime_syscall 175 ns 175 ns 4062031 BM_time_clock_gettime_REALTIME 44 ns 44 ns 15897875 BM_time_clock_gettime_BOOTTIME 47 ns 47 ns 14307903 BM_time_clock_gettime_TAI 210 ns 210 ns 3341372 BM_time_clock_gettime_unsupported 100 ns 100 ns 7030649 BM_time_gettimeofday 47 ns 47 ns 14969643 BM_time_gettimeofday_syscall 163 ns 163 ns 4283542 BM_time_time 59 ns 59 ns 11815385 hikey960 vdso32 (aarch32): ---------------------------------------------------------------------- Benchmark Time CPU Iterations ---------------------------------------------------------------------- BM_time_clock_gettime 90 ns 90 ns 7572898 BM_time_clock_gettime_syscall 251 ns 251 ns 2763442 BM_time_clock_gettime_REALTIME 81 ns 80 ns 8699536 BM_time_clock_gettime_BOOTTIME 97 ns 97 ns 7256667 BM_time_clock_gettime_TAI 272 ns 272 ns 2570419 BM_time_clock_gettime_unsupported 160 ns 160 ns 4379819 BM_time_gettimeofday 73 ns 73 ns 9608922 BM_time_gettimeofday_syscall 200 ns 199 ns 3527957 BM_time_time 123 ns 123 ns 5651095 x86_64 (glibc): -------------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------------- BM_time_clock_gettime 21 ns 21 ns 28873070 BM_time_clock_gettime_syscall 224 ns 224 ns 3095370 BM_time_clock_gettime_REALTIME 17 ns 17 ns 42083086 BM_time_clock_gettime_BOOTTIME 239 ns 239 ns 2924015 BM_time_clock_gettime_TAI 236 ns 236 ns 2961423 BM_time_clock_gettime_unsupported 221 ns 221 ns 3357696 BM_time_gettimeofday 22 ns 22 ns 27975154 BM_time_gettimeofday_syscall 238 ns 238 ns 2882032 BM_time_time 2 ns 2 ns 340354885 BM_time_time_syscall 207 ns 207 ns 3383073 imx7d_pico IOT nyc (w/arm,cpu-registers-not-fw-configured) (armv7a): (virtual timers) Benchmark Time(ns) CPU(ns) Iterations ------------------------------------------------------------------ BM_time_clock_gettime 20 477 1489362 BM_time_clock_gettime_syscall 20 487 1458333 BM_time_clock_gettime_REALTIME 19 464 1400000 BM_time_clock_gettime_BOOTTIME 29 700 1000000 BM_time_clock_gettime_TAI 29 690 1000000 BM_time_clock_gettime_unsupported 9 227 3043478 BM_time_gettimeofday 18 444 1555556 BM_time_gettimeofday_syscall 19 456 1555556 BM_time_time 21 497 1166667 imx7d_pico IOT nyc (wo/arm,cpu-registers-not-fw-configured) (armv7a): (physical timers) Benchmark Time(ns) CPU(ns) Iterations ------------------------------------------------------------------ BM_time_clock_gettime 6 144 4666667 BM_time_clock_gettime_syscall 20 486 1400000 BM_time_clock_gettime_REALTIME 6 136 5000000 BM_time_clock_gettime_BOOTTIME 6 153 4375000 BM_time_clock_gettime_TAI 31 760 1000000 BM_time_clock_gettime_unsupported 10 233 3043478 BM_time_gettimeofday 6 140 5000000 BM_time_gettimeofday_syscall 19 450 1555556 BM_time_time 9 203 3500000 AFTER: hikey960 vdso (aarch64): -------------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------------- BM_time_clock_gettime 48 ns 48 ns 15414753 BM_time_clock_gettime_syscall 175 ns 175 ns 4062031 BM_time_clock_gettime_REALTIME 44 ns 44 ns 15897875 BM_time_clock_gettime_BOOTTIME 47 ns 47 ns 14307903 BM_time_clock_gettime_TAI 210 ns 210 ns 3341372 BM_time_clock_gettime_unsupported 100 ns 100 ns 7030649 BM_time_gettimeofday 47 ns 47 ns 14975314 BM_time_gettimeofday_syscall 164 ns 164 ns 4278797 BM_time_time 16 ns 16 ns 42932165 hikey960 vdso32 (aarch32): -------------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------------- BM_time_clock_gettime 90 ns 90 ns 7572898 BM_time_clock_gettime_syscall 251 ns 251 ns 2763442 BM_time_clock_gettime_REALTIME 81 ns 80 ns 8699536 BM_time_clock_gettime_BOOTTIME 97 ns 97 ns 7256667 BM_time_clock_gettime_TAI 272 ns 272 ns 2570419 BM_time_clock_gettime_unsupported 160 ns 160 ns 4379819 BM_time_gettimeofday 73 ns 73 ns 9596230 BM_time_gettimeofday_syscall 199 ns 199 ns 3575428 BM_time_time 35 ns 35 ns 19798801 imx7d_pico IOT nyc (w/arm,cpu-registers-not-fw-configured) (armv7a): Benchmark Time(ns) CPU(ns) Iterations ------------------------------------------------------------------ BM_time_clock_gettime 20 477 1489362 BM_time_clock_gettime_syscall 20 487 1458333 BM_time_clock_gettime_REALTIME 19 464 1400000 BM_time_clock_gettime_BOOTTIME 29 700 1000000 BM_time_clock_gettime_TAI 29 690 1000000 BM_time_clock_gettime_unsupported 9 227 3043478 BM_time_gettimeofday 18 444 1555556 BM_time_gettimeofday_syscall 19 456 1555556 BM_time_time 2 50 11666667 imx7d_pico IOT nyc (wo/arm,cpu-registers-not-fw-configured) (armv7a): Benchmark Time(ns) CPU(ns) Iterations ------------------------------------------------------------------ BM_time_clock_gettime 6 144 4666667 BM_time_clock_gettime_syscall 20 486 1400000 BM_time_clock_gettime_REALTIME 6 136 5000000 BM_time_clock_gettime_BOOTTIME 6 153 4375000 BM_time_clock_gettime_TAI 31 760 1000000 BM_time_clock_gettime_unsupported 10 233 3043478 BM_time_gettimeofday 6 140 5000000 BM_time_gettimeofday_syscall 19 450 1555556 BM_time_time 2 50 10000000 Test: bionic-unit-tests --gtest_filter=time.time taskset F bionic-benchmarks --bionic_xml=vdso.xml \ --benchmark_filter='BM_time_(time*|clock_gettime*|gettimeofday*)' Bug: 63737556 Change-Id: I81b088a12ca41a6c4733d46c5477527777138efa
2017-12-19Refactor the ato* and strto* family.Elliott Hughes
There are no meaningful changes here, just a minimal conversion to two C++ templates to make further changes easier. Bug: N/A Test: ran tests, benchmarks Change-Id: I958fbf17a85f19dd8f17bfb4bbb9314d220daa3b
2017-10-31Merge "More missing _unlocked <stdio.h> functions."Treehugger Robot
2017-10-31More missing _unlocked <stdio.h> functions.Elliott Hughes
Also simplify trivial one-liners like perror/puts/fputs, and clean up fread/fwrite slightly. Fix perror to match POSIX. Add basic perror and *_unlocked tests. Bug: N/A Test: ran tests Change-Id: I63f83c8e0c15c3c4096509d17421ac331b6fc23d
2017-10-30Fork vfprintf.c/vfwprintf.c.Elliott Hughes
Future changes will start reducing the duplication... Bug: http://b/67371539 Test: ran tests Change-Id: I477afea34f9e1f41817823984bd0548944ee5eec
2017-10-11Add missing includes.Dan Albert
Test: mma Bug: None Change-Id: I0221b213e08d07cc5ac0b704a86e98ae8c0f456f
2017-09-29Add <sys/random.h>.Elliott Hughes
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-15Always log errno when aborting.Elliott Hughes
(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-08-22libc: Add support to allow library calls to find appropriate shell ↵Sandeep Patil
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 aa3e32422cc7089b9b15976f2651a58840d95e4f)
2017-07-24Merge "Replace fmemopen."Elliott Hughes
2017-07-24Merge "Apply recent strto* fix, add new tests."Elliott Hughes
2017-07-24Merge "Replace killpg."Elliott Hughes
2017-07-24Replace fmemopen.Elliott Hughes
A new implementation starting from the FreeBSD fmemopen rather than the OpenBSD one we used to use. The tests were arrived at by translating each sentence in http://pubs.opengroup.org/onlinepubs/9699919799/functions/fmemopen.html, plus http://man7.org/linux/man-pages/man3/fmemopen.3.html for historical GNU bugs. Bug: http://b/31304889 Test: ran tests Change-Id: Id8b168c9ecde638e9cdedbc3b8a0982fc83c7048
2017-07-13Switch to FreeBSD for wcsstr and wmemcpy.Elliott Hughes
Almost all of our w* functions come from FreeBSD already. The one downside is that we can't take all our w* functions from FreeBSD because FreeBSD handles locales very differently from us. Bug: N/A Test: ran tests Change-Id: I177b4332499992babd5d5afe5b3f469f8c4345a5
2017-07-13Apply recent strto* fix, add new tests.Elliott Hughes
The behavior with "0xy" was wrong: we'd swallow the 'x'. Bug: N/A Test: ran tests Change-Id: I2464d22a2408e99880303876306f18a25c390ad9
2017-07-11Replace killpg.Elliott Hughes
Upstream's killpg is diverging further from glibc behavior, so let's just fork. Bug: N/A Test: ran tests Change-Id: I70a3543018bc0a5c0bbf019ac527043b90568fda
2017-07-11Sync with upstream OpenBSD: trivial stuff.Elliott Hughes
No active ingredient to any of these changes. Bug: N/A Test: builds Change-Id: Ib1191a5c2826da024245d03dfc57557c8903a6cc
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
2017-05-03Move libc_log code into libasync_safe.Christopher Ferris
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-02-09libc: add clang FORTIFY supportGeorge Burgess IV
This patch adds clang-style FORTIFY to Bionic. For more information on FORTIFY, please see https://goo.gl/8HS2dW . This implementation works for versions of clang that don't support diagnose_if, so please see the "without diagnose_if" sections. We plan to swap to a diagnose_if-based FORTIFY later this year (since it doesn't really add any features; it just simplifies the implementation a lot, and it gives us much prettier diagnostics) Bug: 32073964 Test: Builds on angler, bullhead, marlin, sailfish. Bionic CTS tests pass on Angler and Bullhead. Change-Id: I607aecbeee81529709b1eee7bef5b0836151eb2b
2017-01-07Move to .md files for even trivial documentation.Elliott Hughes
So it's automatically displayed for folks browsing the source. Bug: N/A Test: N/A Change-Id: I80e823415f1fb12ad8ce5348e926519b6e29580f
2016-11-19Implement <langinfo.h>.Elliott Hughes
POSIX locale only, as usual. The GNU YESSTR and NOSTR extensions return the empty string in the C locale, so I haven't bothered supporting them. Bug: http://b/1401872 Test: bionic tests Change-Id: I6846839e4f9f1812344ed5dce0b93f83c0c20eb3
2016-10-11Allocate all arc4random data on the same page.Elliott Hughes
Saves one dirty page per process. Test: bionic unit tests, reboot, manual check of /proc/*/maps Change-Id: Ibbcafa955d60e43f4cb735fa484c6868aa357cd5
2016-09-15Fix instances of '#if __LP64__'.Josh Gao
Triggers -Wundef, which is on in -Weverything. Bug: http://b/31496165 Change-Id: Ib06107073f7dd1d584c19c222d0430da9d35630b
2016-09-07Fix sscanf/wcstod parsing of NaNs.Elliott Hughes
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-08-26Revert "Switch back to the BSD exec for now."Elliott Hughes
This reverts commit 18c31d7f4c93309a0f316412fcc6a829e41eaaae. 63615066d9f0b0b1c653c91a9b305e6c292c835a fixed the bug. Change-Id: I1d59c4be6ad1a05b23dce0198737f0789d7e034a