Replace malloc() by mmap() in Voodoo Graphics.

Post new patches here!
Post Reply
User avatar
Martin_Riarte
Posts: 21
Joined: Mon 12 Nov, 2018 7:27 pm

Replace malloc() by mmap() in Voodoo Graphics.

Post by Martin_Riarte » Tue 27 Nov, 2018 1:45 am

For the 3Dfx graphics (Voddoo 1/2, etc.), malloc is used to locate memory and then mprotect to change the permissions.

Reasons why malloc is not recommended as a tool:

- Permits only set with the granularity page, but the memory obtained by malloc is unlikely to be the page aligned, and
therefore the permission setting in the adjacent memory will also be terminated, possibly breaking things or denying
permissions of access.
- If you do not reset the previous permissions before calling the free, you can break the inside of malloc.

Solution:

- Replace malloc () with mmap ().
- Replace free () with munmap ().

In my GNU / Linux system in particular (my dear CentOS Linux 6.7), the application is dropped with a message
"mprotect: permission denied.", It drove me crazy ehh ! :cry: .

I solved it with these replacements in a patch and until now, it works (and I already did several tests, ehh!) :lol: .

If any of you have this problem, use it! :D
Attachments
3Dfx-Pantallazo-1.png
3Dfx-Pantallazo-1.png (164.77 KiB) Viewed 503 times
PCemV14Linux-mprotect2mmap.patch
(2.27 KiB) Downloaded 14 times

Post Reply