1*8d67ca89SAndroid Build Coastguard Worker# Android bionic status 2*8d67ca89SAndroid Build Coastguard Worker 3*8d67ca89SAndroid Build Coastguard WorkerThis document details libc/libm/libdl additions and behavior changes. 4*8d67ca89SAndroid Build Coastguard Worker 5*8d67ca89SAndroid Build Coastguard WorkerSee also 6*8d67ca89SAndroid Build Coastguard Worker[Android linker changes for NDK developers](../android-changes-for-ndk-developers.md) 7*8d67ca89SAndroid Build Coastguard Workerfor changes related to native code loading in various Android releases. 8*8d67ca89SAndroid Build Coastguard Worker 9*8d67ca89SAndroid Build Coastguard Worker## Bionic function availability 10*8d67ca89SAndroid Build Coastguard Worker 11*8d67ca89SAndroid Build Coastguard Worker### POSIX 12*8d67ca89SAndroid Build Coastguard Worker 13*8d67ca89SAndroid Build Coastguard WorkerYou can see the current status with respect to POSIX in the form of tests: 14*8d67ca89SAndroid Build Coastguard Workerhttps://android.googlesource.com/platform/bionic/+/main/tests/headers/posix/ 15*8d67ca89SAndroid Build Coastguard Worker 16*8d67ca89SAndroid Build Coastguard WorkerSome POSIX functionality is not supported by the Linux kernel, and 17*8d67ca89SAndroid Build Coastguard Workeris guarded with tests for `__linux__`. Other functionality is not 18*8d67ca89SAndroid Build Coastguard Workersupported by bionic or glibc, and guarded with tests for `__BIONIC__` 19*8d67ca89SAndroid Build Coastguard Workerand `__GLIBC__`. In other cases historical accidents mean 32-bit 20*8d67ca89SAndroid Build Coastguard Workerbionic diverged but 64-bit bionic matches POSIX; these are guarded with 21*8d67ca89SAndroid Build Coastguard Worker`__LP64__`. 22*8d67ca89SAndroid Build Coastguard Worker 23*8d67ca89SAndroid Build Coastguard WorkerMost bionic-only diversions should be accompanied by an explanatory comment. 24*8d67ca89SAndroid Build Coastguard Worker 25*8d67ca89SAndroid Build Coastguard WorkerMissing functions are either obsolete or explicitly disallowed by SELinux: 26*8d67ca89SAndroid Build Coastguard Worker * `a64l`/`l64a` 27*8d67ca89SAndroid Build Coastguard Worker * `confstr` 28*8d67ca89SAndroid Build Coastguard Worker * `crypt`/`encrypt`/`setkey` 29*8d67ca89SAndroid Build Coastguard Worker * `gethostid` 30*8d67ca89SAndroid Build Coastguard Worker * `shm_open`/`shm_unlink` 31*8d67ca89SAndroid Build Coastguard Worker * `sockatmark` 32*8d67ca89SAndroid Build Coastguard Worker * `ualarm` 33*8d67ca89SAndroid Build Coastguard Worker 34*8d67ca89SAndroid Build Coastguard WorkerMissing functionality: 35*8d67ca89SAndroid Build Coastguard Worker * `<aio.h>`. No particular reason not to have this other than that no-one's 36*8d67ca89SAndroid Build Coastguard Worker needed it yet, and it's relatively complex. If/when llvm-libc adds this, 37*8d67ca89SAndroid Build Coastguard Worker maybe we'll just reuse that. 38*8d67ca89SAndroid Build Coastguard Worker * `<monetary.h>`. See 39*8d67ca89SAndroid Build Coastguard Worker [discussion](https://github.com/android/ndk/issues/1182). 40*8d67ca89SAndroid Build Coastguard Worker * `<wordexp.h>`. Unsafe because it passes user input to the shell (!), 41*8d67ca89SAndroid Build Coastguard Worker and often should just be a call to glob() anyway. See also 42*8d67ca89SAndroid Build Coastguard Worker [OpenBSD's discussion about adding wordexp()](https://www.mail-archive.com/[email protected]/msg02325.html). 43*8d67ca89SAndroid Build Coastguard Worker * Locales. Although bionic contains the various `_l()` functions, the only 44*8d67ca89SAndroid Build Coastguard Worker locale supported is a UTF-8 C/POSIX locale. Most of the POSIX APIs are 45*8d67ca89SAndroid Build Coastguard Worker insufficient to support the wide range of languages used by Android users, 46*8d67ca89SAndroid Build Coastguard Worker and apps should use icu4c (or do their i18n work in Java) instead. 47*8d67ca89SAndroid Build Coastguard Worker * Robust mutexes. See 48*8d67ca89SAndroid Build Coastguard Worker [discussion](https://github.com/android/ndk/issues/1181). 49*8d67ca89SAndroid Build Coastguard Worker * Thread cancellation (`pthread_cancel`). Unlikely to ever be implemented 50*8d67ca89SAndroid Build Coastguard Worker because of the difficulty and cost of implementing it, and the difficulty 51*8d67ca89SAndroid Build Coastguard Worker of using it correctly. See 52*8d67ca89SAndroid Build Coastguard Worker [This is why we can't have safe cancellation points](https://lwn.net/Articles/683118/) 53*8d67ca89SAndroid Build Coastguard Worker for more about thread cancellation. 54*8d67ca89SAndroid Build Coastguard Worker 55*8d67ca89SAndroid Build Coastguard WorkerRun `./libc/tools/check-symbols-glibc.py` in bionic/ for the current 56*8d67ca89SAndroid Build Coastguard Workerlist of POSIX functions implemented by glibc but not by bionic. 57*8d67ca89SAndroid Build Coastguard Worker 58*8d67ca89SAndroid Build Coastguard Worker### libc 59*8d67ca89SAndroid Build Coastguard Worker 60*8d67ca89SAndroid Build Coastguard WorkerCurrent libc symbols: https://android.googlesource.com/platform/bionic/+/main/libc/libc.map.txt 61*8d67ca89SAndroid Build Coastguard Worker 62*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in API level 36: 63*8d67ca89SAndroid Build Coastguard Worker * `qsort_r`, `sig2str`/`str2sig` (POSIX Issue 8 additions). 64*8d67ca89SAndroid Build Coastguard Worker * GNU/BSD extension `lchmod`. 65*8d67ca89SAndroid Build Coastguard Worker * GNU extensions `pthread_getaffinity_np`/`pthread_setaffinity_np`. 66*8d67ca89SAndroid Build Coastguard Worker * New system call wrapper: `mseal` (`<sys/mman.h>`). 67*8d67ca89SAndroid Build Coastguard Worker 68*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in V (API level 35): 69*8d67ca89SAndroid Build Coastguard Worker * New `android_crash_detail_register`, `android_crash_detail_unregister`, 70*8d67ca89SAndroid Build Coastguard Worker `android_crash_detail_replace_name`, and `android_crash_detail_replace_data` 71*8d67ca89SAndroid Build Coastguard Worker functionality for adding arbitrary data to tombstones 72*8d67ca89SAndroid Build Coastguard Worker (see `<android/crash_detail.h>` for full documentation). 73*8d67ca89SAndroid Build Coastguard Worker * `tcgetwinsize`, `tcsetwinsize`, `_Fork` (POSIX Issue 8 additions). 74*8d67ca89SAndroid Build Coastguard Worker * `timespec_getres` (C23 addition). 75*8d67ca89SAndroid Build Coastguard Worker * `localtime_rz`, `mktime_z`, `tzalloc`, and `tzfree` (NetBSD 76*8d67ca89SAndroid Build Coastguard Worker extensions implemented in tzcode, and the "least non-standard" 77*8d67ca89SAndroid Build Coastguard Worker functions for avoiding $TZ if you need to use multiple timezones in 78*8d67ca89SAndroid Build Coastguard Worker multi-threaded C). 79*8d67ca89SAndroid Build Coastguard Worker * `mbsrtowcs_l` and `wcsrtombs_l` aliases for `mbsrtowcs` and `wcsrtombs`. 80*8d67ca89SAndroid Build Coastguard Worker * GNU extensions `strerrordesc_np` and `strerrorname_np`. 81*8d67ca89SAndroid Build Coastguard Worker * New system call wrappers: `__riscv_flush_icache` (`<sys/cachectl.h>`), 82*8d67ca89SAndroid Build Coastguard Worker `__riscv_hwprobe` (`<sys/hwprobe.h>`), `epoll_pwait2`/`epoll_pwait2_64` (`<sys/epoll.h>`). 83*8d67ca89SAndroid Build Coastguard Worker 84*8d67ca89SAndroid Build Coastguard WorkerNew libc behavior in V (API level 35): 85*8d67ca89SAndroid Build Coastguard Worker * Added `LD_SHOW_AUXV` to the dynamic linker to dump the ELF auxiliary 86*8d67ca89SAndroid Build Coastguard Worker vector if the environment variable is set. 87*8d67ca89SAndroid Build Coastguard Worker * The printf family now supports `%#m` to print the name of the errno 88*8d67ca89SAndroid Build Coastguard Worker constant (rather than the description printed by `%m`). 89*8d67ca89SAndroid Build Coastguard Worker 90*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in U (API level 34): 91*8d67ca89SAndroid Build Coastguard Worker * `close_range` and `copy_file_range` (Linux-specific GNU extensions). 92*8d67ca89SAndroid Build Coastguard Worker * `memset_explicit` in <string.h> (C23 addition). 93*8d67ca89SAndroid Build Coastguard Worker * `__freadahead` in <stdio_ext.h> (in musl but not glibc). 94*8d67ca89SAndroid Build Coastguard Worker * `posix_spawn_file_actions_addchdir_np` and 95*8d67ca89SAndroid Build Coastguard Worker `posix_spawn_file_actions_addfchdir_np` in <spawn.h> (in musl/glibc 96*8d67ca89SAndroid Build Coastguard Worker and macOS, but not iOS). 97*8d67ca89SAndroid Build Coastguard Worker 98*8d67ca89SAndroid Build Coastguard WorkerNew libc behavior in U (API level 34): 99*8d67ca89SAndroid Build Coastguard Worker * Support for `%b` and `%B` in the printf/wprintf family, `%b` in the 100*8d67ca89SAndroid Build Coastguard Worker scanf/wscanf family, and `0b` prefixes with base 0 in the strtol/wcstol 101*8d67ca89SAndroid Build Coastguard Worker family. 102*8d67ca89SAndroid Build Coastguard Worker * Support for `wN` length modifiers in the printf/wprintf family. 103*8d67ca89SAndroid Build Coastguard Worker * tmpfile() now respects $TMPDIR. 104*8d67ca89SAndroid Build Coastguard Worker 105*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in T (API level 33): 106*8d67ca89SAndroid Build Coastguard Worker * `backtrace`, `backtrace_symbols`, `backtrace_symbols_fd` (`<execinfo.h>`). 107*8d67ca89SAndroid Build Coastguard Worker * New system call wrappers: `preadv2`, `preadv64v2`, `pwritev2`, 108*8d67ca89SAndroid Build Coastguard Worker `pwritev64v2`. 109*8d67ca89SAndroid Build Coastguard Worker 110*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in S (API level 31): 111*8d67ca89SAndroid Build Coastguard Worker * New hooks for sanitizers for TLS access: `__libc_get_static_tls_bounds`, 112*8d67ca89SAndroid Build Coastguard Worker `__libc_register_thread_exit_callback`, `__libc_iterate_dynamic_tls`, 113*8d67ca89SAndroid Build Coastguard Worker `__libc_register_dynamic_tls_listeners`. 114*8d67ca89SAndroid Build Coastguard Worker * New helper to allow the zygote to give each zygote child its own stack 115*8d67ca89SAndroid Build Coastguard Worker cookie (currently unused): `android_reset_stack_guards`. 116*8d67ca89SAndroid Build Coastguard Worker * Non-inline symbols for `ffsl`, `ffsll`. 117*8d67ca89SAndroid Build Coastguard Worker * New system call wrappers: `pidfd_getfd`, `pidfd_open`, `pidfd_send_signal`, 118*8d67ca89SAndroid Build Coastguard Worker `process_madvise`. 119*8d67ca89SAndroid Build Coastguard Worker 120*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in R (API level 30): 121*8d67ca89SAndroid Build Coastguard Worker * Full C11 `<threads.h>` (available as inlines for older API levels). 122*8d67ca89SAndroid Build Coastguard Worker * `memfd_create` and `mlock2` (Linux-specific GNU extensions). 123*8d67ca89SAndroid Build Coastguard Worker * `renameat2` and `statx` (Linux-specific GNU extensions). 124*8d67ca89SAndroid Build Coastguard Worker * `pthread_cond_clockwait`/`pthread_mutex_clocklock`/`pthread_rwlock_clockrdlock`/`pthread_rwlock_clockwrlock`/`sem_clockwait` 125*8d67ca89SAndroid Build Coastguard Worker 126*8d67ca89SAndroid Build Coastguard WorkerNew libc behavior in R (API level 30): 127*8d67ca89SAndroid Build Coastguard Worker * [fdsan](fdsan.md) now aborts when it detects common file descriptor errors, 128*8d67ca89SAndroid Build Coastguard Worker rather than just logging. 129*8d67ca89SAndroid Build Coastguard Worker 130*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in Q (API level 29): 131*8d67ca89SAndroid Build Coastguard Worker * `timespec_get` (C11 `<time.h>` addition) 132*8d67ca89SAndroid Build Coastguard Worker * `reallocarray` (BSD/GNU extension in `<malloc.h>` and `<stdlib.h>`) 133*8d67ca89SAndroid Build Coastguard Worker * `res_randomid` (in `<resolv.h>`) 134*8d67ca89SAndroid Build Coastguard Worker * `pthread_sigqueue` (GNU extension) 135*8d67ca89SAndroid Build Coastguard Worker * `getloadavg` (BSD/GNU extension in <stdlib.h>) 136*8d67ca89SAndroid Build Coastguard Worker 137*8d67ca89SAndroid Build Coastguard WorkerNew libc behavior in Q (API level 29): 138*8d67ca89SAndroid Build Coastguard Worker * Support for [ELF TLS](elf-tls.md). 139*8d67ca89SAndroid Build Coastguard Worker * Whole printf family now supports the GNU `%m` extension, rather than a 140*8d67ca89SAndroid Build Coastguard Worker special-case hack in `syslog`. 141*8d67ca89SAndroid Build Coastguard Worker * `popen` now always uses `O_CLOEXEC`, not just with the `e` extension. 142*8d67ca89SAndroid Build Coastguard Worker * Bug fixes to handling of UTF-8 U+fffe/U+ffff and code points above U+10ffff. 143*8d67ca89SAndroid Build Coastguard Worker * `aligned_alloc` correctly verifies that `size` is a multiple of `alignment`. 144*8d67ca89SAndroid Build Coastguard Worker * Using `%n` with the printf family is now reported as a FORTIFY failure. 145*8d67ca89SAndroid Build Coastguard Worker Previous versions of Android would ignore the `%n` but not consume the 146*8d67ca89SAndroid Build Coastguard Worker corresponding pointer argument, leading to obscure errors. The scanf family 147*8d67ca89SAndroid Build Coastguard Worker is unchanged. 148*8d67ca89SAndroid Build Coastguard Worker * Support in strptime for `%F`, `%G`, `%g`, `%P`, `%u`, `%V`, and `%v`. 149*8d67ca89SAndroid Build Coastguard Worker (strftime already supported them all.) 150*8d67ca89SAndroid Build Coastguard Worker * [fdsan](fdsan.md) detects and logs common file descriptor errors at runtime. 151*8d67ca89SAndroid Build Coastguard Worker 152*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in P (API level 28): 153*8d67ca89SAndroid Build Coastguard Worker * `aligned_alloc` 154*8d67ca89SAndroid Build Coastguard Worker * `__freading`/`__fwriting` (completing <stdio_ext.h>) 155*8d67ca89SAndroid Build Coastguard Worker * `endhostent`/`endnetent`/`endprotoent`/`getnetent`/`getprotoent`/`sethostent`/`setnetent`/`setprotoent` (completing <netdb.h>) 156*8d67ca89SAndroid Build Coastguard Worker * `fexecve` 157*8d67ca89SAndroid Build Coastguard Worker * `fflush_unlocked`/`fgetc_unlocked`/`fgets_unlocked`/`fputc_unlocked`/`fputs_unlocked`/`fread_unlocked`/`fwrite_unlocked` 158*8d67ca89SAndroid Build Coastguard Worker * `getentropy`/`getrandom` (adding <sys/random.h>) 159*8d67ca89SAndroid Build Coastguard Worker * `getlogin_r` 160*8d67ca89SAndroid Build Coastguard Worker * `glob`/`globfree` (adding <glob.h>) 161*8d67ca89SAndroid Build Coastguard Worker * `hcreate`/`hcreate_r`/`hdestroy`/`hdestroy_r`/`hsearch`/`hsearch_r` (completing <search.h>) 162*8d67ca89SAndroid Build Coastguard Worker * `iconv`/`iconv_close`/`iconv_open` (adding <iconv.h>) 163*8d67ca89SAndroid Build Coastguard Worker * `pthread_attr_getinheritsched`/`pthread_attr_setinheritsched`/`pthread_setschedprio` 164*8d67ca89SAndroid Build Coastguard Worker * `pthread_mutexattr_getprotocol`/`pthread_mutexattr_setprotocol` (mutex priority inheritance) 165*8d67ca89SAndroid Build Coastguard Worker * <signal.h> support for `sigaction64_t` and `sigset64_t` allowing LP32 access to real-time signals 166*8d67ca89SAndroid Build Coastguard Worker * <spawn.h> 167*8d67ca89SAndroid Build Coastguard Worker * `swab` 168*8d67ca89SAndroid Build Coastguard Worker * `syncfs` 169*8d67ca89SAndroid Build Coastguard Worker 170*8d67ca89SAndroid Build Coastguard WorkerNew libc behavior in P (API level 28): 171*8d67ca89SAndroid Build Coastguard Worker * `%C` and `%S` support in the printf family (previously only the wprintf family supported these). 172*8d67ca89SAndroid Build Coastguard Worker * `%mc`/`%ms`/`%m[` support in the scanf family. 173*8d67ca89SAndroid Build Coastguard Worker * `%s` support in strptime (strftime already supported it). 174*8d67ca89SAndroid Build Coastguard Worker * Using a `pthread_mutex_t` after it's been destroyed will be detected at 175*8d67ca89SAndroid Build Coastguard Worker runtime and reported as a FORTIFY failure. 176*8d67ca89SAndroid Build Coastguard Worker * Passing a null `FILE*` or `DIR*` to libc is now detected at runtime and 177*8d67ca89SAndroid Build Coastguard Worker reported as a FORTIFY failure. 178*8d67ca89SAndroid Build Coastguard Worker 179*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in O (API level 26): 180*8d67ca89SAndroid Build Coastguard Worker * `sendto` FORTIFY support 181*8d67ca89SAndroid Build Coastguard Worker * `__system_property_read_callback`/`__system_property_wait` 182*8d67ca89SAndroid Build Coastguard Worker * legacy `bsd_signal` 183*8d67ca89SAndroid Build Coastguard Worker * `catclose`/`catgets`/`catopen` (adding <nl_types.h>) 184*8d67ca89SAndroid Build Coastguard Worker * `ctermid` 185*8d67ca89SAndroid Build Coastguard Worker * all 6 <grp.h>/<pwd.h> (get|set|end)(gr|pw)ent functions 186*8d67ca89SAndroid Build Coastguard Worker * `futimes`/`futimesat`/`lutimes` 187*8d67ca89SAndroid Build Coastguard Worker * `getdomainname`/`setdomainname` 188*8d67ca89SAndroid Build Coastguard Worker * `getsubopt` 189*8d67ca89SAndroid Build Coastguard Worker * `hasmntopt` 190*8d67ca89SAndroid Build Coastguard Worker * `mallopt` 191*8d67ca89SAndroid Build Coastguard Worker * `mblen` 192*8d67ca89SAndroid Build Coastguard Worker * 4 <sys/msg.h> `msg*` functions 193*8d67ca89SAndroid Build Coastguard Worker * <langinfo.h> `nl_langinfo`/`nl_langinfo_l` 194*8d67ca89SAndroid Build Coastguard Worker * `pthread_getname_np` 195*8d67ca89SAndroid Build Coastguard Worker * 2 new Linux system calls `quotactl` and `sync_file_range` 196*8d67ca89SAndroid Build Coastguard Worker * 4 <sys/sem.h> `sem*` functions 197*8d67ca89SAndroid Build Coastguard Worker * 4 <sys/shm.h> `shm*` functions 198*8d67ca89SAndroid Build Coastguard Worker * 5 legacy <signal.h> functions: `sighold`/`sigignore`/`sigpause`/`sigrelse`/`sigset` 199*8d67ca89SAndroid Build Coastguard Worker * `strtod_l`/`strtof_l`/`strtol_l`/`strtoul_l` 200*8d67ca89SAndroid Build Coastguard Worker * <wctype.h> `towctrans`/`towctrans_l`/`wctrans`/`wctrans_l` 201*8d67ca89SAndroid Build Coastguard Worker 202*8d67ca89SAndroid Build Coastguard WorkerNew libc behavior in O (API level 26): 203*8d67ca89SAndroid Build Coastguard Worker * Passing an invalid `pthread_t` to libc is now detected at runtime and 204*8d67ca89SAndroid Build Coastguard Worker reported as a FORTIFY failure. Most commonly this is a result of confusing 205*8d67ca89SAndroid Build Coastguard Worker `pthread_t` and `pid_t`. 206*8d67ca89SAndroid Build Coastguard Worker 207*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in N (API level 24): 208*8d67ca89SAndroid Build Coastguard Worker * more FORTIFY support functions (`fread`/`fwrite`/`getcwd`/`pwrite`/`write`) 209*8d67ca89SAndroid Build Coastguard Worker * all remaining `_FILE_OFFSET_BITS=64` functions, completing `_FILE_OFFSET_BITS=64` support in bionic (8) 210*8d67ca89SAndroid Build Coastguard Worker * all 7 `pthread_barrier*` functions 211*8d67ca89SAndroid Build Coastguard Worker * all 5 `pthread_spin*` functions 212*8d67ca89SAndroid Build Coastguard Worker * `lockf`/`preadv`/`pwritev`/`scandirat` and `off64_t` variants 213*8d67ca89SAndroid Build Coastguard Worker * `adjtimex`/`clock_adjtime` 214*8d67ca89SAndroid Build Coastguard Worker * <ifaddrs.h> `getifaddrs`/`freeifaddrs`/`if_freenameindex`/`if_nameindex` 215*8d67ca89SAndroid Build Coastguard Worker * `getgrgid_r`/`getgrnam_r` 216*8d67ca89SAndroid Build Coastguard Worker * GNU extensions `fileno_unlocked`/`strchrnul` 217*8d67ca89SAndroid Build Coastguard Worker * 32-bit `prlimit` 218*8d67ca89SAndroid Build Coastguard Worker 219*8d67ca89SAndroid Build Coastguard WorkerNew libc behavior in N (API level 24): 220*8d67ca89SAndroid Build Coastguard Worker * `sem_wait` now returns EINTR when interrupted by a signal. 221*8d67ca89SAndroid Build Coastguard Worker 222*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in M (API level 23): 223*8d67ca89SAndroid Build Coastguard Worker * <dirent.h> `telldir`, `seekdir`. 224*8d67ca89SAndroid Build Coastguard Worker * <malloc.h> `malloc_info`. 225*8d67ca89SAndroid Build Coastguard Worker * <netdb.h> `gethostbyaddr_r`, `gethostbyname2_r`. 226*8d67ca89SAndroid Build Coastguard Worker * <pthread.h> `pthread_rwlockattr_getkind_np`/`pthread_rwlockattr_setkind_np`. 227*8d67ca89SAndroid Build Coastguard Worker * <pty.h> `forkpty`, `openpty`. 228*8d67ca89SAndroid Build Coastguard Worker * <signal.h> `sigqueue`, `sigtimedwait`, `sigwaitinfo`. 229*8d67ca89SAndroid Build Coastguard Worker * <stdio.h> `fmemopen`, `open_memstream`, `feof_unlocked`, `ferror_unlocked`, `clearerr_unlocked`. 230*8d67ca89SAndroid Build Coastguard Worker * <stdio_ext.h> `__flbf`, `__freadable`, `__fsetlocking`, `__fwritable`, `__fbufsize`, `__fpending`, `_flushlbf`, `__fpurge`. 231*8d67ca89SAndroid Build Coastguard Worker * <stdlib.h> `mkostemp`/`mkostemps`, `lcong48`. 232*8d67ca89SAndroid Build Coastguard Worker * <string.h> `basename`, `strerror_l`, `strerror_r`, `mempcpy`. 233*8d67ca89SAndroid Build Coastguard Worker * <sys/sysinfo.h> `get_nprocs_conf`/`get_nprocs`, `get_phys_pages`, `get_avphys_pages`. 234*8d67ca89SAndroid Build Coastguard Worker * <sys/uio.h> `process_vm_readv`/`process_vm_writev`. 235*8d67ca89SAndroid Build Coastguard Worker * `clock_getcpuclockid`, `login_tty`, `mkfifoat`, `posix_madvise`, `sethostname`, `strcasecmp_l`/`strncasecmp_l`. 236*8d67ca89SAndroid Build Coastguard Worker * <wchar.h> `open_wmemstream`, `wcscasecmp_l`/`wcsncasecmp_l`, `wmempcpy`. 237*8d67ca89SAndroid Build Coastguard Worker * all of <error.h>. 238*8d67ca89SAndroid Build Coastguard Worker * re-introduced various <resolv.h> functions: `ns_format_ttl`, `ns_get16`, `ns_get32`, `ns_initparse`, `ns_makecanon`, `ns_msg_getflag`, `ns_name_compress`, `ns_name_ntol`, `ns_name_ntop`, `ns_name_pack`, `ns_name_pton`, `ns_name_rollback`, `ns_name_skip`, `ns_name_uncompress`, `ns_name_unpack`, `ns_parserr`, `ns_put16`, `ns_put32`, `ns_samename`, `ns_skiprr`, `ns_sprintrr`, and `ns_sprintrrf`. 239*8d67ca89SAndroid Build Coastguard Worker 240*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in L (API level 21): 241*8d67ca89SAndroid Build Coastguard Worker * <android/dlext.h>. 242*8d67ca89SAndroid Build Coastguard Worker * <android/set_abort_message.h>. 243*8d67ca89SAndroid Build Coastguard Worker * <arpa/inet.h> `inet_lnaof`, `inet_netof`, `inet_network`, `inet_makeaddr`. 244*8d67ca89SAndroid Build Coastguard Worker * <wctype.h> `iswblank`. 245*8d67ca89SAndroid Build Coastguard Worker * <ctype.h> `isalnum_l`, `isalpha_l`, `isblank_l`, `icntrl_l`, `isdigit_l`, `isgraph_l`, `islower_l`, `isprint_l`, `ispunct_l`, `isspace_l`, `isupper_l`, `isxdigit_l`, `_tolower`, `tolower_l`, `_toupper`, `toupper_l`. 246*8d67ca89SAndroid Build Coastguard Worker * <fcntl.h> `fallocate`, `posix_fadvise`, `posix_fallocate`, `splice`, `tee`, `vmsplice`. 247*8d67ca89SAndroid Build Coastguard Worker * <inttypes.h> `wcstoimax`, `wcstoumax`. 248*8d67ca89SAndroid Build Coastguard Worker * <link.h> `dl_iterate_phdr`. 249*8d67ca89SAndroid Build Coastguard Worker * <mntent.h> `setmntent`, `endmntent`, `getmntent_r`. 250*8d67ca89SAndroid Build Coastguard Worker * <poll.h> `ppoll`. 251*8d67ca89SAndroid Build Coastguard Worker * <pthread.h> `pthread_condattr_getclock`, `pthread_condattr_setclock`, `pthread_mutex_timedlock`, `pthread_gettid_np`. 252*8d67ca89SAndroid Build Coastguard Worker * <sched.h> `setns`. 253*8d67ca89SAndroid Build Coastguard Worker * <search.h> `insque`, `remque`, `lfind`, `lsearch`, `twalk`. 254*8d67ca89SAndroid Build Coastguard Worker * <stdio.h> `dprintf`, `vdprintf`. 255*8d67ca89SAndroid Build Coastguard Worker * <stdlib.h> `initstate`, `setstate`, `getprogname`/`setprogname`, `atof`/`strtof`, `at_quick_exit`/`_Exit`/`quick_exit`, `grantpt`, `mbtowc`/`wctomb`, `posix_openpt`, `rand_r`/`rand`/`random`/`srand`/`srandom`, `strtold_l`/`strtoll_l`/`strtoull_l`. 256*8d67ca89SAndroid Build Coastguard Worker * <string.h> `strcoll_l`/`strxfrm_l`, `stpcpy`/`stpncpy`. 257*8d67ca89SAndroid Build Coastguard Worker * <sys/resource.h> `prlimit`. 258*8d67ca89SAndroid Build Coastguard Worker * <sys/socket.h> `accept4`, `sendmmsg`. 259*8d67ca89SAndroid Build Coastguard Worker * <sys/stat.h> `mkfifo`/`mknodat`. 260*8d67ca89SAndroid Build Coastguard Worker * <time.h> `strftime_l`. 261*8d67ca89SAndroid Build Coastguard Worker * <unistd.h> `dup3`, `execvpe`, `getpagesize`, `linkat`/`symlinkat`/`readlinkat`, `truncate`. 262*8d67ca89SAndroid Build Coastguard Worker * <wchar.h> `wcstof`, `vfwscanf`/`vswscanf`/`vwscanf`, `wcstold_l`/`wcstoll`/`wcstoll_l`/`wcstoull`/`wcstoull_l`, `mbsnrtowcs`/`wcsnrtombs`, `wcscoll_l`/`wcsxfrm_l`. 263*8d67ca89SAndroid Build Coastguard Worker * <wctype.h> `iswalnum_l`/`iswalpha_l`/`iswblank_l`/`iswcntrl_l`/`iswctype_l`/`iswdigit_l`/`iswgraph_l`/`iswlower_l`/`iswprint_l`/`iswpunct_l`/`iswspace_l`/`iswupper_l`/`iswxdigit_l`, `wctype_l`, `towlower_l`/`towupper_l`. 264*8d67ca89SAndroid Build Coastguard Worker * all of <fts.h>. 265*8d67ca89SAndroid Build Coastguard Worker * all of <locale.h>. 266*8d67ca89SAndroid Build Coastguard Worker * all of <sys/epoll.h>. 267*8d67ca89SAndroid Build Coastguard Worker * all of <sys/fsuid.h>. 268*8d67ca89SAndroid Build Coastguard Worker * all of <sys/inotify.h>. 269*8d67ca89SAndroid Build Coastguard Worker * all of <uchar.h>. 270*8d67ca89SAndroid Build Coastguard Worker 271*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in K (API level 19): 272*8d67ca89SAndroid Build Coastguard Worker * <inttypes.h> `imaxabs`, `imaxdiv`. 273*8d67ca89SAndroid Build Coastguard Worker * <stdlib.h> `abs`, `labs`, `llabs`. 274*8d67ca89SAndroid Build Coastguard Worker * <sys/stat.h> `futimens`. 275*8d67ca89SAndroid Build Coastguard Worker * all of <sys/statvfs.h>. 276*8d67ca89SAndroid Build Coastguard Worker * all of <sys/swap.h>. 277*8d67ca89SAndroid Build Coastguard Worker * all of <sys/timerfd.h>. 278*8d67ca89SAndroid Build Coastguard Worker 279*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in J-MR2 (API level 18): 280*8d67ca89SAndroid Build Coastguard Worker * <stdio.h> `getdelim` and `getline`. 281*8d67ca89SAndroid Build Coastguard Worker * <sys/auxv.h> `getauxval`. 282*8d67ca89SAndroid Build Coastguard Worker * <sys/signalfd.h> `signalfd`. 283*8d67ca89SAndroid Build Coastguard Worker 284*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in J-MR1 (API level 17): 285*8d67ca89SAndroid Build Coastguard Worker * <ftw.h>. 286*8d67ca89SAndroid Build Coastguard Worker * <signal.h> `psiginfo` and `psignal`. 287*8d67ca89SAndroid Build Coastguard Worker * `getsid`, `malloc_usable_size`, `mlockall`/`munlockall`, `posix_memalign`, `unshare`. 288*8d67ca89SAndroid Build Coastguard Worker 289*8d67ca89SAndroid Build Coastguard WorkerNew libc functions in J (API level 16): 290*8d67ca89SAndroid Build Coastguard Worker * the <search.h> tree functions `tdelete`, `tdestroy`, `tfind`, and `tsearch`. 291*8d67ca89SAndroid Build Coastguard Worker * `faccessat`, `readahead`, `tgkill`. 292*8d67ca89SAndroid Build Coastguard Worker * all of <sys/xattr.h>. 293*8d67ca89SAndroid Build Coastguard Worker 294*8d67ca89SAndroid Build Coastguard Workerlibc function count over time: 295*8d67ca89SAndroid Build Coastguard Worker 296*8d67ca89SAndroid Build Coastguard Worker| API level | Function count | 297*8d67ca89SAndroid Build Coastguard Worker|-----------|----------------| 298*8d67ca89SAndroid Build Coastguard Worker| 16 | 842 | 299*8d67ca89SAndroid Build Coastguard Worker| 17 | 870 | 300*8d67ca89SAndroid Build Coastguard Worker| 18 | 878 | 301*8d67ca89SAndroid Build Coastguard Worker| 19 | 893 | 302*8d67ca89SAndroid Build Coastguard Worker| 21 | 1016 | 303*8d67ca89SAndroid Build Coastguard Worker| 22 | 1038 | 304*8d67ca89SAndroid Build Coastguard Worker| 23 | 1103 | 305*8d67ca89SAndroid Build Coastguard Worker| 24 | 1147 | 306*8d67ca89SAndroid Build Coastguard Worker| 25 | 1147 | 307*8d67ca89SAndroid Build Coastguard Worker| 26 | 1199 | 308*8d67ca89SAndroid Build Coastguard Worker| 27 | 1199 | 309*8d67ca89SAndroid Build Coastguard Worker| 28 | 1298 | 310*8d67ca89SAndroid Build Coastguard Worker| 29 | 1312 | 311*8d67ca89SAndroid Build Coastguard Worker| 30 | 1368 | 312*8d67ca89SAndroid Build Coastguard Worker| 31 | 1379 | 313*8d67ca89SAndroid Build Coastguard Worker| 32 | 1379 | 314*8d67ca89SAndroid Build Coastguard Worker| 33 | 1386 | 315*8d67ca89SAndroid Build Coastguard Worker| 34 | 1392 | 316*8d67ca89SAndroid Build Coastguard Worker 317*8d67ca89SAndroid Build Coastguard WorkerData collected by: 318*8d67ca89SAndroid Build Coastguard Worker``` 319*8d67ca89SAndroid Build Coastguard Workerndk-r26c$ for i in `ls -1v toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/*/libc.so` ; \ 320*8d67ca89SAndroid Build Coastguard Worker do echo $i; nm $i | grep -w T | wc -l ; done 321*8d67ca89SAndroid Build Coastguard Worker``` 322*8d67ca89SAndroid Build Coastguard Worker 323*8d67ca89SAndroid Build Coastguard Worker### libm 324*8d67ca89SAndroid Build Coastguard Worker 325*8d67ca89SAndroid Build Coastguard WorkerCurrent libm symbols: https://android.googlesource.com/platform/bionic/+/main/libm/libm.map.txt 326*8d67ca89SAndroid Build Coastguard Worker 327*8d67ca89SAndroid Build Coastguard Worker0 remaining missing C11/POSIX libm functions. 328*8d67ca89SAndroid Build Coastguard Worker 329*8d67ca89SAndroid Build Coastguard WorkerNew libm functions in O (API level 26): 330*8d67ca89SAndroid Build Coastguard Worker * <complex.h> `clog`/`clogf`, `cpow`/`cpowf` functions. 331*8d67ca89SAndroid Build Coastguard Worker 332*8d67ca89SAndroid Build Coastguard WorkerNew libm functions in M (API level 23): 333*8d67ca89SAndroid Build Coastguard Worker * <complex.h> `cabs`, `carg`, `cimag`, `cacos`, `cacosh`, `casin`, `casinh`, `catan`, `catanh`, `ccos`, `ccosh`, `cexp`, `conj`, `cproj`, `csin`, `csinh`, `csqrt`, `ctan`, `ctanh`, `creal`, `cabsf`, `cargf`, `cimagf`, `cacosf`, `cacoshf`, `casinf`, `casinhf`, `catanf`, `catanhf`, `ccosf`, `ccoshf`, `cexpf`, `conjf`, `cprojf`, `csinf`, `csinhf`, `csqrtf`, `ctanf`, `ctanhf`, `crealf`, `cabsl`, `cprojl`, `csqrtl`. 334*8d67ca89SAndroid Build Coastguard Worker * <math.h> `lgammal_r`. 335*8d67ca89SAndroid Build Coastguard Worker 336*8d67ca89SAndroid Build Coastguard WorkerNew libm functions in L (API level 21): 337*8d67ca89SAndroid Build Coastguard Worker * <complex.h> `cabsl`, `cprojl`, `csqrtl`. 338*8d67ca89SAndroid Build Coastguard Worker * <math.h> `isinf`, `significandl`. 339*8d67ca89SAndroid Build Coastguard Worker 340*8d67ca89SAndroid Build Coastguard WorkerNew libm functions in J-MR2 (API level 18): 341*8d67ca89SAndroid Build Coastguard Worker * <math.h> `log2`, `log2f`. 342*8d67ca89SAndroid Build Coastguard Worker 343*8d67ca89SAndroid Build Coastguard Worker 344*8d67ca89SAndroid Build Coastguard Worker## Target API level behavioral differences 345*8d67ca89SAndroid Build Coastguard Worker 346*8d67ca89SAndroid Build Coastguard WorkerMost bionic bug fixes and improvements have been made without checks for 347*8d67ca89SAndroid Build Coastguard Workerthe app's `targetSdkVersion`. There are a handful of exceptions. (If in 348*8d67ca89SAndroid Build Coastguard Workerdoubt, search the source for `android_get_application_target_sdk_version()`.) 349*8d67ca89SAndroid Build Coastguard Worker 350*8d67ca89SAndroid Build Coastguard Worker### Destroyed mutex checking (targetSdkVersion >= 28) 351*8d67ca89SAndroid Build Coastguard Worker 352*8d67ca89SAndroid Build Coastguard WorkerIf a destroyed `pthread_mutex_t` is passed to any of the mutex functions, apps 353*8d67ca89SAndroid Build Coastguard Workertargeting API level 28 or higher will see a 354*8d67ca89SAndroid Build Coastguard Worker"<function> called on a destroyed mutex" fortify failure. Apps targeting older 355*8d67ca89SAndroid Build Coastguard WorkerAPI levels will just have the function fail with EBUSY (matching the likely 356*8d67ca89SAndroid Build Coastguard Workerbehavior before we added the check). 357*8d67ca89SAndroid Build Coastguard Worker 358*8d67ca89SAndroid Build Coastguard Worker### Invalid `pthread_t` handling (targetSdkVersion >= 26) 359*8d67ca89SAndroid Build Coastguard Worker 360*8d67ca89SAndroid Build Coastguard WorkerAs part of a long-term goal to remove the global thread list, 361*8d67ca89SAndroid Build Coastguard Workerand in an attempt to flush out racy code, we changed how an invalid 362*8d67ca89SAndroid Build Coastguard Worker`pthread_t` is handled. For `pthread_detach`, `pthread_getcpuclockid`, 363*8d67ca89SAndroid Build Coastguard Worker`pthread_getschedparam`/`pthread_setschedparam`, `pthread_join`, and 364*8d67ca89SAndroid Build Coastguard Worker`pthread_kill`, instead of returning ESRCH when passed an invalid 365*8d67ca89SAndroid Build Coastguard Worker`pthread_t`, if you're targeting API level 26 or above, they'll abort with the 366*8d67ca89SAndroid Build Coastguard Workermessage "attempt to use invalid pthread\_t". 367*8d67ca89SAndroid Build Coastguard Worker 368*8d67ca89SAndroid Build Coastguard WorkerNote that this doesn't change behavior as much as you might think: the 369*8d67ca89SAndroid Build Coastguard Workerold lookup only held the global thread list lock for the duration of 370*8d67ca89SAndroid Build Coastguard Workerthe lookup, so there was still a race between that and the dereference 371*8d67ca89SAndroid Build Coastguard Workerin the caller, given that callers actually need the tid to pass to some 372*8d67ca89SAndroid Build Coastguard Workersyscall or other, and sometimes update fields in the `pthread_internal_t` 373*8d67ca89SAndroid Build Coastguard Workerstruct too. 374*8d67ca89SAndroid Build Coastguard Worker 375*8d67ca89SAndroid Build Coastguard WorkerWe can't check a thread's tid against 0 to see whether a `pthread_t` 376*8d67ca89SAndroid Build Coastguard Workeris still valid because a dead thread gets its thread struct unmapped 377*8d67ca89SAndroid Build Coastguard Workeralong with its stack, so the dereference isn't safe. 378*8d67ca89SAndroid Build Coastguard Worker 379*8d67ca89SAndroid Build Coastguard WorkerTo fix your code, taking the affected functions one by one: 380*8d67ca89SAndroid Build Coastguard Worker 381*8d67ca89SAndroid Build Coastguard Worker * `pthread_getcpuclockid` and `pthread_getschedparam`/`pthread_setschedparam` 382*8d67ca89SAndroid Build Coastguard Worker should be fine. Unsafe calls to those seem highly unlikely. 383*8d67ca89SAndroid Build Coastguard Worker 384*8d67ca89SAndroid Build Coastguard Worker * Unsafe `pthread_detach` callers probably want to switch to 385*8d67ca89SAndroid Build Coastguard Worker `pthread_attr_setdetachstate` instead, or use 386*8d67ca89SAndroid Build Coastguard Worker `pthread_detach(pthread_self());` from the new thread's start routine 387*8d67ca89SAndroid Build Coastguard Worker rather than calling detach in the parent. 388*8d67ca89SAndroid Build Coastguard Worker 389*8d67ca89SAndroid Build Coastguard Worker * `pthread_join` calls should be safe anyway, because a joinable thread 390*8d67ca89SAndroid Build Coastguard Worker won't actually exit and unmap until it's joined. If you're joining an 391*8d67ca89SAndroid Build Coastguard Worker unjoinable thread, the fix is to stop marking it detached. If you're 392*8d67ca89SAndroid Build Coastguard Worker joining an already-joined thread, you need to rethink your design! 393*8d67ca89SAndroid Build Coastguard Worker 394*8d67ca89SAndroid Build Coastguard Worker * Unsafe `pthread_kill` calls aren't portably fixable. (And are obviously 395*8d67ca89SAndroid Build Coastguard Worker inherently non-portable as-is.) The best alternative on Android is to 396*8d67ca89SAndroid Build Coastguard Worker use `pthread_gettid_np` at some point that you know the thread to be 397*8d67ca89SAndroid Build Coastguard Worker alive, and then call `kill`/`tgkill` with signal 0 (which checks 398*8d67ca89SAndroid Build Coastguard Worker whether a process exists rather than actually sending a 399*8d67ca89SAndroid Build Coastguard Worker signal). That's still not completely safe because if you're too late 400*8d67ca89SAndroid Build Coastguard Worker the tid may have been reused, but your code is inherently unsafe without 401*8d67ca89SAndroid Build Coastguard Worker a redesign anyway. 402*8d67ca89SAndroid Build Coastguard Worker 403*8d67ca89SAndroid Build Coastguard Worker### Interruptable `sem_wait` (targetSdkVersion >= 24) 404*8d67ca89SAndroid Build Coastguard Worker 405*8d67ca89SAndroid Build Coastguard WorkerPOSIX says that `sem_wait` can be interrupted by delivery of a 406*8d67ca89SAndroid Build Coastguard Workersignal. This wasn't historically true in Android, and when we fixed this 407*8d67ca89SAndroid Build Coastguard Workerbug we found that existing code relied on the old behavior. To preserve 408*8d67ca89SAndroid Build Coastguard Workercompatibility, `sem_wait` can only return EINTR on Android if the app 409*8d67ca89SAndroid Build Coastguard Workertargets API level 24 or later. 410*8d67ca89SAndroid Build Coastguard Worker 411*8d67ca89SAndroid Build Coastguard Worker 412*8d67ca89SAndroid Build Coastguard Worker## FORTIFY 413*8d67ca89SAndroid Build Coastguard Worker 414*8d67ca89SAndroid Build Coastguard WorkerThe `_FORTIFY_SOURCE` macro can be used to enable extra 415*8d67ca89SAndroid Build Coastguard Workerautomatic bounds checking for common libc functions. If a buffer 416*8d67ca89SAndroid Build Coastguard Workeroverrun is detected, the program is safely aborted as in this 417*8d67ca89SAndroid Build Coastguard Worker[example](https://source.android.com/devices/tech/debug/native-crash#fortify). 418*8d67ca89SAndroid Build Coastguard Worker 419*8d67ca89SAndroid Build Coastguard WorkerNote that Android's FORTIFY has been extended to cover other issues. It can 420*8d67ca89SAndroid Build Coastguard Workerdetect, for example, passing `O_CREAT` to open(2) without specifying a mode. It 421*8d67ca89SAndroid Build Coastguard Workeralso performs some checking regardless of whether the caller was built with 422*8d67ca89SAndroid Build Coastguard WorkerFORTIFY enabled. From API level 28, for example, calling a `pthread_mutex_` 423*8d67ca89SAndroid Build Coastguard Workerfunction on a destroyed mutex, calling a `<dirent.h>` function on a null 424*8d67ca89SAndroid Build Coastguard Workerpointer, using `%n` with the printf(3) family, or using the scanf(3) `m` 425*8d67ca89SAndroid Build Coastguard Workermodifier incorrectly will all result in FORTIFY failures even for code not built 426*8d67ca89SAndroid Build Coastguard Workerwith FORTIFY. 427*8d67ca89SAndroid Build Coastguard Worker 428*8d67ca89SAndroid Build Coastguard WorkerMore background information is available in our 429*8d67ca89SAndroid Build Coastguard Worker[FORTIFY in Android](https://android-developers.googleblog.com/2017/04/fortify-in-android.html) 430*8d67ca89SAndroid Build Coastguard Workerblog post, and there's more detail about the implementation in 431*8d67ca89SAndroid Build Coastguard Worker[The Anatomy of Clang FORTIFY](clang_fortify_anatomy.md). 432*8d67ca89SAndroid Build Coastguard Worker 433*8d67ca89SAndroid Build Coastguard WorkerThe Android platform is built with `-D_FORTIFY_SOURCE=2`. Users of ndk-build 434*8d67ca89SAndroid Build Coastguard Workeror the NDK's CMake toolchain file also get this by default with NDK r21 or 435*8d67ca89SAndroid Build Coastguard Workernewer. Users of other build systems 436*8d67ca89SAndroid Build Coastguard Workerneed to manually enable FORTIFY by setting `_FORTIFY_SOURCE` themselves in 437*8d67ca89SAndroid Build Coastguard Workerwhatever build system they're using. The exact subset of FORTIFY available to 438*8d67ca89SAndroid Build Coastguard WorkerNDK users will depend on their target ABI level, because when a FORTIFY 439*8d67ca89SAndroid Build Coastguard Workercheck can't be guaranteed at compile-time, a call to a run-time `_chk` 440*8d67ca89SAndroid Build Coastguard Workerfunction is added. 441