]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
3 | * | |
8f6c56a5 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
8f6c56a5 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. | |
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 | |
8ad349bb | 24 | * limitations under the License. |
8f6c56a5 A |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
1c79356b A |
27 | */ |
28 | /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */ | |
91447636 A |
29 | /*! |
30 | @header kern_event.h | |
31 | This header defines in-kernel functions for generating kernel events as well | |
32 | as functions for receiving kernel events using a kernel event socket. | |
33 | */ | |
1c79356b A |
34 | |
35 | #ifndef SYS_KERN_EVENT_H | |
36 | #define SYS_KERN_EVENT_H | |
37 | ||
9bccf70c | 38 | #include <sys/appleapiopts.h> |
1c79356b | 39 | #include <sys/ioccom.h> |
9bccf70c | 40 | #include <sys/sys_domain.h> |
1c79356b A |
41 | |
42 | #define KEVENTS_ON 1 | |
43 | #define KEV_SNDSPACE (4 * 1024) | |
44 | #define KEV_RECVSPACE (8 * 1024) | |
45 | ||
46 | #define KEV_ANY_VENDOR 0 | |
47 | #define KEV_ANY_CLASS 0 | |
48 | #define KEV_ANY_SUBCLASS 0 | |
49 | ||
50 | /* | |
51 | * Vendor Code | |
52 | */ | |
53 | ||
91447636 A |
54 | /*! |
55 | @defined KEV_VENDOR_APPLE | |
56 | @discussion Apple generated kernel events use the hard coded vendor code | |
57 | value of 1. Third party kernel events use a dynamically allocated vendor | |
58 | code. The vendor code can be found using the SIOCGKEVVENDOR ioctl. | |
59 | */ | |
1c79356b A |
60 | #define KEV_VENDOR_APPLE 1 |
61 | ||
62 | ||
63 | /* | |
91447636 | 64 | * Definition of top-level classifications for KEV_VENDOR_APPLE |
1c79356b A |
65 | */ |
66 | ||
91447636 A |
67 | /*! |
68 | @defined KEV_NETWORK_CLASS | |
69 | @discussion Network kernel event class. | |
70 | */ | |
71 | #define KEV_NETWORK_CLASS 1 | |
72 | ||
73 | /*! | |
74 | @defined KEV_IOKIT_CLASS | |
75 | @discussion IOKit kernel event class. | |
76 | */ | |
77 | #define KEV_IOKIT_CLASS 2 | |
78 | ||
79 | /*! | |
80 | @defined KEV_IOKIT_CLASS | |
81 | @discussion System kernel event class. | |
82 | */ | |
83 | #define KEV_SYSTEM_CLASS 3 | |
1c79356b | 84 | |
91447636 A |
85 | /*! |
86 | @defined KEV_APPLESHARE_CLASS | |
87 | @discussion AppleShare kernel event class. | |
88 | */ | |
89 | #define KEV_APPLESHARE_CLASS 4 | |
1c79356b | 90 | |
91447636 A |
91 | /*! |
92 | @struct kern_event_msg | |
93 | @discussion This structure is prepended to all kernel events. This structure | |
94 | is used to determine the format of the remainder of the kernel event. | |
95 | This structure will appear on all messages received on a kernel event | |
96 | socket. To post a kernel event, a slightly different structure is used. | |
97 | @field total_size Total size of the kernel event message including the | |
98 | header. | |
99 | @field vendor_code The vendor code indicates which vendor generated the | |
100 | kernel event. This gives every vendor a unique set of classes and | |
101 | subclasses to use. Use the SIOCGKEVVENDOR ioctl to look up vendor codes | |
102 | for vendors other than Apple. Apple uses KEV_VENDOR_APPLE. | |
103 | @field kev_class The class of the kernel event. | |
104 | @field kev_subclass The subclass of the kernel event. | |
105 | @field id Monotonically increasing value. | |
106 | @field event_code The event code. | |
107 | @field event_data Any additional data about this event. Format will depend | |
108 | on the vendor_code, kev_class, kev_subclass, and event_code. The length | |
109 | of the event_data can be determined using total_size - | |
110 | KEV_MSG_HEADER_SIZE. | |
111 | */ | |
1c79356b | 112 | struct kern_event_msg { |
91447636 A |
113 | u_long total_size; /* Size of entire event msg */ |
114 | u_long vendor_code; /* For non-Apple extensibility */ | |
115 | u_long kev_class; /* Layer of event source */ | |
116 | u_long kev_subclass; /* Component within layer */ | |
117 | u_long id; /* Monotonically increasing value */ | |
118 | u_long event_code; /* unique code */ | |
119 | u_long event_data[1]; /* One or more data longwords */ | |
1c79356b A |
120 | |
121 | }; | |
122 | ||
91447636 A |
123 | /*! |
124 | @defined KEV_MSG_HEADER_SIZE | |
125 | @discussion Size of the header portion of the kern_event_msg structure. This | |
126 | accounts for everything right up to event_data. The size of the data can | |
127 | be found by subtracting KEV_MSG_HEADER_SIZE from the total size from the | |
128 | kern_event_msg. | |
129 | */ | |
130 | #define KEV_MSG_HEADER_SIZE (offsetof(struct kern_event_msg, event_data[0])) | |
1c79356b | 131 | |
91447636 A |
132 | /*! |
133 | @struct kev_request | |
134 | @discussion This structure is used with the SIOCSKEVFILT and SIOCGKEVFILT to | |
135 | set and get the control filter setting for a kernel control socket. | |
136 | @field total_size Total size of the kernel event message including the | |
137 | header. | |
138 | @field vendor_code All kernel events that don't match this vendor code will | |
139 | be ignored. KEV_ANY_VENDOR can be used to receive kernel events with any | |
140 | vendor code. | |
141 | @field kev_class All kernel events that don't match this class will be | |
142 | ignored. KEV_ANY_CLASS can be used to receive kernel events with any | |
143 | class. | |
144 | @field kev_subclass All kernel events that don't match this subclass will be | |
145 | ignored. KEV_ANY_SUBCLASS can be used to receive kernel events with any | |
146 | subclass. | |
147 | */ | |
1c79356b A |
148 | struct kev_request { |
149 | u_long vendor_code; | |
150 | u_long kev_class; | |
151 | u_long kev_subclass; | |
152 | }; | |
153 | ||
91447636 A |
154 | /*! |
155 | @defined KEV_VENDOR_CODE_MAX_STR_LEN | |
156 | @discussion This define sets the maximum length of a string that can be used | |
157 | to identify a vendor or kext when looking up a vendor code. | |
158 | */ | |
159 | #define KEV_VENDOR_CODE_MAX_STR_LEN 200 | |
160 | ||
161 | /*! | |
162 | @struct kev_vendor_code | |
163 | @discussion This structure is used with the SIOCGKEVVENDOR ioctl to convert | |
164 | from a string identifying a kext or vendor, in the form of a bundle | |
165 | identifier, to a vendor code. | |
166 | @field vendor_code After making the SIOCGKEVVENDOR ioctl call, this will | |
167 | be filled in with the vendor code if there is one. | |
168 | @field vendor_string A bundle style identifier. | |
169 | */ | |
170 | struct kev_vendor_code { | |
171 | u_long vendor_code; | |
172 | char vendor_string[KEV_VENDOR_CODE_MAX_STR_LEN]; | |
173 | }; | |
174 | ||
175 | ||
176 | /*! | |
177 | @defined SIOCGKEVID | |
178 | @discussion Retrieve the current event id. Each event generated will have | |
179 | a new idea. The next event to be generated will have an id of id+1. | |
180 | */ | |
1c79356b | 181 | #define SIOCGKEVID _IOR('e', 1, u_long) |
91447636 A |
182 | |
183 | /*! | |
184 | @defined SIOCSKEVFILT | |
185 | @discussion Set the kernel event filter for this socket. Kernel events not | |
186 | matching this filter will not be received on this socket. | |
187 | */ | |
1c79356b | 188 | #define SIOCSKEVFILT _IOW('e', 2, struct kev_request) |
91447636 A |
189 | |
190 | /*! | |
191 | @defined SIOCGKEVFILT | |
192 | @discussion Retrieve the kernel event filter for this socket. Kernel events | |
193 | not matching this filter will not be received on this socket. | |
194 | */ | |
1c79356b A |
195 | #define SIOCGKEVFILT _IOR('e', 3, struct kev_request) |
196 | ||
91447636 A |
197 | /*! |
198 | @defined SIOCGKEVVENDOR | |
199 | @discussion Lookup the vendor code for the specified vendor. ENOENT will be | |
200 | returned if a vendor code for that vendor string does not exist. | |
201 | */ | |
202 | #define SIOCGKEVVENDOR _IOWR('e', 4, struct kev_vendor_code) | |
1c79356b | 203 | |
91447636 A |
204 | #ifdef KERNEL |
205 | /*! | |
206 | @define N_KEV_VECTORS | |
207 | @discussion The maximum number of kev_d_vectors for a kernel event. | |
208 | */ | |
1c79356b A |
209 | #define N_KEV_VECTORS 5 |
210 | ||
91447636 A |
211 | /*! |
212 | @struct kev_d_vectors | |
213 | @discussion This structure is used to append some data to a kernel event. | |
214 | @field data_length The length of data. | |
215 | @field data_ptr A pointer to data. | |
216 | */ | |
1c79356b | 217 | struct kev_d_vectors { |
1c79356b A |
218 | u_long data_length; /* Length of the event data */ |
219 | void *data_ptr; /* Pointer to event data */ | |
91447636 | 220 | }; |
1c79356b | 221 | |
91447636 A |
222 | /*! |
223 | @struct kev_d_vectors | |
224 | @discussion This structure is used when posting a kernel event. | |
225 | @field vendor_code The vendor code assigned by kev_vendor_code_find. | |
226 | @field kev_class The event's class. | |
227 | @field kev_class The event's subclass. | |
228 | @field kev_class The event's code. | |
229 | @field dv An array of vectors describing additional data to be appended to | |
230 | the kernel event. | |
231 | */ | |
1c79356b A |
232 | struct kev_msg { |
233 | u_long vendor_code; /* For non-Apple extensibility */ | |
234 | u_long kev_class; /* Layer of event source */ | |
235 | u_long kev_subclass; /* Component within layer */ | |
236 | u_long event_code; /* The event code */ | |
237 | struct kev_d_vectors dv[N_KEV_VECTORS]; /* Up to n data vectors */ | |
238 | }; | |
239 | ||
91447636 A |
240 | /*! |
241 | @function kev_vendor_code_find | |
242 | @discussion Lookup a vendor_code given a unique string. If the vendor code | |
243 | has not been used since launch, a unique integer will be assigned for | |
244 | that string. Vendor codes will remain the same until the machine is | |
245 | rebooted. | |
246 | @param vendor_string A bundle style vendor identifier (i.e. com.apple). | |
247 | @param vender_code Upon return, a unique vendor code for use when posting | |
248 | kernel events. | |
249 | @result May return ENOMEM if memory constraints prevent allocation of a new | |
250 | vendor code. | |
251 | */ | |
252 | errno_t kev_vendor_code_find(const char *vendor_string, u_long *vender_code); | |
253 | ||
254 | /*! | |
255 | @function kev_msg_post | |
256 | @discussion Post a kernel event message. | |
257 | @param event_msg A structure defining the kernel event message to post. | |
258 | @result Will return zero upon success. May return a number of errors | |
259 | depending on the type of failure. EINVAL indicates that there was | |
260 | something wrong with the kerne event. The vendor code of the kernel | |
261 | event must be assigned using kev_vendor_code_find. If the message is | |
262 | too large, EMSGSIZE will be returned. | |
263 | */ | |
264 | errno_t kev_msg_post(struct kev_msg *event_msg); | |
1c79356b | 265 | |
91447636 A |
266 | #ifdef PRIVATE |
267 | /* | |
268 | * Internal version of kev_post_msg. Allows posting Apple vendor code kernel | |
269 | * events. | |
270 | */ | |
271 | int kev_post_msg(struct kev_msg *event); | |
1c79356b A |
272 | |
273 | LIST_HEAD(kern_event_head, kern_event_pcb); | |
274 | ||
275 | struct kern_event_pcb { | |
276 | LIST_ENTRY(kern_event_pcb) ev_link; /* glue on list of all PCBs */ | |
277 | struct socket *ev_socket; /* pointer back to socket */ | |
278 | u_long vendor_code_filter; | |
279 | u_long class_filter; | |
280 | u_long subclass_filter; | |
281 | }; | |
282 | ||
283 | #define sotoevpcb(so) ((struct kern_event_pcb *)((so)->so_pcb)) | |
284 | ||
1c79356b | 285 | |
91447636 A |
286 | #endif /* PRIVATE */ |
287 | #endif /* KERNEL */ | |
288 | #endif /* SYS_KERN_EVENT_H */ |