--- nono/vm/ram.cpp 2026/04/29 17:04:32 1.1.1.2 +++ nono/vm/ram.cpp 2026/04/29 17:04:36 1.1.1.3 @@ -1,6 +1,7 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // #include "ram.h" @@ -41,13 +42,18 @@ RAMDevice::~RAMDevice() bool RAMDevice::Init() { - // とりあえず。実際は設定ファイルから - if (gMainApp.GetVMType() == VMTYPE_LUNA || - gMainApp.GetVMType() == VMTYPE_LUNA88K) { - ram_size = 16 * 1024 * 1024; - } else { - ram_size = 12 * 1024 * 1024; + const ConfigItem& item = gConfig->Find("ram-size"); // [MB] + ram_size = item.AsInt(); + // XXX 上限は適当。 + // LUNA は空間は 1024MB 分あるが末尾に Null と BusErr 領域が必要なはずで + // メモリの上限は 1023MB くらいのはず。 + if (ram_size < 1 || ram_size > 1023) { + item.Err(); + return false; } + + // MB 表記をバイト単位にしてから確保 + ram_size = ram_size * 1024 * 1024; ram.reset(new uint8[ram_size]); return true; @@ -175,7 +181,7 @@ RAMDevice::LoadGzFile(const char *filepa int rv; // gzip なら(?) ファイルの末尾4バイトが (LE で?) 展開後サイズ(?)。 - decompsize = le32toh(*(uint32 *)&infile[infilesize - 4]); + decompsize = le32toh(*(const uint32 *)&infile[infilesize - 4]); std::unique_ptr dstbuf(new uint8[decompsize]); // gzip 展開 @@ -189,7 +195,7 @@ RAMDevice::LoadGzFile(const char *filepa return 0; } - z.next_in = (Bytef *)infile; + z.next_in = const_cast(infile); z.avail_in = infilesize - 4; z.next_out = dstbuf.get(); z.avail_out = decompsize; @@ -218,8 +224,8 @@ RAMDevice::LoadFile(const char *name, co uint32 entry = 0; // フォーマットだけ判定して分岐 - Elf32_Ehdr *ehdr = (Elf32_Ehdr *)file; - aout_header *aout = (aout_header *)file; + const Elf32_Ehdr *ehdr = (const Elf32_Ehdr *)file; + const aout_header *aout = (const aout_header *)file; if (memcmp(ehdr->e_ident, "\177ELF", 4) == 0) { entry = Load_elf32(name, file, filesize, target_mid); } else if ((be32toh(aout->magic) & 0xffff) == AOUT_OMAGIC) { @@ -247,14 +253,14 @@ RAMDevice::Load_aout(const char *name, c // ヘッダを読み込む // BigEndian しかターゲットにしてないので最初から全部変換しとく - aout.magic = be32toh(((aout_header *)file)->magic); - aout.textsize = be32toh(((aout_header *)file)->textsize); - aout.datasize = be32toh(((aout_header *)file)->datasize); - aout.bsssize = be32toh(((aout_header *)file)->bsssize); - aout.symsize = be32toh(((aout_header *)file)->symsize); - aout.entry = be32toh(((aout_header *)file)->entry); - aout.textrelsize = be32toh(((aout_header *)file)->textrelsize); - aout.datarelsize = be32toh(((aout_header *)file)->datarelsize); + aout.magic = be32toh(((const aout_header *)file)->magic); + aout.textsize = be32toh(((const aout_header *)file)->textsize); + aout.datasize = be32toh(((const aout_header *)file)->datasize); + aout.bsssize = be32toh(((const aout_header *)file)->bsssize); + aout.symsize = be32toh(((const aout_header *)file)->symsize); + aout.entry = be32toh(((const aout_header *)file)->entry); + aout.textrelsize = be32toh(((const aout_header *)file)->textrelsize); + aout.datarelsize = be32toh(((const aout_header *)file)->datarelsize); // マジックをチェック uint32 mid = AOUT_MID(aout.magic); @@ -402,6 +408,10 @@ RAMDevice::Load_elf32(const char *name, for (; i < p_memsz; i++) { ds.Write8(0); } + } else if (p_type == 0x65a3dbe6) { // PT_OPENBSD_RANDOMIZE + // XXX どうする? + continue; + } else { warnx("Load_elf32 \"%s\" p_type %d not supported", name, p_type); return 0;