Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
API guard every post-21 API.
Browse files Browse the repository at this point in the history
This was generated mechanically by reverting my recent re-hide commits
(except for mempcpy, but versioner cleaned that up for me anyway),
reverting the commits which removed versioner, then:

```
m out/soong/ndk_headers.timestamp
cp -r out/soong/ndk/sysroot/usr/include/* bionic/libc/include
git -C bionic clean -df
```

Effectively, this has restored the `versioner` processed headers, but
I'm checking the results of that in so we don't have to keep
`versioner` around.

For the NDK, this restores r27 behavior by default. Anyone that's
opted into weak APIs will get the new behavior. I think this is our
best option. Anyone writing code with Android in mind should be using
weak APIs, but any code being lightly ported (and thus using the
default configuration) should not be, and it's those ports where we're
having trouble with collisions.

Bug: android/ndk#2081
Test: None
Change-Id: I370079d27566b0c1543fb5890c958c8d09b05006
  • Loading branch information
DanAlbert committed Oct 29, 2024
1 parent 5a7331a commit 02ce401
Show file tree
Hide file tree
Showing 66 changed files with 844 additions and 15 deletions.
4 changes: 4 additions & 0 deletions libc/include/android/api-level.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ __BEGIN_DECLS
*
* Available since API level 24.
*/

#if __BIONIC_AVAILABILITY_GUARD(24)
int android_get_application_target_sdk_version() __INTRODUCED_IN(24);
#endif /* __BIONIC_AVAILABILITY_GUARD(24) */


#if __ANDROID_API__ < 29

Expand Down
4 changes: 4 additions & 0 deletions libc/include/android/crash_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ typedef struct crash_detail_t crash_detail_t;
*
* \return a handle to the extra crash detail.
*/

#if __BIONIC_AVAILABILITY_GUARD(35)
crash_detail_t* _Nullable android_crash_detail_register(
const void* _Nonnull name, size_t name_size, const void* _Nullable data, size_t data_size) __INTRODUCED_IN(35);

