all repos — mgba @ 0a52f44fa822539200f5ae6aad1fe5f5a6a3ab0e

mGBA Game Boy Advance Emulator

src/platform/psp2/psp2-memory.c (view raw)

 1/* Copyright (c) 2013-2015 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include <mgba-util/memory.h>
 7
 8#include <psp2/kernel/sysmem.h>
 9#include <psp2/types.h>
10
11void* anonymousMemoryMap(size_t size) {
12	if (size & 0xFFF) {
13		// Align to 4kB pages
14		size += ((~size) & 0xFFF) + 1;
15	}
16	SceUID memblock = sceKernelAllocMemBlock("anon", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW, size, 0);
17	if (memblock < 0) {
18		return 0;
19	}
20	void* ptr;
21	if (sceKernelGetMemBlockBase(memblock, &ptr) < 0) {
22		return 0;
23	}
24	return ptr;
25}
26
27void mappedMemoryFree(void* memory, size_t size) {
28	SceUID uid = sceKernelFindMemBlockByAddr(memory, size);
29	if (uid >= 0) {
30		sceKernelFreeMemBlock(uid);
31	}
32}