Commit graph

116 commits

Author SHA1 Message Date
Elliott Hughes
3bfb6eeb14 sysconf()/getpagesize() documentation.
Plus a little bit of cleanup of the sysconf() implementation...

Change-Id: I017d50e537e4721c9a4c4a62e9dea771ee920fb8
2024-03-27 21:23:42 +00:00
Elliott Hughes
8257268d04 _Fork(): clarify what not running pthread_atfork() handlers means in practice.
Change-Id: I0546069bbef730ffc23b3cea90fe7280d905d885
2024-03-04 22:24:01 +00:00
Elliott Hughes
2411fff9f2 Add _Fork().
POSIX issue 8 function, already in musl/glibc (but not iOS/macOS).

Bug: https://austingroupbugs.net/view.php?id=62
Test: treehugger
Change-Id: Id51611afdab92dff36a540b7d8737fc0e31f3d36
2024-02-29 20:50:58 +00:00
Elliott Hughes
9c06d16ca3 s/master/main/
Test: treehugger
Change-Id: I2c975b2f5f92f23c7357b6f7e785578504298cc6
2023-10-04 23:36:48 +00:00
David Benjamin
7110157e94 Make getentropy available from <unistd.h>
getentropy is originally an OpenBSD-ism, where it was in <unistd.h> from
day one:
https://man.openbsd.org/OpenBSD-5.6/getentropy

FreeBSD's and Linux's current man pages also document it this way:
https://man7.org/linux/man-pages/man3/getentropy.3.html
https://man.freebsd.org/cgi/man.cgi?query=getentropy&sektion=3&format=html

The man7.org URL is even cited by bionic itself in the comments, though
glibc originally put it in <sys/random.h> and added to <unistd.h> very
shortly afterwards:
https://sourceware.org/bugzilla/show_bug.cgi?id=17252#c9

The cited man page (maintained separately from glibc) originally
documented <sys/random.h>...
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/man3/getentropy.3?id=b0265728162cdcafb8e7d7f1372e8de1a4c963ed

But similarly fixed it to <unistd.h> three months later:
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/man3/getentropy.3?id=9cf011f94b56e8832c5a5d8cf66d4a115d34b9cc

musl matches the BSDs in putting it in <unistd.h>, but not
<sys/random.h>.
https://git.musl-libc.org/cgit/musl/tree/include/unistd.h?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc#n183

POSIX will likely place it there too:
https://www.austingroupbugs.net/view.php?id=1134

macOS and Fuchsia place it in <sys/random.h> and not <unistd.h>, though
given the rest of this precedent, they're clearly outliers. (Note iOS
does *not* have getentropy, just macOS. The system has it, but it's not
exposed as public API. See https://dev.gnupg.org/T5375 and
https://github.com/openssl/openssl/pull/15924.)

Use the more standard location in bionic and put getentropy in
<unistd.h>. This will improve portability and avoid needing workarounds
in BoringSSL. For compatibility, keep it also available in
<sys/random.h> by using a <bits/getentropy.h> header.

BYPASS_INCLUSIVE_LANGUAGE_REASON=Above URLs are not hosted by Android and reference the name of a command-line utility, short for 'manual', as in instruction manual

Bug: 290898063
Test: treehugger
Change-Id: Id2d6b6ea09d814e5ba2cb117a7af2c74861148fb
2023-07-17 21:50:53 +00:00
Elliott Hughes
c77993eda3 Mark getpagesize() const.
If folks want to use this instead of PAGE_SIZE, let's let the compiler
know that it doesn't need to be called more than once. Using "const"
rather than "pure" lets us cover more cases, and although this function
may need to check global state, it's _immutable_ global state, so it's
effectively "const".

Test: llvm-objdump -d
Change-Id: I0b13de79d44b57545258121df7cdd6490a9a5be1
2023-06-23 22:40:57 +00:00
Elliott Hughes
655e430b28 Remove the always-true __INTRODUCED_IN() annotations.
The NDK no longer supports API levels earlier than 21.

