-
Notifications
You must be signed in to change notification settings - Fork 0
/
kcgen_main.h
234 lines (194 loc) · 8.33 KB
/
kcgen_main.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
* kcgen_main.h
* kext_tools
*
* Created by nik on 5/20/08.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*
*/
#ifndef _KCGEN_MAIN_H
#define _KCGEN_MAIN_H
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/kext/OSKext.h>
#include <getopt.h>
#include <sysexits.h>
#include <IOKit/kext/OSKext.h>
#include "kext_tools_util.h"
#include "kernelcache.h"
#pragma mark Basic Types & Constants
/*******************************************************************************
* Constants
*******************************************************************************/
enum {
kKcgenExitOK = EX_OK,
kKcgenExitNotFound,
kKcgenExitArchNotFound,
kKcgenExitKextBad,
kKcgenExitStale,
// don't think we use it
kKcgenExitUnspecified = 11,
// don't actually exit with this, it's just a sentinel value
kKcgenExitHelp = 33,
kKcgenExitNoStart
};
#pragma mark Command-line Option Definitions
/*******************************************************************************
* Command-line options. This data is used by getopt_long_only().
*
* Options common to all kext tools are in kext_tools_util.h.
*******************************************************************************/
// kOptNameBundleIdentifier in kext_tools_util.h
// kOptNameSystemExtensions in kext_tools_util.h
#define kOptNameOptionalBundleIdentifier "optional-bundle-id"
/* Prelinked-kernel-generation flags.
*/
#define kOptNamePrelinkedKernel "prelinked-kernel"
#define kOptNameSystemPrelinkedKernel "system-prelinked-kernel"
#define kOptNameKernel "kernel"
#define kOptNameAllLoaded "all-loaded"
#define kOptNameSymbols "symbols"
#define kOptNameVolumeRoot "volume-root"
/* Embedded prelinked-kernel-generation flags.
*/
#define kOptNameAllPersonalities "all-personalities"
#define kOptNameNoLinkFailures "no-link-failures"
#define kOptNameStripSymbols "strip-symbols"
#define kOptNameMaxSliceSize "max-slice-size"
/* Misc flags.
*/
#define kOptNameNoAuthentication "no-authentication"
#define kOptNameTests "print-diagnostics"
#define kOptNameCompressed "compressed"
#define kOptNameUncompressed "uncompressed"
#define kOptArch 'a'
// 'b' in kext_tools_util.h
#define kOptPrelinkedKernel 'c'
// 'h' in kext_tools_util.h
#define kOptKernel 'K'
// 'q' in kext_tools_util.h
#define kOptTests 't'
// 'v' in kext_tools_util.h
#define kOptNoAuthentication 'z'
/* Options with no single-letter variant. */
// Do not use -1, that's getopt() end-of-args return value
// and can cause confusion
#define kLongOptLongindexHack (-2)
#define kLongOptOptionalBundleIdentifier (-3)
#define kLongOptCompressed (-5)
#define kLongOptUncompressed (-6)
#define kLongOptSymbols (-7)
#define kLongOptVolumeRoot (-10)
#define kLongOptAllPersonalities (-11)
#define kLongOptNoLinkFailures (-12)
#define kLongOptStripSymbols (-13)
#define kLongOptMaxSliceSize (-14)
#define kOptChars ":a:b:c:ehK:lLnNqsStvz"
int longopt = 0;
struct option sOptInfo[] = {
{ kOptNameLongindexHack, no_argument, &longopt, kLongOptLongindexHack },
{ kOptNameHelp, no_argument, NULL, kOptHelp },
{ kOptNameQuiet, no_argument, NULL, kOptQuiet },
{ kOptNameVerbose, optional_argument, NULL, kOptVerbose },
{ kOptNameCompressed, optional_argument, &longopt, kLongOptCompressed },
{ kOptNameUncompressed, no_argument, &longopt, kLongOptUncompressed },
{ kOptNameArch, required_argument, NULL, kOptArch },
{ kOptNameVolumeRoot, required_argument, &longopt, kLongOptVolumeRoot },
{ kOptNameBundleIdentifier, required_argument, NULL, kOptBundleIdentifier },
{ kOptNameOptionalBundleIdentifier, required_argument, &longopt, kLongOptOptionalBundleIdentifier },
{ kOptNamePrelinkedKernel, optional_argument, NULL, kOptPrelinkedKernel },
{ kOptNameKernel, required_argument, NULL, kOptKernel },
{ kOptNameSymbols, required_argument, &longopt, kLongOptSymbols },
{ kOptNameTests, no_argument, NULL, kOptTests },
{ kOptNameMaxSliceSize, required_argument, &longopt, kLongOptMaxSliceSize },
/* Always on for kcgen; can be removed at some point. */
{ kOptNameAllPersonalities, no_argument, &longopt, kLongOptAllPersonalities },
{ kOptNameNoLinkFailures, no_argument, &longopt, kLongOptNoLinkFailures },
{ kOptNameStripSymbols, no_argument, &longopt, kLongOptStripSymbols },
{ kOptNameNoAuthentication, no_argument, NULL, kOptNoAuthentication },
{ NULL, 0, NULL, 0 } // sentinel to terminate list
};
typedef struct {
Boolean printTestResults; // -t
char * prelinkedKernelPath; // -c option
Boolean generatePrelinkedSymbols; // -symbols option
Boolean stripSymbols; // -strip-symbols option
CFIndex maxSliceSize;
CFURLRef compressedPrelinkedKernelURL; // -uncompress option
char * kernelPath; // overriden by -K option
CFDataRef kernelFile; // contents of kernelURL
CFURLRef symbolDirURL; // -s option;
CFURLRef volumeRootURL;
CFMutableSetRef kextIDs; // -b; must release
CFMutableSetRef optionalKextIDs; // -optional-bundle-id; must release
CFMutableArrayRef argURLs; // directories & kexts in order
CFMutableArrayRef repositoryURLs; // just non-kext directories
CFMutableArrayRef namedKextURLs;
CFMutableArrayRef targetArchs;
CFArrayRef allKexts; // directories + named
CFArrayRef repositoryKexts; // all from directories (may include named)
CFArrayRef namedKexts;
Boolean compress;
uint32_t compressionType;
Boolean uncompress;
} KcgenArgs;
#pragma mark Function Prototypes
/*******************************************************************************
* Function Prototypes
*******************************************************************************/
ExitStatus readArgs(
int * argc,
char * const ** argv,
KcgenArgs * toolArgs);
const NXArchInfo * addArchForName(
KcgenArgs * toolArgs,
const char * archname);
ExitStatus readPrelinkedKernelArgs(
KcgenArgs * toolArgs,
int argc,
char * const * argv,
Boolean isLongopt);
ExitStatus setPrelinkedKernelArgs(
KcgenArgs * toolArgs,
char * filename);
ExitStatus checkArgs(KcgenArgs * toolArgs);
ExitStatus writeFatFile(
const char * filePath,
CFArrayRef fileSlices,
CFArrayRef fileArchs,
mode_t fileMode,
const struct timeval fileTimes[2]);
ExitStatus checkKextForProblems(
KcgenArgs * toolArgs,
OSKextRef theKext,
const NXArchInfo * arch);
ExitStatus filterKextsForCache(
KcgenArgs * toolArgs,
CFMutableArrayRef kextArray,
const NXArchInfo * arch,
Boolean * fatalOut);
ExitStatus createPrelinkedKernelArchs(
KcgenArgs * toolArgs,
CFMutableArrayRef * prelinkArchsOut);
ExitStatus createExistingPrelinkedSlices(
KcgenArgs * toolArgs,
CFMutableArrayRef * prelinkedSlicesOut,
CFMutableArrayRef * prelinkedArchsOut);
ExitStatus createPrelinkedKernel(
KcgenArgs * toolArgs);
CFArrayRef mergeArchs(
CFArrayRef archSet1,
CFArrayRef archSet2);
ExitStatus createPrelinkedKernelForArch(
KcgenArgs * toolArgs,
CFDataRef * prelinkedKernelOut,
CFDictionaryRef * prelinkedSymbolsOut,
const NXArchInfo * archInfo);
ExitStatus compressPrelinkedKernel(
const char * prelinkedKernelPath,
Boolean compress,
uint32_t compressionType);
void logUsedKexts(
KcgenArgs * toolArgs,
CFArrayRef prelinkKexts);
void usage(UsageLevel usageLevel);
#endif /* _KCGEN_MAIN_H */