Commit graph

68 commits

Author SHA1 Message Date
Elliott Hughes
10a7e2799d Update the _FORTIFY_SOURCE documentation.
Change-Id: Icc73673b792dbc1a20ed70561a461e1fc47b2d6b
2024-05-02 19:13:37 +00:00
Elliott Hughes
a459c0b066 Update status.md.
We were still using "Android O" in developer-facing documentation, we'd forgotten to document the destroyed pthread_mutex_t behavior change, and we'd forgotten to document the existence of _Fork() and <android/crash_detail.h>.

Change-Id: Ie2c94a1956b7252472116cacc90f38fa4e2dd229
2024-03-27 02:16:49 +00:00
Elliott Hughes
9c06d16ca3 s/master/main/
Test: treehugger
Change-Id: I2c975b2f5f92f23c7357b6f7e785578504298cc6
2023-10-04 23:36:48 +00:00
Elliott Hughes
2109f12c3b Add strerrordesc_np() and strerrorname_np().
strerrordesc_np() isn't very useful (being just another name for
strerror()), but strerrorname_np() lets you get "ENOSYS" for ENOSYS,
which will make some of our test assertion messages clearer when we
switch over from strerror().

This also adds `%#m` formatting to all the relevant functions.

Test: treehugger
Change-Id: Icfe07a39a307d591c3f4f2a09d008dc021643062
2023-09-27 11:21:12 -07:00
Elliott Hughes
906d7d41e4 Merge "Add epoll_pwait2()." into main 2023-09-05 21:48:08 +00:00
Elliott Hughes
647472db9b <termios.h>: add two new POSIX functions.
musl already added tcgetwinsize() and tcsetwinsize(), but I didn't
notice.

Trivial single-line inlines added to a header that's already written
that way.

Test: treehugger
Change-Id: Iac95ea6a89f3872025c512f7e61987b81d0aafa7
2023-08-29 09:33:04 -07:00
Elliott Hughes
4c62e59fe6 Add epoll_pwait2().
I've also added doc comments for everything in <sys/epoll.h>.

I've also broken up the old "smoke" test (which was taking 2s on my
riscv64 qemu) to keep the total runtime for all the tests down to 200ms.

Test: treehugger
Change-Id: Icd939af51886fdf21432653a07373c1a0f26e422
2023-08-23 15:59:12 -07:00
Elliott Hughes
838dbacbfd linker: add LD_SHOW_AUXV support.
Yes, `od -t d8 /proc/self/auxv` is clever:
```
$ adb shell od -t d8 /proc/self/auxv
0000000                      33            488593047552
0000020                      51                    4720
0000040                      16                 1155071
0000060                       6                    4096
0000100                      17                     100
0000120                       3            375971917888
0000140                       4                      56
0000160                       5                      12
0000200                       7            488593051648
0000220                       8                       0
0000240                       9            375972184064
0000260                      11                       0
0000300                      12                       0
0000320                      13                       0
0000340                      14                       0
0000360                      23                       0
0000400                      25            549220780840
0000420                      26                       0
0000440                      31            549220786153
0000460                      15            549220780856
0000500                       0                       0
0000520
$
```
But this is a lot easier to read:
```
$ adb shell LD_SHOW_AUXV=1 date
AT_SYSINFO_EHDR      0x7065010000
AT_MINSIGSTKSZ       4720
AT_HWCAP             0b100011001111111111111
AT_PAGESZ            4096
AT_CLKTCK            100
AT_PHDR              0x5c79d60040
AT_PHENT             56
AT_PHNUM             12
AT_BASE              0x7065011000
AT_FLAGS             0
AT_ENTRY             0x5c79da1000
AT_UID               0
AT_EUID              0
AT_GID               0
AT_EGID              0
AT_SECURE            0
AT_RANDOM            0x7ff814eb98
AT_HWCAP2            0
AT_EXECFN            "/system/bin/date"
AT_PLATFORM          "aarch64"
Tue Aug 22 20:43:22 GMT 2023
```

Test: adb shell LD_SHOW_AUXV=1 date
Change-Id: I51c4e8cbb799eb1dc360c9417cc6f82bebdcda73
2023-08-22 14:25:01 -07:00
Elliott Hughes
f3d6b44e2b riscv64: add <sys/hwprobe.h>.
This is source compatible with the current proposal for glibc.

