]>
Commit | Line | Data |
---|---|---|
b0d623f7 A |
1 | /* |
2 | * Copyright (c) 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_STATE_H_ | |
29 | #define _KXLD_STATE_H_ | |
30 | ||
31 | #include <sys/types.h> | |
32 | #if KERNEL | |
33 | #include <libkern/kxld_types.h> | |
34 | #else | |
35 | #include "kxld_types.h" | |
36 | #endif | |
37 | ||
38 | #include "kxld_array.h" | |
39 | #include "kxld_util.h" | |
40 | ||
41 | struct kxld_dict; | |
42 | struct kxld_kext; | |
43 | struct kxld_link_state_hdr; | |
44 | typedef struct kxld_state KXLDState; | |
45 | typedef struct kxld_link_state_hdr KXLDLinkStateHdr; | |
46 | typedef struct kxld_vtable_hdr KXLDVTableHdr; | |
47 | typedef struct kxld_sym_entry_32 KXLDSymEntry32; | |
48 | typedef struct kxld_sym_entry_64 KXLDSymEntry64; | |
49 | ||
50 | struct kxld_state { | |
51 | u_char *file; | |
52 | KXLDArray vtables; | |
53 | boolean_t swap; | |
54 | }; | |
55 | ||
56 | /* | |
57 | * The format of the link state object is as follows: | |
58 | ||
59 | * Field *** Type * | |
60 | ************************************************** | |
61 | * Link state header *** KXLDLinkStateHdr * | |
62 | ************************************************** | |
63 | * Section order entries *** KXLDSectionName * | |
64 | ************************************************** | |
65 | * Vtable headers *** KXLDVTableHdr * | |
66 | ************************************************** | |
67 | * VTables *** KXLDSymEntry[32|64] * | |
68 | ************************************************** | |
69 | * Exported symbols *** KXLDSymEntry[32|64] * | |
70 | ************************************************** | |
71 | * String table *** char[] * | |
72 | ************************************************** | |
73 | ||
74 | */ | |
75 | ||
76 | struct kxld_link_state_hdr { | |
77 | uint32_t magic; | |
78 | uint32_t version; | |
79 | cpu_type_t cputype; | |
80 | cpu_subtype_t cpusubtype; | |
81 | uint32_t nsects; | |
82 | uint32_t sectoff; | |
83 | uint32_t nvtables; | |
84 | uint32_t voff; | |
85 | uint32_t nsyms; | |
86 | uint32_t symoff; | |
87 | }; | |
88 | ||
89 | struct kxld_vtable_hdr { | |
90 | uint32_t nameoff; | |
91 | uint32_t vtableoff; | |
92 | uint32_t nentries; | |
93 | }; | |
94 | ||
95 | struct kxld_sym_entry_32 { | |
96 | uint32_t addr; | |
97 | uint32_t nameoff; | |
98 | uint32_t flags; | |
99 | }; | |
100 | ||
101 | struct kxld_sym_entry_64 { | |
102 | uint64_t addr; | |
103 | uint32_t nameoff; | |
104 | uint32_t flags; | |
105 | } __attribute__((aligned(16))); | |
106 | ||
107 | #define KXLD_SYM_OBSOLETE 0x1 | |
108 | ||
109 | /******************************************************************************* | |
110 | * Constructors and destructors | |
111 | *******************************************************************************/ | |
112 | ||
113 | kern_return_t kxld_state_init_from_file(KXLDState *state, u_char *file, | |
114 | KXLDArray *section_order) | |
115 | __attribute__((nonnull(1,2), visibility("hidden"))); | |
116 | ||
117 | void kxld_state_clear(KXLDState *state) | |
118 | __attribute__((nonnull, visibility("hidden"))); | |
119 | ||
120 | void kxld_state_deinit(KXLDState *state) | |
121 | __attribute__((nonnull, visibility("hidden"))); | |
122 | ||
123 | /******************************************************************************* | |
124 | * Accessors | |
125 | *******************************************************************************/ | |
126 | ||
127 | u_int kxld_state_get_num_symbols(KXLDState *state) | |
128 | __attribute__((pure, nonnull, visibility("hidden"))); | |
129 | ||
130 | kern_return_t kxld_state_get_symbols(KXLDState *state, | |
131 | struct kxld_dict *defined_symbols, | |
132 | struct kxld_dict *obsolete_symbols) | |
133 | __attribute__((nonnull, visibility("hidden"))); | |
134 | ||
135 | u_int kxld_state_get_num_vtables(KXLDState *state) | |
136 | __attribute__((pure, nonnull, visibility("hidden"))); | |
137 | ||
138 | kern_return_t kxld_state_get_vtables(KXLDState *state, | |
139 | struct kxld_dict *patched_vtables) | |
140 | __attribute__((nonnull, visibility("hidden"))); | |
141 | ||
142 | void kxld_state_get_cputype(const KXLDState *state, | |
143 | cpu_type_t *cputype, cpu_subtype_t *cpusubtype) | |
144 | __attribute__((nonnull, visibility("hidden"))); | |
145 | ||
146 | /******************************************************************************* | |
147 | * Exporters | |
148 | *******************************************************************************/ | |
149 | ||
150 | kern_return_t kxld_state_export_kext_to_file(struct kxld_kext *kext, u_char **file, | |
151 | u_long *filesize, struct kxld_dict *tmpdict, KXLDArray *tmps) | |
152 | __attribute__((nonnull, visibility("hidden"))); | |
153 | ||
154 | #endif /* _KXLD_STATE_H_ */ | |
155 |