diff --git a/src/core/libraries/kernel/memory.cpp b/src/core/libraries/kernel/memory.cpp index 2f0162f00..92280308d 100644 --- a/src/core/libraries/kernel/memory.cpp +++ b/src/core/libraries/kernel/memory.cpp @@ -655,12 +655,18 @@ void* PS4_SYSV_ABI posix_mmap(void* addr, u64 len, s32 prot, s32 flags, s32 fd, auto* memory = Core::Memory::Instance(); const auto mem_prot = static_cast(prot); const auto mem_flags = static_cast(flags); + const auto vaddr = reinterpret_cast(addr); - // mmap is less restrictive than other functions in regards to alignment - // To avoid potential issues, align address and size here. - const VAddr aligned_addr = Common::AlignDown(std::bit_cast(addr), 16_KB); + // Align address and size here. Both align up to the next page + const VAddr aligned_addr = Common::AlignUp(vaddr, 16_KB); const u64 aligned_size = Common::AlignUp(len, 16_KB); + if (True(mem_flags & Core::MemoryMapFlags::Fixed) && vaddr != aligned_addr) { + // If flags Fixed is specified, the input address must be aligned. + ErrSceToPosix(ORBIS_KERNEL_ERROR_EINVAL); + return reinterpret_cast(-1); + } + s32 result = ORBIS_OK; if (fd == -1) { result = memory->MapMemory(&addr_out, aligned_addr, aligned_size, mem_prot, mem_flags,