Bug: https://github.com/google/android-riscv64/issues/27
Test: treehugger
Change-Id: I428777e4eac1fe643d442a93a4b3ad1fdf0ffd97
2023-07-28 09:29:06 -07:00
Elliott Hughes
74d9765be9 Add __riscv_flush_icache() to <sys/cachectl.h>.
The obsolete mips header rides again!

The most interesting part of this change is that I've removed the hack
that meant that all system call wrappers starting with `__` defaulted to
being hidden symbols. That's no longer useful given our linker scripts,
and it actively got in the way here because the public libc symbol
actually starts with `__` in glibc, and it would be weird and annoying
for developers if we chose a different name.

Test: strace
Change-Id: I230479787895e8e34f566ade36346a8241eea998
2023-07-12 16:30:55 -07:00
Elliott Hughes
31fc69f67f Fix tzalloc(nullptr) and add a test.
This works (by reading /etc/localtime) on NetBSD, but not on Android
since we have no such file. Fix that by using our equivalent system
property instead.

Also s/time zone/timezone/ in documentation and comments. We've always
been inconsistent about this (as is upstream in code comments and
documentation) but it seems especially odd now we expose a _type_ that
spells it "timezone" to talk of "time zone" even as we're describing
that type and its associated functions.

Bug: https://github.com/chronotope/chrono/issues/499
Test: treehugger
Change-Id: I142995a3ab4deff1073a0aa9e63ce8eac850b93d
2023-06-22 09:51:01 -07:00
Elliott Hughes
2bd4316bd6 Expose tzalloc()/localtime_rz()/mktime_z()/tzfree().
* Rationale

The question often comes up of how to use multiple time zones in C code.
If you're single-threaded, you can just use setenv() to manipulate $TZ.
toybox does this, for example. But that's not thread-safe in two
distinct ways: firstly, getenv() is not thread-safe with respect to
modifications to the environment (and between the way putenv() is
specified and the existence of environ, it's not obvious how to fully
fix that), and secondly the _caller_ needs to ensure that no other
threads are using tzset() or any function that behaves "as if" tzset()
was called (which is neither easy to determine nor easy to ensure).

This isn't a bigger problem because most of the time the right answer
is to stop pretending that libc is at all suitable for any i18n, and
switch to icu4c instead. (The NDK icu4c headers do not include ucal_*,
so this is not a realistic option for most applications.)

But what if you're somewhere in between? Like the rust chrono library,
for example? What then?

Currently their "least worst" option is to reinvent the entire wheel and
read our tzdata files. Which isn't a great solution for anyone, for
obvious maintainability reasons.

So it's probably time we broke the catch-22 here and joined NetBSD in
offering a less broken API than standard C has for the last 40 years.
Sure, any would-be caller will have to have a separate "is this
Android?" and even "is this API level >= 35?" path, but that will fix
itself sometime in the 2030s when developers can just assume "yes, it
is", whereas if we keep putting off exposing anything, this problem
never gets solved.

(No-one's bothered to try to implement the std::chrono::time_zone
functionality in libc++ yet, but they'll face a similar problem if/when
they do.)

* Implementation

The good news is that tzcode already implements these functions, so
there's relatively little here.

I've chosen not to expose `struct state` because `struct __timezone_t`
makes for clearer error messages, given that compiler diagnostics will
show the underlying type name (`struct __timezone_t*`) rather than the
typedef name (`timezone_t`) that's used in calling code.

I've moved us over to FreeBSD's wcsftime() rather than keep the OpenBSD
one building --- I've long wanted to only have one implementation here,
and FreeBSD is already doing the "convert back and forth, calling the
non-wide function in the middle" dance that I'd hoped to get round to
doing myself someday. This should mean that our strftime() and
wcsftime() behaviors can't easily diverge in future, plus macOS/iOS are
mostly FreeBSD, so any bugs will likely be interoperable with the other
major mobile operating system, so there's something nice for everyone
there!

The FreeBSD wcsftime() implementation includes a wcsftime_l()
implementation, so that's one stub we can remove. The flip side of that
is that it uses mbsrtowcs_l() and wcsrtombs_l() which we didn't
previously have. So expose those as aliases of mbsrtowcs() and
wcsrtombs().

Bug: https://github.com/chronotope/chrono/issues/499
Test: treehugger
Change-Id: Iee1b9d763ead15eef3d2c33666b3403b68940c3c
2023-06-16 08:10:47 -07:00
Elliott Hughes
52541eea33 C23: add timespec_getres() and the new TIME_* constants.
Nothing to see here --- you'll want to keep using POSIX clock_gettime()
and clock_getres() instead. But portable code might use this eventually,
and it's trivial, so let's add it anyway.

