litchie / dospad

iDOS - DOSBox port on iOS
https://litchie.com/dospad
GNU General Public License v2.0
615 stars 132 forks source link

Recursive Page Fault Handling Interferes with Multitasking Systems #132

Open MisutaaAsriel opened 3 years ago

MisutaaAsriel commented 3 years ago

Issue

When booting operating systems, such as Windows 95, or Windows 98, some system applications may experience frequent "Page Fault" errors, or system instability.

Furthermore, Windows 98 must be started with either Program Manager or the Windows 95 explorer as its default shell, as the integrated web features of the Windows 98 explorer result in Page Faults at the system level.

Example Page Fault:

MSCONFIG caused an invalid page fault in
module USER.EXE at 001e:00000942
Registers:
E4X=00000000 C=16ef EIP=00000942 EELGS=00000246
EX=17d716cf SS=256f ESP=00008000 EBP=00648030
ECX=00022894 DS=16cf ESI=0002802a FS=015f
EDX=816b1437 ES=00f7 EDI=00643caa GS=0000
Bytes at CS:EIP:
55 86 ec 8b 46 0e 36 89 44 e4 86 5e 0c 36 89 5c
Stack dump:
00003e47 00001acf 004e0000 00000240 00022094
1437015f 78648020 00000001 00000000 000116ef
256f256f 20940000 0001805e 670c0003 301f0040
0000179f

Known Versions Issue Pertains To

Notes

Increasing or decreasing memsize has no effect on this. Would appear to be an issue with how memory paging is handled by iDOS on iOS. Issue appears to be related to how mainline DOSBOX handles page faults.

Memory access functions called by the native code may trigger an I/O port or page fault exception within the guest. DOSBox and DOSBox-X resolve the fault by pushing an exception frame onto the stack and then recursing into another emulation loop which does not break until the fault is resolved. While this is perfectly fine for DOS and Windows 3.1 simple fault handling, this may cause recursion issues with more advanced task switching and fault handling in Windows 95 and later.

The DOSBOX-X fork features the ability to use non-recursive page fault handling in its dynamic_x86 core (dosbox-x #2182). Could this possibly be implemented with the dynrec core in use by iDOS?

litchie commented 3 years ago

iDOS doesn't officially support dynrec core.

By the way, we will eventually build on the latest DOSBox SVN code base, so if there is any improvements regarding exception handling, we will revisit at that time.

MisutaaAsriel commented 3 years ago

The issue occurs with the simple core too. It's an issue with the recursive nature of DOSBOX page faults interfering with how some booted operating systems expect page faults to be handled; rather than the core type.

However, it would seem (based on research I've been doing over the past night) that even if non-recursive page fault handling were implemented, in the same vein as DOSBOX-X, that it wouldn't support the dynrec core.

/* Dynamic core is NOT compatible with the way page faults

  • in the guest are handled in this emulator. Do not use
  • dynamic core if paging is enabled. Do not comment this
  • out, even if it happens to work for a minute, a half
  • hour, a day, because it will turn around and cause
  • Windows 95 to crash when you've become most comfortable
  • with the idea that it works. This code cannot handle
  • the sudden context switch of a page fault and it never
  • will. Don't do it. You have been warned. */

Further, iDOS is configured to use dynrec as its dynamic core, as opposed to dyn_x86, so I wouldn't know where to start in trying to port non-recursive page fault handling for dynamic myself. (I am not comfortable or familiar enough with C/CPP/Obj-C languages, nor the DOSBOX codebase, to competently implement non-recursive page faults in a different core).