2 * Copyright (c) 2000-2019 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _IPC_IPC_EVENTLINK_H_
30 #define _IPC_IPC_EVENTLINK_H_
32 #ifdef MACH_KERNEL_PRIVATE
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>
40 #include <mach/mach_types.h>
41 #include <mach/boolean.h>
42 #include <mach/kern_return.h>
44 #include <kern/assert.h>
45 #include <kern/kern_types.h>
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>
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,
60 __options_decl(ipc_eventlink_type_t
, uint8_t, {
61 IPC_EVENTLINK_TYPE_NO_COPYIN
= 0x1,
62 IPC_EVENTLINK_TYPE_WITH_COPYIN
= 0x2,
65 #define THREAD_ASSOCIATE_WILD ((struct thread *) -1)
67 struct ipc_eventlink_base
;
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 */
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,
83 #if DEVELOPMENT || DEBUG
84 queue_chain_t elb_global_elm
; /* Global list of eventlinks */
88 #define IPC_EVENTLINK_BASE_NULL ((struct ipc_eventlink_base *)NULL)
89 #define ipc_eventlink_active(eventlink) ((eventlink)->el_base->elb_active == TRUE)
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]))
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)
97 void ipc_eventlink_init(void);
99 /* Function declarations */
101 ipc_eventlink_init(void);
103 struct ipc_eventlink
*
104 convert_port_to_eventlink(
108 ipc_eventlink_reference(
109 struct ipc_eventlink
*ipc_eventlink
);
112 ipc_eventlink_deallocate(
113 struct ipc_eventlink
*ipc_eventlink
);
116 ipc_eventlink_notify(
117 mach_msg_header_t
*msg
);
120 mach_eventlink_signal_trap(
121 mach_port_name_t port
,
122 uint64_t signal_count __unused
);
125 mach_eventlink_wait_until_trap(
126 mach_port_name_t eventlink_port
,
128 mach_eventlink_signal_wait_option_t option
,
129 kern_clock_id_t clock_id
,
133 mach_eventlink_signal_wait_until_trap(
134 mach_port_name_t eventlink_port
,
136 uint64_t signal_count __unused
,
137 mach_eventlink_signal_wait_option_t option
,
138 kern_clock_id_t clock_id
,
141 #endif /* MACH_KERNEL_PRIVATE */
142 #endif /* _IPC_IPC_EVENTLINK_H_ */