]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/misc_protos.h
xnu-6153.81.5.tar.gz
[apple/xnu.git] / osfmk / kern / misc_protos.h
index 74a0a7d631750e49120a7c0a81c3ead7876408e3..21742d6649ed3759bf2f34b158c8e77909a38c1f 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2000-2016 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,
@@ -22,7 +22,7 @@
  * 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@
  */
 /*
@@ -35,8 +35,8 @@
  * Version 2.0.
  */
 
-#ifndef        _MISC_PROTOS_H_
-#define        _MISC_PROTOS_H_
+#ifndef _MISC_PROTOS_H_
+#define _MISC_PROTOS_H_
 
 #include <stdarg.h>
 #include <string.h>
 #include <libkern/copyio.h>
 
 #ifndef MIN
-#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MIN(a, b) (((a)<(b))?(a):(b))
 #endif /* MIN */
 #ifndef MAX
-#define MAX(a,b) (((a)>(b))?(a):(b))
+#define MAX(a, b) (((a)>(b))?(a):(b))
 #endif  /* MAX */
 
 /* Set a bit in a bit array */
 extern void setbit(
-       int             which,
-       int             *bitmap);
+       int             which,
+       int             *bitmap);
 
 /* Clear a bit in a bit array */
 extern void clrbit(
-       int             which,
-       int             *bitmap);
+       int             which,
+       int             *bitmap);
 
 /* Find the first set bit in a bit array */
 extern int ffsbit(
-       int             *bitmap);
+       int             *bitmap);
 extern int ffs(
-       unsigned int    mask);
+       unsigned int    mask);
 extern int ffsll(
        unsigned long long mask);
 
 /* Find the last set bit in a bit array */
 extern int fls(
-       unsigned int    mask);
+       unsigned int    mask);
 extern int flsll(
        unsigned long long mask);
 
@@ -83,20 +83,47 @@ extern int flsll(
  * Test if indicated bit is set in bit string.
  */
 extern int testbit(
-       int             which,
-       int             *bitmap);
+       int             which,
+       int             *bitmap);
 
-/* Move an aligned 32 or 64-bit word from user space to kernel space
+/*
+ * Move an aligned 32 or 64-bit word from user space to kernel space
  * using a single read instruction
+ */
+extern int copyin_atomic32(
+       const user_addr_t   user_addr,
+       uint32_t            *kernel_addr);
+
+extern int copyin_atomic64(
+       const user_addr_t   user_addr,
+       uint64_t            *kernel_addr);
+
+/*
+ * Does an atomic copyin at the specified user_address and compares
+ * it to the passed in value, and if it matches, waits.
+ *
+ * This is used to implement adaptive spinning for userspace synchronization
  *
- * when reading a 32-bit word, the value is 0-extended into the kernel space
- * 64-bit buffer passed as `kernel_addr`
- * (think `*kernel_addr = *(uint32_t *)user_addr`)
+ * Returns:
+ * 0:       the value mached, and it paused efficiently for the platform
+ * ESTALE:  the value didn't match, and it returned immediately
+ * other:   the copyin failed (EFAULT, EINVAL, ...)
  */
