libretro / flycast

Flycast is a multiplatform Sega Dreamcast emulator. NOTE: No longer actively developed, use upstream repo for libretro from now on - https://github.com/flyinghead/flycast
http://reicast.com
GNU General Public License v2.0
155 stars 77 forks source link

Segmentation Fault with every game since updating #451

Open sxales opened 5 years ago

sxales commented 5 years ago

I update yesterday for XU4.

Here is the log when trying to run dolphin.zip https://pastebin.com/VCKkrX2x Just in case it was an issue with the rom or bios I ran for a previously working rom of Crazy Taxi for dreamcast https://pastebin.com/F9kZg1Ys

I removed the naomi_boot.bin and dc_nvmem.bin based on #434 but no dice.

sxales commented 5 years ago

I've traced this further. The last working binary for xu4 was dated 10-26 with the subsequent on 11-18 showing the same error.

Perhaps there was some change in the required files or behavior between those dates? Possibly something to do with how naomi bios is loaded (although the fault does occur on dreamcast games as well)

barbudreadmon commented 5 years ago

The last working binary for xu4

Come back after confirming the issue while building from latest sources using make platform=odroid please, there might be issues in how retropie built its binaries, and this is not the concern of lr-reicast.

sxales commented 5 years ago

I did that originally. Building from source is not working either.

blisstik commented 5 years ago

Are you using the RetroArena image?

sxales commented 5 years ago

Are you using the RetroArena image?

@6alileo Yes

sxales commented 5 years ago

I am still thinking this issue is related to the addition of MAME compatibility; probably a change in the configurations, external files required, or an undeclared dependency.

ccontino84 commented 5 years ago

I have the very same issue on my machine after I updated the core (before I was running an old OIT version). This is the log produced by retroarch -v:

Initializing VMU data... Initializing VMU data... Initializing VMU data... Initializing VMU data... SIGSEGV @ 0x7ff7be3f8c42 ... 0x7ff753d00000 -> was not in vram (dyna code 0) [libretro INFO] Fatal error : segfault in signal_handler -> core/libretro/common.cpp : 398 DEBUGBREAK! SIGSEGV @ 0x7ff74f2f4970 ... 0x7ff74f2f4970 -> was not in vram (dyna code 0) [libretro INFO] Fatal error : segfault in signal_handler -> core/libretro/common.cpp : 398 DEBUGBREAK!

I already bisected the code and I can confirm that the issue started on 25th October after this commit a2214fc7735bf7750fd83c3c64055b127db195bf

flyinghead commented 5 years ago

What platform are you on?

Please make sure that both RA and reicast are up to date

ccontino84 commented 5 years ago

I'm on a PC with ArchLinux and Retroarch 1.7.6. If I update the core from the "Online Updater" I get the segfault.

flyinghead commented 5 years ago

Can you build the core with DEBUG=1 (or add the -g option) so we can get a stack trace with symbols? Let me known if you need guidance.

ccontino84 commented 5 years ago

Yes, sure! Here is the gdb log with debug enabled:

Thread 32 "retroarch" received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7fffaa5fd700 (LWP 11593)] bm_GetCode (addr=2684354560) at core/hw/sh4/dyna/blockmanager.cpp:47 47 DynarecCodeEntryPtr rv=(DynarecCodeEntryPtr)FPCA(addr); (gdb) bt

0 bm_GetCode (addr=2684354560) at core/hw/sh4/dyna/blockmanager.cpp:47

1 0x00007fffd538e589 in ngen_mainloop (v_cntx=0x7fffd538e589 <ngen_mainloop(void*)+64>) at core/rec-x64/rec_x64.cpp:147

2 0x0000000000000000 in ?? ()

flyinghead commented 5 years ago

This is a normal SIGSEGV. Type the following gdb command before running RA: handle SIGSEGV nostop noprint

ccontino84 commented 5 years ago

Here we go:

Initializing VMU data...
Initializing VMU data...
Initializing VMU data...
Initializing VMU data...
[New Thread 0x7fffaa5fd700 (LWP 4450)]
SIGSEGV @ 0x7fffd63c08d3 ... 0x7fff63d00000 -> was not in vram (dyna code 0)
[libretro INFO] Fatal error : segfault
 in signal_handler -> core/libretro/common.cpp : 398 
DEBUGBREAK!

Thread 32 "retroarch" received signal SIGILL, Illegal instruction.
[Switching to Thread 0x7fffaa5fd700 (LWP 4450)]
os_DebugBreak () at core/libretro/libretro.cpp:2700
2700       __builtin_trap();
(gdb) bt
#0  os_DebugBreak () at core/libretro/libretro.cpp:2700
#1  0x00007fff5f2c1808 in signal_handler (sn=11, si=0x7fffaa5fc630, segfault_ctx=0x7fffaa5fc500)
    at core/libretro/common.cpp:398
#2  <signal handler called>
#3  bm_GetCode (addr=2684354560) at core/hw/sh4/dyna/blockmanager.cpp:47
#4  0x00007fffd538e589 in ngen_mainloop (v_cntx=0x7fffd538e589 <ngen_mainloop(void*)+64>) at core/rec-x64/rec_x64.cpp:147
#5  0x0000000000000000 in ?? ()
(gdb) continue
Continuing.
SIGSEGV @ 0x7fff5f2c0a01 ... 0x7fff5f2c0a01 -> was not in vram (dyna code 0)
[libretro INFO] Fatal error : segfault
 in signal_handler -> core/libretro/common.cpp : 398 