This *doesn't* include <ctype.h> because I have a separate change
rewriting that (that's blocked on the upcoming libc++ update).

Test: treehugger
Change-Id: I53e915f27011dfc0513e0c78d8799377e183ceca
2023-06-16 12:39:33 -07:00
Elliott Hughes
f4ace9d634 libc/include: remove easy __ANDROID_API__ tautologies.
The next NDK to take these headers only supports API 21 and later, so
clean up some of the trivial cruft.

This doesn't include the remaining "legacy inlines", since they're a bit
more complicated. I'll remove those in later changes.

Test: treehugger
Change-Id: I94c32f6393dd3ae831165917303ea591222baa0d
2023-02-23 17:38:37 +00:00
zijunzhao
3d59110f72 Nullability check for unistd module
Bugs: b/245972273
Test: None
Change-Id: I6037b1cd0bf233476a1cc0fbc8308a87de50c550
2023-02-01 20:40:35 +00:00
Elliott Hughes
d4fd67ce69 Add some missing "Available since" documentation.
Also fix formatting of `errno` in one function.

Test: treehugger
Change-Id: Ibf362bcd36c901dab2a422afe09e0f78011315aa
2022-11-30 19:55:32 +00:00
zijunzhao
c2e412e086 Add copy_file_range(2) syscall stub to bionic.
Test: treehugger
Bug: https://buganizer.corp.google.com/issues/227784687
Change-Id: I543306cd2234189401bf7c9d80d405eeb6e4d41d
2022-05-12 16:53:41 +00:00
Maciej Żenczykowski
b65e105047 add new Linux close_range() system call to bionic
See:
  https://man7.org/linux/man-pages/man2/close_range.2.html

Note: 'man close_range' documents 'flags' as unsigned int,
while glibc unistd.h as just 'int'.  Picking 'int' to match glibc,
though it probably doesn't matter.

BYPASS_INCLUSIVE_LANGUAGE_REASON=man is a cli command
Test: TreeHugger
Bug: 229913920
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1e2d1c8edc2ea28922d60f3ce3e534a784622cd1
2022-05-06 10:33:04 +00:00
Dan Albert
2dbea434d1 Make swab(3) inline prior to API 28.
Test: make checkbuild
Bug: https://stackoverflow.com/q/54392471/632035
Change-Id: Iaeb55231ea2395d7e1e31be63034f5db19025060
2020-08-07 13:10:51 -07:00
Elliott Hughes
5ac438e5da Clean up mips references in the headers.
Test: treehugger
Change-Id: I1997af980b9e46c7c530f9e6cb1aa407b2d63d76
2020-02-13 18:00:16 -08:00
Elliott Hughes
95c6cd753f Stop using the __ANDROID_API_x__ constants.
Historically we've made a few mistakes where they haven't matched the
right number. And most non-Googlers are much more familiar with the
numbers, so it seems to make sense to rely more on them. Especially in
header files, which we actually expect real people to have to read from
time to time.

Test: treehugger
Change-Id: I0d4a97454ee108de1d32f21df285315c5488d886
2019-12-20 13:26:14 -08:00
Elliott Hughes
0e14c5a869 <unistd.h> __INTRODUCED_IN cleaup.
The NDK doesn't support anything older than API level 16, so remove some
more clutter.

Test: builds
Change-Id: If257a27841396af001b089b7ae0fbd8c3e0128e4
2019-10-03 20:35:38 -07:00
Elliott Hughes
f106a391d3 Remove __INTRODUCED_IN for obsolete API levels.
The NDK only supports >= 16, so remove anything older than that to avoid
giving the misleading impression that such old targets are still
supported.

(This change doesn't touch <unistd.h>. I'll follow up with that once the
outstanding FORTIFY changes to that file are in.)

Test: builds
Change-Id: I6cc6ecdb99fe228a4afa71f78e5fd45309ba9786
2019-10-03 16:09:04 -07:00
Josh Gao
3403315521 Annotate no_return and returns_twice functions.
When building the bionic tests, we use -fno-builtins, which turns off
clang's recognition of vfork as a magical function that can return
twice. Explicitly annotate our returns_twice functions to ensure that
we generate correct code even in -fno-builtins (and while we're at it,
annotate the no_return functions as well, so we generate faster code).

Bug: http://b/131856005
Test: treehugger
Change-Id: I465f8042a965f0c7c03caa5f17af67deea8f5d9d
2019-05-13 13:17:51 -07:00
Elliott Hughes
9c6017778b Document the set*id functions.
In particular, document the fact that they only affect the calling thread
on Android.

Bug: http://b/13134174
Test: ran tests
Change-Id: Ica6af451400d47e24358f59495ded63b2110eb8b
2018-08-28 12:17:20 -07:00
George Burgess IV
9024235005 Remove __overloadable/__RENAME_CLANG
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-02-06 13:35:56 -08:00
Elliott Hughes
cc0fe6e8c0 The future is now (2018 edition).
Bug: N/A
Test: builds
Change-Id: Ic638e5b1f4e5901885fe7bc60b2a265817636b21
2018-01-30 08:54:12 -08:00
Elliott Hughes
a34817457f Improve the _FILE_OFFSET_BITS docs and link to them.
We're still seeing lots of confusion. People do seem to look as far as
the headers, but stop there. So let's try a bit harder to point them in
the right direction.

Also explicitly state that removing _FILE_OFFSET_BITS=64 is the
behavior-preserving fix for compilation problems when upgrading to NDK
r15 or later.

Bug: N/A
Test: N/A
Change-Id: I2d5c65b2fb5cccb9977901e51fea1ad2ccc0fd95
2017-11-28 15:47:01 -08:00
Treehugger Robot
ac29d9f3b9 Merge "Add POSIX swab." 2017-10-19 21:49:29 +00:00
Elliott Hughes
4d215aad85 Add POSIX fexecve.
I'm skeptical about the usefulness of this, but it's in POSIX, it's
in glibc (but not iOS), and it is used in some internal source (test
runners and container code).

Bug: N/A
Test: ran tests
Change-Id: I92c5398f2a679b21a33fba92bc8e67e3ae2eb76f
2017-10-18 16:26:17 -07:00
Elliott Hughes
fa386e0d1e Add POSIX swab.
Surprisingly to me, there are actual uses of `swab` in the codebases
I have available to search, including one with a #ifndef __ANDROID__
around it.

Bug: N/A
Test: ran tests
Change-Id: Ic91b78ae22bb65c346cb46dd38916f48d979abe0
2017-10-18 13:34:32 -07:00
Elliott Hughes
bda6f3b6af Improve names for function arguments in <unistd.h> for Studio.
Spotted while adding syncfs(2). I'd previously seen that this file already
had names, but apparently not inspected them. A couple were missing, a
couple (pipe/pipe2) could usefully have a more specific type, and many
hadruntogethercstylenames.

Bug: http://b/64613623
Test: builds
Change-Id: I6b4a131bf51bf04825317ec481bc55e87c88c2b3
2017-08-25 15:07:05 -07:00
Elliott Hughes
896362eb0e Add syncfs(2).
GMM calls this system call directly at the moment. That's silly.

Bug: http://b/36405699
Test: ran tests
Change-Id: I1e14c0e5ce0bc2aa888d884845ac30dc20f13cd5
2017-08-24 16:31:49 -07:00
Treehugger Robot
1db06faa38 Merge "libc: Split FORTIFY into its own headers" 2017-08-01 02:03:52 +00:00
Elliott Hughes
06bd5862b1 POSIX getlogin_r/LOGIN_NAME_MAX/TTY_NAME_MAX.
Bug: N/A
Test: ran tests
Change-Id: I97c8ecc82fb09c3fa4bb5e6f000d46f04f3d1702
2017-07-28 16:34:38 -07:00
George Burgess IV
b97049c039 libc: Split FORTIFY into its own headers
This patch cleans up our standard headers by moving most of the FORTIFY
cruft out in to its own sandbox. In order to include the *_chk and
*_real declarations, you can either enable FORTIFY, or `#define
__BIONIC_DECLARE_FORTIFY_HELPERS`.

Both sys/select.h and strings.h are explicitly ignored by this patch.
Both of these files have very small __BIONIC_FORTIFY blocks, and don't
define any actual FORTIFY'ed functions (just macros, and 3 *_chk
functions).

