]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/kxld_types.h
xnu-1456.1.26.tar.gz
[apple/xnu.git] / libkern / libkern / kxld_types.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_TYPES_H
29 #define _KXLD_TYPES_H
30
31 #include <stdarg.h>
32 #include <stdint.h>
33 #include <mach/kern_return.h>
34
35 /*******************************************************************************
36 * Macros
37 *******************************************************************************/
38
39 /* For 32-bit-specific linking code */
40 #if (!KERNEL || !__LP64__)
41 #define KXLD_USER_OR_ILP32 1
42 #endif
43
44 /* For 64-bit-specific linking code */
45 #if (!KERNEL || __LP64__)
46 #define KXLD_USER_OR_LP64 1
47 #endif
48
49 /* For ppc-specific linking code */
50 #if (!KERNEL || __ppc__)
51 #define KXLD_USER_OR_PPC 1
52 #endif
53
54 /* For i386-specific linking code */
55 #if (!KERNEL || __i386__)
56 #define KXLD_USER_OR_I386 1
57 #endif
58
59 /* For x86_64-specific linking code */
60 #if (!KERNEL || __x86_64__)
61 #define KXLD_USER_OR_X86_64 1
62 #endif
63
64 /* For arm-specific linking code */
65 #if (!KERNEL || __arm__)
66 #define KXLD_USER_OR_ARM 1
67 #endif
68
69 /* For linking code specific to architectures that support common symbols */
70 #if (!KERNEL || __i386__ || __ppc__)
71 #define KXLD_USER_OR_COMMON 1
72 #endif
73
74 /* For linking code specific to architectures that support strict patching */
75 #if (!KERNEL || !(__i386__ || __ppc__))
76 #define KXLD_USER_OR_STRICT_PATCHING 1
77 #endif
78
79 /* For linking code specific to architectures that use MH_OBJECT */
80 #if (!KERNEL || __i386__ || __ppc__ || __arm__)
81 #define KXLD_USER_OR_OBJECT 1
82 #endif
83
84 /* For linking code specific to architectures that use MH_KEXT_BUNDLE */
85 #if (!KERNEL || __x86_64__)
86 #define KXLD_USER_OR_BUNDLE 1
87 #endif
88
89 /* We no longer need to generate our own GOT for any architectures, but the code
90 * required to do this will be saved inside this macro.
91 */
92 #define KXLD_USER_OR_GOT 0
93
94 /*******************************************************************************
95 * Types
96 *******************************************************************************/
97
98 /* Maintains linker state across links. One context should be allocate for
99 * each link thread.
100 */
101 typedef struct kxld_context KXLDContext;
102
103 /* Unless we're in a 32-bit kernel, all internal math is performed in 64 bits
104 * and cast to smaller values as needed by the architecture for which we are
105 * linking. All returned arguments should be handled similarly.
106 * Note: This size can be increased for future architectural size increases
107 */
108 #if KERNEL && !__LP64__
109 typedef uint32_t kxld_addr_t;
110 typedef uint32_t kxld_size_t;
111 #else
112 typedef uint64_t kxld_addr_t;
113 typedef uint64_t kxld_size_t;
114 #endif /* KERNEL && !__LP64__ */
115
116 /* Flags for general linker behavior */
117 enum kxld_flags {
118 kKxldFlagDefault = 0x0
119 };
120 typedef enum kxld_flags KXLDFlags;
121
122 /* Flags for the allocation callback */
123 enum kxld_allocate_flags {
124 kKxldAllocateDefault = 0x0,
125 kKxldAllocateWritable = 0x1 /* kxld may write into the allocated memory */
126 };
127 typedef enum kxld_allocate_flags KXLDAllocateFlags;
128
129 /* This specifies the function type of the callback that the linker uses to get
130 * the base address and allocated memory for relocation and linker output,
131 * respectively. Note that it is compatible with the standard allocators (e.g.
132 * malloc).
133 */
134 typedef kxld_addr_t (*KXLDAllocateCallback)(size_t size,
135 KXLDAllocateFlags *flags, void *user_data);
136
137 /* Flags for the logging callback */
138 typedef enum kxld_log_subsystem {
139 kKxldLogLinking = 0x0,
140 kKxldLogPatching = 0x01
141 } KXLDLogSubsystem;
142
143 typedef enum kxld_log_level {
144 kKxldLogExplicit = 0x0,
145 kKxldLogErr = 0x1,
146 kKxldLogWarn = 0x2,
147 kKxldLogBasic = 0x3,
148 kKxldLogDetail = 0x4,
149 kKxldLogDebug = 0x5
150 } KXLDLogLevel;
151
152 typedef void (*KXLDLoggingCallback) (KXLDLogSubsystem sys, KXLDLogLevel level,
153 const char *format, va_list ap, void *user_data);
154
155 #endif /* _KXLD_TYPES_H */
156