Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ int DoMapDirect(void** addr, size_t len, int prot, int flags, int64_t physStart,
return 0;
}

int DoMapAnon(void** addr, size_t len, int prot, int flags) {
int DoMapAnon(void** addr, size_t len, int prot, int flags, size_t alignment) {
ValidateOutput(addr);
if (len == 0 || (len & (PS5_PAGE_SIZE - 1)) != 0) return SCE_KERNEL_ERROR_EINVAL;
GuestAllocations::Mutation mutation;
Expand All @@ -732,7 +732,7 @@ int DoMapAnon(void** addr, size_t len, int prot, int flags) {
return 0;
}
ReplaceFixedOverlap(mutation, *addr, len, flags);
void* mapped = MapAligned(*addr, len, LinuxProtFromSce(prot), flags, PS5_PAGE_SIZE);
void* mapped = MapAligned(*addr, len, LinuxProtFromSce(prot), flags, alignment);
try {
mutation.Add(mapped, len, (prot & 3) != 0, (prot & 2) != 0);
} catch (...) {
Expand Down
2 changes: 1 addition & 1 deletion core/libs/prx/libkernel/DirectMemory/DirectMemory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool DirectMemoryFind(int64_t offset, bool findNext, int64_t* start, int64_t* en
void DirectMemoryRetype(int64_t start, size_t len, int memoryType);
size_t DirectMemoryFreeRun(uint64_t offset, uint64_t limit);
int DoMapDirect(void** addr, size_t len, int prot, int flags, int64_t physStart, size_t alignment);
int DoMapAnon(void** addr, size_t len, int prot, int flags);
int DoMapAnon(void** addr, size_t len, int prot, int flags, size_t alignment = PS5_PAGE_SIZE);
int DoMprotect(const void* addr, size_t len, int prot);
int DoMtypeprotect(const void* addr, size_t len, int type, int prot);
int DoMunmap(void* addr, size_t len);
Expand Down
6 changes: 4 additions & 2 deletions core/libs/prx/libkernel/DirectMemory/PosixMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ constexpr int GuestSyncInvalidate = 0x2;
constexpr int GuestAdviceCore = 9;
constexpr int GuestAdviceProtect = 10;
constexpr std::uintptr_t GuestUserAddressEnd = 0x800000000000;
constexpr int GuestAlignedSuper = 0x1000000;
constexpr std::size_t SuperpageSize = std::size_t{1} << 21;

bool RoundLength(std::size_t length, std::size_t& rounded) {
constexpr auto mask = PS5_PAGE_SIZE - 1;
Expand Down Expand Up @@ -63,15 +65,15 @@ void* APS5_VABI mmap_nid_postfix(void* address, std::size_t length, int protecti
std::size_t rounded;
if (!RoundLength(length, rounded) || (protection & ~7) != 0)
return failed(GuestInvalid);
if (flags != (GuestPrivate | GuestAnonymous))
if ((flags & ~GuestAlignedSuper) != (GuestPrivate | GuestAnonymous))
return failed(GuestNotSupported);
if (descriptor != -1 || offset != 0)
return failed(GuestInvalid);
// A non-fixed address is a hint; the kernel may choose another address.
(void)address;
void* mapped = nullptr;
try {
const auto result = DoMapAnon(&mapped, rounded, protection, 0);
const auto result = DoMapAnon(&mapped, rounded, protection, 0, (flags & GuestAlignedSuper) != 0 ? SuperpageSize : PS5_PAGE_SIZE);
if (result != 0) return failed(GuestNoMemory);
return mapped;
} catch (const std::bad_alloc&) {
Expand Down
13 changes: 13 additions & 0 deletions core/libs/tests/GuestMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1310,4 +1310,17 @@ int main() {
}
Require(munmap_nid_postfix(mapped, 1) == 0);
}

reject(page, 3, 0x2001002, -1, 0, 45);
constexpr std::size_t superpage = std::size_t{1} << 21;
auto* aligned = static_cast<unsigned char*>(mmap_nid_postfix(nullptr, superpage + page, 3, 0x1001002, -1, 0));
Require(aligned != failed && (reinterpret_cast<std::uintptr_t>(aligned) & (superpage - 1)) == 0);
aligned[0] = 1;
aligned[superpage + page - 1] = 2;
{
GuestAllocations::Mutation mutation;
const auto range = mutation.Find(aligned);
Require(range.bytes == superpage + page && range.readable && range.writable);
}
Require(munmap_nid_postfix(aligned, superpage + page) == 0);
}
Loading