mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-14 15:00:30 +02:00
On iOS, the base search stepped up from 0x100000000 in 8MB increments, right through the app's binary and early heap: about 100 failed vm_remaps (each logged twice) every time a game started. On macOS, Find4GBBase freed its probe allocation before the views were mapped. Now the kernel picks a free range of exactly the span the views need, which stays reserved and inaccessible, and the views are mapped over it with VM_FLAGS_OVERWRITE. One try, no race, and the gaps between views fault. Unmasked (macOS), ask for 4GB alignment first, which lets the ARM64 JIT pointerify. The old search remains as a fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
2.0 KiB
C++
68 lines
2.0 KiB
C++
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
#ifdef _WIN32
|
|
#include "CommonWindows.h"
|
|
#elif defined(__APPLE__)
|
|
#include <mach/mach.h>
|
|
#endif
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
// This class lets you create a block of anonymous RAM, and then arbitrarily map views into it.
|
|
// Multiple views can mirror the same section of the block, which makes it very convient for emulating
|
|
// memory mirrors.
|
|
|
|
struct MemArenaData;
|
|
|
|
class MemArena {
|
|
public:
|
|
size_t roundup(size_t x);
|
|
bool GrabMemSpace(size_t size);
|
|
void ReleaseSpace();
|
|
void *CreateView(s64 offset, size_t size, void *base = 0);
|
|
void ReleaseView(s64 offset, void *view, size_t size);
|
|
|
|
// This only finds 1 GB in 32-bit
|
|
u8 *Find4GBBase();
|
|
bool NeedsProbing();
|
|
#if defined(__APPLE__)
|
|
// Asks the kernel for a free range of this size for the views, and keeps it reserved (inaccessible), so
|
|
// CreateView can map over it without anything else taking it in between. ReleaseSpace releases it too.
|
|
// alignMask: the address bits that must be zero.
|
|
u8 *ReserveViewSpace(size_t size, size_t alignMask);
|
|
void ReleaseViewSpace();
|
|
#endif
|
|
|
|
private:
|
|
#ifdef _WIN32
|
|
HANDLE hMemoryMapping;
|
|
SYSTEM_INFO sysInfo;
|
|
#elif defined(__APPLE__)
|
|
size_t vm_size;
|
|
vm_address_t vm_mem; // same type as vm_address_t
|
|
vm_address_t reserved_mem = 0;
|
|
size_t reserved_size = 0;
|
|
#else
|
|
int fd = -1;
|
|
#endif
|
|
};
|