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