ndk_cruft.cpp revision b30aff405a220495941f1673b0a5e66c4fa8b84c
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>
33efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes#include <inttypes.h>
34a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle#include <pthread.h>
35fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes#include <stdio.h>
36567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <stdlib.h>
37567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <sys/resource.h>
38bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes#include <sys/syscall.h>
39567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <sys/time.h>
40567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <sys/types.h>
41567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <sys/wait.h>
42567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#include <unistd.h>
43567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes
44567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes// These were accidentally declared in <unistd.h> because we stupidly used to inline
45567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes// getpagesize() and __getpageshift(). Needed for backwards compatibility with old NDK apps.
46567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughesextern "C" {
47567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes  unsigned int __page_size = PAGE_SIZE;
480e44bc3baeb1677e5fbdda87a737b9c508c95132Elliott Hughes  unsigned int __page_shift = 12;
49567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes}
50567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes
51567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes// TODO: remove this backward compatibility hack (for jb-mr1 strace binaries).
52567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughesextern "C" pid_t __wait4(pid_t pid, int* status, int options, struct rusage* rusage) {
53567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes  return wait4(pid, status, options, rusage);
54567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes}
55567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes
56062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes// TODO: does anything still need this?
57567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughesextern "C" int __open() {
58567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes  abort();
59567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes}
60567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes
61062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes// TODO: does anything still need this?
62062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughesextern "C" void** __get_tls() {
63062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes#include "private/__get_tls.h"
64062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes  return __get_tls();
65062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes}
66062092543fdbd6fa2676e4f5b37a15f7bba94332Elliott Hughes
67152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes// This non-standard function was in our <string.h> for some reason.
68152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughesextern "C" void memswap(void* m1, void* m2, size_t n) {
69152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes  char* p = reinterpret_cast<char*>(m1);
70152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes  char* p_end = p + n;
71152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes  char* q = reinterpret_cast<char*>(m2);
72152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes  while (p < p_end) {
73152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes    char tmp = *p;
74152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes    *p = *q;
75152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes    *q = tmp;
76152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes    p++;
77152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes    q++;
78152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes  }
79152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes}
80152b9de19ade833ada124390ef153e53d3d3e2edElliott Hughes
81a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravleextern "C" int pthread_attr_setstackaddr(pthread_attr_t*, void*) {
82a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle  // This was removed from POSIX.1-2008, and is not implemented on bionic.
83a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle  // Needed for ABI compatibility with the NDK.
84a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle  return ENOSYS;
85a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle}
86a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle
87a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravleextern "C" int pthread_attr_getstackaddr(const pthread_attr_t* attr, void** stack_addr) {
88a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle  // This was removed from POSIX.1-2008.
89a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle  // Needed for ABI compatibility with the NDK.
90a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle  *stack_addr = (char*)attr->stack_base + attr->stack_size;
91a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle  return 0;
92a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle}
93a4eafa6dbc98378f3fa759fec8590871e2b5ae29Calin Juravle
94efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes// Non-standard cruft that should only ever have been in system/core/toolbox.
95efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughesextern "C" char* strtotimeval(const char* str, struct timeval* ts) {
96efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes  char* s;
97efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes  ts->tv_sec = strtoumax(str, &s, 10);
98efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes
99efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes  long fractional_seconds = 0;
100efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes  if (*s == '.') {
101efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes    s++;
102efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes    int count = 0;
103efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes
104efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes    // Read up to 6 digits (microseconds).
105efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes    while (*s && isdigit(*s)) {
106efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes      if (++count < 7) {
107efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes        fractional_seconds = fractional_seconds*10 + (*s - '0');
108efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes      }
109efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes      s++;
110efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes    }
111efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes
112efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes    for (; count < 6; count++) {
113efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes      fractional_seconds *= 10;
114efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes    }
115efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes  }
116efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes
117efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes  ts->tv_usec = fractional_seconds;
118efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes  return s;
119efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes}
120efbdb53f84f4e1faf38f3c1a4cb60a83b9885ef4Elliott Hughes
121eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughesstatic inline int digitval(int ch) {
122eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  unsigned d;
123eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
124eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  d = (unsigned)(ch - '0');
125eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  if (d < 10) return (int)d;
126eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
127eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  d = (unsigned)(ch - 'a');
128eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  if (d < 6) return (int)(d+10);
129eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
130eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  d = (unsigned)(ch - 'A');
131eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  if (d < 6) return (int)(d+10);
132eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
133eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  return -1;
134eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes}
135eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
136eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes// This non-standard function was in our <inttypes.h> for some reason.
137eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughesextern "C" uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n) {
138eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  const unsigned char*  p   = (const unsigned char *)nptr;
139eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  const unsigned char*  end = p + n;
140eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  int                   minus = 0;
141eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  uintmax_t             v = 0;
142eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  int                   d;
143eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
144eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  while (p < end && isspace(*p)) {
145eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    p++;
146eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  }
147eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
148eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  if (p < end) {
149eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    char c = p[0];
150eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    if (c == '-' || c == '+') {
151eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes      minus = (c == '-');
152eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes      p++;
153eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    }
154eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  }
155eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
156eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  if (base == 0) {
157eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    if (p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
158eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes      p += 2;
159eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes      base = 16;
160eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    } else if (p+1 < end && p[0] == '0') {
161eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes      p   += 1;
162eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes      base = 8;
163eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    } else {
164eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes      base = 10;
165eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    }
166eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  } else if (base == 16) {
167eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    if (p+2 < end && p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
168eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes      p += 2;
169eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    }
170eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  }
171eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
172eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  while (p < end && (d = digitval(*p)) >= 0 && d < base) {
173eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    v = v*base + d;
174eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    p += 1;
175eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  }
176eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
177eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  if (endptr) {
178eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes    *endptr = (char*) p;
179eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  }
180eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
181eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  return minus ? -v : v;
182eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes}
183eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
184eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes// This non-standard function was in our <inttypes.h> for some reason.
185eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughesextern "C" intmax_t strntoimax(const char* nptr, char** endptr, int base, size_t n) {
186eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes  return (intmax_t) strntoumax(nptr, endptr, base, n);
187eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes}
188eae5902e73dc4381811e08fd2334bf4a9300a928Elliott Hughes
189fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes// POSIX calls this dprintf, but LP32 Android had fdprintf instead.
190fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughesextern "C" int fdprintf(int fd, const char* fmt, ...) {
191fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes  va_list ap;
192fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes  va_start(ap, fmt);
193fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes  int rc = vdprintf(fd, fmt, ap);
194fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes  va_end(ap);
195fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes  return rc;
196fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes}
197fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes
198fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes// POSIX calls this vdprintf, but LP32 Android had fdprintf instead.
199fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughesextern "C" int vfdprintf(int fd, const char* fmt, va_list ap) {
200fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes  return vdprintf(fd, fmt, ap);
201fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes}
202fcac8ff97f6b6cced6546e0096cadc1039b68b5eElliott Hughes
203b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes#define __futex_wake __real_futex_wake
204b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes#define __futex_wait __real_futex_wait
205b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes#include "private/bionic_futex.h"
206b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes#undef __futex_wake
207b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes#undef __futex_wait
208bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes
209bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes// This used to be in <sys/atomics.h>.
210bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughesextern "C" int __futex_wake(volatile void* ftx, int count) {
211b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes  return __real_futex_wake(ftx, count);
212bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes}
213bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes
214bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes// This used to be in <sys/atomics.h>.
215bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughesextern "C" int __futex_wait(volatile void* ftx, int value, const struct timespec* timeout) {
216b30aff405a220495941f1673b0a5e66c4fa8b84cElliott Hughes  return __real_futex_wait(ftx, value, timeout);
217bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes}
218bd3a98c6b9850a8e55fb0e0ed9f045212c494881Elliott Hughes
219001707363ddee680d466c88dd330900683dadf63Anthony King// Unity's libmono uses this.
220001707363ddee680d466c88dd330900683dadf63Anthony Kingextern "C" int tkill(pid_t tid, int sig) {
221001707363ddee680d466c88dd330900683dadf63Anthony King  return syscall(__NR_tkill, tid, sig);
222001707363ddee680d466c88dd330900683dadf63Anthony King}
223001707363ddee680d466c88dd330900683dadf63Anthony King
224567a8de3ca5b4c4f033bfbcdd339a3fd59a76227Elliott Hughes#endif
225