Vita: Wait, what do you mean sceKernelFindMemBlockByAddr has been in vitasdk for 4.5 years?

This commit is contained in:
Vicki Pfau 2020-08-20 00:09:20 -07:00
parent 8a3a2bf058
commit 0a52f44fa8
1 changed files with 3 additions and 25 deletions

View File

@ -4,22 +4,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <mgba-util/memory.h> #include <mgba-util/memory.h>
#include <mgba-util/vector.h>
#include <psp2/kernel/sysmem.h> #include <psp2/kernel/sysmem.h>
#include <psp2/types.h> #include <psp2/types.h>
DECLARE_VECTOR(SceUIDList, SceUID);
DEFINE_VECTOR(SceUIDList, SceUID);
static struct SceUIDList uids;
static bool listInit = false;
void* anonymousMemoryMap(size_t size) { void* anonymousMemoryMap(size_t size) {
if (!listInit) {
SceUIDListInit(&uids, 8);
listInit = true;
}
if (size & 0xFFF) { if (size & 0xFFF) {
// Align to 4kB pages // Align to 4kB pages
size += ((~size) & 0xFFF) + 1; size += ((~size) & 0xFFF) + 1;
@ -28,7 +17,6 @@ void* anonymousMemoryMap(size_t size) {
if (memblock < 0) { if (memblock < 0) {
return 0; return 0;
} }
*SceUIDListAppend(&uids) = memblock;
void* ptr; void* ptr;
if (sceKernelGetMemBlockBase(memblock, &ptr) < 0) { if (sceKernelGetMemBlockBase(memblock, &ptr) < 0) {
return 0; return 0;
@ -37,18 +25,8 @@ void* anonymousMemoryMap(size_t size) {
} }
void mappedMemoryFree(void* memory, size_t size) { void mappedMemoryFree(void* memory, size_t size) {
UNUSED(size); SceUID uid = sceKernelFindMemBlockByAddr(memory, size);
size_t i; if (uid >= 0) {
for (i = 0; i < SceUIDListSize(&uids); ++i) {
SceUID uid = *SceUIDListGetPointer(&uids, i);
void* ptr;
if (sceKernelGetMemBlockBase(uid, &ptr) < 0) {
continue;
}
if (ptr == memory) {
sceKernelFreeMemBlock(uid); sceKernelFreeMemBlock(uid);
SceUIDListShift(&uids, i, 1);
return;
}
} }
} }