-extern int copyin_word(
+extern int copyin_atomic32_wait_if_equals(
        const user_addr_t   user_addr,
-       uint64_t            *kernel_addr,
-       vm_size_t           nbytes);
+       uint32_t            value);
+
+/*
+ * Move a 32 or 64-bit word from kernel space to user space
+ * using a single write instruction
+ */
+extern int copyout_atomic32(
+       uint32_t            u32,
+       user_addr_t         user_addr);
+
+extern int copyout_atomic64(
+       uint64_t            u64,
+       user_addr_t         user_addr);
 
 /* Move a NUL-terminated string from a user space to kernel space */
 extern int copyinstr(
@@ -121,15 +148,12 @@ extern int copyoutmsg(
 extern void inval_copy_windows(thread_t);
 extern void copy_window_fault(thread_t, vm_map_t, int);
 
-extern int copyin_validate(const user_addr_t, uintptr_t, vm_size_t);
-extern int copyout_validate(uintptr_t, const user_addr_t, vm_size_t);
+extern int sscanf(const char *input, const char *fmt, ...) __scanflike(2, 3);
 
-extern int sscanf(const char *input, const char *fmt, ...) __scanflike(2,3);
-
-/* sprintf() is being deprecated. Please use snprintf() instead. */ 
+/* sprintf() is being deprecated. Please use snprintf() instead. */
 extern integer_t sprintf(char *buf, const char *fmt, ...) __deprecated;
 
-extern int printf(const char *format, ...) __printflike(1,2);
+extern int printf(const char *format, ...) __printflike(1, 2);
 extern int vprintf(const char *format, va_list ap);
 
 #if KERNEL_PRIVATE
@@ -144,46 +168,47 @@ int     _consume_printf_args(int, ...);
 #endif
 #endif
 
-extern int paniclog_append_noflush(const char *format, ...) __printflike(1,2);
+extern int paniclog_append_noflush(const char *format, ...) __printflike(1, 2);
 
-extern int kdb_printf(const char *format, ...) __printflike(1,2);
+extern int kdb_printf(const char *format, ...) __printflike(1, 2);
 
-extern int kdb_log(const char *format, ...) __printflike(1,2);
+extern int kdb_log(const char *format, ...) __printflike(1, 2);
 
-extern int kdb_printf_unbuffered(const char *format, ...) __printflike(1,2);
+extern int kdb_printf_unbuffered(const char *format, ...) __printflike(1, 2);
 
 extern void printf_init(void);
 
-extern int snprintf(char *, size_t, const char *, ...) __printflike(3,4);
+extern int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
+extern int scnprintf(char *, size_t, const char *, ...) __printflike(3, 4);
 
 extern void log(int level, char *fmt, ...);
 
-void 
+void
 _doprnt(
-       const char      *fmt,
-       va_list                 *argp,
-       void                    (*putc)(char),
-       int                     radix);
+       const char      *fmt,
+       va_list                 *argp,
+       void                    (*putc)(char),
+       int                     radix);
 
 void
 _doprnt_log(
-       const char      *fmt,
-       va_list                 *argp,
-       void                    (*putc)(char),
-       int                     radix);
+       const char      *fmt,
+       va_list                 *argp,
+       void                    (*putc)(char),
+       int                     radix);
 
 int
 __doprnt(
-       const char      *fmt,
-       va_list                 argp,
-       void                    (*putc)(int, void *),
+       const char      *fmt,
+       va_list                 argp,
+       void                    (*putc)(int, void *),
        void                    *arg,
-       int                     radix,
-       int                     is_log);
+       int                     radix,
+       int                     is_log);
 
 extern void safe_gets(
-       char    *str,
-       int     maxlen);
+       char    *str,
+       int     maxlen);
 
 extern void cnputcusr(char);
 
@@ -214,28 +239,28 @@ extern int cngetc(void);
 extern int cnmaygetc(void);
 
 extern int _setjmp(
-       jmp_buf_t       *jmp_buf);
+       jmp_buf_t       *jmp_buf);
 
 extern int _longjmp(
-       jmp_buf_t       *jmp_buf,
-       int             value);
+       jmp_buf_t       *jmp_buf,
+       int             value);
 
 extern void bootstrap_create(void);
 
-#if    DIPC
-extern boolean_t       no_bootstrap_task(void);
-extern ipc_port_t      get_root_master_device_port(void);
-#endif /* DIPC */
+#if     DIPC
+extern boolean_t        no_bootstrap_task(void);
+extern ipc_port_t       get_root_master_device_port(void);
+#endif  /* DIPC */
 
-extern kern_return_t   kernel_set_special_port(
-               host_priv_t     host_priv,
-               int             which,
-               ipc_port_t      port);
+extern kern_return_t    kernel_set_special_port(
+       host_priv_t     host_priv,
+       int             which,
+       ipc_port_t      port);
 
-extern kern_return_t   kernel_get_special_port(
-               host_priv_t     host_priv,
-               int             which,
-               ipc_port_t      *portp);
+extern kern_return_t    kernel_get_special_port(
+       host_priv_t     host_priv,
+       int             which,
+       ipc_port_t      *portp);
 
 user_addr_t get_useraddr(void);
 
@@ -244,4 +269,4 @@ struct kmod_info_t;
 
 extern uint64_t early_random(void);
 
-#endif /* _MISC_PROTOS_H_ */
+#endif  /* _MISC_PROTOS_H_ */