X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/36401178fd6817c043cc00b0c00c7f723e58efae..d190cdc3f5544636abb56dc1874be391d3e1b148:/bsd/libkern/libkern.h?ds=sidebyside diff --git a/bsd/libkern/libkern.h b/bsd/libkern/libkern.h index 81b719c2e..4e6606007 100644 --- a/bsd/libkern/libkern.h +++ b/bsd/libkern/libkern.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2012 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -73,10 +73,12 @@ #include #include /* for platform-specific va_list */ #include +#include #include #include #include + #ifdef __APPLE_API_OBSOLETE /* BCD conversions. */ extern u_char const bcd2bin_data[]; @@ -123,13 +125,13 @@ min(u_int a, u_int b) { return (a < b ? a : b); } -static inline u_long -ulmax(u_long a, u_long b) +static inline u_int32_t +ulmax(u_int32_t a, u_int32_t b) { return (a > b ? a : b); } -static inline u_long -ulmin(u_long a, u_long b) +static inline u_int32_t +ulmin(u_int32_t a, u_int32_t b) { return (a < b ? a : b); } @@ -138,16 +140,15 @@ ulmin(u_long a, u_long b) /* Prototypes for non-quad routines. */ extern int ffs(int); -extern int locc(int, char *, u_int); -extern u_long random(void); -extern char *rindex(const char *, int); +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 **stringp, const char *delim); +extern char *strsep(char **, const char *); +extern void *memchr(const void *, int, size_t); int snprintf(char *, size_t, const char *, ...) __printflike(3,4); @@ -156,10 +157,19 @@ int sprintf(char *bufp, const char *, ...) __deprecated; int sscanf(const char *, char const *, ...) __scanflike(2,3); int printf(const char *, ...) __printflike(1,2); +#if KERNEL_PRIVATE +int _consume_printf_args(int, ...); +#endif + #if CONFIG_NO_PRINTF_STRINGS +#if KERNEL_PRIVATE +#define printf(x, ...) _consume_printf_args( 0, ## __VA_ARGS__ ) +#else #define printf(x, ...) do {} while (0) #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); int copystr(const void *kfaddr, void *kdaddr, size_t len, size_t *done); @@ -167,63 +177,42 @@ 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 copyin(const user_addr_t uaddr, void *kaddr, size_t len); int copyout(const void *kaddr, user_addr_t udaddr, size_t len); +#if XNU_KERNEL_PRIVATE +extern int copyin_word(const user_addr_t user_addr, uint64_t *kernel_addr, vm_size_t nbytes); +#endif int vsscanf(const char *, char const *, va_list); extern int vprintf(const char *, va_list); extern int vsnprintf(char *, size_t, const char *, va_list); +#if XNU_KERNEL_PRIVATE +extern int vprintf_log_locked(const char *, va_list); +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; +#ifdef KERNEL_PRIVATE +extern void invalidate_icache(vm_offset_t, unsigned, int); +extern void flush_dcache(vm_offset_t, unsigned, int); +#else extern void invalidate_icache(vm_offset_t, unsigned, int); extern void flush_dcache(vm_offset_t, unsigned, int); +#endif extern void invalidate_icache64(addr64_t, unsigned, int); extern void flush_dcache64(addr64_t, unsigned, int); -/* - * assembly versions of clz... ideally we would just call - * __builtin_clz(num), unfortunately this one is ill defined - * by gcc for num=0 - */ -static __inline__ unsigned int +static inline int clz(unsigned int num) { -#if __ppc__ - unsigned int result; - __asm__ volatile( - "cntlzw %0, %1" - : "=r" (result) - : "r" (num) - ); - return result; - -#elif __i386__ - unsigned int result; - __asm__ volatile( - "bsrl %1, %0\n\t" - "cmovel %2, %0" - : "=r" (result) - : "rm" (num), "r" (63) - ); - return 31 ^ result; - -#elif __arm__ && !__thumb__ && defined(_ARM_ARCH_5) - unsigned int result; - __asm__ volatile( - "clz %0, %1" - : "=r" (result) - : "r" (num) - ); - - return result; -#else - return num?__builtin_clz(num):__builtin_clz(0); -#endif + // On Intel, clz(0) is undefined + return num ? __builtin_clz(num) : sizeof(num) * CHAR_BIT; } - __END_DECLS #endif /* _LIBKERN_LIBKERN_H_ */