]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/kxld.h
6b3ef392bcbd51575c1a33355efd834a2e2620f0
[apple/xnu.git] / libkern / libkern / kxld.h
1 /*
2 * Copyright (c) 2007-2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_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 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
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 #ifndef _KXLD_H
29 #define _KXLD_H
30
31 #include <sys/types.h>
32 #include <mach/boolean.h> // boolean_t
33 #include <mach/kern_return.h> // kern_return_t
34 #include <mach/machine.h> // cpu_type_t and cpu_subtype_t
35 #include <mach/vm_types.h>
36
37 #include "kxld_types.h"
38
39 /*******************************************************************************
40 * API
41 *******************************************************************************/
42
43 /*******************************************************************************
44 * Creates a state object for the linker. A context must be created for each
45 * link thread and destroyed at the end of the thread's life. A context should
46 * be reused for all links occuring in that link thread.
47 * context Returns a pointer to the new context object
48 * allocate callback Callback to allocate memory for the linked kext
49 * log_callback Callback for all kxld logging output
50 * flags Flags to control the behavior of kxld
51 * cputype The target arch's CPU type (0 for host arch)
52 * cpusubtype The target arch's CPU subtype (0 for host subtype)
53 * pagesize The target page size (0 for host page size)
54 *******************************************************************************/
55 kern_return_t kxld_create_context(
56 KXLDContext **context,
57 KXLDAllocateCallback allocate_callback,
58 KXLDLoggingCallback log_callback,
59 KXLDFlags flags,
60 cpu_type_t cputype,
61 cpu_subtype_t cpusubtype,
62 vm_size_t pagesize)
63 __attribute__((nonnull(1,2),visibility("default")));
64
65 /*******************************************************************************
66 * Destroys a link context and frees all associated memory. Should be called at
67 * the end of a link thread's life.
68 *******************************************************************************/
69 void kxld_destroy_context(
70 KXLDContext *context)
71 __attribute__((nonnull,visibility("default")));
72
73 /*******************************************************************************
74 * Links a kext against its dependencies, using a callback to allocate the memory
75 * at which it will be located.
76 * NOTE: The object data itself must be mmapped with PROT_WRITE and MAP_PRIVATE
77 * context The KXLDContext object for the current link thread.
78 * file The kext object file read into memory.
79 * Supported formats: Mach-O, Mach-O64, Fat.
80 * size The size of the kext in memory. Must be nonzero.
81 * name The name, usually the bundle identifier, of the kext
82 * callback_data Data that is to be passed to the callback functions.
83 * dependencies An array of pointers to the kexts upon which this kext
84 * is dependent.
85 * num_dependencies Number of entries in the 'dependencies' array.
86 * linked_object This will be set to the address of the linked kext
87 * object. If the address provided by the
88 * kxld_alloc_callback is considered writable, this
89 * pointer will be set to that address. Otherwise, the
90 * linked object will be written to a temporary buffer
91 * that should be freed by the caller.
92 * kmod_info_kern Kernel address of the kmod_info_t structure.
93 ******************************************************************************/
94 kern_return_t kxld_link_file(
95 KXLDContext *context,
96 u_char *file,
97 u_long size,
98 const char *name,
99 void *callback_data,
100 KXLDDependency *dependencies,
101 u_int num_dependencies,
102 u_char **linked_object,
103 kxld_addr_t *kmod_info_kern)
104 __attribute__((nonnull(1,2,4,6,8,9), visibility("default")));
105
106 /*******************************************************************************
107 *******************************************************************************/
108 boolean_t kxld_validate_copyright_string(const char *str)
109 __attribute__((pure, nonnull, visibility("default")));
110
111 #endif // _KXLD_H_
112