feat(json2): implement sce::Json values, strings, arrays, objects, parser and null-access callback
- **Layouts:** `String`, `Array`, `Object` and `Value` are pointer-sized handles to host-side storage. The title stores `String`/`Array`/`Object` at an 8-byte stride and `Value` in 0x20-byte slots, so none of them can be bigger. The pair an `Object::iterator` dereferences to has its key at +0x00 and its `Value` at +0x10, which the title reads directly. Array and object iterators are 8 bytes.
- **Parser:** a strict RFC 8259 parser.
- Numbers: integers that fit `int64` become `Integer`, larger non-negative ones `UInteger`, and everything else `Real`.
- Strings: `\u` escapes, including surrogate pairs, are decoded to UTF-8.
- Errors: on any error `parse` returns a negative code (`0x80920101`) and leaves the target value untouched.
- **Serialisation:** compact output. Strings are escaped; reals use `%.17g`, and a non-finite real throws.
- **Null access:** a typed getter on a value of another type, a missing key or an out-of-range index goes through the null-access callback. The callback's result is used when its type matches (any type for `operator[]`). Otherwise a static default value of the requested type is returned. `terminate` clears the callback.
- **Integer getters:** `getInteger`/`getUInteger`/`getReal` convert between the integer kinds and to real where the value fits.
- `setGlobalNullAccessCallBack` (NID `00oCq0RwSAY`) was identified by hashing its mangled name.
- `MemAllocator`'s base constructor and destructor install the abstract class's vtable. A derived allocator replaces it with its own, so its entries (which throw, like a pure virtual call) run only if a pure virtual is called. `Initializer::initialize` throws on a null parameter instead of silently accepting it.
- Mutating a value that isn't the expected type (`referArray` on a string, etc.) throws.
feat(libkernel): pread, pwrite, getdents and getdirentries on linux
- **pread/pwrite:** use the existing `NativePread`/`NativePwrite` and don't move the file offset. A null buffer with a non-zero size returns `EFAULT`, a negative offset `EINVAL`, and host failures go through `SceErrorFromErrno`.
- **getdirentries:**
- reads host `getdents64` records and converts them to the FreeBSD `struct dirent` layout the guest expects (`d_fileno` u32, `d_reclen` u16, `d_type` u8, `d_namlen` u8, NUL-terminated name, record padded to 4 bytes);
- `*basep` gets the directory position from before the read;
- when a record doesn't fit in the guest buffer, the descriptor is moved with `lseek` back to that entry's cookie, so the next call resumes there;
- if not even the first record fits, the call returns `EINVAL` without consuming anything, and a name longer than 255 bytes returns `ENAMETOOLONG`.
- **getdents** is `getdirentries` without `basep`.
- Adds the guest `EFAULT`, `EINVAL` and `ENAMETOOLONG` constants.
feat(relinker): lower register-form EXTRQ and relocate following instructions for short sites
- **Lowering:** register-form EXTRQ is emitted out of line with SSE2 only. Two scratch XMM registers (distinct from both operands) are spilled; one gets the index (`src >> 8 & 63`), the other `(64 - length) & 63` (`length` masked to 6 bits, so 0 means 64). The destination is shifted right by the index, then left and right by the complement, which keeps the low `length` bits. INSERTQ register form is still reported as unsupported.
- **Short sites:** when a site is shorter than a `jmp rel32`, the converter extends it over the instructions that follow it until it's 5 bytes long:
- following EXTRQ/INSERTQ instructions (before any other instruction) are lowered into the same stub, via a new `MatchSequence`;
- other instructions are copied after the lowered body (`LowerOutOfLine`'s new `trailing` bytes), but only if they're sequential, have no RIP-relative operand and no branch target;
- anything else (a return, a branch, RIP-relative code, the segment ending) still fails the relink, as does a branch target inside the extended site.
- `docs/TechnicalDebt.md` now lists only the INSERTQ register form, MONITORX/MWAITX/CLZERO/RDPRU/MCOMMIT and SHA-NI.
feat(userservice): user name, user number and accessibility settings of the initial user
They report the initial user, following `sceUserServiceGetGamePresets`:
- **Name:** `Player`. A buffer shorter than 17 bytes returns `SCE_USER_SERVICE_ERROR_BUFFER_TOO_SHORT` (`0x8096000A`).
- **User number:** 1.
- **Accessibility settings:** 0, the setting-off value on a fresh console.
fix(libc): don't walk guest frame pointers when reporting an unhandled exception
Only log __builtin_return_address(0), which doesn't depend on the guest's frames. After the fix, the log prints the exception type and the terminate handler prints what().
feat(libc): mspace memalign, malloc stats, thread-unsafe flag and nested mspaces
- Memalign uses the existing aligned allocation.
- Stats fill `SceLibcMallocManagedSize` (size checked against 0x28) from new `inUse`/`peakInUse` counters on the arena. The system size is the arena's extent.
- The thread-unsafe flag is accepted: the implementation always locks, so skipping locks is only an optimisation it doesn't need. Other flags are still rejected.
- An overlapping create is allowed only when the new range lies entirely inside a live block of the other mspace. Every other overlap is still rejected.
feat(libkernel): hinted and no-overwrite mappings, virtual range names and usleep
- **Non-fixed mapping with an address hint:** `MapAligned` threw `Non-fixed mapping address hints are not implemented`. On the PS5 the hint is where the search starts. On Linux the mapping is now placed at the first free, aligned range at or above the hint, found from `/proc/self/maps` and mapped with `MAP_FIXED_NOREPLACE` so nothing existing can be replaced. `RequireAvailable` is now only checked for fixed mappings, because a hint may point at used memory. Windows still throws.
- **`SCE_KERNEL_MAP_NO_OVERWRITE` (`0x80`):** it was rejected as an unknown flag. With `MAP_FIXED` on Linux it maps with `MAP_FIXED_NOREPLACE`, and it no longer takes the "remap fixed into registered" path, so it fails instead of replacing a registered range. The unsupported-flags error now includes the flag value.
- **Virtual range names:** `sceKernelSetVirtualRangeName` was `NotImplemented` and `sceKernelClearVirtualRangeName` wasn't exported. Names are now kept in a registry, split and trimmed on overlap. `sceKernelVirtualQuery` reports the name and splits its reported region at name boundaries. `sceKernelMapNamedDirectMemory` and `sceKernelMapNamedFlexibleMemory` now name the range instead of ignoring the name.
- **`usleep`** is exported (POSIX, beside `nanosleep`).
feat(input): support game controllers and configurable bindings
- Add optional per-game keyboard and mouse bindings through `anyps5-input.ini` or `ANYPS5_INPUT_CONFIG`. Unspecified actions keep their built-in bindings, and repeated action entries provide alternatives.
- Keep wheel presses and focus-loss state handling compatible with dynamically sized bindings. Report configuration errors through the existing video and pad failure path.
- Document the format and remove the resolved input-mapping debt item.
fix(relinker): report buffered output write failures
Small buffered writes can report success even when flushing fails. Both FileWriter::Write overloads now close the stream before checking for errors.
Added Linux regression tests using /dev/full. Both fail before the fix
fix(recompiler): widen constants of 64-bit operands instead of repeating them
TranslationContext::readU32Pair builds a 64-bit source from two 32-bit reads, taking the high half from offsetOperand(operand, 1). For registers that is the next register. For a literal or an inline constant, offsetOperand returns the same operand, so the constant ended up in both halves: the literal L was read as L:L instead of 0:L.
feat(libc): sscanf_s on linux
sscanf_s was a NotImplemented placeholder in libc/Export.cpp, and a retail title uses it to parse strings. It's now implemented on Linux. Windows still throws NotImplemented.
feat(agc): emit indexed indirect draws
This implements `sceAgcDcbDrawIndexIndirect` and `sceAgcDcbDrawIndexIndirectMulti`. They were stubs that aborted with "not implemented".
They follow the existing non-indexed `sceAgcDcbDrawIndirect` / `DrawIndirectMulti`:
- `DrawIndexIndirect` emits `DRAW_INDEX_INDIRECT` (0x25): data offset, base vertex / start instance SGPR locations, draw initiator (5 dwords, matching `GetSize` = 20).
- `DrawIndexIndirectMulti` emits `DRAW_INDEX_INDIRECT_MULTI` (0x38): the same fields, plus the draw-index location / count-indirect control word, count, count address and stride (10 dwords, matching `GetSize` = 40). The stride must be at least 20, the size of an indexed record.
fix: support SDK startup, linear framebuffers and indexed draws
Fix SDK startup with an empty allocator replacement table, add linear framebuffer presentation through the current presentation path, and implement explicit indexed draws with packet validation. Retain buffer-address regression coverage for the correction already upstream, and restrict the POSIX exception-runtime test to Unix so Windows test builds succeed.
Also fix two issues reproduced after rebasing: render-target format lookup probed unsupported formats by repeatedly throwing exceptions, costing about 78 ms per draw; the lookup now searches supported entries directly. Recorder buffers now use Windows FLS cleanup to avoid MinGW freeing emulated TLS storage before running their destructors. Cross-DLL tests check independent values and destruction on standard and native Windows threads.
Ported from shadPS4 (GPL-2.0-or-later) with system fonts removed, stubs made to throw,
and sceFontCloseFont implemented.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ButHENCbXXt8h4EZuWUabJ
GuestModuleWriter::WriteLinux adds read permission to every PT_LOAD, including
the SCE dynlib data segment, which has no flags and is never mapped on the PS5.
When that segment starts inside the last page of the preceding RW segment, the
read-only mapping covers the tail of its bss and the module's initializer faults
on its first write there. The symbol and relocation tables it holds are already
copied into the appended segment, so it no longer needs to be mapped.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ButHENCbXXt8h4EZuWUabJ
The host-region fallback added with the Demon's Souls work calls VirtualQuery and
includes windows.h unconditionally, so libkernel no longer compiles on Linux.
On Linux, read the containing mapping and its permissions from /proc/self/maps.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ButHENCbXXt8h4EZuWUabJ