]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/ulock.h
xnu-7195.81.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@
0a7de745 5 *
39037602
A
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.
0a7de745 14 *
39037602
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
39037602
A
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.
0a7de745 25 *
39037602
A
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _SYS_ULOCK_H
30#define _SYS_ULOCK_H
31
cb323159
A
32#include <mach/mach_port.h>
33#include <sys/cdefs.h>
34#include <stdint.h>
35
39037602
A
36__BEGIN_DECLS
37
38#if PRIVATE
39
40#ifdef XNU_KERNEL_PRIVATE
41extern mach_port_name_t ipc_entry_name_mask(mach_port_name_t name);
42
43static __inline mach_port_name_t
44ulock_owner_value_to_port_name(uint32_t uval)
45{
46 /*
47 * userland uses the least significant bits for flags as these are
48 * never used in the mach port name, and are generally always set by
49 * the ipc_entry code in the kernel. Here we reconstruct a mach port
50 * name that we can use in the kernel.
51 */
52 return ipc_entry_name_mask((mach_port_name_t)uval);
53}
54#else
55static __inline mach_port_name_t
56ulock_owner_value_to_port_name(uint32_t uval)
57{
58 return uval | 0x3;
59}
60#endif
61
62#ifndef KERNEL
63
64extern int __ulock_wait(uint32_t operation, void *addr, uint64_t value,
0a7de745 65 uint32_t timeout); /* timeout is specified in microseconds */
f427ee49
A
66extern int __ulock_wait2(uint32_t operation, void *addr, uint64_t value,
67 uint64_t timeout, uint64_t value2);
39037602
A
68extern int __ulock_wake(uint32_t operation, void *addr, uint64_t wake_value);
69
70#endif /* !KERNEL */
71
72/*
cb323159
A
73 * operation bits [7, 0] contain the operation code.
74 *
75 * NOTE: make sure to add logic for handling any new
76 * types to kdp_ulock_find_owner()
39037602 77 */
cb323159
A
78#define UL_COMPARE_AND_WAIT 1
79#define UL_UNFAIR_LOCK 2
80#define UL_COMPARE_AND_WAIT_SHARED 3
81#define UL_UNFAIR_LOCK64_SHARED 4
82#define UL_COMPARE_AND_WAIT64 5
83#define UL_COMPARE_AND_WAIT64_SHARED 6
39037602 84/* obsolete names */
cb323159
A
85#define UL_OSSPINLOCK UL_COMPARE_AND_WAIT
86#define UL_HANDOFFLOCK UL_UNFAIR_LOCK
39037602 87/* These operation code are only implemented in (DEVELOPMENT || DEBUG) kernels */
0a7de745 88#define UL_DEBUG_SIMULATE_COPYIN_FAULT 253
cb323159
A
89#define UL_DEBUG_HASH_DUMP_ALL 254
90#define UL_DEBUG_HASH_DUMP_PID 255
39037602
A
91
92/*
93 * operation bits [15, 8] contain the flags for __ulock_wake
94 */
cb323159
A
95#define ULF_WAKE_ALL 0x00000100
96#define ULF_WAKE_THREAD 0x00000200
f427ee49 97#define ULF_WAKE_ALLOW_NON_OWNER 0x00000400
39037602
A
98
99/*
100 * operation bits [23, 16] contain the flags for __ulock_wait
d9a64523
A
101 *
102 * @const ULF_WAIT_WORKQ_DATA_CONTENTION
103 * The waiter is contending on this lock for synchronization around global data.
39037602
A
104 * This causes the workqueue subsystem to not create new threads to offset for
105 * waiters on this lock.
d9a64523
A
106 *
107 * @const ULF_WAIT_CANCEL_POINT
108 * This wait is a cancelation point
cb323159
A
109 *
110 * @const ULF_WAIT_ADAPTIVE_SPIN
111 * Use adaptive spinning when the thread that currently holds the unfair lock
112 * is on core.
39037602 113 */
d9a64523
A
114#define ULF_WAIT_WORKQ_DATA_CONTENTION 0x00010000
115#define ULF_WAIT_CANCEL_POINT 0x00020000
cb323159 116#define ULF_WAIT_ADAPTIVE_SPIN 0x00040000
39037602
A
117
118/*
119 * operation bits [31, 24] contain the generic flags
120 */
cb323159 121#define ULF_NO_ERRNO 0x01000000
39037602
A
122
123/*
124 * masks
125 */
0a7de745
A
126#define UL_OPCODE_MASK 0x000000FF
127#define UL_FLAGS_MASK 0xFFFFFF00
128#define ULF_GENERIC_MASK 0xFFFF0000
39037602 129
0a7de745 130#define ULF_WAIT_MASK (ULF_NO_ERRNO | \
cb323159
A
131 ULF_WAIT_WORKQ_DATA_CONTENTION | \
132 ULF_WAIT_CANCEL_POINT | ULF_WAIT_ADAPTIVE_SPIN)
39037602 133
cb323159
A
134#define ULF_WAKE_MASK (ULF_NO_ERRNO | \
135 ULF_WAKE_ALL | \
f427ee49
A
136 ULF_WAKE_THREAD | \
137 ULF_WAKE_ALLOW_NON_OWNER)
39037602
A
138
139#endif /* PRIVATE */
140
141__END_DECLS
142
143#endif