]>
git.saurik.com Git - apple/xnu.git/blob - san/kasan-memintrinsics.c
2 * Copyright (c) 2016 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 #include <mach/boolean.h>
32 #include <mach/boolean.h>
33 #include <machine/limits.h>
34 #include <kern/debug.h>
36 #include <kasan_internal.h>
37 #include <memintrinsics.h>
40 static bool check_intrinsics
= true;
42 static bool check_intrinsics
= false;
46 __asan_bcopy(const void *src
, void *dst
, size_t sz
)
48 if (check_intrinsics
) {
49 kasan_check_range(src
, sz
, TYPE_MEMLD
);
50 kasan_check_range(dst
, sz
, TYPE_MEMSTR
);
52 __nosan_bcopy(src
, dst
, sz
);
56 __asan_memmove(void *src
, const void *dst
, size_t sz
)
58 if (check_intrinsics
) {
59 kasan_check_range(src
, sz
, TYPE_MEMLD
);
60 kasan_check_range(dst
, sz
, TYPE_MEMSTR
);
62 return __nosan_memmove(src
, dst
, sz
);
66 __asan_memcpy(void *dst
, const void *src
, size_t sz
)
68 if (check_intrinsics
) {
69 kasan_check_range(src
, sz
, TYPE_MEMLD
);
70 kasan_check_range(dst
, sz
, TYPE_MEMSTR
);
72 return __nosan_memcpy(dst
, src
, sz
);
76 __asan_memset(void *dst
, int c
, size_t sz
)
78 if (check_intrinsics
) {
79 kasan_check_range(dst
, sz
, TYPE_MEMSTR
);
81 return __nosan_memset(dst
, c
, sz
);
85 __asan_bzero(void *dst
, size_t sz
)
87 if (check_intrinsics
) {
88 kasan_check_range(dst
, sz
, TYPE_MEMSTR
);
90 __nosan_bzero(dst
, sz
);
94 __asan_bcmp(const void *a
, const void *b
, size_t len
)
96 if (check_intrinsics
) {
97 kasan_check_range(a
, len
, TYPE_MEMLD
);
98 kasan_check_range(b
, len
, TYPE_MEMLD
);
100 return __nosan_bcmp(a
, b
, len
);
104 __asan_memcmp(const void *a
, const void *b
, size_t n
)
106 if (check_intrinsics
) {
107 kasan_check_range(a
, n
, TYPE_MEMLD
);
108 kasan_check_range(b
, n
, TYPE_MEMLD
);
110 return __nosan_memcmp(a
, b
, n
);
114 __asan_strlcpy(char *dst
, const char *src
, size_t sz
)
116 if (check_intrinsics
) {
117 kasan_check_range(dst
, sz
, TYPE_STRINGSTR
);
119 return __nosan_strlcpy(dst
, src
, sz
);
123 __asan_strlcat(char *dst
, const char *src
, size_t sz
)
125 if (check_intrinsics
) {
126 kasan_check_range(dst
, sz
, TYPE_STRINGSTR
);
128 return __nosan_strlcat(dst
, src
, sz
);
132 __asan_strncpy(char *dst
, const char *src
, size_t sz
)
134 if (check_intrinsics
) {
135 kasan_check_range(dst
, sz
, TYPE_STRINGSTR
);
137 return __nosan_strncpy(dst
, src
, sz
);
141 __asan_strncat(char *dst
, const char *src
, size_t sz
)
143 if (check_intrinsics
) {
144 kasan_check_range(dst
, strlen(dst
) + sz
+ 1, TYPE_STRINGSTR
);
146 return __nosan_strncat(dst
, src
, sz
);
150 __asan_strnlen(const char *src
, size_t sz
)
152 if (check_intrinsics
) {
153 kasan_check_range(src
, sz
, TYPE_STRINGLD
);
156 return __nosan_strnlen(src
, sz
);
160 __asan_strlen(const char *src
)
162 size_t sz
= __nosan_strlen(src
);
163 if (check_intrinsics
) {
164 kasan_check_range(src
, sz
+ 1, TYPE_STRINGLD
);