ndk_cruft.cpp revision 152b9de19ade833ada124390ef153e53d3d3e2ed
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
32#include <stdlib.h>
33#include <sys/resource.h>
34#include <sys/time.h>
35#include <sys/types.h>
36#include <sys/wait.h>
37#include <unistd.h>
38
39// These were accidentally declared in <unistd.h> because we stupidly used to inline
40// getpagesize() and __getpageshift(). Needed for backwards compatibility with old NDK apps.
41extern "C" {
42  unsigned int __page_size = PAGE_SIZE;
43  unsigned int __page_shift = 12;
44}
45
46// TODO: remove this backward compatibility hack (for jb-mr1 strace binaries).
47extern "C" pid_t __wait4(pid_t pid, int* status, int options, struct rusage* rusage) {
48  return wait4(pid, status, options, rusage);
49}
50
51// TODO: does anything still need this?
52extern "C" int __open() {
53  abort();
54}
55
56// TODO: does anything still need this?
57extern "C" void** __get_tls() {
58#include "private/__get_tls.h"
59  return __get_tls();
60}
61
62// This non-standard function was in our <string.h> for some reason.
63extern "C" void memswap(void* m1, void* m2, size_t n) {
64  char* p = reinterpret_cast<char*>(m1);
65  char* p_end = p + n;
66  char* q = reinterpret_cast<char*>(m2);
67  while (p < p_end) {
68    char tmp = *p;
69    *p = *q;
70    *q = tmp;
71    p++;
72    q++;
73  }
74}
75
76#endif
77