This patch also makes the versioner ignore the FORTIFY implementation
headers, since we're guaranteed to pick the FORTIFY'ed headers up when
looking at the regular headers. (...Not to mention that making the
FORTIFY'ed headers freestanding would be annoying to do and maintain for
~no benefit).

We bake the knowledge of where FORTIFY headers live directly into the
versioner. We could go with a more general approach (e.g. adding an -X
IGNORED_FILE flag that tells the versioner to ignore
$HEADER_PATH/$IGNORED_FILE), but we'd then have to repeat that for every
test, every manual invocation of the versioner, etc. for no benefit
that's obvious to me.

Bug: 12231437
Test: m checkbuild on bullhead internal master + CtsBionicTestCases. no
new errors.

Change-Id: Iffc0cc609009b33d989cdaddde0a809282131a5b
2017-07-27 17:00:13 -07:00
Elliott Hughes
00fedf5879 Undo recent _FILE_OFFSET_BITS=64 changes.
We had several bugs filed saying "if I set _FILE_OFFSET_BITS=64 when
targeting an API < L, various functions are missing". Instead of
saying "yes, they are", we quietly just modified the header files to
expose the non-64-bit variants. This makes no sense. We can't just say
"oh, yeah, we don't have a version of this function that agrees with
your calling code about how large off_t is, but here's a version that
doesn't: I'm sure it'll be fine".

