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
29 #include <private/bionic_ifuncs.h>
30 #include <stddef.h>
31 #include <sys/auxv.h>
32
33 extern "C" {
34
35 typedef void* memchr_func(const void*, int, size_t);
DEFINE_IFUNC_FOR(memchr)36 DEFINE_IFUNC_FOR(memchr) {
37 if (arg->_hwcap2 & HWCAP2_MTE) {
38 RETURN_FUNC(memchr_func, __memchr_aarch64_mte);
39 } else {
40 RETURN_FUNC(memchr_func, __memchr_aarch64);
41 }
42 }
43
44 typedef void* memcmp_func(void*, const void*, size_t);
DEFINE_IFUNC_FOR(memcmp)45 DEFINE_IFUNC_FOR(memcmp) {
46 // TODO: enable the SVE version.
47 RETURN_FUNC(memcmp_func, __memcmp_aarch64);
48 }
49
50 typedef void* memcpy_func(void*, const void*, size_t);
DEFINE_IFUNC_FOR(memcpy)51 DEFINE_IFUNC_FOR(memcpy) {
52 if (arg->_hwcap & HWCAP_ASIMD) {
53 RETURN_FUNC(memcpy_func, __memcpy_aarch64_simd);
54 } else {
55 RETURN_FUNC(memcpy_func, __memcpy_aarch64);
56 }
57 }
58
59 typedef void* memmove_func(void*, const void*, size_t);
DEFINE_IFUNC_FOR(memmove)60 DEFINE_IFUNC_FOR(memmove) {
61 if (arg->_hwcap & HWCAP_ASIMD) {
62 RETURN_FUNC(memmove_func, __memmove_aarch64_simd);
63 } else {
64 RETURN_FUNC(memmove_func, __memmove_aarch64);
65 }
66 }
67
68 typedef int stpcpy_func(char*, const char*);
DEFINE_IFUNC_FOR(stpcpy)69 DEFINE_IFUNC_FOR(stpcpy) {
70 // TODO: enable the SVE version.
71 RETURN_FUNC(stpcpy_func, __stpcpy_aarch64);
72 }
73
74 typedef char* strchr_func(const char*, int);
DEFINE_IFUNC_FOR(strchr)75 DEFINE_IFUNC_FOR(strchr) {
76 if (arg->_hwcap2 & HWCAP2_MTE) {
77 RETURN_FUNC(strchr_func, __strchr_aarch64_mte);
78 } else {
79 RETURN_FUNC(strchr_func, __strchr_aarch64);
80 }
81 }
82
83 typedef char* strchrnul_func(const char*, int);
DEFINE_IFUNC_FOR(strchrnul)84 DEFINE_IFUNC_FOR(strchrnul) {
85 if (arg->_hwcap2 & HWCAP2_MTE) {
86 RETURN_FUNC(strchrnul_func, __strchrnul_aarch64_mte);
87 } else {
88 RETURN_FUNC(strchrnul_func, __strchrnul_aarch64);
89 }
90 }
91
92 typedef int strcmp_func(const char*, const char*);
DEFINE_IFUNC_FOR(strcmp)93 DEFINE_IFUNC_FOR(strcmp) {
94 // TODO: enable the SVE version.
95 RETURN_FUNC(strcmp_func, __strcmp_aarch64);
96 }
97
98 typedef int strcpy_func(char*, const char*);
DEFINE_IFUNC_FOR(strcpy)99 DEFINE_IFUNC_FOR(strcpy) {
100 // TODO: enable the SVE version.
101 RETURN_FUNC(strcpy_func, __strcpy_aarch64);
102 }
103
104 typedef size_t strlen_func(const char*);
DEFINE_IFUNC_FOR(strlen)105 DEFINE_IFUNC_FOR(strlen) {
106 if (arg->_hwcap2 & HWCAP2_MTE) {
107 RETURN_FUNC(strlen_func, __strlen_aarch64_mte);
108 } else {
109 RETURN_FUNC(strlen_func, __strlen_aarch64);
110 }
111 }
112
113 typedef int strncmp_func(const char*, const char*, int);
DEFINE_IFUNC_FOR(strncmp)114 DEFINE_IFUNC_FOR(strncmp) {
115 // TODO: enable the SVE version.
116 RETURN_FUNC(strncmp_func, __strncmp_aarch64);
117 }
118
119 typedef size_t strnlen_func(const char*);
DEFINE_IFUNC_FOR(strnlen)120 DEFINE_IFUNC_FOR(strnlen) {
121 // TODO: enable the SVE version.
122 RETURN_FUNC(strnlen_func, __strnlen_aarch64);
123 }
124
125 typedef char* strrchr_func(const char*, int);
DEFINE_IFUNC_FOR(strrchr)126 DEFINE_IFUNC_FOR(strrchr) {
127 if (arg->_hwcap2 & HWCAP2_MTE) {
128 RETURN_FUNC(strrchr_func, __strrchr_aarch64_mte);
129 } else {
130 RETURN_FUNC(strrchr_func, __strrchr_aarch64);
131 }
132 }
133
134 } // extern "C"
135