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