Commit graph

33 commits

Author SHA1 Message Date
刘皓
b55f6dd1f4
Add more error checking to sandbox bindings
* Added checks for when an incorrect number of arguments is passed to a
  function
* Added checks for when an argument of object type has mismatching type
  (arguments of numeric and string types were already checked for type
  mismatches before this commit)
* Added checks for trying to read certain properties of a disposed
  object
2025-08-18 14:04:09 -04:00
刘皓
0d18b9e422
Handle initialize being called multiple times in binding-sandbox/font-binding.cpp 2025-07-01 15:14:41 -04:00
刘皓
6092f4a6fc
Change exception_raise in sandbox bindings to take const Exception & instead of Exception & as argument 2025-06-03 23:11:06 -04:00
刘皓
afb0748ffa
Use a priority deque to allocate object keys/WASI file descriptors 2025-06-03 10:59:30 -04:00
刘皓
56c711f1c1
Move some serialization-related code from binding-util to sandbox-serial-util 2025-05-29 21:06:29 -04:00
刘皓
2896ec5abd
Implement save state serialization for C++ objects owned by the bindings in libretro builds 2025-05-22 12:49:01 -04:00
刘皓
4561a0b0f8
Fix edge case in set_private_data in libretro builds 2025-05-20 19:16:20 -04:00
刘皓
551206e7b4
Don't set private data if an exception has occurred in the bindings 2025-05-20 18:58:44 -04:00
刘皓
cd628048ef
Store destructors in a global table instead of in the object itself in libretro builds 2025-05-19 19:27:30 -04:00
刘皓
16e701fc7c
Rearrange typenums in binding-sandbox/binding-util.h in lexicographic order 2025-05-19 16:19:57 -04:00
刘皓
031245491f
Keep track of all C++ objects allocated by bindings in libretro builds
This commit adds `sb()->create_object()`, `sb()->get_object()`,
`sb()->check_object_type()` and `sb()->destroy_object()` in libretro
builds to keep track of all C++ objects allocated by the bindings in
libretro builds. This has some benefits:

* Any C++ objects allocated by the bindings that are still alive when
  the game terminates can now be deallocated instead of being leaked
  like before.
* We now keep track of the types of all objects allocated by the
  bindings, so we will be able to detect when the bindings attempt to
  access objects of mismatching type.
* Keeping track of all allocated objects is required to implement
  libretro save states.
* Objects are now kept track of using numeric keys whose sizes are the
  same on every platform rather than pointers, which helps with making
  save states portable across platforms.
2025-05-19 14:44:44 -04:00
刘皓
83a6b7a1f1
Re-add missing GFX_LOCK/GFX_UNLOCK calls in binding-sandbox 2025-05-17 19:41:43 -04:00
刘皓
134e08ce6a
Allow the entire codebase to build with -fno-exceptions -fno-rtti in libretro builds 2025-05-16 21:59:54 -04:00
刘皓
3ba12e5672
Fix handling of big-endian platforms in libretro builds
In big-endian libretro builds, the WebAssembly memory is reversed, so no
byte-swapping is required to read from/write to WebAssembly memory
(which is little-endian).

However, that means the ways to get and set values in WebAssembly memory
are endianness-dependent, so I've added the correct such ways for
big-endian platforms.
2025-05-10 18:55:14 -04:00
刘皓
c5747f17c5
Fix minor issues in binding-sandbox/binding-base.h and binding-sandbox/binding-util.h 2025-05-10 09:25:43 -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
刘皓
3e3df818aa
Use C getcwd() instead of Ruby Dir.pwd() to get CWD in libretro builds 2025-05-06 18:02:03 -04:00
刘皓
13c0657691
Handle current working directory properly in libretro builds
Any relative paths that the game tries to access in libretro builds will
now be relative to whatever is the current working directory in the Ruby
sandbox, which will also now be initialized to the game directory during
initialization. Before, all of the bindings that took paths were
hardcoded to prepend the path with the game directory.
2025-05-06 16:55:28 -04:00
刘皓
82b2ad0ef1
Add serializable-binding.h in libretro builds 2025-05-01 13:58:54 -04:00
刘皓
5b94ce4e80
Refactor binding-sandbox header files into .cpp files 2025-04-30 22:31:13 -04:00
刘皓
09bcb1532c
Refactor out the SANDBOX_COROUTINE() macro
Removing this macro allows the correct line numbers to show up in GDB
stack traces.
2025-04-30 19:00:48 -04:00
刘皓
2de7a050db
Use property binding helper macros in libretro builds 2025-04-30 15:47:02 -04:00
刘皓
8182f3591c
Fix typo in wrap_property in libretro binding utils 2025-04-29 00:07:54 -04:00
刘皓
c0b0816b8a
Add wrap_property helper function for bindings in libretro builds 2025-04-28 13:39:06 -04:00
刘皓
c32073d200
Fix memory leak in dfree implementation in libretro builds 2025-04-20 17:48:19 -04:00
刘皓
b3976bf61e
Fix several bugs and missing bindings in libretro builds 2025-04-16 21:57:13 -04:00
刘皓
06819fb9a9
Start implementing VX/VX Ace bindings in libretro builds 2025-04-13 17:30:50 -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
刘皓
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
刘皓
206e8508b6
Replace WABT's WebAssembly runtime with a custom implementation 2025-02-11 20:40:55 -05:00
刘皓
739185594e
Implement more of binding-sandbox 2025-01-22 11:52:10 -05:00
刘皓
4c9e68e066
Convert VALUEs to little-endian before passing to function pointers 2025-01-21 20:14:53 -05:00
刘皓
019812f71e
Start writing class/method stubs for binding-sandbox
I know I've got a long road ahead of me. I'm committing my work so far
for future reference and so that I can check for CI failures.
2025-01-21 12:56:17 -05:00