--- nono/vm/human68k.cpp 2026/04/29 17:04:44 1.1.1.5 +++ nono/vm/human68k.cpp 2026/04/29 17:04:50 1.1.1.6 @@ -9,6 +9,7 @@ // #include "human68k.h" +#include "autofd.h" #include "bus.h" #include "iodevstream.h" #include "mainapp.h" @@ -80,7 +81,7 @@ Human68k::Init() putmsg(1, "arg=%s", human68k_arg); // 実行ファイルオープン - int file_fd = open(human68k_file, O_RDONLY); + autofd file_fd = open(human68k_file, O_RDONLY); if (file_fd == -1) { warn("Human68k executable \"%s\" open failed", human68k_file); return false; @@ -89,7 +90,6 @@ Human68k::Init() struct stat st; if (fstat(file_fd, &st) != 0) { warn("Human68k executable \"%s\" fstat failed", human68k_file); - close(file_fd); return false; } uint32 file_size; @@ -100,7 +100,6 @@ Human68k::Init() file = (uint8 *)mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, file_fd, 0); if (file == MAP_FAILED) { warn("Human68k executable \"%s\" mmap failed", human68k_file); - close(file_fd); return false; } @@ -120,21 +119,19 @@ Human68k::Init() warnx("Human68k executable \"%s\" cannot identify file type", human68k_file); munmap(file, file_size); - close(file_fd); return false; } } if (!r) { warnx("Human68k executable \"%s\" invalid file format", human68k_file); munmap(file, file_size); - close(file_fd); return false; } munmap(file, file_size); - close(file_fd); uint32 last_addr = load_addr + load_size + bss_size; + int ram_size = gRAM->GetSize(); IODeviceStream ds(ram); boot_addr = 0x200; @@ -307,7 +304,7 @@ Human68k::LoadZ(uint8 *file, uint size) bool Human68k::LoadMem(uint32 addr, uint8 *src, uint size) { - if (addr + size > ram_size) { + if (addr + size >= gRAM->GetSize()) { errx(EXIT_FAILURE, "file too large"); } @@ -611,7 +608,7 @@ Human68k::FLineOp(m68kcpu *cpu) vecaddr += 0xd000; RegD(0) = m68030_read_32(cpu, vecaddr); m68030_write_32(cpu, vecaddr, addr); - } + } break; }