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

Post Reply
User avatar
Martin_Riarte
Posts: 30
Joined: Mon 12 Nov, 2018 7:27 pm

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

Post by Martin_Riarte »

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 8108 times
PCemV14Linux-mprotect2mmap.patch
(2.27 KiB) Downloaded 598 times
User avatar
SarahWalker
Site Admin
Posts: 2054
Joined: Thu 24 Apr, 2014 4:18 pm

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

Post by SarahWalker »

Merged at rev 1224.
Post Reply