libretro / px68k-libretro

Portable SHARP X68000 Emulator for Libretro
http://hissorii.blog45.fc2.com
GNU General Public License v2.0
45 stars 40 forks source link

Etoile Princesse 28008 Segmentation fault #170

Open Kelvfimer opened 3 months ago

Kelvfimer commented 3 months ago

Hello

Running latest commit it doesn't matter I use a disk version of HD version of the game it ends in 28008 Segmentation fault

Platform

odroid n2+ Linux 4.9 Retroarch 1.18 PX68k 4c7542e34df71e3ebab77b5867901747d58dbb38

Logs

I can't see any error on the logs retroarch.log

Troubleshooting steps done

I see an old issue similar but it's not related https://github.com/libretro/px68k-libretro/issues/135

Kelvfimer commented 3 months ago

I tried to debug the issue compiling the emulator in Debug mode but the segfault is gone and the game is playable...

I tried on Windows Retroarch and it works.

So I added symbols to the release version and what I see is failing here


Thread 1 "retroarch" received signal SIGSEGV, Segmentation fault.
0x0000007fa326a234 in rm_main (addr=38134) at x68k/mem_wrap.c:172
172                     return MEM[addr ^ 1];
(gdb) where
#0  0x0000007fa326a234 in rm_main (addr=38134) at x68k/mem_wrap.c:172
#1  0x0000007fa326a780 in cpu_readmem24_word (addr=38135) at x68k/mem_wrap.c:377
#2  0x0000007fa32268f8 in C68k_Exec (cpu=cpu@entry=0x7fa330da90 <C68K>, cycle=cycle@entry=200) at m68000/c68k/c68k_op3.inc:1769
#3  0x0000007fa3277004 in WinX68k_Exec () at libretro.c:1956
#4  retro_run () at libretro.c:2121
#5  0x00000000004253e0 in ?? ()
#6  0x00000000004272d8 in ?? ()
#7  0x000000000041eabc in ?? ()
#8  0x0000007fa61e756c in ?? () from target:/usr/lib/libc.so.6
#9  0x0000007fa61e7640 in __libc_start_main () from target:/usr/lib/libc.so.6
#10 0x0000000000410570 in ?? ()

it's trying to return a memory

168     static uint8_t rm_main(uint32_t addr)
169     {
170             addr &= 0x00ffffff;
171             if (addr < 0x00c00000) /* Use RAM upto 12MB */
172                     return MEM[addr ^ 1];
173             else if (addr < 0x00e00000)
174                     return GVRAM_Read(addr);
175             return MemReadTable[(addr >> 13) & 0xff](addr);
176     }

if I try to print it (gdb) print *addr Cannot access memory at address 0x94f6

If I do other debuggin session increasing RAM to 12MB and CPU to 16MHZ same behaviour but in other part of the code

Thread 1 "retroarch" received signal SIGSEGV, Segmentation fault.
0x0000007fb0bba1b4 in wm_cnt (addr=26516, val=126 '~') at x68k/mem_wrap.c:143
143                     MEM[addr ^ 1] = val;
(gdb) where
#0  0x0000007fb0bba1b4 in wm_cnt (addr=26516, val=126 '~') at x68k/mem_wrap.c:143
#1  0x0000007fb0bba468 in cpu_writemem24_word (addr=26516, val=32298) at x68k/mem_wrap.c:296
#2  0x0000007fb0b72434 in C68k_Exec (cpu=cpu@entry=0x7fb0c5da90 <C68K>, cycle=cycle@entry=200) at m68000/c68k/c68kexec.c:400
#3  0x0000007fb0bc7004 in WinX68k_Exec () at libretro.c:1956
#4  retro_run () at libretro.c:2121
#5  0x00000000004253e0 in ?? ()
#6  0x00000000004272d8 in ?? ()
#7  0x000000000041eabc in ?? ()
#8  0x0000007fb3b3756c in ?? () from target:/usr/lib/libc.so.6
#9  0x0000007fb3b37640 in __libc_start_main () from target:/usr/lib/libc.so.6
#10 0x0000000000410570 in ?? ()
(gdb) list
138             if (addr < 0x00c00000) /* Use RAM upto 12MB */
139             {
140     #ifdef MSB_FIRST
141                     MEM[addr    ] = val;
142     #else
143                     MEM[addr ^ 1] = val;
144     #endif
145             }
146             else if (addr < 0x00e00000)
147                     GVRAM_Write(addr, val);
(gdb)

priting address

(gdb) print *addr
Cannot access memory at address 0x6794
(gdb) info args
addr = 26516
val = 126 '~'

As far as I see all is related to MEM[ adrr ^ 1] Writing or reading memory

Troubleshoot

Tested in Windows retroarch and it works. Compiles px68k in debug mode works fine with no seg fault. I change MHZ and memory sizes and it doesn't fix it. Retroarch logs doesn't throw anything. retroarch2024_04_1409_34_15.log

Maybe @LibretroAdmin @kivutar can help on this

negativeExponent commented 2 days ago

fix a lot of these buffer-overflows in my repo. im just to lazy to push the changes now coz both repos have changed drastically. ill see if i can do it differently for this one.

Kelvfimer commented 2 days ago

thx so much for your feedback and effort fixing these issues :) . Eager to see the PR.

negativeExponent commented 2 days ago

thank me when i send the PR. what other games did you find having these buffer overflows? from my testing way back, it was like 10 games or so that is core-crashing especially when compilation options was so high. post the games you discovered so far to have these issue,

Kelvfimer commented 2 days ago

To be frank I noticed the issue only on Etoile Princesse . I tested Castlevania, arcus Odissey, both street fightes, crossfire, Daikaimura, Darius extra, CH68, gariu densetsu, hatenkou, Mahou, Sol-feace, Super Hang on with no issues.

However I can run other tests at my summer leave in a few weeks ahead. I will also join to the conversation my colleague Qbert that was also testing if he noticed any buffer overflow.

Kelvfimer commented 2 days ago

@negativeExponent I see that you fixed the raft issue due to the cpu timing in castlevania among other issues. Good to see this improvements on the emu :) https://github.com/negativeExponent/px68k-libretro

negativeExponent commented 2 days ago

are you able to compile core yourself? ill try to make a repo for some fixes i want to push (though with my history with libretro, dunno when my PR would even get merged)