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 | |
| 29 | #if defined(__clang__) |
| 30 | // clang interprets -fno-builtin more loosely than you might expect, |
| 31 | // and thinks it's okay to still substitute builtins as long as they're |
| 32 | // named __aeabi_* rather than __builtin_*, which causes infinite |
| 33 | // recursion if we have the fortified memcpy visible in this file. |
| 34 | #undef _FORTIFY_SOURCE |
| 35 | #endif |
| 36 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 37 | #include <stddef.h> |
| 38 | #include <string.h> |
| 39 | |
Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame^] | 40 | extern int __cxa_atexit(void (*)(void*), void*, void*); |
David 'Digit' Turner | 3e16f84 | 2009-05-14 14:25:26 +0200 | [diff] [blame] | 41 | |
David 'Digit' Turner | 0ba91ed | 2009-05-20 11:42:52 +0200 | [diff] [blame] | 42 | /* The "C++ ABI for ARM" document states that static C++ constructors, |
| 43 | * which are called from the .init_array, should manually call |
Nick Kralevich | bdbdbb8 | 2013-08-27 16:35:01 -0700 | [diff] [blame] | 44 | * __aeabi_atexit() to register static destructors explicitly. |
David 'Digit' Turner | 0ba91ed | 2009-05-20 11:42:52 +0200 | [diff] [blame] | 45 | * |
| 46 | * Note that 'dso_handle' is the address of a magic linker-generate |
| 47 | * variable from the shared object that contains the constructor/destructor |
| 48 | */ |
| 49 | |
Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame^] | 50 | // Make this a weak symbol to avoid a multiple definition error when linking with libstdc++-v3. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 51 | int __attribute__((weak)) |
Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame^] | 52 | __aeabi_atexit(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 | |
| 56 | |
| 57 | void __aeabi_memcpy8(void *dest, const void *src, size_t n) { |
| 58 | memcpy(dest, src, n); |
| 59 | } |
| 60 | |
| 61 | void __aeabi_memcpy4(void *dest, const void *src, size_t n) { |
| 62 | memcpy(dest, src, n); |
| 63 | } |
| 64 | |
| 65 | void __aeabi_memcpy(void *dest, const void *src, size_t n) { |
| 66 | memcpy(dest, src, n); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | void __aeabi_memmove8(void *dest, const void *src, size_t n) { |
| 71 | memmove(dest, src, n); |
| 72 | } |
| 73 | |
| 74 | void __aeabi_memmove4(void *dest, const void *src, size_t n) { |
| 75 | memmove(dest, src, n); |
| 76 | } |
| 77 | |
| 78 | void __aeabi_memmove(void *dest, const void *src, size_t n) { |
| 79 | memmove(dest, src, n); |
| 80 | } |
| 81 | |
| 82 | /* |
Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame^] | 83 | * __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] | 84 | * This allows __aeabi_memclr to tail-call __aeabi_memset |
| 85 | */ |
Elliott Hughes | c999f76 | 2014-07-10 16:57:27 -0700 | [diff] [blame^] | 86 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 87 | void __aeabi_memset8(void *dest, size_t n, int c) { |
| 88 | memset(dest, c, n); |
| 89 | } |
| 90 | |
| 91 | void __aeabi_memset4(void *dest, size_t n, int c) { |
| 92 | memset(dest, c, n); |
| 93 | } |
| 94 | |
| 95 | void __aeabi_memset(void *dest, size_t n, int c) { |
| 96 | memset(dest, c, n); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | void __aeabi_memclr8(void *dest, size_t n) { |
| 101 | __aeabi_memset8(dest, n, 0); |
| 102 | } |
| 103 | |
| 104 | void __aeabi_memclr4(void *dest, size_t n) { |
| 105 | __aeabi_memset4(dest, n, 0); |
| 106 | } |
| 107 | |
| 108 | void __aeabi_memclr(void *dest, size_t n) { |
| 109 | __aeabi_memset(dest, n, 0); |
| 110 | } |