[rpcsx-os/vm] Added kMapInternalReserveOnly mapping flag

Use if you need to allocate guest memory, but delay host allocation
This commit is contained in:
DH 2023-06-29 13:33:21 +03:00
parent 4ee7d2d54a
commit 3d5ea2120c
3 changed files with 18 additions and 9 deletions

View file

@ -721,7 +721,7 @@ int main(int argc, const char *argv[]) {
// entryPoint();
// rx::vm::printHostStats();
rx::vm::uninitialize();
rx::vm::deinitialize();
return status;
}

View file

@ -135,13 +135,13 @@ std::string rx::vm::mapFlagsToString(std::int32_t flags) {
result += "System";
flags &= ~kMapFlagSystem;
}
if ((flags & kMapFlagAllAvaiable) == kMapFlagAllAvaiable) {
if ((flags & kMapFlagAllAvailable) == kMapFlagAllAvailable) {
if (!result.empty()) {
result += " | ";
}
result += "AllAvaiable";
flags &= ~kMapFlagAllAvaiable;
result += "AllAvailable";
flags &= ~kMapFlagAllAvailable;
}
if ((flags & kMapFlagNoCore) == kMapFlagNoCore) {
if (!result.empty()) {
@ -616,7 +616,7 @@ void rx::vm::initialize() {
// orbis::bridge.setUpSharedMemory(kMinAddress, kMemorySize, "/orbis-memory");
}
void rx::vm::uninitialize() {
void rx::vm::deinitialize() {
std::printf("Memory: shutdown\n");
::close(gMemoryShm);
gMemoryShm = -1;
@ -648,7 +648,7 @@ bool setMemoryRangeName(std::uint64_t phyAddress, std::uint64_t size,
*/
void *rx::vm::map(void *addr, std::uint64_t len, std::int32_t prot,
std::int32_t flags) {
std::int32_t flags, std::int32_t internalFlags) {
std::printf("rx::vm::map(addr = %p, len = %" PRIu64
", prot = %s, flags = %s)\n",
addr, len, mapProtToString(prot).c_str(),
@ -795,6 +795,10 @@ void *rx::vm::map(void *addr, std::uint64_t len, std::int32_t prot,
allocInfo.flags = kBlockFlagDirectMemory; // TODO
allocInfo.name[0] = '\0'; // TODO
if (internalFlags & kMapInternalReserveOnly) {
return reinterpret_cast<void *>(address);
}
auto result =
utils::map(reinterpret_cast<void *>(address), len, prot & kMapProtCpuAll,
realFlags, gMemoryShm, address - kMinAddress);
@ -916,4 +920,5 @@ void rx::vm::printHostStats() {
}
free(line);
fclose(maps);
}

View file

@ -29,7 +29,7 @@ enum MapFlags {
kMapFlagNoSync = 0x800,
kMapFlagAnonymous = 0x1000,
kMapFlagSystem = 0x2000,
kMapFlagAllAvaiable = 0x4000,
kMapFlagAllAvailable = 0x4000,
kMapFlagNoCore = 0x20000,
kMapFlagPrefaultRead = 0x40000,
kMapFlagSelf = 0x80000,
@ -45,6 +45,10 @@ enum MapProt {
kMapProtGpuAll = 0x30,
};
enum MapInternalFlags {
kMapInternalReserveOnly = 1 << 0,
};
struct VirtualQueryInfo {
uint64_t start;
uint64_t end;
@ -63,8 +67,8 @@ std::string mapProtToString(std::int32_t prot);
void printHostStats();
void initialize();
void uninitialize();
void *map(void *addr, std::uint64_t len, std::int32_t prot, std::int32_t flags);
void deinitialize();
void *map(void *addr, std::uint64_t len, std::int32_t prot, std::int32_t flags, std::int32_t internalFlags = 0);
bool unmap(void *addr, std::uint64_t size);
bool protect(void *addr, std::uint64_t size, std::int32_t prot);