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@
33 #include <mach/boolean.h> // boolean_t
34 #include <mach/kern_return.h>
36 /*******************************************************************************
38 *******************************************************************************/
40 /* For 32-bit-specific linking code */
41 #if (!KERNEL || !__LP64__)
42 #define KXLD_USER_OR_ILP32 1
45 /* For 64-bit-specific linking code */
46 #if (!KERNEL || __LP64__)
47 #define KXLD_USER_OR_LP64 1
50 /* For ppc-specific linking code */
51 #if (!KERNEL || __ppc__)
52 #define KXLD_USER_OR_PPC 1
55 /* For i386-specific linking code */
56 #if (!KERNEL || __i386__)
57 #define KXLD_USER_OR_I386 1
60 /* For x86_64-specific linking code */
61 #if (!KERNEL || __x86_64__)
62 #define KXLD_USER_OR_X86_64 1
65 /* For arm-specific linking code */
66 #if (!KERNEL || __arm__)
67 #define KXLD_USER_OR_ARM 1
70 /* For linking code specific to architectures that support common symbols */
71 #if (!KERNEL || __i386__ || __ppc__)
72 #define KXLD_USER_OR_COMMON 1
75 /* For linking code specific to architectures that support strict patching */
76 #if (!KERNEL || !(__i386__ || __ppc__))
77 #define KXLD_USER_OR_STRICT_PATCHING 1
80 /* For linking code specific to architectures that use MH_OBJECT */
81 #if (!KERNEL || __i386__ || __ppc__ || __arm__)
82 #define KXLD_USER_OR_OBJECT 1
85 /* For linking code specific to architectures that use MH_KEXT_BUNDLE */
86 #if (!KERNEL || __i386__ || __x86_64__ || __arm__)
87 #define KXLD_USER_OR_BUNDLE 1
90 /* We no longer need to generate our own GOT for any architectures, but the code
91 * required to do this will be saved inside this macro.
93 #define KXLD_USER_OR_GOT 0
95 /*******************************************************************************
97 *******************************************************************************/
99 /* Maintains linker state across links. One context should be allocate for
102 typedef struct kxld_context KXLDContext
;
104 /* Unless we're in a 32-bit kernel, all internal math is performed in 64 bits
105 * and cast to smaller values as needed by the architecture for which we are
106 * linking. All returned arguments should be handled similarly.
107 * Note: This size can be increased for future architectural size increases
109 #if KERNEL && !__LP64__
110 typedef uint32_t kxld_addr_t
;
111 typedef uint32_t kxld_size_t
;
113 typedef uint64_t kxld_addr_t
;
114 typedef uint64_t kxld_size_t
;
115 #endif /* KERNEL && !__LP64__ */
117 /* Flags for general linker behavior */
119 kKxldFlagDefault
= 0x0,
121 typedef enum kxld_flags KXLDFlags
;
123 /* Flags for the allocation callback */
124 enum kxld_allocate_flags
{
125 kKxldAllocateDefault
= 0x0,
126 kKxldAllocateWritable
= 0x1, /* kxld may write into the allocated memory */
128 typedef enum kxld_allocate_flags KXLDAllocateFlags
;
130 /* This specifies the function type of the callback that the linker uses to get
131 * the base address and allocated memory for relocation and linker output,
132 * respectively. Note that it is compatible with the standard allocators (e.g.
135 typedef kxld_addr_t (*KXLDAllocateCallback
)(size_t size
,
136 KXLDAllocateFlags
*flags
, void *user_data
);
138 /* Flags for the logging callback */
139 typedef enum kxld_log_subsystem
{
140 kKxldLogLinking
= 0x0,
141 kKxldLogPatching
= 0x01
144 typedef enum kxld_log_level
{
145 kKxldLogExplicit
= 0x0,
149 kKxldLogDetail
= 0x4,
153 /* This structure is used to describe a dependency kext. The kext field
154 * is a pointer to the binary executable of the dependency. The interface
155 * field is a pointer to an optional interface kext that restricts the
156 * symbols that may be accessed in the dependency kext.
158 * For example, to use this structure with the KPIs, set the kext field
159 * to point to the kernel's Mach-O binary, and set interface to point
160 * to the KPI's Mach-O binary.
162 typedef struct kxld_dependency
{
167 u_long interface_size
;
168 char * interface_name
;
169 boolean_t is_direct_dependency
;
172 typedef void (*KXLDLoggingCallback
) (KXLDLogSubsystem sys
, KXLDLogLevel level
,
173 const char *format
, va_list ap
, void *user_data
);
175 #endif /* _KXLD_TYPES_H */