Expand Down Expand Up @@ -123,5 +125,7 @@ void android_crash_detail_replace_data(crash_detail_t* _Nonnull crash_detail, co
* \param name_size number of bytes of the buffer pointed to by name
*/
void android_crash_detail_replace_name(crash_detail_t* _Nonnull crash_detail, const void* _Nonnull name, size_t name_size) __INTRODUCED_IN(35);
#endif /* __BIONIC_AVAILABILITY_GUARD(35) */


__END_DECLS
12 changes: 12 additions & 0 deletions libc/include/android/fdsan.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ enum android_fdsan_owner_type {
/*
* Create an owner tag with the specified type and least significant 56 bits of tag.
*/

#if __BIONIC_AVAILABILITY_GUARD(29)
uint64_t android_fdsan_create_owner_tag(enum android_fdsan_owner_type type, uint64_t tag) __INTRODUCED_IN(29) __attribute__((__weak__));

/*
Expand Down Expand Up @@ -169,6 +171,8 @@ const char* _Nonnull android_fdsan_get_tag_type(uint64_t tag) __INTRODUCED_IN(29
* Get an owner tag's value, with the type masked off.
*/
uint64_t android_fdsan_get_tag_value(uint64_t tag) __INTRODUCED_IN(29);
#endif /* __BIONIC_AVAILABILITY_GUARD(29) */


enum android_fdsan_error_level {
// No errors.
Expand All @@ -187,6 +191,8 @@ enum android_fdsan_error_level {
/*
* Get the error level.
*/

#if __BIONIC_AVAILABILITY_GUARD(29)
enum android_fdsan_error_level android_fdsan_get_error_level() __INTRODUCED_IN(29) __attribute__((__weak__));

/*
Expand All @@ -204,9 +210,15 @@ enum android_fdsan_error_level android_fdsan_get_error_level() __INTRODUCED_IN(2
* (e.g. postfork).
*/
enum android_fdsan_error_level android_fdsan_set_error_level(enum android_fdsan_error_level new_level) __INTRODUCED_IN(29) __attribute__((__weak__));
#endif /* __BIONIC_AVAILABILITY_GUARD(29) */


/*
* Set the error level to the global setting if available, or a default value.
*/

#if __BIONIC_AVAILABILITY_GUARD(30)
enum android_fdsan_error_level android_fdsan_set_error_level_from_property(enum android_fdsan_error_level default_level) __INTRODUCED_IN(30) __attribute__((__weak__));
#endif /* __BIONIC_AVAILABILITY_GUARD(30) */

__END_DECLS
4 changes: 4 additions & 0 deletions libc/include/arpa/nameser.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ __BEGIN_DECLS
#define ns_sprintrrf __ns_sprintrrf
#endif


#if __BIONIC_AVAILABILITY_GUARD(22)
int ns_msg_getflag(ns_msg __handle, int __flag) __INTRODUCED_IN(22);
uint16_t ns_get16(const u_char* _Nonnull __src) __INTRODUCED_IN(22);
uint32_t ns_get32(const u_char* _Nonnull __src) __INTRODUCED_IN(22);
Expand All @@ -571,6 +573,8 @@ void ns_name_rollback(const u_char* _Nonnull __src, const u_char* _Nullable * _N

int ns_makecanon(const char* _Nonnull __src, char* _Nonnull __dst, size_t __dst_size) __INTRODUCED_IN(22);
int ns_samename(const char* _Nonnull __lhs, const char* _Nonnull __rhs) __INTRODUCED_IN(22);
#endif /* __BIONIC_AVAILABILITY_GUARD(22) */


__END_DECLS

Expand Down
8 changes: 8 additions & 0 deletions libc/include/bits/fortify/poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,17 @@
#error "Never include this file directly; instead, include <poll.h>"
#endif


#if __BIONIC_AVAILABILITY_GUARD(23)
int __poll_chk(struct pollfd* _Nullable, nfds_t, int, size_t) __INTRODUCED_IN(23);
int __ppoll_chk(struct pollfd* _Nullable, nfds_t, const struct timespec* _Nullable, const sigset_t* _Nullable, size_t) __INTRODUCED_IN(23);
#endif /* __BIONIC_AVAILABILITY_GUARD(23) */


#if __BIONIC_AVAILABILITY_GUARD(28)
int __ppoll64_chk(struct pollfd* _Nullable, nfds_t, const struct timespec* _Nullable, const sigset64_t* _Nullable, size_t) __INTRODUCED_IN(28);
#endif /* __BIONIC_AVAILABILITY_GUARD(28) */


#if defined(__BIONIC_FORTIFY)
#define __bos_fd_count_trivially_safe(bos_val, fds, fd_count) \
Expand Down
4 changes: 4 additions & 0 deletions libc/include/bits/fortify/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
#error "Never include this file directly; instead, include <sys/socket.h>"
#endif


#if __BIONIC_AVAILABILITY_GUARD(26)
ssize_t __sendto_chk(int, const void* _Nonnull, size_t, size_t, int, const struct sockaddr* _Nullable, socklen_t) __INTRODUCED_IN(26);
#endif /* __BIONIC_AVAILABILITY_GUARD(26) */

ssize_t __recvfrom_chk(int, void* _Nullable, size_t, size_t, int, struct sockaddr* _Nullable, socklen_t* _Nullable);

#if defined(__BIONIC_FORTIFY)
Expand Down
4 changes: 4 additions & 0 deletions libc/include/bits/fortify/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
#endif

char* _Nullable __fgets_chk(char* _Nonnull, int, FILE* _Nonnull, size_t);

#if __BIONIC_AVAILABILITY_GUARD(24)
size_t __fread_chk(void* _Nonnull, size_t, size_t, FILE* _Nonnull, size_t) __INTRODUCED_IN(24);
size_t __fwrite_chk(const void* _Nonnull, size_t, size_t, FILE* _Nonnull, size_t) __INTRODUCED_IN(24);
#endif /* __BIONIC_AVAILABILITY_GUARD(24) */


#if defined(__BIONIC_FORTIFY) && !defined(__BIONIC_NO_STDIO_FORTIFY)

Expand Down
4 changes: 4 additions & 0 deletions libc/include/bits/fortify/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@
#error "Never include this file directly; instead, include <string.h>"
#endif


#if __BIONIC_AVAILABILITY_GUARD(23)
void* _Nullable __memchr_chk(const void* _Nonnull, int, size_t, size_t) __INTRODUCED_IN(23);
void* _Nullable __memrchr_chk(const void* _Nonnull, int, size_t, size_t) __INTRODUCED_IN(23);
#endif /* __BIONIC_AVAILABILITY_GUARD(23) */

char* _Nonnull __stpncpy_chk2(char* _Nonnull, const char* _Nonnull, size_t, size_t, size_t);
char* _Nonnull __strncpy_chk2(char* _Nonnull, const char* _Nonnull, size_t, size_t, size_t);
size_t __strlcpy_chk(char* _Nonnull, const char* _Nonnull, size_t, size_t);
Expand Down
28 changes: 28 additions & 0 deletions libc/include/bits/fortify/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,52 @@
#error "Never include this file directly; instead, include <unistd.h>"
#endif


#if __BIONIC_AVAILABILITY_GUARD(24)
char* _Nullable __getcwd_chk(char* _Nullable, size_t, size_t) __INTRODUCED_IN(24);
#endif /* __BIONIC_AVAILABILITY_GUARD(24) */



#if __BIONIC_AVAILABILITY_GUARD(23)
ssize_t __pread_chk(int, void* _Nonnull, size_t, off_t, size_t) __INTRODUCED_IN(23);
#endif /* __BIONIC_AVAILABILITY_GUARD(23) */

ssize_t __pread_real(int, void* _Nonnull, size_t, off_t) __RENAME(pread);


#if __BIONIC_AVAILABILITY_GUARD(23)
ssize_t __pread64_chk(int, void* _Nonnull, size_t, off64_t, size_t) __INTRODUCED_IN(23);
#endif /* __BIONIC_AVAILABILITY_GUARD(23) */

ssize_t __pread64_real(int, void* _Nonnull, size_t, off64_t) __RENAME(pread64);


#if __BIONIC_AVAILABILITY_GUARD(24)
ssize_t __pwrite_chk(int, const void* _Nonnull, size_t, off_t, size_t) __INTRODUCED_IN(24);
#endif /* __BIONIC_AVAILABILITY_GUARD(24) */

ssize_t __pwrite_real(int, const void* _Nonnull, size_t, off_t) __RENAME(pwrite);


#if __BIONIC_AVAILABILITY_GUARD(24)
ssize_t __pwrite64_chk(int, const void* _Nonnull, size_t, off64_t, size_t) __INTRODUCED_IN(24);
#endif /* __BIONIC_AVAILABILITY_GUARD(24) */

ssize_t __pwrite64_real(int, const void* _Nonnull, size_t, off64_t) __RENAME(pwrite64);

ssize_t __read_chk(int, void* __BIONIC_COMPLICATED_NULLNESS, size_t, size_t);

#if __BIONIC_AVAILABILITY_GUARD(24)
ssize_t __write_chk(int, const void* __BIONIC_COMPLICATED_NULLNESS, size_t, size_t) __INTRODUCED_IN(24);
#endif /* __BIONIC_AVAILABILITY_GUARD(24) */


#if __BIONIC_AVAILABILITY_GUARD(23)
ssize_t __readlink_chk(const char* _Nonnull, char* _Nonnull, size_t, size_t) __INTRODUCED_IN(23);
ssize_t __readlinkat_chk(int dirfd, const char* _Nonnull, char* _Nonnull, size_t, size_t) __INTRODUCED_IN(23);
#endif /* __BIONIC_AVAILABILITY_GUARD(23) */


#if defined(__BIONIC_FORTIFY)

Expand Down
4 changes: 4 additions & 0 deletions libc/include/bits/getentropy.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ __BEGIN_DECLS
*
* See also arc4random_buf() which is available in all API levels.
*/

#if __BIONIC_AVAILABILITY_GUARD(28)
__nodiscard int getentropy(void* _Nonnull __buffer, size_t __buffer_size) __INTRODUCED_IN(28);
#endif /* __BIONIC_AVAILABILITY_GUARD(28) */


__END_DECLS
4 changes: 4 additions & 0 deletions libc/include/bits/lockf.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@ __BEGIN_DECLS
*
* See also flock().
*/

#if __BIONIC_AVAILABILITY_GUARD(24)
int lockf(int __fd, int __op, off_t __length) __RENAME_IF_FILE_OFFSET64(lockf64) __INTRODUCED_IN(24);

/**
* Like lockf() but allows using a 64-bit length
* even from a 32-bit process without `_FILE_OFFSET_BITS=64`.
*/
int lockf64(int __fd, int __op, off64_t __length) __INTRODUCED_IN(24);
#endif /* __BIONIC_AVAILABILITY_GUARD(24) */


__END_DECLS
8 changes: 8 additions & 0 deletions libc/include/bits/strcasecmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ int strcasecmp(const char* _Nonnull __s1, const char* _Nonnull __s2) __attribute
/**
* Like strcasecmp() but taking a `locale_t`.
*/

#if __BIONIC_AVAILABILITY_GUARD(23)
int strcasecmp_l(const char* _Nonnull __s1, const char* _Nonnull __s2, locale_t _Nonnull __l) __attribute_pure__ __INTRODUCED_IN(23);
#endif /* __BIONIC_AVAILABILITY_GUARD(23) */


/**
* [strncasecmp(3)](https://man7.org/linux/man-pages/man3/strncasecmp.3.html) compares the first
Expand All @@ -66,6 +70,10 @@ int strncasecmp(const char* _Nonnull __s1, const char* _Nonnull __s2, size_t __n
/**
* Like strncasecmp() but taking a `locale_t`.
*/

#if __BIONIC_AVAILABILITY_GUARD(23)
int strncasecmp_l(const char* _Nonnull __s1, const char* _Nonnull __s2, size_t __n, locale_t _Nonnull __l) __attribute_pure__ __INTRODUCED_IN(23);
#endif /* __BIONIC_AVAILABILITY_GUARD(23) */


__END_DECLS
4 changes: 4 additions & 0 deletions libc/include/bits/wctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ wctype_t wctype(const char* _Nonnull __name);
int iswctype(wint_t __wc, wctype_t __type);

typedef const void* wctrans_t;

#if __BIONIC_AVAILABILITY_GUARD(26)
wint_t towctrans(wint_t __wc, wctrans_t _Nonnull __transform) __INTRODUCED_IN(26);
wctrans_t _Nullable wctrans(const char* _Nonnull __name) __INTRODUCED_IN(26);
#endif /* __BIONIC_AVAILABILITY_GUARD(26) */


__END_DECLS

Expand Down
Loading

0 comments on commit 02ce401

Please sign in to comment.