Commit graph

24 commits

Author SHA1 Message Date
刘皓
c802e24f1b
Fix WASI file descriptor deserialization bugs in libretro builds 2025-05-28 17:07:22 -04:00
刘皓
1f5d90822c
Remove designated initializers
Apparently these are not valid until C++20.
2025-05-27 21:28:29 -04:00
刘皓
8ca753d85d
Continue implementing save state deserialization in libretro builds 2025-05-27 16:59:41 -04:00
刘皓
e957af931c
Implement save state serialization for WASI file descriptors in libretro builds 2025-05-23 23:59:29 -04:00
刘皓
28fb36af98
Capitalize /Dist, /Game, /Save and /System in libretro builds for consistency 2025-05-13 17:53:59 -04:00
刘皓
d62d6aef3e
Remove WASI_DEBUG macro 2025-05-12 13:50:48 -04:00
刘皓
67e61917a7
Apply big-endian fixes to binding-sandbox/wasi.cpp as well 2025-05-12 12:39:08 -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
刘皓
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
刘皓
d71cd242c7
Improve save directory creation algorithm in libretro builds
Before, if the game tried to create a save file, missing parent
directories would always be created because they could possibly exist
only in the game directory and not in the save directory, and we
wouldn't know due to the union mounting of the save and game
directories. But this is inconsistent with the behaviour of file
creation, where it should fail if parent directories don't exist.

The behaviour has been changed to only create parent directories if the
parent directories already exist. I know that sounds strange, but if the
parent directories exist, it could be that they only exist in the game
directory but not the save directory due to the union mounting, so we
need to create the parent directories, which will be created in the save
directory due to it being set as the write directory in PhysFS.
2025-05-07 22:13:45 -04:00
刘皓
c85e9554ec
Implement writing to filesystem (i.e. game saving) in libretro builds
Files are written to the libretro save directory, which is mounted at
/save in PhysFS. All filesystem calls made from Ruby in libretro builds
are routed through PhysFS, so the game can just use any ordinary
filesystem function provided by Ruby to interact with /save.

It's also union mounted on top of the game directory (located at /game
in PhysFS) so that games that write their save files to the current
working directory will have their save files saved to the libretro save
directory instead of the game directory.

For security and portability reasons, nothing outside of the libretro
save directory can be written to, and nothing outside of the libretro
save directory, the libretro game directory and the various embedded
files used by the runtime can be read from.
2025-05-07 16:01:41 -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
刘皓
0d07aff3e2
Remove exceptions from the sandbox implementation in libretro builds 2025-04-25 13:31:32 -04:00
刘皓
dcd29f44a9
Remove dependency on libzip in libretro builds 2025-03-31 13:26:54 -04:00
刘皓
f3419a9c16
Merge branch 'libretro-compat' into libretro 2025-03-03 12:08:13 -05:00
刘皓
eac2b76f64
Don't use preferred path separator in wasi.cpp 2025-03-03 11:21:47 -05:00
刘皓
66152bf5c5
Merge branch 'libretro-compat' into libretro 2025-02-27 23:34:08 -05:00
刘皓
20f806abef
Remove dependency on xxd 2025-02-27 23:32:30 -05:00
刘皓
7c5ae9a8e5
Start integrating libretro OpenGL graphics 2025-02-18 14:05:14 -05:00
刘皓
decb4236bd
Fix use after free in wasi.cpp found by AddressSanitizer 2025-02-17 00:07:54 -05:00
刘皓
37a7559e38
Remove dependency on ghc::filesystem in libretro builds 2025-02-01 13:03:13 -05:00
刘皓
c42949713d
Start integrating the audio code into libretro builds 2025-01-27 00:34:52 -05:00
刘皓
84ca884f84
Reimplement WASI filesystem on top of existing mkxp-z filesystem implementation
This allows more flexibility when loading games in libretro builds,
since we can now load games either from a directory or from a ZIP or 7Z
archive. Also, the path cache is now active for all filesystem calls
made from inside Ruby.
2025-01-25 22:03:52 -05:00
刘皓
510f1b0211
Move sandbox files to binding-sandbox directory 2025-01-16 22:16:14 -05:00
Renamed from src/sandbox/wasi.cpp (Browse further)