blob: 83e5ca4da713c219ea8568ecd8d3d3dc287ab912 [file] [log] [blame]
Peter Collingbourne900d07d2019-10-28 13:11:00 -07001/*
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 Collingbourne900d07d2019-10-28 13:11:00 -070029#include <private/bionic_ifuncs.h>
30#include <stddef.h>
31#include <sys/auxv.h>
32
33extern "C" {
34
Peter Collingbourne900d07d2019-10-28 13:11:00 -070035typedef void* memchr_func(const void*, int, size_t);
36DEFINE_IFUNC_FOR(memchr) {
Peter Collingbourne7e201172020-12-21 14:08:38 -080037 if (arg->_hwcap2 & HWCAP2_MTE) {
Peter Collingbourne2361d4e2020-06-03 16:55:37 -070038 RETURN_FUNC(memchr_func, __memchr_aarch64_mte);
Peter Collingbourne900d07d2019-10-28 13:11:00 -070039 } else {
Peter Collingbourne337a5b32020-02-21 12:11:02 -080040 RETURN_FUNC(memchr_func, __memchr_aarch64);
41 }
42}
43
44typedef int stpcpy_func(char*, const char*);
45DEFINE_IFUNC_FOR(stpcpy) {
Peter Collingbourne7e201172020-12-21 14:08:38 -080046 if (arg->_hwcap2 & HWCAP2_MTE) {
Peter Collingbourne2361d4e2020-06-03 16:55:37 -070047 RETURN_FUNC(stpcpy_func, __stpcpy_aarch64_mte);
Peter Collingbourne337a5b32020-02-21 12:11:02 -080048 } else {
49 RETURN_FUNC(stpcpy_func, __stpcpy_aarch64);
Peter Collingbourne900d07d2019-10-28 13:11:00 -070050 }
51}
52
53typedef char* strchr_func(const char*, int);
54DEFINE_IFUNC_FOR(strchr) {
Peter Collingbourne7e201172020-12-21 14:08:38 -080055 if (arg->_hwcap2 & HWCAP2_MTE) {
Peter Collingbourne337a5b32020-02-21 12:11:02 -080056 RETURN_FUNC(strchr_func, __strchr_aarch64_mte);
Peter Collingbourne900d07d2019-10-28 13:11:00 -070057 } else {
Peter Collingbourne337a5b32020-02-21 12:11:02 -080058 RETURN_FUNC(strchr_func, __strchr_aarch64);
59 }
60}
61
62typedef char* strchrnul_func(const char*, int);
63DEFINE_IFUNC_FOR(strchrnul) {
Peter Collingbourne7e201172020-12-21 14:08:38 -080064 if (arg->_hwcap2 & HWCAP2_MTE) {
Peter Collingbourne2361d4e2020-06-03 16:55:37 -070065 RETURN_FUNC(strchrnul_func, __strchrnul_aarch64_mte);
Peter Collingbourne337a5b32020-02-21 12:11:02 -080066 } else {
67 RETURN_FUNC(strchrnul_func, __strchrnul_aarch64);
Peter Collingbourne900d07d2019-10-28 13:11:00 -070068 }
69}
70
71typedef int strcmp_func(const char*, const char*);
72DEFINE_IFUNC_FOR(strcmp) {
Peter Collingbourne7e201172020-12-21 14:08:38 -080073 if (arg->_hwcap2 & HWCAP2_MTE) {
Peter Collingbourne2361d4e2020-06-03 16:55:37 -070074 RETURN_FUNC(strcmp_func, __strcmp_aarch64_mte);
Peter Collingbourne900d07d2019-10-28 13:11:00 -070075 } else {
Peter Collingbourne337a5b32020-02-21 12:11:02 -080076 RETURN_FUNC(strcmp_func, __strcmp_aarch64);
77 }
78}
79
80typedef int strcpy_func(char*, const char*);
81DEFINE_IFUNC_FOR(strcpy) {
Peter Collingbourne7e201172020-12-21 14:08:38 -080082 if (arg->_hwcap2 & HWCAP2_MTE) {
Peter Collingbourne2361d4e2020-06-03 16:55:37 -070083 RETURN_FUNC(strcpy_func, __strcpy_aarch64_mte);
Peter Collingbourne337a5b32020-02-21 12:11:02 -080084 } else {
85 RETURN_FUNC(strcpy_func, __strcpy_aarch64);
Peter Collingbourne900d07d2019-10-28 13:11:00 -070086 }
87}
88
89typedef size_t strlen_func(const char*);
90DEFINE_IFUNC_FOR(strlen) {
Peter Collingbourne7e201172020-12-21 14:08:38 -080091 if (arg->_hwcap2 & HWCAP2_MTE) {
Peter Collingbourne337a5b32020-02-21 12:11:02 -080092 RETURN_FUNC(strlen_func, __strlen_aarch64_mte);
Peter Collingbourne900d07d2019-10-28 13:11:00 -070093 } else {
Peter Collingbourne337a5b32020-02-21 12:11:02 -080094 RETURN_FUNC(strlen_func, __strlen_aarch64);
Peter Collingbourne900d07d2019-10-28 13:11:00 -070095 }
96}
97
98typedef int strncmp_func(const char*, const char*, int);
99DEFINE_IFUNC_FOR(strncmp) {
Peter Collingbourne7e201172020-12-21 14:08:38 -0800100 if (arg->_hwcap2 & HWCAP2_MTE) {
Peter Collingbourne2361d4e2020-06-03 16:55:37 -0700101 RETURN_FUNC(strncmp_func, __strncmp_aarch64_mte);
Peter Collingbourne900d07d2019-10-28 13:11:00 -0700102 } else {
Peter Collingbourne337a5b32020-02-21 12:11:02 -0800103 RETURN_FUNC(strncmp_func, __strncmp_aarch64);
Peter Collingbourne900d07d2019-10-28 13:11:00 -0700104 }
105}
106
Peter Collingbourne337a5b32020-02-21 12:11:02 -0800107typedef char* strrchr_func(const char*, int);
108DEFINE_IFUNC_FOR(strrchr) {
Peter Collingbourne7e201172020-12-21 14:08:38 -0800109 if (arg->_hwcap2 & HWCAP2_MTE) {
Peter Collingbourne2361d4e2020-06-03 16:55:37 -0700110 RETURN_FUNC(strrchr_func, __strrchr_aarch64_mte);
Peter Collingbourne337a5b32020-02-21 12:11:02 -0800111 } else {
112 RETURN_FUNC(strrchr_func, __strrchr_aarch64);
Peter Collingbourne900d07d2019-10-28 13:11:00 -0700113 }
114}
115
116} // extern "C"