Elliott Hughes | 567a8de | 2013-10-24 17:14:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | // This file perpetuates the mistakes of the past, but only for 32-bit targets. |
| 30 | #if !defined(__LP64__) |
| 31 | |
Elliott Hughes | efbdb53 | 2014-04-07 15:17:19 -0700 | [diff] [blame] | 32 | #include <ctype.h> |
| 33 | #include <inttypes.h> |
Calin Juravle | a4eafa6 | 2014-03-10 18:10:04 +0000 | [diff] [blame] | 34 | #include <pthread.h> |
Elliott Hughes | 567a8de | 2013-10-24 17:14:55 -0700 | [diff] [blame] | 35 | #include <stdlib.h> |
| 36 | #include <sys/resource.h> |
| 37 | #include <sys/time.h> |
| 38 | #include <sys/types.h> |
| 39 | #include <sys/wait.h> |
| 40 | #include <unistd.h> |
| 41 | |
| 42 | // These were accidentally declared in <unistd.h> because we stupidly used to inline |
| 43 | // getpagesize() and __getpageshift(). Needed for backwards compatibility with old NDK apps. |
| 44 | extern "C" { |
| 45 | unsigned int __page_size = PAGE_SIZE; |
Elliott Hughes | 0e44bc3 | 2014-02-24 15:55:31 -0800 | [diff] [blame] | 46 | unsigned int __page_shift = 12; |
Elliott Hughes | 567a8de | 2013-10-24 17:14:55 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | // TODO: remove this backward compatibility hack (for jb-mr1 strace binaries). |
| 50 | extern "C" pid_t __wait4(pid_t pid, int* status, int options, struct rusage* rusage) { |
| 51 | return wait4(pid, status, options, rusage); |
| 52 | } |
| 53 | |
Elliott Hughes | 0620925 | 2013-11-06 16:20:54 -0800 | [diff] [blame] | 54 | // TODO: does anything still need this? |
Elliott Hughes | 567a8de | 2013-10-24 17:14:55 -0700 | [diff] [blame] | 55 | extern "C" int __open() { |
| 56 | abort(); |
| 57 | } |
| 58 | |
Elliott Hughes | 0620925 | 2013-11-06 16:20:54 -0800 | [diff] [blame] | 59 | // TODO: does anything still need this? |
| 60 | extern "C" void** __get_tls() { |
| 61 | #include "private/__get_tls.h" |
| 62 | return __get_tls(); |
| 63 | } |
| 64 | |
Elliott Hughes | 152b9de | 2014-03-10 15:54:40 -0700 | [diff] [blame] | 65 | // This non-standard function was in our <string.h> for some reason. |
| 66 | extern "C" void memswap(void* m1, void* m2, size_t n) { |
| 67 | char* p = reinterpret_cast<char*>(m1); |
| 68 | char* p_end = p + n; |
| 69 | char* q = reinterpret_cast<char*>(m2); |
| 70 | while (p < p_end) { |
| 71 | char tmp = *p; |
| 72 | *p = *q; |
| 73 | *q = tmp; |
| 74 | p++; |
| 75 | q++; |
| 76 | } |
| 77 | } |
| 78 | |
Calin Juravle | a4eafa6 | 2014-03-10 18:10:04 +0000 | [diff] [blame] | 79 | extern "C" int pthread_attr_setstackaddr(pthread_attr_t*, void*) { |
| 80 | // This was removed from POSIX.1-2008, and is not implemented on bionic. |
| 81 | // Needed for ABI compatibility with the NDK. |
| 82 | return ENOSYS; |
| 83 | } |
| 84 | |
| 85 | extern "C" int pthread_attr_getstackaddr(const pthread_attr_t* attr, void** stack_addr) { |
| 86 | // This was removed from POSIX.1-2008. |
| 87 | // Needed for ABI compatibility with the NDK. |
| 88 | *stack_addr = (char*)attr->stack_base + attr->stack_size; |
| 89 | return 0; |
| 90 | } |
| 91 | |
Elliott Hughes | efbdb53 | 2014-04-07 15:17:19 -0700 | [diff] [blame] | 92 | // Non-standard cruft that should only ever have been in system/core/toolbox. |
| 93 | extern "C" char* strtotimeval(const char* str, struct timeval* ts) { |
| 94 | char* s; |
| 95 | ts->tv_sec = strtoumax(str, &s, 10); |
| 96 | |
| 97 | long fractional_seconds = 0; |
| 98 | if (*s == '.') { |
| 99 | s++; |
| 100 | int count = 0; |
| 101 | |
| 102 | // Read up to 6 digits (microseconds). |
| 103 | while (*s && isdigit(*s)) { |
| 104 | if (++count < 7) { |
| 105 | fractional_seconds = fractional_seconds*10 + (*s - '0'); |
| 106 | } |
| 107 | s++; |
| 108 | } |
| 109 | |
| 110 | for (; count < 6; count++) { |
| 111 | fractional_seconds *= 10; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | ts->tv_usec = fractional_seconds; |
| 116 | return s; |
| 117 | } |
| 118 | |
Elliott Hughes | 567a8de | 2013-10-24 17:14:55 -0700 | [diff] [blame] | 119 | #endif |