]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
24 | * | |
25 | * HISTORY | |
26 | * | |
27 | * 1999 Mar 29 rsulack created. | |
28 | */ | |
29 | ||
30 | #ifndef _MACH_KMOD_H_ | |
31 | #define _MACH_KMOD_H_ | |
32 | ||
33 | #include <mach/kern_return.h> | |
34 | ||
35 | #define KMOD_CNTL_START 1 // call kmod's start routine | |
36 | #define KMOD_CNTL_STOP 2 // call kmod's stop routine | |
37 | #define KMOD_CNTL_RETAIN 3 // increase a kmod's reference count | |
38 | #define KMOD_CNTL_RELEASE 4 // decrease a kmod's reference count | |
39 | #define KMOD_CNTL_GET_CMD 5 // get kmod load cmd from kernel | |
40 | ||
41 | #define KMOD_PACK_IDS(from, to) (((unsigned long)from << 16) | (unsigned long)to) | |
42 | #define KMOD_UNPACK_FROM_ID(i) ((unsigned long)i >> 16) | |
43 | #define KMOD_UNPACK_TO_ID(i) ((unsigned long)i & 0xffff) | |
44 | ||
45 | #define KMOD_MAX_NAME 64 | |
46 | ||
47 | typedef int kmod_t; | |
48 | typedef int kmod_control_flavor_t; | |
49 | typedef void* kmod_args_t; | |
50 | ||
51 | typedef struct kmod_reference { | |
52 | struct kmod_reference *next; | |
53 | struct kmod_info *info; | |
54 | } kmod_reference_t; | |
55 | ||
56 | /**************************************************************************************/ | |
57 | /* warning any changes to this structure affect the following macros. */ | |
58 | /**************************************************************************************/ | |
59 | ||
60 | #define KMOD_RETURN_SUCCESS KERN_SUCCESS | |
61 | #define KMOD_RETURN_FAILURE KERN_FAILURE | |
62 | ||
63 | typedef kern_return_t kmod_start_func_t(struct kmod_info *ki, void *data); | |
64 | typedef kern_return_t kmod_stop_func_t(struct kmod_info *ki, void *data); | |
65 | ||
66 | typedef struct kmod_info { | |
67 | struct kmod_info *next; | |
68 | int info_version; // version of this structure | |
69 | int id; | |
70 | char name[KMOD_MAX_NAME]; | |
71 | char version[KMOD_MAX_NAME]; | |
72 | int reference_count; // # refs to this | |
73 | kmod_reference_t *reference_list; // who this refs | |
74 | vm_address_t address; // starting address | |
75 | vm_size_t size; // total size | |
76 | vm_size_t hdr_size; // unwired hdr size | |
77 | kmod_start_func_t *start; | |
78 | kmod_stop_func_t *stop; | |
79 | } kmod_info_t; | |
80 | ||
81 | typedef kmod_info_t *kmod_info_array_t; | |
82 | ||
83 | #define KMOD_INFO_NAME kmod_info | |
84 | #define KMOD_INFO_VERSION 1 | |
85 | ||
86 | #define KMOD_DECL(name, version) \ | |
87 | static kmod_start_func_t name ## _module_start; \ | |
88 | static kmod_stop_func_t name ## _module_stop; \ | |
89 | kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \ | |
90 | { #name }, { version }, -1, 0, 0, 0, 0, \ | |
91 | name ## _module_start, \ | |
92 | name ## _module_stop }; | |
93 | ||
94 | #define KMOD_EXPLICIT_DECL(name, version, start, stop) \ | |
95 | kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \ | |
96 | { #name }, { version }, -1, 0, 0, 0, 0, \ | |
97 | start, stop }; | |
98 | ||
99 | // the following is useful for libaries that don't need their own start and stop functions | |
100 | #define KMOD_LIB_DECL(name, version) \ | |
101 | kmod_info_t KMOD_INFO_NAME = { 0, KMOD_INFO_VERSION, -1, \ | |
102 | { #name }, { version }, -1, 0, 0, 0, 0, \ | |
103 | kmod_default_start, \ | |
104 | kmod_default_stop }; | |
105 | ||
106 | ||
107 | // ************************************************************************************* | |
108 | // kmod kernel to user commands | |
109 | // ************************************************************************************* | |
110 | ||
111 | #define KMOD_LOAD_EXTENSION_PACKET 1 | |
112 | #define KMOD_LOAD_WITH_DEPENDENCIES_PACKET 2 | |
113 | ||
114 | // for generic packets | |
115 | #define KMOD_IOKIT_START_RANGE_PACKET 0x1000 | |
116 | #define KMOD_IOKIT_END_RANGE_PACKET 0x1fff | |
117 | ||
118 | typedef struct kmod_load_extension_cmd { | |
119 | int type; | |
120 | char name[KMOD_MAX_NAME]; | |
121 | } kmod_load_extension_cmd_t; | |
122 | ||
123 | typedef struct kmod_load_with_dependencies_cmd { | |
124 | int type; | |
125 | char name[KMOD_MAX_NAME]; | |
126 | char dependencies[1][KMOD_MAX_NAME]; | |
127 | } kmod_load_with_dependencies_cmd_t; | |
128 | ||
129 | typedef struct kmod_generic_cmd { | |
130 | int type; | |
131 | char data[1]; | |
132 | } kmod_generic_cmd_t; | |
133 | ||
134 | #ifdef KERNEL_PRIVATE | |
135 | ||
136 | extern void kmod_init(); | |
137 | ||
138 | extern kern_return_t kmod_create_fake(char *name, char *version); | |
139 | ||
0b4e3aa0 | 140 | extern kmod_info_t *kmod_lookupbyname(const char * name); |
1c79356b A |
141 | extern kmod_info_t *kmod_lookupbyid(kmod_t id); |
142 | ||
143 | extern kern_return_t kmod_load_extension(char *name); | |
144 | extern kern_return_t kmod_load_extension_with_dependencies(char *name, char **dependencies); | |
145 | extern kern_return_t kmod_send_generic(int type, void *data, int size); | |
146 | ||
147 | extern kmod_start_func_t kmod_default_start; | |
148 | extern kmod_stop_func_t kmod_default_stop; | |
149 | ||
150 | extern kern_return_t kmod_initialize_cpp(kmod_info_t *info); | |
151 | extern kern_return_t kmod_finalize_cpp(kmod_info_t *info); | |
152 | ||
153 | extern void kmod_dump(vm_offset_t *addr, unsigned int cnt); | |
154 | ||
155 | #endif /* KERNEL_PRIVATE */ | |
156 | ||
157 | #endif /* _MACH_KMOD_H_ */ |