]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/ulock.h
xnu-3789.41.3.tar.gz
[apple/xnu.git] / bsd / sys / ulock.h
CommitLineData
39037602
A
1/*
2 * Copyright (c) 2015 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _SYS_ULOCK_H
30#define _SYS_ULOCK_H
31
32__BEGIN_DECLS
33
34#if PRIVATE
35
36#ifdef XNU_KERNEL_PRIVATE
37extern mach_port_name_t ipc_entry_name_mask(mach_port_name_t name);
38
39static __inline mach_port_name_t
40ulock_owner_value_to_port_name(uint32_t uval)
41{
42 /*
43 * userland uses the least significant bits for flags as these are
44 * never used in the mach port name, and are generally always set by
45 * the ipc_entry code in the kernel. Here we reconstruct a mach port
46 * name that we can use in the kernel.
47 */
48 return ipc_entry_name_mask((mach_port_name_t)uval);
49}
50#else
51static __inline mach_port_name_t
52ulock_owner_value_to_port_name(uint32_t uval)
53{
54 return uval | 0x3;
55}
56#endif
57
58#ifndef KERNEL
59
60extern int __ulock_wait(uint32_t operation, void *addr, uint64_t value,
61 uint32_t timeout); /* timeout is specified in microseconds */
62extern int __ulock_wake(uint32_t operation, void *addr, uint64_t wake_value);
63
64#endif /* !KERNEL */
65
66/*
67 * operation bits [7, 0] contain the operation code
68 */
69#define UL_COMPARE_AND_WAIT 1
70#define UL_UNFAIR_LOCK 2
71/* obsolete names */
72#define UL_OSSPINLOCK UL_COMPARE_AND_WAIT
73#define UL_HANDOFFLOCK UL_UNFAIR_LOCK
74/* These operation code are only implemented in (DEVELOPMENT || DEBUG) kernels */
75#define UL_DEBUG_SIMULATE_COPYIN_FAULT 253
76#define UL_DEBUG_HASH_DUMP_ALL 254
77#define UL_DEBUG_HASH_DUMP_PID 255
78
79/*
80 * operation bits [15, 8] contain the flags for __ulock_wake
81 */
82#define ULF_WAKE_ALL 0x00000100
83#define ULF_WAKE_THREAD 0x00000200
84
85/*
86 * operation bits [23, 16] contain the flags for __ulock_wait
87 */
88/* The waiter is contending on this lock for synchronization around global data.
89 * This causes the workqueue subsystem to not create new threads to offset for
90 * waiters on this lock.
91 */
92#define ULF_WAIT_WORKQ_DATA_CONTENTION 0x00010000
93
94/*
95 * operation bits [31, 24] contain the generic flags
96 */
97#define ULF_NO_ERRNO 0x01000000
98
99/*
100 * masks
101 */
102#define UL_OPCODE_MASK 0x000000FF
103#define UL_FLAGS_MASK 0xFFFFFF00
104#define ULF_GENERIC_MASK 0xFFFF0000
105
106#define ULF_WAIT_MASK (ULF_NO_ERRNO | \
107 ULF_WAIT_WORKQ_DATA_CONTENTION)
108
109#define ULF_WAKE_MASK (ULF_WAKE_ALL | \
110 ULF_WAKE_THREAD | \
111 ULF_NO_ERRNO)
112
113#endif /* PRIVATE */
114
115__END_DECLS
116
117#endif