xref: /xnu-8792.81.2/bsd/sys/kern_event.h (revision 19c3b8c28c31cb8130e034cfb5df6bf9ba342d90)
1*19c3b8c2SApple OSS Distributions /*
2*19c3b8c2SApple OSS Distributions  * Copyright (c) 2000-2021 Apple Inc. All rights reserved.
3*19c3b8c2SApple OSS Distributions  *
4*19c3b8c2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*19c3b8c2SApple OSS Distributions  *
6*19c3b8c2SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*19c3b8c2SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*19c3b8c2SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*19c3b8c2SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*19c3b8c2SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*19c3b8c2SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*19c3b8c2SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*19c3b8c2SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*19c3b8c2SApple OSS Distributions  *
15*19c3b8c2SApple OSS Distributions  * Please obtain a copy of the License at
16*19c3b8c2SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*19c3b8c2SApple OSS Distributions  *
18*19c3b8c2SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*19c3b8c2SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*19c3b8c2SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*19c3b8c2SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*19c3b8c2SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*19c3b8c2SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*19c3b8c2SApple OSS Distributions  * limitations under the License.
25*19c3b8c2SApple OSS Distributions  *
26*19c3b8c2SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*19c3b8c2SApple OSS Distributions  */
28*19c3b8c2SApple OSS Distributions /* Copyright (c) 1998, 1999 Apple Computer, Inc. All Rights Reserved */
29*19c3b8c2SApple OSS Distributions /*!
30*19c3b8c2SApple OSS Distributions  *       @header kern_event.h
31*19c3b8c2SApple OSS Distributions  *       This header defines in-kernel functions for generating kernel events as
32*19c3b8c2SApple OSS Distributions  *       well as functions for receiving kernel events using a kernel event
33*19c3b8c2SApple OSS Distributions  *       socket.
34*19c3b8c2SApple OSS Distributions  */
35*19c3b8c2SApple OSS Distributions 
36*19c3b8c2SApple OSS Distributions #ifndef SYS_KERN_EVENT_H
37*19c3b8c2SApple OSS Distributions #define SYS_KERN_EVENT_H
38*19c3b8c2SApple OSS Distributions 
39*19c3b8c2SApple OSS Distributions #include <sys/appleapiopts.h>
40*19c3b8c2SApple OSS Distributions #include <sys/ioccom.h>
41*19c3b8c2SApple OSS Distributions #include <sys/sys_domain.h>
42*19c3b8c2SApple OSS Distributions 
43*19c3b8c2SApple OSS Distributions #define KEV_SNDSPACE    (4 * 1024)
44*19c3b8c2SApple OSS Distributions #define KEV_RECVSPACE   (32 * 1024)
45*19c3b8c2SApple OSS Distributions 
46*19c3b8c2SApple OSS Distributions #define KEV_ANY_VENDOR          0
47*19c3b8c2SApple OSS Distributions #define KEV_ANY_CLASS           0
48*19c3b8c2SApple OSS Distributions #define KEV_ANY_SUBCLASS        0
49*19c3b8c2SApple OSS Distributions 
50*19c3b8c2SApple OSS Distributions /*
51*19c3b8c2SApple OSS Distributions  * Vendor Code
52*19c3b8c2SApple OSS Distributions  */
53*19c3b8c2SApple OSS Distributions 
54*19c3b8c2SApple OSS Distributions /*!
55*19c3b8c2SApple OSS Distributions  *       @defined KEV_VENDOR_APPLE
56*19c3b8c2SApple OSS Distributions  *       @discussion Apple generated kernel events use the hard coded vendor code
57*19c3b8c2SApple OSS Distributions  *       value of 1. Third party kernel events use a dynamically allocated vendor
58*19c3b8c2SApple OSS Distributions  *       code. The vendor code can be found using the SIOCGKEVVENDOR ioctl.
59*19c3b8c2SApple OSS Distributions  */
60*19c3b8c2SApple OSS Distributions #define KEV_VENDOR_APPLE        1
61*19c3b8c2SApple OSS Distributions 
62*19c3b8c2SApple OSS Distributions /*
63*19c3b8c2SApple OSS Distributions  * Definition of top-level classifications for KEV_VENDOR_APPLE
64*19c3b8c2SApple OSS Distributions  */
65*19c3b8c2SApple OSS Distributions 
66*19c3b8c2SApple OSS Distributions /*!
67*19c3b8c2SApple OSS Distributions  *       @defined KEV_NETWORK_CLASS
68*19c3b8c2SApple OSS Distributions  *       @discussion Network kernel event class.
69*19c3b8c2SApple OSS Distributions  */
70*19c3b8c2SApple OSS Distributions #define KEV_NETWORK_CLASS       1
71*19c3b8c2SApple OSS Distributions 
72*19c3b8c2SApple OSS Distributions /*!
73*19c3b8c2SApple OSS Distributions  *       @defined KEV_IOKIT_CLASS
74*19c3b8c2SApple OSS Distributions  *       @discussion IOKit kernel event class.
75*19c3b8c2SApple OSS Distributions  */
76*19c3b8c2SApple OSS Distributions #define KEV_IOKIT_CLASS         2
77*19c3b8c2SApple OSS Distributions 
78*19c3b8c2SApple OSS Distributions /*!
79*19c3b8c2SApple OSS Distributions  *       @defined KEV_SYSTEM_CLASS
80*19c3b8c2SApple OSS Distributions  *       @discussion System kernel event class.
81*19c3b8c2SApple OSS Distributions  */
82*19c3b8c2SApple OSS Distributions #define KEV_SYSTEM_CLASS        3
83*19c3b8c2SApple OSS Distributions 
84*19c3b8c2SApple OSS Distributions /*!
85*19c3b8c2SApple OSS Distributions  *       @defined KEV_APPLESHARE_CLASS
86*19c3b8c2SApple OSS Distributions  *       @discussion AppleShare kernel event class.
87*19c3b8c2SApple OSS Distributions  */
88*19c3b8c2SApple OSS Distributions #define KEV_APPLESHARE_CLASS    4
89*19c3b8c2SApple OSS Distributions 
90*19c3b8c2SApple OSS Distributions /*!
91*19c3b8c2SApple OSS Distributions  *       @defined KEV_FIREWALL_CLASS
92*19c3b8c2SApple OSS Distributions  *       @discussion Firewall kernel event class.
93*19c3b8c2SApple OSS Distributions  */
94*19c3b8c2SApple OSS Distributions #define KEV_FIREWALL_CLASS      5
95*19c3b8c2SApple OSS Distributions 
96*19c3b8c2SApple OSS Distributions /*!
97*19c3b8c2SApple OSS Distributions  *       @defined KEV_IEEE80211_CLASS
98*19c3b8c2SApple OSS Distributions  *       @discussion IEEE 802.11 kernel event class.
99*19c3b8c2SApple OSS Distributions  */
100*19c3b8c2SApple OSS Distributions #define KEV_IEEE80211_CLASS     6
101*19c3b8c2SApple OSS Distributions 
102*19c3b8c2SApple OSS Distributions /*!
103*19c3b8c2SApple OSS Distributions  *       @defined KEV_NKE_CLASS
104*19c3b8c2SApple OSS Distributions  *       @discussion NKE kernel event class.
105*19c3b8c2SApple OSS Distributions  */
106*19c3b8c2SApple OSS Distributions #define KEV_NKE_CLASS           7
107*19c3b8c2SApple OSS Distributions 
108*19c3b8c2SApple OSS Distributions #define KEV_NKE_ALF_SUBCLASS            1
109*19c3b8c2SApple OSS Distributions #define KEV_NKE_ALF_STATE_CHANGED       1
110*19c3b8c2SApple OSS Distributions 
111*19c3b8c2SApple OSS Distributions /*
112*19c3b8c2SApple OSS Distributions  * The following struct is KPI, but it was originally defined with a trailing
113*19c3b8c2SApple OSS Distributions  * array member of size one, intended to be used as a Variable-Length Array.
114*19c3b8c2SApple OSS Distributions  * That's problematic because the compiler doesn't know that the array is
115*19c3b8c2SApple OSS Distributions  * accessed out-of-bounds and can assume it isn't. This makes
116*19c3b8c2SApple OSS Distributions  * -Warray-bounds-pointer-arithmetic sad. We can't just change the code because
117*19c3b8c2SApple OSS Distributions  * it requires users to also change their uses of the class, at a minimum
118*19c3b8c2SApple OSS Distributions  * because kern_event_msg's size changes when making the last member a VLA. This
119*19c3b8c2SApple OSS Distributions  * macro allows users of this KPI to opt-in to the new behavior.
120*19c3b8c2SApple OSS Distributions  */
121*19c3b8c2SApple OSS Distributions #if defined(XNU_KERN_EVENT_DATA_IS_VLA)
122*19c3b8c2SApple OSS Distributions #define XNU_KERN_EVENT_DATA_SIZE /* nothing, it's a VLA */
123*19c3b8c2SApple OSS Distributions #else
124*19c3b8c2SApple OSS Distributions #define XNU_KERN_EVENT_DATA_SIZE 1
125*19c3b8c2SApple OSS Distributions #endif
126*19c3b8c2SApple OSS Distributions 
127*19c3b8c2SApple OSS Distributions /*!
128*19c3b8c2SApple OSS Distributions  *       @struct kern_event_msg
129*19c3b8c2SApple OSS Distributions  *       @discussion This structure is prepended to all kernel events. This
130*19c3b8c2SApple OSS Distributions  *               structure is used to determine the format of the remainder of
131*19c3b8c2SApple OSS Distributions  *               the kernel event. This structure will appear on all messages
132*19c3b8c2SApple OSS Distributions  *               received on a kernel event socket. To post a kernel event, a
133*19c3b8c2SApple OSS Distributions  *               slightly different structure is used.
134*19c3b8c2SApple OSS Distributions  *       @field total_size Total size of the kernel event message including the
135*19c3b8c2SApple OSS Distributions  *               header.
136*19c3b8c2SApple OSS Distributions  *       @field vendor_code The vendor code indicates which vendor generated the
137*19c3b8c2SApple OSS Distributions  *               kernel event. This gives every vendor a unique set of classes
138*19c3b8c2SApple OSS Distributions  *               and subclasses to use. Use the SIOCGKEVVENDOR ioctl to look up
139*19c3b8c2SApple OSS Distributions  *               vendor codes for vendors other than Apple. Apple uses
140*19c3b8c2SApple OSS Distributions  *               KEV_VENDOR_APPLE.
141*19c3b8c2SApple OSS Distributions  *       @field kev_class The class of the kernel event.
142*19c3b8c2SApple OSS Distributions  *       @field kev_subclass The subclass of the kernel event.
143*19c3b8c2SApple OSS Distributions  *       @field id Monotonically increasing value.
144*19c3b8c2SApple OSS Distributions  *       @field event_code The event code.
145*19c3b8c2SApple OSS Distributions  *       @field event_data Any additional data about this event. Format will
146*19c3b8c2SApple OSS Distributions  *               depend on the vendor_code, kev_class, kev_subclass, and
147*19c3b8c2SApple OSS Distributions  *               event_code. The length of the event_data can be determined
148*19c3b8c2SApple OSS Distributions  *               using total_size - KEV_MSG_HEADER_SIZE.
149*19c3b8c2SApple OSS Distributions  */
150*19c3b8c2SApple OSS Distributions struct kern_event_msg {
151*19c3b8c2SApple OSS Distributions 	u_int32_t       total_size;     /* Size of entire event msg */
152*19c3b8c2SApple OSS Distributions 	u_int32_t       vendor_code;    /* For non-Apple extensibility */
153*19c3b8c2SApple OSS Distributions 	u_int32_t       kev_class;      /* Layer of event source */
154*19c3b8c2SApple OSS Distributions 	u_int32_t       kev_subclass;   /* Component within layer */
155*19c3b8c2SApple OSS Distributions 	u_int32_t       id;             /* Monotonically increasing value */
156*19c3b8c2SApple OSS Distributions 	u_int32_t       event_code;     /* unique code */
157*19c3b8c2SApple OSS Distributions 	u_int32_t       event_data[XNU_KERN_EVENT_DATA_SIZE];   /* One or more data words */
158*19c3b8c2SApple OSS Distributions };
159*19c3b8c2SApple OSS Distributions 
160*19c3b8c2SApple OSS Distributions /*!
161*19c3b8c2SApple OSS Distributions  *       @defined KEV_MSG_HEADER_SIZE
162*19c3b8c2SApple OSS Distributions  *       @discussion Size of the header portion of the kern_event_msg structure.
163*19c3b8c2SApple OSS Distributions  *               This accounts for everything right up to event_data. The size
164*19c3b8c2SApple OSS Distributions  *               of the data can be found by subtracting KEV_MSG_HEADER_SIZE
165*19c3b8c2SApple OSS Distributions  *               from the total size from the kern_event_msg.
166*19c3b8c2SApple OSS Distributions  */
167*19c3b8c2SApple OSS Distributions #define KEV_MSG_HEADER_SIZE (offsetof(struct kern_event_msg, event_data[0]))
168*19c3b8c2SApple OSS Distributions 
169*19c3b8c2SApple OSS Distributions /*!
170*19c3b8c2SApple OSS Distributions  *       @struct kev_request
171*19c3b8c2SApple OSS Distributions  *       @discussion This structure is used with the SIOCSKEVFILT and
172*19c3b8c2SApple OSS Distributions  *               SIOCGKEVFILT to set and get the control filter setting for a
173*19c3b8c2SApple OSS Distributions  *               kernel control socket.
174*19c3b8c2SApple OSS Distributions  *       @field total_size Total size of the kernel event message including the
175*19c3b8c2SApple OSS Distributions  *               header.
176*19c3b8c2SApple OSS Distributions  *       @field vendor_code All kernel events that don't match this vendor code
177*19c3b8c2SApple OSS Distributions  *               will be ignored. KEV_ANY_VENDOR can be used to receive kernel
178*19c3b8c2SApple OSS Distributions  *               events with any vendor code.
179*19c3b8c2SApple OSS Distributions  *       @field kev_class All kernel events that don't match this class will be
180*19c3b8c2SApple OSS Distributions  *               ignored. KEV_ANY_CLASS can be used to receive kernel events with
181*19c3b8c2SApple OSS Distributions  *               any class.
182*19c3b8c2SApple OSS Distributions  *       @field kev_subclass All kernel events that don't match this subclass
183*19c3b8c2SApple OSS Distributions  *               will be ignored. KEV_ANY_SUBCLASS can be used to receive kernel
184*19c3b8c2SApple OSS Distributions  *               events with any subclass.
185*19c3b8c2SApple OSS Distributions  */
186*19c3b8c2SApple OSS Distributions struct kev_request {
187*19c3b8c2SApple OSS Distributions 	u_int32_t       vendor_code;
188*19c3b8c2SApple OSS Distributions 	u_int32_t       kev_class;
189*19c3b8c2SApple OSS Distributions 	u_int32_t       kev_subclass;
190*19c3b8c2SApple OSS Distributions };
191*19c3b8c2SApple OSS Distributions 
192*19c3b8c2SApple OSS Distributions /*!
193*19c3b8c2SApple OSS Distributions  *       @defined KEV_VENDOR_CODE_MAX_STR_LEN
194*19c3b8c2SApple OSS Distributions  *       @discussion This define sets the maximum length of a string that can be
195*19c3b8c2SApple OSS Distributions  *               used to identify a vendor or kext when looking up a vendor code.
196*19c3b8c2SApple OSS Distributions  */
197*19c3b8c2SApple OSS Distributions #define KEV_VENDOR_CODE_MAX_STR_LEN     200
198*19c3b8c2SApple OSS Distributions 
199*19c3b8c2SApple OSS Distributions /*!
200*19c3b8c2SApple OSS Distributions  *       @struct kev_vendor_code
201*19c3b8c2SApple OSS Distributions  *       @discussion This structure is used with the SIOCGKEVVENDOR ioctl to
202*19c3b8c2SApple OSS Distributions  *               convert from a string identifying a kext or vendor, in the
203*19c3b8c2SApple OSS Distributions  *               form of a bundle identifier, to a vendor code.
204*19c3b8c2SApple OSS Distributions  *       @field vendor_code After making the SIOCGKEVVENDOR ioctl call, this will
205*19c3b8c2SApple OSS Distributions  *               be filled in with the vendor code if there is one.
206*19c3b8c2SApple OSS Distributions  *       @field vendor_string A bundle style identifier.
207*19c3b8c2SApple OSS Distributions  */
208*19c3b8c2SApple OSS Distributions #pragma pack(4)
209*19c3b8c2SApple OSS Distributions struct kev_vendor_code {
210*19c3b8c2SApple OSS Distributions 	u_int32_t       vendor_code;
211*19c3b8c2SApple OSS Distributions 	char            vendor_string[KEV_VENDOR_CODE_MAX_STR_LEN];
212*19c3b8c2SApple OSS Distributions };
213*19c3b8c2SApple OSS Distributions #pragma pack()
214*19c3b8c2SApple OSS Distributions 
215*19c3b8c2SApple OSS Distributions /*!
216*19c3b8c2SApple OSS Distributions  *       @defined SIOCGKEVID
217*19c3b8c2SApple OSS Distributions  *       @discussion Retrieve the current event id. Each event generated will
218*19c3b8c2SApple OSS Distributions  *               have a new id. The next event to be generated will have an id
219*19c3b8c2SApple OSS Distributions  *               of id+1.
220*19c3b8c2SApple OSS Distributions  */
221*19c3b8c2SApple OSS Distributions #define SIOCGKEVID      _IOR('e', 1, u_int32_t)
222*19c3b8c2SApple OSS Distributions 
223*19c3b8c2SApple OSS Distributions /*!
224*19c3b8c2SApple OSS Distributions  *       @defined SIOCSKEVFILT
225*19c3b8c2SApple OSS Distributions  *       @discussion Set the kernel event filter for this socket. Kernel events
226*19c3b8c2SApple OSS Distributions  *               not matching this filter will not be received on this socket.
227*19c3b8c2SApple OSS Distributions  */
228*19c3b8c2SApple OSS Distributions #define SIOCSKEVFILT    _IOW('e', 2, struct kev_request)
229*19c3b8c2SApple OSS Distributions 
230*19c3b8c2SApple OSS Distributions /*!
231*19c3b8c2SApple OSS Distributions  *       @defined SIOCGKEVFILT
232*19c3b8c2SApple OSS Distributions  *       @discussion Retrieve the kernel event filter for this socket. Kernel
233*19c3b8c2SApple OSS Distributions  *               events not matching this filter will not be received on this
234*19c3b8c2SApple OSS Distributions  *               socket.
235*19c3b8c2SApple OSS Distributions  */
236*19c3b8c2SApple OSS Distributions #define SIOCGKEVFILT    _IOR('e', 3, struct kev_request)
237*19c3b8c2SApple OSS Distributions 
238*19c3b8c2SApple OSS Distributions /*!
239*19c3b8c2SApple OSS Distributions  *       @defined SIOCGKEVVENDOR
240*19c3b8c2SApple OSS Distributions  *       @discussion Lookup the vendor code for the specified vendor. ENOENT will
241*19c3b8c2SApple OSS Distributions  *               be returned if a vendor code for that vendor string does not
242*19c3b8c2SApple OSS Distributions  *               exist.
243*19c3b8c2SApple OSS Distributions  */
244*19c3b8c2SApple OSS Distributions #define SIOCGKEVVENDOR  _IOWR('e', 4, struct kev_vendor_code)
245*19c3b8c2SApple OSS Distributions 
246*19c3b8c2SApple OSS Distributions #ifdef PRIVATE
247*19c3b8c2SApple OSS Distributions struct xkevtpcb {
248*19c3b8c2SApple OSS Distributions 	u_int32_t       kep_len;
249*19c3b8c2SApple OSS Distributions 	u_int32_t       kep_kind;
250*19c3b8c2SApple OSS Distributions 	u_int64_t       kep_evtpcb;
251*19c3b8c2SApple OSS Distributions 	u_int32_t       kep_vendor_code_filter;
252*19c3b8c2SApple OSS Distributions 	u_int32_t       kep_class_filter;
253*19c3b8c2SApple OSS Distributions 	u_int32_t       kep_subclass_filter;
254*19c3b8c2SApple OSS Distributions };
255*19c3b8c2SApple OSS Distributions 
256*19c3b8c2SApple OSS Distributions struct kevtstat {
257*19c3b8c2SApple OSS Distributions 	u_int64_t       kes_pcbcount __attribute__((aligned(8)));
258*19c3b8c2SApple OSS Distributions 	u_int64_t       kes_gencnt __attribute__((aligned(8)));
259*19c3b8c2SApple OSS Distributions 	u_int64_t       kes_badvendor __attribute__((aligned(8)));
260*19c3b8c2SApple OSS Distributions 	u_int64_t       kes_toobig __attribute__((aligned(8)));
261*19c3b8c2SApple OSS Distributions 	u_int64_t       kes_nomem __attribute__((aligned(8)));
262*19c3b8c2SApple OSS Distributions 	u_int64_t       kes_fullsock __attribute__((aligned(8)));
263*19c3b8c2SApple OSS Distributions 	u_int64_t       kes_posted __attribute__((aligned(8)));
264*19c3b8c2SApple OSS Distributions };
265*19c3b8c2SApple OSS Distributions #endif /* PRIVATE */
266*19c3b8c2SApple OSS Distributions 
267*19c3b8c2SApple OSS Distributions #ifdef KERNEL
268*19c3b8c2SApple OSS Distributions /*!
269*19c3b8c2SApple OSS Distributions  *       @define N_KEV_VECTORS
270*19c3b8c2SApple OSS Distributions  *       @discussion The maximum number of kev_d_vectors for a kernel event.
271*19c3b8c2SApple OSS Distributions  */
272*19c3b8c2SApple OSS Distributions #define N_KEV_VECTORS   5
273*19c3b8c2SApple OSS Distributions 
274*19c3b8c2SApple OSS Distributions /*!
275*19c3b8c2SApple OSS Distributions  *       @struct kev_d_vectors
276*19c3b8c2SApple OSS Distributions  *       @discussion This structure is used to append some data to a kernel
277*19c3b8c2SApple OSS Distributions  *               event.
278*19c3b8c2SApple OSS Distributions  *       @field data_length The length of data.
279*19c3b8c2SApple OSS Distributions  *       @field data_ptr A pointer to data.
280*19c3b8c2SApple OSS Distributions  */
281*19c3b8c2SApple OSS Distributions struct kev_d_vectors {
282*19c3b8c2SApple OSS Distributions 	u_int32_t       data_length;    /* Length of the event data */
283*19c3b8c2SApple OSS Distributions 	void            *data_ptr;      /* Pointer to event data */
284*19c3b8c2SApple OSS Distributions };
285*19c3b8c2SApple OSS Distributions 
286*19c3b8c2SApple OSS Distributions /*!
287*19c3b8c2SApple OSS Distributions  *       @struct kev_msg
288*19c3b8c2SApple OSS Distributions  *       @discussion This structure is used when posting a kernel event.
289*19c3b8c2SApple OSS Distributions  *       @field vendor_code The vendor code assigned by kev_vendor_code_find.
290*19c3b8c2SApple OSS Distributions  *       @field kev_class The event's class.
291*19c3b8c2SApple OSS Distributions  *       @field kev_class The event's subclass.
292*19c3b8c2SApple OSS Distributions  *       @field kev_class The event's code.
293*19c3b8c2SApple OSS Distributions  *       @field dv An array of vectors describing additional data to be appended
294*19c3b8c2SApple OSS Distributions  *               to the kernel event.
295*19c3b8c2SApple OSS Distributions  */
296*19c3b8c2SApple OSS Distributions struct kev_msg {
297*19c3b8c2SApple OSS Distributions 	u_int32_t vendor_code;          /* For non-Apple extensibility */
298*19c3b8c2SApple OSS Distributions 	u_int32_t kev_class;            /* Layer of event source */
299*19c3b8c2SApple OSS Distributions 	u_int32_t kev_subclass;         /* Component within layer */
300*19c3b8c2SApple OSS Distributions 	u_int32_t event_code;           /* The event code */
301*19c3b8c2SApple OSS Distributions 	struct kev_d_vectors dv[N_KEV_VECTORS]; /* Up to n data vectors */
302*19c3b8c2SApple OSS Distributions };
303*19c3b8c2SApple OSS Distributions 
304*19c3b8c2SApple OSS Distributions /*!
305*19c3b8c2SApple OSS Distributions  *       @function kev_vendor_code_find
306*19c3b8c2SApple OSS Distributions  *       @discussion Lookup a vendor_code given a unique string. If the vendor
307*19c3b8c2SApple OSS Distributions  *               code has not been used since launch, a unique integer will be
308*19c3b8c2SApple OSS Distributions  *               assigned for that string. Vendor codes will remain the same
309*19c3b8c2SApple OSS Distributions  *               until the machine is rebooted.
310*19c3b8c2SApple OSS Distributions  *       @param vendor_string A bundle style vendor identifier(i.e. com.apple).
311*19c3b8c2SApple OSS Distributions  *       @param vendor_code Upon return, a unique vendor code for use when
312*19c3b8c2SApple OSS Distributions  *               posting kernel events.
313*19c3b8c2SApple OSS Distributions  *       @result May return ENOMEM if memory constraints prevent allocation of a
314*19c3b8c2SApple OSS Distributions  *               new vendor code.
315*19c3b8c2SApple OSS Distributions  */
316*19c3b8c2SApple OSS Distributions errno_t kev_vendor_code_find(const char *vendor_string, u_int32_t *vendor_code);
317*19c3b8c2SApple OSS Distributions 
318*19c3b8c2SApple OSS Distributions /*!
319*19c3b8c2SApple OSS Distributions  *       @function kev_msg_post
320*19c3b8c2SApple OSS Distributions  *       @discussion Post a kernel event message.
321*19c3b8c2SApple OSS Distributions  *       @param event_msg A structure defining the kernel event message to post.
322*19c3b8c2SApple OSS Distributions  *       @result Will return zero upon success. May return a number of errors
323*19c3b8c2SApple OSS Distributions  *               depending on the type of failure. EINVAL indicates that there
324*19c3b8c2SApple OSS Distributions  *               was something wrong with the kerne event. The vendor code of
325*19c3b8c2SApple OSS Distributions  *               the kernel event must be assigned using kev_vendor_code_find.
326*19c3b8c2SApple OSS Distributions  *               If the message is too large, EMSGSIZE will be returned.
327*19c3b8c2SApple OSS Distributions  */
328*19c3b8c2SApple OSS Distributions errno_t kev_msg_post(struct kev_msg *event_msg);
329*19c3b8c2SApple OSS Distributions 
330*19c3b8c2SApple OSS Distributions #ifdef PRIVATE
331*19c3b8c2SApple OSS Distributions /*
332*19c3b8c2SApple OSS Distributions  * Internal version of kev_msg_post. Allows posting Apple vendor code kernel
333*19c3b8c2SApple OSS Distributions  * events.
334*19c3b8c2SApple OSS Distributions  */
335*19c3b8c2SApple OSS Distributions int     kev_post_msg(struct kev_msg *event);
336*19c3b8c2SApple OSS Distributions int     kev_post_msg_nowait(struct kev_msg *event);
337*19c3b8c2SApple OSS Distributions 
338*19c3b8c2SApple OSS Distributions LIST_HEAD(kern_event_head, kern_event_pcb);
339*19c3b8c2SApple OSS Distributions 
340*19c3b8c2SApple OSS Distributions struct kern_event_pcb {
341*19c3b8c2SApple OSS Distributions 	decl_lck_mtx_data(, evp_mtx);   /* per-socket mutex */
342*19c3b8c2SApple OSS Distributions 	LIST_ENTRY(kern_event_pcb) evp_link;    /* glue on list of all PCBs */
343*19c3b8c2SApple OSS Distributions 	struct socket *evp_socket;              /* pointer back to socket */
344*19c3b8c2SApple OSS Distributions 	u_int32_t evp_vendor_code_filter;
345*19c3b8c2SApple OSS Distributions 	u_int32_t evp_class_filter;
346*19c3b8c2SApple OSS Distributions 	u_int32_t evp_subclass_filter;
347*19c3b8c2SApple OSS Distributions };
348*19c3b8c2SApple OSS Distributions 
349*19c3b8c2SApple OSS Distributions #define sotoevpcb(so)   ((struct kern_event_pcb *)((so)->so_pcb))
350*19c3b8c2SApple OSS Distributions 
351*19c3b8c2SApple OSS Distributions #endif /* PRIVATE */
352*19c3b8c2SApple OSS Distributions #endif /* KERNEL */
353*19c3b8c2SApple OSS Distributions #endif /* SYS_KERN_EVENT_H */
354