]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/libkern/libkern.h
xnu-1228.3.13.tar.gz
[apple/xnu.git] / bsd / libkern / libkern.h
index 6ab2b920195ea4a1a37457593ecc0f363680c829..81b719c2eb58048bb7bd32d95b39d3fc976f8917 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  *
  *     @(#)libkern.h   8.1 (Berkeley) 6/10/93
  */
+/*
+ * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
+ * support for mandatory and extensible security protections.  This notice
+ * is included in support of clause 2.2 (b) of the Apple Public License,
+ * Version 2.0.
+ */
 
 #ifndef _LIBKERN_LIBKERN_H_
 #define _LIBKERN_LIBKERN_H_
 
 #include <sys/appleapiopts.h>
 #include <stdint.h>
+#include <stdarg.h>    /* for platform-specific va_list */
 #include <string.h>
 #include <sys/cdefs.h>
 #include <sys/types.h>
@@ -127,6 +134,8 @@ ulmin(u_long a, u_long b)
        return (a < b ? a : b);
 }
 
+
+
 /* Prototypes for non-quad routines. */
 extern int     ffs(int);
 extern int     locc(int, char *, u_int);
@@ -138,11 +147,18 @@ 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);
+
+int    snprintf(char *, size_t, const char *, ...) __printflike(3,4);
 
-int    snprintf(char *, size_t, const char *, ...);
-int    sprintf(char *bufp, const char *, ...);
-int    sscanf(const char *, char const *, ...);
-void printf(const char *, ...);
+/* sprintf() is being deprecated. Please use snprintf() instead. */
+int    sprintf(char *bufp, const char *, ...) __deprecated;
+int    sscanf(const char *, char const *, ...) __scanflike(2,3);
+int    printf(const char *, ...) __printflike(1,2);
+
+#if CONFIG_NO_PRINTF_STRINGS
+#define printf(x, ...)  do {} while (0)
+#endif
 
 uint32_t       crc32(uint32_t crc, const void *bufp, size_t len);
 
@@ -152,15 +168,62 @@ 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);
 
-int vsscanf(const char *, char const *, __darwin_va_list);
-extern int     vsnprintf(char *, size_t, const char *, __darwin_va_list);
-extern int     vsprintf(char *bufp, const char *, __darwin_va_list); 
+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);
+
+/* vsprintf() is being deprecated. Please use vsnprintf() instead. */
+extern int     vsprintf(char *bufp, const char *, va_list) __deprecated;
 
 extern void invalidate_icache(vm_offset_t, unsigned, int);
 extern void flush_dcache(vm_offset_t, unsigned, int);
 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
+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
+}
+
+
 __END_DECLS
 
 #endif /* _LIBKERN_LIBKERN_H_ */