Index: branches/cparm/CHANGES =================================================================== --- branches/cparm/CHANGES (revision 2005) +++ branches/cparm/CHANGES (revision 2006) @@ -1,3 +1,6 @@ +- security fixes in printf.c +- Fixed a weird bug in boot arguments that could prevent 10.8 to boot + - security, stability, bugs fixes - moved __doprnt to the xnu version Index: branches/cparm/i386/libsaio/bootstruct.c =================================================================== --- branches/cparm/i386/libsaio/bootstruct.c (revision 2005) +++ branches/cparm/i386/libsaio/bootstruct.c (revision 2006) @@ -30,17 +30,13 @@ #include "bootstruct.h" #include "platform.h" -boot_args_common *bootArgs = NULL; - /*========================================================================== * structure of parameters passed to * the kernel by the booter. */ -boot_args_Legacy *bootArgsLegacy = NULL; -boot_args_107 *bootArgs107 = NULL; -boot_args_108 *bootArgs108 = NULL; -/* ... */ +boot_args_legacy *bootArgsLegacy= NULL; +boot_args *bootArgs= NULL; PrivateBootInfo_t *bootInfo = NULL; @@ -58,13 +54,13 @@ unsigned long memoryMapCount = 0; - bootArgs = (boot_args_common *)malloc(sizeof(boot_args_common)); + 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"); else { - bzero(bootArgs, sizeof(boot_args_common)); + bzero(bootArgs, sizeof(boot_args)); bzero(bootInfo, sizeof(PrivateBootInfo_t)); // Get system memory map. Also update the size of the @@ -147,89 +143,49 @@ bootArgs->Video.v_baseAddr = Video->v_baseAddr; return; } -boot_args_common * getBootArgs(void) +boot_args * getBootArgs(void) { return bootArgs; } -#define AllocateKernelMemoryForBootArgs(Ver) \ -{ \ -bootArgs##Ver = (boot_args_##Ver *)AllocateKernelMemory(sizeof(boot_args_##Ver));\ -} - -#define CopyCommonBootArgsHeader(Ver) \ -{ \ -bootArgs##Ver->Revision = bootArgs->Header.Revision ;\ -bootArgs##Ver->Version = bootArgs->Header.Version ;\ -} - -// For 10.6, 10.5 and 10.4 please use :Legacy:, for 10.7 use :107:, for 10.8 use :108: -#define CopyCommonBootArgs(Ver) \ -{ \ -bcopy(bootArgs->CommandLine, bootArgs##Ver->CommandLine, BOOT_LINE_LENGTH);\ -bootArgs##Ver->MemoryMap = bootArgs->MemoryMap ;\ -bootArgs##Ver->MemoryMapSize = bootArgs->MemoryMapSize ;\ -bootArgs##Ver->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize ;\ -bootArgs##Ver->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion ;\ -bootArgs##Ver->Video = bootArgs->Video ;\ -bootArgs##Ver->deviceTreeP = bootArgs->deviceTreeP ;\ -bootArgs##Ver->deviceTreeLength = bootArgs->deviceTreeLength ;\ -bootArgs##Ver->kaddr = bootArgs->kaddr ;\ -bootArgs##Ver->ksize = bootArgs->ksize ;\ -bootArgs##Ver->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart ;\ -bootArgs##Ver->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount ;\ -bootArgs##Ver->efiSystemTable = bootArgs->efiSystemTable ;\ -bootArgs##Ver->efiMode = bootArgs->efiMode ;\ -bootArgs##Ver->performanceDataStart = bootArgs->performanceDataStart ;\ -bootArgs##Ver->performanceDataSize = bootArgs->performanceDataSize ;\ -bootArgs##Ver->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart ;\ -} - -/* - * Darwin 10.7+ specific boot arguments - * - * for 10.7 use :107:, for 10.8 use :108: - */ -#define Copy107plusBootArgs(Ver) \ -{ \ -bootArgs##Ver->keyStoreDataStart = bootArgs->keyStoreDataStart ;\ -bootArgs##Ver->keyStoreDataSize = bootArgs->keyStoreDataSize ;\ -bootArgs##Ver->bootMemStart = bootArgs->bootMemStart ;\ -bootArgs##Ver->bootMemSize = bootArgs->bootMemSize ;\ -bootArgs##Ver->PhysicalMemorySize = bootArgs->PhysicalMemorySize ;\ -bootArgs##Ver->FSBFrequency = bootArgs->FSBFrequency ;\ -bootArgs##Ver->debugMode = bootArgs->debugMode ;\ -} - -#define init_boot_args(Ver) \ -{ \ -AllocateKernelMemoryForBootArgs(Ver);\ -CopyCommonBootArgsHeader(Ver);\ -CopyCommonBootArgs(Ver);\ -} - /* Copy boot args after kernel and record address. */ void -reserveKern107BootStruct(void) -{ - init_boot_args(107); - Copy107plusBootArgs(107); -} - -void -reserveKern108BootStruct(void) -{ - init_boot_args(108); - Copy107plusBootArgs(108); +reserveKernBootStruct(void) +{ + void *oldAddr = bootArgs; - /* Darwin 10.8 specific boot arguments */ + bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args)); + bcopy(oldAddr, bootArgs, sizeof(boot_args)); + } void reserveKernLegacyBootStruct(void) -{ - init_boot_args(Legacy); +{ + bootArgsLegacy = (boot_args_legacy *)AllocateKernelMemory(sizeof(boot_args_legacy)); + + bootArgsLegacy->Revision = bootArgs->Revision ; + bootArgsLegacy->Version = bootArgs->Version ; + bcopy(bootArgs->CommandLine, bootArgsLegacy->CommandLine, BOOT_LINE_LENGTH); + bootArgsLegacy->MemoryMap = bootArgs->MemoryMap ; + bootArgsLegacy->MemoryMapSize = bootArgs->MemoryMapSize ; + bootArgsLegacy->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize ; + bootArgsLegacy->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion ; + bootArgsLegacy->Video = bootArgs->Video ; + bootArgsLegacy->deviceTreeP = bootArgs->deviceTreeP ; + bootArgsLegacy->deviceTreeLength = bootArgs->deviceTreeLength ; + bootArgsLegacy->kaddr = bootArgs->kaddr ; + bootArgsLegacy->ksize = bootArgs->ksize ; + bootArgsLegacy->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart ; + bootArgsLegacy->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount ; + bootArgsLegacy->efiSystemTable = bootArgs->efiSystemTable ; + bootArgsLegacy->efiMode = bootArgs->efiMode ; + bootArgsLegacy->performanceDataStart = bootArgs->performanceDataStart ; + bootArgsLegacy->performanceDataSize = bootArgs->performanceDataSize ; + bootArgsLegacy->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart ; + + } void Index: branches/cparm/i386/libsaio/bootstruct.h =================================================================== --- branches/cparm/i386/libsaio/bootstruct.h (revision 2005) +++ branches/cparm/i386/libsaio/bootstruct.h (revision 2006) @@ -32,15 +32,9 @@ /*! Kernel boot args global also used by booter for its own data. */ -extern boot_args_common *bootArgs; +extern boot_args_legacy *bootArgsLegacy; +extern boot_args *bootArgs; -/*! - Boot args passed to the kernel. - */ -extern boot_args_Legacy *bootArgsLegacy; -extern boot_args_107 *bootArgs107; -extern boot_args_108 *bootArgs108; - #define VGA_TEXT_MODE 0 #if 0 Index: branches/cparm/i386/libsaio/bootXnu.h =================================================================== --- branches/cparm/i386/libsaio/bootXnu.h (revision 2005) +++ branches/cparm/i386/libsaio/bootXnu.h (revision 2006) @@ -91,17 +91,6 @@ typedef struct Boot_Video Boot_Video; -/* Struct describing an image passed in by the booter */ -struct boot_icon_element { - unsigned int width; - unsigned int height; - int y_offset_from_center; - unsigned int data_size; - unsigned int __reserved1[4]; - unsigned char data[0]; -}; -typedef struct boot_icon_element boot_icon_element; - /* Values for v_display */ #define GRAPHICS_MODE 1 @@ -121,7 +110,7 @@ #define kBootArgsEfiMode32 32 #define kBootArgsEfiMode64 64 -typedef struct boot_args_Legacy { +typedef struct boot_args_legacy { uint16_t Revision; /* Revision of boot_args structure */ uint16_t Version; /* Version of boot_args structure */ @@ -152,152 +141,59 @@ uint64_t efiRuntimeServicesVirtualPageStart; /* virtual address of defragmented runtime pages */ uint32_t __reserved3[2]; -} boot_args_Legacy; +} boot_args_legacy; -typedef struct boot_args_107 { - uint16_t Revision; /* Revision of boot_args structure */ - uint16_t Version; /* Version of boot_args structure */ - +/* Bitfields for boot_args->flags */ +#define kBootArgsFlagRebootOnPanic (1 << 0) +#define kBootArgsFlagHiDPI (1 << 1) + +typedef struct boot_args { + uint16_t Revision; /* Revision of boot_args structure */ + uint16_t Version; /* Version of boot_args structure */ + uint8_t efiMode; /* 32 = 32-bit, 64 = 64-bit */ uint8_t debugMode; /* Bit field with behavior changes */ - uint8_t __reserved1[2]; - - char CommandLine[BOOT_LINE_LENGTH]; /* Passed in command line */ - + uint16_t flags; + + char CommandLine[BOOT_LINE_LENGTH]; /* Passed in command line */ + uint32_t MemoryMap; /* Physical address of memory map */ uint32_t MemoryMapSize; uint32_t MemoryMapDescriptorSize; uint32_t MemoryMapDescriptorVersion; - - Boot_Video Video; /* Video Information */ - - uint32_t deviceTreeP; /* Physical address of flattened device tree */ + + Boot_Video Video; /* Video Information */ + + uint32_t deviceTreeP; /* Physical address of flattened device tree */ uint32_t deviceTreeLength; /* Length of flattened tree */ - + uint32_t kaddr; /* Physical address of beginning of kernel text */ uint32_t ksize; /* Size of combined kernel text+data+efi */ - + uint32_t efiRuntimeServicesPageStart; /* physical address of defragmented runtime pages */ uint32_t efiRuntimeServicesPageCount; uint64_t efiRuntimeServicesVirtualPageStart; /* virtual address of defragmented runtime pages */ - + uint32_t efiSystemTable; /* physical address of system table in runtime area */ - uint32_t __reserved2; - + uint32_t kslide; + uint32_t performanceDataStart; /* physical address of log */ uint32_t performanceDataSize; - + uint32_t keyStoreDataStart; /* physical address of key store data */ uint32_t keyStoreDataSize; - uint64_t bootMemStart; - uint64_t bootMemSize; + uint64_t bootMemStart; + uint64_t bootMemSize; uint64_t PhysicalMemorySize; uint64_t FSBFrequency; uint64_t pciConfigSpaceBaseAddress; uint32_t pciConfigSpaceStartBusNumber; uint32_t pciConfigSpaceEndBusNumber; uint32_t __reserved4[730]; - -} boot_args_107; - -typedef struct boot_args_108 { - uint16_t Revision; /* Revision of boot_args structure */ - uint16_t Version; /* Version of boot_args structure */ - - uint8_t efiMode; /* 32 = 32-bit, 64 = 64-bit */ - uint8_t debugMode; /* Bit field with behavior changes */ - uint8_t __reserved1[2]; - - char CommandLine[BOOT_LINE_LENGTH]; /* Passed in command line */ - - uint32_t MemoryMap; /* Physical address of memory map */ - uint32_t MemoryMapSize; - uint32_t MemoryMapDescriptorSize; - uint32_t MemoryMapDescriptorVersion; - - Boot_Video Video; /* Video Information */ - - uint32_t deviceTreeP; /* Physical address of flattened device tree */ - uint32_t deviceTreeLength; /* Length of flattened tree */ - - uint32_t kaddr; /* Physical address of beginning of kernel text */ - uint32_t ksize; /* Size of combined kernel text+data+efi */ - - uint32_t efiRuntimeServicesPageStart; /* physical address of defragmented runtime pages */ - uint32_t efiRuntimeServicesPageCount; - uint64_t efiRuntimeServicesVirtualPageStart; /* virtual address of defragmented runtime pages */ - - uint32_t efiSystemTable; /* physical address of system table in runtime area */ - uint32_t __reserved2; - - uint32_t performanceDataStart; /* physical address of log */ - uint32_t performanceDataSize; - - uint32_t keyStoreDataStart; /* physical address of key store data */ - uint32_t keyStoreDataSize; - uint64_t bootMemStart; - uint64_t bootMemSize; - uint64_t PhysicalMemorySize; - uint64_t FSBFrequency; - uint64_t pciConfigSpaceBaseAddress; - uint32_t pciConfigSpaceStartBusNumber; - uint32_t pciConfigSpaceEndBusNumber; - uint32_t __reserved4[730]; - -} boot_args_108; // for now apparently the same package for 10.8 and 10.7 - -typedef struct boot_args_header { - uint16_t Revision; /* Revision of boot_args structure */ - uint16_t Version; /* Version of boot_args structure */ -} boot_args_header; - -typedef struct boot_args_10x { - boot_args_header Header; - Boot_Video Video; /* Video Information */ - - uint32_t MemoryMap; /* Physical address of memory map */ - uint32_t MemoryMapSize; - uint32_t MemoryMapDescriptorSize; - uint32_t MemoryMapDescriptorVersion; - - uint8_t debugMode; /* Bit field with behavior changes */ - uint8_t efiMode; /* 32 = 32-bit, 64 = 64-bit */ - - - uint32_t deviceTreeP; /* Physical address of flattened device tree */ - uint32_t deviceTreeLength; /* Length of flattened tree */ - - char CommandLine[BOOT_LINE_LENGTH]; /* Passed in command line */ - - - uint32_t keyStoreDataStart; /* physical address of key store data */ - uint32_t keyStoreDataSize; - uint32_t efiRuntimeServicesPageStart; /* physical address of defragmented runtime pages */ - uint32_t efiRuntimeServicesPageCount; - uint64_t efiRuntimeServicesVirtualPageStart; /* virtual address of defragmented runtime pages */ - - uint32_t efiSystemTable; /* physical address of system table in runtime area */ - uint64_t FSBFrequency; - - uint32_t performanceDataSize; - uint32_t performanceDataStart; /* physical address of log */ - - uint32_t kaddr; /* Physical address of beginning of kernel text */ - uint32_t ksize; /* Size of combined kernel text+data+efi */ - - uint64_t bootMemStart; - uint64_t bootMemSize; - uint64_t PhysicalMemorySize; - - uint64_t pciConfigSpaceBaseAddress; - uint32_t pciConfigSpaceStartBusNumber; - uint32_t pciConfigSpaceEndBusNumber; -} boot_args_10x; +} boot_args; -typedef struct boot_args_10x boot_args_common; +extern char assert_boot_args_size_is_4096[sizeof(boot_args) == 4096 ? 1 : -1]; -extern char assert_boot_args_107_size_is_4096[sizeof(boot_args_107) == 4096 ? 1 : -1]; -extern char assert_boot_args_108_size_is_4096[sizeof(boot_args_108) == 4096 ? 1 : -1]; - #endif /* _PEXPERT_I386_BOOT_H */ + Index: branches/cparm/i386/libsaio/saio_internal.h =================================================================== --- branches/cparm/i386/libsaio/saio_internal.h (revision 2005) +++ branches/cparm/i386/libsaio/saio_internal.h (revision 2006) @@ -92,12 +92,11 @@ extern void copyKernBootStruct(void); extern void finalizeBootStruct(void); extern void reserveKernLegacyBootStruct(void); -extern void reserveKern107BootStruct(void); -extern void reserveKern108BootStruct(void); +extern void reserveKernBootStruct(void); extern void setBootArgsVideoMode(int mode); extern void setBootArgsVideoStruct(Boot_Video *Video); extern uint32_t getVideoMode(void); -extern boot_args_common * getBootArgs(void); +extern boot_args * getBootArgs(void); /* cache.c */ Index: branches/cparm/i386/boot2/boot.c =================================================================== --- branches/cparm/i386/boot2/boot.c (revision 2005) +++ branches/cparm/i386/boot2/boot.c (revision 2006) @@ -90,7 +90,6 @@ static bool find_file_with_ext(const char* dir, const char *ext, const char * name_compare, size_t ext_size); static bool found_extra_kext(void); static void determineCpuArch(void); -static void init_pic(void); void getKernelCachePath(void); #ifdef NBP_SUPPORT static bool gUnloadPXEOnExit = false; @@ -151,25 +150,6 @@ malloc_init(0, 0, 0, malloc_error); } -static void init_pic(void) -{ - /* Remap IRQ's */ - /* - outb(0x20, 0x11); - outb(0xA0, 0x11); - outb(0x21, 0x20); - outb(0xA1, 0x28); - outb(0x21, 0x04); - outb(0xA1, 0x02); - outb(0x21, 0x01); - outb(0xA1, 0x01); - */ - //outb(0x70, inb(0x70)|0x80); /* Disable NMI */ - - outb(0x21, 0xff); /* Maskout all interrupts Pic1 */ - outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */ -} - //========================================================================== // execKernel - Load the kernel image (mach-o) and jump to its entry point. @@ -182,20 +162,20 @@ if(((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] <= '6') { - bootArgs->Header.Version = kBootArgsVersion1; - bootArgs->Header.Revision = ((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3]; + bootArgs->Version = kBootArgsVersion1; + bootArgs->Revision = ((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3]; } else { #if kBootArgsVersion > 1 - bootArgs->Header.Version = kBootArgsVersion; - bootArgs->Header.Revision = kBootArgsRevision; + bootArgs->Version = kBootArgsVersion; + bootArgs->Revision = kBootArgsRevision; #else if(((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] >= '7') { - bootArgs->Header.Version = 2; - bootArgs->Header.Revision = 0; + bootArgs->Version = 2; + bootArgs->Revision = 0; } #endif } @@ -208,7 +188,11 @@ (int *)&bootArgs->ksize ); if ( ret != 0 ) - return ret; + return ret; + + // Reserve space for boot args for 10.7 only (for 10.6 and earlier, we will convert (to legacy) the structure and reserve kernel memory for it later.) + if(((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] >= '7') + reserveKernBootStruct(); // Load boot drivers from the specifed root path. @@ -306,21 +290,8 @@ execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL, NULL, NULL); // Notify modules that the kernel is about to be started - switch (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3]) { - case '4': - case '5': - case '6': - reserveKernLegacyBootStruct(); - break; - case '7': - reserveKern107BootStruct(); - break; - case '8': - reserveKern108BootStruct(); - break; - default: - break; - } + if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] <= '6') + reserveKernLegacyBootStruct(); #if UNUSED turnOffFloppy(); @@ -331,29 +302,18 @@ IMPS_LAPIC_WRITE(LAPIC_LVT1, LAPIC_ICR_DM_NMI); #endif - switch (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3]) { - case '4': - case '5': - case '6': - // Jump to kernel's entry point. There's no going back now. XXX LEGACY OS XXX - startprog( kernelEntry, bootArgsLegacy ); - break; - case '7': - init_pic(); - // Jump to kernel's entry point. There's no going back now. XXX LION XXX - startprog( kernelEntry, bootArgs107 ); - break; - case '8': - init_pic(); - // Jump to kernel's entry point. There's no going back now. XXX MOUNTAIN LION XXX - startprog( kernelEntry, bootArgs108 ); - break; - default: - printf("Error: Unsupported Darwin version\n"); - getc(); - break; + if (((BVRef)(uint32_t)get_env(envgBootVolume))->OSVersion[3] <= '6') { + + // Jump to kernel's entry point. There's no going back now. XXX LEGACY OS XXX + startprog( kernelEntry, bootArgsLegacy ); } + outb(0x21, 0xff); /* Maskout all interrupts Pic1 */ + outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */ + + // Jump to kernel's entry point. There's no going back now. XXX LION XXX + startprog( kernelEntry, bootArgs ); + // Should not be reached return 0; Index: branches/cparm/i386/boot2/mboot.c =================================================================== --- branches/cparm/i386/boot2/mboot.c (revision 2005) +++ branches/cparm/i386/boot2/mboot.c (revision 2006) @@ -340,8 +340,8 @@ This is the same assumption that initKernBootStruct makes. We could check the multiboot info I guess, but why bother? */ - boot_args_common temporaryBootArgsData; - bzero(&temporaryBootArgsData, sizeof(boot_args_common)); + boot_args temporaryBootArgsData; + bzero(&temporaryBootArgsData, sizeof(boot_args)); bootArgs = &temporaryBootArgsData; bootArgs->Video.v_display = VGA_TEXT_MODE; Index: branches/cparm/i386/modules/GUI/gui.c =================================================================== --- branches/cparm/i386/modules/GUI/gui.c (revision 2005) +++ branches/cparm/i386/modules/GUI/gui.c (revision 2006) @@ -122,7 +122,7 @@ #define MAX(x, y) ((x) > (y) ? (x) : (y)) #endif -#define VIDEO(x) (((boot_args_common*)getBootArgs())->Video.v_ ## x) +#define VIDEO(x) (((boot_args*)getBootArgs())->Video.v_ ## x) #define vram VIDEO(baseAddr) Index: branches/cparm/i386/modules/GUI/graphic_utils.c =================================================================== --- branches/cparm/i386/modules/GUI/graphic_utils.c (revision 2005) +++ branches/cparm/i386/modules/GUI/graphic_utils.c (revision 2006) @@ -11,7 +11,7 @@ #include "gui.h" #include "platform.h" -#define VIDEO(x) (((boot_args_common*)getBootArgs())->Video.v_ ## x) +#define VIDEO(x) (((boot_args*)getBootArgs())->Video.v_ ## x) #define MIN(x, y) ((x) < (y) ? (x) : (y)) static unsigned long lookUpCLUTIndex( unsigned char index, Index: branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c =================================================================== --- branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c (revision 2005) +++ branches/cparm/i386/modules/HibernateEnabler/graphic_utils.c (revision 2006) @@ -17,7 +17,7 @@ ((size_t) ( (char *)&((st *)(0))->m - (char *)0 )) #endif -#define VIDEO(x) (((boot_args_common*)getBootArgs())->Video.v_ ## x) +#define VIDEO(x) (((boot_args*)getBootArgs())->Video.v_ ## x) #define MIN(x, y) ((x) < (y) ? (x) : (y)) Index: branches/cparm/i386/libsa/printf.c =================================================================== --- branches/cparm/i386/libsa/printf.c (revision 2005) +++ branches/cparm/i386/libsa/printf.c (revision 2006) @@ -549,7 +549,7 @@ } } while (++p != &buf[MAXBUF]) { - (*putc)(*p, arg); + if (putc) (*putc)(*p, arg); nprinted++; }