Skip to content

Commit

Permalink
fix save state fails with large memory size (fix #960)
Browse files Browse the repository at this point in the history
  • Loading branch information
copy committed Dec 9, 2023
1 parent 6110595 commit 8372a0d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ v86util.range = function(size)

v86util.view = function(constructor, memory, offset, length)
{
dbg_assert(offset >= 0);
return new Proxy({},
{
get: function(target, property, receiver)
Expand Down
2 changes: 1 addition & 1 deletion src/vga.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ function VGAScreen(cpu, bus, vga_memory_size)
}


const vga_offset = cpu.svga_allocate_memory(this.vga_memory_size);
const vga_offset = cpu.svga_allocate_memory(this.vga_memory_size) >>> 0;
this.svga_memory = v86util.view(Uint8Array, cpu.wasm_memory, vga_offset, this.vga_memory_size);

this.diff_addr_min = this.vga_memory_size;
Expand Down
63 changes: 35 additions & 28 deletions tests/api/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,43 @@ const config_filesystem = {
log_level: 0,
};

function run_test(name, config, done)
const config_large_memory = {
bios: { url: __dirname + "/../../bios/seabios.bin" },
vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
cdrom: { url: __dirname + "/../../images/linux4.iso", async: true },
autostart: true,
memory_size: 2048 * 1024 * 1024,
vga_memory_size: 512 * 1024 * 1024,
network_relay_url: "<UNUSED>",
disable_jit: +process.env.DISABLE_JIT,
log_level: 0,
};

async function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }

async function run_test(name, config, done)
{
const emulator = new V86(config);

setTimeout(async function()
{
console.log("Saving: %s", name);
const state = await emulator.save_state();

setTimeout(async function()
{
console.log("Restoring: %s", name);
await emulator.restore_state(state);

setTimeout(function()
{
console.log("Done: %s", name);
emulator.stop();
done && done();
}, 1000);
}, 1000);
}, 5000);
await sleep(5000);

console.log("Saving: %s", name);
const state = await emulator.save_state();

await sleep(1000);

console.log("Restoring: %s", name);
await emulator.restore_state(state);

await sleep(1000);

console.log("Done: %s", name);
emulator.stop();
}

run_test("async cdrom", config_async_cdrom, function()
{
run_test("sync cdrom", config_sync_cdrom, function()
{
run_test("filesystem", config_filesystem, function()
{
});
});
});
(async function() {
await run_test("async cdrom", config_async_cdrom);
await run_test("sync cdrom", config_sync_cdrom);
await run_test("filesystem", config_filesystem);
await run_test("large memory size", config_large_memory);
})();

0 comments on commit 8372a0d

Please sign in to comment.