_FILE_OFFSET_BITS=64 on Android LP32 has always been a game of chance,
but that game should be "are all the functions my code needs available
at compile time?", not "will my code actually work at run time?".

Bug: https://github.com/android-ndk/ndk/issues/449
Bug: https://github.com/android-ndk/ndk/issues/442
Bug: https://github.com/android-ndk/ndk/issues/333
Bug: https://github.com/android-ndk/ndk/issues/332
Bug: https://github.com/android-ndk/ndk/issues/324
Test: builds
Change-Id: Ib095251d3e21e77ed50cc3575388107fecec4ecd
2017-07-10 19:52:18 +00:00
Josh Gao
2e8e5e60b6 DO NOT MERGE: The future is now.
__INTRODUCED_IN_FUTURE -> __INTRODUCED_IN(26)

Bug: http://b/37437368
Test: treehugger
Change-Id: I601a23da83b65a0cd582cc840ed3856a9031b673
(cherry picked from commit cb302f932a)
2017-04-20 16:57:25 -07:00
Dan Albert
9c2094f3c5 Fixup API level guards for new fortify functions.
Test: tools/update_headers.sh && make checkbuild
Bug: None
Change-Id: I9d06ea8a5ee9dc27d957f59e6e84150651ed1c76
2017-02-14 22:22:13 -08:00
George Burgess IV
156d5a8ae9 Match __bos0 to __pass_object_size0 in FORTIFY
pass_object_size(N) forwards the result of __builtin_object_size(param,
N) to a function. So, a function that looks like:

  size_t foo(void *const p __pass_object_size) { return __bos0(p); }
  int bar = foo(baz);

would effectively be turned into

  size_t foo(void *const p, size_t sz) { return sz; }
  int bar = foo(baz, __bos(baz)); // note that this is not __bos0

This is bad, since if we're using __bos0, we want more relaxed
objectsize checks.

__bos0 should be more permissive than __bos in all cases, so this
change Should Be Fine™.

This change also makes GCC and clang share another function's
implementation (recv). I just realized we need to add special
diagnostic-related overloads bits for clang to it, but I can do that in
another patch.

