feat(libkernel_sys): implement symlink #3491

Merged
babyhuey merged 1 commit from upstream-pr/3491 into main 2026-10-11 11:54:52 +00:00
babyhuey commented 2026-10-11 11:35:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T11:35:17Z.


What

Exports symlink (waIF+5fE5HQ) from libkernel_sys, the module titles import it from, next to readlink and link. The target text is stored as given, so readlink returns it unchanged, and a link to a missing target is allowed, as on FreeBSD. On the host it is a directory symlink when the target is an existing directory and a file symlink otherwise. Windows calls CreateSymbolicLinkW with SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE, since MinGW's std::filesystem::create_symlink returns ENOSYS there; Linux uses std::filesystem. Errors return -1 with errno:

  • a null argument gives EFAULT and an empty one ENOENT
  • a new name that already exists gives EEXIST
  • a missing directory for the new name gives ENOENT
  • on Windows, when the process can't create symbolic links (no Developer Mode or SeCreateSymbolicLinkPrivilege), EPERM

An absolute target throws (NotImplemented): a guest absolute path such as /app0/... would point at the wrong place once stored on the host. Any other host failure throws as well.

PS5VR (PPSA99177) stops at it on main 0f863c10, now that fstatfs (#3439) is in (catalog build, eboot.bin and sce_module/libc.prx unwrapped as #2605 requires; tracked in #1578):

  • Linux: app.elf: symbol lookup error: app.elf: undefined symbol: waIF+5fE5HQ
  • Windows, with #3439 before it merged: FAIL: unresolved ELF import waIF+5fE5HQ (symlink) from libkernel_sys.prx
  • with this PR, Linux and Windows: PS5VR loads every import, creates its Vulkan device and stops in AGC with sceAgcCreatePrimState: invalid user configuration register offsets

Tested

Linux (Ubuntu 24.04, GCC 13), Release: guest_kernel_sys passes 5/5 (--repeat until-fail:5). The new cases create a relative link and read it back with readlink, check it resolves to the same file, create a dangling link, and check each error above through errno. Where symbolic links can't be created (Windows without the privilege), the test checks for EPERM and skips the success cases, as #3169 does for lstat. check_conventions.py passes. Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release, Developer Mode off and not elevated: guest_kernel_sys passes 5/5 with no warnings; CreateSymbolicLinkW returns ERROR_PRIVILEGE_NOT_HELD, so the test checks EPERM and skips the success cases. The success cases have only run on Linux. The first head used create_symlink, which fails on Windows with ENOSYS.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818754936 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3491). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T11:35:17Z. --- ### What Exports `symlink` (`waIF+5fE5HQ`) from libkernel_sys, the module titles import it from, next to `readlink` and `link`. The target text is stored as given, so `readlink` returns it unchanged, and a link to a missing target is allowed, as on FreeBSD. On the host it is a directory symlink when the target is an existing directory and a file symlink otherwise. Windows calls `CreateSymbolicLinkW` with `SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE`, since MinGW's `std::filesystem::create_symlink` returns `ENOSYS` there; Linux uses `std::filesystem`. Errors return -1 with `errno`: - a null argument gives `EFAULT` and an empty one `ENOENT` - a new name that already exists gives `EEXIST` - a missing directory for the new name gives `ENOENT` - on Windows, when the process can't create symbolic links (no Developer Mode or `SeCreateSymbolicLinkPrivilege`), `EPERM` An absolute target throws (`NotImplemented`): a guest absolute path such as `/app0/...` would point at the wrong place once stored on the host. Any other host failure throws as well. PS5VR (PPSA99177) stops at it on `main` 0f863c10, now that `fstatfs` (#3439) is in (catalog build, `eboot.bin` and `sce_module/libc.prx` unwrapped as #2605 requires; tracked in #1578): - Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: waIF+5fE5HQ` - Windows, with #3439 before it merged: `FAIL: unresolved ELF import waIF+5fE5HQ (symlink) from libkernel_sys.prx` - with this PR, Linux and Windows: PS5VR loads every import, creates its Vulkan device and stops in AGC with `sceAgcCreatePrimState: invalid user configuration register offsets` ### Tested Linux (Ubuntu 24.04, GCC 13), Release: `guest_kernel_sys` passes 5/5 (`--repeat until-fail:5`). The new cases create a relative link and read it back with `readlink`, check it resolves to the same file, create a dangling link, and check each error above through `errno`. Where symbolic links can't be created (Windows without the privilege), the test checks for `EPERM` and skips the success cases, as #3169 does for `lstat`. `check_conventions.py` passes. Windows 11 (MinGW-w64 GCC 15.2 from WinLibs), Release, Developer Mode off and not elevated: `guest_kernel_sys` passes 5/5 with no warnings; `CreateSymbolicLinkW` returns `ERROR_PRIVILEGE_NOT_HELD`, so the test checks `EPERM` and skips the success cases. The success cases have only run on Linux. The first head used `create_symlink`, which fails on Windows with `ENOSYS`. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 11:35:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T11:35:41Z.


Progress report (0f863c1 → 6bc537c)

📉 System libraries: 85.72% (-0.02%, +1 declared functions)

🆕 1 declared as stubs
Library Name
libkernel_sys symlink_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108599683 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3491#issuecomment-6108599683). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T11:35:41Z. --- <!-- progress-report --> ### Progress report (0f863c1 → 6bc537c) 📉 **System libraries**: 85.72% (-0.02%, +1 declared functions) <details> <summary>🆕 1 declared as stubs</summary> | Library | Name | | - | - | | libkernel_sys | `symlink_nid_postfix` | </details>
adriadam10 commented 2026-10-11 11:54:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T11:54:42Z.


Checked build and guest_kernel_sys on Linux (libs scope, 18/18 pass); the new cases don't link without the change. symlink follows link (EFAULT/ENOENT/EEXIST, absolute targets and other host failures throw). The Windows privilege path is code-reviewed only. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108749260 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3491#issuecomment-6108749260). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T11:54:42Z. --- Checked build and `guest_kernel_sys` on Linux (libs scope, 18/18 pass); the new cases don't link without the change. `symlink` follows `link` (EFAULT/ENOENT/EEXIST, absolute targets and other host failures throw). The Windows privilege path is code-reviewed only. Merging.
screamm commented 2026-10-11 12:01:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T12:01:08Z.


Windows validation of the current head 6bc537ce merged onto main 0f863c10 (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, Developer Mode on, full build including libs):

guest_kernel_sys aborts at the first symlink call:

what():  symlink: Function not implemented

(exit 0xc0000409). The cause is std::filesystem::create_symlink / create_directory_symlink: on this MinGW-w64 toolchain they fail with std::errc::function_not_supported (generic 40), which the export then throws instead of reaching its EPERM branch. A standalone program built with the same g++ shows the same. The existing readlink symlink cases in GuestKernelSys.cpp are already skipped on MinGW for that reason.

A working Windows path is CreateSymbolicLinkW(link, target, SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE | (directory ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0)), mapping ERROR_PRIVILEGE_NOT_HELD to EPERM and ERROR_ALREADY_EXISTS/ERROR_FILE_EXISTS to EEXIST; lstat already recognises the resulting reparse point since #2898, so the round trip can be tested here. Happy to rerun once the branch is updated.

Validation run with Claude Code assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108800096 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3491#issuecomment-6108800096). Originally posted by [screamm](https://github.com/screamm) on 2026-10-11T12:01:08Z. --- Windows validation of the current head `6bc537ce` merged onto `main` `0f863c10` (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, Developer Mode on, full build including `libs`): `guest_kernel_sys` aborts at the first symlink call: ``` what(): symlink: Function not implemented ``` (exit `0xc0000409`). The cause is `std::filesystem::create_symlink` / `create_directory_symlink`: on this MinGW-w64 toolchain they fail with `std::errc::function_not_supported` (generic 40), which the export then throws instead of reaching its `EPERM` branch. A standalone program built with the same `g++` shows the same. The existing readlink symlink cases in `GuestKernelSys.cpp` are already skipped on MinGW for that reason. A working Windows path is `CreateSymbolicLinkW(link, target, SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE | (directory ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0))`, mapping `ERROR_PRIVILEGE_NOT_HELD` to `EPERM` and `ERROR_ALREADY_EXISTS`/`ERROR_FILE_EXISTS` to `EEXIST`; `lstat` already recognises the resulting reparse point since #2898, so the round trip can be tested here. Happy to rerun once the branch is updated. Validation run with Claude Code assistance.
screamm commented 2026-10-11 12:23:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T12:23:38Z.


Follow-up now that this is merged: on main 1e8fff68 (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Release, full build) guest_kernel_sys is red, deterministically, with the failure reported above:

[libc] unhandled exception 'St12system_error' thrown from 00007ff86b35fe86
terminate called after throwing an instance of 'std::runtime_error'
  what():  symlink: Function not implemented

std::filesystem::create_symlink is not implemented in this MinGW-w64 libstdc++, so every Windows symlink call throws. A fix branch using CreateSymbolicLinkW (unprivileged-create flag, directory flag when the target is a directory, ERROR_PRIVILEGE_NOT_HELD → EPERM, existing names → EEXIST) with a real Windows round trip in the test is being prepared and will be linked from here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108981600 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3491#issuecomment-6108981600). Originally posted by [screamm](https://github.com/screamm) on 2026-10-11T12:23:38Z. --- Follow-up now that this is merged: on `main` `1e8fff68` (Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Release, full build) `guest_kernel_sys` is red, deterministically, with the failure reported above: ``` [libc] unhandled exception 'St12system_error' thrown from 00007ff86b35fe86 terminate called after throwing an instance of 'std::runtime_error' what(): symlink: Function not implemented ``` `std::filesystem::create_symlink` is not implemented in this MinGW-w64 libstdc++, so every Windows `symlink` call throws. A fix branch using `CreateSymbolicLinkW` (unprivileged-create flag, directory flag when the target is a directory, `ERROR_PRIVILEGE_NOT_HELD` → `EPERM`, existing names → `EEXIST`) with a real Windows round trip in the test is being prepared and will be linked from here.
screamm commented 2026-10-11 12:28:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-11T12:28:59Z.


The fix is babyhuey's open #3510; my Developer-Mode-on validation and two remaining points are posted there, so no separate branch from me.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6109025359 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3491#issuecomment-6109025359). Originally posted by [screamm](https://github.com/screamm) on 2026-10-11T12:28:59Z. --- The fix is babyhuey's open #3510; my Developer-Mode-on validation and two remaining points are posted there, so no separate branch from me.
Sign in to join this conversation.
No reviewers
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!3491
No description provided.