]> git.saurik.com Git - apple/xnu.git/blame - san/memintrinsics.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / san / memintrinsics.h
CommitLineData
5ba3f43e 1/*
c3c9b80d 2 * Copyright (c) 2016-2020 Apple Inc. All rights reserved.
5ba3f43e
A
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28#ifndef _SAN_MEMINTRINSICS_H_
29#define _SAN_MEMINTRINSICS_H_
30
31/*
32 * Non-sanitized versions of memory intrinsics
33 */
0a7de745
A
34static inline void *
35__nosan_memcpy(void *dst, const void *src, size_t sz)
36{
37 return memcpy(dst, src, sz);
38}
39static inline void *
40__nosan_memset(void *src, int c, size_t sz)
41{
42 return memset(src, c, sz);
43}
44static inline void *
45__nosan_memmove(void *src, const void *dst, size_t sz)
46{
47 return memmove(src, dst, sz);
48}
49static inline int
50__nosan_bcmp(const void *a, const void *b, size_t sz)
51{
52 return bcmp(a, b, sz);
53}
54static inline void
55__nosan_bcopy(const void *src, void *dst, size_t sz)
56{
cb323159 57 bcopy(src, dst, sz);
0a7de745
A
58}
59static inline int
60__nosan_memcmp(const void *a, const void *b, size_t sz)
61{
62 return memcmp(a, b, sz);
63}
64static inline void
65__nosan_bzero(void *dst, size_t sz)
66{
cb323159 67 bzero(dst, sz);
0a7de745 68}
5ba3f43e 69
0a7de745
A
70static inline size_t
71__nosan_strlcpy(char *dst, const char *src, size_t sz)
72{
73 return strlcpy(dst, src, sz);
74}
75static inline char *
76__nosan_strncpy(char *dst, const char *src, size_t sz)
77{
c3c9b80d
A
78#ifdef __clang__
79#pragma clang diagnostic push
80#pragma clang diagnostic ignored "-Wdeprecated-declarations"
81#endif
0a7de745 82 return strncpy(dst, src, sz);
c3c9b80d
A
83#ifdef __clang__
84#pragma clang diagnostic pop
85#endif
0a7de745
A
86}
87static inline size_t
88__nosan_strlcat(char *dst, const char *src, size_t sz)
89{
90 return strlcat(dst, src, sz);
91}
92static inline char *
93__nosan_strncat(char *dst, const char *src, size_t sz)
94{
c3c9b80d
A
95#ifdef __clang__
96#pragma clang diagnostic push
97#pragma clang diagnostic ignored "-Wdeprecated-declarations"
98#endif
0a7de745 99 return strncat(dst, src, sz);
c3c9b80d
A
100#ifdef __clang__
101#pragma clang diagnostic pop
102#endif
0a7de745
A
103}
104static inline size_t
105__nosan_strnlen(const char *src, size_t sz)
106{
107 return strnlen(src, sz);
108}
109static inline size_t
110__nosan_strlen(const char *src)
111{
112 return strlen(src);
113}
5ba3f43e
A
114
115#if KASAN
116void *__asan_memcpy(void *src, const void *dst, size_t sz);
117void *__asan_memset(void *src, int c, size_t sz);
118void *__asan_memmove(void *src, const void *dst, size_t sz);
119void __asan_bcopy(const void *src, void *dst, size_t sz);
120void __asan_bzero(void *dst, size_t sz);
121int __asan_bcmp(const void *a, const void *b, size_t sz);
122int __asan_memcmp(const void *a, const void *b, size_t sz);
123
124size_t __asan_strlcpy(char *dst, const char *src, size_t sz);
125char *__asan_strncpy(char *dst, const char *src, size_t sz);
126size_t __asan_strlcat(char *dst, const char *src, size_t sz);
127char *__asan_strncat(char *dst, const char *src, size_t sz);
128size_t __asan_strnlen(const char *src, size_t sz);
129size_t __asan_strlen(const char *src);
130
131#define memcpy __asan_memcpy
132#define memmove __asan_memmove
133#define memset __asan_memset
134#define bcopy __asan_bcopy
135#define bzero __asan_bzero
136#define bcmp __asan_bcmp
137#define memcmp __asan_memcmp
138
139#define strlcpy __asan_strlcpy
140#define strncpy __asan_strncpy
141#define strlcat __asan_strlcat
142#define strncat __asan_strncat
143// #define strnlen __asan_strnlen
144// #define strlen __asan_strlen
145
146#endif
147
148#endif /* _SAN_MEMINTRINSICS_H_ */