Bug: None
Test: Bullhead builds and boots; CtsBionicTestCases passes.
Change-Id: I6818d0041328ab5fd0946a1e57321a977c1e1250
2017-02-10 18:14:43 -08:00
George Burgess IV
7cc779f15c libc: add clang FORTIFY support
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-02-09 15:49:32 -08:00
Elliott Hughes
79a8f4b2c9 Fix return type of sync(2).
Bug: N/A
Test: builds
Change-Id: Ie93f1e8609baf2939c809f673b96248a384695ee
2016-11-29 15:16:08 -08:00
Elliott Hughes
5bc78c8bcd Add and use constants for the Android API levels.
Test: bionic tests still pass
Change-Id: If1b619cfc9db1d3f5d91f14f2ace71058dca0c4a
2016-11-16 16:55:42 -08:00
Elliott Hughes
95fa061678 Rename __pure, __pure2, and __purefunc.
These names were pretty misleading (aka "backwards"), so switch to the
same obvious names glibc uses.

Test: build.
Change-Id: Ia98c9dbbccd0820386116562347654e84669034a
2016-09-28 12:36:38 -07:00
Dan Albert
a39f5d8b95 Make getpagesize inline static.
Needed to avoid multiple definition errors.

Test: make checkbuild tests
Bug: None
Change-Id: Ife83e89f5232e98d363e2b2edd7a353ed61c4836
2016-09-14 17:16:33 -07:00
Dan Albert
2990404206 Correct more fortify availability guards.
Test: make checkbuild
Bug: http://b/30465923
Change-Id: I90ac222483ecd39f1e7cc358babfb64e305cffcb
2016-09-08 16:13:27 -07:00
Elliott Hughes
fd936ae025 POSIX says <fcntl.h> makes SEEK_* visible.
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/fcntl.h.html

We already had two copies of these constants, so time to factor them out
into bits/.

Change-Id: I213c0d2372e41463593f878d338002b8eaa918cd
2016-08-12 10:16:34 -07:00
Josh Gao
d80a52eb65 Add __attribute__((sentinel)) tags to execl and friends.
Give a compile time diagnostic when the nullptr sentinel is missing
from an execl family call, instead of just pulling arbitrary values.

Bug: http://b/30793878
Change-Id: I1c49005c58b7ad4a5b04f0435b722d4c744e8f0e
Test: Built bullhead
2016-08-10 15:26:41 -07:00
Dan Albert
dfa6bbb54b Guard fortify inlines with __ANDROID_API__.
Test: make checkbuild with libc ndk_library patches applied
Change-Id: Ic5e248994c4f2702b0f4d6dfeda787187ea86017
2016-08-05 16:33:32 -07:00
Josh Gao
b6a4a4c0cc Add version information for legacy inlines.
Bug: http://b/30170081
Change-Id: Ib5962ea3037dd692a98b6691d263871549aac8af
2016-08-02 14:32:42 -07:00
Elliott Hughes
3b2096a9d6 Remove unnecessary 'extern's.
Change-Id: Iba2b3fb6ff88e504f1657b915120ae43d58a1e03
2016-07-22 18:57:12 -07:00
Josh Gao
46b44160e9 Update header versions for NDK platform fixes.
Bug: http://b/28178111
Change-Id: Icd638673b409aa43a91490f77c6b4d79c9ea20d9
2016-06-02 13:40:35 -07:00
Josh Gao
6e9c1f61d8 Remove declaration for __brk.
Bug: http://b/28178111
Change-Id: I972789cd5da552000c32fd107b9df98330323d89
2016-06-01 18:21:06 -07:00
Josh Gao
34c599a8b0 Add __INTRODUCED_IN_FUTURE for unreleased APIs.
Future API levels aren't known (e.g. 25 could be a maintenance release
of N that doesn't contain any bionic updates), so use a placeholder
macro that we can find and replace with the actual API level before each
release.

Bug: http://b/28178111
Change-Id: I667fe53ea1ac49b64135170fc30d5dbe9df94e29
2016-04-29 16:39:50 -07:00
Josh Gao
14adff1cfa Add versioning information to symbols.
Bug: http://b/28178111
Change-Id: I46bf95accd819f4521afb1173d8badcc5e9df31c
2016-04-29 16:39:50 -07:00
Josh Gao
8c8ef5965d Move <sys/sysconf.h> to <bits/sysconf.h>.
Also remove unneeded declaration of sysconf in <unistd.h>.

Bug: http://b/28067717
Change-Id: Ife4692e48ca97480e422db0686c61133e1d619aa
2016-04-07 18:02:00 -07:00