* Copyright (c) 2000-2012 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
- *
+ *
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*-
#include <sys/appleapiopts.h>
#include <stdint.h>
-#include <stdarg.h> /* for platform-specific va_list */
+#include <stdarg.h> /* for platform-specific va_list */
#include <string.h>
#include <machine/limits.h>
#include <sys/cdefs.h>
#ifdef __APPLE_API_OBSOLETE
/* BCD conversions. */
-extern u_char const bcd2bin_data[];
-extern u_char const bin2bcd_data[];
+extern u_char const bcd2bin_data[];
+extern u_char const bin2bcd_data[];
-#define bcd2bin(bcd) (bcd2bin_data[bcd])
-#define bin2bcd(bin) (bin2bcd_data[bin])
+#define bcd2bin(bcd) (bcd2bin_data[bcd])
+#define bin2bcd(bin) (bin2bcd_data[bin])
#endif /* __APPLE_API_OBSOLETE */
#ifdef __APPLE_API_PRIVATE
-extern char const hex2ascii_data[];
+extern char const hex2ascii_data[];
-#define hex2ascii(hex) (hex2ascii_data[hex])
+#define hex2ascii(hex) (hex2ascii_data[hex])
#endif /* __APPLE_API_PRIVATE */
__BEGIN_DECLS
static inline int
imax(int a, int b)
{
- return (a > b ? a : b);
+ return a > b ? a : b;
}
static inline int
imin(int a, int b)
{
- return (a < b ? a : b);
+ return a < b ? a : b;
}
static inline long
lmax(long a, long b)
{
- return (a > b ? a : b);
+ return a > b ? a : b;
}
static inline long
lmin(long a, long b)
{
- return (a < b ? a : b);
+ return a < b ? a : b;
}
static inline u_int
max(u_int a, u_int b)
{
- return (a > b ? a : b);
+ return a > b ? a : b;
}
static inline u_int
min(u_int a, u_int b)
{
- return (a < b ? a : b);
+ return a < b ? a : b;
}
static inline u_int32_t
ulmax(u_int32_t a, u_int32_t b)
{
- return (a > b ? a : b);
+ return a > b ? a : b;
}
static inline u_int32_t
ulmin(u_int32_t a, u_int32_t b)
{
- return (a < b ? a : b);
+ return a < b ? a : b;
}
/* Prototypes for non-quad routines. */
-extern int ffs(int);
-extern int ffsll(unsigned long long);
-extern int fls(int);
-extern int flsll(unsigned long long);
-extern u_int32_t random(void);
-extern int scanc(u_int, u_char *, const u_char *, int);
-extern int skpc(int, int, char *);
-extern long strtol(const char*, char **, int);
-extern u_long strtoul(const char *, char **, int);
-extern quad_t strtoq(const char *, char **, int);
+extern int ffs(unsigned int);
+extern int ffsll(unsigned long long);
+extern int fls(unsigned int);
+extern int flsll(unsigned long long);
+extern u_int32_t random(void);
+extern int scanc(u_int, u_char *, const u_char *, int);
+extern int skpc(int, int, char *);
+extern long strtol(const char*, char **, int);
+extern u_long strtoul(const char *, char **, int);
+extern quad_t strtoq(const char *, char **, int);
extern u_quad_t strtouq(const char *, char **, int);
-extern char *strsep(char **, const char *);
-extern void *memchr(const void *, int, size_t);
-extern void url_decode(char *str);
+extern char *strsep(char **, const char *);
+extern void *memchr(const void *, int, size_t);
+extern void url_decode(char *str);
-int snprintf(char *, size_t, const char *, ...) __printflike(3,4);
+/*
+ * NOTE: snprintf() returns the full length of the formatted string even if it
+ * couldn't fit in the supplied buffer.
+ * Use scnprintf() if you need the actual number of bytes (minus the \0)
+ */
+int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
+int scnprintf(char *, size_t, const char *, ...) __printflike(3, 4);
/* sprintf() is being deprecated. Please use snprintf() instead. */
-int sprintf(char *bufp, const char *, ...) __deprecated __printflike(2,3);
-int sscanf(const char *, char const *, ...) __scanflike(2,3);
-int printf(const char *, ...) __printflike(1,2);
+int sprintf(char *bufp, const char *, ...) __deprecated __printflike(2, 3);
+int sscanf(const char *, char const *, ...) __scanflike(2, 3);
+int printf(const char *, ...) __printflike(1, 2);
#if KERNEL_PRIVATE
-int _consume_printf_args(int, ...);
+int _consume_printf_args(int, ...);
#endif
#if CONFIG_NO_PRINTF_STRINGS
#endif
#endif
-uint16_t crc16(uint16_t crc, const void *bufp, size_t len);
-uint32_t crc32(uint32_t crc, const void *bufp, size_t len);
+uint16_t crc16(uint16_t crc, const void *bufp, size_t len);
+uint32_t crc32(uint32_t crc, const void *bufp, size_t len);
#if XNU_KERNEL_PRIVATE
#if KASAN
uint16_t __nosan_crc16(uint16_t crc, const void *bufp, size_t len);
#else
static inline uint16_t
-__nosan_crc16(uint16_t crc, const void *bufp, size_t len) { return crc16(crc, bufp, len); }
+__nosan_crc16(uint16_t crc, const void *bufp, size_t len)
+{
+ return crc16(crc, bufp, len);
+}
#endif
#endif
-int copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done);
-int copyinstr(const user_addr_t uaddr, void *kaddr, size_t len, size_t *done);
-int copyoutstr(const void *kaddr, user_addr_t udaddr, size_t len, size_t *done);
+int copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done);
+int copyinstr(const user_addr_t uaddr, void *kaddr, size_t len, size_t *done) OS_WARN_RESULT;
+int copyoutstr(const void *kaddr, user_addr_t udaddr, size_t len, size_t *done);
#if XNU_KERNEL_PRIVATE
-extern int copyin_word(const user_addr_t user_addr, uint64_t *kernel_addr, vm_size_t nbytes);
+int copyin_atomic32(const user_addr_t user_addr, uint32_t *u32);
+int copyin_atomic32_wait_if_equals(const user_addr_t user_addr, uint32_t u32);
+int copyin_atomic64(const user_addr_t user_addr, uint64_t *u64);
+int copyout_atomic32(uint32_t u32, user_addr_t user_addr);
+int copyout_atomic64(uint64_t u64, user_addr_t user_addr);
+int copyoutstr_prevalidate(const void *kaddr, user_addr_t uaddr, size_t len);
#endif
int vsscanf(const char *, char const *, va_list);
-extern int vprintf(const char *, va_list) __printflike(1,0);
-extern int vsnprintf(char *, size_t, const char *, va_list) __printflike(3,0);
+extern int vprintf(const char *, va_list) __printflike(1, 0);
+extern int vsnprintf(char *, size_t, const char *, va_list) __printflike(3, 0);
+extern int vscnprintf(char *, size_t, const char *, va_list) __printflike(3, 0);
#if XNU_KERNEL_PRIVATE
-extern int vprintf_log_locked(const char *, va_list) __printflike(1,0);
-extern void osobject_retain(void * object);
-extern void osobject_release(void * object);
+extern int vprintf_log_locked(const char *, va_list, bool addcr) __printflike(1, 0);
+extern void osobject_retain(void * object);
+extern void osobject_release(void * object);
#endif
/* vsprintf() is being deprecated. Please use vsnprintf() instead. */
-extern int vsprintf(char *bufp, const char *, va_list) __deprecated __printflike(2,0);
+extern int vsprintf(char *bufp, const char *, va_list) __deprecated __printflike(2, 0);
#ifdef KERNEL_PRIVATE
#ifdef __arm__