@aptre/v86 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/v86.browser.js +48 -19
- package/dist/v86.browser.js.map +2 -2
- package/dist/v86.js +48 -19
- package/dist/v86.js.map +2 -2
- package/package.json +1 -1
- package/src/browser/starter.ts +47 -3
- package/src/cpu.ts +16 -32
package/dist/v86.js
CHANGED
|
@@ -19300,26 +19300,24 @@ var CPU = class {
|
|
|
19300
19300
|
);
|
|
19301
19301
|
}
|
|
19302
19302
|
resize_memory(new_size) {
|
|
19303
|
-
const
|
|
19304
|
-
const
|
|
19305
|
-
const
|
|
19306
|
-
if (
|
|
19307
|
-
const
|
|
19308
|
-
|
|
19309
|
-
|
|
19310
|
-
|
|
19311
|
-
|
|
19312
|
-
this.mem8 = view(Uint8Array, this.wasm_memory, mem8_offset, new_size);
|
|
19313
|
-
this.mem32s = view(
|
|
19314
|
-
Int32Array,
|
|
19315
|
-
this.wasm_memory,
|
|
19316
|
-
mem8_offset,
|
|
19317
|
-
new_size >> 2
|
|
19318
|
-
);
|
|
19303
|
+
const offset = this.mem8.byteOffset;
|
|
19304
|
+
const needed = offset + new_size;
|
|
19305
|
+
const current = this.wasm_memory.buffer.byteLength;
|
|
19306
|
+
if (needed > current) {
|
|
19307
|
+
const pages = Math.ceil((needed - current) / WASM_PAGE_SIZE);
|
|
19308
|
+
this.wasm_memory.grow(pages);
|
|
19309
|
+
}
|
|
19310
|
+
this.mem8 = view(Uint8Array, this.wasm_memory, offset, new_size);
|
|
19311
|
+
this.mem32s = view(Uint32Array, this.wasm_memory, offset, new_size >> 2);
|
|
19319
19312
|
this.memory_size[0] = new_size;
|
|
19320
19313
|
}
|
|
19321
19314
|
set_state(state) {
|
|
19322
|
-
|
|
19315
|
+
const saved_memory_size = state[0];
|
|
19316
|
+
if (saved_memory_size > this.memory_size[0]) {
|
|
19317
|
+
this.resize_memory(saved_memory_size);
|
|
19318
|
+
} else {
|
|
19319
|
+
this.memory_size[0] = saved_memory_size;
|
|
19320
|
+
}
|
|
19323
19321
|
if (this.mem8.length !== this.memory_size[0]) {
|
|
19324
19322
|
console.warn(
|
|
19325
19323
|
"Note: Memory size mismatch. we=" + this.mem8.length + " state=" + this.memory_size[0]
|
|
@@ -26174,12 +26172,24 @@ var V86 = class {
|
|
|
26174
26172
|
this.bus = bus[0];
|
|
26175
26173
|
this.emulator_bus = bus[1];
|
|
26176
26174
|
let cpu;
|
|
26177
|
-
|
|
26175
|
+
const memory_size = options.memory_size || 64 * 1024 * 1024;
|
|
26176
|
+
const vga_memory_size = options.vga_memory_size || 8 * 1024 * 1024;
|
|
26177
|
+
const memory_max = options.memory_max || (memory_size + vga_memory_size) * 4;
|
|
26178
|
+
const wasm_initial_pages = 256;
|
|
26179
|
+
const wasm_max_pages = Math.max(
|
|
26180
|
+
wasm_initial_pages,
|
|
26181
|
+
Math.min(Math.ceil(memory_max / WASM_PAGE_SIZE), 65536)
|
|
26182
|
+
);
|
|
26183
|
+
const wasm_memory = new WebAssembly.Memory({
|
|
26184
|
+
initial: wasm_initial_pages,
|
|
26185
|
+
maximum: wasm_max_pages
|
|
26186
|
+
});
|
|
26178
26187
|
const wasm_table = new WebAssembly.Table({
|
|
26179
26188
|
element: "anyfunc",
|
|
26180
26189
|
initial: WASM_TABLE_SIZE + WASM_TABLE_OFFSET
|
|
26181
26190
|
});
|
|
26182
26191
|
const wasm_shared_funcs = {
|
|
26192
|
+
memory: wasm_memory,
|
|
26183
26193
|
cpu_exception_hook: (n) => this.cpu_exception_hook(n),
|
|
26184
26194
|
run_hardware_timers: function(a, t) {
|
|
26185
26195
|
return cpu.run_hardware_timers(a, t);
|
|
@@ -26314,7 +26324,6 @@ var V86 = class {
|
|
|
26314
26324
|
};
|
|
26315
26325
|
}
|
|
26316
26326
|
wasm_fn({ env: wasm_shared_funcs }).then((exports) => {
|
|
26317
|
-
wasm_memory = exports.memory;
|
|
26318
26327
|
exports["rust_init"]();
|
|
26319
26328
|
const emulator = this.v86 = new v86(this.emulator_bus, {
|
|
26320
26329
|
exports,
|
|
@@ -26841,6 +26850,26 @@ var V86 = class {
|
|
|
26841
26850
|
async run() {
|
|
26842
26851
|
this.v86.run();
|
|
26843
26852
|
}
|
|
26853
|
+
/**
|
|
26854
|
+
* Grow guest memory to the specified size in bytes. Stops the VM,
|
|
26855
|
+
* grows WASM linear memory, updates memory_size, clears the TLB,
|
|
26856
|
+
* and resumes execution.
|
|
26857
|
+
*/
|
|
26858
|
+
async growMemory(newSizeBytes) {
|
|
26859
|
+
const cpu = this.v86.cpu;
|
|
26860
|
+
if (newSizeBytes <= cpu.memory_size[0]) {
|
|
26861
|
+
return;
|
|
26862
|
+
}
|
|
26863
|
+
const wasRunning = this.cpu_is_running;
|
|
26864
|
+
if (wasRunning) {
|
|
26865
|
+
await this.stop();
|
|
26866
|
+
}
|
|
26867
|
+
cpu.resize_memory(newSizeBytes);
|
|
26868
|
+
cpu.full_clear_tlb();
|
|
26869
|
+
if (wasRunning) {
|
|
26870
|
+
await this.run();
|
|
26871
|
+
}
|
|
26872
|
+
}
|
|
26844
26873
|
/**
|
|
26845
26874
|
* Stop emulation. Do nothing if emulator is not running. Can be asynchronous.
|
|
26846
26875
|
*/
|