Index: branches/rekursor/CHANGES =================================================================== --- branches/rekursor/CHANGES (revision 0) +++ branches/rekursor/CHANGES (revision 4) @@ -0,0 +1,5 @@ +- Added SystemID option permitting to change the System UUID to a fixed/reproduceable value. +- Added the PciRoot autodetection feature imported from pcefi10.5 + - Added automatic "system-id" injection from dmi bios, also compatible with SystemID boot option and former SMUUID from smbios,plist + - Added "system-type' automatic injection (1=Desktop) plus override possibility with the new system-type option in bootConfig +- Added SMserial and SMproductname new options for smbios.plist Index: branches/rekursor/i386/libsaio/xml.c =================================================================== --- branches/rekursor/i386/libsaio/xml.c (revision 3) +++ branches/rekursor/i386/libsaio/xml.c (revision 4) @@ -509,7 +509,7 @@ if (gTagsFree == 0) { #if USEMALLOC - tag = (TagPtr)malloc(kTagsPerBlock * sizeof(Tag)); + tag = (TagPtr)MALLOC(kTagsPerBlock * sizeof(Tag)); #else tag = (TagPtr)AllocateBootXMemory(kTagsPerBlock * sizeof(Tag)); #endif @@ -590,7 +590,7 @@ if (symbol == 0) { #if USEMALLOC - symbol = (SymbolPtr)malloc(sizeof(Symbol) + 1 + strlen(string)); + symbol = (SymbolPtr)MALLOC(sizeof(Symbol) + 1 + strlen(string)); #else symbol = (SymbolPtr)AllocateBootXMemory(sizeof(Symbol) + 1 + strlen(string)); #endif Index: branches/rekursor/i386/libsaio/bootstruct.c =================================================================== --- branches/rekursor/i386/libsaio/bootstruct.c (revision 3) +++ branches/rekursor/i386/libsaio/bootstruct.c (revision 4) @@ -48,8 +48,8 @@ if ( !init_done ) { - bootArgs = (boot_args *)malloc(sizeof(boot_args)); - bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t)); + bootArgs = (boot_args *)MALLOC(sizeof(boot_args)); + bootInfo = (PrivateBootInfo_t *)MALLOC(sizeof(PrivateBootInfo_t)); if (bootArgs == 0 || bootInfo == 0) stop("Couldn't allocate boot info\n"); Index: branches/rekursor/i386/libsaio/ext2fs.c =================================================================== --- branches/rekursor/i386/libsaio/ext2fs.c (revision 3) +++ branches/rekursor/i386/libsaio/ext2fs.c (revision 4) @@ -19,7 +19,7 @@ } void EX2GetDescription(CICell ih, char *str, long strMaxLen) { - char * buf=malloc (EX2ProbeSize); + char * buf=MALLOC (EX2ProbeSize); str[0]=0; if (!buf) return; @@ -38,4 +38,4 @@ str[strMaxLen]=0; strncpy (str, buf+0x478, min (strMaxLen, 16)); free (buf); -} \ No newline at end of file +} Index: branches/rekursor/i386/libsaio/device_tree.c =================================================================== --- branches/rekursor/i386/libsaio/device_tree.c (revision 3) +++ branches/rekursor/i386/libsaio/device_tree.c (revision 4) @@ -62,13 +62,13 @@ static Property *freeProperties, *allocedProperties; Property * -DT__AddProperty(Node *node, char *name, uint32_t length, void *value) +DT__AddProperty(Node *node, const char * name, uint32_t length, void *value) { Property *prop; DPRINTF("DT__AddProperty([Node '%s'], '%s', %d, 0x%x)\n", DT__GetName(node), name, length, value); if (freeProperties == NULL) { - void *buf = malloc(kAllocSize); + void *buf = MALLOC(kAllocSize); int i; DPRINTF("Allocating more free properties\n"); @@ -117,7 +117,7 @@ Node *node; if (freeNodes == NULL) { - void *buf = malloc(kAllocSize); + void *buf = MALLOC(kAllocSize); int i; DPRINTF("Allocating more free nodes\n"); @@ -276,7 +276,7 @@ buf = 0; } else { if (*buffer_p == 0) { - buf = malloc(totalSize); + buf = MALLOC(totalSize); } else { buf = *buffer_p; } @@ -342,7 +342,7 @@ } if (child == 0 && createIfMissing) { DPRINTF("Creating node\n"); - char *str = malloc(strlen(nameBuf) + 1); + char *str = MALLOC(strlen(nameBuf) + 1); // XXX this will leak strcpy(str, nameBuf); Index: branches/rekursor/i386/libsaio/hfs.c =================================================================== --- branches/rekursor/i386/libsaio/hfs.c (revision 3) +++ branches/rekursor/i386/libsaio/hfs.c (revision 4) @@ -154,15 +154,15 @@ } #ifdef __i386__ - if (!gTempStr) gTempStr = (char *)malloc(4096); - if (!gLinkTemp) gLinkTemp = (char *)malloc(64); - if (!gBTreeHeaderBuffer) gBTreeHeaderBuffer = (char *)malloc(512); + if (!gTempStr) gTempStr = (char *)MALLOC(4096); + if (!gLinkTemp) gLinkTemp = (char *)MALLOC(64); + if (!gBTreeHeaderBuffer) gBTreeHeaderBuffer = (char *)MALLOC(512); if (!gHFSMdbVib) { - gHFSMdbVib = (char *)malloc(kBlockSize); + gHFSMdbVib = (char *)MALLOC(kBlockSize); gHFSMDB = (HFSMasterDirectoryBlock *)gHFSMdbVib; } if (!gHFSPlusHeader) { - gHFSPlusHeader = (char *)malloc(kBlockSize); + gHFSPlusHeader = (char *)MALLOC(kBlockSize); gHFSPlus = (HFSPlusVolumeHeader *)gHFSPlusHeader; } if (!gTempStr || !gLinkTemp || !gBTreeHeaderBuffer || @@ -596,7 +596,7 @@ } nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize); - nodeBuf = (char *)malloc(nodeSize); + nodeBuf = (char *)MALLOC(nodeSize); node = (BTNodeDescriptor *)nodeBuf; index = *dirIndex % nodeSize; @@ -728,7 +728,7 @@ curNode = SWAP_BE32(gBTHeaders[btree]->rootNode); nodeSize = SWAP_BE16(gBTHeaders[btree]->nodeSize); - nodeBuf = (char *)malloc(nodeSize); + nodeBuf = (char *)MALLOC(nodeSize); node = (BTNodeDescriptor *)nodeBuf; while (1) { @@ -866,7 +866,7 @@ } if (extentBuffer == 0) { - extentBuffer = malloc(sizeofExtent * extentDensity); + extentBuffer = MALLOC(sizeofExtent * extentDensity); if (extentBuffer == 0) return -1; } Index: branches/rekursor/i386/libsaio/device_tree.h =================================================================== --- branches/rekursor/i386/libsaio/device_tree.h (revision 3) +++ branches/rekursor/i386/libsaio/device_tree.h (revision 4) @@ -27,7 +27,7 @@ extern Property * -DT__AddProperty(Node *node, char *name, uint32_t length, void *value); +DT__AddProperty(Node *node, const char * name, uint32_t length, void *value); extern Node * DT__AddChild(Node *parent, char *name); Index: branches/rekursor/i386/libsaio/spd.c =================================================================== --- branches/rekursor/i386/libsaio/spd.c (revision 3) +++ branches/rekursor/i386/libsaio/spd.c (revision 4) @@ -92,7 +92,7 @@ { slot->InUse = YES; - slot->spd = malloc(spd_size); + slot->spd = MALLOC(spd_size); if (slot->spd) { bzero(slot->spd, spd_size); Index: branches/rekursor/i386/libsaio/hfs_compare.c =================================================================== --- branches/rekursor/i386/libsaio/hfs_compare.c (revision 3) +++ branches/rekursor/i386/libsaio/hfs_compare.c (revision 4) @@ -35,7 +35,7 @@ static unsigned short * UncompressStructure(struct compressed_block *bp, int count, int size) { - unsigned short *out = malloc(size); + unsigned short *out = MALLOC(size); unsigned short *op = out; unsigned short data; int i, j; Index: branches/rekursor/i386/libsaio/Makefile =================================================================== --- branches/rekursor/i386/libsaio/Makefile (revision 3) +++ branches/rekursor/i386/libsaio/Makefile (revision 4) @@ -40,7 +40,7 @@ freq_detect.o platform.o dsdt_patcher.o \ smbios_patcher.o fake_efi.o ext2fs.o \ hpet.o spd.o usb.o pci_setup.o \ - device_inject.o nvidia.o ati.o + device_inject.o nvidia.o ati.o pci_root.o SAIO_EXTERN_OBJS = console.o Index: branches/rekursor/i386/libsaio/ufs.c =================================================================== --- branches/rekursor/i386/libsaio/ufs.c (revision 3) +++ branches/rekursor/i386/libsaio/ufs.c (revision 4) @@ -127,12 +127,12 @@ gCurrentIH = 0; #ifdef __i386__ - if (!gULBuf) gULBuf = (char *) malloc(UFS_LABEL_SIZE); - if (!gFSBuf) gFSBuf = (char *) malloc(SBSIZE); - if (!gTempName) gTempName = (char *) malloc(MAXNAMLEN + 1); - if (!gTempName2) gTempName2 = (char *) malloc(MAXNAMLEN + 1); - if (!gRootInodePtr) gRootInodePtr = (InodePtr) malloc(sizeof(Inode)); - if (!gFileInodePtr) gFileInodePtr = (InodePtr) malloc(sizeof(Inode)); + if (!gULBuf) gULBuf = (char *) MALLOC(UFS_LABEL_SIZE); + if (!gFSBuf) gFSBuf = (char *) MALLOC(SBSIZE); + if (!gTempName) gTempName = (char *) MALLOC(MAXNAMLEN + 1); + if (!gTempName2) gTempName2 = (char *) MALLOC(MAXNAMLEN + 1); + if (!gRootInodePtr) gRootInodePtr = (InodePtr) MALLOC(sizeof(Inode)); + if (!gFileInodePtr) gFileInodePtr = (InodePtr) MALLOC(sizeof(Inode)); if (!gULBuf || !gFSBuf || !gTempName || !gTempName2 || !gRootInodePtr || !gFileInodePtr) return -1; #endif @@ -168,7 +168,7 @@ gFragSize = gFS->fs_fsize; gFragsPerBlock = gBlockSize / gFragSize; if (gTempBlock != 0) free(gTempBlock); - gTempBlock = malloc(gBlockSize); + gTempBlock = MALLOC(gBlockSize); CacheInit(ih, gBlockSize); gCurrentIH = ih; Index: branches/rekursor/i386/libsaio/SMBIOS.h =================================================================== --- branches/rekursor/i386/libsaio/SMBIOS.h (revision 3) +++ branches/rekursor/i386/libsaio/SMBIOS.h (revision 4) @@ -39,6 +39,12 @@ typedef UInt32 SMBDWord; typedef UInt64 SMBQWord; +struct DMIHeader { + SMBByte type; + SMBByte length; + SMBWord handle; +} __attribute__((packed)); + struct DMIEntryPoint { SMBByte anchor[5]; SMBByte checksum; Index: branches/rekursor/i386/libsaio/smbios_patcher.c =================================================================== --- branches/rekursor/i386/libsaio/smbios_patcher.c (revision 3) +++ branches/rekursor/i386/libsaio/smbios_patcher.c (revision 4) @@ -227,7 +227,7 @@ {.type=132, .len=0x06, .numfunc=sm_one} }; -static inline struct SMBEntryPoint * getAddressOfSmbiosTable() +struct SMBEntryPoint * getAddressOfSmbiosTable() { /* First see if we can even find the damn SMBIOS table * The logic here is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking Index: branches/rekursor/i386/libsaio/smbios_patcher.h =================================================================== --- branches/rekursor/i386/libsaio/smbios_patcher.h (revision 3) +++ branches/rekursor/i386/libsaio/smbios_patcher.h (revision 4) @@ -53,5 +53,6 @@ int (*numfunc)(int tablen); }; +struct SMBEntryPoint * getAddressOfSmbiosTable(); #endif /* !__LIBSAIO_SMBIOS_PATCHER_H */ Index: branches/rekursor/i386/libsaio/memory.c =================================================================== --- branches/rekursor/i386/libsaio/memory.c (revision 3) +++ branches/rekursor/i386/libsaio/memory.c (revision 4) @@ -39,11 +39,11 @@ char *nameBuf; uint32_t *buffer; - nameBuf = malloc(strlen(rangeName) + 1); + nameBuf = MALLOC(strlen(rangeName) + 1); if (nameBuf == 0) return -1; strcpy(nameBuf, rangeName); - buffer = malloc(2 * sizeof(uint32_t)); + buffer = MALLOC(2 * sizeof(uint32_t)); if (buffer == 0) return -1; buffer[0] = start; Index: branches/rekursor/i386/libsaio/pci_root.c =================================================================== --- branches/rekursor/i386/libsaio/pci_root.c (revision 0) +++ branches/rekursor/i386/libsaio/pci_root.c (revision 4) @@ -0,0 +1,121 @@ +/* + * Copyright 2009 netkas + */ + +#include "libsaio.h" +#include "bootstruct.h" + +#ifndef DEBUG_PCIROOT +#define DEBUG_PCIROOT 0 +#endif + +#if DEBUG_PCIROOT==1 +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + +int rootuid = 10; //value means function wasnt ran yet + +unsigned int findrootuid(unsigned char * dsdt) +{ + int i; + for (i=0; i<64; i++) //not far than 64 symbols from pci root + { + if(dsdt[i] == '_' && dsdt[i+1] == 'U' && dsdt[i+2] == 'I' && dsdt[i+3] == 'D' && dsdt[i+5] == 0x08) + { + return dsdt[i+4]; + } + } + printf("pci root uid not found\n"); + return 11; +} + +unsigned int findpciroot(unsigned char * dsdt,int size) +{ + int i; + for (i=0; ibootConfig)) + dsdt_filename="DSDT.aml"; + + if (getValueForKey("-pci1", &val, &len, &bootInfo->bootConfig)) //fallback + { + user_uid_value = 1; + rootuid = user_uid_value; + return rootuid; + } + else user_uid_value = 0; + + + // Check booting partition + sprintf(dirspec,"%s",dsdt_filename); + fd=open (dirspec,0); + if (fd<0) + { // Check Extra on booting partition + sprintf(dirspec,"/Extra/%s",dsdt_filename); + fd=open (dirspec,0); + if (fd<0) + { // Fall back to booter partition + sprintf(dirspec,"bt(0,0)/Extra/%s",dsdt_filename); + fd=open (dirspec,0); + if (fd<0) + { + verbose("No DSDT found, using 0 as uid value.\n"); + rootuid = user_uid_value; + return rootuid; + } + } + } + + // Load replacement DSDT + new_dsdt=(void*)MALLOC(file_size (fd)); + if (!new_dsdt) + { + printf("Couldn't allocate memory for DSDT\n"); + rootuid = user_uid_value; + return rootuid; + } + fsize = file_size(fd); + if (read (fd, new_dsdt, file_size (fd))!=file_size (fd)) + { + printf("Couldn't read file\n"); + rootuid = user_uid_value; + return rootuid; + } + close (fd); + rootuid=findpciroot(new_dsdt, fsize); + if(rootuid == 11)rootuid=0; //usualy when _UID isnt present, it means uid is zero + if(rootuid == 10) //algo failed, PCI0 wasnt found; + { + printf("pci root uid value wasnt found, using zero, if you want it to be 1, use -pci1 flag"); + rootuid = user_uid_value; + } + free(new_dsdt); + return rootuid; +} + Index: branches/rekursor/i386/libsaio/pci_root.h =================================================================== --- branches/rekursor/i386/libsaio/pci_root.h (revision 0) +++ branches/rekursor/i386/libsaio/pci_root.h (revision 4) @@ -0,0 +1,13 @@ +/* + * Copyright 2008 mackerintel + */ + +#ifndef __LIBSAIO_PCI_ROOT_H +#define __LIBSAIO_PCI_ROOT_H + +#include "libsaio.h" + + +extern int getPciRootUID(); + +#endif /* !__LIBSAIO_DSDT_PATCHER_H */ Index: branches/rekursor/i386/libsaio/device_inject.c =================================================================== --- branches/rekursor/i386/libsaio/device_inject.c (revision 3) +++ branches/rekursor/i386/libsaio/device_inject.c (revision 4) @@ -70,7 +70,7 @@ if (len > 1) { // the resulting binary will be the half size of the input hex string - binStr = malloc(len / 2); + binStr = MALLOC(len / 2); binStrIdx = 0; hexNibbleIdx = 0; for (hexStrIdx = 0; hexStrIdx < len; hexStrIdx++) @@ -127,7 +127,7 @@ char *string = efi_inject_get_devprop_string(&strlength); /* Use the static "device-properties" boot config key contents if available, - * otheriwse use the generated one. + * otherwise use the generated one. */ if (!getValueForKey(DEVICE_PROPERTIES_PROP, &val, &cnt, &bootInfo->bootConfig) && string) { @@ -157,7 +157,7 @@ struct DevPropString *devprop_create_string(void) { - string = (struct DevPropString*)malloc(sizeof(struct DevPropString)); + string = (struct DevPropString*)MALLOC(sizeof(struct DevPropString)); if(string == NULL) return NULL; @@ -174,7 +174,7 @@ const char *val; int len; - struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice)); + struct DevPropDevice *device = (struct DevPropDevice*)MALLOC(sizeof(struct DevPropDevice)); if(!device || !string || !path) { if(device) free(device); @@ -186,6 +186,8 @@ if (getValueForKey("PciRoot", &val, &len, &bootInfo->bootConfig)) PciRootID = atoi(val); + else // rekursor: if no default pciroot is set in the boot.plist file then go and get this PciRootID: + PciRootID = (uint32_t) ascii_hex_to_int(&path[strlen(pciroot_string)]); if(strncmp(path, pciroot_string, strlen(pciroot_string))) { @@ -270,10 +272,10 @@ string->length += device->length; if(!string->entries) - if((string->entries = (struct DevPropDevice**)malloc(sizeof(device)))== NULL) + if((string->entries = (struct DevPropDevice**)MALLOC(sizeof(device)))== NULL) return 0; - string->entries[string->numentries++] = (struct DevPropDevice*)malloc(sizeof(device)); + string->entries[string->numentries++] = (struct DevPropDevice*)MALLOC(sizeof(device)); string->entries[string->numentries-1] = device; return device; @@ -286,7 +288,7 @@ return 0; uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2); - uint8_t *data = (uint8_t*)malloc(length); + uint8_t *data = (uint8_t*)MALLOC(length); { if(!data) return 0; @@ -316,7 +318,7 @@ uint32_t offset = device->length - (24 + (6 * device->num_pci_devpaths)); - uint8_t *newdata = (uint8_t*)malloc((length + offset)); + uint8_t *newdata = (uint8_t*)MALLOC((length + offset)); if(!newdata) return 0; if(device->data) @@ -330,7 +332,7 @@ device->numentries++; if(!device->data) - device->data = (uint8_t*)malloc(sizeof(uint8_t)); + device->data = (uint8_t*)MALLOC(sizeof(uint8_t)); else free(device->data); @@ -342,7 +344,7 @@ char *devprop_generate_string(struct DevPropString *string) { - char *buffer = (char*)malloc(string->length * 2); + char *buffer = (char*)MALLOC(string->length * 2); char *ptr = buffer; if(!buffer) @@ -423,6 +425,7 @@ if(!device) return 0; uint8_t builtin = 0x0; + char tmp[10]; if((vendor_id != 0x168c) && (builtin_set == 0)) { builtin_set = 1; @@ -430,6 +433,9 @@ } if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1)) return 0; + sprintf(tmp, "Slot-%x",devices_number); // 1 - vga card. FIXME - for 2+ vgas + if(!devprop_add_value(device, "AAPL,slot-name", tmp, strlen(tmp))) + return 0; devices_number++; return 1; } @@ -437,7 +443,7 @@ void set_eth_builtin(pci_dt_t *eth_dev) { char *devicepath = get_pci_dev_path(eth_dev); - struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice)); + struct DevPropDevice *device = (struct DevPropDevice*)MALLOC(sizeof(struct DevPropDevice)); verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath); @@ -449,7 +455,7 @@ { verbose("Setting up lan keys\n"); devprop_add_network_template(device, eth_dev->vendor_id); - stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length); + stringdata = (uint8_t*)MALLOC(sizeof(uint8_t) * string->length); if(stringdata) { memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length); Index: branches/rekursor/i386/libsaio/ntfs.c =================================================================== --- branches/rekursor/i386/libsaio/ntfs.c (revision 3) +++ branches/rekursor/i386/libsaio/ntfs.c (revision 4) @@ -157,7 +157,7 @@ size_t nameSize; char *buf; - buf = (char *)malloc(MAX_CLUSTER_SIZE); + buf = (char *)MALLOC(MAX_CLUSTER_SIZE); if (buf == 0) { goto error; } Index: branches/rekursor/i386/libsaio/nvidia.c =================================================================== --- branches/rekursor/i386/libsaio/nvidia.c (revision 3) +++ branches/rekursor/i386/libsaio/nvidia.c (revision 4) @@ -610,7 +610,7 @@ (REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id, devicepath); - rom = malloc(0x10000); + rom = MALLOC(0x10000); if(!rom) { @@ -697,7 +697,7 @@ if (!string) string = devprop_create_string(); - struct DevPropDevice *device = malloc(sizeof(struct DevPropDevice)); + struct DevPropDevice *device = MALLOC(sizeof(struct DevPropDevice)); device = devprop_add_device(string, devicepath); if(!device) @@ -733,7 +733,7 @@ if (set_vbios_prop) devprop_add_value(device, "vbios", rom, (nvBiosOveride > 0) ? nvBiosOveride : (rom[2] * 512)); - stringdata = malloc(sizeof(uint8_t) * string->length); + stringdata = MALLOC(sizeof(uint8_t) * string->length); if(!stringdata) { printf("no stringdata press a key...\n"); Index: branches/rekursor/i386/libsaio/ati.c =================================================================== --- branches/rekursor/i386/libsaio/ati.c (revision 3) +++ branches/rekursor/i386/libsaio/ati.c (revision 4) @@ -293,7 +293,7 @@ REG32W(0xa8, 0); REG32R(0xac); - BIOSBase = malloc(0x10000); + BIOSBase = MALLOC(0x10000); if(BIOSBase) { REG32W(0xa8, 0); @@ -428,7 +428,7 @@ printf("dumping pci config space, 256 bytes\n"); int i; uint8_t *config_space; - config_space = malloc(256); + config_space = MALLOC(256); for(i=0; i<=255; i++) config_space[i] = pci_config_read8( ati_dev->dev.addr, i); devprop_add_value(device, "ATY,PCIConfigSpace", config_space, 256); @@ -648,7 +648,7 @@ if (!string) string = devprop_create_string(); - struct DevPropDevice *device = malloc(sizeof(struct DevPropDevice)); + struct DevPropDevice *device = MALLOC(sizeof(struct DevPropDevice)); device = devprop_add_device(string, devicepath); if(!device) @@ -713,7 +713,7 @@ { sprintf(romfilename, "ati_%04x_%04x.rom", (uint16_t)ati_dev->device_id, (uint16_t)ati_dev->vendor_id); verbose("looking for file /Extra/%s\n", romfilename); - rom = malloc(0x20000); + rom = MALLOC(0x20000); rom_size = load_ati_bios_file((char *)romfilename, (char *)rom); if(rom_size > 0x10000) rom_size = 0x10000; //we dont need rest anyway; if(rom_size == 0) printf("file not found\n"); @@ -762,7 +762,7 @@ } else verbose("Bios image not found at %x, content %x %x\n", biosimage, (uint8_t)biosimage[0], (uint8_t)biosimage[1]); if(toFree) free(biosimage); } - stringdata = malloc(sizeof(uint8_t) * string->length); + stringdata = MALLOC(sizeof(uint8_t) * string->length); if(!stringdata) { printf("no stringdata press a key...\n"); Index: branches/rekursor/i386/libsaio/sys.c =================================================================== --- branches/rekursor/i386/libsaio/sys.c (revision 3) +++ branches/rekursor/i386/libsaio/sys.c (revision 4) @@ -324,7 +324,7 @@ const char * entryName; if (gMakeDirSpec == 0) - gMakeDirSpec = (char *)malloc(1024); + gMakeDirSpec = (char *)MALLOC(1024); if (!dirSpec) { long idx, len; @@ -559,7 +559,7 @@ { struct dirstuff * dirp = 0; - dirp = (struct dirstuff *) malloc(sizeof(struct dirstuff)); + dirp = (struct dirstuff *) MALLOC(sizeof(struct dirstuff)); if (dirp == NULL) goto error; @@ -587,7 +587,7 @@ if ((bvr = getBootVolumeRef(path, &dirPath)) == NULL) goto error; - dirp = (struct dirstuff *) malloc(sizeof(struct dirstuff)); + dirp = (struct dirstuff *) MALLOC(sizeof(struct dirstuff)); if (dirp == NULL) goto error; Index: branches/rekursor/i386/libsaio/nbp.c =================================================================== --- branches/rekursor/i386/libsaio/nbp.c (revision 3) +++ branches/rekursor/i386/libsaio/nbp.c (revision 4) @@ -120,7 +120,7 @@ if ( !gNetBVR ) { - gNetBVR = malloc( sizeof(*gNetBVR) ); + gNetBVR = MALLOC( sizeof(*gNetBVR) ); if ( gNetBVR ) { bzero(gNetBVR, sizeof(*gNetBVR)); Index: branches/rekursor/i386/libsaio/disk.c =================================================================== --- branches/rekursor/i386/libsaio/disk.c (revision 3) +++ branches/rekursor/i386/libsaio/disk.c (revision 4) @@ -500,7 +500,7 @@ BVFree bvFreeFunc, int probe, int type, unsigned int bvrFlags ) { - BVRef bvr = (BVRef) malloc( sizeof(*bvr) ); + BVRef bvr = (BVRef) MALLOC( sizeof(*bvr) ); if ( bvr ) { bzero(bvr, sizeof(*bvr)); @@ -569,7 +569,7 @@ BVFree bvFreeFunc, int probe, int type, unsigned int bvrFlags ) { - BVRef bvr = (BVRef) malloc( sizeof(*bvr) ); + BVRef bvr = (BVRef) MALLOC( sizeof(*bvr) ); if ( bvr ) { bzero(bvr, sizeof(*bvr)); @@ -650,7 +650,7 @@ BVFree bvFreeFunc, int probe, int type, unsigned int bvrFlags ) { - BVRef bvr = (BVRef) malloc( sizeof(*bvr) ); + BVRef bvr = (BVRef) MALLOC( sizeof(*bvr) ); if ( bvr ) { bzero(bvr, sizeof(*bvr)); @@ -750,7 +750,7 @@ do { // Create a new mapping. - map = (struct DiskBVMap *) malloc( sizeof(*map) ); + map = (struct DiskBVMap *) MALLOC( sizeof(*map) ); if ( map ) { map->biosdev = biosdev; @@ -976,7 +976,7 @@ struct Block0 *block0_p; unsigned int blksize; unsigned int factor; - void *buffer = malloc(BPS); + void *buffer = MALLOC(BPS); /* Check for alternate block size */ if (readBytes( biosdev, 0, 0, BPS, buffer ) != 0) { @@ -987,7 +987,7 @@ blksize = OSSwapBigToHostInt16(block0_p->sbBlkSize); if (blksize != BPS) { free(buffer); - buffer = malloc(blksize); + buffer = MALLOC(blksize); } factor = blksize / BPS; } else { @@ -998,7 +998,7 @@ do { // Create a new mapping. - map = (struct DiskBVMap *) malloc( sizeof(*map) ); + map = (struct DiskBVMap *) MALLOC( sizeof(*map) ); if ( map ) { int error; @@ -1074,7 +1074,7 @@ int fatbits; // Allocating buffer for 4 sectors. - const void * probeBuffer = malloc(PROBEFS_SIZE); + const void * probeBuffer = MALLOC(PROBEFS_SIZE); if (probeBuffer == NULL) goto exit; @@ -1128,7 +1128,7 @@ static BVRef diskScanGPTBootVolumes( int biosdev, int * countPtr ) { struct DiskBVMap * map = NULL; - void *buffer = malloc(BPS); + void *buffer = MALLOC(BPS); int error; if ( error = readBytes( biosdev, /*secno*/0, 0, BPS, buffer ) != 0) { verbose("Failed to read boot sector from BIOS device %02xh. Error=%d\n", biosdev, error); @@ -1223,7 +1223,7 @@ UInt32 bufferSize = IORound(gptCount * gptSize, BPS); if(bufferSize == 0) goto scanErr; - buffer = malloc(bufferSize); + buffer = MALLOC(bufferSize); if(readBytes(biosdev, gptBlock, 0, bufferSize, buffer) != 0) goto scanErr; @@ -1231,7 +1231,7 @@ verbose("Read GPT\n"); // Allocate a new map for this BIOS device and insert it into the chain - map = malloc(sizeof(*map)); + map = MALLOC(sizeof(*map)); map->biosdev = biosdev; map->bvr = NULL; map->bvrcnt = 0; @@ -1573,7 +1573,7 @@ /* * Allocate and copy the matched bvr entry into a new one. */ - newBVR = (BVRef) malloc(sizeof(*newBVR)); + newBVR = (BVRef) MALLOC(sizeof(*newBVR)); bcopy(bvr, newBVR, sizeof(*newBVR)); /* @@ -1730,7 +1730,7 @@ { if ( gBootSector == NULL ) { - gBootSector = (struct disk_blk0 *) malloc(sizeof(*gBootSector)); + gBootSector = (struct disk_blk0 *) MALLOC(sizeof(*gBootSector)); if ( gBootSector == NULL ) return -1; } bootSector = gBootSector; @@ -1767,7 +1767,7 @@ { if ( gBootSector == NULL ) { - gBootSector = (struct disk_blk0 *) malloc(sizeof(*gBootSector)); + gBootSector = (struct disk_blk0 *) MALLOC(sizeof(*gBootSector)); if ( gBootSector == NULL ) return -1; } bootSector = (struct disk_boot1f32_blk *) gBootSector; Index: branches/rekursor/i386/libsaio/cache.c =================================================================== --- branches/rekursor/i386/libsaio/cache.c (revision 3) +++ branches/rekursor/i386/libsaio/cache.c (revision 4) @@ -90,8 +90,8 @@ gCacheIH = ih; #ifdef __i386__ - if (!gCacheBuffer) gCacheBuffer = (char *) malloc(kCacheSize); - if (!gCacheEntries) gCacheEntries = (CacheEntry *) malloc(kCacheMaxEntries * sizeof(CacheEntry)); + if (!gCacheBuffer) gCacheBuffer = (char *) MALLOC(kCacheSize); + if (!gCacheEntries) gCacheEntries = (CacheEntry *) MALLOC(kCacheMaxEntries * sizeof(CacheEntry)); if ( !gCacheBuffer || !gCacheEntries ) { gCacheIH = 0; // invalidate cache Index: branches/rekursor/i386/libsaio/pci.c =================================================================== --- branches/rekursor/i386/libsaio/pci.c (revision 3) +++ branches/rekursor/i386/libsaio/pci.c (revision 4) @@ -67,7 +67,7 @@ if (!id || id == 0xffffffff) continue; - new = (pci_dt_t*)malloc(sizeof(pci_dt_t)); + new = (pci_dt_t*)MALLOC(sizeof(pci_dt_t)); if (!new) return; memset(new, 0, sizeof(pci_dt_t)); @@ -116,7 +116,7 @@ void build_pci_dt(void) { - root_pci_dev = malloc(sizeof(pci_dt_t)); + root_pci_dev = MALLOC(sizeof(pci_dt_t)); if (!root_pci_dev) return; @@ -132,20 +132,27 @@ { pci_dt_t *current, *end; char tmp[30]; + int uid = 0; dev_path[0] = 0; end = root_pci_dev; + uid = getPciRootUID(); + while (end != pci_dt) { current = pci_dt; while (current->parent != end) current = current->parent; end = current; - - sprintf(tmp, "%s/Pci(0x%x,0x%x)", - (current->parent == root_pci_dev) ? "PciRoot(0x0)" : "", + if (current->parent == root_pci_dev) + { + sprintf(tmp, "PciRoot(0x%x)/Pci(0x%x,0x%x)", uid, current->dev.bits.dev, current->dev.bits.func); + } else { + sprintf(tmp, "/Pci(0x%x,0x%x)", + current->dev.bits.dev, current->dev.bits.func); + } strcat(dev_path, tmp); } Index: branches/rekursor/i386/libsaio/stringTable.c =================================================================== --- branches/rekursor/i386/libsaio/stringTable.c (revision 3) +++ branches/rekursor/i386/libsaio/stringTable.c (revision 4) @@ -106,7 +106,7 @@ len = strlen(key); tab = (char *)table; - buf = (char *)malloc(len + 3); + buf = (char *)MALLOC(len + 3); sprintf(buf, "\"%s\"", key); len = strlen(buf); @@ -164,7 +164,7 @@ if (begin == end) return 0; bufsize = end - begin + 1; - newstr = malloc(bufsize); + newstr = MALLOC(bufsize); strlcpy(newstr, begin, bufsize); *list = end; *size = newsize; @@ -241,7 +241,7 @@ int size; if (getValueForConfigTableKey(config, key, &val, &size)) { - newstr = (char *)malloc(size+1); + newstr = (char *)MALLOC(size+1); for (p = newstr; size; size--, p++, val++) { if ((*p = *val) == '\\') { switch (*++val) { @@ -278,7 +278,7 @@ int size; if (getValueForKey(key, &val, &size, config) && size) { - newstr = (char *)malloc(size + 1); + newstr = (char *)MALLOC(size + 1); strlcpy(newstr, val, size + 1); return newstr; } else { @@ -338,6 +338,15 @@ return retval; } +/* Return NULL if no option has been successfully retrieved, or the string otherwise */ +const char * getStringForKey(const char * key, config_file_t *config) +{ + static const char* value =0; + int len=0; + if(getValueForKey(key, &value, &len, config)!=YES) value = 0; + return value; +} + /* Returns TRUE if a value was found, FALSE otherwise. * The boolean value of the key is stored in 'val'. */ @@ -550,7 +559,7 @@ pos = 0; char *configBuffer; - configBuffer = malloc(strlen(buffer)+1); + configBuffer = MALLOC(strlen(buffer)+1); strcpy(configBuffer, buffer); while (1) @@ -716,7 +725,7 @@ char * newString(const char * oldString) { if ( oldString ) - return strcpy(malloc(strlen(oldString)+1), oldString); + return strcpy(MALLOC(strlen(oldString)+1), oldString); else return NULL; } Index: branches/rekursor/i386/libsaio/msdos.c =================================================================== --- branches/rekursor/i386/libsaio/msdos.c (revision 3) +++ branches/rekursor/i386/libsaio/msdos.c (revision 4) @@ -156,7 +156,7 @@ return 0; } - buf=malloc (512); + buf=MALLOC (512); /* * Read the boot sector of the filesystem, and then check the * boot signature. If not a dos boot sector then error out. @@ -630,10 +630,10 @@ st = (struct msdosdirstate *)*dirIndex; if (!st) { - st=malloc (sizeof (*st)); + st=MALLOC (sizeof (*st)); if (dirPath[0]) { - uint8_t *buf=malloc(msdosclustersize); + uint8_t *buf=MALLOC(msdosclustersize); dirp = getdirpfrompath (ih, dirPath, buf); if (!dirp || !(dirp->deAttributes & ATTR_DIRECTORY)) { @@ -665,14 +665,14 @@ { int i; for (i=0;vfatname[i];i++); - *name = malloc (256); + *name = MALLOC (256); utf_encodestr(vfatname, i, (u_int8_t *)*name, 255, OSLittleEndian ); } else { int i, j, k; uint16_t tmp[13]; - *name = malloc (26); + *name = MALLOC (26); for (i=7;i>=0;i--) if (dirp->deName[i]!=' ') break; @@ -725,7 +725,7 @@ return -1; if (filePath[0] == '/') filePath++; - buf = malloc(msdosclustersize); + buf = MALLOC(msdosclustersize); dirp = getdirpfrompath (ih, filePath, buf); if (!dirp || (dirp->deAttributes & ATTR_DIRECTORY)) @@ -774,7 +774,7 @@ return -1; if (filePath[0] == '/') filePath++; - buf = malloc(msdosclustersize); + buf = MALLOC(msdosclustersize); dirp = getdirpfrompath (ih, filePath, buf); if (!dirp || (dirp->deAttributes & ATTR_DIRECTORY)) { @@ -866,7 +866,7 @@ label[0] = '\0'; initRoot (&st); - st.buf = malloc(msdosclustersize); + st.buf = MALLOC(msdosclustersize); while ((dirp = getnextdirent (ih, vfatlabel, &st))) if (dirp->deAttributes & ATTR_VOLUME) { strncpy((char *)label, (char *)dirp->deName, LABEL_LENGTH); @@ -887,7 +887,7 @@ /* else look in the boot blocks */ if (!labelfound || str[0] == '\0') { - char *buf = malloc (512); + char *buf = MALLOC (512); union bootsector *bsp = (union bootsector *)buf; Seek(ih, 0); Read(ih, (long)buf, 512); @@ -907,7 +907,7 @@ long MSDOSGetUUID(CICell ih, char *uuidStr) { - char *buf = malloc (512); + char *buf = MALLOC (512); union bootsector *bsp = (union bootsector *)buf; if (MSDOSInitPartition (ih)<0) Index: branches/rekursor/i386/libsaio/fake_efi.c =================================================================== --- branches/rekursor/i386/libsaio/fake_efi.c (revision 3) +++ branches/rekursor/i386/libsaio/fake_efi.c (revision 4) @@ -1,3 +1,4 @@ + /* * Copyright 2007 David F. Elliott. All rights reserved. */ @@ -14,6 +15,7 @@ #include "device_inject.h" #include "pci.h" #include "sl.h" +#include "SMBIOS.h" extern struct SMBEntryPoint * getSmbios(); extern void setup_pci_devs(pci_dt_t *pci_dt); @@ -55,7 +57,7 @@ static inline char * mallocStringForGuid(EFI_GUID const *pGuid) { - char *string = malloc(37); + char *string = MALLOC(37); efi_guid_unparse_upper(pGuid, string); return string; } @@ -79,7 +81,7 @@ static EFI_UINT32 const FIRMWARE_REVISION = 132; /* FIXME: Find a constant for this. */ /* Default platform system_id (fix by IntVar) */ -static EFI_CHAR8 const SYSTEM_ID[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10};//random value gen by uuidgen +static EFI_CHAR8 const SYSTEM_ID[] = "0123456789ABCDEF";//random value gen by uuidgen /* Just a ret instruction */ static uint8_t const VOIDRET_INSTRUCTIONS[] = {0xc3}; @@ -273,9 +275,9 @@ */ /* These should be const but DT__AddProperty takes char* */ -static char TSC_Frequency_prop[] = "TSCFrequency"; -static char FSB_Frequency_prop[] = "FSBFrequency"; -static char CPU_Frequency_prop[] = "CPUFrequency"; +static const char const TSC_Frequency_prop[] = "TSCFrequency"; +static const char const FSB_Frequency_prop[] = "FSBFrequency"; +static const char const CPU_Frequency_prop[] = "CPUFrequency"; /*========================================================================== * SMBIOS @@ -316,17 +318,176 @@ */ /* These should be const but DT__AddProperty takes char* */ -static char FIRMWARE_REVISION_PROP[] = "firmware-revision"; -static char FIRMWARE_ABI_PROP[] = "firmware-abi"; -static char FIRMWARE_VENDOR_PROP[] = "firmware-vendor"; -static char FIRMWARE_ABI_PROP_VALUE[] = "EFI64"; -static char SYSTEM_ID_PROP[] = "system-id"; +static const char const FIRMWARE_REVISION_PROP[] = "firmware-revision"; +static const char const FIRMWARE_ABI_PROP[] = "firmware-abi"; +static const char const FIRMWARE_VENDOR_PROP[] = "firmware-vendor"; +static const char const FIRMWARE_ABI_PROP_VALUE[] = "EFI64"; +static const char const SYSTEM_ID_PROP[] = "system-id"; +static const char const SYSTEM_SERIAL_PROP[] = "SystemSerialNumber"; +static const char const SYSTEM_TYPE_PROP[] = "system-type"; +static const char const MODEL_PROP[] = "Model"; -void -setupEfiDeviceTree(void) +#define UUID_LEN 16 + +/* Get an smbios option string option to convert to EFI_CHAR16 string */ +static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len) { + const char * src=0; + EFI_CHAR16* dst = 0; + size_t i; + + if (!key || !(*key) || !len || !(src = getStringForKey(key, &bootInfo->smbiosConfig))) + return 0; + + *len = strlen(src); + dst = (EFI_CHAR16*) MALLOC(((*len)+1)*2); + for (i=0; i<*len; i++) dst[i] = src[i]; + dst[*len] = '\0'; + + return dst; +} + +#define DEBUG_SMBIOS 1 + +/* Get the SystemID from the bios dmi info */ +static EFI_CHAR8* getSmbiosUUID() +{ + struct SMBEntryPoint *smbios; + struct DMIHeader *dmihdr; + SMBByte *p; + int i, found, isZero, isOnes; + static EFI_CHAR8 uuid[UUID_LEN+1]=""; + + smbios = getAddressOfSmbiosTable(); /* checks for _SM_ anchor and table header checksum */ + if (memcmp( &smbios->dmi.anchor[0], "_DMI_", 5) != 0) { + return 0; + } + verbose(">>> SMBIOSAddr=0x%08x\n", smbios); + verbose(">>> DMI: addr=0x%08x, len=0x%d, count=%d\n", smbios->dmi.tableAddress, + smbios->dmi.tableLength, smbios->dmi.structureCount); + i = 0; + found = 0; + p = (SMBByte *) smbios->dmi.tableAddress; + while (i < smbios->dmi.structureCount && p + 4 <= (SMBByte *)smbios->dmi.tableAddress + smbios->dmi.tableLength) { + dmihdr = (struct DMIHeader *) p; + verbose(">>>>>> DMI(%d): type=0x%02x, len=0x%d\n",i,dmihdr->type,dmihdr->length); + if (dmihdr->length < 4 || dmihdr->type == 127 /* EOT */) break; + if (dmihdr->type == 1) { /* 3.3.2 System Information */ + if (dmihdr->length >= 0x19) found = 1; + break; + } + p = p + dmihdr->length; + while ((p - (SMBByte *)smbios->dmi.tableAddress + 1 < smbios->dmi.tableLength) && (p[0] != 0x00 || p[1] != 0x00)) + p++; + p += 2; + i++; + } + + if (!found) return 0; + + verbose("Found SMBIOS System Information Table 1\n"); + p += 8; + + for (i=0, isZero=1, isOnes=1; i to valid UUID.\n", szUUID); + return (EFI_CHAR8*) 0; + } + return (EFI_CHAR8*) ret; // new allocated buffer containing the converted string to bin +} +*/ + +/* return a binary UUID value from the overriden SystemID and SMUUID if ound, + * or from the bios if not, or from a fixed value if no bios value is found + */ +static EFI_CHAR8* getSystemID() +{ // unable to determine UUID for host. Error: 35 fix + const char * sysId = getStringForKey("SystemID", &bootInfo->bootConfig); + EFI_CHAR8* ret = getUUIDFromString(sysId); + if(!sysId || !ret) // try smbios.plist SMUUID override + ret=getUUIDFromString((sysId = getStringForKey("SMUUID",&bootInfo->smbiosConfig))); + if(!sysId || !ret) { // try bios dmi info UUID extraction + ret = getSmbiosUUID(); + sysId=0; + } + if(!ret) // no bios dmi UUID available, set a fixed value for system-id + ret=getUUIDFromString((sysId = (const char*) SYSTEM_ID)); + + verbose("Customizing SystemID with : %s\n", sysId ? sysId :"BIOS internal UUID"); + return ret; +} + +void setupEfiDeviceTree(void) +{ + EFI_CHAR16* ret16=0; + EFI_CHAR8* ret=0; + size_t len=0; Node *node; + EFI_CHAR8 SystemType=1; + const char *value; + node = DT__FindNode("/", false); + if (node == 0) { stop("Couldn't get root node"); } @@ -348,7 +509,7 @@ Node *runtimeServicesNode = DT__AddChild(node, "runtime-services"); /* The value of the table property is the 32-bit physical address for the RuntimeServices table. - * Sice the EFI system table already has a pointer to it, we simply use the address of that pointer + * Since the EFI system table already has a pointer to it, we simply use the address of that pointer * for the pointer to the property data. Warning.. DT finalization calls free on that but we're not * the only thing to use a non-malloc'd pointer for something in the DT */ @@ -369,16 +530,35 @@ if(fsbFrequency != 0) DT__AddProperty(efiPlatformNode, FSB_Frequency_prop, sizeof(uint64_t), &fsbFrequency); - // unable to determine UUID for host. Error: 35 fix - DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, sizeof(SYSTEM_ID), (EFI_UINT32*)&SYSTEM_ID); - - /* Export TSC and CPU frequencies for use by the kernel or KEXTs + /* Export TSC and CPU frequencies for use by the kernel or KEXTs */ if(tscFrequency != 0) DT__AddProperty(efiPlatformNode, TSC_Frequency_prop, sizeof(uint64_t), &tscFrequency); + if(cpuFrequency != 0) DT__AddProperty(efiPlatformNode, CPU_Frequency_prop, sizeof(uint64_t), &cpuFrequency); + /* Export system-id. Can be disabled with system-id=No in com.apple.Boot.plist */ + if((ret=getSystemID())) + DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32*) ret); + + /* Export system-type. Allowed values are: 0x01 for desktop computer (default), 0x02 for portable computers */ + if (getValueForKey("system-type", &value, (int*) &len, &bootInfo->bootConfig) && value != NULL) { + if (*value != '1' && *value != '2') + verbose("Error: system-type must be 1 (desktop) or 2 (portable). Defaulting to 1!\n"); + else + SystemType = (unsigned char) (*value-'0'); + } + DT__AddProperty(node, SYSTEM_TYPE_PROP, sizeof(EFI_CHAR8), &SystemType); + + /* Export SystemSerialNumber if present */ + if ((ret16=getSmbiosChar16("SMserial", &len))) + DT__AddProperty(efiPlatformNode, SYSTEM_SERIAL_PROP, len, ret16); + + /* Export Model if present */ + if ((ret16=getSmbiosChar16("SMproductname", &len))) + DT__AddProperty(efiPlatformNode, MODEL_PROP, len, ret16); + /* Fill /efi/device-properties node. */ setupDeviceProperties(node); @@ -417,3 +597,4 @@ // Add configuration table entries to both the services table and the device tree setupEfiConfigurationTable(); } + Index: branches/rekursor/i386/libsaio/saio_internal.h =================================================================== --- branches/rekursor/i386/libsaio/saio_internal.h (revision 3) +++ branches/rekursor/i386/libsaio/saio_internal.h (revision 4) @@ -150,6 +150,7 @@ extern char * newStringForKey(char *key, config_file_t *configBuff); extern BOOL getValueForBootKey(const char *line, const char *match, const char **matchval, int *len); extern BOOL getValueForKey(const char *key, const char **val, int *size, config_file_t *configBuff); +extern const char * getStringForKey(const char * key, config_file_t *config); extern BOOL getBoolForKey(const char *key, BOOL *val, config_file_t *configBuff); extern BOOL getIntForKey(const char *key, int *val, config_file_t *configBuff); extern BOOL getColorForKey(const char *key, unsigned int *val, config_file_t *configBuff); Index: branches/rekursor/i386/boot2/picopng.c =================================================================== --- branches/rekursor/i386/boot2/picopng.c (revision 3) +++ branches/rekursor/i386/boot2/picopng.c (revision 4) @@ -45,7 +45,7 @@ png_alloc_node_t *node; if (png_alloc_find_node(addr)) return; - node = malloc(sizeof (png_alloc_node_t)); + node = MALLOC(sizeof (png_alloc_node_t)); node->addr = addr; node->size = size; node->prev = png_alloc_tail; @@ -73,7 +73,7 @@ void *png_alloc_malloc(size_t size) { - void *addr = malloc(size); + void *addr = MALLOC(size); png_alloc_add_node(addr, size); return addr; } @@ -1097,7 +1097,7 @@ return 1; } insize = (uint32_t) statbuf.st_size; - inbuf = malloc(insize); + inbuf = MALLOC(insize); infp = fopen(fname, "rb"); if (!infp) { perror("fopen"); Index: branches/rekursor/i386/boot2/graphics.c =================================================================== --- branches/rekursor/i386/boot2/graphics.c (revision 3) +++ branches/rekursor/i386/boot2/graphics.c (revision 4) @@ -52,7 +52,7 @@ { VBEInfoBlock vbeInfo; int err, small; - char *buff = malloc(sizeof(char)*256); + char *buff = MALLOC(sizeof(char)*256); if(!buff) return 0; bzero( &vbeInfo, sizeof(vbeInfo) ); @@ -151,7 +151,7 @@ if ( err != errSuccess ) return 0; - char *buff=malloc(sizeof(char)*3072); + char *buff=MALLOC(sizeof(char)*3072); if(!buff) return 0; // Loop through the mode list, and find the matching mode. @@ -349,7 +349,7 @@ unsigned char value; } * bp = (struct RLEBlock *) rleData; - out = cp = (char *) malloc( outBytes ); + out = cp = (char *) MALLOC( outBytes ); if ( out == NULL ) return NULL; while ( rleBlocks-- ) @@ -483,7 +483,7 @@ switch ( VIDEO(depth) ) { case 16 : - img16 = malloc(width * height * 2); + img16 = MALLOC(width * height * 2); if ( !img16 ) break; for (cnt = 0; cnt < (width * height); cnt++) img16[cnt] = lookUpCLUTIndex(imageData[cnt], 16); @@ -491,7 +491,7 @@ break; case 32 : - img32 = malloc(width * height * 4); + img32 = MALLOC(width * height * 4); if ( !img32 ) break; for (cnt = 0; cnt < (width * height); cnt++) img32[cnt] = lookUpCLUTIndex(imageData[cnt], 32); @@ -499,7 +499,7 @@ break; default : - img = malloc(width * height); + img = MALLOC(width * height); bcopy(imageData, img, width * height); break; } @@ -525,7 +525,7 @@ error = -1; goto failed; } - pngData = malloc(pngSize); + pngData = MALLOC(pngSize); if (read(pngFile, (char *) pngData, pngSize) != pngSize) { error = -1; goto failed; @@ -543,7 +543,7 @@ error = -1; goto failed; } - uint8_t *result = malloc(info->width*4*info->height); + uint8_t *result = MALLOC(info->width*4*info->height); *width = info->width; *height = info->height; memcpy(result, info->image->data, info->width*4*info->height); @@ -575,7 +575,7 @@ error = -1; goto failed; } - uint8_t *result = malloc(info->width*4*info->height); + uint8_t *result = MALLOC(info->width*4*info->height); *width = info->width; *height = info->height; memcpy(result, info->image->data, info->width*4*info->height); @@ -592,7 +592,7 @@ uint16_t width=0,height=0; uint8_t *imagedata = 0; - pixmap_t *pm=malloc(sizeof(pixmap_t)); + pixmap_t *pm=MALLOC(sizeof(pixmap_t)); if(!pm) return 0; if((loadPngImage(filename, &width, &height, &imagedata))!=0) return 0; pm->width = width; @@ -610,7 +610,7 @@ uint16_t width=0,height=0; uint8_t *imagedata = 0; - pixmap_t *pm=malloc(sizeof(pixmap_t)); + pixmap_t *pm=MALLOC(sizeof(pixmap_t)); if(!pm) return 0; if((loadEmbeddedPngImage(pngData, pngSize, &width, &height, &imagedata))!=0) return 0; pm->width = width; Index: branches/rekursor/i386/boot2/boot.c =================================================================== --- branches/rekursor/i386/boot2/boot.c (revision 3) +++ branches/rekursor/i386/boot2/boot.c (revision 4) @@ -115,11 +115,12 @@ //========================================================================== // Malloc error function -static void malloc_error(char *addr, size_t size) +//========================================================================== +// Malloc error function + +static void malloc_error(char *addr, size_t size, const char *file, int line) { - printf("\nMemory allocation error (0x%x, 0x%x)\n", - (unsigned)addr, (unsigned)size); - asm volatile ("hlt"); + stop("\nMemory allocation error! Addr=0x%x, Size=0x%x, File=%s, Line=%d\n", (unsigned)addr, (unsigned)size, file, line); } /*! Index: branches/rekursor/i386/boot2/drivers.c =================================================================== --- branches/rekursor/i386/boot2/drivers.c (revision 3) +++ branches/rekursor/i386/boot2/drivers.c (revision 4) @@ -145,11 +145,11 @@ static long InitDriverSupport( void ) { - gExtensionsSpec = (char *) malloc( 4096 ); - gDriverSpec = (char *) malloc( 4096 ); - gFileSpec = (char *) malloc( 4096 ); - gTempSpec = (char *) malloc( 4096 ); - gFileName = (char *) malloc( 4096 ); + gExtensionsSpec = (char *) MALLOC( 4096 ); + gDriverSpec = (char *) MALLOC( 4096 ); + gFileSpec = (char *) MALLOC( 4096 ); + gTempSpec = (char *) MALLOC( 4096 ); + gFileName = (char *) MALLOC( 4096 ); if ( !gExtensionsSpec || !gDriverSpec || !gFileSpec || !gTempSpec || !gFileName ) stop("InitDriverSupport error"); @@ -434,7 +434,7 @@ (bundleType == kCFBundleType2) ? "Contents/MacOS/" : ""); executablePathLength = strlen(gFileSpec) + 1; - tmpExecutablePath = malloc(executablePathLength); + tmpExecutablePath = MALLOC(executablePathLength); if (tmpExecutablePath == 0) break; strcpy(tmpExecutablePath, gFileSpec); @@ -442,7 +442,7 @@ sprintf(gFileSpec, "%s/%s", dirSpec, name); bundlePathLength = strlen(gFileSpec) + 1; - tmpBundlePath = malloc(bundlePathLength); + tmpBundlePath = MALLOC(bundlePathLength); if (tmpBundlePath == 0) break; strcpy(tmpBundlePath, gFileSpec); @@ -456,7 +456,7 @@ if (length == -1) break; length = length + 1; - buffer = malloc(length); + buffer = MALLOC(length); if (buffer == 0) break; strlcpy(buffer, (char *)kLoadAddr, length); @@ -471,7 +471,7 @@ module->executablePath = tmpExecutablePath; module->bundlePath = tmpBundlePath; module->bundlePathLength = bundlePathLength; - module->plistAddr = (void *)malloc(length); + module->plistAddr = (void *)MALLOC(length); if ((module->executablePath == 0) || (module->bundlePath == 0) || (module->plistAddr == 0)) break; @@ -727,7 +727,7 @@ return -2; } - tmpModule = (ModulePtr)malloc(sizeof(Module)); + tmpModule = (ModulePtr)MALLOC(sizeof(Module)); if (tmpModule == 0) { XMLFreeTag(moduleDict); @@ -784,7 +784,7 @@ #endif uncompressed_size = OSSwapBigToHostInt32(kernel_header->uncompressed_size); - binary = buffer = malloc(uncompressed_size); + binary = buffer = MALLOC(uncompressed_size); size = decompress_lzss((u_int8_t *) binary, &kernel_header->data[0], OSSwapBigToHostInt32(kernel_header->compressed_size)); Index: branches/rekursor/i386/boot2/bmdecompress.c =================================================================== --- branches/rekursor/i386/boot2/bmdecompress.c (revision 3) +++ branches/rekursor/i386/boot2/bmdecompress.c (revision 4) @@ -34,10 +34,10 @@ int i, j; uint32_t * input; - uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc0 = MALLOC((width+2) * sizeof(uint16_t)); + uint16_t * sc1 = MALLOC((width+2) * sizeof(uint16_t)); + uint16_t * sc2 = MALLOC((width+2) * sizeof(uint16_t)); + uint16_t * sc3 = MALLOC((width+2) * sizeof(uint16_t)); uint32_t sr0, sr1, sr2, sr3; bzero(sc0, (width+2) * sizeof(uint16_t)); @@ -135,10 +135,10 @@ int i, j; uint32_t * input; - uint16_t * sc0 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc1 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc2 = malloc((width+2) * sizeof(uint16_t)); - uint16_t * sc3 = malloc((width+2) * sizeof(uint16_t)); + uint16_t * sc0 = MALLOC((width+2) * sizeof(uint16_t)); + uint16_t * sc1 = MALLOC((width+2) * sizeof(uint16_t)); + uint16_t * sc2 = MALLOC((width+2) * sizeof(uint16_t)); + uint16_t * sc3 = MALLOC((width+2) * sizeof(uint16_t)); uint32_t sr0, sr1, sr2, sr3; bzero(sc0, (width+2) * sizeof(uint16_t)); @@ -238,7 +238,7 @@ *dw = (int) src[1]; *dh = (int) src[2]; - ret = malloc ((*dw * *dh * *bitsPerPixel)/ 8); + ret = MALLOC ((*dw * *dh * *bitsPerPixel)/ 8); switch(*bitsPerPixel) { Index: branches/rekursor/i386/boot2/gui.c =================================================================== --- branches/rekursor/i386/boot2/gui.c (revision 3) +++ branches/rekursor/i386/boot2/gui.c (revision 4) @@ -155,10 +155,10 @@ pixmap_t *getCroppedPixmapAtPosition( pixmap_t *from, position_t pos, uint16_t width, uint16_t height ) { - pixmap_t *cropped = malloc( sizeof( pixmap_t ) ); + pixmap_t *cropped = MALLOC( sizeof( pixmap_t ) ); if( !cropped ) return 0; - cropped->pixels = malloc( width * height * 4 ); + cropped->pixels = MALLOC( width * height * 4 ); if ( !cropped->pixels ) return 0; @@ -180,11 +180,11 @@ int createBackBuffer( window_t *window ) { - gui.backbuffer = malloc(sizeof(pixmap_t)); + gui.backbuffer = MALLOC(sizeof(pixmap_t)); if(!gui.backbuffer) return 1; - gui.backbuffer->pixels = malloc( window->width * window->height * 4 ); + gui.backbuffer->pixels = MALLOC( window->width * window->height * 4 ); if(!gui.backbuffer->pixels) { free(gui.backbuffer); @@ -200,11 +200,11 @@ int createWindowBuffer( window_t *window ) { - window->pixmap = malloc(sizeof(pixmap_t)); + window->pixmap = MALLOC(sizeof(pixmap_t)); if(!window->pixmap) return 1; - window->pixmap->pixels = malloc( window->width * window->height * 4 ); + window->pixmap->pixels = MALLOC( window->width * window->height * 4 ); if(!window->pixmap->pixels) { free(window->pixmap); @@ -879,7 +879,7 @@ struct putc_info pi; - if( formattedtext = (char *) malloc(1024) ) + if( formattedtext = (char *) MALLOC(1024) ) { // format the text va_start(ap, fmt); @@ -965,7 +965,7 @@ struct putc_info pi; - if( formattedtext = (char *) malloc(1024) ) + if( formattedtext = (char *) MALLOC(1024) ) { // format the text va_start(ap, fmt); @@ -1053,7 +1053,7 @@ position_t origin, cursor, bounds; font_t *font = &font_console; - if( formattedtext = (char *) malloc(1024) ) + if( formattedtext = (char *) MALLOC(1024) ) { // format the text pi.str = formattedtext; @@ -1204,12 +1204,12 @@ { end = x + 1; - if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) + if( (font->chars[count] = MALLOC(sizeof(pixmap_t)) ) ) { font->chars[count]->width = ( end - start) - 1; font->chars[count]->height = font->height; - if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) + if ( ( font->chars[count]->pixels = MALLOC( font->chars[count]->width * data->image->height * 4) ) ) { space += ( font->chars[count]->width * data->image->height * 4 ); // we skip the first line because there are just the red pixels for the char width @@ -1286,7 +1286,7 @@ for( i=0; i < sizeof(images) / sizeof(images[0]); i++) { // create pixmap_t buffer for each image - images[i].image = malloc(sizeof(pixmap_t)); + images[i].image = MALLOC(sizeof(pixmap_t)); } LOADPNG(background); @@ -1526,7 +1526,7 @@ return; pixmap_t progressbar; - progressbar.pixels=malloc(width * 4 * buff->height); + progressbar.pixels=MALLOC(width * 4 * buff->height); if(!progressbar.pixels) return; Index: branches/rekursor/i386/boot2/ramdisk.c =================================================================== --- branches/rekursor/i386/boot2/ramdisk.c (revision 3) +++ branches/rekursor/i386/boot2/ramdisk.c (revision 4) @@ -73,8 +73,8 @@ strcpy(gRAMDiskFile, param); // Set gMI as well for the multiboot ramdisk driver hook. - gMI = gRAMDiskMI = malloc(sizeof(multiboot_info)); - struct multiboot_module * ramdisk_module = malloc(sizeof(multiboot_module)); + gMI = gRAMDiskMI = MALLOC(sizeof(multiboot_info)); + struct multiboot_module * ramdisk_module = MALLOC(sizeof(multiboot_module)); // Fill in multiboot info and module structures. if (gRAMDiskMI != NULL && ramdisk_module != NULL) @@ -224,4 +224,4 @@ getc(); setActiveDisplayPage(0); } -} \ No newline at end of file +} Index: branches/rekursor/i386/boot2/options.c =================================================================== --- branches/rekursor/i386/boot2/options.c (revision 3) +++ branches/rekursor/i386/boot2/options.c (revision 4) @@ -634,7 +634,7 @@ { int i; MemoryRange *mp = bootInfo->memoryMap; - char *buff = malloc(sizeof(char)*1024); + char *buff = MALLOC(sizeof(char)*1024); if(!buff) return 0; char info[] = "BIOS reported memory ranges:\n"; @@ -771,12 +771,12 @@ if (getValueForKey( kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig )) { cnt += 1; - prompt = malloc(cnt); + prompt = MALLOC(cnt); strlcpy(prompt, val, cnt); } else { - name = malloc(80); + name = MALLOC(80); getBootVolumeDescription( gBootVolume, name, 80, NO ); - prompt = malloc(256); + prompt = MALLOC(256); sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name); free(name); cnt = 0; @@ -851,7 +851,7 @@ if ( gDeviceCount ) { // Allocate memory for an array of menu items. - menuItems = (MenuItem *) malloc( sizeof(MenuItem) * gDeviceCount ); + menuItems = (MenuItem *) MALLOC( sizeof(MenuItem) * gDeviceCount ); if ( menuItems == NULL ) goto done; // Associate a menu item for each BVRef. @@ -1187,7 +1187,7 @@ char * configKernelFlags; char * valueBuffer; - valueBuffer = (char *)malloc(VALUE_SIZE); + valueBuffer = (char *)MALLOC(VALUE_SIZE); skipblanks( &cp ); @@ -1263,7 +1263,7 @@ val = ""; cnt = 0; } - configKernelFlags = (char *)malloc(cnt + 1); + configKernelFlags = (char *)MALLOC(cnt + 1); strlcpy(configKernelFlags, val, cnt + 1); if (processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0)) { @@ -1417,7 +1417,7 @@ size = file_size(fd); if (size > MAX_TEXT_FILE_SIZE) size = MAX_TEXT_FILE_SIZE; - buffer = malloc( size + 1 ); + buffer = MALLOC( size + 1 ); read(fd, buffer, size); close(fd); @@ -1587,4 +1587,4 @@ } return result; -} \ No newline at end of file +} Index: branches/rekursor/i386/libsa/libsa.h =================================================================== --- branches/rekursor/i386/libsa/libsa.h (revision 3) +++ branches/rekursor/i386/libsa/libsa.h (revision 4) @@ -30,10 +30,16 @@ #include #include #include +#include /* * string.c */ +static inline int isxdigit(char c) +{ + return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); +} + #ifndef bcopy extern void bcopy(const void * src, void * dst, size_t len); #endif @@ -91,8 +97,9 @@ /* * zalloc.c */ -extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t)); -extern void * malloc(size_t size); +#define MALLOC(size) malloc(size, __FILE__, __LINE__) +extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int)); +extern void * malloc(size_t size,const char *file, int line); extern void free(void * start); extern void * realloc(void * ptr, size_t size); Index: branches/rekursor/i386/libsa/zalloc.c =================================================================== --- branches/rekursor/i386/libsa/zalloc.c (revision 3) +++ branches/rekursor/i386/libsa/zalloc.c (revision 4) @@ -48,7 +48,7 @@ static short availableNodes, allocedNodes, totalNodes; static char * zalloc_base; static char * zalloc_end; -static void (*zerror)(char *, size_t); +static void (*zerror)(char *, size_t, const char *, int); static void zallocate(char * start,int size); static void zinsert(zmem * zp, int ndx); @@ -61,7 +61,7 @@ #define ZALLOC_NODES 16384 -static void malloc_error(char *addr, size_t size) +static void malloc_error(char *addr, size_t size, const char *file, int line) { #ifdef i386 asm volatile ("hlt"); @@ -69,7 +69,7 @@ } // define the block of memory that the allocator will use -void malloc_init(char * start, int size, int nodes, void (*malloc_err_fn)(char *, size_t)) +void malloc_init(char * start, int size, int nodes, void (*malloc_err_fn)(char *, size_t, const char *, int)) { zalloc_base = start ? start : (char *)ZALLOC_ADDR; totalNodes = nodes ? nodes : ZALLOC_NODES; @@ -86,7 +86,7 @@ #define BEST_FIT 1 -void * malloc(size_t size) +void * malloc(size_t size, const char *file, int line) { int i; #if BEST_FIT @@ -104,7 +104,7 @@ size = ((size + 0xf) & ~0xf); if (size == 0) { - if (zerror) (*zerror)((char *)0xdeadbeef, 0); + if (zerror) (*zerror)((char *)0xdeadbeef, 0, file, line); } #if BEST_FIT smallestSize = 0; @@ -155,7 +155,7 @@ done: if ((ret == 0) || (ret + size >= zalloc_end)) { - if (zerror) (*zerror)(ret, size); + if (zerror) (*zerror)(ret, size, file, line); } if (ret != 0) { @@ -204,7 +204,7 @@ } } if ( !found ) { - if (zerror) (*zerror)(pointer, rp); + if (zerror) (*zerror)(pointer, rp, "free", 0); else return; } #if ZDEBUG @@ -232,7 +232,7 @@ if ((start + tsize) < zavailable[i].start) { if (++availableNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 0); + if (zerror) (*zerror)((char *)0xf000f000, 0, "free", 0); } zinsert(zavailable, i); zavailable[i].start = start; @@ -242,7 +242,7 @@ } if (++availableNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 1); + if (zerror) (*zerror)((char *)0xf000f000, 1, "free", 0); } zavailable[i].start = start; zavailable[i].size = tsize; @@ -260,7 +260,7 @@ zalloced[allocedNodes].start = start; zalloced[allocedNodes].size = size; if (++allocedNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 2); + if (zerror) (*zerror)((char *)0xf000f000, 2, "zallocate", 0); }; } @@ -315,7 +315,7 @@ /* This is the simplest way possible. Should fix this. */ void * realloc(void * start, size_t newsize) { - void * newstart = malloc(newsize); + void * newstart = malloc(newsize, __FILE__, __LINE__); bcopy(start, newstart, newsize); free(start); return newstart;