Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazi/i386/boot2/drivers.c

1/*
2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 2.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/*
25 * drivers.c - Driver Loading Functions.
26 *
27 * Copyright (c) 2000 Apple Computer, Inc.
28 *
29 * DRI: Josh de Cesare
30 */
31
32#include <mach-o/fat.h>
33#include <libkern/OSByteOrder.h>
34#include <mach/machine.h>
35
36//#include "bootstruct.h"
37//#include "ramdisk.h"
38#include "boot.h"
39#include "sl.h"
40#include "xml.h"
41
42struct Module {
43 struct Module *nextModule;
44 long willLoad;
45 TagPtr dict;
46 char *plistAddr;
47 long plistLength;
48 char *executablePath;
49 char *bundlePath;
50 long bundlePathLength;
51};
52typedef struct Module Module, *ModulePtr;
53
54struct DriverInfo {
55 char *plistAddr;
56 long plistLength;
57 void *executableAddr;
58 long executableLength;
59 void *bundlePathAddr;
60 long bundlePathLength;
61};
62typedef struct DriverInfo DriverInfo, *DriverInfoPtr;
63
64#define kDriverPackageSignature1 'MKXT'
65#define kDriverPackageSignature2 'MOSX'
66
67struct DriversPackage {
68 unsigned long signature1;
69 unsigned long signature2;
70 unsigned long length;
71 unsigned long alder32;
72 unsigned long version;
73 unsigned long numDrivers;
74 unsigned long reserved1;
75 unsigned long reserved2;
76};
77typedef struct DriversPackage DriversPackage;
78
79enum {
80 kCFBundleType2,
81 kCFBundleType3
82};
83
84long (*LoadExtraDrivers_p)(FileLoadDrivers_t FileLoadDrivers_p);
85
86static unsigned long Alder32( unsigned char * buffer, long length );
87
88static long FileLoadDrivers(char *dirSpec, long plugin);
89static long NetLoadDrivers(char *dirSpec);
90static long LoadDriverMKext(char *fileSpec);
91static long LoadDriverPList(char *dirSpec, char *name, long bundleType);
92static long LoadMatchedModules(void);
93static long MatchPersonalities(void);
94static long MatchLibraries(void);
95#ifdef NOTDEF
96static ModulePtr FindModule(char *name);
97static void ThinFatFile(void **loadAddrP, unsigned long *lengthP);
98#endif
99static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities);
100static long InitDriverSupport(void);
101
102static ModulePtr gModuleHead, gModuleTail;
103static TagPtr gPersonalityHead, gPersonalityTail;
104static char * gExtensionsSpec;
105static char * gDriverSpec;
106static char * gFileSpec;
107static char * gTempSpec;
108static char * gFileName;
109
110static unsigned long
111Alder32( unsigned char * buffer, long length )
112{
113 long cnt;
114 unsigned long result, lowHalf, highHalf;
115
116 lowHalf = 1;
117 highHalf = 0;
118
119for ( cnt = 0; cnt < length; cnt++ )
120 {
121 if ((cnt % 5000) == 0)
122 {
123 lowHalf %= 65521L;
124 highHalf %= 65521L;
125 }
126
127 lowHalf += buffer[cnt];
128 highHalf += lowHalf;
129 }
130
131lowHalf %= 65521L;
132highHalf %= 65521L;
133
134result = (highHalf << 16) | lowHalf;
135
136return result;
137}
138
139
140//==========================================================================
141// InitDriverSupport
142
143static long
144InitDriverSupport( void )
145{
146 gExtensionsSpec = malloc( 4096 );
147 gDriverSpec = malloc( 4096 );
148 gFileSpec = malloc( 4096 );
149 gTempSpec = malloc( 4096 );
150 gFileName = malloc( 4096 );
151
152 if ( !gExtensionsSpec || !gDriverSpec || !gFileSpec || !gTempSpec || !gFileName )
153 stop("InitDriverSupport error");
154
155 return 0;
156}
157
158//==========================================================================
159// LoadDrivers
160
161long LoadDrivers( char * dirSpec )
162{
163chardirSpecExtra[128];
164const char *override_pathfolder = NULL; // full path to a folder.
165intfd = 0, len = 0;
166
167if ( InitDriverSupport() != 0 )
168return 0;
169
170// Load extra drivers if a hook has been installed.
171if (LoadExtraDrivers_p != NULL)
172{
173(*LoadExtraDrivers_p)(&FileLoadDrivers);
174}
175
176if ( gBootFileType == kNetworkDeviceType )
177{
178if (NetLoadDrivers(dirSpec) != 0)
179{
180error("Could not load drivers from the network\n");
181return -1;
182}
183}
184else if ( gBootFileType == kBlockDeviceType )
185{
186// Take in account user overriding. - does this still work ???
187if (getValueForKey(kAltExtensionsKey, &override_pathfolder, &len, &bootInfo->bootConfig))
188{
189// Specify a path to a folder, ending with / e.g. kext=/Extra/testkext/
190strcpy(dirSpecExtra, override_pathfolder);
191fd = FileLoadDrivers(dirSpecExtra, 0);
192if (fd >= 0) goto success_fd;
193}
194
195// No need to specify (gRAMDiskVolume && !gRAMDiskBTAliased).
196// First try to load Extra extensions from a ramdisk if isn't aliased as bt(0,0).
197strcpy(dirSpecExtra, "rd(0,0)/"); // check it's "root".
198fd = FileLoadDrivers(dirSpecExtra, 0);
199if (fd >= 0) goto success_fd;
200
201// Also no need to specify (gRAMDiskVolume && gRAMDiskBTAliased); checking paths on a
202// ramdisk aliased as bt(0,0) (rdbt), is the same as checking paths on booter volume.
203// In this case the following two will point to the ramdisk.
204
205// Check booter volume/rdbt Extra for specific OS files, on specific OS folders.
206sprintf(dirSpecExtra, "bt(0,0)/Extra/%s/", &gMacOSVersion);
207fd = FileLoadDrivers(dirSpecExtra, 0);
208if (fd >= 0) goto success_fd;
209
210// Removed /Extra path from search algo. If needed can be specified with override key!
211
212// Check booter volume/rdbt Extra in case we don't keep specific OS folders.
213strcpy(dirSpecExtra, "bt(0,0)/Extra/");
214fd = FileLoadDrivers(dirSpecExtra, 0);
215if (fd >= 0) goto success_fd;
216
217// Also try to load Extensions from boot helper partitions.
218if (gBootVolume->flags & kBVFlagBooter)
219{
220strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/");
221if (FileLoadDrivers(dirSpecExtra, 0) != 0)
222{
223strcpy(dirSpecExtra, "/com.apple.boot.R/System/Library/");
224if (FileLoadDrivers(dirSpecExtra, 0) != 0)
225{
226strcpy(dirSpecExtra, "/com.apple.boot.S/System/Library/");
227FileLoadDrivers(dirSpecExtra, 0);
228}
229}
230}
231
232success_fd:
233// if user initialized gMKextName ("MKext Cache" flag)...
234if (gMKextName[0] != '\0')
235{
236verbose("LoadDrivers: Loading from [%s]\n", gMKextName);
237if ( LoadDriverMKext(gMKextName) != 0 )
238{
239error("Could not load %s\n", gMKextName);
240return -1;
241}
242}
243else // else load kext cache from default paths.
244{
245strcpy(gExtensionsSpec, dirSpec); // = "/"
246strcat(gExtensionsSpec, "System/Library/"); // "/" + "System/Library/"
247FileLoadDrivers(gExtensionsSpec, 0); // "/System/Library/" - legacy path
248}
249}
250else
251{
252return 0;
253}
254
255MatchPersonalities();
256
257MatchLibraries();
258
259LoadMatchedModules();
260
261return 0;
262}
263
264//==========================================================================
265// FileLoadMKext
266
267static long
268FileLoadMKext( const char * dirSpec, const char * extDirSpec )
269{
270longret, flags, time, time2;
271charaltDirSpec[512];
272
273sprintf (altDirSpec, "%s%s", dirSpec, extDirSpec);
274ret = GetFileInfo(altDirSpec, "Extensions.mkext", &flags, &time);
275msglog("(%s) Extensions.mkext time = %d\n", __FUNCTION__, time);
276
277if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat))
278{
279ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2);
280//Azi: hum... finaly got it :P
281verbose("(%s) Extensions time +1 = %d\n", __FUNCTION__, time2 + 1);
282
283if ((ret != 0)
284|| ((flags & kFileTypeMask) != kFileTypeDirectory)
285|| (((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1))))
286{
287sprintf(gDriverSpec, "%sExtensions.mkext", altDirSpec);
288//Azi: hum... finaly got it :P
289msglog("LoadDrivers: Loading from [%s]\n", gDriverSpec);
290
291if (LoadDriverMKext(gDriverSpec) == 0)
292return 0;
293}
294}
295return -1;
296}
297
298//==========================================================================
299// FileLoadDrivers
300
301static long
302FileLoadDrivers( char * dirSpec, long plugin )
303{
304 long ret, length, flags, time, bundleType;
305 long long index;
306 long result = -1;
307 const char * name;
308
309 if ( !plugin )
310 {
311 // First try 10.6's path for loading Extensions.mkext.
312 if (FileLoadMKext(dirSpec, "Caches/com.apple.kext.caches/Startup/") == 0)
313return 0; // "bt(0,0)/Extra/10.6/"
314
315 // Next try the legacy path.
316 else if (FileLoadMKext(dirSpec, "") == 0)
317 return 0;
318
319 strcat(dirSpec, "Extensions");
320 }
321
322 index = 0;
323 while (1) {
324
325 ret = GetDirEntry(dirSpec, &index, &name, &flags, &time);
326 if (ret == -1) break;
327
328 // Make sure this is a directory.
329 if ((flags & kFileTypeMask) != kFileTypeDirectory) continue;
330
331 // Make sure this is a kext.
332 length = strlen(name);
333 if (strcmp(name + length - 5, ".kext")) continue;
334
335 // Save the file name.
336 strcpy(gFileName, name);
337
338 // Determine the bundle type.
339 sprintf(gTempSpec, "%s/%s", dirSpec, gFileName);
340 ret = GetFileInfo(gTempSpec, "Contents", &flags, &time);
341 if (ret == 0) bundleType = kCFBundleType2;
342 else bundleType = kCFBundleType3;
343
344 if (!plugin)
345 sprintf(gDriverSpec, "%s/%s/%sPlugIns", dirSpec, gFileName,
346 (bundleType == kCFBundleType2) ? "Contents/" : "");
347
348 ret = LoadDriverPList(dirSpec, gFileName, bundleType);
349
350 if (result != 0)
351 result = ret;
352
353 if (!plugin)
354 FileLoadDrivers(gDriverSpec, 1);
355 }
356
357 return result;
358}
359
360//==========================================================================
361//
362
363static long
364NetLoadDrivers( char * dirSpec )
365{
366 long tries;
367
368#if NODEF
369 long cnt;
370
371 // Get the name of the kernel
372 cnt = strlen(gBootFile);
373 while (cnt--) {
374 if ((gBootFile[cnt] == '\\') || (gBootFile[cnt] == ',')) {
375 cnt++;
376 break;
377 }
378 }
379#endif
380
381 // INTEL modification
382 sprintf(gDriverSpec, "%s%s.mkext", dirSpec, bootInfo->bootFile);
383
384 verbose("NetLoadDrivers: Loading from [%s]\n", gDriverSpec);
385
386 tries = 3;
387 while (tries--)
388 {
389 if (LoadDriverMKext(gDriverSpec) == 0) break;
390 }
391 if (tries == -1) return -1;
392
393 return 0;
394}
395
396//==========================================================================
397// loadDriverMKext
398
399static long
400LoadDriverMKext( char * fileSpec )
401{
402 unsigned long driversAddr, driversLength;
403 long length;
404 char segName[32];
405 DriversPackage * package;
406
407#define GetPackageElement(e) OSSwapBigToHostInt32(package->e)
408
409 // Load the MKext.
410 length = LoadThinFatFile(fileSpec, (void **)&package);
411 if (length < sizeof (DriversPackage)) return -1;
412
413 // Verify the MKext.
414 if (( GetPackageElement(signature1) != kDriverPackageSignature1) ||
415 ( GetPackageElement(signature2) != kDriverPackageSignature2) ||
416 ( GetPackageElement(length) > kLoadSize ) ||
417 ( GetPackageElement(alder32) !=
418 Alder32((unsigned char *)&package->version, GetPackageElement(length) - 0x10) ) )
419 {
420 return -1;
421 }
422
423 // Make space for the MKext.
424 driversLength = GetPackageElement(length);
425 driversAddr = AllocateKernelMemory(driversLength);
426
427 // Copy the MKext.
428 memcpy((void *)driversAddr, (void *)package, driversLength);
429
430 // Add the MKext to the memory map.
431 sprintf(segName, "DriversPackage-%lx", driversAddr);
432 AllocateMemoryRange(segName, driversAddr, driversLength,
433 kBootDriverTypeMKEXT);
434
435 return 0;
436}
437
438//==========================================================================
439// LoadDriverPList
440
441static long
442LoadDriverPList( char * dirSpec, char * name, long bundleType )
443{
444 long length, executablePathLength, bundlePathLength;
445 ModulePtr module;
446 TagPtr personalities;
447 char * buffer = 0;
448 char * tmpExecutablePath = 0;
449 char * tmpBundlePath = 0;
450 long ret = -1;
451
452 do {
453 // Save the driver path.
454
455 sprintf(gFileSpec, "%s/%s/%s", dirSpec, name,
456 (bundleType == kCFBundleType2) ? "Contents/MacOS/" : "");
457 executablePathLength = strlen(gFileSpec) + 1;
458
459 tmpExecutablePath = malloc(executablePathLength);
460 if (tmpExecutablePath == 0) break;
461
462 strcpy(tmpExecutablePath, gFileSpec);
463
464 sprintf(gFileSpec, "%s/%s", dirSpec, name);
465 bundlePathLength = strlen(gFileSpec) + 1;
466
467 tmpBundlePath = malloc(bundlePathLength);
468 if (tmpBundlePath == 0) break;
469
470 strcpy(tmpBundlePath, gFileSpec);
471
472 // Construct the file spec to the plist, then load it.
473
474 sprintf(gFileSpec, "%s/%s/%sInfo.plist", dirSpec, name,
475 (bundleType == kCFBundleType2) ? "Contents/" : "");
476
477 length = LoadFile(gFileSpec);
478 if (length == -1) break;
479
480 length = length + 1;
481 buffer = malloc(length);
482 if (buffer == 0) break;
483
484 strlcpy(buffer, (char *)kLoadAddr, length);
485
486 // Parse the plist.
487
488 ret = ParseXML(buffer, &module, &personalities);
489 if (ret != 0) { break; }
490
491 // Allocate memory for the driver path and the plist.
492
493 module->executablePath = tmpExecutablePath;
494 module->bundlePath = tmpBundlePath;
495 module->bundlePathLength = bundlePathLength;
496 module->plistAddr = malloc(length);
497
498 if ((module->executablePath == 0) || (module->bundlePath == 0) || (module->plistAddr == 0))
499 break;
500
501 // Save the driver path in the module.
502 //strcpy(module->driverPath, tmpDriverPath);
503 tmpExecutablePath = 0;
504 tmpBundlePath = 0;
505
506 // Add the plist to the module.
507
508 strlcpy(module->plistAddr, (char *)kLoadAddr, length);
509 module->plistLength = length;
510
511 // Add the module to the end of the module list.
512
513 if (gModuleHead == 0)
514 gModuleHead = module;
515 else
516 gModuleTail->nextModule = module;
517 gModuleTail = module;
518
519 // Add the persionalities to the personality list.
520
521 if (personalities) personalities = personalities->tag;
522 while (personalities != 0)
523 {
524 if (gPersonalityHead == 0)
525 gPersonalityHead = personalities->tag;
526 else
527 gPersonalityTail->tagNext = personalities->tag;
528
529 gPersonalityTail = personalities->tag;
530 personalities = personalities->tagNext;
531 }
532
533 ret = 0;
534 }
535 while (0);
536
537 if ( buffer ) free( buffer );
538 if ( tmpExecutablePath ) free( tmpExecutablePath );
539 if ( tmpBundlePath ) free( tmpBundlePath );
540
541 return ret;
542}
543
544
545//==========================================================================
546// LoadMatchedModules
547
548static long
549LoadMatchedModules( void )
550{
551 TagPtr prop;
552 ModulePtr module;
553 char *fileName, segName[32];
554 DriverInfoPtr driver;
555 long length, driverAddr, driverLength;
556 void *executableAddr = 0;
557
558
559 module = gModuleHead;
560
561 while (module != 0)
562 {
563 if (module->willLoad)
564 {
565 prop = XMLGetProperty(module->dict, kPropCFBundleExecutable);
566
567 if (prop != 0)
568 {
569 fileName = prop->string;
570 sprintf(gFileSpec, "%s%s", module->executablePath, fileName);
571 length = LoadThinFatFile(gFileSpec, &executableAddr);
572if (length == 0)
573{
574length = LoadFile(gFileSpec);
575executableAddr = (void *)kLoadAddr;
576}
577 //printf("%s length = %d addr = 0x%x\n", gFileSpec, length, driverModuleAddr); getc();
578 }
579 else
580 length = 0;
581
582 if (length != -1)
583 {
584//driverModuleAddr = (void *)kLoadAddr;
585 //if (length != 0)
586 //{
587// ThinFatFile(&driverModuleAddr, &length);
588//}
589
590 // Make make in the image area.
591 driverLength = sizeof(DriverInfo) + module->plistLength + length + module->bundlePathLength;
592 driverAddr = AllocateKernelMemory(driverLength);
593
594 // Set up the DriverInfo.
595 driver = (DriverInfoPtr)driverAddr;
596 driver->plistAddr = (char *)(driverAddr + sizeof(DriverInfo));
597 driver->plistLength = module->plistLength;
598 if (length != 0)
599 {
600 driver->executableAddr = (void *)(driverAddr + sizeof(DriverInfo) +
601 module->plistLength);
602 driver->executableLength = length;
603 }
604 else
605 {
606 driver->executableAddr = 0;
607 driver->executableLength = 0;
608 }
609 driver->bundlePathAddr = (void *)(driverAddr + sizeof(DriverInfo) +
610 module->plistLength + driver->executableLength);
611 driver->bundlePathLength = module->bundlePathLength;
612
613 // Save the plist, module and bundle.
614 strcpy(driver->plistAddr, module->plistAddr);
615 if (length != 0)
616 {
617 memcpy(driver->executableAddr, executableAddr, length);
618 }
619 strcpy(driver->bundlePathAddr, module->bundlePath);
620
621 // Add an entry to the memory map.
622 sprintf(segName, "Driver-%lx", (unsigned long)driver);
623 AllocateMemoryRange(segName, driverAddr, driverLength,
624 kBootDriverTypeKEXT);
625 }
626 }
627 module = module->nextModule;
628 }
629
630 return 0;
631}
632
633//==========================================================================
634// MatchPersonalities
635
636static long
637MatchPersonalities( void )
638{
639 /* IONameMatch support not implemented */
640 return 0;
641}
642
643//==========================================================================
644// MatchLibraries
645
646static long
647MatchLibraries( void )
648{
649 TagPtr prop, prop2;
650 ModulePtr module, module2;
651 long done;
652
653 do {
654 done = 1;
655 module = gModuleHead;
656
657 while (module != 0)
658 {
659 if (module->willLoad == 1)
660 {
661 prop = XMLGetProperty(module->dict, kPropOSBundleLibraries);
662 if (prop != 0)
663 {
664 prop = prop->tag;
665 while (prop != 0)
666 {
667 module2 = gModuleHead;
668 while (module2 != 0)
669 {
670 prop2 = XMLGetProperty(module2->dict, kPropCFBundleIdentifier);
671 if ((prop2 != 0) && (!strcmp(prop->string, prop2->string)))
672 {
673 if (module2->willLoad == 0) module2->willLoad = 1;
674 break;
675 }
676 module2 = module2->nextModule;
677 }
678 prop = prop->tagNext;
679 }
680 }
681 module->willLoad = 2;
682 done = 0;
683 }
684 module = module->nextModule;
685 }
686 }
687 while (!done);
688
689 return 0;
690}
691
692
693//==========================================================================
694// FindModule
695
696#if NOTDEF
697static ModulePtr
698FindModule( char * name )
699{
700 ModulePtr module;
701 TagPtr prop;
702
703 module = gModuleHead;
704
705 while (module != 0)
706 {
707 prop = GetProperty(module->dict, kPropCFBundleIdentifier);
708 if ((prop != 0) && !strcmp(name, prop->string)) break;
709 module = module->nextModule;
710 }
711
712 return module;
713}
714#endif /* NOTDEF */
715
716//==========================================================================
717// ParseXML
718
719static long
720ParseXML( char * buffer, ModulePtr * module, TagPtr * personalities )
721{
722long length, pos;
723TagPtr moduleDict, required;
724ModulePtr tmpModule;
725
726 pos = 0;
727
728 while (1)
729 {
730 length = XMLParseNextTag(buffer + pos, &moduleDict);
731 if (length == -1) break;
732
733 pos += length;
734
735 if (moduleDict == 0) continue;
736 if (moduleDict->type == kTagTypeDict) break;
737
738 XMLFreeTag(moduleDict);
739 }
740
741 if (length == -1) return -1;
742
743 required = XMLGetProperty(moduleDict, kPropOSBundleRequired);
744 if ( (required == 0) ||
745 (required->type != kTagTypeString) ||
746 !strcmp(required->string, "Safe Boot"))
747 {
748 XMLFreeTag(moduleDict);
749 return -2;
750 }
751
752 tmpModule = malloc(sizeof(Module));
753 if (tmpModule == 0)
754 {
755 XMLFreeTag(moduleDict);
756 return -1;
757 }
758 tmpModule->dict = moduleDict;
759
760 // For now, load any module that has OSBundleRequired != "Safe Boot".
761
762 tmpModule->willLoad = 1;
763
764 *module = tmpModule;
765
766 // Get the personalities.
767
768 *personalities = XMLGetProperty(moduleDict, kPropIOKitPersonalities);
769
770 return 0;
771}
772
773#if NOTDEF
774static char gPlatformName[64];
775#endif
776
777long
778DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize)
779{
780 long ret;
781 compressed_kernel_header * kernel_header = (compressed_kernel_header *) binary;
782 u_int32_t uncompressed_size, size;
783 void *buffer;
784unsigned long len;
785
786#if 0
787 printf("kernel header:\n");
788 printf("signature: 0x%x\n", kernel_header->signature);
789 printf("compress_type: 0x%x\n", kernel_header->compress_type);
790 printf("adler32: 0x%x\n", kernel_header->adler32);
791 printf("uncompressed_size: 0x%x\n", kernel_header->uncompressed_size);
792 printf("compressed_size: 0x%x\n", kernel_header->compressed_size);
793 getc();
794#endif
795
796 if (kernel_header->signature == OSSwapBigToHostConstInt32('comp')) {
797 if (kernel_header->compress_type != OSSwapBigToHostConstInt32('lzss')) {
798 error("kernel compression is bad\n");
799 return -1;
800 }
801#if NOTDEF
802 if (kernel_header->platform_name[0] && strcmp(gPlatformName, kernel_header->platform_name))
803 return -1;
804 if (kernel_header->root_path[0] && strcmp(gBootFile, kernel_header->root_path))
805 return -1;
806#endif
807
808 uncompressed_size = OSSwapBigToHostInt32(kernel_header->uncompressed_size);
809 binary = buffer = malloc(uncompressed_size);
810
811 size = decompress_lzss((u_int8_t *) binary, &kernel_header->data[0],
812 OSSwapBigToHostInt32(kernel_header->compressed_size));
813 if (uncompressed_size != size) {
814 error("size mismatch from lzss: %x\n", size);
815 return -1;
816 }
817 if (OSSwapBigToHostInt32(kernel_header->adler32) !=
818 Alder32(binary, uncompressed_size)) {
819 printf("adler mismatch\n");
820 return -1;
821 }
822 }
823
824 ret = ThinFatFile(&binary, &len);
825 if (ret == 0 && len == 0 && archCpuType==CPU_TYPE_X86_64)
826 {
827 archCpuType=CPU_TYPE_I386;
828 ret = ThinFatFile(&binary, &len);
829 }
830
831 ret = DecodeMachO(binary, rentry, raddr, rsize);
832
833 if (ret<0 && archCpuType==CPU_TYPE_X86_64)
834 {
835 archCpuType=CPU_TYPE_I386;
836 ret = DecodeMachO(binary, rentry, raddr, rsize);
837 }
838
839 return ret;
840}
841

Archive Download this file

Revision: 847