CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/MemArenaHorizon.cpp
Views: 1401
// Copyright (C) 2023 M4xw12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314#include "ppsspp_config.h"15#if PPSSPP_PLATFORM(SWITCH)1617#include <stdio.h>18#include <malloc.h> // memalign19#include <switch.h>2021#include "Common/MemArena.h"2223static uintptr_t memoryBase = 0;24static uintptr_t memoryCodeBase = 0;25static uintptr_t memorySrcBase = 0;2627size_t MemArena::roundup(size_t x) {28return x;29}3031bool MemArena::NeedsProbing() {32return false;33}3435bool MemArena::GrabMemSpace(size_t size) {36return true;37}3839void MemArena::ReleaseSpace() {40if (R_FAILED(svcUnmapProcessCodeMemory(envGetOwnProcessHandle(), (u64)memoryCodeBase, (u64)memorySrcBase, 0x10000000)))41printf("Failed to release view space...\n");4243free((void *)memorySrcBase);44memorySrcBase = 0;45}4647void *MemArena::CreateView(s64 offset, size_t size, void *base) {48Result rc = svcMapProcessMemory(base, envGetOwnProcessHandle(), (u64)(memoryCodeBase + offset), size);49if (R_FAILED(rc)) {50printf("Fatal error creating the view... base: %p offset: %p size: %p src: %p err: %d\n",51(void *)base, (void *)offset, (void *)size, (void *)(memoryCodeBase + offset), rc);52} else {53printf("Created the view... base: %p offset: %p size: %p src: %p err: %d\n",54(void *)base, (void *)offset, (void *)size, (void *)(memoryCodeBase + offset), rc);55}5657return base;58}5960void MemArena::ReleaseView(s64 offset, void *view, size_t size) {61if (R_FAILED(svcUnmapProcessMemory(view, envGetOwnProcessHandle(), (u64)(memoryCodeBase + offset), size)))62printf("Failed to unmap view...\n");63}6465u8 *MemArena::Find4GBBase() {66memorySrcBase = (uintptr_t)memalign(0x1000, 0x10000000);6768if (!memoryBase)69memoryBase = (uintptr_t)virtmemReserve(0x10000000);7071if (!memoryCodeBase)72memoryCodeBase = (uintptr_t)virtmemReserve(0x10000000);7374if (R_FAILED(svcMapProcessCodeMemory(envGetOwnProcessHandle(), (u64)memoryCodeBase, (u64)memorySrcBase, 0x10000000)))75printf("Failed to map memory...\n");76if (R_FAILED(svcSetProcessMemoryPermission(envGetOwnProcessHandle(), memoryCodeBase, 0x10000000, Perm_Rx)))77printf("Failed to set perms...\n");7879return (u8 *)memoryBase;80}8182#endif // PPSSPP_PLATFORM(SWITCH)838485