void DebugFree(void * blk) { Memory * Block; if(lout_memory==NULL) ErrorInternal("Free:Кучи еще нет!"); if(blk==NULL) ErrorInternal("Попытка освободить память до ее размещения !"); if((Block=FindMem(blk))==NULL) { //ErrorInternal("Освобождаемая память не найдена !"); return; } //освобождение блока Block->id=MEMFREE; SizeFree+=Block->size; #ifdef DebugFile if(FileError){ fprintf(FileError,"\nFree \t= %8li\tRunning \t= %li\tAll %li", (long)Block->size, SizeAllocate-SizeFree, SizeMemory); } #endif }
void * DebugRealloc(void * old_blk,size_t size) { void * new_blk; Memory * Block; if(lout_memory==NULL) ErrorInternal("Realloc:Кучи еще нет!"); if(size == 0) return NULL; if(old_blk==NULL){ new_blk=DebugMalloc(size); return new_blk; } if((Block=FindMem(old_blk))==NULL) ErrorInternal("\nИсходный буфер для REALLOC не найден!"); if(Block->size <= size + sizeof(Memory)){ // требуется блок больших размеров new_blk=DebugMalloc(size); if(new_blk!=NULL && old_blk!=NULL) memcpy(new_blk,old_blk,(Block->size<=size ? Block->size:size)); if(old_blk!=NULL) DebugFree(old_blk); } else { // требуется блок меньших размеров Memory * NewBlock = (Memory *)((char *)Block + size + sizeof(Memory)); NewBlock->id = MEMFREE; NewBlock->size= Block->size-(size+sizeof(Memory)); SizeFree += NewBlock->size; Block->size = size; new_blk = old_blk; #ifdef DebugFile if(FileError){ fprintf(FileError,"\nRealloc \t= %8li\tRunning \t= %li\tAll %li", (long)Block->size, SizeAllocate-SizeFree, SizeMemory); } #endif } return new_blk; }
static UINTN detect_bootcode(UINT64 partlba, CHARN **bootcodename) { UINTN status; BOOLEAN bootable; // read MBR data status = read_sector(partlba, sector); if (status != 0) return status; // check bootable signature if (*((UINT16 *)(sector + 510)) == 0xaa55 && sector[0] != 0) bootable = TRUE; else bootable = FALSE; *bootcodename = NULL; // detect specific boot codes if (CompareMem(sector + 2, "LILO", 4) == 0 || CompareMem(sector + 6, "LILO", 4) == 0) { *bootcodename = STR("LILO"); } else if (CompareMem(sector + 3, "SYSLINUX", 8) == 0) { *bootcodename = STR("SYSLINUX"); } else if (FindMem(sector, 512, "ISOLINUX", 8) >= 0) { *bootcodename = STR("ISOLINUX"); } else if (FindMem(sector, 512, "Geom\0Hard Disk\0Read\0 Error\0", 27) >= 0) { *bootcodename = STR("GRUB"); } else if ((*((UINT32 *)(sector + 502)) == 0 && *((UINT32 *)(sector + 506)) == 50000 && *((UINT16 *)(sector + 510)) == 0xaa55) || FindMem(sector, 512, "Starting the BTX loader", 23) >= 0) { *bootcodename = STR("FreeBSD"); } else if (FindMem(sector, 512, "!Loading", 8) >= 0 || FindMem(sector, 512, "/cdboot\0/CDBOOT\0", 16) >= 0) { *bootcodename = STR("OpenBSD"); } else if (FindMem(sector, 512, "Not a bootxx image", 18) >= 0) { *bootcodename = STR("NetBSD"); } else if (FindMem(sector, 512, "NTLDR", 5) >= 0) { *bootcodename = STR("Windows NTLDR"); } else if (FindMem(sector, 512, "BOOTMGR", 7) >= 0) { *bootcodename = STR("Windows BOOTMGR (Vista)"); } else if (FindMem(sector, 512, "CPUBOOT SYS", 11) >= 0 || FindMem(sector, 512, "KERNEL SYS", 11) >= 0) { *bootcodename = STR("FreeDOS"); } else if (FindMem(sector, 512, "OS2LDR", 6) >= 0 || FindMem(sector, 512, "OS2BOOT", 7) >= 0) { *bootcodename = STR("eComStation"); } else if (FindMem(sector, 512, "Be Boot Loader", 14) >= 0) { *bootcodename = STR("BeOS"); } else if (FindMem(sector, 512, "yT Boot Loader", 14) >= 0) { *bootcodename = STR("ZETA"); } else if (FindMem(sector, 512, "\x04" "beos\x06" "system\x05" "zbeos", 18) >= 0) { *bootcodename = STR("Haiku"); } if (FindMem(sector, 512, "Non-system disk", 15) >= 0) // dummy FAT boot sector *bootcodename = STR("None (Non-system disk message)"); // TODO: Add a note if a specific code was detected, but the sector is not bootable? if (*bootcodename == NULL) { if (bootable) *bootcodename = STR("Unknown, but bootable"); else *bootcodename = STR("None"); } return 0; }