Thursday, December 08, 2022

Re: desmume, any special reqs to run it?

Index: Makefile
===================================================================
RCS file: /cvs/ports/emulators/desmume/Makefile,v
retrieving revision 1.30
diff -u -p -u -p -r1.30 Makefile
--- Makefile 31 Mar 2022 17:12:50 -0000 1.30
+++ Makefile 9 Dec 2022 02:29:32 -0000
@@ -3,7 +3,7 @@ USE_WXNEEDED = Yes
COMMENT = Nintendo DS emulator

DISTNAME = desmume-0.9.11
-REVISION = 10
+REVISION = 11

CATEGORIES = emulators

@@ -44,6 +44,7 @@ COMPILER = base-clang ports-gcc
CONFIGURE_STYLE = gnu
FIX_CRLF_FILES = src/MMU_timing.h \
src/path.h \
+ src/arm_jit.cpp \
src/utils/AsmJit/core/stringbuilder.h

.include <bsd.port.mk>
Index: patches/patch-src_arm_jit_cpp
===================================================================
RCS file: patches/patch-src_arm_jit_cpp
diff -N patches/patch-src_arm_jit_cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_arm_jit_cpp 9 Dec 2022 02:29:32 -0000
@@ -0,0 +1,18 @@
+BSS is immutable so mark it as mutable so that mprotect RWX works
+
+see: mimmutable(1)
+https://github.com/google/syzkaller/commit/bc009f82ea71c399f19eef28f115ff5cda7be4ba
+
+Index: src/arm_jit.cpp
+--- src/arm_jit.cpp.orig
++++ src/arm_jit.cpp
+@@ -198,7 +198,8 @@ static u8 recompile_counts[(1<<26)/16];
+ // Reduces memory needed for function pointers.
+ // FIXME win64 needs this too, x86_32 doesn't
+
+-DS_ALIGN(4096) static u8 scratchpad[1<<25];
++DS_ALIGN(4096) static u8 scratchpad[1<<25]
++ __attribute__((section(".openbsd.mutable")));
+ static u8 *scratchptr;
+
+ struct ASMJIT_API StaticCodeGenerator : public Context
Index: patches/patch-src_path_h
===================================================================
RCS file: /cvs/ports/emulators/desmume/patches/patch-src_path_h,v
retrieving revision 1.3
diff -u -p -u -p -r1.3 patch-src_path_h
--- patches/patch-src_path_h 11 Mar 2022 18:59:34 -0000 1.3
+++ patches/patch-src_path_h 9 Dec 2022 02:29:32 -0000
@@ -3,7 +3,7 @@ From upstream 8454c93fa37ce9f3c8becc7004
Index: src/path.h
--- src/path.h.orig
+++ src/path.h
-@@ -375,7 +375,7 @@ class PathInfo (public)
+@@ -375,7 +375,7 @@ class PathInfo (public)
else if (strchr(strftimeArgs, *p))
{
char tmp[MAX_PATH];
Mike Larkin writes:

> On Sun, Dec 04, 2022 at 05:30:47PM -0700, Anthony J. Bentley wrote:
>> Mikolaj Kucharski writes:
>> > I just wanted to see how Nintendo 3DS emulators work on OpenBSD. Never
>> > played with them before.
>> >
>> > $ desmume some-game-decrypted.3ds
>> > mprotect failed: Operation not permitted
>> > Abort trap (core dumped)
>> >
>> > I tried with few 3DS files and one CIA file, always the same output
>> > like above. Any tips?
>>
>> desmume is a DS emulator, not a 3DS emulator. It doesn't support 3DS
>> files or CIA files.
>>
>> (citra is a 3DS emulator and should be able to handle those files.)
>>
>> That said, desmume shouldn't crash like that. I'll look into it.
>>
>
> My money's on wxallowed :)
>
> -ml

Here is a diff unbreaking desmume. I am attaching it because it contains
^M being removed from an existing patch.

I came across this same issue with my WIP-port of flycast. It has to be
adapted for immutable userland mappings in 7.2 -current.

Globals are in BSS and are immutable by default. They need to be marked
as mutable in order for mprotect RWX to work.

I took this fix from syzkaller. see:
https://github.com/google/syzkaller/commit/bc009f82ea71c399f19eef28f115ff5cda7be4ba

flycast had to be patched in three places. see:
https://www.namtsui.com/cgi-bin/cvsweb/ports/emulators/flycast/patches/patch-core_hw_aica_dsp_x64_cpp?rev=1.6&content-type=text/x-cvsweb-markup
https://www.namtsui.com/cgi-bin/cvsweb/ports/emulators/flycast/patches/patch-core_hw_arm7_arm7_rec_cpp?rev=1.6&content-type=text/x-cvsweb-markup
https://www.namtsui.com/cgi-bin/cvsweb/ports/emulators/flycast/patches/patch-core_hw_sh4_dyna_driver_cpp?rev=1.6&content-type=text/x-cvsweb-markup

This unbreaks the emulator with my testing of Chrono Trigger.

Feedback and tests are welcome. OK?

No comments:

Post a Comment