]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/kmod.h
xnu-792.21.3.tar.gz
[apple/xnu.git] / osfmk / mach / kmod.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, 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
29 #ifndef _MACH_KMOD_H_
30 #define _MACH_KMOD_H_
31
32 #include <mach/kern_return.h>
33
34 #include <sys/cdefs.h>
35
36 #define KMOD_CNTL_START 1 // call kmod's start routine
37 #define KMOD_CNTL_STOP 2 // call kmod's stop routine
38 #define KMOD_CNTL_RETAIN 3 // increase a kmod's reference count
39 #define KMOD_CNTL_RELEASE 4 // decrease a kmod's reference count
40 #define KMOD_CNTL_GET_CMD 5 // get kmod load cmd from kernel
41
42 #define KMOD_PACK_IDS(from, to) (((unsigned long)from << 16) | (unsigned long)to)
43 #define KMOD_UNPACK_FROM_ID(i) ((unsigned long)i >> 16)
44 #define KMOD_UNPACK_TO_ID(i) ((unsigned long)i & 0xffff)
45
46 typedef int kmod_t;
47 typedef int kmod_control_flavor_t;
48 typedef void* kmod_args_t;
49
50 #define KMOD_MAX_NAME 64
51
52 #if __DARWIN_ALIGN_POWER
53 #pragma options align=power
54 #endif
55
56 /* LP64todo - not 64-bit safe */
57 typedef struct kmod_reference {
58 struct kmod_reference *next;
59 struct kmod_info *info;
60 } kmod_reference_t;
61
62 #if __DARWIN_ALIGN_POWER
63 #pragma options align=reset
64 #endif
65
66 /**************************************************************************************/
67 /* warning any changes to this structure affect the following macros. */
68 /**************************************************************************************/
69
70 #define KMOD_RETURN_SUCCESS KERN_SUCCESS
71 #define KMOD_RETURN_FAILURE KERN_FAILURE
72
73 typedef kern_return_t kmod_start_func_t(struct kmod_info *ki, void *data);
74 typedef kern_return_t kmod_stop_func_t(struct kmod_info *ki, void *data);
75
76 #if __DARWIN_ALIGN_POWER
77 #pragma options align=power
78 #endif
79
80 /* LP64todo - not 64-bit safe */
81
82 typedef struct kmod_info {
83 struct kmod_info *next;
84 int info_version; // version of this structure
85 int id;
86 char name[KMOD_MAX_NAME];
87 char version[KMOD_MAX_NAME];
88 int reference_count; // # refs to this
89 kmod_reference_t *reference_list; // who this refs
90 vm_address_t address; // starting address
91 vm_size_t size; // total size
92 vm_size_t hdr_size; // unwired hdr size
93 kmod_start_func_t *start;
94 kmod_stop_func_t *stop;
95 } kmod_info_t;
96
97 #if __DARWIN_ALIGN_POWER
98 #pragma options align=reset
99 #endif
100
101 typedef kmod_info_t *kmod_info_array_t;
102
103 #define KMOD_INFO_NAME kmod_info
104 #define KMOD_INFO_VERSION 1
105
106 #define KMOD_DECL(name, version) \
107 static kmod_start_func_t name ## _module_start; \
108 static kmod_stop_func_t name ## _module_stop; \
109 kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \
110 { #name }, { version }, -1, 0, 0, 0, 0, \
111 name ## _module_start, \
112 name ## _module_stop };
113
114 #define KMOD_EXPLICIT_DECL(name, version, start, stop) \
115 kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \
116 { #name }, { version }, -1, 0, 0, 0, 0, \
117 start, stop };
118
119 // the following is useful for libaries that don't need their own start and stop functions
120 #define KMOD_LIB_DECL(name, version) \
121 kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \
122 { #name }, { version }, -1, 0, 0, 0, 0, \
123 kmod_default_start, \
124 kmod_default_stop };
125
126
127 // *************************************************************************************
128 // kmod kernel to user commands
129 // *************************************************************************************
130
131 #define KMOD_LOAD_EXTENSION_PACKET 1
132 #define KMOD_LOAD_WITH_DEPENDENCIES_PACKET 2
133
134 // for generic packets
135 #define KMOD_IOKIT_START_RANGE_PACKET 0x1000
136 #define KMOD_IOKIT_END_RANGE_PACKET 0x1fff
137
138 typedef struct kmod_load_extension_cmd {
139 int type;
140 char name[KMOD_MAX_NAME];
141 } kmod_load_extension_cmd_t;
142
143 typedef struct kmod_load_with_dependencies_cmd {
144 int type;
145 char name[KMOD_MAX_NAME];
146 char dependencies[1][KMOD_MAX_NAME];
147 } kmod_load_with_dependencies_cmd_t;
148
149 typedef struct kmod_generic_cmd {
150 int type;
151 char data[1];
152 } kmod_generic_cmd_t;
153
154 #ifdef KERNEL_PRIVATE
155
156 extern kmod_info_t *kmod_lookupbyname(const char * name);
157 extern kmod_info_t *kmod_lookupbyid(kmod_t id);
158
159 extern kmod_info_t *kmod_lookupbyname_locked(const char * name);
160 extern kmod_info_t *kmod_lookupbyid_locked(kmod_t id);
161 extern kmod_start_func_t kmod_default_start;
162 extern kmod_stop_func_t kmod_default_stop;
163
164 __BEGIN_DECLS
165 extern void kmod_init(void);
166
167 extern kern_return_t kmod_create_fake(const char *name, const char *version);
168 extern kern_return_t kmod_create_fake_with_address(const char *name, const char *version,
169 vm_address_t address, vm_size_t size,
170 int * return_id);
171 extern kern_return_t kmod_destroy_fake(kmod_t id);
172
173 extern kern_return_t kmod_load_extension(char *name);
174 extern kern_return_t kmod_load_extension_with_dependencies(char *name, char **dependencies);
175 extern kern_return_t kmod_send_generic(int type, void *data, int size);
176
177 extern kern_return_t kmod_initialize_cpp(kmod_info_t *info);
178 extern kern_return_t kmod_finalize_cpp(kmod_info_t *info);
179
180 extern void kmod_dump(vm_offset_t *addr, unsigned int dump_cnt);
181 __END_DECLS
182
183 #endif /* KERNEL_PRIVATE */
184
185 #endif /* _MACH_KMOD_H_ */