Commit graph

17 commits

Author SHA1 Message Date
刘皓
09ed08c087
Fix edge case in memory reallocation algorithm in wasm-rt.cpp 2025-05-10 11:09:20 -04:00
刘皓
b8d785b7e1
Implement growing VM memory in libretro builds
The binding coroutines in libretro builds are constructed on the VM
stack, so reallocating the VM memory would corrupt the memory of any
currently existing coroutines.

I've changed it so that the coroutines are no longer constructed on the
VM stack so that they're unaffected by VM memory reallocations, and
added a "slot" mechanism for storing variables on the VM stack. (Any
Ruby `VALUE`s used by a coroutine have to be stored on the VM stack so
that the Ruby garbage collector doesn't free them while they're being
used, which is why the slot mechanism is necessary.)
2025-05-09 22:49:13 -04:00
刘皓
41fc9bf7c7
Pin wasm2c version in libretro builds
To prevent incompatibilities between wasm2c and the custom wasm-rt
implementation.
2025-05-01 00:53:26 -04:00
刘皓
52d65cfe96
Decrease Ruby stack size in libretro builds from 16 MiB to 2 MiB
I highly doubt any game needs that much stack space.
2025-04-21 13:05:17 -04:00
刘皓
de5216c3ce
Implement loading from encrypted game archives in libretro builds 2025-03-30 23:37:19 -04:00
刘皓
6f6d0044ff
Decrease size of Ruby in libretro builds
This decreases the size of the libretro core by around 10% without
having a discernable effect on game compatibility.
2025-03-27 22:00:00 -04:00
刘皓
fac72be163
Fix a second Ruby memory leak
Okay, I think that fixes all the memory leaks. Finally! I'll submit a
pull request to Ruby to fix both of the memory leaks.
2025-03-27 00:28:37 -04:00
刘皓
322d61b604
Allow adjusting Ruby GC parameters in libretro builds
There seems to be a memory leak somewhere. I'm tweaking the GC
parameters to be more conservative to help track down the leak.
2025-03-21 11:56:45 -04:00
刘皓
85025c5f33
Fix Bitmap.blt and Bitmap.stretch_blt in libretro builds
Whoops, I accidentally switched these two functions!
2025-03-20 22:54:31 -04:00
刘皓
7d557354da
Implement flashable and viewport element bindings for libretro builds 2025-03-20 22:38:05 -04:00
刘皓
eeef9ff943
Don't make sandbox_malloc into a coroutine
Okay, the coroutine implementation of `sandbox_malloc` is clearly
broken. It would be working if Asyncify instrumented the `memory.grow`
WebAssembly instruction, but it doesn't instrument it.

This commit reverts commit 42c4ff9497 and
also increases the default VM memory allocation from 64 MiB to 96 MiB to
account for the lack of ability to increase the memory allocation at run
time. I'll find some new way to implement increasing the memory
allocation later.
2025-03-18 13:49:41 -04:00
刘皓
b68dae451d
Zero out memory allocated by wasm-rt
In release 1.0 of the WebAssembly Specification, it says that all the
bytes in WebAssembly memory need to be initialized to 0 on creation of
the memory, and when memory is grown, the new bytes also need to be
initialized to 0.

It seems this zeroing behaviour is indeed required for the sandbox to
operate correctly. Not zeroing leads to undefined behaviour. This
manifested as a crash that occurred when restarting the libretro core,
but for some reason, only on Emscripten. Not sure why this didn't happen
on other platforms. Even sanitizers weren't able to detect the bug!

(cherry picked from commit edf061e323b8f0ab0c6a72c76ae7ccc07a1649c0)
2025-03-02 14:05:49 -05:00
刘皓
42c4ff9497
Make sandbox_malloc into a coroutine
According to AddressSanitizer, when `sandbox_malloc` causes the
WebAssembly memory to grow in size, every single coroutine on the
sandbox stack gets corrupted. So if `sandbox_malloc` is going to cause
the memory to grow in size, we need to yield so that there are no
coroutines on the sandbox stack while the reallocation occurs.
2025-02-17 00:38:40 -05:00
刘皓
58cf92e482
Fix memory corruption in wasm-rt found by AddressSanitizer 2025-02-16 17:52:41 -05:00
刘皓
5e93e5e834
Mark wasm_rt_trap as noreturn 2025-02-16 01:26:16 -05:00
刘皓
865285db51
Change the name of the PAGE_SIZE macro 2025-02-13 15:20:18 -05:00
刘皓
206e8508b6
Replace WABT's WebAssembly runtime with a custom implementation 2025-02-11 20:40:55 -05:00