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