Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 29 | #include <private/bionic_ifuncs.h> |
| 30 | #include <stddef.h> |
| 31 | #include <sys/auxv.h> |
| 32 | |
| 33 | extern "C" { |
| 34 | |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 35 | typedef void* memchr_func(const void*, int, size_t); |
| 36 | DEFINE_IFUNC_FOR(memchr) { |
Peter Collingbourne | 7e20117 | 2020-12-21 14:08:38 -0800 | [diff] [blame] | 37 | if (arg->_hwcap2 & HWCAP2_MTE) { |
Peter Collingbourne | 2361d4e | 2020-06-03 16:55:37 -0700 | [diff] [blame] | 38 | RETURN_FUNC(memchr_func, __memchr_aarch64_mte); |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 39 | } else { |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 40 | RETURN_FUNC(memchr_func, __memchr_aarch64); |
| 41 | } |
| 42 | } |
| 43 | |
Elliott Hughes | 7daf459 | 2022-11-17 00:34:13 +0000 | [diff] [blame^] | 44 | typedef void* memcpy_func(void*, const void*, size_t); |
| 45 | DEFINE_IFUNC_FOR(memcpy) { |
| 46 | if (arg->_hwcap & HWCAP_ASIMD) { |
| 47 | RETURN_FUNC(memcpy_func, __memcpy_aarch64_simd); |
| 48 | } else { |
| 49 | RETURN_FUNC(memcpy_func, __memcpy_aarch64); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | typedef void* memmove_func(void*, const void*, size_t); |
| 54 | DEFINE_IFUNC_FOR(memmove) { |
| 55 | if (arg->_hwcap & HWCAP_ASIMD) { |
| 56 | RETURN_FUNC(memmove_func, __memmove_aarch64_simd); |
| 57 | } else { |
| 58 | RETURN_FUNC(memmove_func, __memmove_aarch64); |
| 59 | } |
| 60 | } |
| 61 | |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 62 | typedef int stpcpy_func(char*, const char*); |
| 63 | DEFINE_IFUNC_FOR(stpcpy) { |
Peter Collingbourne | 7e20117 | 2020-12-21 14:08:38 -0800 | [diff] [blame] | 64 | if (arg->_hwcap2 & HWCAP2_MTE) { |
Peter Collingbourne | 2361d4e | 2020-06-03 16:55:37 -0700 | [diff] [blame] | 65 | RETURN_FUNC(stpcpy_func, __stpcpy_aarch64_mte); |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 66 | } else { |
| 67 | RETURN_FUNC(stpcpy_func, __stpcpy_aarch64); |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | typedef char* strchr_func(const char*, int); |
| 72 | DEFINE_IFUNC_FOR(strchr) { |
Peter Collingbourne | 7e20117 | 2020-12-21 14:08:38 -0800 | [diff] [blame] | 73 | if (arg->_hwcap2 & HWCAP2_MTE) { |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 74 | RETURN_FUNC(strchr_func, __strchr_aarch64_mte); |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 75 | } else { |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 76 | RETURN_FUNC(strchr_func, __strchr_aarch64); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | typedef char* strchrnul_func(const char*, int); |
| 81 | DEFINE_IFUNC_FOR(strchrnul) { |
Peter Collingbourne | 7e20117 | 2020-12-21 14:08:38 -0800 | [diff] [blame] | 82 | if (arg->_hwcap2 & HWCAP2_MTE) { |
Peter Collingbourne | 2361d4e | 2020-06-03 16:55:37 -0700 | [diff] [blame] | 83 | RETURN_FUNC(strchrnul_func, __strchrnul_aarch64_mte); |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 84 | } else { |
| 85 | RETURN_FUNC(strchrnul_func, __strchrnul_aarch64); |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
| 89 | typedef int strcmp_func(const char*, const char*); |
| 90 | DEFINE_IFUNC_FOR(strcmp) { |
Peter Collingbourne | 7e20117 | 2020-12-21 14:08:38 -0800 | [diff] [blame] | 91 | if (arg->_hwcap2 & HWCAP2_MTE) { |
Peter Collingbourne | 2361d4e | 2020-06-03 16:55:37 -0700 | [diff] [blame] | 92 | RETURN_FUNC(strcmp_func, __strcmp_aarch64_mte); |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 93 | } else { |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 94 | RETURN_FUNC(strcmp_func, __strcmp_aarch64); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | typedef int strcpy_func(char*, const char*); |
| 99 | DEFINE_IFUNC_FOR(strcpy) { |
Peter Collingbourne | 7e20117 | 2020-12-21 14:08:38 -0800 | [diff] [blame] | 100 | if (arg->_hwcap2 & HWCAP2_MTE) { |
Peter Collingbourne | 2361d4e | 2020-06-03 16:55:37 -0700 | [diff] [blame] | 101 | RETURN_FUNC(strcpy_func, __strcpy_aarch64_mte); |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 102 | } else { |
| 103 | RETURN_FUNC(strcpy_func, __strcpy_aarch64); |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
| 107 | typedef size_t strlen_func(const char*); |
| 108 | DEFINE_IFUNC_FOR(strlen) { |
Peter Collingbourne | 7e20117 | 2020-12-21 14:08:38 -0800 | [diff] [blame] | 109 | if (arg->_hwcap2 & HWCAP2_MTE) { |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 110 | RETURN_FUNC(strlen_func, __strlen_aarch64_mte); |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 111 | } else { |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 112 | RETURN_FUNC(strlen_func, __strlen_aarch64); |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | typedef int strncmp_func(const char*, const char*, int); |
| 117 | DEFINE_IFUNC_FOR(strncmp) { |
Peter Collingbourne | 7e20117 | 2020-12-21 14:08:38 -0800 | [diff] [blame] | 118 | if (arg->_hwcap2 & HWCAP2_MTE) { |
Peter Collingbourne | 2361d4e | 2020-06-03 16:55:37 -0700 | [diff] [blame] | 119 | RETURN_FUNC(strncmp_func, __strncmp_aarch64_mte); |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 120 | } else { |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 121 | RETURN_FUNC(strncmp_func, __strncmp_aarch64); |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 125 | typedef char* strrchr_func(const char*, int); |
| 126 | DEFINE_IFUNC_FOR(strrchr) { |
Peter Collingbourne | 7e20117 | 2020-12-21 14:08:38 -0800 | [diff] [blame] | 127 | if (arg->_hwcap2 & HWCAP2_MTE) { |
Peter Collingbourne | 2361d4e | 2020-06-03 16:55:37 -0700 | [diff] [blame] | 128 | RETURN_FUNC(strrchr_func, __strrchr_aarch64_mte); |
Peter Collingbourne | 337a5b3 | 2020-02-21 12:11:02 -0800 | [diff] [blame] | 129 | } else { |
| 130 | RETURN_FUNC(strrchr_func, __strrchr_aarch64); |
Peter Collingbourne | 900d07d | 2019-10-28 13:11:00 -0700 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | |
| 134 | } // extern "C" |