]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/libsa/string.h
2 * Copyright (c) 2000-2006 Apple Computer, 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@
29 * NOTICE: This file was modified by McAfee Research in 2004 to introduce
30 * support for mandatory and extensible security protections. This notice
31 * is included in support of clause 2.2 (b) of the Apple Public License,
41 #ifdef MACH_KERNEL_PRIVATE
44 #include <sys/types.h>
52 #if defined (__cplusplus)
53 #if __cplusplus >= 201103L
59 #define NULL ((void *)0)
63 extern void *memcpy(void *, const void *, size_t);
64 extern int memcmp(const void *, const void *, size_t);
65 extern void *memmove(void *, const void *, size_t);
66 extern void *memset(void *, int, size_t);
67 extern int memset_s(void *, size_t, int, size_t);
69 extern size_t strlen(const char *);
70 extern size_t strnlen(const char *, size_t);
72 /* strcpy() is being deprecated. Please use strlcpy() instead. */
73 extern char *strcpy(char *, const char *) __deprecated
;
74 extern char *strncpy(char *, const char *, size_t);
76 extern size_t strlcat(char *, const char *, size_t);
77 extern size_t strlcpy(char *, const char *, size_t);
79 /* strcat() is being deprecated. Please use strlcat() instead. */
80 extern char *strcat(char *, const char *) __deprecated
;
81 extern char *strncat(char *, const char *, size_t);
83 /* strcmp() is being deprecated. Please use strncmp() instead. */
84 extern int strcmp(const char *, const char *);
85 extern int strncmp(const char *, const char *, size_t);
87 extern int strcasecmp(const char *s1
, const char *s2
);
88 extern int strncasecmp(const char *s1
, const char *s2
, size_t n
);
89 extern char *strnstr(char *s
, const char *find
, size_t slen
);
90 extern char *strchr(const char *s
, int c
);
91 #ifdef XNU_KERNEL_PRIVATE
92 extern char *strrchr(const char *s
, int c
);
94 extern char *STRDUP(const char *, int);
95 extern int strprefix(const char *s1
, const char *s2
);
97 extern int bcmp(const void *, const void *, size_t);
98 extern void bcopy(const void *, void *, size_t);
99 extern void bzero(void *, size_t);
100 extern int timingsafe_bcmp(const void *b1
, const void *b2
, size_t n
);
103 #include <san/memintrinsics.h>
106 #if __has_builtin(__builtin_dynamic_object_size)
107 #define XNU_BOS __builtin_dynamic_object_size
109 #define XNU_BOS __builtin_object_size
113 /* __nochk_ functions for opting out of type 1 bounds checking */
114 __attribute__((always_inline
)) static inline void *
115 __nochk_memcpy(void *dest
, const void *src
, size_t len
)
117 return __builtin___memcpy_chk(dest
, src
, len
, XNU_BOS(dest
, 0));
119 __attribute__((always_inline
)) static inline void *
120 __nochk_memmove(void *dest
, const void *src
, size_t len
)
122 return __builtin___memmove_chk(dest
, src
, len
, XNU_BOS(dest
, 0));
124 __attribute__((always_inline
)) static inline void
125 __nochk_bcopy(const void *src
, void *dest
, size_t len
)
127 __builtin___memmove_chk(dest
, src
, len
, XNU_BOS(dest
, 0));
130 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_13
131 /* older deployment target */
132 #elif defined(KASAN) || (defined (_FORTIFY_SOURCE) && _FORTIFY_SOURCE == 0)
133 /* _FORTIFY_SOURCE disabled */
134 #else /* _chk macros */
136 #ifdef XNU_KERNEL_PRIVATE
137 /* Stricter checking in xnu than kexts. When type is set to 1, __builtin_object_size
138 * returns the size of the closest surrounding sub-object, which would detect copying past
139 * the end of a struct member. */
140 #define BOS_COPY_TYPE 1
142 #define BOS_COPY_TYPE 0
145 #if __has_builtin(__builtin___memcpy_chk)
146 #define memcpy(dest, src, len) __builtin___memcpy_chk(dest, src, len, XNU_BOS(dest, BOS_COPY_TYPE))
149 #if __has_builtin(__builtin___memmove_chk)
150 #define memmove(dest, src, len) __builtin___memmove_chk(dest, src, len, XNU_BOS(dest, BOS_COPY_TYPE))
153 #if __has_builtin(__builtin___strncpy_chk)
154 #define strncpy(dest, src, len) __builtin___strncpy_chk(dest, src, len, XNU_BOS(dest, 1))
157 #if __has_builtin(__builtin___strncat_chk)
158 #define strncat(dest, src, len) __builtin___strncat_chk(dest, src, len, XNU_BOS(dest, 1))
161 #if __has_builtin(__builtin___strlcat_chk)
162 #define strlcat(dest, src, len) __builtin___strlcat_chk(dest, src, len, XNU_BOS(dest, 1))
165 #if __has_builtin(__builtin___strlcpy_chk)
166 #define strlcpy(dest, src, len) __builtin___strlcpy_chk(dest, src, len, XNU_BOS(dest, 1))
169 #if __has_builtin(__builtin___strcpy_chk)
170 #define strcpy(dest, src, len) __builtin___strcpy_chk(dest, src, XNU_BOS(dest, 1))
173 #if __has_builtin(__builtin___strcat_chk)
174 #define strcat(dest, src) __builtin___strcat_chk(dest, src, XNU_BOS(dest, 1))
177 #if __has_builtin(__builtin___memmove_chk)
178 #define bcopy(src, dest, len) __builtin___memmove_chk(dest, src, len, XNU_BOS(dest, BOS_COPY_TYPE))
181 #endif /* _chk macros */
186 #endif /* _STRING_H_ */