Chameleon

Chameleon Commit Details

Date:2011-07-05 02:02:28 (12 years 9 months ago)
Author:Evan Lojewski
Commit:1108
Parents: 1107
Message:Modify kext laoding behaviour. Nolonger uses OSBundleRequired property (for now).
Changes:
M/trunk/i386/boot2/drivers.c
M/trunk/i386/boot2/boot.c
M/trunk/i386/boot2/options.c

File differences

trunk/i386/boot2/drivers.c
8888
8989
9090
91
92
93
94
95
91
92
93
94
95
96
9697
9798
9899
......
102103
103104
104105
105
106
106107
107108
108109
......
296297
297298
298299
299
300
300301
301302
302303
......
354355
355356
356357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
357417
358418
359419
360
420
361421
362422
363423
......
393453
394454
395455
396
456
397457
398458
399459
......
439499
440500
441501
442
502
443503
444504
445505
......
453513
454514
455515
456
516
457517
518
519
458520
459521
460522
461523
462
463524
464525
465
526
527
466528
467529
468530
......
472534
473535
474536
475
537
476538
539
540
477541
478542
479543
480
481544
482545
483546
484
485547
486548
487549
488550
489551
490552
491
492553
493554
494555
......
498559
499560
500561
501
502562
503563
504564
......
546606
547607
548608
549
609
550610
551611
552612
......
589649
590650
591651
652
653
654
592655
593656
594657
......
721784
722785
723786
724
787
725788
726789
727790
......
741804
742805
743806
744
745
746
747
807
808
748809
810
749811
750812
751813
814
752815
753816
754817
/*static*/ unsigned long Adler32( unsigned char * buffer, long length );
static long FileLoadDrivers(char *dirSpec, long plugin);
static long NetLoadDrivers(char *dirSpec);
static long LoadDriverMKext(char *fileSpec);
static long LoadDriverPList(char *dirSpec, char *name, long bundleType);
static long LoadMatchedModules(void);
long FileLoadDrivers(char *dirSpec, long plugin);
long NetLoadDrivers(char *dirSpec);
long LoadDriverMKext(char *fileSpec);
long LoadDriverPList(char *dirSpec, char *name, long bundleType);
long LoadMatchedModules(void);
static long MatchPersonalities(void);
static long MatchLibraries(void);
#ifdef NOTDEF
static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities);
static long InitDriverSupport(void);
static ModulePtr gModuleHead, gModuleTail;
ModulePtr gModuleHead, gModuleTail;
static TagPtr gPersonalityHead, gPersonalityTail;
static char * gExtensionsSpec;
static char * gDriverSpec;
//==========================================================================
// FileLoadDrivers
static long
long
FileLoadDrivers( char * dirSpec, long plugin )
{
long ret, length, flags, time, bundleType;
return result;
}
long
FileLoadDriver( char * dirSpec, long plugin )
{
long ret, length, flags, time, bundleType;
long long index;
long result = -1;
const char * name;
if ( !plugin )
{
// First try 10.6's path for loading Extensions.mkext.
if (FileLoadMKext(dirSpec, "Caches/com.apple.kext.caches/Startup/") == 0)
return 0;
// Next try the legacy path.
else if (FileLoadMKext(dirSpec, "") == 0)
return 0;
strcat(dirSpec, "Extensions");
}
index = 0;
while (1) {
ret = GetDirEntry(dirSpec, &index, &name, &flags, &time);
if (ret == -1) break;
// Make sure this is a directory.
if ((flags & kFileTypeMask) != kFileTypeDirectory) continue;
// Make sure this is a kext.
length = strlen(name);
if (strcmp(name + length - 5, ".kext")) continue;
// Save the file name.
strcpy(gFileName, name);
// Determine the bundle type.
sprintf(gTempSpec, "%s/%s", dirSpec, gFileName);
ret = GetFileInfo(gTempSpec, "Contents", &flags, &time);
if (ret == 0) bundleType = kCFBundleType2;
else bundleType = kCFBundleType3;
if (!plugin)
sprintf(gDriverSpec, "%s/%s/%sPlugIns", dirSpec, gFileName,
(bundleType == kCFBundleType2) ? "Contents/" : "");
ret = LoadDriverPList(dirSpec, gFileName, bundleType);
if (result != 0)
result = ret;
if (!plugin)
FileLoadDrivers(gDriverSpec, 1);
}
return result;
}
//==========================================================================
//
static long
long
NetLoadDrivers( char * dirSpec )
{
long tries;
//==========================================================================
// loadDriverMKext
static long
long
LoadDriverMKext( char * fileSpec )
{
unsigned long driversAddr, driversLength;
//==========================================================================
// LoadDriverPList
static long
long
LoadDriverPList( char * dirSpec, char * name, long bundleType )
{
long length, executablePathLength, bundlePathLength;
do {
// Save the driver path.
sprintf(gFileSpec, "%s/%s/%s", dirSpec, name,
if(name) sprintf(gFileSpec, "%s/%s/%s", dirSpec, name,
(bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");
else sprintf(gFileSpec, "%s/%s", dirSpec,
(bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");
executablePathLength = strlen(gFileSpec) + 1;
tmpExecutablePath = malloc(executablePathLength);
if (tmpExecutablePath == 0) break;
strcpy(tmpExecutablePath, gFileSpec);
sprintf(gFileSpec, "%s/%s", dirSpec, name);
if(name) sprintf(gFileSpec, "%s/%s", dirSpec, name);
else sprintf(gFileSpec, "%s", dirSpec);
bundlePathLength = strlen(gFileSpec) + 1;
tmpBundlePath = malloc(bundlePathLength);
// Construct the file spec to the plist, then load it.
sprintf(gFileSpec, "%s/%s/%sInfo.plist", dirSpec, name,
if(name) sprintf(gFileSpec, "%s/%s/%sInfo.plist", dirSpec, name,
(bundleType == kCFBundleType2) ? "Contents/" : "");
else sprintf(gFileSpec, "%s/%sInfo.plist", dirSpec,
(bundleType == kCFBundleType2) ? "Contents/" : "");
length = LoadFile(gFileSpec);
if (length == -1) break;
length = length + 1;
buffer = malloc(length);
if (buffer == 0) break;
strlcpy(buffer, (char *)kLoadAddr, length);
// Parse the plist.
ret = ParseXML(buffer, &module, &personalities);
if (ret != 0) { break; }
// Allocate memory for the driver path and the plist.
module->executablePath = tmpExecutablePath;
if ((module->executablePath == 0) || (module->bundlePath == 0) || (module->plistAddr == 0))
break;
// Save the driver path in the module.
//strcpy(module->driverPath, tmpDriverPath);
tmpExecutablePath = 0;
//==========================================================================
// LoadMatchedModules
static long
long
LoadMatchedModules( void )
{
TagPtr prop;
//}
// Make make in the image area.
execute_hook("LoadMatchedModules", module, &length, executableAddr, NULL);
driverLength = sizeof(DriverInfo) + module->plistLength + length + module->bundlePathLength;
driverAddr = AllocateKernelMemory(driverLength);
ParseXML( char * buffer, ModulePtr * module, TagPtr * personalities )
{
long length, pos;
TagPtr moduleDict, required;
TagPtr moduleDict;
ModulePtr tmpModule;
pos = 0;
if (length == -1) return -1;
required = XMLGetProperty(moduleDict, kPropOSBundleRequired);
if ( (required == 0) ||
(required->type != kTagTypeString) ||
!strcmp(required->string, "Safe Boot"))
#if 0 /** remove this check. **/
if (strcmp(XMLCastString(XMLGetProperty(moduleDict, kPropOSBundleRequired)), "Safe Boot") == 0)
{
// Don't load Safe Boot kexts. NOTE: -x should be check too.
XMLFreeTag(moduleDict);
return -2;
}
#endif
tmpModule = malloc(sizeof(Module));
if (tmpModule == 0)
trunk/i386/boot2/boot.c
148148
149149
150150
151
152
151153
152154
153155
154156
155
157
158
156159
157160
158161
......
160163
161164
162165
163
164
165
166
166167
167168
168169
......
370371
371372
372373
373
374
374375
375376
376377
......
432433
433434
434435
435
436
436437
437438
438439
// Notify modules that the kernel has been decoded
execute_hook("DecodedKernel", (void*)binary, NULL, NULL, NULL);
setupFakeEfi();
// Load boot drivers from the specifed root path.
//if (!gHaveKernelCache)
LoadDrivers("/");
execute_hook("DriversLoaded", (void*)binary, NULL, NULL, NULL);
clearActivityIndicator();
if (gErrors) {
printf("Pausing %d seconds...\n", kBootErrorTimeout);
sleep(kBootErrorTimeout);
}
setupFakeEfi();
md0Ramdisk();
verbose("Starting Darwin %s\n",( archCpuType == CPU_TYPE_I386 ) ? "x86" : "x86_64");
bool tryresume;
bool tryresumedefault;
bool forceresume;
bool usecache = false; //true;
bool usecache = false;// true;
// additional variable for testing alternate kernel image locations on boot helper partitions.
char bootFileSpec[512];
archCpuType = CPU_TYPE_I386;
}
}
//archCpuType = CPU_TYPE_I386;
archCpuType = CPU_TYPE_I386;
// Notify moduals that we are attempting to boot
execute_hook("PreBoot", NULL, NULL, NULL, NULL);
trunk/i386/boot2/options.c
11841184
11851185
11861186
1187
1187
11881188
11891189
11901190
// Load com.apple.Boot.plist from the selected volume
// and use its contents to override default bootConfig.
loadSystemConfig(&bootInfo->overrideConfig);
loadSystemConfig(&bootInfo->bootConfig);
// Use the kernel name specified by the user, or fetch the name
// in the config table, or use the default if not specified.

Archive Download the corresponding diff file

Revision: 1108