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