]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/ipc_eventlink.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_eventlink.h
1 /*
2 * Copyright (c) 2000-2019 Apple Computer, 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 _IPC_IPC_EVENTLINK_H_
30 #define _IPC_IPC_EVENTLINK_H_
31
32 #ifdef MACH_KERNEL_PRIVATE
33
34 #include <mach/std_types.h>
35 #include <mach/port.h>
36 #include <mach/mach_eventlink_types.h>
37 #include <mach_assert.h>
38 #include <mach_debug.h>
39
40 #include <mach/mach_types.h>
41 #include <mach/boolean.h>
42 #include <mach/kern_return.h>
43
44 #include <kern/assert.h>
45 #include <kern/kern_types.h>
46
47 #include <ipc/ipc_types.h>
48 #include <ipc/ipc_object.h>
49 #include <ipc/ipc_port.h>
50 #include <kern/waitq.h>
51 #include <os/refcnt.h>
52
53 __options_decl(ipc_eventlink_option_t, uint64_t, {
54 IPC_EVENTLINK_NONE = 0,
55 IPC_EVENTLINK_NO_WAIT = 0x1,
56 IPC_EVENTLINK_HANDOFF = 0x2,
57 IPC_EVENTLINK_FORCE_WAKEUP = 0x4,
58 });
59
60 __options_decl(ipc_eventlink_type_t, uint8_t, {
61 IPC_EVENTLINK_TYPE_NO_COPYIN = 0x1,
62 IPC_EVENTLINK_TYPE_WITH_COPYIN = 0x2,
63 });
64
65 #define THREAD_ASSOCIATE_WILD ((struct thread *) -1)
66
67 struct ipc_eventlink_base;
68
69 struct ipc_eventlink {
70 ipc_port_t el_port; /* Port for eventlink object */
71 thread_t el_thread; /* Thread associated with eventlink object */
72 struct ipc_eventlink_base *el_base; /* eventlink base struct */
73 uint64_t el_sync_counter; /* Sync counter for wait/ signal */
74 uint64_t el_wait_counter; /* Counter passed in eventlink wait */
75 };
76
77 struct ipc_eventlink_base {
78 struct ipc_eventlink elb_eventlink[2]; /* Eventlink pair */
79 struct waitq elb_waitq; /* waitq */
80 os_refcnt_t elb_ref_count; /* ref count for eventlink */
81 uint32_t elb_active:1,
82 elb_type:8;
83 #if DEVELOPMENT || DEBUG
84 queue_chain_t elb_global_elm; /* Global list of eventlinks */
85 #endif
86 };
87
88 #define IPC_EVENTLINK_BASE_NULL ((struct ipc_eventlink_base *)NULL)
89 #define ipc_eventlink_active(eventlink) ((eventlink)->el_base->elb_active == TRUE)
90
91 #define eventlink_remote_side(eventlink) ((eventlink) == &((eventlink)->el_base->elb_eventlink[0]) ? \
92 &((eventlink)->el_base->elb_eventlink[1]) : &((eventlink)->el_base->elb_eventlink[0]))
93
94 #define ipc_eventlink_lock(eventlink) waitq_lock(&(eventlink)->el_base->elb_waitq)
95 #define ipc_eventlink_unlock(eventlink) waitq_unlock(&(eventlink)->el_base->elb_waitq)
96
97 void ipc_eventlink_init(void);
98
99 /* Function declarations */
100 void
101 ipc_eventlink_init(void);
102
103 struct ipc_eventlink *
104 convert_port_to_eventlink(
105 mach_port_t port);
106
107 void
108 ipc_eventlink_reference(
109 struct ipc_eventlink *ipc_eventlink);
110
111 void
112 ipc_eventlink_deallocate(
113 struct ipc_eventlink *ipc_eventlink);
114
115 void
116 ipc_eventlink_notify(
117 mach_msg_header_t *msg);
118
119 uint64_t
120 mach_eventlink_signal_trap(
121 mach_port_name_t port,
122 uint64_t signal_count __unused);
123
124 uint64_t
125 mach_eventlink_wait_until_trap(
126 mach_port_name_t eventlink_port,
127 uint64_t wait_count,
128 mach_eventlink_signal_wait_option_t option,
129 kern_clock_id_t clock_id,
130 uint64_t deadline);
131
132 uint64_t
133 mach_eventlink_signal_wait_until_trap(
134 mach_port_name_t eventlink_port,
135 uint64_t wait_count,
136 uint64_t signal_count __unused,
137 mach_eventlink_signal_wait_option_t option,
138 kern_clock_id_t clock_id,
139 uint64_t deadline);
140
141 #endif /* MACH_KERNEL_PRIVATE */
142 #endif /* _IPC_IPC_EVENTLINK_H_ */