]>
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 __asan_bcopy(const void *src
, void *dst
, size_t sz
)
42 kasan_check_range(src
, sz
, TYPE_MEMR
);
43 kasan_check_range(dst
, sz
, TYPE_MEMW
);
44 __nosan_bcopy(src
, dst
, sz
);
48 __asan_memmove(void *src
, const void *dst
, size_t sz
)
50 kasan_check_range(src
, sz
, TYPE_MEMR
);
51 kasan_check_range(dst
, sz
, TYPE_MEMW
);
52 return __nosan_memmove(src
, dst
, sz
);
56 __asan_memcpy(void *dst
, const void *src
, size_t sz
)
58 kasan_check_range(src
, sz
, TYPE_MEMR
);
59 kasan_check_range(dst
, sz
, TYPE_MEMW
);
60 return __nosan_memcpy(dst
, src
, sz
);
64 __asan_memset(void *dst
, int c
, size_t sz
)
66 kasan_check_range(dst
, sz
, TYPE_MEMW
);
67 return __nosan_memset(dst
, c
, sz
);
71 __asan_bzero(void *dst
, size_t sz
)
73 kasan_check_range(dst
, sz
, TYPE_MEMW
);
74 __nosan_bzero(dst
, sz
);
78 __asan_bcmp(const void *a
, const void *b
, size_t len
)
80 kasan_check_range(a
, len
, TYPE_MEMR
);
81 kasan_check_range(b
, len
, TYPE_MEMR
);
82 return __nosan_bcmp(a
, b
, len
);
86 __asan_memcmp(const void *a
, const void *b
, size_t n
)
88 kasan_check_range(a
, n
, TYPE_MEMR
);
89 kasan_check_range(b
, n
, TYPE_MEMR
);
90 return __nosan_memcmp(a
, b
, n
);
94 __asan_strlcpy(char *dst
, const char *src
, size_t sz
)
96 kasan_check_range(dst
, sz
, TYPE_STRW
);
97 return __nosan_strlcpy(dst
, src
, sz
);
101 __asan_strlcat(char *dst
, const char *src
, size_t sz
)
103 kasan_check_range(dst
, sz
, TYPE_STRW
);
104 return __nosan_strlcat(dst
, src
, sz
);
108 __asan_strncpy(char *dst
, const char *src
, size_t sz
)
110 kasan_check_range(dst
, sz
, TYPE_STRW
);
111 return __nosan_strncpy(dst
, src
, sz
);
115 __asan_strncat(char *dst
, const char *src
, size_t sz
)
117 kasan_check_range(dst
, strlen(dst
) + sz
+ 1, TYPE_STRW
);
118 return __nosan_strncat(dst
, src
, sz
);
122 __asan_strnlen(const char *src
, size_t sz
)
124 kasan_check_range(src
, sz
, TYPE_STRR
);
125 return __nosan_strnlen(src
, sz
);
129 __asan_strlen(const char *src
)
131 size_t sz
= __nosan_strlen(src
);
132 kasan_check_range(src
, sz
+ 1, TYPE_STRR
);