DEBUGBREAK!

Thread 32 "retroarch" received signal SIGILL, Illegal instruction.
os_DebugBreak () at core/libretro/libretro.cpp:2700
2700       __builtin_trap();
(gdb) bt
#0  os_DebugBreak () at core/libretro/libretro.cpp:2700
#1  0x00007fff5f2c1808 in signal_handler (sn=4, si=0x7fffaa5fc030, segfault_ctx=0x7fffaa5fbf00)
    at core/libretro/common.cpp:398
#2  <signal handler called>
#3  os_DebugBreak () at core/libretro/libretro.cpp:2700
#4  0x00007fff5f2c1808 in signal_handler (sn=11, si=0x7fffaa5fc630, segfault_ctx=0x7fffaa5fc500)
    at core/libretro/common.cpp:398
#5  <signal handler called>
#6  bm_GetCode (addr=2684354560) at core/hw/sh4/dyna/blockmanager.cpp:47
#7  0x00007fffd538e589 in ngen_mainloop (v_cntx=0x7fffd538e589 <ngen_mainloop(void*)+64>) at core/rec-x64/rec_x64.cpp:147
#8  0x0000000000000000 in ?? ()
flyinghead commented 5 years ago

In the file core/hw/mem/_vmem.cpp, please uncomment line 683: printf("Allocated %d PAGES [%08X]\n",++pagecnt,addr); and rerun with gdb

ccontino84 commented 5 years ago

Unfortunately the change didn't have any effect, the string is not printed in the log and everything looks the same as before. EDIT: I made an interesting discovery. I don't get segfault if I use the same core with retroarch installed via snap. Could be something wrong in the Arch binary package? Strange because it was working fine with the old version of the core.

flyinghead commented 5 years ago

It could very well have to do with how RA is built for Arch. However I don't know what could cause this. It looks like reicast is not using virtual memory or something is wrong in this area. There are some compile flags (TARGET_NO_VMEM) but I assume you don't use any special flag except for debug mode. Can you paste a full log of a (crashing) run? In your previous posts the beginning of the log is missing. That's where the vmem is initialized.

ccontino84 commented 5 years ago

For the test I'm up-to-date with master and changed only the DEBUG flag in Makefile:

$ git diff
diff --git a/Makefile b/Makefile
index db13ab8e..66d5d664 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-DEBUG         := 0
+DEBUG         := 1
 NO_REND       := 0
 HAVE_GL       := 1
 HAVE_GL2      := 0
