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