Linux: direct-memory mappings with addr == NULL get a top-down address, and titles that require the low window assert at start-up #692

Closed
opened 2026-10-05 16:02:20 +00:00 by jeffrey12cali · 3 comments
jeffrey12cali commented 2026-10-05 16:02:20 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-05T16:02:20Z.


Symptom. Running a Unity PS5 title on the Linux back end, the very first
sceKernelAllocateDirectMemory + sceKernelMapDirectMemory2 pair (256 MB, prot=0xf3,
align=0x200000, type=12) succeeds, but the title immediately re-issues the identical request and
then aborts inside its own allocator (a call + ud2 assert, not a kernel error).

Root cause. The title passes addr == NULL and expects a low virtual address. On Windows the
guest arena supplies one: the first mapping lands at 0x200000000 and later regions follow
contiguously. On Linux MapPlaced() (core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp) falls
through to mmap(nullptr, ...), so the caller gets a top-down 0x7f... address, rejects it and
retries; the retry trips the allocator's bookkeeping assert.

Measured with the map direct trace on both platforms:

1st map 2nd op
Windows (sos_runtime.exe) 0x200000000+0x10000000 reserve 0x210000000+0x100000
Linux (unpatched) 0x7fffdb200000+0x10000000 map direct of another 256 MB, then SIGABRT

Fix we use locally. A Linux-only low arena: reserve 0x200000000 for 16 GiB with
MAP_FIXED_NOREPLACE | PROT_NONE | MAP_NORESERVE once, then bump-allocate aligned MAP_FIXED chunks
inside it when MapPlaced() is called with no requested address; fall back to the current behaviour if
the reservation fails. After that, mappings land at 0x200000000 / 0x210000000 exactly as on Windows
and the start-up assert is gone.

Questions. Is there an intended Linux placement policy for direct memory (matching the Windows
guest arena)? Would you take a patch that adds a low-window reservation, ideally behind the same
knob that decides the Windows arena base? Happy to open a PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5715205905 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/692). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-05T16:02:20Z. --- **Symptom.** Running a Unity PS5 title on the Linux back end, the very first `sceKernelAllocateDirectMemory` + `sceKernelMapDirectMemory2` pair (256 MB, `prot=0xf3`, `align=0x200000`, `type=12`) succeeds, but the title immediately re-issues the *identical* request and then aborts inside its own allocator (a `call` + `ud2` assert, not a kernel error). **Root cause.** The title passes `addr == NULL` and expects a low virtual address. On Windows the guest arena supplies one: the first mapping lands at `0x200000000` and later regions follow contiguously. On Linux `MapPlaced()` (`core/libs/prx/libkernel/DirectMemory/DirectMemory.cpp`) falls through to `mmap(nullptr, ...)`, so the caller gets a top-down `0x7f...` address, rejects it and retries; the retry trips the allocator's bookkeeping assert. Measured with the `map direct` trace on both platforms: | | 1st map | 2nd op | | --- | --- | --- | | Windows (`sos_runtime.exe`) | `0x200000000+0x10000000` | `reserve 0x210000000+0x100000` | | Linux (unpatched) | `0x7fffdb200000+0x10000000` | `map direct` of another 256 MB, then SIGABRT | **Fix we use locally.** A Linux-only low arena: reserve `0x200000000` for 16 GiB with `MAP_FIXED_NOREPLACE | PROT_NONE | MAP_NORESERVE` once, then bump-allocate aligned `MAP_FIXED` chunks inside it when `MapPlaced()` is called with no requested address; fall back to the current behaviour if the reservation fails. After that, mappings land at `0x200000000` / `0x210000000` exactly as on Windows and the start-up assert is gone. **Questions.** Is there an intended Linux placement policy for direct memory (matching the Windows guest arena)? Would you take a patch that adds a low-window reservation, ideally behind the same knob that decides the Windows arena base? Happy to open a PR.
alfalfa-star commented 2026-10-05 18:32:53 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-05T18:32:53Z.


