Index: branches/cparm/Chameleon.xcodeproj/project.pbxproj =================================================================== --- branches/cparm/Chameleon.xcodeproj/project.pbxproj (revision 2117) +++ branches/cparm/Chameleon.xcodeproj/project.pbxproj (revision 2118) @@ -480,6 +480,11 @@ AB43B3F214C383120018D529 /* udivdi3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = udivdi3.c; sourceTree = ""; }; AB43B3F314C383120018D529 /* umoddi3.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = umoddi3.c; sourceTree = ""; }; AB43B3F814C384040018D529 /* stack_protector.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stack_protector.c; sourceTree = ""; }; + AB5BBD60164D270C000C872E /* gen_uuid-uuid.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = "gen_uuid-uuid.c"; sourceTree = ""; }; + AB5BBD68164D391E000C872E /* uuid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uuid.h; sourceTree = ""; }; + AB5BBD69164D39FC000C872E /* unpack.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = unpack.c; sourceTree = ""; }; + AB5BBD6A164D3A46000C872E /* uuidP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = uuidP.h; sourceTree = ""; }; + AB5BBD77164D3C9A000C872E /* pack.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pack.c; sourceTree = ""; }; AB6DE3E6163976A80065E17F /* bcopy_scalar.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = bcopy_scalar.s; sourceTree = ""; }; AB79217514F38CF200F5EB39 /* bootXnu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bootXnu.h; sourceTree = ""; }; AB79219214F3919E00F5EB39 /* ModuleHelp.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ModuleHelp.txt; sourceTree = ""; }; @@ -1041,7 +1046,12 @@ AB43B2ED14C37E520018D529 /* libsaio */ = { isa = PBXGroup; children = ( + AB5BBD60164D270C000C872E /* gen_uuid-uuid.c */, ABA0C7BF1568190C003440AF /* arc4random-fbsd.c */, + AB5BBD69164D39FC000C872E /* unpack.c */, + AB5BBD77164D3C9A000C872E /* pack.c */, + AB5BBD6A164D3A46000C872E /* uuidP.h */, + AB5BBD68164D391E000C872E /* uuid.h */, ABA0C7C01568190C003440AF /* lib.c */, ABA0C7C11568190C003440AF /* rtc.c */, ABA0C7C21568190C003440AF /* time.c */, Index: branches/cparm/CHANGES =================================================================== --- branches/cparm/CHANGES (revision 2117) +++ branches/cparm/CHANGES (revision 2118) @@ -1,4 +1,8 @@ - Security fixes +- Implemented random uuid +- device_inject is now embedded into the modules that need it, and not in the core anymore + +- Security fixes - Fixed few bugs in AcpiCodec - Fixes some bugs related to the auto-installer Index: branches/cparm/i386/libsaio/fake_efi.h =================================================================== --- branches/cparm/i386/libsaio/fake_efi.h (revision 2117) +++ branches/cparm/i386/libsaio/fake_efi.h (revision 2118) @@ -9,6 +9,7 @@ #define MAX_CONFIGURATION_TABLE_ENTRIES (uint32_t)10 #include "efi.h" #include "SMBIOS.h" +#include "device_tree.h" extern void Index: branches/cparm/i386/libsaio/xml.c =================================================================== --- branches/cparm/i386/libsaio/xml.c (revision 2117) +++ branches/cparm/i386/libsaio/xml.c (revision 2118) @@ -1027,7 +1027,12 @@ // Update the refCount and return the string. symbol->refCount++; - if (lastGuy && lastGuy->next != 0) stop("last guy not last!"); + if (lastGuy && lastGuy->next != 0) + { + free(symbol); + stop("last guy not last!"); + return 0; + } return symbol->string; } Index: branches/cparm/i386/libsaio/bootstruct.c =================================================================== --- branches/cparm/i386/libsaio/bootstruct.c (revision 2117) +++ branches/cparm/i386/libsaio/bootstruct.c (revision 2118) @@ -57,7 +57,10 @@ bootArgs = (boot_args *)malloc(sizeof(boot_args)); bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t)); if (bootArgs == NULL || bootInfo == NULL) + { stop("Couldn't allocate boot info\n"); + return; + } else { bzero(bootArgs, sizeof(boot_args)); @@ -94,6 +97,7 @@ node = DT__FindNode("/", true); if (node == 0) { stop("Couldn't create root node"); + return; } getPlatformName(platformName, sizeof(platformName)); @@ -204,6 +208,7 @@ // XXX could make a two-part map here stop("No memory map found\n"); + return; } @@ -281,6 +286,7 @@ // I Guess that if sane_size == 0 we've got a big problem here, // and it means that the memory map was not converted properly stop("Unable to convert memory map into proper format\n"); + return; } #define MEG (1024*1024) @@ -305,11 +311,13 @@ addr = (void *)AllocateKernelMemory(size); if (addr == 0) { stop("Couldn't allocate device tree\n"); + return; } DT__FlattenDeviceTree((void **)&addr, &size); if (!size) { stop("Couldn't get flatten device tree\n"); + return; } bootArgs->deviceTreeP = (uint32_t)addr; bootArgs->deviceTreeLength = size; Index: branches/cparm/i386/libsaio/hfs_CaseTables.h =================================================================== --- branches/cparm/i386/libsaio/hfs_CaseTables.h (revision 2117) +++ branches/cparm/i386/libsaio/hfs_CaseTables.h (revision 2118) @@ -476,7 +476,7 @@ // Please update count if you add/remove entries but also please just let // the compiler calculate it so you don't get it wrong. //#define kLowerCaseTableNBlocks 182 -#define kLowerCaseTableNBlocks (sizeof(gLowerCaseTableCompressed)/sizeof(*gLowerCaseTableCompressed)) +#define kLowerCaseTableNBlocks (sizeof(gLowerCaseTableCompressed)/sizeof(struct compressed_block)) // WARNING: The expanded size MUST be updated if you change the table and // cannot be calculated at compile time. #define kLowerCaseTableDataSize 5632 /* size of uncompressed structure in bytes */ @@ -552,7 +552,7 @@ // Please update count if you add/remove entries but also please just let // the compiler calculate it so you don't get it wrong. //#define kCompareTableNBlocks 64 -#define kCompareTableNBlocks (sizeof(gCompareTableCompressed)/sizeof(*gCompareTableCompressed)) +#define kCompareTableNBlocks (sizeof(gCompareTableCompressed)/sizeof(struct compressed_block)) // WARNING: The expanded size MUST be updated if you change the table and // cannot be calculated at compile time. #define kCompareTableDataSize 512 /* size of uncompressed structure in bytes */ Index: branches/cparm/i386/libsaio/uuid.h =================================================================== --- branches/cparm/i386/libsaio/uuid.h (revision 0) +++ branches/cparm/i386/libsaio/uuid.h (revision 2118) @@ -0,0 +1,64 @@ +/* + * Public include file for the UUID library + * + * Copyright (C) 1996, 1997, 1998 Theodore Ts'o. + * + * %Begin-Header% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF + * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * %End-Header% + */ + +#ifndef _UUID_UUID_H +#define _UUID_UUID_H + +#include + +#ifndef _UUID_T +#define _UUID_T +typedef __darwin_uuid_t uuid_t; +#endif /* _UUID_T */ + +#ifndef _UUID_STRING_T +#define _UUID_STRING_T +typedef __darwin_uuid_string_t uuid_string_t; +#endif /* _UUID_STRING_T */ + +#define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \ + static const uuid_t name __attribute__ ((unused)) = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15} + +#ifdef __cplusplus +extern "C" { +#endif + +void uuid_generate_random(uuid_t out); +void uuid_generate(uuid_t out); + +#ifdef __cplusplus +} +#endif + +#endif /* _UUID_UUID_H */ Index: branches/cparm/i386/libsaio/unpack.c =================================================================== --- branches/cparm/i386/libsaio/unpack.c (revision 0) +++ branches/cparm/i386/libsaio/unpack.c (revision 2118) @@ -0,0 +1,62 @@ +/* + * Internal routine for unpacking UUID + * + * Copyright (C) 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF + * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * %End-Header% + */ + +#include "libsaio.h" + +void uuid_unpack(const uuid_t in, struct uuid *uu) +{ + const uint8_t *ptr = in; + uint32_t tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_low = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_mid = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->time_hi_and_version = tmp; + + tmp = *ptr++; + tmp = (tmp << 8) | *ptr++; + uu->clock_seq = tmp; + + memcpy(uu->node, ptr, 6); +} + Index: branches/cparm/i386/libsaio/device_tree.h =================================================================== --- branches/cparm/i386/libsaio/device_tree.h (revision 2117) +++ branches/cparm/i386/libsaio/device_tree.h (revision 2118) @@ -25,6 +25,63 @@ struct _Node * next; } Node; +#define MAX_PCI_DEV_PATHS 4 +#define MAX_STRING_NUM_ENTRIES 100 + +#define DEV_PATH_HEADER \ +uint8_t type; \ +uint8_t subtype; \ +uint16_t length; + +struct ACPIDevPath { + //uint8_t type; // = 2 ACPI device-path + //uint8_t subtype; // = 1 ACPI Device-path + //uint16_t length; // = 0x0c + DEV_PATH_HEADER + uint32_t _HID; // = 0xD041030A ? + uint32_t _UID; // = 0x00000000 PCI ROOT +}; + +struct PCIDevPath { + //uint8_t type; // = 1 Hardware device-path + //uint8_t subtype; // = 1 PCI + //uint16_t length; // = 6 + DEV_PATH_HEADER + uint8_t function; // pci func number + uint8_t device; // pci dev number +}; + +struct DevicePathEnd { + //uint8_t type; // = 0x7f + //uint8_t subtype; // = 0xff + //uint16_t length; // = 4; + DEV_PATH_HEADER +}; + +struct DevPropDevice { + uint32_t length; + uint16_t numentries; + uint16_t WHAT2; // 0x0000 ? + struct ACPIDevPath acpi_dev_path; // = 0x02010c00 0xd041030a + struct PCIDevPath pci_dev_path[MAX_PCI_DEV_PATHS]; // = 0x01010600 func dev + struct DevicePathEnd path_end; // = 0x7fff0400 + uint8_t *data; + + // ------------------------ + uint8_t num_pci_devpaths; + struct DevPropString *string; + // ------------------------ +}; + +struct DevPropString { + uint32_t length; + uint32_t WHAT2; // 0x01000000 ? + uint16_t numentries; + uint16_t WHAT3; // 0x0000 ? + struct DevPropDevice *entries; +}; + + extern Property * DT__AddProperty(Node *node, const char *name, uint32_t length, void *value); Index: branches/cparm/i386/libsaio/hfs_compare.c =================================================================== --- branches/cparm/i386/libsaio/hfs_compare.c (revision 2117) +++ branches/cparm/i386/libsaio/hfs_compare.c (revision 2118) @@ -48,6 +48,7 @@ if(out + size <= op + bp->count) { stop("HFS+ Unicode tables are malformed\n"); + return 0; } data = bp->data; for (j=0; jcount; j++) { Index: branches/cparm/i386/libsaio/Makefile =================================================================== --- branches/cparm/i386/libsaio/Makefile (revision 2117) +++ branches/cparm/i386/libsaio/Makefile (revision 2118) @@ -36,8 +36,7 @@ xml.o md5.o device_tree.o modules.o \ cpu.o platform.o \ fake_efi.o \ - device_inject.o \ - convert.o acpi_tools.o smbios.o uterror.o lzss.o lib.o rtc.o time.o + convert.o acpi_tools.o smbios.o uterror.o lzss.o lib.o rtc.o time.o gen_uuid-uuid.o pack.o unpack.o # Options enabled by default: Index: branches/cparm/i386/libsaio/SMBIOS.h =================================================================== --- branches/cparm/i386/libsaio/SMBIOS.h (revision 2117) +++ branches/cparm/i386/libsaio/SMBIOS.h (revision 2118) @@ -181,7 +181,7 @@ SMBString version; SMBString serialNumber; // 2.1+ spec (25 bytes) - SMBByte uuid[16]; // can be all 0 or all 1's + SMBByte uuid[UUID_LEN]; // can be all 0 or all 1's SMBByte wakeupReason; // reason for system wakeup // 2.4+ spec (27 bytes) SMBString skuNumber; Index: branches/cparm/i386/libsaio/cpu_intel_amd.c =================================================================== --- branches/cparm/i386/libsaio/cpu_intel_amd.c (revision 2117) +++ branches/cparm/i386/libsaio/cpu_intel_amd.c (revision 2118) @@ -448,7 +448,7 @@ else if (Vendor != CPUID_VENDOR_AMD) { stop("Error: CPU unsupported\n"); - halt(); + return; } /* get extended cpuid results */ Index: branches/cparm/i386/libsaio/gen_uuid-uuid.c =================================================================== --- branches/cparm/i386/libsaio/gen_uuid-uuid.c (revision 0) +++ branches/cparm/i386/libsaio/gen_uuid-uuid.c (revision 2118) @@ -0,0 +1,86 @@ +/* + * gen_uuid.c --- generate a DCE-compatible uuid + * + * Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o. + * + * %Begin-Header% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF + * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * %End-Header% + */ + +/* + * Force inclusion of SVID stuff since we need it if we're compiling in + * gcc-wall wall mode + */ +#define _SVID_SOURCE + +#include "libsaio.h" +#include "uuid.h" + +static void get_random_bytes(void *buf, int nbytes); + +/* + * Generate a series of random bytes, using arc4random + */ +static void get_random_bytes(void *buf, int nbytes) +{ + unsigned char *cp = (unsigned char *) buf; + u_int32_t u; + int n = nbytes / sizeof(u); + + while (n-- > 0) { + u = arc4random(); + memcpy(cp, &u, sizeof(u)); + cp += sizeof(u); + } + if ((n = nbytes % sizeof(u)) > 0) { + u = arc4random(); + memcpy(cp, &u, n); + } + return; +} + +void uuid_generate_random(uuid_t out) +{ + uuid_t buf; + struct uuid uu; + + get_random_bytes(buf, sizeof(buf)); + uuid_unpack(buf, &uu); + + uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000; + uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF) | 0x4000; + uuid_pack(&uu, out); +} + +/* + * This is the generic front-end + */ +void uuid_generate(uuid_t out) +{ + uuid_generate_random(out); +} Index: branches/cparm/i386/libsaio/modules.c =================================================================== --- branches/cparm/i386/libsaio/modules.c (revision 2117) +++ branches/cparm/i386/libsaio/modules.c (revision 2118) @@ -357,12 +357,8 @@ * hook is executed. When registering a new callback name, the callback is added sorted. * NOTE: the hooks take four void* arguments. */ -VOID register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*)) -{ - DBG("Adding callback for hook '%s'.\n", name); - - moduleHook_t* hook = get_callback(name); - +static VOID __register_hook_callback(moduleHook_t* hook, const char* name, void(*callback)(void*, void*, void*, void*, void*, void*)) +{ if(hook) { // append @@ -402,9 +398,30 @@ print_hook_list(); getc(); #endif +} + +VOID register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*)) +{ + DBG("Adding callback for hook '%s'.\n", name); + moduleHook_t* hook = get_callback(name); + + __register_hook_callback(hook, name, callback); } +VOID register_one_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*)) +{ + DBG("Adding one callback for hook '%s'.\n", name); + + moduleHook_t* hook = get_callback(name); + + if (hook) + { + return; + } + __register_hook_callback(hook, name, callback); +} + #if DEBUG_MODULES unsigned long vmaddr; long vmsize; Index: branches/cparm/i386/libsaio/modules.h =================================================================== --- branches/cparm/i386/libsaio/modules.h (revision 2117) +++ branches/cparm/i386/libsaio/modules.h (revision 2118) @@ -24,7 +24,7 @@ #include "efi.h" #define DEFAULT_BUNDLE_SPEC_SIZE 4096 -#define macho_64 1 +#define macho_64 0 extern unsigned long long textAddress; extern unsigned long long textSection; @@ -74,6 +74,7 @@ */ EFI_STATUS execute_hook(const char* name, void*, void*, void*, void*, void*, void*); VOID register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*)); +VOID register_one_callback(const char* name, void(*callback)(void*, void*, void*, void*, void*, void*)); void rebase_location(UInt32* location, char* base, int type); void bind_location(UInt32* location, char* value, UInt32 addend, int type); Index: branches/cparm/i386/libsaio/uuidP.h =================================================================== --- branches/cparm/i386/libsaio/uuidP.h (revision 0) +++ branches/cparm/i386/libsaio/uuidP.h (revision 2118) @@ -0,0 +1,67 @@ +/* + * uuid.h -- private header file for uuids + * + * Copyright (C) 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF + * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * %End-Header% + */ + +#include "uuid.h" + +/* + * Offset between 15-Oct-1582 and 1-Jan-70 + */ +#define TIME_OFFSET_HIGH 0x01B21DD2 +#define TIME_OFFSET_LOW 0x13814000 + +struct uuid { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint16_t clock_seq; + uint8_t node[6]; +}; + +/* UUID Variant definitions */ +#define UUID_VARIANT_NCS 0 +#define UUID_VARIANT_DCE 1 +#define UUID_VARIANT_MICROSOFT 2 +#define UUID_VARIANT_OTHER 3 + +/* UUID Type definitions */ +#define UUID_TYPE_DCE_TIME 1 +#define UUID_TYPE_DCE_RANDOM 4 + +/* + * prototypes + */ +void uuid_pack(const struct uuid *uu, uuid_t ptr); +void uuid_unpack(const uuid_t in, struct uuid *uu); + + Index: branches/cparm/i386/libsaio/device_inject.c =================================================================== --- branches/cparm/i386/libsaio/device_inject.c (revision 2117) +++ branches/cparm/i386/libsaio/device_inject.c (revision 2118) @@ -11,6 +11,7 @@ #include "device_inject.h" #include "convert.h" #include "platform.h" +#include "modules.h" #ifndef DEBUG_INJECT #define DEBUG_INJECT 0 @@ -22,58 +23,10 @@ #define DBG(x...) #endif -char *efi_inject_get_devprop_string(uint32_t *len) -{ - struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString); +static char *efi_inject_get_devprop_string(uint32_t *len); +void setupDeviceProperties_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6); +static EFI_STATUS setupDeviceProperties(Node *node); - if(string) - { - *len = string->length; - return devprop_generate_string(string); - } - return NULL; -} - -void setupDeviceProperties(Node *node) -{ - const char *val; - uint8_t *binStr; - uint8_t *kbinStr; - - int cnt = 0, cnt2 = 0; - - static char DEVICE_PROPERTIES_PROP[] = "device-properties"; - - /* Generate devprop string. - */ - uint32_t strlength; - char *string = efi_inject_get_devprop_string(&strlength); - if (string == NULL) { - verbose("efi_inject_get_devprop_string NULL trying stringdata\n"); - return; - } - /* Use the static "device-properties" boot config key contents if available, - * otheriwse use the generated one. - */ - if (!getValueForKey(kDeviceProperties, &val, &cnt, DEFAULT_BOOT_CONFIG)) - { - val = (const char*)string; - cnt = strlength * 2; - } - - if (cnt > 1) - { - binStr = convertHexStr2Binary(val, &cnt2); - - if (cnt2 > 0) - { - kbinStr = (uint8_t*)AllocateKernelMemory(cnt2); - bcopy(binStr,kbinStr,cnt2); - DT__AddProperty(node, DEVICE_PROPERTIES_PROP, cnt2, kbinStr); - } - } -} - struct DevPropString *devprop_create_string(void) { struct DevPropString *string = (struct DevPropString*)malloc(sizeof(struct DevPropString)); @@ -97,7 +50,7 @@ pci_dt_t *current; pci_dt_t *end; - end = root_pci_dev; + end = (pci_dt_t *)(uint32_t)get_env(envPCIRootDev); device = malloc(sizeof(struct DevPropDevice)); if (!device) { @@ -200,140 +153,6 @@ return device; } -#if 0 -struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path) -{ - struct DevPropDevice *device; - const char pciroot_string[] = "PciRoot(0x"; - const char pci_device_string[] = "Pci(0x"; - - if (string == NULL || path == NULL) { - return NULL; - } - device = malloc(sizeof(struct DevPropDevice)); - if (!device) { - return NULL; - } - if (strncmp(path, pciroot_string, strlen(pciroot_string))) { - free(device); - printf("ERROR parsing device path 1\n"); - return NULL; - } - - memset(device, 0, sizeof(struct DevPropDevice)); - device->acpi_dev_path._UID = getPciRootUID(); - - int numpaths = 0; - int x, curr = 0, w = 0; - - char buff[16]; - - - for (x = 0; x < strlen(path); x++) - { - - if (!strncmp(&path[x], pci_device_string, strlen(pci_device_string))) - { - x+=strlen(pci_device_string); - curr=x; - while(path[++x] != ','); - - w = x-curr; - - if ((w > 4) || /*(w > sizeof(buff)) ||*/ (w == 0)) { - printf("ERROR parsing device path 2\n"); - break; - } - - snprintf(buff, x-curr, "%s",&path[curr]); - - device->pci_dev_path[numpaths].device = (uint8_t)strtoul(buff, NULL, 16); - - bzero(buff, sizeof(buff)); - - x += 3; // 0x - curr = x; - while(path[++x] != ')'); - - w = x-curr; - - if ((w > 4) || /*(w > sizeof(buff)) ||*/ (w == 0)) { - printf("ERROR parsing device path 3\n"); - break; - } - - snprintf(buff, x-curr, "%s",&path[curr]); - - device->pci_dev_path[numpaths].function = (uint8_t)strtoul(buff, NULL, 16); // TODO: find dev from char *path - - numpaths++; - } - } - - if(!numpaths) - { - printf("ERROR parsing device path 4\n"); - free(device); - return NULL; - } - - device->numentries = 0x00; - - device->acpi_dev_path.length = 0x0c; - device->acpi_dev_path.type = 0x02; - device->acpi_dev_path.subtype = 0x01; - device->acpi_dev_path._HID = 0xd041030a; - - device->num_pci_devpaths = numpaths; - device->length = 24 + (6*numpaths); - - int i; - - for(i = 0; i < numpaths; i++) - { - device->pci_dev_path[i].length = 0x06; - device->pci_dev_path[i].type = 0x01; - device->pci_dev_path[i].subtype = 0x01; - } - - device->path_end.length = 0x04; - device->path_end.type = 0x7f; - device->path_end.subtype = 0xff; - - device->string = string; - device->data = NULL; - string->length += device->length; - - if(!string->entries) - { - if((string->entries = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice) * MAX_STRING_NUM_ENTRIES))== NULL) - { - printf("ERROR parsing device path 6\n"); - - free(device); - return NULL; - } - } - struct DevPropDevice **string_entries_arrey = (struct DevPropDevice **) string->entries; - - if ((string->numentries+1) < MAX_STRING_NUM_ENTRIES) - { - string->numentries++; - - } - else - { - free(string->entries); - free(device); - return NULL; - } - - string_entries_arrey[string->numentries-1] = device; - - return device; -} -#endif - int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len) { @@ -344,35 +163,34 @@ uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2); uint8_t *data = (uint8_t*)malloc(length); - { - if(!data) - { - return 0; - } - - memset(data, 0, length); - uint32_t off= 0; - data[off+1] = ((strlen(nm) * 2) + 6) >> 8; - data[off] = ((strlen(nm) * 2) + 6) & 0x00FF; - - off += 4; - uint32_t i=0, l = strlen(nm); - for(i = 0 ; i < l ; i++, off += 2) - { - data[off] = *nm++; - } - - off += 2; - l = len; - uint32_t *datalength = (uint32_t*)&data[off]; - *datalength = l + 4; - off += 4; - for(i = 0 ; i < l ; i++, off++) - { - data[off] = *vl++; - } - } + if(!data) + { + return 0; + } + + memset(data, 0, length); + uint32_t off= 0; + data[off+1] = ((strlen(nm) * 2) + 6) >> 8; + data[off] = ((strlen(nm) * 2) + 6) & 0x00FF; + + off += 4; + uint32_t i=0, l = strlen(nm); + for(i = 0 ; i < l ; i++, off += 2) + { + data[off] = *nm++; + } + + off += 2; + l = len; + uint32_t *datalength = (uint32_t*)&data[off]; + *datalength = l + 4; + off += 4; + for(i = 0 ; i < l ; i++, off++) + { + data[off] = *vl++; + } + uint32_t offset = device->length - (24 + (6 * device->num_pci_devpaths)); uint8_t *newdata = (uint8_t*)malloc((length + offset)); @@ -394,12 +212,8 @@ device->string->length += length; device->numentries++; - if(!device->data) + if(device->data) { - //device->data = (uint8_t*)malloc(sizeof(uint8_t)); //IMHO this is useless - } - else - { free(device->data); } @@ -421,16 +235,16 @@ } snprintf(buffer, len, "%08x%08x%04x%04x", dp_swap32(string->length), string->WHAT2, - dp_swap16(string->numentries), string->WHAT3); + dp_swap16(string->numentries), string->WHAT3); buffer += 24; len -= 24; int i = 0, x = 0; struct DevPropDevice **string_entries_arrey = (struct DevPropDevice **) string->entries; - + while(i < string->numentries) { - if (!(ilength), - dp_swap16(string_entries_arrey[i]->numentries), string_entries_arrey[i]->WHAT2); + dp_swap16(string_entries_arrey[i]->numentries), string_entries_arrey[i]->WHAT2); buffer += 16; len -= 16; snprintf(buffer, len,"%02x%02x%04x%08x%08x", string_entries_arrey[i]->acpi_dev_path.type, - string_entries_arrey[i]->acpi_dev_path.subtype, - dp_swap16(string_entries_arrey[i]->acpi_dev_path.length), - string_entries_arrey[i]->acpi_dev_path._HID, - dp_swap32(string_entries_arrey[i]->acpi_dev_path._UID)); + string_entries_arrey[i]->acpi_dev_path.subtype, + dp_swap16(string_entries_arrey[i]->acpi_dev_path.length), + string_entries_arrey[i]->acpi_dev_path._HID, + dp_swap32(string_entries_arrey[i]->acpi_dev_path._UID)); buffer += 24; len -= 24; @@ -456,10 +270,10 @@ break; } snprintf(buffer, len,"%02x%02x%04x%02x%02x", string_entries_arrey[i]->pci_dev_path[x].type, - string_entries_arrey[i]->pci_dev_path[x].subtype, - dp_swap16(string_entries_arrey[i]->pci_dev_path[x].length), - string_entries_arrey[i]->pci_dev_path[x].function, - string_entries_arrey[i]->pci_dev_path[x].device); + string_entries_arrey[i]->pci_dev_path[x].subtype, + dp_swap16(string_entries_arrey[i]->pci_dev_path[x].length), + string_entries_arrey[i]->pci_dev_path[x].function, + string_entries_arrey[i]->pci_dev_path[x].device); buffer += 12; len -= 12; } @@ -467,8 +281,8 @@ break; } snprintf(buffer, len,"%02x%02x%04x", string_entries_arrey[i]->path_end.type, - string_entries_arrey[i]->path_end.subtype, - dp_swap16(string_entries_arrey[i]->path_end.length)); + string_entries_arrey[i]->path_end.subtype, + dp_swap16(string_entries_arrey[i]->path_end.length)); buffer += 8; len -= 8; @@ -500,7 +314,7 @@ for(i = 0; i < string->numentries; i++) { - if (!(ilength; + return devprop_generate_string(string); + } + return NULL; +} + +static EFI_STATUS setupDeviceProperties(Node *node) +{ + const char *val; + uint8_t *binStr; + uint8_t *kbinStr; + + int cnt = 0, cnt2 = 0; + + static char DEVICE_PROPERTIES_PROP[] = "device-properties"; + + /* Generate devprop string. + */ + uint32_t strlength = 0; + char *string = efi_inject_get_devprop_string(&strlength); + if (string == NULL) { + DBG("efi_inject_get_devprop_string NULL trying stringdata\n"); + return EFI_NO_MEDIA; + } + + val = (const char*)string; + cnt = strlength * 2; + + if (cnt > 1) + { + binStr = convertHexStr2Binary(val, &cnt2); + + if (cnt2 > 0) + { + kbinStr = (uint8_t*)AllocateKernelMemory(cnt2); + if (kbinStr) + { + bcopy(binStr,kbinStr,cnt2); + DT__AddProperty(node, DEVICE_PROPERTIES_PROP, cnt2, kbinStr); + return EFI_SUCCESS; + } + } + } + return EFI_DEVICE_ERROR; + +} + +void setupDeviceProperties_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) +{ + Node *node = (Node *)arg1; + EFI_STATUS *ret = (EFI_STATUS*)arg2; + *ret = setupDeviceProperties(node); +} + +void register_device_inject(void) +{ + register_one_callback("setupDeviceProperties", &setupDeviceProperties_hook); } \ No newline at end of file Index: branches/cparm/i386/libsaio/device_inject.h =================================================================== --- branches/cparm/i386/libsaio/device_inject.h (revision 2117) +++ branches/cparm/i386/libsaio/device_inject.h (revision 2118) @@ -9,73 +9,17 @@ #define __LIBSAIO_DEVICE_INJECT_H #include "pci.h" +#include "device_tree.h" #define DP_ADD_TEMP_VAL(dev, val) devprop_add_value(dev, (char*)val[0], (uint8_t*)val[1], strlen(val[1]) + 1) #define DP_ADD_TEMP_VAL_DATA(dev, val) devprop_add_value(dev, (char*)val.name, (uint8_t*)val.data, val.size) -#define MAX_PCI_DEV_PATHS 4 -#define MAX_STRING_NUM_ENTRIES 100 -extern void setupDeviceProperties(Node *node); +struct DevPropString *devprop_create_string(void); +struct DevPropDevice *devprop_add_device(struct DevPropString *string, pci_dt_t * pci_dt); +struct DevPropDevice *devprop_make_device(pci_dt_t *pci_dt); +int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len); +void register_device_inject(void); +char *devprop_generate_string(struct DevPropString *string); +void devprop_free_string(struct DevPropString *string); -#define DEV_PATH_HEADER \ - uint8_t type; \ - uint8_t subtype; \ - uint16_t length; - -struct ACPIDevPath { - //uint8_t type; // = 2 ACPI device-path - //uint8_t subtype; // = 1 ACPI Device-path - //uint16_t length; // = 0x0c - DEV_PATH_HEADER - uint32_t _HID; // = 0xD041030A ? - uint32_t _UID; // = 0x00000000 PCI ROOT -}; - -struct PCIDevPath { - //uint8_t type; // = 1 Hardware device-path - //uint8_t subtype; // = 1 PCI - //uint16_t length; // = 6 - DEV_PATH_HEADER - uint8_t function; // pci func number - uint8_t device; // pci dev number -}; - -struct DevicePathEnd { - //uint8_t type; // = 0x7f - //uint8_t subtype; // = 0xff - //uint16_t length; // = 4; - DEV_PATH_HEADER -}; - -struct DevPropDevice { - uint32_t length; - uint16_t numentries; - uint16_t WHAT2; // 0x0000 ? - struct ACPIDevPath acpi_dev_path; // = 0x02010c00 0xd041030a - struct PCIDevPath pci_dev_path[MAX_PCI_DEV_PATHS]; // = 0x01010600 func dev - struct DevicePathEnd path_end; // = 0x7fff0400 - uint8_t *data; - - // ------------------------ - uint8_t num_pci_devpaths; - struct DevPropString *string; - // ------------------------ -}; - -struct DevPropString { - uint32_t length; - uint32_t WHAT2; // 0x01000000 ? - uint16_t numentries; - uint16_t WHAT3; // 0x0000 ? - struct DevPropDevice *entries; -}; - -char *efi_inject_get_devprop_string(uint32_t *len); -struct DevPropString *devprop_create_string(void); -struct DevPropDevice *devprop_add_device(struct DevPropString *string, pci_dt_t * pci_dt); -struct DevPropDevice *devprop_make_device(pci_dt_t *pci_dt); -int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len); -char *devprop_generate_string(struct DevPropString *string); -void devprop_free_string(struct DevPropString *string); - #endif /* !__LIBSAIO_DEVICE_INJECT_H */ Index: branches/cparm/i386/libsaio/sys.c =================================================================== --- branches/cparm/i386/libsaio/sys.c (revision 2117) +++ branches/cparm/i386/libsaio/sys.c (revision 2118) @@ -67,13 +67,8 @@ #include "modules.h" #include "xml.h" # include "md5.h" -#include -#if 0 /* No OS X release has ever included this. */ -#include -#else /* copied from uuid/namespace.h, just like BootX's fs.c does. */ UUID_DEFINE( kFSUUIDNamespaceSHA1, 0xB3, 0xE2, 0x0F, 0x39, 0xF2, 0x92, 0x11, 0xD6, 0x97, 0xA4, 0x00, 0x30, 0x65, 0x43, 0xEC, 0xAC ); -#endif #if UNUSED extern int multiboot_partition; @@ -400,7 +395,7 @@ fdesc = GetFreeFd(); io = &iob[fdesc]; - bzero(io, sizeof(*io)); + bzero(io, sizeof(struct iob)); // Mark the descriptor as taken. io->i_flgs = F_ALLOC; @@ -632,7 +627,7 @@ fdesc = GetFreeFd(); io = &iob[fdesc]; - bzero(io, sizeof(*io)); + bzero(io, sizeof(struct iob)); // Mark the descriptor as taken. Set the F_MEM flag to indicate // that the file buffer is provided by the caller. Index: branches/cparm/i386/libsaio/pack.c =================================================================== --- branches/cparm/i386/libsaio/pack.c (revision 0) +++ branches/cparm/i386/libsaio/pack.c (revision 2118) @@ -0,0 +1,68 @@ +/* + * Internal routine for packing UUID's + * + * Copyright (C) 1996, 1997 Theodore Ts'o. + * + * %Begin-Header% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, and the entire permission notice in its entirety, + * including the disclaimer of warranties. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF + * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * %End-Header% + */ + +#include "libsaio.h" + +void uuid_pack(const struct uuid *uu, uuid_t ptr) +{ + uint32_t tmp; + unsigned char *out = ptr; + + tmp = uu->time_low; + out[3] = (unsigned char) tmp; + tmp >>= 8; + out[2] = (unsigned char) tmp; + tmp >>= 8; + out[1] = (unsigned char) tmp; + tmp >>= 8; + out[0] = (unsigned char) tmp; + + tmp = uu->time_mid; + out[5] = (unsigned char) tmp; + tmp >>= 8; + out[4] = (unsigned char) tmp; + + tmp = uu->time_hi_and_version; + out[7] = (unsigned char) tmp; + tmp >>= 8; + out[6] = (unsigned char) tmp; + + tmp = uu->clock_seq; + out[9] = (unsigned char) tmp; + tmp >>= 8; + out[8] = (unsigned char) tmp; + + memcpy(out+10, uu->node, 6); +} + Index: branches/cparm/i386/libsaio/nbp.c =================================================================== --- branches/cparm/i386/libsaio/nbp.c (revision 2117) +++ branches/cparm/i386/libsaio/nbp.c (revision 2118) @@ -116,10 +116,10 @@ if ( !gNetBVR ) { - gNetBVR = malloc( sizeof(*gNetBVR) ); + gNetBVR = malloc( sizeof(struct BootVolume) ); if ( gNetBVR ) { - bzero(gNetBVR, sizeof(*gNetBVR)); + bzero(gNetBVR, sizeof(struct BootVolume)); gNetBVR->biosdev = biosdev; gNetBVR->flags = kBVFlagPrimary | kBVFlagNativeBoot; gNetBVR->description = NBPGetDescription; Index: branches/cparm/i386/libsaio/load.c =================================================================== --- branches/cparm/i386/libsaio/load.c (revision 2117) +++ branches/cparm/i386/libsaio/load.c (revision 2118) @@ -269,7 +269,10 @@ (vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) { - stop("Kernel overflows available space"); + *load_addr = ~0; + *load_size = 0; + stop("Kernel overflows available space"); + return -1; } if (vmsize && (strncmp(segname, "__PRELINK", sizeof("__PRELINK")) == 0 || strncmp(segname, "__PRELINK_INFO", sizeof("__PRELINK_INFO")) == 0)) Index: branches/cparm/i386/libsaio/platform.h =================================================================== --- branches/cparm/i386/libsaio/platform.h (revision 2117) +++ branches/cparm/i386/libsaio/platform.h (revision 2118) @@ -62,9 +62,6 @@ /* Maximum number of SPD bytes */ #define MAX_SPD_SIZE 256 -/* Size of SMBIOS UUID in bytes */ -#define UUID_LEN 16 - typedef struct _RamSlotInfo_t { uint32_t ModuleSize; // Size of Module in MB uint32_t Frequency; // in Mhz @@ -121,6 +118,8 @@ #define envgDeviceCount "boot.hw.device_count" #define envarchCpuType "boot.hw.cputype" +#define envPCIRootDev "boot.hw.pci_root_dev" + #define envgHaveKernelCache "boot.kern.HaveKernelCache" #define envAdler32 "boot.kern.adler32" #define envkCacheFile "boot.kern.kernelcache" Index: branches/cparm/i386/libsaio/disk.c =================================================================== --- branches/cparm/i386/libsaio/disk.c (revision 2117) +++ branches/cparm/i386/libsaio/disk.c (revision 2118) @@ -588,10 +588,10 @@ BVFree bvFreeFunc, int probe, int type, unsigned int bvrFlags ) { - BVRef bvr = (BVRef) malloc( sizeof(*bvr) ); + BVRef bvr = (BVRef) malloc( sizeof(struct BootVolume) ); if ( bvr ) { - bzero(bvr, sizeof(*bvr)); + bzero(bvr, sizeof(struct BootVolume)); bvr->biosdev = biosdev; bvr->part_no = partno; @@ -658,10 +658,10 @@ BVFree bvFreeFunc, int probe, int type, unsigned int bvrFlags ) { - BVRef bvr = (BVRef) malloc( sizeof(*bvr) ); + BVRef bvr = (BVRef) malloc( sizeof(struct BootVolume) ); if ( bvr ) { - bzero(bvr, sizeof(*bvr)); + bzero(bvr, sizeof(struct BootVolume)); bvr->biosdev = biosdev; bvr->part_no = partno; @@ -739,10 +739,10 @@ BVFree bvFreeFunc, int probe, int type, unsigned int bvrFlags ) { - BVRef bvr = (BVRef) malloc( sizeof(*bvr) ); + BVRef bvr = (BVRef) malloc( sizeof(struct BootVolume) ); if ( bvr ) { - bzero(bvr, sizeof(*bvr)); + bzero(bvr, sizeof(struct BootVolume)); bvr->biosdev = biosdev; bvr->part_no = partno; @@ -837,7 +837,7 @@ #endif // Create a new mapping. - map = (struct DiskBVMap *) malloc( sizeof(*map) ); + map = (struct DiskBVMap *) malloc( sizeof(struct DiskBVMap) ); if ( !map ) { return NULL; @@ -1138,7 +1138,7 @@ // Create a new mapping. - map = (struct DiskBVMap *) malloc( sizeof(*map) ); + map = (struct DiskBVMap *) malloc( sizeof(struct DiskBVMap) ); if ( !map ) { return NULL; @@ -1399,7 +1399,7 @@ DBG("Read GPT\n"); // Allocate a new map for this BIOS device and insert it into the chain - map = malloc(sizeof(*map)); + map = (struct DiskBVMap *) malloc(sizeof(struct DiskBVMap)); if (!map) { goto scanErr; } @@ -1830,6 +1830,10 @@ void rescanBIOSDevice(int biosdev) { struct DiskBVMap *oldMap = diskResetBootVolumes(biosdev); + if (oldMap == NULL) + { + return; + } CacheReset(); diskFreeMap(oldMap); oldMap = NULL; @@ -1856,7 +1860,10 @@ else if(prevMap != NULL) prevMap->next = map->next; else - stop(""); + { + stop("diskResetBootVolumes error\n"); + return NULL; + } } // Return the old map, either to be freed, or reinserted later return map; @@ -1966,11 +1973,11 @@ /* * Allocate and copy the matched bvr entry into a new one. */ - newBVR = (BVRef) malloc(sizeof(*newBVR)); + newBVR = (BVRef) malloc(sizeof(struct BootVolume)); if (!newBVR) { continue; } - bcopy(bvr, newBVR, sizeof(*newBVR)); + bcopy(bvr, newBVR, sizeof(struct BootVolume)); /* * Adjust the new bvr's fields. @@ -2245,7 +2252,7 @@ { if ( gBootSector == NULL ) { - gBootSector = (struct disk_blk0 *) malloc(sizeof(*gBootSector)); + gBootSector = (struct disk_blk0 *) malloc(sizeof(struct disk_blk0)); if ( gBootSector == NULL ) return -1; } bootSector = gBootSector; @@ -2283,7 +2290,7 @@ { if ( gBootSector == NULL ) { - gBootSector = (struct disk_blk0 *) malloc(sizeof(*gBootSector)); + gBootSector = (struct disk_blk0 *) malloc(sizeof(struct disk_blk0)); if ( gBootSector == NULL ) return -1; } bootSector = (struct disk_boot1f32_blk *) gBootSector; Index: branches/cparm/i386/libsaio/acpi_tools.c =================================================================== --- branches/cparm/i386/libsaio/acpi_tools.c (revision 2117) +++ branches/cparm/i386/libsaio/acpi_tools.c (revision 2118) @@ -194,9 +194,13 @@ // Compute number of table pointers included in RSDT num_tables = get_num_tables(rsdt); - for (index = 0; index < num_tables; index++) { + for (index = 0; index < num_tables; index++) + { + if (!table_array[index]) continue; + if ((*(U32 *) (table_array[index]->Signature) == signature) && - (GetChecksum(table_array[index], table_array[index]->Length) == 0)) { + (GetChecksum(table_array[index], table_array[index]->Length) == 0)) + { return (table_array[index]); } } @@ -222,11 +226,15 @@ switch (method) { case 0x2: { - for (index = 0; index < num_tables; index++) { + for (index = 0; index < num_tables; index++) + { U64 ptr = xsdt->TableOffsetEntry[index]; + if (!ptr) continue; + if ((*(U32 *) ((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Signature == signature) && - (GetChecksum(((ACPI_TABLE_HEADER *) (unsigned long)ptr), ((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Length) == 0)) { + (GetChecksum(((ACPI_TABLE_HEADER *) (unsigned long)ptr), ((ACPI_TABLE_HEADER *) (unsigned long)ptr)->Length) == 0)) + { return (((ACPI_TABLE_HEADER *) (unsigned long)ptr)); } } @@ -237,9 +245,13 @@ { ACPI_TABLE_HEADER *table = (ACPI_TABLE_HEADER *) xsdt->TableOffsetEntry; - for (index = 0; index < num_tables; index++) { + for (index = 0; index < num_tables; index++) + { + if (!table) continue; + if (((U32) (table->Signature) == signature) && - (GetChecksum(table, table->Length) == 0)) { + (GetChecksum(table, table->Length) == 0)) + { return (table); } // Move array pointer to next 64-bit pointer @@ -292,9 +304,14 @@ if (current == 0ul) return (0ul); - for (; current < end; current += 16) { - if (*(volatile U64 *)current == NAMESEG64("RSD PTR ")) { - if (GetChecksum(current, ACPI_RSDP_REV0_SIZE) == 0) { + for (; current < end; current += 16) + { + if (!current) continue; + + if (*(volatile U64 *)current == NAMESEG64("RSD PTR ")) + { + if (GetChecksum(current, ACPI_RSDP_REV0_SIZE) == 0) + { // RSD pointer structure checksum okay, lookup the RSDT pointer. acpi_tables->RsdPointer = (ACPI_TABLE_RSDP *)current; acpi_tables->RsdtPointer = (ACPI_TABLE_RSDT *) acpi_tables->RsdPointer->RsdtPhysicalAddress; Index: branches/cparm/i386/libsaio/arc4random-fbsd.c =================================================================== --- branches/cparm/i386/libsaio/arc4random-fbsd.c (revision 2117) +++ branches/cparm/i386/libsaio/arc4random-fbsd.c (revision 2118) @@ -284,12 +284,12 @@ return (r % upper_bound); } +#if 0 void arc4_init(void) { } -#if 0 /*-------- Test code for i386 --------*/ #include #include Index: branches/cparm/i386/libsaio/pci.c =================================================================== --- branches/cparm/i386/libsaio/pci.c (revision 2117) +++ branches/cparm/i386/libsaio/pci.c (revision 2118) @@ -8,7 +8,7 @@ #include "bootstruct.h" #include "pci.h" #include "modules.h" -#include "device_inject.h" +#include "platform.h" #ifndef DEBUG_PCI #define DEBUG_PCI 0 @@ -20,8 +20,6 @@ #define DBG(x...) #endif -pci_dt_t *root_pci_dev; -static char* dev_path; // TODO: Figure out what is going on here... static void scan_pci_bus(pci_dt_t *start, uint8_t bus); static void enable_pci_devs(void); @@ -145,14 +143,17 @@ void build_pci_dt(void) { - dev_path = malloc(sizeof(char) * 256); // TODO: remove - - root_pci_dev = malloc(sizeof(pci_dt_t)); + pci_dt_t *root_pci_dev; + + root_pci_dev = malloc(sizeof(pci_dt_t)); - if (!dev_path || !root_pci_dev) { + if (!root_pci_dev) + { stop("Couldn't allocate memory for the pci root device\n"); return ; } + set_env(envPCIRootDev,(uint32_t)root_pci_dev); + bzero(root_pci_dev, sizeof(pci_dt_t)); enable_pci_devs(); scan_pci_bus(root_pci_dev, 0); @@ -164,51 +165,11 @@ #endif } -#if 0 -char *get_pci_dev_path(pci_dt_t *pci_dt) -{ - char* buffer = malloc(sizeof(char) * 256); +static void setup_pci_devs(pci_dt_t *current) +{ - if (!buffer) { - return NULL; - } - - pci_dt_t *current; - pci_dt_t *end; - char tmp[64]; - - buffer[0] = 0; - end = root_pci_dev; - - int uid = getPciRootUID(); - while (end != pci_dt) - { - current = pci_dt; - while (current->parent != end) - current = current->parent; - end = current; - if (current->parent == root_pci_dev) - { - snprintf(tmp, sizeof(tmp),"PciRoot(0x%x)/Pci(0x%x,0x%x)", uid, - current->dev.bits.dev, current->dev.bits.func); - } - else - { - snprintf(tmp, sizeof(tmp) ,"/Pci(0x%x,0x%x)", - current->dev.bits.dev, current->dev.bits.func); - } - snprintf(buffer, sizeof(char) * 256,"%s%s", buffer, tmp); - } - return buffer; -} -#endif - -void setup_pci_devs(pci_dt_t *pci_dt) -{ - pci_dt_t *current = pci_dt; - while (current) - { + { execute_hook("PCIDevice", (void*)current, NULL, NULL, NULL, NULL, NULL); setup_pci_devs(current->children); @@ -216,6 +177,19 @@ } } +void setup_root_pci_devs(void) +{ + pci_dt_t *root_pci_dev = (pci_dt_t *)(uint32_t)get_env(envPCIRootDev); + + if (!root_pci_dev) + { + stop("No PCI root device\n"); + return ; + } + + setup_pci_devs(root_pci_dev); +} + #ifndef OPTION_ROM void dump_pci_dt(pci_dt_t *pci_dt) { Index: branches/cparm/i386/libsaio/biosfn.c =================================================================== --- branches/cparm/i386/libsaio/biosfn.c (revision 2117) +++ branches/cparm/i386/libsaio/biosfn.c (revision 2118) @@ -827,7 +827,7 @@ dp->cylinders = bb.ecx.r.h | ((bb.ecx.r.l & 0xC0) << 2); dp->totalDrives = bb.edx.r.l; } else { - bzero(dp, sizeof(*dp)); + bzero(dp, sizeof(struct driveParameters)); } return bb.eax.r.h; Index: branches/cparm/i386/libsaio/convert.c =================================================================== --- branches/cparm/i386/libsaio/convert.c (revision 2117) +++ branches/cparm/i386/libsaio/convert.c (revision 2118) @@ -79,28 +79,6 @@ return uuid; } -/** XXX AsereBLN replace by strtoul */ -#if UNUSED -uint32_t ascii_hex_to_int(char *buff) -{ - uint32_t value = 0, i, digit; - for(i = 0; i < (uint32_t)strlen(buff); i++) - { - if (buff[i] >= 48 && buff[i] <= 57) // '0' through '9' - digit = buff[i] - 48; - else if (buff[i] >= 65 && buff[i] <= 70) // 'A' through 'F' - digit = buff[i] - 55; - else if (buff[i] >= 97 && buff[i] <= 102) // 'a' through 'f' - digit = buff[i] - 87; - else - return value; - - value = digit + 16 * value; - } - return value; -} -#endif - void *convertHexStr2Binary(const char *hexStr, int *outLength) { int len; Index: branches/cparm/i386/libsaio/pci.h =================================================================== --- branches/cparm/i386/libsaio/pci.h (revision 2117) +++ branches/cparm/i386/libsaio/pci.h (revision 2118) @@ -53,7 +53,6 @@ #define PCI_ADDR_REG 0xcf8 #define PCI_DATA_REG 0xcfc -extern pci_dt_t *root_pci_dev; extern uint8_t pci_config_read8(uint32_t, uint8_t); extern uint16_t pci_config_read16(uint32_t, uint8_t); extern uint32_t pci_config_read32(uint32_t, uint8_t); @@ -63,7 +62,7 @@ //extern char *get_pci_dev_path(pci_dt_t *); extern void build_pci_dt(void); extern void dump_pci_dt(pci_dt_t *); -extern void setup_pci_devs(pci_dt_t *pci_dt); +extern void setup_root_pci_devs(void); extern int getPciRootUID(void); //----------------------------------------------------------------------------- Index: branches/cparm/i386/libsaio/saio_types.h =================================================================== --- branches/cparm/i386/libsaio/saio_types.h (revision 2117) +++ branches/cparm/i386/libsaio/saio_types.h (revision 2118) @@ -35,6 +35,7 @@ #include #endif #include "bootXnu.h" +#include "uuidP.h" #if DEBUG #define DEBUG_DISK(x) printf x @@ -77,6 +78,7 @@ #define kRenamePartition "Rename Partition" /* disk.c */ #define kSMBIOSKey "SMBIOS" /* fake_efi.c */ #define kSystemID "SystemId" /* fake_efi.c */ +#define kRandomSystemID "RandomSystemId" /* fake_efi.c */ #define kSystemType "SystemType" /* fake_efi.c */ #define kPCIRootUID "PCIRootUID" /* pci_root.c */ #define kDefaultPartition "Default Partition" /* sys.c */ @@ -86,7 +88,10 @@ #define kRebootOnPanic "RebootOnPanic" #define kEnableHiDPI "EnableHiDPI" // enable High resolution display (aka Retina) +#define UUID_LEN sizeof(uuid_t) +#define UUID_STR_LEN sizeof(uuid_string_t) + #define PLATFORM_NAME_LEN 64 #define ROOT_PATH_LEN 256 Index: branches/cparm/i386/libsaio/convert.h =================================================================== --- branches/cparm/i386/libsaio/convert.h (revision 2117) +++ branches/cparm/i386/libsaio/convert.h (revision 2118) @@ -9,10 +9,6 @@ #include "libsaio.h" #include "efi.h" -#define UUID_LEN 16 - -#define UUID_STR_LEN UUID_LEN*2 + 8 - const char * getStringFromUUID(const EFI_CHAR8* uuid); EFI_CHAR8* getUUIDFromString(const char *source); void *convertHexStr2Binary(const char *hexStr, int *outLength); Index: branches/cparm/i386/libsaio/fake_efi.c =================================================================== --- branches/cparm/i386/libsaio/fake_efi.c (revision 2117) +++ branches/cparm/i386/libsaio/fake_efi.c (revision 2118) @@ -14,7 +14,6 @@ #include "fake_efi.h" #include "efi_tables.h" #include "platform.h" -#include "device_inject.h" #include "convert.h" #include "pci.h" #include "sl.h" @@ -75,6 +74,7 @@ static VOID setup_machine_signature(VOID); static VOID setupEfiConfigurationTable(VOID); static EFI_STATUS EFI_FindAcpiTables(VOID); +static VOID efi_setupDeviceProperties(Node *node); /*========================================================================== * Utility function to make a device tree string from an EFI_GUID @@ -110,13 +110,10 @@ /* Info About the current Firmware */ #define FIRMWARE_MAINTENER "cparm, armelcadetpetit@gmail.com" -static EFI_CHAR16 const FIRMWARE_NAME[] = {'M','a','s','h','e','r','b','r','u','m','-','2', 0}; -static EFI_UINT32 const FIRMWARE_REVISION = 0x00010800; //1.8 +static EFI_CHAR16 const FIRMWARE_NAME[] = {'M','a','s','h','e','r','b','r','u','m','-','2','.','1', 0}; +static EFI_UINT32 const FIRMWARE_REVISION = 0x00020100; //2.1 static EFI_UINT32 const DEVICE_SUPPORTED = 0x00000001; -/* Default platform system_id (fix by IntVar) */ -static EFI_CHAR8 const SYSTEM_ID[] = "0123456789ABCDEF"; //random value gen by uuidgen - /* Just a ret instruction */ static uint8_t const VOIDRET_INSTRUCTIONS[] = {0xc3}; @@ -240,7 +237,50 @@ } } -void finalizeEFIConfigTable(void ) +static VOID efi_setupDeviceProperties(Node *node) +{ + const char *val; + uint8_t *binStr; + uint8_t *kbinStr; + + int cnt = 0, cnt2 = 0; + + static char DEVICE_PROPERTIES_PROP[] = "device-properties"; + + EFI_STATUS ret = EFI_NO_MEDIA; + + execute_hook("setupDeviceProperties", node, &ret, NULL, NULL, NULL, NULL); + + if (ret != EFI_SUCCESS) + { + /* + * Use the static "device-properties" boot config key contents if available + */ + if (!getValueForKey(kDeviceProperties, &val, &cnt, DEFAULT_BOOT_CONFIG)) + { + return; + } + + if (cnt > 1) + { + binStr = convertHexStr2Binary(val, &cnt2); + + if (cnt2 > 0) + { + kbinStr = (uint8_t*)AllocateKernelMemory(cnt2); + + if (kbinStr) + { + bcopy(binStr,kbinStr,cnt2); + DT__AddProperty(node, DEVICE_PROPERTIES_PROP, cnt2, kbinStr); + } + } + } + } +} + + +void finalizeEFIConfigTable(void) { if (get_env(envarchCpuType) == CPU_TYPE_I386) { @@ -691,15 +731,36 @@ // unable to determine UUID for host. Error: 35 fix // Rek: new SMsystemid option conforming to smbios notation standards, this option should // belong to smbios config only ... - EFI_CHAR8* ret = getUUIDFromString(getStringForKey(kSystemID, DEFAULT_BOOT_CONFIG)); + EFI_CHAR8* ret = NULL; + uuid_t uuid; + { + bool value = false; + if (getBoolForKey( kRandomSystemID, &value, DEFAULT_BOOT_CONFIG ) && value) + { + uuid_generate_random(uuid); + ret = (EFI_CHAR8*)uuid; + if (ret) goto out; + } + } + + + { + const char *user_uuid = getStringForKey(kSystemID, DEFAULT_BOOT_CONFIG); + if (user_uuid) + { + ret = getUUIDFromString(user_uuid); + } + } + if (!ret) // try bios dmi info UUID extraction ret = getSmbiosUUID(); if (!ret) { - // no bios dmi UUID available, set a fixed value for system-id - ret=getUUIDFromString((const char*) SYSTEM_ID); + // no bios dmi UUID available, get random uuid + uuid_generate_random(uuid); + ret = (EFI_CHAR8*)uuid; verbose("Customizing SystemID with : %s\n", getStringFromUUID(ret)); // apply a nice formatting to the displayed output } else @@ -710,8 +771,10 @@ } +out: if (ret) - { + { + memcpy(sysid, ret, UUID_LEN); set_env_copy(envSysId, sysid, sizeof(sysid)); } @@ -727,7 +790,11 @@ static VOID setupSystemType(VOID) { Node *node = DT__FindNode("/", false); - if (node == 0) stop("Couldn't get root node"); + if (node == 0) + { + stop("Couldn't get root node"); + return; + } // we need to write this property after facp parsing // Export system-type only if it has been overrriden by the SystemType option kType = get_env(envType); @@ -740,7 +807,11 @@ node = DT__FindNode("/", false); - if (node == 0) stop("Couldn't get root node"); + if (node == 0) + { + stop("Couldn't get root node"); + return; + } #ifndef NO_BOOT_IMG { @@ -934,7 +1005,7 @@ } // Fill /efi/device-properties node. - setupDeviceProperties(efiNode); + efi_setupDeviceProperties(efiNode); } /* @@ -1090,7 +1161,7 @@ void setupFakeEfi(void) { // Collect PCI info &| Generate device prop string - setup_pci_devs(root_pci_dev); + setup_root_pci_devs(); // load smbios.plist file if any setupSmbiosConfigFile("SMBIOS.plist"); Index: branches/cparm/i386/boot2/graphics.c =================================================================== --- branches/cparm/i386/boot2/graphics.c (revision 2117) +++ branches/cparm/i386/boot2/graphics.c (revision 2118) @@ -143,12 +143,10 @@ // Clear output mode info. - //bzero( outModeInfo, sizeof(*outModeInfo) ); bzero( outModeInfo, sizeof(VBEModeInfoBlock) ); // Get VBE controller info containing the list of supported modes. - //bzero( &vbeInfo, sizeof(vbeInfo) ); bzero( &vbeInfo, sizeof(VBEInfoBlock) ); strlcpy( (char*)&vbeInfo, "VBE2", sizeof(VBEInfoBlock) ); Index: branches/cparm/i386/boot2/boot.c =================================================================== --- branches/cparm/i386/boot2/boot.c (revision 2117) +++ branches/cparm/i386/boot2/boot.c (revision 2118) @@ -407,8 +407,9 @@ // Scan and record the system's hardware information. scan_platform(); + // Pseudo-random generator initialization. - arc4_init(); + // arc4_init(); set_env(envgBIOSDev, (BIOSDev = biosdev & kBIOSDevMask)); set_env(envShouldboot, false); @@ -419,12 +420,12 @@ set_env(envgHaveKernelCache, false); InitBootPrompt(); - + // First get info for boot volume. scanBootVolumes(BIOSDev, 0); bvChain = getBVChainForBIOSDev(BIOSDev); - + setBootGlobals(bvChain); // Load Booter boot.plist config file @@ -899,7 +900,7 @@ SetgRootPath(platformInfo->rootPath); #endif - Adler32 = OSSwapHostToBigInt32(adler32((unsigned char *)platformInfo, sizeof(*platformInfo))); + Adler32 = OSSwapHostToBigInt32(adler32((unsigned char *)platformInfo, sizeof(PlatformInfo))); safe_set_env(envAdler32, Adler32); free(platformInfo); Index: branches/cparm/i386/boot2/drivers.c =================================================================== --- branches/cparm/i386/boot2/drivers.c (revision 2117) +++ branches/cparm/i386/boot2/drivers.c (revision 2118) @@ -129,7 +129,10 @@ gFileName = malloc( DEFAULT_DRIVER_SPEC_SIZE ); if ( !gExtensionsSpec || !gDriverSpec || !gFileSpec || !gTempSpec || !gFileName ) + { stop("InitDriverSupport error"); + return -1; + } DriverSet = true; set_env(envDriverExtSpec,(uint32_t)gExtensionsSpec); Index: branches/cparm/i386/boot2/options.c =================================================================== --- branches/cparm/i386/boot2/options.c (revision 2117) +++ branches/cparm/i386/boot2/options.c (revision 2118) @@ -561,7 +561,7 @@ setCursorPosition(0, 0, 1); } - dump_pci_dt(root_pci_dev->children); + dump_pci_dt(((pci_dt_t *)(uint32_t)get_env(envPCIRootDev))->children); pause(); Index: branches/cparm/i386/modules/RamDiskLoader/ramdisk.c =================================================================== --- branches/cparm/i386/modules/RamDiskLoader/ramdisk.c (revision 2117) +++ branches/cparm/i386/modules/RamDiskLoader/ramdisk.c (revision 2118) @@ -130,6 +130,10 @@ { // Release ramdisk BVRef and DiskBVMap. struct DiskBVMap *oldMap = diskResetBootVolumes(0x100); + if (oldMap == NULL) + { + return; + } CacheReset(); diskFreeMap(oldMap); Index: branches/cparm/i386/modules/YellowIconFixer/YellowIconFixer.c =================================================================== --- branches/cparm/i386/modules/YellowIconFixer/YellowIconFixer.c (revision 2117) +++ branches/cparm/i386/modules/YellowIconFixer/YellowIconFixer.c (revision 2118) @@ -64,6 +64,7 @@ void YellowIconFixer_start(void); void YellowIconFixer_start(void) { + register_device_inject(); register_hook_callback("PCIDevice", &SATA_hook); } Index: branches/cparm/i386/modules/YellowIconFixer/Makefile =================================================================== --- branches/cparm/i386/modules/YellowIconFixer/Makefile (revision 2117) +++ branches/cparm/i386/modules/YellowIconFixer/Makefile (revision 2118) @@ -58,7 +58,7 @@ VPATH = $(OBJROOT):$(SYMROOT) -SATA_OBJS = YellowIconFixer.o stack_protector.o +SATA_OBJS = YellowIconFixer.o device_inject.o stack_protector.o SFILES = @@ -84,7 +84,7 @@ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ -macosx_version_min 10.6 \ - $(OBJROOT)/stack_protector.o $(OBJROOT)/YellowIconFixer.o -o $(SYMROOT)/$(BUNDLE_EXEC) + $(OBJROOT)/stack_protector.o $(OBJROOT)/device_inject.o $(OBJROOT)/YellowIconFixer.o -o $(SYMROOT)/$(BUNDLE_EXEC) @rm -rf $(SYMROOT)/$(BUNDLE_NAME).bundle @mkdir $(SYMROOT)/$(BUNDLE_NAME).bundle @mkdir $(SYMROOT)/$(BUNDLE_NAME).bundle/Contents @@ -118,6 +118,10 @@ YellowIconFixer.o: $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "YellowIconFixer.c" $(INC) -o "$(OBJROOT)/YellowIconFixer.o" +device_inject.o: + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "$(LIBSAIODIR)/device_inject.c" $(INC) -o "$(OBJROOT)/device_inject.o" + + include ../../MakeInc.dir # dependencies Index: branches/cparm/i386/modules/GUI/graphic_utils.c =================================================================== --- branches/cparm/i386/modules/GUI/graphic_utils.c (revision 2117) +++ branches/cparm/i386/modules/GUI/graphic_utils.c (revision 2118) @@ -486,12 +486,10 @@ // Clear output mode info. - //bzero( outModeInfo, sizeof(*outModeInfo) ); bzero( outModeInfo, sizeof(VBEModeInfoBlock) ); // Get VBE controller info containing the list of supported modes. - //bzero( &vbeInfo, sizeof(vbeInfo) ); bzero( &vbeInfo, sizeof(VBEInfoBlock) ); strlcpy( (char*)&vbeInfo, "VBE2", sizeof(VBEInfoBlock) ); Index: branches/cparm/i386/modules/KernelPatcher/kernel_patcher.c =================================================================== --- branches/cparm/i386/modules/KernelPatcher/kernel_patcher.c (revision 2117) +++ branches/cparm/i386/modules/KernelPatcher/kernel_patcher.c (revision 2118) @@ -8,6 +8,16 @@ #include "platform.h" #include "modules.h" +#ifndef DEBUG_KERNEL_PATCHER +#define DEBUG_KERNEL_PATCHER 0 +#endif + +#if DEBUG_KERNEL_PATCHER +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + long long symbol_handler(char* module, char* symbolName, long long addr, char is64); patchRoutine_t* patches = NULL; @@ -17,6 +27,8 @@ static kernSymbols_t* lookup_kernel_symbol(const char* name); static int determineKernelArchitecture(void* kernelData); static int locate_symbols(void* kernelData); +static unsigned int parse_mach_64(char *module, void* binary, long long(*symbol_handler)(char*, char*, long long, char)); +static unsigned int handle_symtable_64(char *module, UInt32 base, struct symtab_command* symtabCommand, long long(*symbol_handler)(char*, char*, long long, char), char is64); /* * Internal patches provided by this module. @@ -219,6 +231,310 @@ } } +static unsigned int parse_mach_64(char *module, void* binary, long long(*symbol_handler)(char*, char*, long long, char)) // TODO: add param to specify valid archs +{ + char is64 = false; + unsigned int module_start = 0xFFFFFFFF; + EFI_STATUS bind_status = EFI_SUCCESS; + + // TODO convert all of the structs to a union + struct dyld_info_command* dyldInfoCommand = NULL; + struct symtab_command* symtabCommand = NULL; + + { + struct segment_command *segCommand = NULL; + struct segment_command_64 *segCommand64 = NULL; + struct load_command *loadCommand = NULL; + UInt32 binaryIndex = 0; + UInt16 cmd = 0; + + // Parse through the load commands + if(((struct mach_header*)binary)->magic == MH_MAGIC) + { + is64 = false; + binaryIndex += sizeof(struct mach_header); + } + else if(((struct mach_header_64*)binary)->magic == MH_MAGIC_64) + { + // NOTE: modules cannot be 64bit... + is64 = true; + binaryIndex += sizeof(struct mach_header_64); + } + else + { + printf("Modules: Invalid mach magic\n"); + getc(); + return 0xFFFFFFFF; + } + + + + /*if(((struct mach_header*)binary)->filetype != MH_DYLIB) + { + printf("Module is not a dylib. Unable to load.\n"); + getc(); + return NULL; // Module is in the incorrect format + }*/ + + while(cmd < ((struct mach_header*)binary)->ncmds) + { + cmd++; + + loadCommand = binary + binaryIndex; + UInt32 cmdSize = loadCommand->cmdsize; + + + switch ((loadCommand->cmd & 0x7FFFFFFF)) + { + case LC_SYMTAB: + symtabCommand = binary + binaryIndex; + break; + + case LC_SEGMENT: // 32bit macho + { + segCommand = binary + binaryIndex; + + //printf("Segment name is %s\n", segCommand->segname); + + if(strncmp("__TEXT", segCommand->segname, sizeof("__TEXT")) == 0) + { + UInt32 sectionIndex; + +#if DEBUG_KERNEL_PATCHER + unsigned long fileaddr; + long filesize; + vmaddr = (segCommand->vmaddr & 0x3fffffff); + vmsize = segCommand->vmsize; + fileaddr = ((unsigned long)(binary + binaryIndex) + segCommand->fileoff); + filesize = segCommand->filesize; + + printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n", + segCommand->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, + (unsigned) segCommand->nsects, (unsigned)segCommand->flags); +#if DEBUG_KERNEL_PATCHER==2 + + getc(); +#endif +#endif + + sectionIndex = sizeof(struct segment_command); + + struct section *sect; + + while(sectionIndex < segCommand->cmdsize) + { + sect = binary + binaryIndex + sectionIndex; + + sectionIndex += sizeof(struct section); + + + if(strncmp("__text", sect->sectname,sizeof("__text")) == 0) + { + // __TEXT,__text found, save the offset and address for when looking for the calls. + textSection = sect->offset; + textAddress = sect->addr; + break; + } + } + } + break; + } + case LC_SEGMENT_64: // 64bit macho's + { + segCommand64 = binary + binaryIndex; + + //printf("Segment name is %s\n", segCommand->segname); + + if(strncmp("__TEXT", segCommand64->segname, sizeof("__TEXT")) == 0) + { + UInt32 sectionIndex; + +#if DEBUG_KERNEL_PATCHER + unsigned long fileaddr; + long filesize; + vmaddr = (segCommand64->vmaddr & 0x3fffffff); + vmsize = segCommand64->vmsize; + fileaddr = ((unsigned long)(binary + binaryIndex) + segCommand64->fileoff); + filesize = segCommand64->filesize; + + printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n", + segCommand64->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, + (unsigned) segCommand64->nsects, (unsigned)segCommand64->flags); +#if DEBUG_KERNEL_PATCHER==2 + + getc(); +#endif +#endif + + sectionIndex = sizeof(struct segment_command_64); + + struct section_64 *sect; + + while(sectionIndex < segCommand64->cmdsize) + { + sect = binary + binaryIndex + sectionIndex; + + sectionIndex += sizeof(struct section_64); + + + if(strncmp("__text", sect->sectname, sizeof("__text")) == 0) + { + // __TEXT,__text found, save the offset and address for when looking for the calls. + textSection = sect->offset; + textAddress = sect->addr; + + break; + } + } + } + + break; + } + case LC_DYSYMTAB: + break; + + case LC_LOAD_DYLIB: + case LC_LOAD_WEAK_DYLIB ^ LC_REQ_DYLD: + break; + + case LC_ID_DYLIB: + break; + + + case LC_DYLD_INFO: + // Bind and rebase info is stored here + dyldInfoCommand = binary + binaryIndex; + break; + + case LC_UUID: + break; + + case LC_UNIXTHREAD: + break; + + default: + DBG("Unhandled loadcommand 0x%X\n", loadCommand->cmd & 0x7FFFFFFF); + break; + + } + + binaryIndex += cmdSize; + } + //if(!moduleName) return NULL; + } + + // bind_macho uses the symbols. + module_start = handle_symtable_64(module, (UInt32)binary, symtabCommand, symbol_handler, is64); + + // Rebase the module before binding it. + if(dyldInfoCommand && dyldInfoCommand->rebase_off) + { + rebase_macho(binary, (char*)dyldInfoCommand->rebase_off, dyldInfoCommand->rebase_size); + } + + if(dyldInfoCommand && dyldInfoCommand->bind_off) + { + bind_status = bind_macho(module, binary, (char*)dyldInfoCommand->bind_off, dyldInfoCommand->bind_size); + } + + if(dyldInfoCommand && dyldInfoCommand->weak_bind_off && (bind_status == EFI_SUCCESS)) + { + // NOTE: this currently should never happen. + bind_status = bind_macho(module, binary, (char*)dyldInfoCommand->weak_bind_off, dyldInfoCommand->weak_bind_size); + } + + if(dyldInfoCommand && dyldInfoCommand->lazy_bind_off && (bind_status == EFI_SUCCESS)) + { + // NOTE: we are binding the lazy pointers as a module is laoded, + // This should be changed to bind when a symbol is referened at runtime instead. + bind_status = bind_macho(module, binary, (char*)dyldInfoCommand->lazy_bind_off, dyldInfoCommand->lazy_bind_size); + } + + if (bind_status != EFI_SUCCESS) { + module_start = 0xFFFFFFFF; + } + + return module_start; + +} + +static unsigned int handle_symtable_64(char *module, UInt32 base, struct symtab_command* symtabCommand, long long(*symbol_handler)(char*, char*, long long, char), char is64) +{ + unsigned int module_start = 0xFFFFFFFF; + + UInt32 symbolIndex = 0; + if (!symtabCommand) { + return 0xFFFFFFFF; + } + char* symbolString = base + (char*)symtabCommand->stroff; + if(!is64) + { + struct nlist* symbolEntry = (void*)base + symtabCommand->symoff; + while(symbolIndex < symtabCommand->nsyms) + { + if(symbolEntry->n_value) + { + if(strstr(symbolString + symbolEntry->n_un.n_strx, "module_start") || (strncmp(symbolString + symbolEntry->n_un.n_strx, "start", sizeof("start")) == 0)) + { + module_start = base + symbolEntry->n_value; + DBG("n_value %x module_start %x\n", (unsigned)symbolEntry->n_value, (unsigned)module_start); + } + else + { + symbol_handler(module, symbolString + symbolEntry->n_un.n_strx, (long long)base + symbolEntry->n_value, is64); + + + } +#if DEBUG_KERNEL_PATCHER + bool isTexT = (((unsigned)symbolEntry->n_value > (unsigned)vmaddr) && ((unsigned)(vmaddr + vmsize) > (unsigned)symbolEntry->n_value )); + printf("%s %s\n", isTexT ? "__TEXT :" : "__DATA(OR ANY) :", symbolString + symbolEntry->n_un.n_strx); +#if DEBUG_KERNEL_PATCHER==2 + + if(strcmp(symbolString + symbolEntry->n_un.n_strx, "_BootHelp_txt") == 0) + { + long long addr = (long long)base + symbolEntry->n_value; + unsigned char *BootHelp = NULL; + BootHelp = (unsigned char*)(UInt32)addr; + printf("method 1: __DATA : BootHelp_txt[0] %x\n", BootHelp[0]); + + long long addr2 = symbolEntry->n_value; + unsigned char *BootHelp2 = NULL; + BootHelp2 = (unsigned char*)(UInt32)addr2; + printf("method 2: __DATA : BootHelp_txt[0] %x\n", BootHelp2[0]); + } +#endif +#endif + + } + + symbolEntry++; + symbolIndex++; // TODO remove + } + } + else + { + struct nlist_64* symbolEntry = (void*)base + symtabCommand->symoff; + // NOTE First entry is *not* correct, but we can ignore it (i'm getting radar:// right now) + while(symbolIndex < symtabCommand->nsyms) + { + + if(strstr(symbolString + symbolEntry->n_un.n_strx, "module_start") || (strncmp(symbolString + symbolEntry->n_un.n_strx, "start",sizeof("start")) == 0)) + { + module_start = (unsigned int)(base + symbolEntry->n_value); + } + else + { + symbol_handler(module, symbolString + symbolEntry->n_un.n_strx, (long long)base + symbolEntry->n_value, is64); + } + + symbolEntry++; + symbolIndex++; // TODO remove + } + } + return module_start; + +} + /** ** This functions located the requested symbols in the mach-o file. ** as well as determines the start of the __TEXT segment and __TEXT,__text sections @@ -226,7 +542,7 @@ static int locate_symbols(void* kernelData) { char is64 = 1; - parse_mach("VirtualXnuSyms",kernelData, symbol_handler); + parse_mach_64("VirtualXnuSyms",kernelData, symbol_handler); //handle_symtable((UInt32)kernelData, symtableData, &symbol_handler, determineKernelArchitecture(kernelData) == KERNEL_64); return 1 << is64; } Index: branches/cparm/i386/modules/Networking/Networking.c =================================================================== --- branches/cparm/i386/modules/Networking/Networking.c (revision 2117) +++ branches/cparm/i386/modules/Networking/Networking.c (revision 2118) @@ -9,6 +9,7 @@ #include "pci.h" #include "device_inject.h" #include "platform.h" +#include "fake_efi.h" #ifndef DEBUG_ETHERNET #define DEBUG_ETHERNET 0 @@ -63,6 +64,7 @@ void Networking_start(void); void Networking_start(void) { + register_device_inject(); register_hook_callback("PCIDevice", &Networking_hook); } Index: branches/cparm/i386/modules/Networking/Makefile =================================================================== --- branches/cparm/i386/modules/Networking/Makefile (revision 2117) +++ branches/cparm/i386/modules/Networking/Makefile (revision 2118) @@ -58,7 +58,7 @@ VPATH = $(OBJROOT):$(SYMROOT) -NET_OBJS = Networking.o stack_protector.o +NET_OBJS = Networking.o device_inject.o stack_protector.o SFILES = @@ -84,7 +84,7 @@ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ -macosx_version_min 10.6 \ - $(OBJROOT)/stack_protector.o $(OBJROOT)/Networking.o -o $(SYMROOT)/$(BUNDLE_EXEC) + $(OBJROOT)/stack_protector.o $(OBJROOT)/device_inject.o $(OBJROOT)/Networking.o -o $(SYMROOT)/$(BUNDLE_EXEC) @rm -rf $(SYMROOT)/$(BUNDLE_NAME).bundle @mkdir $(SYMROOT)/$(BUNDLE_NAME).bundle @mkdir $(SYMROOT)/$(BUNDLE_NAME).bundle/Contents @@ -118,6 +118,10 @@ Networking.o: $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "Networking.c" $(INC) -o "$(OBJROOT)/Networking.o" +device_inject.o: + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "$(LIBSAIODIR)/device_inject.c" $(INC) -o "$(OBJROOT)/device_inject.o" + + include ../../MakeInc.dir # dependencies Index: branches/cparm/i386/modules/GraphicsEnabler/GraphicsEnabler.c =================================================================== --- branches/cparm/i386/modules/GraphicsEnabler/GraphicsEnabler.c (revision 2117) +++ branches/cparm/i386/modules/GraphicsEnabler/GraphicsEnabler.c (revision 2118) @@ -12,6 +12,7 @@ #include "ati.h" #include "gma.h" #include "modules.h" +#include "device_inject.h" void GraphicsEnabler_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6); @@ -19,6 +20,7 @@ void GraphicsEnabler_start(void) { + register_device_inject(); register_hook_callback("PCIDevice", &GraphicsEnabler_hook); } Index: branches/cparm/i386/modules/GraphicsEnabler/Makefile =================================================================== --- branches/cparm/i386/modules/GraphicsEnabler/Makefile (revision 2117) +++ branches/cparm/i386/modules/GraphicsEnabler/Makefile (revision 2118) @@ -58,7 +58,7 @@ VPATH = $(OBJROOT):$(SYMROOT) -GRAPHICS_ENABLER_OBJS = nvidia.o ati.o gma.o GraphicsEnabler.o stack_protector.o +GRAPHICS_ENABLER_OBJS = nvidia.o ati.o gma.o GraphicsEnabler.o device_inject.o stack_protector.o SFILES = @@ -84,6 +84,7 @@ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ $(OBJROOT)/stack_protector.o \ + $(OBJROOT)/device_inject.o \ $(OBJROOT)/nvidia.o \ $(OBJROOT)/ati.o \ $(OBJROOT)/gma.o \ @@ -130,6 +131,10 @@ gma.o: $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "gma.c" $(INC) -o "$(OBJROOT)/gma.o" +device_inject.o: + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c "$(LIBSAIODIR)/device_inject.c" $(INC) -o "$(OBJROOT)/device_inject.o" + + include ../../MakeInc.dir # dependencies Index: branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c =================================================================== --- branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c (revision 2117) +++ branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c (revision 2118) @@ -180,12 +180,10 @@ // Clear output mode info. - //bzero( outModeInfo, sizeof(*outModeInfo) ); bzero( outModeInfo, sizeof(VBEModeInfoBlock) ); // Get VBE controller info containing the list of supported modes. - //bzero( &vbeInfo, sizeof(vbeInfo) ); bzero( &vbeInfo, sizeof(VBEInfoBlock) ); strlcpy( (char*)&vbeInfo, "VBE2", sizeof(VBEInfoBlock) ); Index: branches/cparm/i386/modules/Keymapper/Keylayout.c =================================================================== --- branches/cparm/i386/modules/Keymapper/Keylayout.c (revision 2117) +++ branches/cparm/i386/modules/Keymapper/Keylayout.c (revision 2118) @@ -111,13 +111,13 @@ if (current_layout) free(current_layout); - current_layout = malloc(sizeof(*current_layout)); + current_layout = malloc(sizeof(struct keyboard_layout)); if (!current_layout) goto fail; key_b_lseek(fd, KEYBOARD_LAYOUTS_MAP_OFFSET, 0); - if (read(fd, (char*) current_layout, sizeof(*current_layout)) != sizeof(*current_layout)) { + if (read(fd, (char*) current_layout, sizeof(struct keyboard_layout)) != sizeof(struct keyboard_layout)) { printf("Wrong keyboard layout file %s size\n", filename); goto fail; } Index: branches/cparm/i386/modules/SMBiosPatcher/smbios_patcher.c =================================================================== --- branches/cparm/i386/modules/SMBiosPatcher/smbios_patcher.c (revision 2117) +++ branches/cparm/i386/modules/SMBiosPatcher/smbios_patcher.c (revision 2118) @@ -923,7 +923,7 @@ ret->anchor[1] = 0x53; ret->anchor[2] = 0x4d; ret->anchor[3] = 0x5f; - ret->entryPointLength = sizeof(*ret); + ret->entryPointLength = sizeof(struct SMBEntryPoint); ret->majorVersion = 2; ret->minorVersion = 1; ret->maxStructureSize = 0; // will be calculated later in this function @@ -1361,7 +1361,7 @@ newsmbios->dmi.checksum = 0; newsmbios->dmi.checksum = 256 - checksum8(&newsmbios->dmi, sizeof(newsmbios->dmi)); newsmbios->checksum = 0; - newsmbios->checksum = 256 - checksum8(newsmbios, sizeof(*newsmbios)); + newsmbios->checksum = 256 - checksum8(newsmbios, sizeof(struct SMBEntryPoint)); if (!done) { verbose("Patched DMI Table\n"); Index: branches/cparm/i386/modules/ACPICodec/acpi_codec.c =================================================================== --- branches/cparm/i386/modules/ACPICodec/acpi_codec.c (revision 2117) +++ branches/cparm/i386/modules/ACPICodec/acpi_codec.c (revision 2118) @@ -379,6 +379,9 @@ { U64 ptr = xsdt->TableOffsetEntry[index]; + if (!ptr) continue; + + { if (ptr > ULONG_MAX) { @@ -493,6 +496,8 @@ for (index=0;indexSignature) == NAMESEG(ACPI_SIG_FADT)) { ACPI_TABLE_FADT *FacpPointer = ((ACPI_TABLE_FADT*)table_array[index]); @@ -703,7 +708,7 @@ current = (U8 *) DsdtPointer; current = decodeTableHeader(current, &header); - end = current - sizeof(*header) + header->Length; + end = current - sizeof(ACPI_TABLE_HEADER) + header->Length; ns.depth = 0; acpi_processor_count = 0; //DBG("* DSDT debug start\n"); @@ -3716,6 +3721,8 @@ return(0); } + bzero(&cpu, sizeof(CPU_DETAILS)); + collect_cpu_info(&cpu); if (enable_cstates && pmbase) @@ -4554,7 +4561,8 @@ for (index = 0; index < num_tables; index++) { - + if (!table_array[index]) continue; + { int method = 0; Index: branches/cparm/i386/util/fdisk/cmd.c =================================================================== --- branches/cparm/i386/util/fdisk/cmd.c (revision 2117) +++ branches/cparm/i386/util/fdisk/cmd.c (revision 2118) @@ -202,7 +202,7 @@ /* Unused, so just zero out */ if (pp->id == DOSPTYP_UNUSED) { - memset(pp, 0, sizeof(*pp)); + memset(pp, 0, sizeof(prt_t)); printf("Partition %d is disabled.\n", pn + 1); return (ret); } Index: branches/cparm/i386/util/fdisk/part.c =================================================================== --- branches/cparm/i386/util/fdisk/part.c (revision 2117) +++ branches/cparm/i386/util/fdisk/part.c (revision 2118) @@ -241,7 +241,7 @@ /* Zero out entry if not used */ if (partn->id == DOSPTYP_UNUSED ) { - memset(partn, 0, sizeof(*partn)); + memset(partn, 0, sizeof(prt_t)); } } @@ -353,7 +353,7 @@ /* Zero out entry if not used */ if (part->id == DOSPTYP_UNUSED ) { - memset(part, 0, sizeof(*part)); + memset(part, 0, sizeof(prt_t)); return; } @@ -390,7 +390,7 @@ /* Zero out entry if not used */ if (part->id == DOSPTYP_UNUSED ) { - memset(part, 0, sizeof(*part)); + memset(part, 0, sizeof(prt_t)); return; } Index: branches/cparm/i386/util/fdisk/auto.c =================================================================== --- branches/cparm/i386/util/fdisk/auto.c (revision 2117) +++ branches/cparm/i386/util/fdisk/auto.c (revision 2118) @@ -44,154 +44,154 @@ /* The default style is the first one in the list */ struct _auto_style { - char *style_name; - int (*style_fn)(disk_t *, mbr_t *); - char *description; + char *style_name; + int (*style_fn)(disk_t *, mbr_t *); + char *description; } style_fns[] = { - {"boothfs", AUTO_boothfs, "8Mb boot plus HFS+ root partition"}, - {"bootufs", AUTO_bootufs, "8Mb boot plus UFS root partition"}, - {"hfs", AUTO_hfs, "Entire disk as one HFS+ partition"}, - {"ufs", AUTO_ufs, "Entire disk as one UFS partition"}, - {"dos", AUTO_dos, "Entire disk as one DOS partition"}, - {"raid", AUTO_raid, "Entire disk as one 0xAC partition"}, - {0,0} + {"boothfs", AUTO_boothfs, "8Mb boot plus HFS+ root partition"}, + {"bootufs", AUTO_bootufs, "8Mb boot plus UFS root partition"}, + {"hfs", AUTO_hfs, "Entire disk as one HFS+ partition"}, + {"ufs", AUTO_ufs, "Entire disk as one UFS partition"}, + {"dos", AUTO_dos, "Entire disk as one DOS partition"}, + {"raid", AUTO_raid, "Entire disk as one 0xAC partition"}, + {0,0} }; void AUTO_print_styles(FILE *f) { - struct _auto_style *fp; - int i; - - for (i=0, fp = &style_fns[0]; fp->style_name != NULL; i++, fp++) { - fprintf(f, " %-10s %s%s\n", fp->style_name, fp->description, (i==0) ? " (default)" : ""); - } + struct _auto_style *fp; + int i; + + for (i=0, fp = &style_fns[0]; fp->style_name != NULL; i++, fp++) { + fprintf(f, " %-10s %s%s\n", fp->style_name, fp->description, (i==0) ? " (default)" : ""); + } } int AUTO_init(disk_t *disk, char *style, mbr_t *mbr) { - struct _auto_style *fp; - - for (fp = &style_fns[0]; fp->style_name != NULL; fp++) { - /* If style is NULL, use the first (default) style */ - if (style == NULL || strcasecmp(style, fp->style_name) == 0) { - return (*fp->style_fn)(disk, mbr); - } - } - warnx("No such auto-partition style %s", style); - return AUTO_ERR; + struct _auto_style *fp; + + for (fp = &style_fns[0]; fp->style_name != NULL; fp++) { + /* If style is NULL, use the first (default) style */ + if (style == NULL || strcasecmp(style, fp->style_name) == 0) { + return (*fp->style_fn)(disk, mbr); + } + } + warnx("No such auto-partition style %s", style); + return AUTO_ERR; } static int use_whole_disk(disk_t *disk, unsigned char id, mbr_t *mbr) { - MBR_clear(mbr); - mbr->part[0].id = id; - mbr->part[0].bs = 63; - mbr->part[0].ns = disk->real->size - 63; - PRT_fix_CHS(disk, &mbr->part[0], 0); - return AUTO_OK; + MBR_clear(mbr); + mbr->part[0].id = id; + mbr->part[0].bs = 63; + mbr->part[0].ns = disk->real->size - 63; + PRT_fix_CHS(disk, &mbr->part[0], 0); + return AUTO_OK; } /* DOS style: one partition for the whole disk */ int AUTO_dos(disk_t *disk, mbr_t *mbr) { - int cc; - cc = use_whole_disk(disk, 0x0C, mbr); - if (cc == AUTO_OK) { - mbr->part[0].flag = DOSACTIVE; - } - return cc; + int cc; + cc = use_whole_disk(disk, 0x0C, mbr); + if (cc == AUTO_OK) { + mbr->part[0].flag = DOSACTIVE; + } + return cc; } /* HFS style: one partition for the whole disk */ int AUTO_hfs(disk_t *disk, mbr_t *mbr) { - int cc; - cc = use_whole_disk(disk, 0xAF, mbr); - if (cc == AUTO_OK) { - mbr->part[0].flag = DOSACTIVE; - } - return cc; + int cc; + cc = use_whole_disk(disk, 0xAF, mbr); + if (cc == AUTO_OK) { + mbr->part[0].flag = DOSACTIVE; + } + return cc; } /* UFS style: one partition for the whole disk */ int AUTO_ufs(disk_t *disk, mbr_t *mbr) { - int cc; - cc = use_whole_disk(disk, 0xA8, mbr); - if (cc == AUTO_OK) { - mbr->part[0].flag = DOSACTIVE; - } - return cc; + int cc; + cc = use_whole_disk(disk, 0xA8, mbr); + if (cc == AUTO_OK) { + mbr->part[0].flag = DOSACTIVE; + } + return cc; } /* One boot partition, one HFS+ root partition */ int AUTO_boothfs (disk_t *disk, mbr_t *mbr) { - /* Check disk size. */ - if (disk->real->size < 16 * 2048) { - errx(1, "Disk size must be greater than 16Mb"); - return AUTO_ERR; - } - - MBR_clear(mbr); - - /* 8MB boot partition */ - mbr->part[0].id = 0xAB; - mbr->part[0].bs = 63; - mbr->part[0].ns = 8 * 1024 * 2; - mbr->part[0].flag = DOSACTIVE; - PRT_fix_CHS(disk, &mbr->part[0], 0); - - /* Rest of the disk for rooting */ - mbr->part[1].id = 0xAF; - mbr->part[1].bs = (mbr->part[0].bs + mbr->part[0].ns); - mbr->part[1].ns = disk->real->size - mbr->part[0].ns - 63; - PRT_fix_CHS(disk, &mbr->part[1], 1); - - return AUTO_OK; + /* Check disk size. */ + if (disk->real->size < 16 * 2048) { + errx(1, "Disk size must be greater than 16Mb"); + return AUTO_ERR; + } + + MBR_clear(mbr); + + /* 8MB boot partition */ + mbr->part[0].id = 0xAB; + mbr->part[0].bs = 63; + mbr->part[0].ns = 8 * 1024 * 2; + mbr->part[0].flag = DOSACTIVE; + PRT_fix_CHS(disk, &mbr->part[0], 0); + + /* Rest of the disk for rooting */ + mbr->part[1].id = 0xAF; + mbr->part[1].bs = (mbr->part[0].bs + mbr->part[0].ns); + mbr->part[1].ns = disk->real->size - mbr->part[0].ns - 63; + PRT_fix_CHS(disk, &mbr->part[1], 1); + + return AUTO_OK; } /* One boot partition, one UFS root partition */ int AUTO_bootufs(disk_t *disk, mbr_t *mbr) { - /* Check disk size. */ - if (disk->real->size < 16 * 2048) { - errx(1, "Disk size must be greater than 16Mb"); - return AUTO_ERR; - } - - MBR_clear(mbr); - - /* 8MB boot partition */ - mbr->part[0].id = 0xAB; - mbr->part[0].bs = 63; - mbr->part[0].ns = 8 * 1024 * 2; - mbr->part[0].flag = DOSACTIVE; - PRT_fix_CHS(disk, &mbr->part[0], 0); - - /* Rest of the disk for rooting */ - mbr->part[1].id = 0xA8; - mbr->part[1].bs = (mbr->part[0].bs + mbr->part[0].ns); - mbr->part[1].ns = disk->real->size - mbr->part[0].ns - 63; - PRT_fix_CHS(disk, &mbr->part[1], 1); - - return AUTO_OK; + /* Check disk size. */ + if (disk->real->size < 16 * 2048) { + errx(1, "Disk size must be greater than 16Mb"); + return AUTO_ERR; + } + + MBR_clear(mbr); + + /* 8MB boot partition */ + mbr->part[0].id = 0xAB; + mbr->part[0].bs = 63; + mbr->part[0].ns = 8 * 1024 * 2; + mbr->part[0].flag = DOSACTIVE; + PRT_fix_CHS(disk, &mbr->part[0], 0); + + /* Rest of the disk for rooting */ + mbr->part[1].id = 0xA8; + mbr->part[1].bs = (mbr->part[0].bs + mbr->part[0].ns); + mbr->part[1].ns = disk->real->size - mbr->part[0].ns - 63; + PRT_fix_CHS(disk, &mbr->part[1], 1); + + return AUTO_OK; } /* RAID style: one 0xAC partition for the whole disk */ int AUTO_raid(disk_t *disk, mbr_t *mbr) { - return use_whole_disk(disk, 0xAC, mbr); + return use_whole_disk(disk, 0xAC, mbr); } Index: branches/cparm/i386/util/fdisk/user.c =================================================================== --- branches/cparm/i386/util/fdisk/user.c (revision 2117) +++ branches/cparm/i386/util/fdisk/user.c (revision 2118) @@ -168,7 +168,7 @@ if (yn) { strlcpy(cmd.cmd, "erase", sizeof(cmd.cmd)); cmd.args[0] = '\0'; - st /* false positive ?? */ = Xerase(&cmd, disk, mbr, tt, offset); + Xerase(&cmd, disk, mbr, tt, offset); modified = 1; } } @@ -215,7 +215,7 @@ /* Write out MBR */ if (modified) { - if (st /*??*/ == CMD_SAVE) { + if (st == CMD_SAVE) { int shared = 0; printf("Writing current MBR to disk.\n"); fd = DISK_openshared(disk->name, O_RDWR, &shared); Index: branches/cparm/i386/util/md.c =================================================================== --- branches/cparm/i386/util/md.c (revision 2117) +++ branches/cparm/i386/util/md.c (revision 2118) @@ -566,6 +566,7 @@ fprintf(stderr, "%s: file = \"%s\" ", name, real_mak_name); perror("stat"); fflush(stdout), fflush(stderr); + fclose(mak); return NULL; } if (D_open) Index: branches/cparm/i386/util/amlsgn.m =================================================================== --- branches/cparm/i386/util/amlsgn.m (revision 2117) +++ branches/cparm/i386/util/amlsgn.m (revision 2118) @@ -53,12 +53,14 @@ #import #import +#include + #include "Intel_Acpi/acpidecode.h" #include "Intel_Acpi/ppmsetup.h" unsigned long uuid32; -#define UUID_LEN 16 -#define UUID_STR_LEN UUID_LEN*2 + 8 +#define UUID_LEN sizeof(uuid_t) +#define UUID_STR_LEN sizeof(uuid_string_t) typedef int8_t EFI_CHAR8; unsigned long Index: branches/cparm/xcode3_sym.zip =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream