Relinked executable lies outside the guest arena, so JITs cannot reserve memory near their code (PS5CEMU-HAR's Azahar) #5217

Closed
opened 2026-10-13 14:54:08 +00:00 by YossiYad · 5 comments
YossiYad commented 2026-10-13 14:54:08 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-13T14:54:08Z.


PS5CEMU-HAR (PPSA99360, catalog 3.5.0) cannot start its 3DS emulator: Azahar's JIT wants its code buffer within 2 GiB of the executable's code, and the relinked executable is loaded at a host address outside the guest arena, so no guest mapping can be that close.

How it shows up. Linux (Fedora 44 distrobox, GCC 16, Release), RX 7700 XT, main 0f2683cb with #4514, #4469 and #4467 applied (the title's three earlier stops; #3787 is merged). The launcher runs at 60 fps. Launching ftpd.3dsx (mtheall/ftpd v3.2.1, GPL) from the 3DS side:

  • On that stack: what(): mapping address hint is above the guest address space arena. The core dump shows the title's code calling sceKernelReserveVirtualRange with no MAP_FIXED and the hint 0x564c90000000, from a loop that steps 64 MiB at a time through the 2 GiB around its code (DoReserveVirtual → MapPlaced → GuestArenaAllocateAtOrAbove).
  • With the hint handled as FreeBSD 11.4 does (#5218, retry from the bottom of the map through vm_map_find_min), nothing throws: the reservation lands inside the arena, the title's allocator finds it too far from its code, and it reports ftpd pro did not start: Azahar did not start: can't alloc (Xbyak's allocation error) and returns to its library.

Why. On the console the executable sits low in the application area, so a hint derived from a code address is an ordinary guest address. Here the relinked app.elf is a host PIE (0x564c... in this run), above the arena's end at 0xFC00000000. Fixed mappings outside the arena are refused (fixed mapping is outside the guest address space arena), so the title cannot place its JIT memory near its code either way.

The same applies to any title or emulator whose JIT uses rel32 calls into its own executable (dynarmic and Xbyak-based code buffers do), and Cemu on the Wii U side of the same title reserves through the same path (port/cemu/MemMapperPS5.cpp).

Question for the maintainers. Should the executable (and its modules) be loaded inside the guest arena, where the console would place them, or should mappings near a host-loaded executable be allowed outside the arena? Both touch the loader and the arena's guarantees, so I have not started on either.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5832547128 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5217). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-13T14:54:08Z. --- PS5CEMU-HAR (PPSA99360, catalog 3.5.0) cannot start its 3DS emulator: Azahar's JIT wants its code buffer within 2 GiB of the executable's code, and the relinked executable is loaded at a host address outside the guest arena, so no guest mapping can be that close. **How it shows up.** Linux (Fedora 44 distrobox, GCC 16, Release), RX 7700 XT, `main` `0f2683cb` with #4514, #4469 and #4467 applied (the title's three earlier stops; #3787 is merged). The launcher runs at 60 fps. Launching `ftpd.3dsx` (mtheall/ftpd v3.2.1, GPL) from the 3DS side: - On that stack: `what(): mapping address hint is above the guest address space arena`. The core dump shows the title's code calling `sceKernelReserveVirtualRange` with no `MAP_FIXED` and the hint `0x564c90000000`, from a loop that steps 64 MiB at a time through the 2 GiB around its code (`DoReserveVirtual` → `MapPlaced` → `GuestArenaAllocateAtOrAbove`). - With the hint handled as FreeBSD 11.4 does (#5218, retry from the bottom of the map through `vm_map_find_min`), nothing throws: the reservation lands inside the arena, the title's allocator finds it too far from its code, and it reports `ftpd pro did not start: Azahar did not start: can't alloc` (Xbyak's allocation error) and returns to its library. **Why.** On the console the executable sits low in the application area, so a hint derived from a code address is an ordinary guest address. Here the relinked `app.elf` is a host PIE (`0x564c...` in this run), above the arena's end at `0xFC00000000`. Fixed mappings outside the arena are refused (`fixed mapping is outside the guest address space arena`), so the title cannot place its JIT memory near its code either way. The same applies to any title or emulator whose JIT uses `rel32` calls into its own executable (dynarmic and Xbyak-based code buffers do), and Cemu on the Wii U side of the same title reserves through the same path (`port/cemu/MemMapperPS5.cpp`). **Question for the maintainers.** Should the executable (and its modules) be loaded inside the guest arena, where the console would place them, or should mappings near a host-loaded executable be allowed outside the arena? Both touch the loader and the arena's guarantees, so I have not started on either.
MarcZX10 commented 2026-10-13 15:01:31 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T15:01:31Z.


I traced the current Linux path to clarify the scope of #5218. GuestArena reserves the console application interval (0x2_0000_0000 through 0xfc00_000000) and records existing host mappings there as occupied. MapPlaced then allocates non-fixed guest mappings from that arena. So the fallback in #5218 can make the reservation succeed, but it cannot put the result within 2 GiB of a PIE executable mapped above the arena, as in the reported 0x564c... run. Simply allowing arbitrary out-of-arena mappings would also need defined behavior for guest containment, protection, unmap, and memory tracking. This looks like a separate loader/address-space design decision: constrain the host executable placement into a suitable guest range, or add a separately tracked near-code mapping region. I have not established which is compatible across Linux, Windows, and macOS.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148534311 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5217#issuecomment-6148534311). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T15:01:31Z. --- I traced the current Linux path to clarify the scope of #5218. `GuestArena` reserves the console application interval (`0x2_0000_0000` through `0xfc00_000000`) and records existing host mappings there as occupied. `MapPlaced` then allocates non-fixed guest mappings from that arena. So the fallback in #5218 can make the reservation succeed, but it cannot put the result within 2 GiB of a PIE executable mapped above the arena, as in the reported `0x564c...` run. Simply allowing arbitrary out-of-arena mappings would also need defined behavior for guest containment, protection, unmap, and memory tracking. This looks like a separate loader/address-space design decision: constrain the host executable placement into a suitable guest range, or add a separately tracked near-code mapping region. I have not established which is compatible across Linux, Windows, and macOS.
YossiYad commented 2026-10-13 16:39:15 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by YossiYad on 2026-10-13T16:39:15Z.


A second title that depends on where the executable sits, and it gives the console address: Ruffle Flash (PPSA68091, catalog 1.2.0) segfaults on Linux main 0214069e right after its own Ruffle PS5: jailbreak ok log line.

Its early init (ruffle_ps5_early_init) opens /app0/imports.txt (362 lines, 00000000024d5370 _init_env, ...: the GOT slot of each import, relative to image base 0), reads each line with fscanf("%lx %127s"), and checks *(0x400000 + offset) != 0, printing Ruffle PS5: unresolved import: %s otherwise (cmpq $0x0,0x400000(%rax) at the crash). So it assumes the executable's image base is 0x400000, as the console loads it. Here the relinked app.elf is at 0x55e555760000, so 0x400000 + 0x24d5370 is unmapped and the read faults.

That makes two shapes of the same dependency: PS5CEMU-HAR's JIT wants memory near the code, and Ruffle reads its own GOT at the console's absolute address. Loading the executable at its console base would cover both; a near-code mapping region would cover only the first.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6150426945 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5217#issuecomment-6150426945). Originally posted by [YossiYad](https://github.com/YossiYad) on 2026-10-13T16:39:15Z. --- A second title that depends on where the executable sits, and it gives the console address: Ruffle Flash (PPSA68091, catalog 1.2.0) segfaults on Linux `main` `0214069e` right after its own `Ruffle PS5: jailbreak ok` log line. Its early init (`ruffle_ps5_early_init`) opens `/app0/imports.txt` (362 lines, `00000000024d5370 _init_env`, ...: the GOT slot of each import, relative to image base 0), reads each line with `fscanf("%lx %127s")`, and checks `*(0x400000 + offset) != 0`, printing `Ruffle PS5: unresolved import: %s` otherwise (`cmpq $0x0,0x400000(%rax)` at the crash). So it assumes the executable's image base is `0x400000`, as the console loads it. Here the relinked `app.elf` is at `0x55e555760000`, so `0x400000 + 0x24d5370` is unmapped and the read faults. That makes two shapes of the same dependency: PS5CEMU-HAR's JIT wants memory near the code, and Ruffle reads its own GOT at the console's absolute address. Loading the executable at its console base would cover both; a near-code mapping region would cover only the first.
MarcZX10 commented 2026-10-13 22:18:15 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T22:18:15Z.


The second report strengthens the evidence, but I checked the current allocator and there is a constraint to reconcile before choosing a base. GuestArena.cpp starts the arena at 0x200000000 (8 GiB), and AllocateAtOrAbove clamps lower hints to that start. If the executable were fixed at Ruffle’s 0x400000, a JIT request near its code would still be placed at least about 8 GiB away, beyond the reported 2 GiB search window. Conversely, putting the executable inside the arena would leave Ruffle’s hard-coded 0x400000 + GOT offset reads unmapped unless we also provide a compatible alias or relocation strategy. So these two reports do not appear to be solved by one simple fixed image base; the loader and arena design needs to account for both constraints.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156401004 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5217#issuecomment-6156401004). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T22:18:15Z. --- The second report strengthens the evidence, but I checked the current allocator and there is a constraint to reconcile before choosing a base. `GuestArena.cpp` starts the arena at `0x200000000` (8 GiB), and `AllocateAtOrAbove` clamps lower hints to that start. If the executable were fixed at Ruffle’s `0x400000`, a JIT request near its code would still be placed at least about 8 GiB away, beyond the reported 2 GiB search window. Conversely, putting the executable inside the arena would leave Ruffle’s hard-coded `0x400000 + GOT offset` reads unmapped unless we also provide a compatible alias or relocation strategy. So these two reports do not appear to be solved by one simple fixed image base; the loader and arena design needs to account for both constraints.
0xRickx commented 2026-10-15 15:49:26 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by 0xRickx on 2026-10-15T15:49:26Z.


A third title that needs console-like addresses, in a different shape: Super Mario Sunshine (PPSA99312, catalog 0.10.0, griches/PS5_Sunshine) needs memory below 2 GiB.

On Windows main 92e50418 with #6220 (its earlier uname sysctl stop), it exits 2 s in:

[Super Mario Sunshine] no disc image in the title's folder: copy your GMSE01 .iso, .gcm or .ciso beside eboot.bin
[Super Mario Sunshine] [port] no memory below 2 GiB for the game's stack
[Super Mario Sunshine] exit status 1: asking the shell to close the title

The game code is not published, but the port's probe title is (ps5/probe/memprobe.c). It says the PC port keeps every address the game can see in 32 bits, and it shows what it asks the console for: a plain anonymous mmap with a low hint and no MAP_FIXED (64 MiB at 0x20000000, a 128 MiB stack pool at 0x40000000; the comment notes that the title's libc.prx sits at 0x80000000 and that a hint is taken when the range is free), then pthread_attr_setstack on that pool.

Two things stand in the way here:

  • mmap_nid_postfix drops the hint of a private anonymous mapping without MAP_FIXED (PosixMemory.cpp passes nullptr on to DoMapAnon), so the hint handling from #5218 never sees it.
  • Even with the hint, the arena starts at 0x200000000 (GuestArena.cpp), so nothing below 2 GiB can be returned.

So the address-space decision would need to cover low 32-bit guest mappings too, besides memory near the code (PS5CEMU-HAR) and the image at 0x400000 (Ruffle). I can't check what the port does past this point: the next step needs the user's own disc image.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6196217273 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5217#issuecomment-6196217273). Originally posted by [0xRickx](https://github.com/0xRickx) on 2026-10-15T15:49:26Z. --- A third title that needs console-like addresses, in a different shape: Super Mario Sunshine (PPSA99312, catalog 0.10.0, [griches/PS5_Sunshine](https://github.com/griches/PS5_Sunshine)) needs memory below 2 GiB. On Windows `main` 92e50418 with #6220 (its earlier `uname` sysctl stop), it exits 2 s in: ``` [Super Mario Sunshine] no disc image in the title's folder: copy your GMSE01 .iso, .gcm or .ciso beside eboot.bin [Super Mario Sunshine] [port] no memory below 2 GiB for the game's stack [Super Mario Sunshine] exit status 1: asking the shell to close the title ``` The game code is not published, but the port's probe title is ([`ps5/probe/memprobe.c`](https://github.com/griches/PS5_Sunshine/blob/e01f5db1702ac21f2683666abc10917ff9dd206b/ps5/probe/memprobe.c#L1-L10)). It says the PC port keeps every address the game can see in 32 bits, and it shows what it asks the console for: a plain anonymous `mmap` with a low hint and no `MAP_FIXED` (64 MiB at `0x20000000`, a 128 MiB stack pool at `0x40000000`; the comment notes that the title's `libc.prx` sits at `0x80000000` and that a hint is taken when the range is free), then `pthread_attr_setstack` on that pool. Two things stand in the way here: - `mmap_nid_postfix` drops the hint of a private anonymous mapping without `MAP_FIXED` ([`PosixMemory.cpp`](https://github.com/boykopovar/AnyPS5/blob/92e50418f33b8950ceea950cb37331a941f5be0e/core/libs/prx/libkernel/DirectMemory/PosixMemory.cpp#L116-L119) passes `nullptr` on to `DoMapAnon`), so the hint handling from #5218 never sees it. - Even with the hint, the arena starts at `0x200000000` ([`GuestArena.cpp`](https://github.com/boykopovar/AnyPS5/blob/92e50418f33b8950ceea950cb37331a941f5be0e/core/libs/prx/libc/src/GuestArena.cpp#L40)), so nothing below 2 GiB can be returned. So the address-space decision would need to cover low 32-bit guest mappings too, besides memory near the code (PS5CEMU-HAR) and the image at `0x400000` (Ruffle). I can't check what the port does past this point: the next step needs the user's own disc image. AI-assisted (Claude Code).
QRMOE commented 2026-10-15 16:32:06 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by QRMOE on 2026-10-15T16:32:06Z.


@0xRickx I implemented the low anonymous mapping part in draft #6469, based on current main 0029e62f9. The regression uses the two sizes and hints from the public probe: main returns 0x200000000 / 0x204000000, while the branch returns 0x20000000 / 0x40000000 on this Windows host. Both changes are needed: forwarding mmap’s hint and extending the arena below 8 GiB. Unhinted allocations still start at 8 GiB. Libraries build and 25 related tests pass.

I also found a separate next-step limitation: pthread_attr_setstack stores the supplied address, but scePthreadCreate does not use it on Windows or Linux. This PR only addresses allocation; it does not establish that the game runs or resolve the other titles’ high-loaded PIE/JIT placement.

Title tracking is now #6468, with #6220 and #6469 listed. If you can rerun the title with those patches, please post the next stop there; no disc image or other game assets need to be shared. Full Linux/Windows CI and title confirmation are still pending.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6197089540 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/5217#issuecomment-6197089540). Originally posted by [QRMOE](https://github.com/QRMOE) on 2026-10-15T16:32:06Z. --- @0xRickx I implemented the low anonymous mapping part in draft #6469, based on current main 0029e62f9. The regression uses the two sizes and hints from the public probe: main returns 0x200000000 / 0x204000000, while the branch returns 0x20000000 / 0x40000000 on this Windows host. Both changes are needed: forwarding mmap’s hint and extending the arena below 8 GiB. Unhinted allocations still start at 8 GiB. Libraries build and 25 related tests pass. I also found a separate next-step limitation: pthread_attr_setstack stores the supplied address, but scePthreadCreate does not use it on Windows or Linux. This PR only addresses allocation; it does not establish that the game runs or resolve the other titles’ high-loaded PIE/JIT placement. Title tracking is now #6468, with #6220 and #6469 listed. If you can rerun the title with those patches, please post the next stop there; no disc image or other game assets need to be shared. Full Linux/Windows CI and title confirmation are still pending.
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#5217
No description provided.