diff --git a/core/hw/mem/_vmem.cpp b/core/hw/mem/_vmem.cpp
index 32e58468..b403b2d1 100644
--- a/core/hw/mem/_vmem.cpp
+++ b/core/hw/mem/_vmem.cpp
@@ -680,7 +680,7 @@ bool BM_LockedWrite(u8* address)

        if (addr<sizeof(p_sh4rcb->fpcb))
        {
-               //printf("Allocated %d PAGES [%08X]\n",++pagecnt,addr);
+               printf("Allocated %d PAGES [%08X]\n",++pagecnt,addr);

 #ifdef _WIN32
       verify(VirtualAlloc(address,PAGE_SIZE,MEM_COMMIT,PAGE_READWRITE));

Full log here: https://hastebin.com/onufigufot.cs

flyinghead commented 5 years ago

Looks like your log is empty. Can you check?

ccontino84 commented 5 years ago

I also tried a couple of hours ago and it didn't work, but now it's magically back.. strange. Now it's attached here: retroarch.log

barbudreadmon commented 5 years ago

@ckont if your computer is showing random behavior, you should check your memory modules through the memtest utility.

ccontino84 commented 5 years ago

@barbudreadmon I don't see a random behavior here, I always get the segfault at the same point using the Arch RA binary package with the latest version of the core. Just to be on the safe side I ran memtest86 and found 0 errors:

Result summary
Test Start Time 2019-03-28 19:55:44
Elapsed Time    3:03:29
Memory Range Tested     0x0 - 41F340000 (16883MB)
CPU Selection Mode  Parallel (All CPUs)
ECC Polling     Enabled

# Tests Passed  48/48 (100%)
Test                        # Tests Passed  Errors
Test 0 [Address test, walking ones, 1 CPU]  4/4 (100%)  0
Test 1 [Address test, own address, 1 CPU]   4/4 (100%)  0
Test 2 [Address test, own address]      4/4 (100%)  0
Test 3 [Moving inversions, ones & zeroes]   4/4 (100%)  0
Test 4 [Moving inversions, 8-bit pattern]   4/4 (100%)  0
Test 5 [Moving inversions, random pattern]  4/4 (100%)  0
Test 6 [Block move, 64-byte blocks]         4/4 (100%)  0
Test 7 [Moving inversions, 32-bit pattern]  4/4 (100%)  0
Test 8 [Random number sequence]         4/4 (100%)  0
Test 9 [Modulo 20, ones & zeros]        4/4 (100%)  0
Test 10 [Bit fade test, 2 patterns, 1 CPU]  4/4 (100%)  0
Test 13 [Hammer test]               4/4 (100%)  0
barbudreadmon commented 5 years ago

I also tried a couple of hours ago and it didn't work, but now it's magically back.. strange.

Looked like random behavior to me

The whole "illegal instruction" thingy and issue inside the dynarec makes me think it's something related to cpu set instructions, what's your cpu ?

ccontino84 commented 5 years ago

I have a Ryzen 5 2400g.

Looked like random behavior to me

I was referring to hastebin.com which didn't show the log for some reason

EDIT: attached log with full stacktrace: retroarch_full_stacktrace.log

flyinghead commented 5 years ago

Yeah apparently hastebin.com had issues but it's working now.

The only idea I have is that something is wrong in the Arch retroarch binary package. Or at least something is causing issues in the reicast core.

It'd be interesting to compare how different are the build options for snap and Arch.

ccontino84 commented 5 years ago

I tried to compile retroarch from sources and used this AUR package: https://aur.archlinux.org/packages/retroarch-git/ In the end I get exactly the same error. This is how retroarch is build:

  ./configure \
    --prefix='/usr' \
    --disable-jack \
    --disable-oss
  make clean
  make
  make -C gfx/video_filters

I'm wondering if the issue could be a dynamically linked library and not retroarch itself, since the snap package comes with the libraries included. But still only the reicast core crashes, everything else works perfectly :confused:

ccontino84 commented 4 years ago

FYI now I get the error also when using the snap package. For now I stick to an old version of reicast to avoid the problem.

flyinghead commented 4 years ago

Assuming resolved. Reopen if help needed

ccontino84 commented 4 years ago

I'm still using the same old version of reicast with retroarch installed via snap because the new flycast core doesn't work for me. I always get the segfault :(

flyinghead commented 4 years ago

Can you try to compile a debug version of flycast and check where the problem happens? Also logs, etc.

ccontino84 commented 4 years ago

I'm now testing using retroarch installed from arch repo, because the snap was more difficult to debug. Anyway I get the same error:

[INFO] Requesting core OpenGL context (3.0). [libretro INFO] 00:00:410 hw/mem/_vmem.cpp:547 N[VMEM]: Info: nvmem is enabled, with addr space of size 4GB [libretro INFO] 00:00:410 hw/mem/_vmem.cpp:548 I[VMEM]: Info: p_sh4rcb: 0x7ffd6a3e0000 virt_ram_base: 0x7ffd724e0000 [libretro INFO] 00:00:429 reios/reios.cpp:704 I[REIOS]: reios: Init [libretro INFO] 00:00:430 e/hw/flashrom/flashrom.h:111 I[FLASHROM]: Loaded /mnt/dc/AeroWings//dc/dc_boot.bin as bootrom [libretro INFO] 00:00:430 e/hw/flashrom/flashrom.h:111 I[FLASHROM]: Loaded /mnt/dc/AeroWings//dc/dc_nvmem.bin as nvram [libretro INFO] 00:00:431 nullDC.cpp:134 I[DYNAREC]: Using Recompiler [libretro INFO] 00:00:431 hw/sh4/interpr/sh4_interpreter.cpp:116 I[INTERPRETER]: Sh4 Reset [libretro INFO] 00:00:431 hw/sh4/dyna/driver.cpp:73 I[DYNAREC]: recSh4:Dynarec Cache clear at A0000000 free space 16777216 [libretro INFO] 00:00:431 hw/sh4/dyna/driver.cpp:413 I[DYNAREC]: recSh4 Init [libretro INFO] 00:00:439 imgread/common.cpp:130 I[GDROM]: gdrom: Opened image "/mnt/dc/AeroWings/AeroWings.cdi" [libretro INFO] 00:00:451 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:452 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:453 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:453 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:458 hw/sh4/interpr/sh4_interpreter.cpp:116 I[INTERPRETER]: Sh4 Reset [libretro INFO] 00:00:458 hw/sh4/dyna/driver.cpp:73 I[DYNAREC]: recSh4:Dynarec Cache clear at A0000000 free space 16777216 [libretro INFO] 00:00:458 reios/reios.cpp:170 I[REIOS]: hardware SEGA SEGAKATANA maker SEGA ENTERPRISES ks E650 type GD-ROM num 1/1 area JUE ctrl 0799 dev A vga 1 wince 0 product T40202D 50 version V1.001 date 19990819 boot 1ST_READ.BIN softco xeal.cjb.net [libretro INFO] 00:00:458 nullDC.cpp:152 N[BOOT]: [LUT]: Product number: T40202D 50. [INFO] [Environ]: SET_ROTATION: 0

[libretro INFO] 00:02:524 hw/sh4/dyna/driver.cpp:85 I[DYNAREC]: cntx // fpcb offset: -135266304 // pc offset: -184 // pc A0000000 [libretro ERROR] 00:00:562 libretro/common.cpp:373 E[COMMON]: SIGSEGV @ 7fff99d3f7f2 ... 0x7ffe7b7d0000 -> was not in vram (dyna code 0) [libretro INFO] Fatal error : segfault in signal_handler -> core/libretro/common.cpp : 374

Thread 1 "retroarch" received signal SIGILL, Illegal instruction. os_DebugBreak () at core/libretro/libretro.cpp:3225 3225 __builtin_trap(); (gdb) bt

0 os_DebugBreak () at core/libretro/libretro.cpp:3225

1 0x00007ffe73a5e2f8 in signal_handler (sn=11, si=0x7fffffffdd70, segfault_ctx=0x7fffffffdc40)

at core/libretro/common.cpp:374

2

3 bm_GetCode (addr=2684354560) at core/hw/sh4/dyna/blockmanager.cpp:46

4 0x00007fff99d3f82f in bm_GetCodeByVAddr (addr=2684354560) at core/hw/sh4/dyna/blockmanager.cpp:58

5 0x00007fff98bf8e5e in ngen_mainloop (v_cntx=0x7fff98bf8e5e <ngen_mainloop(void*)+76>)

at core/rec-x64/rec_x64.cpp:165

6 0x0000000000000001 in ?? ()

7 0x0000000000000330 in ?? ()

8 0x0000000000000000 in ?? ()

(gdb) continue Continuing. [libretro ERROR] 02:08:667 libretro/common.cpp:373 E[COMMON]: SIGSEGV @ 7ffe73a5cbd0 ... 0x7ffe73a5cbd0 -> was not in vram (dyna code 0) [libretro INFO] Fatal error : segfault in signal_handler -> core/libretro/common.cpp : 374

Thread 1 "retroarch" received signal SIGILL, Illegal instruction. os_DebugBreak () at core/libretro/libretro.cpp:3225 3225 __builtin_trap(); (gdb) bt

0 os_DebugBreak () at core/libretro/libretro.cpp:3225

1 0x00007ffe73a5e2f8 in signal_handler (sn=4, si=0x7fffffffd770, segfault_ctx=0x7fffffffd640)

at core/libretro/common.cpp:374

2

3 os_DebugBreak () at core/libretro/libretro.cpp:3225

4 0x00007ffe73a5e2f8 in signal_handler (sn=11, si=0x7fffffffdd70, segfault_ctx=0x7fffffffdc40)

at core/libretro/common.cpp:374

5

6 bm_GetCode (addr=2684354560) at core/hw/sh4/dyna/blockmanager.cpp:46

7 0x00007fff99d3f82f in bm_GetCodeByVAddr (addr=2684354560) at core/hw/sh4/dyna/blockmanager.cpp:58

8 0x00007fff98bf8e5e in ngen_mainloop (v_cntx=0x7fff98bf8e5e <ngen_mainloop(void*)+76>)

at core/rec-x64/rec_x64.cpp:165

9 0x0000000000000001 in ?? ()

10 0x0000000000000330 in ?? ()

11 0x0000000000000000 in ?? ()

flyinghead commented 4 years ago

Are you using any compilation/build flags?

ccontino84 commented 4 years ago

No, I've just cloned the repo and set DEBUG=1 The pc is the same I described above in my previous comments (Ryzen 2400G)

flyinghead commented 4 years ago

bm_GetCode() should access p_sh4rcb at 0x7ffd6a3e0000 (printed above), but instead uses 7ffe7b7d0000, which is outside the array and even past the end of the virtual mem space!

Can you walk up the stack to bm_GetCode and check the value of *p_sh4rcb ? the pc is A0000000 which should translate to index 0.

ccontino84 commented 4 years ago

Sorry, I'm not very familiar with gdb. Is this what you need?

[libretro INFO] 00:00:510 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:510 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:511 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:512 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:516 hw/sh4/interpr/sh4_interpreter.cpp:116 I[INTERPRETER]: Sh4 Reset [libretro INFO] 00:00:516 hw/sh4/dyna/driver.cpp:73 I[DYNAREC]: recSh4:Dynarec Cache clear at A0000000 free space 16777216 [libretro INFO] 00:00:516 reios/reios.cpp:170 I[REIOS]: hardware SEGA SEGAKATANA maker SEGA ENTERPRISES ks E650 type GD-ROM num 1/1 area JUE ctrl 0799 dev A vga 1 wince 0 product T40202D 50 version V1.001 date 19990819 boot 1ST_READ.BIN softco xeal.cjb.net [libretro INFO] 00:00:516 nullDC.cpp:152 N[BOOT]: [LUT]: Product number: T40202D 50. [INFO] [Environ]: SET_ROTATION: 0

[libretro INFO] 00:02:583 hw/sh4/dyna/driver.cpp:85 I[DYNAREC]: cntx // fpcb offset: -135266304 // pc offset: -184 // pc A0000000 [libretro ERROR] 00:00:610 libretro/common.cpp:373 E[COMMON]: SIGSEGV @ 7fff99d3f7f2 ... 0x7ffe7b780000 -> was not in vram (dyna code 0) [libretro INFO] Fatal error : segfault in signal_handler -> core/libretro/common.cpp : 374

Thread 1 "retroarch" received signal SIGILL, Illegal instruction. os_DebugBreak () at core/libretro/libretro.cpp:3225 3225 __builtin_trap();

(gdb) info registers rax 0x0 0 rbx 0x2 2 rcx 0x5555567af010 93825011478544 rdx 0x555557299440 93825022923840 rsi 0x7 7 rdi 0x555557a1fcb0 93825030814896 rbp 0x1 0x1 rsp 0x7fffffffdbe0 0x7fffffffdbe0 r8 0x5555567af016 93825011478550 r9 0x6 6 r10 0x7fffffffd350 140737488343888 r11 0x0 0 r12 0x7ffff7f92010 140737353687056 r13 0x1 1 r14 0x0 0 r15 0x330 816 rip 0x7ffe6f308bd0 0x7ffe6f308bd0 <os_DebugBreak()+43> eflags 0x10206 [ PF IF RF ] cs 0x33 51 ss 0x2b 43 ds 0x0 0 es 0x0 0 fs 0x0 0 gs 0x0 0

(gdb) info frame Stack level 0, frame at 0x7fffffffdbf0: rip = 0x7ffe6f308bd0 in os_DebugBreak (core/libretro/libretro.cpp:3225); saved rip = 0x7ffe6f30a2f8 called by frame at 0x7fffffffdc40 source language c++. Arglist at 0x7fffffffdbd8, args: Locals at 0x7fffffffdbd8, Previous frame's sp is 0x7fffffffdbf0 Saved registers: rip at 0x7fffffffdbe8

(gdb) x/100x $sp 0x7fffffffdbe0: 0x7b780000 0x00007ffe 0x6f30a2f8 0x00007ffe 0x7fffffffdbf0: 0xffffe0e0 0x00007fff 0xffffdc40 0x00007fff 0x7fffffffdc00: 0xffffdd70 0x00007fff 0x9892673a 0x0000000b 0x7fffffffdc10: 0x00000330 0x00000000 0x00007c36 0x00000000 0x7fffffffdc20: 0x99d3f7f2 0x00007fff 0xe2846200 0x929e2463 0x7fffffffdc30: 0x1b855d58 0x00000000 0xf6195930 0x00007fff 0x7fffffffdc40: 0x00000007 0x00000000 0x00000000 0x00000000 0x7fffffffdc50: 0x00000000 0x00000000 0x00000000 0x00007fff 0x7fffffffdc60: 0x00000000 0x00000000 0x567af01c 0x00005555 0x7fffffffdc70: 0x00000003 0x00000000 0x00000008 0x00000000 0x7fffffffdc80: 0x00000246 0x00000000 0xf7f92010 0x00007fff 0x7fffffffdc90: 0x00000001 0x00000000 0x00000000 0x00000000 0x7fffffffdca0: 0x00000330 0x00000000 0xa0000000 0x00000000 0x7fffffffdcb0: 0x00000001 0x00000000 0x00000001 0x00000000 0x7fffffffdcc0: 0x00000002 0x00000000 0x00000000 0x00000000 0x7fffffffdcd0: 0x7b780000 0x00007ffe 0xf3de51f1 0x00007fff 0x7fffffffdce0: 0xffffe1e8 0x00007fff 0x99d3f7f2 0x00007fff 0x7fffffffdcf0: 0x00010206 0x00000000 0x00000033 0x002b0000 0x7fffffffdd00: 0x00000004 0x00000000 0x0000000e 0x00000000 0x7fffffffdd10: 0x00000000 0x00000000 0x7b780000 0x00007ffe 0x7fffffffdd20: 0xffffde00 0x00007fff 0x987f6525 0x00007fff 0x7fffffffdd30: 0xffffde68 0x00007fff 0xffffddc0 0x00007fff 0x7fffffffdd40: 0xffffddd0 0x00007fff 0xf7fdd739 0x00007fff 0x7fffffffdd50: 0x00000033 0x00000000 0x57293b30 0x00005555 0x7fffffffdd60: 0x00000005 0x00000000 0x00000000 0x00000000

flyinghead commented 4 years ago

Type up 3 times then p/x *p_sh4rcb

ccontino84 commented 4 years ago

This is what I get

[libretro INFO] 00:01:785 hw/sh4/dyna/driver.cpp:85 I[DYNAREC]: cntx // fpcb offset: -135266304 // pc offset: -184 // pc A0000000 [libretro ERROR] 00:00:818 libretro/common.cpp:373 E[COMMON]: SIGSEGV @ 7fff99d3f7f2 ... 0x7ffe7b560000 -> was not in vram (dyna code 0) [libretro INFO] Fatal error : segfault in signal_handler -> core/libretro/common.cpp : 374

Thread 1 "retroarch" received signal SIGILL, Illegal instruction. os_DebugBreak () at core/libretro/libretro.cpp:3225 3225 __builtin_trap(); (gdb) up

1 0x00007ffe737ea2f8 in signal_handler (sn=11, si=0x7fffffffdd70, segfault_ctx=0x7fffffffdc40)

at core/libretro/common.cpp:374

374 die("segfault"); (gdb) up

2

(gdb) up

3 bm_GetCode (addr=2684354560) at core/hw/sh4/dyna/blockmanager.cpp:46

46 DynarecCodeEntryPtr rv = FPCA(addr); (gdb) p/x *p_sh4rcb value of type `Sh4RCB' requires 135266304 bytes, which is more than max-value-size

flyinghead commented 4 years ago

Sorry: p/x p_sh4rcb

ccontino84 commented 4 years ago

(gdb) p/x p_sh4rcb $1 = 0x7ffe7b560000

flyinghead commented 4 years ago

Is it the same value you see earlier in the log? hw/mem/_vmem.cpp:548 I[VMEM]: Info: p_sh4rcb: 0x7ffd6a3e0000 virt_ram_base: 0x7ffd724e0000

ccontino84 commented 4 years ago

No that was a different value

[libretro INFO] 00:00:654 hw/mem/_vmem.cpp:548 I[VMEM]: Info: p_sh4rcb: 0x7ffd6a170000 virt_ram_base: 0x7ffd72270000

flyinghead commented 4 years ago

So we need to find out when and why it's modified. Here is a gdb script:

break retro_load_game
run
watch p_sh4rcb
cont

Answer y when setting the first breakpoint. gdb should break when p_sh4rcbis initialized, in vmem_platform_init:

Old value = (Sh4RCB *) 0x0
New value = (Sh4RCB *) 0x7ffed0f10000

Note the new value which should be the one printed in the log, then type cont to find when it's overwritten.

ccontino84 commented 4 years ago

Here is the output

[libretro INFO] Rumble interface supported! [WARN] SYSTEM DIR is empty, assume CONTENT DIR /mnt/dc/AeroWings/AeroWings.cdi [INFO] [Environ]: SYSTEM_DIRECTORY: "/mnt/dc/AeroWings/".

................................ [libretro INFO] File extension is: .cdi [libretro INFO] 00:00:410 libretro/libretro.cpp:1945 I[COMMON]: Creating dir: /mnt/dc/AeroWings//dc/data

[INFO] Requesting core OpenGL context (3.0).

Thread 1 "retroarch" hit Hardware watchpoint 2: p_sh4rcb

Old value = (Sh4RCB ) 0x0 New value = (Sh4RCB ) 0x7ffe7b9a0000 vmem_platform_init (vmem_base_addr=0x7fff9b3a7ce0 , sh4rcb_addr=0x7fff9b53cc80 ) at core/libretro/vmem_utils.cpp:179 179 vmem_base_addr = (void)(ptrint + sizeof(Sh4RCB));

(gdb) cont Continuing. [libretro INFO] 00:18:688 hw/mem/_vmem.cpp:547 N[VMEM]: Info: nvmem is enabled, with addr space of size 4GB [libretro INFO] 00:18:689 hw/mem/_vmem.cpp:548 I[VMEM]: Info: p_sh4rcb: 0x7ffe7b9a0000 virt_ram_base: 0x7ffe83aa0000 [libretro INFO] 00:18:702 reios/reios.cpp:704 I[REIOS]: reios: Init [libretro INFO] 00:18:703 e/hw/flashrom/flashrom.h:111 I[FLASHROM]: Loaded /mnt/dc/AeroWings//dc/dc_boot.bin as bootrom [libretro INFO] 00:18:703 e/hw/flashrom/flashrom.h:111 I[FLASHROM]: Loaded /mnt/dc/AeroWings//dc/dc_nvmem.bin as nvram [libretro INFO] 00:18:703 nullDC.cpp:134 I[DYNAREC]: Using Recompiler [libretro INFO] 00:18:703 hw/sh4/interpr/sh4_interpreter.cpp:116 I[INTERPRETER]: Sh4 Reset [libretro INFO] 00:18:703 hw/sh4/dyna/driver.cpp:73 I[DYNAREC]: recSh4:Dynarec Cache clear at A0000000 free space 16777216 [libretro INFO] 00:18:704 hw/sh4/dyna/driver.cpp:413 I[DYNAREC]: recSh4 Init [libretro INFO] 00:18:711 imgread/common.cpp:130 I[GDROM]: gdrom: Opened image "/mnt/dc/AeroWings/AeroWings.cdi" [libretro INFO] 00:18:721 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:18:722 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:18:723 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:18:723 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:18:728 hw/sh4/interpr/sh4_interpreter.cpp:116 I[INTERPRETER]: Sh4 Reset [libretro INFO] 00:18:728 hw/sh4/dyna/driver.cpp:73 I[DYNAREC]: recSh4:Dynarec Cache clear at A0000000 free space 16777216 [libretro INFO] 00:18:729 reios/reios.cpp:170 I[REIOS]: hardware SEGA SEGAKATANA maker SEGA ENTERPRISES ks E650 type GD-ROM num 1/1 area JUE ctrl 0799 dev A vga 1 wince 0 product T40202D 50 version V1.001 date 19990819 boot 1ST_READ.BIN softco xeal.cjb.net [libretro INFO] 00:18:729 nullDC.cpp:152 N[BOOT]: [LUT]: Product number: T40202D 50. [INFO] [Environ]: SET_ROTATION: 0 [INFO] [RCHEEVOS]: ext_hash 0b886555 ('cdi') [INFO] Skipping SRAM load.. [INFO] Version of libretro API: 1 [INFO] Compiled against API: 1 [INFO] [RCHEEVOS]: Load task finished [INFO] [Cheats]: Load game-specific cheatfile: /home/cloud/.config/retroarch/cheats/Flycast/AeroWings.cht [INFO] [Audio]: Set audio input rate to: 44055.94 Hz. [INFO] [Video]: Video @ fullscreen [INFO] [Video]: Using HW render, OpenGL driver forced. [INFO] [Video]: Using configured "gl" driver for GL HW render. [ERROR] [Wayland]: Failed to connect to Wayland server. [New Thread 0x7fffb0e10700 (LWP 3910)] ................................ [New Thread 0x7fffb2ffd700 (LWP 3924)] [INFO] [GLX]: GLX_OML_sync_control and GLX_MESA_swap_control supported, using better swap control method... [INFO] [GL]: Found GL context: x [INFO] [GL]: Detecting screen resolution 1920x1080. [INFO] [GLX]: Window manager is KWin. [INFO] [XINERAMA]: Xinerama version: 1.1. [INFO] [XINERAMA]: Xinerama screens: 1. [INFO] [GLX]: Using Xinerama on screen #0. [INFO] [GLX]: X = 0, Y = 0, W = 1920, H = 1080. [INFO] [GLX]: Using windowed fullscreen. [New Thread 0x7fffb27fc700 (LWP 3925)] [INFO] [GLX]: Found swap function: glXSwapIntervalEXT.

[INFO] [GL]: Vendor: X.Org, Renderer: AMD RAVEN (DRM 3.33.0, 5.3.9-arch1-1, LLVM 9.0.1). [INFO] [GL]: Version: 4.5 (Compatibility Profile) Mesa 19.3.3. [INFO] [GL]: Using Core GL context, setting up VAO... [INFO] [GL]: Using resolution 1920x1080 [INFO] [GL]: Default shader backend found: glsl. [INFO] [Shaders]: preset directory: /home/cloud/.config/retroarch/shaders/presets [INFO] [Shader driver]: Using GLSL shader backend. [INFO] [GLSL]: Checking GLSL shader support ... [WARN] [GL]: Stock GLSL shaders will be used. ................................ Thread 1 "retroarch" hit Breakpoint 1, retro_load_game (game=0x7ffff7fdbd55 <_dl_map_object+149>) at core/libretro/libretro.cpp:1818 1818 {

(gdb) cont Continuing.

[libretro INFO] Rumble interface supported! [WARN] SYSTEM DIR is empty, assume CONTENT DIR /mnt/dc/AeroWings/AeroWings.cdi [INFO] [Environ]: SYSTEM_DIRECTORY: "/mnt/dc/AeroWings/".

................................ [libretro INFO] File extension is: .cdi [libretro INFO] 00:00:379 libretro/libretro.cpp:1945 I[COMMON]: Creating dir: /mnt/dc/AeroWings//dc/data

[INFO] Requesting core OpenGL context (3.0). [libretro INFO] 00:00:379 hw/mem/_vmem.cpp:547 N[VMEM]: Info: nvmem is enabled, with addr space of size 4GB [libretro INFO] 00:00:379 hw/mem/_vmem.cpp:548 I[VMEM]: Info: p_sh4rcb: 0x7ffd6a3b0000 virt_ram_base: 0x7ffd724b0000 [libretro INFO] 00:00:391 reios/reios.cpp:704 I[REIOS]: reios: Init [libretro INFO] 00:00:392 e/hw/flashrom/flashrom.h:111 I[FLASHROM]: Loaded /mnt/dc/AeroWings//dc/dc_boot.bin as bootrom [libretro INFO] 00:00:392 e/hw/flashrom/flashrom.h:111 I[FLASHROM]: Loaded /mnt/dc/AeroWings//dc/dc_nvmem.bin as nvram [libretro INFO] 00:00:392 nullDC.cpp:134 I[DYNAREC]: Using Recompiler [libretro INFO] 00:00:392 hw/sh4/interpr/sh4_interpreter.cpp:116 I[INTERPRETER]: Sh4 Reset [libretro INFO] 00:00:392 hw/sh4/dyna/driver.cpp:73 I[DYNAREC]: recSh4:Dynarec Cache clear at A0000000 free space 16777216 [libretro INFO] 00:00:392 hw/sh4/dyna/driver.cpp:413 I[DYNAREC]: recSh4 Init [libretro INFO] 00:00:398 imgread/common.cpp:130 I[GDROM]: gdrom: Opened image "/mnt/dc/AeroWings/AeroWings.cdi" [libretro INFO] 00:00:408 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:409 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:409 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:410 hw/maple/maple_devs.cpp:543 I[MAPLE]: Initializing VMU data... [libretro INFO] 00:00:414 hw/sh4/interpr/sh4_interpreter.cpp:116 I[INTERPRETER]: Sh4 Reset [libretro INFO] 00:00:414 hw/sh4/dyna/driver.cpp:73 I[DYNAREC]: recSh4:Dynarec Cache clear at A0000000 free space 16777216 [libretro INFO] 00:00:414 reios/reios.cpp:170 I[REIOS]: hardware SEGA SEGAKATANA maker SEGA ENTERPRISES ks E650 type GD-ROM num 1/1 area JUE ctrl 0799 dev A vga 1 wince 0 product T40202D 50 version V1.001 date 19990819 boot 1ST_READ.BIN softco xeal.cjb.net [libretro INFO] 00:00:414 nullDC.cpp:152 N[BOOT]: [LUT]: Product number: T40202D 50. [INFO] [Environ]: SET_ROTATION: 0

[libretro INFO] 00:38:477 hw/sh4/dyna/driver.cpp:85 I[DYNAREC]: cntx // fpcb offset: -135266304 // pc offset: -184 // pc A0000000 [libretro ERROR] 00:00:542 libretro/common.cpp:373 E[COMMON]: SIGSEGV @ 7fff99d3f7f2 ... 0x7ffe7b9a0000 -> was not in vram (dyna code 0) [libretro INFO] Fatal error : segfault in signal_handler -> core/libretro/common.cpp : 374

Thread 1 "retroarch" received signal SIGILL, Illegal instruction. os_DebugBreak () at core/libretro/libretro.cpp:3225 3225 __builtin_trap();

flyinghead commented 4 years ago

Ok so p_sh4rcb is not overwritten, yet it crashes.

Can you put a breakpoint at _vmem.cpp:486 and check the values of ptrint, start and end?

br _vmem.cpp:486
r
p/x ptrint
p/x start
p/x end

Thanks

ccontino84 commented 4 years ago

[libretro INFO] 00:00:154 hw/mem/_vmem.cpp:548 I[VMEM]: Info: p_sh4rcb: 0x7ffd65d70000 virt_ram_base: 0x7ffd6de70000 .............. [libretro INFO] 00:27:256 hw/sh4/dyna/driver.cpp:85 I[DYNAREC]: cntx // fpcb offset: -135266304 // pc offset: -184 // pc A0000000

Thread 1 "retroarch" hit Breakpoint 2, BM_LockedWrite ( address=0x7ffe7b560000 "") at core/hw/mem/_vmem.cpp:486 486 if (ptrint >= start && ptrint < end) { (gdb) p/x ptrint $1 = 0x7ffe7b560000 (gdb) p/x start $2 = 0x7ffd65d70000 (gdb) p/x end $3 = 0x7ffd6dd70000

(gdb) cont Continuing. [libretro ERROR] 01:04:612 libretro/common.cpp:373 E[COMMON]: SIGSEGV @ 7fff99d3f7f2 ... 0x7ffe7b560000 -> was not in vram (dyna code 0) [libretro INFO] Fatal error : segfault in signal_handler -> core/libretro/common.cpp : 374

flyinghead commented 4 years ago

Where does this 0x7ffe7b560000value come from?

Can you put this printf at core/hw/sh4/dyna/blockmanager.cpp:46 (first line of bm_GetCode)?

printf("addr %x p_sh4rcb %p &sh4rcb.fpcb[0] %p FPCB_MASK %x &rv %p\n", addr, p_sh4rcb, &p_sh4rcb->fpcb[0], FPCB_MASK, &FPCA(addr));
ccontino84 commented 4 years ago

[libretro INFO] 00:00:835 hw/mem/_vmem.cpp:548 I[VMEM]: Info: p_sh4rcb: 0x7ffd6a390000 virt_ram_base: 0x7ffd72490000 ................ [libretro INFO] 00:00:869 hw/sh4/interpr/sh4_interpreter.cpp:116 I[INTERPRETER]: Sh4 Reset [libretro INFO] 00:00:869 hw/sh4/dyna/driver.cpp:73 I[DYNAREC]: recSh4:Dynarec Cache clear at A0000000 free space 16777216 [libretro INFO] 00:00:869 reios/reios.cpp:170 I[REIOS]: hardware SEGA SEGAKATANA maker SEGA ENTERPRISES ks E650 type GD-ROM num 1/1 area JUE ctrl 0799 dev A vga 1 wince 0 product T40202D 50 version V1.001 date 19990819 boot 1ST_READ.BIN softco xeal.cjb.net [libretro INFO] 00:00:869 nullDC.cpp:152 N[BOOT]: [LUT]: Product number: T40202D 50. [INFO] [Environ]: SET_ROTATION: 0

[libretro INFO] 00:01:952 hw/sh4/dyna/driver.cpp:85 I[DYNAREC]: cntx // fpcb offset: -135266304 // pc offset: -184 // pc A0000000 addr a0000000 p_sh4rcb 0x7ffe7b780000 &sh4rcb.fpcb[0] 0x7ffe7b780000 FPCB_MASK ffffff &rv 0x7ffe7b780000 [libretro ERROR] 00:00:981 libretro/common.cpp:373 E[COMMON]: SIGSEGV @ 7fff99d3f850 ... 0x7ffe7b780000 -> was not in vram (dyna code 0)

Meanwhile I also tried with my laptop, an XPS precision with i7-8850H on Ubuntu 18.04. There it works perfectly with the latest version..

flyinghead commented 4 years ago

So the main difference is ArchLinux vs. Ubuntu 18, right? It could also be the CPU but I doubt it at this point.

I'm running out of idea here. I think the best way for me is to try to reproduce it on a virtual machine running ArchLinux. But I won't be able to do that until a week or so.

ccontino84 commented 4 years ago

No problem, I'm still happy with the old version of reicast (great job btw!). In case it helps I also get the segfault using this docker image https://hub.docker.com/r/maciekbaron/retroarch on both desktop and laptop. Could be for a completely different reason however

flyinghead commented 4 years ago

@ccontino84 I installed Arch Linux in a VM and compiled retroarch 1.8.4 and the latest flycast and I still don't get any crash at startup...

ccontino84 commented 4 years ago

Interesting, I installed Ubuntu 19.10 in a VM and I still get the error using the retroarch snap package (flycast core downloaded from core updater):

[libretro INFO] File extension is: .cdi

[INFO] Requesting core OpenGL context (3.0). [libretro WARN] 00:00:392 hw/mem/_vmem.cpp:530 W[VMEM]: Warning! nvmem is DISABLED (due to failure or not being built-in [libretro INFO] Fatal error : mprotect failed... in mem_region_unlock -> core/libretro/vmem_utils.cpp : 59

[libretro ERROR] 00:00:582 libretro/common.cpp:373 E[COMMON]: SIGSEGV @ 7fc93dc515d8 ... 0x7fc93dc515d8 -> was not in vram (dyna code 0) [libretro INFO] Fatal error : segfault in signal_handler -> core/libretro/common.cpp : 374

Illegal instruction (core dumped)

The mprotect failed part is new, but the error looks similar. Other cores like PCSX ReARMed are working fine.