(The whole "zero as an error return" precluding the direct use of
Linux's CLOCK_ constants is what really makes this a terrible API ---
we're going to have to add explicit translation any time they add a
new base.)

Test: treehugger
Change-Id: Iddb6cbe67b67b2b10fdd8b5ee654896d23deee47
2023-04-25 17:29:22 -07:00
Elliott Hughes
599d12d651 Document a couple of new-in-U features.
Test: N/A
Change-Id: I78acd8d772aacbb3b88649d78b759cffabd94e8f
2023-04-21 15:31:16 -07:00
Elliott Hughes
462ca8b314 <spawn.h>: add posix_spawn_file_actions_addchdir_np()/posix_spawn_file_actions_addfchdir_np().
The recent header nullability additions and the corresponding source
cleanup made me notice that we're missing a couple of actions that most
of the other implementations have. They've also been added to the _next_
revision of POSIX, unchanged except for the removal of the `_np` suffix.

They're trivial to implement, the testing is quite simple too, and
if they're going to be in POSIX soon, having them accessible in older
versions of Android via __RENAME() seems useful. (No-one else has shipped
the POSIX names yet.)

Bug: http://b/152414297
Test: treehugger
Change-Id: I0d2a1e47fbd2e826cff9c45038928aa1b6fcce59
2023-04-04 17:28:39 -07:00
Elliott Hughes
046fe15fb5 Explicitly mention bionic's single C.UTF-8 locale.
Test: treehugger
Change-Id: Iea45c0211d3476579f9778dfc7a0111f2e54a983
2022-12-02 20:15:42 +00:00
Elliott Hughes
82be76b5a2 Add __freadahead.
At the time I added <stdio_ext.h>, I just added what was on the man
page (which matched glibc), not realizing that musl and glibc had
slightly different functionality in their headers.

The toybox maintainer came up with a legitimate use case for this, for
which there is no portable workaround, so I'm adding it here. I'm not
adding the other functions that are in musl but not glibc for lack of a
motivating use case.

Bug: http://lists.landley.net/htdig.cgi/toybox-landley.net/2022-April/020864.html
Test: treehugger
Change-Id: I073baa86ff0271064d4e2f20a584d38787ead6b0
2022-09-22 23:47:42 +00:00
Elliott Hughes
f9fac36f15 Merge "Add C23's memset_explicit()." 2022-08-11 22:01:28 +00:00
Elliott Hughes
1f462dec34 Add %b and %B support to the scanf/wscanf and strto*/wcsto* families.
Coming to C23 via WG14 N2630.

This one is a little interesting, because it actually changes existing
behavior. Previously "0b101" would be parsed as "0", "b", "101" by these
functions. I'm led to believe that glibc plans to actually have separate
versions of these functions for C23 and pre-C23, so callers can have the
behavior they (implicitly) specify by virtue of which -std= they compile
with. Android has never really done anything like that, and I'm pretty
sure app developers have more than enough to worry about with API levels
without having to deal with the cartesian product of API level and C
standard.

Therefore, my plan A is "if you're running on Android >= U, you get C23
behavior". My plan B in the (I think unlikely) event that that actually
causes trouble for anyone is "if you're _targeting_ Android >= U, you
get C23 behavior". I don't think we'd actually want to have two versions
of each of these functions under any circumstances --- that seems by far
the most confusing option.

Test: treehugger
Change-Id: I0bbb30315d3fabd306905ad1484361f5d8745935
2022-08-11 00:25:08 +00:00
Elliott Hughes
0d64243407 Add C23's memset_explicit().
https://open-std.org/jtc1/sc22/wg14/www/docs/n2897.htm

Test: treehugger
Change-Id: Ia0cfc72bdf3c22eda6a4fc9adaa4c0ca0ff9a7c8
2022-08-10 23:36:16 +00:00
Elliott Hughes
b813a6a6be Add %b and %B support to the printf/wprintf family.
Coming to C23 via WG14 N2630, and already in glibc.

We're still missing clang support for %b and %B in format string checking,
but it's probably easier to fix this first. (Apparently GCC already has
support because of glibc.)