A second title hits the same gap, through flexible memory rather than direct memory: LEGO Horizon Adventures (PPSA14632, Unreal Engine), which bundles its own libc.prx and libSceNpCppWebApi.prx.

Symptom. On Linux the title segfaults in its online subsystem while preparing sceNpSessionSignalingInitialize: one of its interface pointers was never set.

Cause. The bundled sce::Np::CppWebApi::Common::initialize maps its 0x80000-byte heap with sceKernelMapNamedFlexibleMemory (prot 2, no address), gets a host address (0x7ffff197c000), and passes it to sceLibcMspaceCreate in the title's own libc.prx. That function returns NULL, so initialize returns 0x80553504 and the interface is not created. Per the disassembly of the bundled libc, mspace creation only accepts a base and capacity that lie in one of two windows:

  • base >= 0x400000 and base + capacity < 0xFC_0000_0001, or
  • base >= 0x800_0000_0000 and base + capacity < 0xF00_0000_0001

So any title whose libc builds an mspace on memory it maps without an address cannot work while Linux places such mappings top-down.

Check. As a local experiment only, MapPlaced() on Linux with no address returned MapAtOrAbove(0x200000000, ...) instead of mmap(nullptr, ...). The title's direct memory then lands at 0x200000000 - 0x81c0000000 (as on Windows), initialize succeeds, the segfault is gone and it runs on to an unrelated missing export. A Linux arena at the Windows base with the same end as the Windows arena would cover both ranges this libc accepts in the first window.

Tested on Arch Linux, GCC 16.2, main at 33e9a121 plus #672, #580, #722, #723, #730 and #734. Happy to run a Linux arena PR against this title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6000670648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/692#issuecomment-6000670648). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-05T18:32:53Z. --- A second title hits the same gap, through flexible memory rather than direct memory: LEGO Horizon Adventures (PPSA14632, Unreal Engine), which bundles its own `libc.prx` and `libSceNpCppWebApi.prx`. **Symptom.** On Linux the title segfaults in its online subsystem while preparing `sceNpSessionSignalingInitialize`: one of its interface pointers was never set. **Cause.** The bundled `sce::Np::CppWebApi::Common::initialize` maps its 0x80000-byte heap with `sceKernelMapNamedFlexibleMemory` (prot 2, no address), gets a host address (`0x7ffff197c000`), and passes it to `sceLibcMspaceCreate` in the title's own `libc.prx`. That function returns NULL, so `initialize` returns `0x80553504` and the interface is not created. Per the disassembly of the bundled libc, mspace creation only accepts a base and capacity that lie in one of two windows: - `base >= 0x400000` and `base + capacity < 0xFC_0000_0001`, or - `base >= 0x800_0000_0000` and `base + capacity < 0xF00_0000_0001` So any title whose libc builds an mspace on memory it maps without an address cannot work while Linux places such mappings top-down. **Check.** As a local experiment only, `MapPlaced()` on Linux with no address returned `MapAtOrAbove(0x200000000, ...)` instead of `mmap(nullptr, ...)`. The title's direct memory then lands at `0x200000000 - 0x81c0000000` (as on Windows), `initialize` succeeds, the segfault is gone and it runs on to an unrelated missing export. A Linux arena at the Windows base with the same end as the Windows arena would cover both ranges this libc accepts in the first window. Tested on Arch Linux, GCC 16.2, `main` at `33e9a121` plus #672, #580, #722, #723, #730 and #734. Happy to run a Linux arena PR against this title.
jeffrey12cali commented 2026-10-05 23:21:50 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-05T23:21:50Z.


Confirmed on our side, and opened as a draft PR: #780 (first commit).

The low-window reservation makes Linux match the Windows back end for this title:

before   map direct 0x7fffdb200000+0x10000000   -> title re-issues the same 256 MB, then asserts (SIGABRT)
after    map direct 0x200000000+0x10000000, 0x210000000+0x10000000   (same as Windows)

