Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle munmap over multiple VMAs #1822

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mikusp
Copy link
Contributor

@mikusp mikusp commented Dec 18, 2024

Ratchet&Clank CUSA01073 allocates multiple memory areas and then tries to unmap them in one go. According to the documentation of munmap that should be allowed.

The PR merges the VMA containing the starting address with the next one until the area reaches at least the size to unmap, and then performs the unmap as before.

@raphaelthegreat
Copy link
Collaborator

raphaelthegreat commented Dec 18, 2024

Merging VMAs before unmap is not accurate to freebsd unfortunately and its not guaranteed to succeed unless the mapping are contiguous in physical memory as well. In addition I'm not sure if windows placeholder mechanism allows you to call VirtualFree on multiple allocations.

I recommend to follow the freebsd logic instead https://github.com/freebsd/freebsd-src/blob/aa5d3dec9df9379ab610f426e9653d1a55b254e5/sys/vm/vm_map.c#L4031
Retrieve the first VMA iterator with FindVma and iterate entries to unmap. The existing logic can be moved to an UnmapEntry function similar to freebsd that works only on a single VMA

@mikusp
Copy link
Contributor Author

mikusp commented Dec 18, 2024

Thanks for the suggestion, I'll make the change

@ElBread3
Copy link
Contributor

With many games it instead crashes at a [Debug] <Critical> memory.cpp:operator():643: Assertion Failed! Adding a mapping to already mapped region error. Don't know if this is progress or an issue with the implementation though.

@mikusp
Copy link
Contributor Author

mikusp commented Dec 21, 2024

@raphaelthegreat @ElBread3 I've pushed a different implementation

@brad0demx
Copy link

Would it be possible for this to get a rebase? CUSA05485 boots using this PR and I heard the splash screen should be improved on 0.5.X

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants