fwsGonzo / libriscv

The fastest RISC-V sandbox
BSD 3-Clause "New" or "Revised" License
522 stars 46 forks source link

Allow loading binary translation DLLs on Windows #136

Closed fwsGonzo closed 1 month ago

fwsGonzo commented 1 month ago

Even though most people don't have compilers on Windows, games are packaged, and the script is already precompiled. So, why not just create a MinGW .dll as part of that process, and then allow loading it on Windows?

Binary translated libriscv is stupidly fast. It's going to be worth it.

$ wine64 rvlinux.exe ../../binaries/measure_mips/fib
0034:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
0034:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
005c:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
005c:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
0064:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
0064:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
006c:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
006c:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
002c:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
002c:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
00bc:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
00bc:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
>>> Program exited, exit code = 3819729467 (0xE3AC723B)
Instructions executed: 1280000008  Runtime: 70.346ms  Insn/s: 18196mi/s
Pages in use: 4 (16 kB virtual memory, total 38 kB)

Preliminary results show that it works just fine.

$ strings rvbintr-E3BDE914.dll | grep -i '\.dll$'
KERNEL32.dll
msvcrt.dll

Minimal dependencies.

fwsGonzo commented 1 month ago

The latest PR https://github.com/fwsGonzo/libriscv/pull/138 fixes a few things, now making it possible to run binary translated libriscv on Windows. In order to close this issue though, this feature should also work on Windows builds of my game. In order to test, I should create a mingw .dll on the server, place it in the Windows build folder and monitor that it gets loaded on the Windows client. If the client runs normally, I will consider it solved.

fwsGonzo commented 1 month ago

Can conform that it's working on a highly complex game and game server, where one client is running Windows with ~10-12 binary translated libriscv programs running in various threads. The first time I tried it my desktop froze and I had to reboot, but it hasn't happened since. I tried putting a mutex on the emulated dlopen() stuff - but I can only wait and see if it happens again.

For now, I consider this first attempt as a success. My game runs in Steam, wine + wine64 and several other programs run on the terminal using wine.