@alfalfa-star your two-window analysis of sceLibcMspaceCreate is consistent with what we see, and the
reservation here is 0x200000000 + 16 GiB (MAP_FIXED_NOREPLACE, PROT_NONE, MAP_NORESERVE, then
aligned MAP_FIXED chunks), so both MapPlaced() users - direct memory and flexible memory - land
inside your first accepted window (base >= 0x400000, base + capacity < 0xFC00000001). If you would
rather land a Linux-arena PR for the flexible-memory side, say so and I will keep #780 to the direct
memory path and rebase onto yours.

Progress this unblocked: the start-up assert is gone and the title now reaches on-screen output - the
PS boot logo and the publisher (MCS) logo, holding ~60 FPS, with vo 459 / agc 204 / pm4 900,
which are the same counts the working Windows build of the same commit produces.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6005298363 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/692#issuecomment-6005298363). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-05T23:21:50Z. --- Confirmed on our side, and opened as a draft PR: #780 (first commit). The low-window reservation makes Linux match the Windows back end for this title: ``` before map direct 0x7fffdb200000+0x10000000 -> title re-issues the same 256 MB, then asserts (SIGABRT) after map direct 0x200000000+0x10000000, 0x210000000+0x10000000 (same as Windows) ``` @alfalfa-star your two-window analysis of `sceLibcMspaceCreate` is consistent with what we see, and the reservation here is `0x200000000` + 16 GiB (`MAP_FIXED_NOREPLACE`, `PROT_NONE`, `MAP_NORESERVE`, then aligned `MAP_FIXED` chunks), so both `MapPlaced()` users - direct memory and flexible memory - land inside your first accepted window (`base >= 0x400000`, `base + capacity < 0xFC00000001`). If you would rather land a Linux-arena PR for the flexible-memory side, say so and I will keep #780 to the direct memory path and rebase onto yours. Progress this unblocked: the start-up assert is gone and the title now reaches on-screen output - the PS boot logo and the publisher (MCS) logo, holding ~60 FPS, with `vo` 459 / `agc` 204 / `pm4` 900, which are the same counts the working Windows build of the same commit produces.
jeffrey12cali commented 2026-10-10 11:07:36 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jeffrey12cali on 2026-10-10T11:07:36Z.


Closing the loop on this issue: #861 merged today, so the direct-memory case in the title is fixed on main —
addr == NULL mappings inside the PS5 window now land in the low arena instead of getting a top-down address.

I want to be precise about what that does and does not cover, because @alfalfa-star's report is a different
mechanism. #861 places the guest address space; it does not change how flexible memory allocates. So the
PPSA14632 symptom described above (bundled libc.prx and libSceNpCppWebApi.prx, segfault in the online
subsystem while preparing sceNpSessionSignalInvitation) is not something I have tested and I am not claiming
this issue covers it. If anyone can retest that title on current main, it is worth knowing whether the
failure is now the same one or a separate flexible-memory gap.

For our own reference on the direct-memory side: PPSA28997 reaches its main menu and holds 60 FPS through 15
minutes of continuous play on a tree that carries this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6096855293 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/692#issuecomment-6096855293). Originally posted by [jeffrey12cali](https://github.com/jeffrey12cali) on 2026-10-10T11:07:36Z. --- Closing the loop on this issue: #861 merged today, so the direct-memory case in the title is fixed on `main` — `addr == NULL` mappings inside the PS5 window now land in the low arena instead of getting a top-down address. I want to be precise about what that does and does not cover, because @alfalfa-star's report is a different mechanism. #861 places the guest address space; it does not change how flexible memory allocates. So the `PPSA14632` symptom described above (bundled `libc.prx` and `libSceNpCppWebApi.prx`, segfault in the online subsystem while preparing `sceNpSessionSignalInvitation`) is not something I have tested and I am not claiming this issue covers it. If anyone can retest that title on current `main`, it is worth knowing whether the failure is now the same one or a separate flexible-memory gap. For our own reference on the direct-memory side: `PPSA28997` reaches its main menu and holds 60 FPS through 15 minutes of continuous play on a tree that carries this change.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#692
No description provided.