ndk_cruft.cpp revision 8229ae46f4fb165a18da4dca1be74c4c099c3ee7
1567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes/* 2567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * Copyright (C) 2013 The Android Open Source Project 3567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * All rights reserved. 4567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * 5567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * Redistribution and use in source and binary forms, with or without 6567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * modification, are permitted provided that the following conditions 7567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * are met: 8567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * * Redistributions of source code must retain the above copyright 9567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * notice, this list of conditions and the following disclaimer. 10567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * * Redistributions in binary form must reproduce the above copyright 11567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * notice, this list of conditions and the following disclaimer in 12567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * the documentation and/or other materials provided with the 13567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * distribution. 14567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * 15567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes * SUCH DAMAGE. 27567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes */ 28567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes 29567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes// This file perpetuates the mistakes of the past, but only for 32-bit targets. 30567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#if !defined(__LP64__) 31567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes 32efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes#include <ctype.h> 33d1ead2af8bf2f6bb801da272e3778f89efefe613Elliott Hughes#include <dirent.h> 34efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes#include <inttypes.h> 35a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle#include <pthread.h> 36205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albert#include <signal.h> 37fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes#include <stdio.h> 38567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <stdlib.h> 39567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <sys/resource.h> 40bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes#include <sys/syscall.h> 41567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <sys/time.h> 42567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <sys/types.h> 43567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <sys/wait.h> 44567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <unistd.h> 45001f8f041bf21c53d4a0b919ef2c859b047bac0aDan Albert#include <wchar.h> 46567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes 47567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes// These were accidentally declared in <unistd.h> because we stupidly used to inline 48567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes// getpagesize() and __getpageshift(). Needed for backwards compatibility with old NDK apps. 49567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughesextern "C" { 50567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes unsigned int __page_size = PAGE_SIZE; 510e44bc3baeb1677e5fbdda87a737b9c508c95132Elliott Hughes unsigned int __page_shift = 12; 52567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes} 53567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes 54567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes// TODO: remove this backward compatibility hack (for jb-mr1 strace binaries). 55567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughesextern "C" pid_t __wait4(pid_t pid, int* status, int options, struct rusage* rusage) { 56567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes return wait4(pid, status, options, rusage); 57567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes} 58567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes 59062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes// TODO: does anything still need this? 60567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughesextern "C" int __open() { 61567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes abort(); 62567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes} 63567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes 64062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes// TODO: does anything still need this? 65062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughesextern "C" void** __get_tls() { 66062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes#include "private/__get_tls.h" 67062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes return __get_tls(); 68062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes} 69062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes 70152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes// This non-standard function was in our <string.h> for some reason. 71152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughesextern "C" void memswap(void* m1, void* m2, size_t n) { 72152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes char* p = reinterpret_cast<char*>(m1); 73152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes char* p_end = p + n; 74152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes char* q = reinterpret_cast<char*>(m2); 75152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes while (p < p_end) { 76152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes char tmp = *p; 77152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes *p = *q; 78152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes *q = tmp; 79152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes p++; 80152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes q++; 81152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes } 82152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes} 83152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes 84a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravleextern "C" int pthread_attr_setstackaddr(pthread_attr_t*, void*) { 85a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle // This was removed from POSIX.1-2008, and is not implemented on bionic. 86a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle // Needed for ABI compatibility with the NDK. 87a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle return ENOSYS; 88a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle} 89a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle 90a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravleextern "C" int pthread_attr_getstackaddr(const pthread_attr_t* attr, void** stack_addr) { 91a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle // This was removed from POSIX.1-2008. 92a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle // Needed for ABI compatibility with the NDK. 93a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle *stack_addr = (char*)attr->stack_base + attr->stack_size; 94a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle return 0; 95a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle} 96a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle 97efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes// Non-standard cruft that should only ever have been in system/core/toolbox. 98efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughesextern "C" char* strtotimeval(const char* str, struct timeval* ts) { 99efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes char* s; 100efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes ts->tv_sec = strtoumax(str, &s, 10); 101efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes 102efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes long fractional_seconds = 0; 103efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes if (*s == '.') { 104efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes s++; 105efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes int count = 0; 106efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes 107efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes // Read up to 6 digits (microseconds). 108efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes while (*s && isdigit(*s)) { 109efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes if (++count < 7) { 110efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes fractional_seconds = fractional_seconds*10 + (*s - '0'); 111efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes } 112efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes s++; 113efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes } 114efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes 115efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes for (; count < 6; count++) { 116efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes fractional_seconds *= 10; 117efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes } 118efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes } 119efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes 120efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes ts->tv_usec = fractional_seconds; 121efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes return s; 122efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes} 123efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes 124eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughesstatic inline int digitval(int ch) { 125eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes unsigned d; 126eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 127eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes d = (unsigned)(ch - '0'); 128eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes if (d < 10) return (int)d; 129eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 130eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes d = (unsigned)(ch - 'a'); 131eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes if (d < 6) return (int)(d+10); 132eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 133eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes d = (unsigned)(ch - 'A'); 134eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes if (d < 6) return (int)(d+10); 135eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 136eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes return -1; 137eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes} 138eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 139eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes// This non-standard function was in our <inttypes.h> for some reason. 140eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughesextern "C" uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n) { 141eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes const unsigned char* p = (const unsigned char *)nptr; 142eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes const unsigned char* end = p + n; 143eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes int minus = 0; 144eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes uintmax_t v = 0; 145eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes int d; 146eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 147eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes while (p < end && isspace(*p)) { 148eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes p++; 149eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes } 150eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 151eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes if (p < end) { 152eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes char c = p[0]; 153eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes if (c == '-' || c == '+') { 154eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes minus = (c == '-'); 155eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes p++; 156eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes } 157eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes } 158eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 159eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes if (base == 0) { 160eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes if (p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { 161eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes p += 2; 162eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes base = 16; 163eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes } else if (p+1 < end && p[0] == '0') { 164eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes p += 1; 165eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes base = 8; 166eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes } else { 167eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes base = 10; 168eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes } 169eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes } else if (base == 16) { 170eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes if (p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) { 171eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes p += 2; 172eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes } 173eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes } 174eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 175eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes while (p < end && (d = digitval(*p)) >= 0 && d < base) { 176eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes v = v*base + d; 177eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes p += 1; 178eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes } 179eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 180eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes if (endptr) { 181eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes *endptr = (char*) p; 182eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes } 183eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 184eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes return minus ? -v : v; 185eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes} 186eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 187eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes// This non-standard function was in our <inttypes.h> for some reason. 188eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughesextern "C" intmax_t strntoimax(const char* nptr, char** endptr, int base, size_t n) { 189eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes return (intmax_t) strntoumax(nptr, endptr, base, n); 190eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes} 191eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes 192fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes// POSIX calls this dprintf, but LP32 Android had fdprintf instead. 193fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughesextern "C" int fdprintf(int fd, const char* fmt, ...) { 194fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes va_list ap; 195fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes va_start(ap, fmt); 196fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes int rc = vdprintf(fd, fmt, ap); 197fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes va_end(ap); 198fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes return rc; 199fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes} 200fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes 201fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes// POSIX calls this vdprintf, but LP32 Android had fdprintf instead. 202fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughesextern "C" int vfdprintf(int fd, const char* fmt, va_list ap) { 203fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes return vdprintf(fd, fmt, ap); 204fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes} 205fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes 206b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes#define __futex_wake __real_futex_wake 207b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes#define __futex_wait __real_futex_wait 208b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes#include "private/bionic_futex.h" 209b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes#undef __futex_wake 210b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes#undef __futex_wait 211bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes 212bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes// This used to be in <sys/atomics.h>. 213bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughesextern "C" int __futex_wake(volatile void* ftx, int count) { 214b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes return __real_futex_wake(ftx, count); 215bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes} 216bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes 217bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes// This used to be in <sys/atomics.h>. 218bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughesextern "C" int __futex_wait(volatile void* ftx, int value, const struct timespec* timeout) { 219b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes return __real_futex_wait(ftx, value, timeout); 220bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes} 221bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes 222001707363ddee680d466c88dd330900683dadf63Anthony King// Unity's libmono uses this. 223001707363ddee680d466c88dd330900683dadf63Anthony Kingextern "C" int tkill(pid_t tid, int sig) { 224001707363ddee680d466c88dd330900683dadf63Anthony King return syscall(__NR_tkill, tid, sig); 225001707363ddee680d466c88dd330900683dadf63Anthony King} 226001707363ddee680d466c88dd330900683dadf63Anthony King 227001f8f041bf21c53d4a0b919ef2c859b047bac0aDan Albertextern "C" wchar_t* wcswcs(wchar_t* haystack, wchar_t* needle) { 228001f8f041bf21c53d4a0b919ef2c859b047bac0aDan Albert return wcsstr(haystack, needle); 229001f8f041bf21c53d4a0b919ef2c859b047bac0aDan Albert} 230001f8f041bf21c53d4a0b919ef2c859b047bac0aDan Albert 231205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albert// This was removed from POSIX 2008. 232205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albertextern "C" sighandler_t bsd_signal(int signum, sighandler_t handler) { 233205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albert return signal(signum, handler); 234205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albert} 235205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albert 236205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albert// sysv_signal() was never in POSIX. 237205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albertextern sighandler_t _signal(int signum, sighandler_t handler, int flags); 238205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albertextern "C" sighandler_t sysv_signal(int signum, sighandler_t handler) { 239205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albert return _signal(signum, handler, SA_RESETHAND); 240205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albert} 241205dd7d9b3ba314ef8601e4613823c2d62a0605bDan Albert 2423d5cb30d23cfc6a72f01c00246e69a2c614c8228Elliott Hughes// This is a system call that was never in POSIX. Use readdir(3) instead. 243d1ead2af8bf2f6bb801da272e3778f89efefe613Elliott Hughesextern "C" int __getdents64(unsigned int, dirent*, unsigned int); 244d1ead2af8bf2f6bb801da272e3778f89efefe613Elliott Hughesextern "C" int getdents(unsigned int fd, dirent* dirp, unsigned int count) { 2453d5cb30d23cfc6a72f01c00246e69a2c614c8228Elliott Hughes return __getdents64(fd, dirp, count); 2463d5cb30d23cfc6a72f01c00246e69a2c614c8228Elliott Hughes} 2473d5cb30d23cfc6a72f01c00246e69a2c614c8228Elliott Hughes 248bffbfeed7a595dcbe5843a77d84c409a0225b4e1Elliott Hughes// This is a BSDism that we never implemented correctly. Used by Firefox. 249bffbfeed7a595dcbe5843a77d84c409a0225b4e1Elliott Hughesextern "C" int issetugid() { 250bffbfeed7a595dcbe5843a77d84c409a0225b4e1Elliott Hughes return 0; 251bffbfeed7a595dcbe5843a77d84c409a0225b4e1Elliott Hughes} 252bffbfeed7a595dcbe5843a77d84c409a0225b4e1Elliott Hughes 2538229ae46f4fb165a18da4dca1be74c4c099c3ee7Dan Albert// This was removed from POSIX 2004. 2548229ae46f4fb165a18da4dca1be74c4c099c3ee7Dan Albertextern "C" pid_t wait3(int* status, int options, struct rusage* rusage) { 2558229ae46f4fb165a18da4dca1be74c4c099c3ee7Dan Albert return wait4(-1, status, options, rusage); 2568229ae46f4fb165a18da4dca1be74c4c099c3ee7Dan Albert} 2578229ae46f4fb165a18da4dca1be74c4c099c3ee7Dan Albert 258567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#endif 259