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 uint8_t elb_type; 82 #if DEVELOPMENT || DEBUG 83 queue_chain_t elb_global_elm; /* Global list of eventlinks */ 84 #endif 85 }; 86 87 #define IPC_EVENTLINK_BASE_NULL ((struct ipc_eventlink_base *)NULL) 88 #define ipc_eventlink_active(eventlink) waitq_valid(&(eventlink)->el_base->elb_waitq) 89 90 #define eventlink_remote_side(eventlink) ((eventlink) == &((eventlink)->el_base->elb_eventlink[0]) ? \ 91 &((eventlink)->el_base->elb_eventlink[1]) : &((eventlink)->el_base->elb_eventlink[0])) 92 93 #define ipc_eventlink_lock(eventlink) waitq_lock(&(eventlink)->el_base->elb_waitq) 94 #define ipc_eventlink_unlock(eventlink) waitq_unlock(&(eventlink)->el_base->elb_waitq) 95 96 void ipc_eventlink_init(void); 97 98 /* Function declarations */ 99 void 100 ipc_eventlink_init(void); 101 102 struct ipc_eventlink * 103 convert_port_to_eventlink( 104 mach_port_t port); 105 106 void 107 ipc_eventlink_reference( 108 struct ipc_eventlink *ipc_eventlink); 109 110 void 111 ipc_eventlink_deallocate( 112 struct ipc_eventlink *ipc_eventlink); 113 114 uint64_t 115 mach_eventlink_signal_trap( 116 mach_port_name_t port, 117 uint64_t signal_count __unused); 118 119 uint64_t 120 mach_eventlink_wait_until_trap( 121 mach_port_name_t eventlink_port, 122 uint64_t wait_count, 123 mach_eventlink_signal_wait_option_t option, 124 kern_clock_id_t clock_id, 125 uint64_t deadline); 126 127 uint64_t 128 mach_eventlink_signal_wait_until_trap( 129 mach_port_name_t eventlink_port, 130 uint64_t wait_count, 131 uint64_t signal_count __unused, 132 mach_eventlink_signal_wait_option_t option, 133 kern_clock_id_t clock_id, 134 uint64_t deadline); 135 136 #endif /* MACH_KERNEL_PRIVATE */ 137 #endif /* _IPC_IPC_EVENTLINK_H_ */ 138