xref: /xnu-8796.101.5/libkern/libkern/coreanalytics/coreanalytics_shim.h (revision aca3beaa3dfbd42498b42c5e5ce20a938e6554e5)
1 /*
2  * Copyright (c) 2020 Apple 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 #ifdef KERNEL_PRIVATE
29 #ifndef _COREANALYTICS_SHIM_H
30 #define _COREANALYTICS_SHIM_H
31 
32 /*
33  * Shim between xnu and CoreAnalyticsFamily kext.
34  * If you're trying to use CoreAnalytics from within xnu, you're in the wrong place.
35  * See libkern/libkern/coreanalytics/coreanalytics.h instead.
36  */
37 
38 #ifdef __cplusplus
39 #include <libkern/c++/OSDictionary.h>
40 #include <libkern/c++/OSString.h>
41 #include <libkern/c++/OSObject.h>
42 #include <IOKit/IOService.h>
43 #endif /* __cplusplus */
44 
45 #include <os/base.h>
46 
47 /*
48  * Increment whenever core_analytics_hub_functions_s changes.
49  * CoreAnalyticsHub will report which version it was built against.
50  * If the versions don't match, we will panic at boot.
51  * This likely means CoreAnalyticsHub needs to be rebuilt.
52  */
53 #define CORE_ANALYTICS_FUNCTIONS_TABLE_VERSION 1
54 
55 #ifdef __cplusplus
56 typedef const struct core_analytics_hub_functions_s {
57 	int version;
58 	bool (*analytics_send_event_lazy)(IOService *core_analytics_hub, OSString *event_name, OSObject *event_payload);
59 } core_analytics_hub_functions_t;
60 #else
61 typedef const struct core_analytics_hub_functions_s {
62 	int version;
63 	bool (*analytics_send_event_lazy)(void *core_analytics_hub, void *event_name, void *event_payload);
64 } core_analytics_hub_functions_t;
65 #endif /* __cplusplus */
66 
67 __BEGIN_DECLS
68 
69 OS_EXPORT OS_NONNULL1
70 void core_analytics_hub_register(core_analytics_hub_functions_t *fns);
71 
72 __END_DECLS
73 
74 #ifdef XNU_KERNEL_PRIVATE
75 /* XNU private interface to shim into CoreAnalyticsHub */
76 extern core_analytics_hub_functions_t *core_analytics_hub_functions;
77 
78 #ifdef __cplusplus
79 typedef IOService core_analytics_family_service_t;
80 extern "C" {
81 #else
82 /*
83  * Anonymous struct representing the CoreAnalyticsFamily IOService.
84  * This is just here to provide some basic type-checking to C clients.
85  */
86 typedef struct core_analytics_family_service core_analytics_family_service_t;
87 #endif
88 /*
89  * Match the CoreAnalyticsFamily IOService.
90  * Retains a reference to the IOService which may be released via
91  * core_analyics_family_release.
92  * May block.
93  */
94 core_analytics_family_service_t *core_analytics_family_match(void);
95 
96 /*
97  * Release the reference retained by core_analytics_family_match
98  */
99 #ifdef __cplusplus
100 void core_analytics_family_release(LIBKERN_CONSUMED core_analytics_family_service_t *);
101 #else
102 void core_analytics_family_release(core_analytics_family_service_t *);
103 #endif
104 
105 int core_analytics_send_event_lazy(core_analytics_family_service_t *core_analytics_hub, const char *event_spec, const ca_event_t event);
106 
107 /*
108  * Checks if field spec is string. If yes, it returns size of the string buffer,
109  * (not strlen) else it returns 0.
110  */
111 size_t core_analytics_field_is_string(const char *field_spec);
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif /* XNU_KERNEL_PRIVATE */
117 
118 #endif /* _COREANALYTICS_SHIM_H */
119 #endif /* KERNEL_PRIVATE */
120