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