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

[WIP] Implement mmap/munmap #44

Open
wants to merge 108 commits into
base: vita
Choose a base branch
from
Open

[WIP] Implement mmap/munmap #44

wants to merge 108 commits into from

Conversation

d3m3vilurr
Copy link
Contributor

@d3m3vilurr d3m3vilurr commented Oct 6, 2019

No description provided.

xyzz and others added 30 commits August 13, 2015 14:07
MrNetrix changes and user-defined heap size
Allows building the manuals using recent versions of TexInfo.
@Rinnegatamante
Copy link
Member

Rinnegatamante commented Oct 6, 2019

Does this make malloc to use mmap when heap finished? If so, depending on the case, it can break already existing homebrews. (Eg: an homebrew using vita2d that allocs a lot of textures will result in running out of available memblocks making mmap fail despite having still free memory. The viceversa case would apply too, you run out of newlib heap and keep alloc-ing memblocks with malloc until you run out of memblocks and then vita2d becomes completely unusable to alloc new textures).

@d3m3vilurr
Copy link
Contributor Author

hm. maybe yes (main flow is alloc small block ->alloc large block->alloc with mmap->extend heap memblock, but i just readed very roughly). and it related mmap_threshold and default value for this is 128k.
you can change these settings values(M_TRIM_THRESHOLD, M_TOP_PAD, M_MMAP_THRESHOLD, M_MMAP_MAX) with mallopt`
(this is the reason why my test result is 96MB (default heap size is 32MB + mmap_max is 64)

and I'm not sure that this patch occurs breaking of homebrews if that apps were had quite right memory handling.

@d3m3vilurr d3m3vilurr changed the title Implement mmap/munmap and malloc with mmap Implement mmap/munmap Oct 6, 2019
@d3m3vilurr
Copy link
Contributor Author

@Rinnegatamante split malloc part to #46 to easy reviewing

@Rinnegatamante
Copy link
Member

Rinnegatamante commented Oct 13, 2019

I'm quite sure mmap can't be replaced in all cases with sceKernelAllocMemBlock. Speaking about dynarec: mmap's generally used in that case but on Vita we need sceKernelAllocMemBlockForVM:
ioq3 armv7 dynarec: https://github.com/ioquake/ioq3/blob/master/code/qcommon/vm_armv7l.c#L628
vitaQuakeIII armv7 dynarec: https://github.com/Rinnegatamante/vitaQuakeIII/blob/master/code/qcommon/vm_armv7l.c#L619

@frangarcj may know more about this.

@d3m3vilurr
Copy link
Contributor Author

d3m3vilurr commented Oct 13, 2019

well... we don't need to replace all of sceKernelAllocMemBlock cases.
mmap/munmmap are just one of posix spec functions.
technically, this functions don't need to care about dynarec as same reason.

more detail explain, maybe dynarec requires PROT_EXEC flag, and it's reason why you need sceKernelAllocMemBlockForVM instead sceKernelAllocMemBlock
it mean, you can patch mmap for PROT_EXEC, but maybe we need to introduce another chunk structure for detecting allocation method.
in this time, mmap function doesn't support the PROT_EXEC | PROT_WRITE

PS. same reason, ioq3 repo is wrong.


sorry ioq3's code is right. that code called mprotect with PROT_READ|PROT_EXEC

@d3m3vilurr d3m3vilurr changed the title Implement mmap/munmap [WIP] Implement mmap/munmap Oct 17, 2019
@d3m3vilurr
Copy link
Contributor Author

added mark WIP.
we can detect alloc function using sceKernelGetMemBlockInfoByAddr
I'll update this patch to support RX memory block.
but I don't know good approach yet to implement mprotect to switch perm between WX and RX without any kernel plugin.

I didn't test yet, but imo, sceKernelOpenVMDomain and sceKernelCloseVMDomain will open all vm area.

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.