| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2008 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 | */ | 
| Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame] | 28 |  | 
| Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame] | 29 | // clang interprets -fno-builtin more loosely than you might expect, | 
|  | 30 | // and thinks it's okay to still substitute builtins as long as they're | 
|  | 31 | // named __aeabi_* rather than __builtin_*, which causes infinite | 
|  | 32 | // recursion if we have the fortified memcpy visible in this file. | 
|  | 33 | #undef _FORTIFY_SOURCE | 
| Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame] | 34 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | #include <stddef.h> | 
|  | 36 | #include <string.h> | 
|  | 37 |  | 
| Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame] | 38 | extern int __cxa_atexit(void (*)(void*), void*, void*); | 
| David 'Digit' Turner | 3e16f84 | 2009-05-14 14:25:26 +0200 | [diff] [blame] | 39 |  | 
| Dan Albert | 690211f | 2014-09-26 15:36:14 -0700 | [diff] [blame] | 40 | // All of these are weak symbols to avoid multiple definition errors when | 
|  | 41 | // linking with libstdc++-v3 or compiler-rt. | 
|  | 42 |  | 
| David 'Digit' Turner | 0ba91ed | 2009-05-20 11:42:52 +0200 | [diff] [blame] | 43 | /* The "C++ ABI for ARM" document states that static C++ constructors, | 
|  | 44 | * which are called from the .init_array, should manually call | 
| Nick Kralevich | bdbdbb8 | 2013-08-27 16:35:01 -0700 | [diff] [blame] | 45 | * __aeabi_atexit() to register static destructors explicitly. | 
| David 'Digit' Turner | 0ba91ed | 2009-05-20 11:42:52 +0200 | [diff] [blame] | 46 | * | 
|  | 47 | * Note that 'dso_handle' is the address of a magic linker-generate | 
|  | 48 | * variable from the shared object that contains the constructor/destructor | 
|  | 49 | */ | 
|  | 50 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 51 | int __attribute__((weak)) | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 52 | __aeabi_atexit_impl(void *object, void (*destructor) (void *), void *dso_handle) { | 
| David 'Digit' Turner | 0ba91ed | 2009-05-20 11:42:52 +0200 | [diff] [blame] | 53 | return __cxa_atexit(destructor, object, dso_handle); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 54 | } | 
|  | 55 |  | 
| Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame] | 56 | int __attribute__((weak)) | 
|  | 57 | __aeabi_atexit_impl2(void *object, void (*destructor) (void *), void *dso_handle) { | 
|  | 58 | return __cxa_atexit(destructor, object, dso_handle); | 
|  | 59 | } | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 60 |  | 
| Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame] | 61 |  | 
|  | 62 | void __attribute__((weak)) __aeabi_memcpy8_impl(void *dest, const void *src, size_t n) { | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 63 | memcpy(dest, src, n); | 
|  | 64 | } | 
|  | 65 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 66 | void __attribute__((weak)) __aeabi_memcpy4_impl(void *dest, const void *src, size_t n) { | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 67 | memcpy(dest, src, n); | 
|  | 68 | } | 
|  | 69 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 70 | void __attribute__((weak)) __aeabi_memcpy_impl(void *dest, const void *src, size_t n) { | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 71 | memcpy(dest, src, n); | 
|  | 72 | } | 
|  | 73 |  | 
| Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame] | 74 | void __attribute__((weak)) __aeabi_memcpy8_impl2(void *dest, const void *src, size_t n) { | 
|  | 75 | memcpy(dest, src, n); | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | void __attribute__((weak)) __aeabi_memcpy4_impl2(void *dest, const void *src, size_t n) { | 
|  | 79 | memcpy(dest, src, n); | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | void __attribute__((weak)) __aeabi_memcpy_impl2(void *dest, const void *src, size_t n) { | 
|  | 83 | memcpy(dest, src, n); | 
|  | 84 | } | 
|  | 85 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 86 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 87 | void __attribute__((weak)) __aeabi_memmove8_impl(void *dest, const void *src, size_t n) { | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 88 | memmove(dest, src, n); | 
|  | 89 | } | 
|  | 90 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 91 | void __attribute__((weak)) __aeabi_memmove4_impl(void *dest, const void *src, size_t n) { | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 92 | memmove(dest, src, n); | 
|  | 93 | } | 
|  | 94 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 95 | void __attribute__((weak)) __aeabi_memmove_impl(void *dest, const void *src, size_t n) { | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 96 | memmove(dest, src, n); | 
|  | 97 | } | 
|  | 98 |  | 
| Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame] | 99 | void __attribute__((weak)) __aeabi_memmove8_impl2(void *dest, const void *src, size_t n) { | 
|  | 100 | memmove(dest, src, n); | 
|  | 101 | } | 
|  | 102 |  | 
|  | 103 | void __attribute__((weak)) __aeabi_memmove4_impl2(void *dest, const void *src, size_t n) { | 
|  | 104 | memmove(dest, src, n); | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | void __attribute__((weak)) __aeabi_memmove_impl2(void *dest, const void *src, size_t n) { | 
|  | 108 | memmove(dest, src, n); | 
|  | 109 | } | 
|  | 110 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 111 | /* | 
| Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame] | 112 | * __aeabi_memset has the order of its second and third arguments reversed. | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 113 | *  This allows __aeabi_memclr to tail-call __aeabi_memset | 
|  | 114 | */ | 
| Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame] | 115 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 116 | void __attribute__((weak)) __aeabi_memset8_impl(void *dest, size_t n, int c) { | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 117 | memset(dest, c, n); | 
|  | 118 | } | 
|  | 119 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 120 | void __attribute__((weak)) __aeabi_memset4_impl(void *dest, size_t n, int c) { | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 121 | memset(dest, c, n); | 
|  | 122 | } | 
|  | 123 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 124 | void __attribute__((weak)) __aeabi_memset_impl(void *dest, size_t n, int c) { | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 125 | memset(dest, c, n); | 
|  | 126 | } | 
|  | 127 |  | 
| Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame] | 128 | void __attribute__((weak)) __aeabi_memset8_impl2(void *dest, size_t n, int c) { | 
|  | 129 | memset(dest, c, n); | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | void __attribute__((weak)) __aeabi_memset4_impl2(void *dest, size_t n, int c) { | 
|  | 133 | memset(dest, c, n); | 
|  | 134 | } | 
|  | 135 |  | 
|  | 136 | void __attribute__((weak)) __aeabi_memset_impl2(void *dest, size_t n, int c) { | 
|  | 137 | memset(dest, c, n); | 
|  | 138 | } | 
|  | 139 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 140 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 141 | void __attribute__((weak)) __aeabi_memclr8_impl(void *dest, size_t n) { | 
|  | 142 | __aeabi_memset8_impl(dest, n, 0); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 143 | } | 
|  | 144 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 145 | void __attribute__((weak)) __aeabi_memclr4_impl(void *dest, size_t n) { | 
|  | 146 | __aeabi_memset4_impl(dest, n, 0); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 147 | } | 
|  | 148 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 149 | void __attribute__((weak)) __aeabi_memclr_impl(void *dest, size_t n) { | 
|  | 150 | __aeabi_memset_impl(dest, n, 0); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 151 | } | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 152 |  | 
| Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame] | 153 | void __attribute__((weak)) __aeabi_memclr8_impl2(void *dest, size_t n) { | 
|  | 154 | __aeabi_memset8_impl(dest, n, 0); | 
|  | 155 | } | 
|  | 156 |  | 
|  | 157 | void __attribute__((weak)) __aeabi_memclr4_impl2(void *dest, size_t n) { | 
|  | 158 | __aeabi_memset4_impl(dest, n, 0); | 
|  | 159 | } | 
|  | 160 |  | 
|  | 161 | void __attribute__((weak)) __aeabi_memclr_impl2(void *dest, size_t n) { | 
|  | 162 | __aeabi_memset_impl(dest, n, 0); | 
|  | 163 | } | 
|  | 164 |  | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 165 | #define __AEABI_SYMVERS(fn_name) \ | 
| Dimitry Ivanov | 6d142bc | 2016-01-08 10:06:44 -0800 | [diff] [blame] | 166 | __asm__(".symver " #fn_name "_impl, " #fn_name "@@LIBC_N"); \ | 
| Dimitry Ivanov | 6f72fde | 2016-01-05 20:38:32 -0800 | [diff] [blame] | 167 | __asm__(".symver " #fn_name "_impl2, " #fn_name "@LIBC_PRIVATE") | 
| Dimitry Ivanov | d90d067 | 2016-01-05 16:38:43 -0800 | [diff] [blame] | 168 |  | 
|  | 169 | __AEABI_SYMVERS(__aeabi_atexit); | 
|  | 170 | __AEABI_SYMVERS(__aeabi_memcpy8); | 
|  | 171 | __AEABI_SYMVERS(__aeabi_memcpy4); | 
|  | 172 | __AEABI_SYMVERS(__aeabi_memcpy); | 
|  | 173 | __AEABI_SYMVERS(__aeabi_memmove8); | 
|  | 174 | __AEABI_SYMVERS(__aeabi_memmove4); | 
|  | 175 | __AEABI_SYMVERS(__aeabi_memmove); | 
|  | 176 | __AEABI_SYMVERS(__aeabi_memset8); | 
|  | 177 | __AEABI_SYMVERS(__aeabi_memset4); | 
|  | 178 | __AEABI_SYMVERS(__aeabi_memset); | 
|  | 179 | __AEABI_SYMVERS(__aeabi_memclr8); | 
|  | 180 | __AEABI_SYMVERS(__aeabi_memclr4); | 
|  | 181 | __AEABI_SYMVERS(__aeabi_memclr); | 
|  | 182 |  | 
|  | 183 | #undef __AEABI_SYMVERS |