Test: treehugger
Change-Id: Ie8bfe4630d00c50e1d047d6756a7f799205356db
2022-08-01 22:18:40 +00:00
Elliott Hughes
a39ac04033 Document another obsolete POSIX function.
ualarm(3) was removed from POSIX in 2008, but somehow wasn't included in
the list of such functions (perhaps because it's not inherently useless
like a lot of the other stuff is; it just has a better replacement).

Test: N/A
Change-Id: I0347d3e7f1357bc2acb870f74e9084872c28ca3e
2022-06-14 17:23:35 -07:00
Elliott Hughes
02335c7738 T is API level 33, not 32.
The actual constant was fixed, but the docs weren't.

Test: treehugger
Change-Id: Id76d38cd8b17be02ddece8bbb2695f5d172fee9b
2022-02-16 14:41:09 -08:00
Elliott Hughes
57f17dea20 Update the status for S and T.
Test: treehugger
Change-Id: I21c4374d7e55dbbb2294cef5cc7bf50b7fe1b549
2022-01-14 16:26:25 -08:00
Elliott Hughes
733cedd1c4 Add a libc wrapper for statx(2).
Bug: http://b/127675384
Bug: http://b/146676114
Test: treehugger
Change-Id: I844edc12f62717e579870a040cf03dfe60dc280b
2020-02-23 11:36:53 -08:00
Elliott Hughes
9c381b046f docs/status.md: link to github.
We've had discussions about <monetary.h> (which wasn't previously
mentioned here at all, an oversight) and robust mutexes on github that
are worth linking to.

Bug: https://github.com/android/ndk/issues/1181
Bug: https://github.com/android/ndk/issues/1182
Test: N/A
Change-Id: If0d2c28757a3cbfffc358e8847dc4de1a67d9001
2020-02-05 16:04:57 -08:00
Elliott Hughes
b5a7741bb3 Mention why we don't have pthread_cancel().
It's a somewhat frequently asked question.

Change-Id: I2ad88e8d79607e49a891eb2304e9be63494ad193
2020-01-22 15:10:52 -08:00
Elliott Hughes
91e3bd1f33 Document the changed fdsan default from Q to R.
Change-Id: I98c50232184a8bf929579a7a30460dc33555475e
2020-01-16 15:23:58 -08:00
Elliott Hughes
502dc0b9c3 Update docs/status.md function counts for recent releases.
Test: N/A
Change-Id: I99b7227334d0858f19ec7544a255fe47f265d810
2019-11-12 21:06:07 -08:00
Elliott Hughes
8f3f191bf3 Link our two main developer-facing docs together.
Bug: http://b/139329827
Test: N/A
Change-Id: I38e05f1a7eaa8ff31b503541e34f2e362cd4722e
2019-08-15 08:19:49 -07:00
Elliott Hughes
da32ff104b Merge "Add memfd_create(2) and mlock2(2)." 2019-08-06 17:08:13 +00:00
Elliott Hughes
3d24d2b088 Add memfd_create(2) and mlock2(2).
These are old enough now that the latest devices will have kernels that
support them.

Also add basic doc comments to <sys/mman.h>.

Test: treehugger
Change-Id: I1b5ff5db0b6270f5c374287cac1d6a751a0259f5
2019-08-05 16:31:08 -07:00
Tom Cherry
f0d9271fe2 Update docs for clockwait/clocklock functions
Test: n/a
Change-Id: Ie4853912c9ed63d29121e62406682896012962ec
2019-08-05 14:13:25 -07:00
Elliott Hughes
05b675e8bf Add renameat2.
Bug: http://b/127675384
Test: new tests
Change-Id: Ia2e3d5679180391ca98e62fa429fa11cbf167507
2019-08-02 09:09:59 -07:00
Christopher Ferris
2671de2896 Fix usage of () and [].
The usage was reversed, [] is used for the name and () is used for the
link destination.

Test: NA
Change-Id: I07bf8645a888d5690d6c3d58edc3899b3e287df4
2019-06-27 20:42:38 -07:00
Elliott Hughes
4206711352 threads.h: Add C11 thread support.
FreeBSD, glibc, and musl have all implemented C11 threads at this
point. POSIX is looking at how to align with it. Probably time to jump
on the bandwagon ourselves...

Implemented in the same style as <termios.h> so we can provide this
functionality even on older API levels. This does mean that this is
strictly more expensive than calling pthread functions directly.

Although this isn't in POSIX yet, assume that it's going to be basically
the same as C11 and add the header test anyway. We should revisit this
when POSIX actually adds <threads.h>.

