]>
Commit | Line | Data |
---|---|---|
91447636 | 1 | /* |
39236c6e | 2 | * Copyright (c) 2004-2012 Apple Inc. All rights reserved. |
91447636 | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
91447636 | 5 | * |
2d21ac55 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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
91447636 A |
27 | */ |
28 | ||
29 | #ifndef _I386_LOCKS_H_ | |
30 | #define _I386_LOCKS_H_ | |
31 | ||
32 | #include <sys/appleapiopts.h> | |
33 | #include <kern/kern_types.h> | |
34 | ||
35 | #ifdef MACH_KERNEL_PRIVATE | |
36 | ||
37 | #include <i386/hw_lock_types.h> | |
38 | ||
39 | extern unsigned int LcksOpts; | |
40 | ||
41 | #define enaLkDeb 0x00000001 /* Request debug in default attribute */ | |
42 | #define enaLkStat 0x00000002 /* Request statistic in default attribute */ | |
39236c6e | 43 | #define disLkRWPrio 0x00000004 /* Disable RW lock priority promotion */ |
91447636 | 44 | |
6d2010ae | 45 | #endif /* MACH_KERNEL_PRIVATE */ |
91447636 | 46 | |
6d2010ae | 47 | #if defined(MACH_KERNEL_PRIVATE) |
91447636 | 48 | typedef struct { |
6d2010ae A |
49 | volatile uintptr_t interlock; |
50 | #if MACH_LDEBUG | |
51 | unsigned long lck_spin_pad[9]; /* XXX - usimple_lock_data_t */ | |
52 | #endif | |
91447636 A |
53 | } lck_spin_t; |
54 | ||
55 | #define LCK_SPIN_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */ | |
56 | ||
6d2010ae | 57 | #else /* MACH_KERNEL_PRIVATE */ |
91447636 A |
58 | #ifdef KERNEL_PRIVATE |
59 | typedef struct { | |
b0d623f7 | 60 | unsigned long opaque[10]; |
91447636 | 61 | } lck_spin_t; |
6d2010ae | 62 | #else /* KERNEL_PRIVATE */ |
91447636 A |
63 | typedef struct __lck_spin_t__ lck_spin_t; |
64 | #endif | |
65 | #endif | |
66 | ||
67 | #ifdef MACH_KERNEL_PRIVATE | |
6d2010ae A |
68 | /* The definition of this structure, including the layout of the |
69 | * state bitfield, is tailored to the asm implementation in i386_lock.s | |
70 | */ | |
91447636 A |
71 | typedef struct _lck_mtx_ { |
72 | union { | |
73 | struct { | |
b0d623f7 | 74 | volatile uintptr_t lck_mtxd_owner; |
6d2010ae A |
75 | union { |
76 | struct { | |
77 | volatile uint32_t | |
78 | lck_mtxd_waiters:16, | |
79 | lck_mtxd_pri:8, | |
80 | lck_mtxd_ilocked:1, | |
81 | lck_mtxd_mlocked:1, | |
82 | lck_mtxd_promoted:1, | |
83 | lck_mtxd_spin:1, | |
84 | lck_mtxd_is_ext:1, | |
85 | lck_mtxd_pad3:3; | |
86 | }; | |
87 | uint32_t lck_mtxd_state; | |
88 | }; | |
6d2010ae A |
89 | /* Pad field used as a canary, initialized to ~0 */ |
90 | uint32_t lck_mtxd_pad32; | |
91447636 A |
91 | } lck_mtxd; |
92 | struct { | |
2d21ac55 | 93 | struct _lck_mtx_ext_ *lck_mtxi_ptr; |
6d2010ae | 94 | uint32_t lck_mtxi_tag; |
6d2010ae | 95 | uint32_t lck_mtxi_pad32; |
91447636 A |
96 | } lck_mtxi; |
97 | } lck_mtx_sw; | |
98 | } lck_mtx_t; | |
99 | ||
b0d623f7 | 100 | #define lck_mtx_owner lck_mtx_sw.lck_mtxd.lck_mtxd_owner |
91447636 A |
101 | #define lck_mtx_waiters lck_mtx_sw.lck_mtxd.lck_mtxd_waiters |
102 | #define lck_mtx_pri lck_mtx_sw.lck_mtxd.lck_mtxd_pri | |
b0d623f7 | 103 | #define lck_mtx_promoted lck_mtx_sw.lck_mtxd.lck_mtxd_promoted |
6d2010ae | 104 | #define lck_mtx_is_ext lck_mtx_sw.lck_mtxd.lck_mtxd_is_ext |
91447636 A |
105 | |
106 | #define lck_mtx_tag lck_mtx_sw.lck_mtxi.lck_mtxi_tag | |
107 | #define lck_mtx_ptr lck_mtx_sw.lck_mtxi.lck_mtxi_ptr | |
6d2010ae A |
108 | #define lck_mtx_state lck_mtx_sw.lck_mtxd.lck_mtxd_state |
109 | /* This pattern must subsume the interlocked, mlocked and spin bits */ | |
110 | #define LCK_MTX_TAG_INDIRECT 0x07ff1007 /* lock marked as Indirect */ | |
111 | #define LCK_MTX_TAG_DESTROYED 0x07fe2007 /* lock marked as Destroyed */ | |
91447636 | 112 | |
0c530ab8 A |
113 | /* Adaptive spin before blocking */ |
114 | extern unsigned int MutexSpin; | |
b0d623f7 A |
115 | extern int lck_mtx_lock_spinwait_x86(lck_mtx_t *mutex); |
116 | extern void lck_mtx_lock_wait_x86(lck_mtx_t *mutex); | |
117 | extern void lck_mtx_lock_acquire_x86(lck_mtx_t *mutex); | |
6d2010ae | 118 | extern void lck_mtx_unlock_wakeup_x86(lck_mtx_t *mutex, int prior_lock_state); |
2d21ac55 | 119 | |
b0d623f7 | 120 | extern void lck_mtx_lock_mark_destroyed(lck_mtx_t *mutex); |
b0d623f7 | 121 | extern int lck_mtx_lock_grab_mutex(lck_mtx_t *mutex); |
0c530ab8 | 122 | |
316670eb A |
123 | extern void hw_lock_byte_init(volatile uint8_t *lock_byte); |
124 | extern void hw_lock_byte_lock(volatile uint8_t *lock_byte); | |
125 | extern void hw_lock_byte_unlock(volatile uint8_t *lock_byte); | |
0c530ab8 | 126 | |
91447636 A |
127 | typedef struct { |
128 | unsigned int type; | |
b0d623f7 | 129 | unsigned int pad4; |
91447636 A |
130 | vm_offset_t pc; |
131 | vm_offset_t thread; | |
132 | } lck_mtx_deb_t; | |
133 | ||
134 | #define MUTEX_TAG 0x4d4d | |
135 | ||
136 | typedef struct { | |
137 | unsigned int lck_mtx_stat_data; | |
138 | } lck_mtx_stat_t; | |
139 | ||
140 | typedef struct _lck_mtx_ext_ { | |
141 | lck_mtx_t lck_mtx; | |
142 | struct _lck_grp_ *lck_mtx_grp; | |
143 | unsigned int lck_mtx_attr; | |
b0d623f7 | 144 | unsigned int lck_mtx_pad1; |
91447636 | 145 | lck_mtx_deb_t lck_mtx_deb; |
2d21ac55 | 146 | uint64_t lck_mtx_stat; |
b0d623f7 | 147 | unsigned int lck_mtx_pad2[2]; |
91447636 A |
148 | } lck_mtx_ext_t; |
149 | ||
150 | #define LCK_MTX_ATTR_DEBUG 0x1 | |
0c530ab8 | 151 | #define LCK_MTX_ATTR_DEBUGb 0 |
91447636 | 152 | #define LCK_MTX_ATTR_STAT 0x2 |
0c530ab8 | 153 | #define LCK_MTX_ATTR_STATb 1 |
91447636 | 154 | |
3e170ce0 A |
155 | #define LCK_MTX_EVENT(lck) ((event_t)(((unsigned int*)lck)+(sizeof(lck_mtx_t)-1)/sizeof(unsigned int))) |
156 | ||
6d2010ae A |
157 | #else /* MACH_KERNEL_PRIVATE */ |
158 | #ifdef XNU_KERNEL_PRIVATE | |
159 | typedef struct { | |
160 | unsigned long opaque[2]; | |
161 | } lck_mtx_t; | |
162 | ||
163 | typedef struct { | |
164 | unsigned long opaque[10]; | |
165 | } lck_mtx_ext_t; | |
91447636 A |
166 | #else |
167 | #ifdef KERNEL_PRIVATE | |
168 | typedef struct { | |
6d2010ae | 169 | unsigned long opaque[2]; |
91447636 | 170 | } lck_mtx_t; |
b0d623f7 A |
171 | |
172 | typedef struct { | |
173 | unsigned long opaque[10]; | |
174 | } lck_mtx_ext_t; | |
175 | ||
91447636 | 176 | #else |
b0d623f7 A |
177 | typedef struct __lck_mtx_t__ lck_mtx_t; |
178 | typedef struct __lck_mtx_ext_t__ lck_mtx_ext_t; | |
91447636 A |
179 | #endif |
180 | #endif | |
6d2010ae | 181 | #endif |
91447636 A |
182 | |
183 | #ifdef MACH_KERNEL_PRIVATE | |
2d21ac55 | 184 | #pragma pack(1) /* Make sure the structure stays as we defined it */ |
b0d623f7 | 185 | typedef struct _lck_rw_t_internal_ { |
2d21ac55 | 186 | volatile uint16_t lck_rw_shared_count; /* No. of accepted readers */ |
316670eb | 187 | volatile uint8_t lck_rw_interlock; /* Interlock byte */ |
2d21ac55 A |
188 | volatile uint8_t |
189 | lck_rw_priv_excl:1, /* Writers prioritized if set */ | |
190 | lck_rw_want_upgrade:1, /* Read-to-write upgrade waiting */ | |
191 | lck_rw_want_write:1, /* Writer waiting or locked for write */ | |
192 | lck_r_waiting:1, /* Reader is sleeping on lock */ | |
193 | lck_w_waiting:1, /* Writer is sleeping on lock */ | |
194 | lck_rw_can_sleep:1, /* Can attempts to lock go to sleep? */ | |
b0d623f7 | 195 | lck_rw_padb6:2; /* padding */ |
2d21ac55 | 196 | |
b0d623f7 | 197 | uint32_t lck_rw_tag; /* This can be obsoleted when stats |
2d21ac55 A |
198 | * are in |
199 | */ | |
b0d623f7 | 200 | uint32_t lck_rw_pad8; |
b0d623f7 | 201 | uint32_t lck_rw_pad12; |
91447636 | 202 | } lck_rw_t; |
2d21ac55 | 203 | #pragma pack() |
91447636 | 204 | |
0c530ab8 A |
205 | #define LCK_RW_ATTR_DEBUG 0x1 |
206 | #define LCK_RW_ATTR_DEBUGb 0 | |
207 | #define LCK_RW_ATTR_STAT 0x2 | |
208 | #define LCK_RW_ATTR_STATb 1 | |
209 | #define LCK_RW_ATTR_READ_PRI 0x3 | |
210 | #define LCK_RW_ATTR_READ_PRIb 2 | |
211 | #define LCK_RW_ATTR_DIS_THREAD 0x40000000 | |
212 | #define LCK_RW_ATTR_DIS_THREADb 30 | |
213 | #define LCK_RW_ATTR_DIS_MYLOCK 0x10000000 | |
214 | #define LCK_RW_ATTR_DIS_MYLOCKb 28 | |
215 | ||
91447636 A |
216 | #define LCK_RW_TAG_DESTROYED 0x00002007 /* lock marked as Destroyed */ |
217 | ||
218 | #else | |
219 | #ifdef KERNEL_PRIVATE | |
b0d623f7 | 220 | #pragma pack(1) |
91447636 | 221 | typedef struct { |
b0d623f7 | 222 | uint32_t opaque[3]; |
b0d623f7 | 223 | uint32_t opaque4; |
91447636 | 224 | } lck_rw_t; |
b0d623f7 | 225 | #pragma pack() |
91447636 A |
226 | #else |
227 | typedef struct __lck_rw_t__ lck_rw_t; | |
228 | #endif | |
229 | #endif | |
230 | ||
fe8ab488 A |
231 | #ifdef MACH_KERNEL_PRIVATE |
232 | ||
233 | extern void kernel_preempt_check (void); | |
234 | ||
235 | #endif /* MACH_KERNEL_PRIVATE */ | |
236 | ||
91447636 | 237 | #endif /* _I386_LOCKS_H_ */ |