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