2 * Copyright (c) 2007-2008 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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>
37 #include "kxld_types.h"
39 /*******************************************************************************
41 *******************************************************************************/
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 *******************************************************************************/
54 kern_return_t
kxld_create_context(
55 KXLDContext
**context
,
56 KXLDAllocateCallback allocate_callback
,
57 KXLDLoggingCallback log_callback
,
60 cpu_subtype_t cpusubtype
)
61 __attribute__((nonnull(1,2),visibility("default")));
63 /*******************************************************************************
64 * Destroys a link context and frees all associated memory. Should be called at
65 * the end of a link thread's life.
66 *******************************************************************************/
67 void kxld_destroy_context(
69 __attribute__((nonnull
,visibility("default")));
71 /*******************************************************************************
72 * Links a kext against its dependencies, using a callback to allocate the memory
73 * at which it will be located.
74 * NOTE: The object data itself must be mmapped with PROT_WRITE and MAP_PRIVATE
75 * context The KXLDContext object for the current link thread.
76 * file The kext object file read into memory.
77 * Supported formats: Mach-O, Mach-O64, Fat.
78 * size The size of the kext in memory. Must be nonzero.
79 * name The name, usually the bundle identifier, of the kext
80 * callback_data Data that is to be passed to the callback functions.
81 * deps An array of pointers to the link state of kexts upon
82 * which this kext is dependent.
83 * ndeps Number of entries in the 'deps' array.
84 * linked_object If this is not null, it will be set to the address of
85 * the linked kext object. If the address provided by the
86 * kxld_alloc_callback is considered writable, this pointer
87 * will be set to that address. Otherwise, the linked
88 * object will be written to a temporary buffer that should
89 * be freed by the caller.
90 * kmod_info_kern Kernel address of the kmod_info_t structure.
91 * link_state If this is not null, it will be set to the address of a
92 * block of memory that contains state generated by the
93 * linking process for use by links of dependent kexts.
94 * The link state object is serialized and can be written
95 * directly to disk. This memory should be freed by the
96 * caller when no longer needed.
97 * link_state_size The size of the returned link state buffer.
98 * symbol_file If this is not null, it will be set to the address of a
99 * buffer containing a Mach-O symbol file that may be
100 * written to disk. This should be freed by the caller
101 * when no longer needed.
102 * Note: symbol files are never generated in the kernel
103 * symbol_file_size The size of the returned symbol file buffer.
104 *******************************************************************************/
105 kern_return_t
kxld_link_file(
106 KXLDContext
*context
,
113 u_char
**linked_object
,
114 kxld_addr_t
*kmod_info_kern
,
116 u_long
*link_state_size
,
117 u_char
**symbol_file
,
118 u_long
*symbol_file_size
)
119 __attribute__((nonnull(1, 2), visibility("default")));
121 /*******************************************************************************
122 *******************************************************************************/
123 boolean_t
kxld_validate_copyright_string(const char *str
)
124 __attribute__((pure
, nonnull
, visibility("default")));