shadps4-emu / shadPS4

PS4 emulator for Windows and Linux
https://shadps4.net/
GNU General Public License v2.0
1.14k stars 59 forks source link

Allocation of virtual memory backing file fails with small page file, crashes program #261

Open xezrunner opened 2 weeks ago

xezrunner commented 2 weeks ago

CreateFileMapping2() returns null after numerous successful attempts at starting a game. Rebooting the system and trying again resolves the issue for a while, but it eventually happens again.

I am unsure whether this is an issue on the emulator or Windows side. My machine has 8GB of RAM and a 14GB page file.

https://github.com/shadps4-emu/shadPS4/blob/379ec554a8aa6e683a3a094a9f4ce8ec6da3f3e9/src/core/address_space.cpp#L54-L58

I have been attempting to get a game running through debugging, so I have the code up. I inserted my own code to break if the backing pointer is zero:

0

That assert hits and crashes, even when running the executable without a debugger.

raphaelthegreat commented 2 weeks ago

Call Common::GetLastErrorMsg to get a more detailed description of the error from the OS

xezrunner commented 2 weeks ago

Call Common::GetLastErrorMsg to get a more detailed description of the error from the OS

Thanks, that did point me in the right direction!

It is weird how it works initially upon reboot, until some time passes where it just starts returning null.

image

xezrunner commented 2 weeks ago

I am not familiar with virtual memory management, but I read from Win32 docs:

If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a size for the file mapping object in the dwMaximumSizeHigh and dwMaximumSizeLow parameters. In this scenario, CreateFileMapping creates a file mapping object of a specified size that is backed by the system paging file instead of by a file in the file system.

I manually allocated a larger page file from 4GB to 12GB and that resolved the issue. Noticed that I was sort-of low on disk space, so the OS probably did not allocate a larger page file to conserve space.

Perhaps it would be beneficial to let it map an actual file instead of using the page file in cases where the page file is held small by the OS (so when this "insufficient resources" error occurs)?

raphaelthegreat commented 2 weeks ago

This is not supposed to be a file per sense, its a file mapping so we can map portions of it to the reserved virtual address space. Having it write to disk will not be ideal

xezrunner commented 2 weeks ago

This is not supposed to be a file per sense, its a file mapping so we can map portions of it to the reserved virtual address space. Having it write to disk will not be ideal

That makes sense. In that case, at least additional logging/non-destructive error handling (useful error message to increase page size?) would be useful here.

This crash seems to be happening early enough that the logging doesn't appear to be initialized yet - the console doesn't show anything and the assertion crashes further when it tries to call Common::Log::Impl::Stop().

dima-xd commented 1 week ago

Now I am having the same issue