Test: new tests
Change-Id: I8602d67ce71ca7f8ed1529daa0a8ea1feb083dd6
2019-04-24 09:12:29 -07:00
Elliott Hughes
a1fb15bb67 strptime: support everything that strftime supports.
Our strptime was missing `%F`, `%G`, `%g`, `%P`, `%u`, `%V`, and
`%v`. Most of these are already supported upstream (and I've just pulled
their current implementation), but some aren't. We're horribly out of
sync anyway, so I'll upstream the missing pieces and then try to get us
back in sync later.

Test: new tests, but originally found by toybox trying to use %F
Change-Id: Ib1a10801a7a3b9c9189440c3b300109bde535fd9
2019-03-26 19:07:40 -07:00
Elliott Hughes
b282a6d4d3 Document various libc behavior changes.
Test: N/A
Change-Id: I3044c394180058ba500762239b16a4c740caca44
2019-03-20 11:23:53 -07:00
Christopher Ferris
a22f5d5175 Make aligned_alloc match the standard.
Jemalloc does not verify that the size parameter is a multiple of
alignment. Fix this since it only went into P.

Fix the unit tests, and fix malloc debug/malloc hooks to handle this
new restrictive behavior.

Bug: 126944692

Test: Ran bionic unit tests.
Test: Ran bionic unit tests with malloc hooks enabled (no new tests fail).
Test: Ran bionic unit tests with malloc debug enabled (no new tests fail).
Test: Ran malloc debug unit tests.
Change-Id: I4d50785928815679c781ca729f998454d76b9192
2019-03-01 23:56:23 -08:00
Elliott Hughes
2d0b28bc0d Add getloadavg(3).
Lets us build ninja with bionic.

Bug: N/A
Test: ran tests
Change-Id: I97eef1247d794b58a2b9aee4851551632e5a4e48
2018-10-23 11:23:00 -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
670ea7aca9 Explicitly say pthread_cancel in the docs.
Bug: http://b/33943372
Test: N/A
Change-Id: If71691f7ff20c9b8c14de15692543bbd858c9aab
2018-09-14 17:05:01 -07:00
Elliott Hughes
86bce192e9 Document various post-P bionic changes.
Historically we haven't documented many behavioral changes, but it's
probably useful to record that information before it's lost (even if,
long term, it might be more useful in the man pages or the doc comments).

Bug: N/A
Test: N/A
Change-Id: Iaa4f651fd6576298d848894b61285ef95879deb9
2018-09-05 12:01:15 -07:00
Elliott Hughes
3876ade842 Fill out historical "what was added when" information.
Bug: N/A
Test: N/A
Change-Id: Ifa1807c6bb61dea2a4831785492b13118c66490d
2018-08-30 14:25:32 -07:00
Elliott Hughes
a7119af33e Update libc status documentation.
Bug: N/A
Test: N/A
Change-Id: Ied9659f0388a4affa65f0948b3e4a58d0dca5605
2018-07-17 13:26:14 -07:00
Elliott Hughes
07f62385b6 Document FORTIFY.
Hilariously, our blog post didn't actually say how to turn it on :-)

Bug: N/A
Test: N/A
Change-Id: I6e773e88c32a70b0f8b8b6d105fce74d68ebf5cd
2018-05-01 13:13:47 -07:00
Elliott Hughes
61c169e5db Separate the new P functions from the new P behavior in the docs.
Bug: N/A
Test: N/A
Change-Id: If3810a1e4d3ab2a5bd5f83a1ab6bbcc1a729f685
2018-03-01 15:44:42 -08:00
Elliott Hughes
48b688b1b1 Document the strptime %s change.
Bug: https://issuetracker.google.com/37128336
Test: N/A
Change-Id: I9b35c14d84b9f4ec85b9d54af47314d0442ebde2
2018-03-01 15:10:19 -08:00
Elliott Hughes
3e235911c9 Add struct sigaction64 and sigaction64.
Bug: http://b/72493232
Test: ran tests
Change-Id: I47b0560a30aa33a9b1f1978dfb7f84d2e3d389b8
2018-02-01 14:45:15 -08:00
Elliott Hughes
13550b8c57 Update our status in light of recent additions.
Bug: N/A
Test: N/A
Change-Id: Ib0af6ba6bb270b03b3837c7e0fa2f9c02508c924
2018-01-25 22:50:09 -08:00