feat(libkernel): honour RTLD_NODELETE and RTLD_NOLOAD in dlopen, as FreeBSD 11 rtld does #27297

Merged
kiansaeidnia merged 1 commit from upstream-pr/27297 into main 2026-11-28 00:01:52 +00:00
kiansaeidnia commented 2026-11-25 19:08:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kiansaeidnia on 2026-11-25T19:08:57Z.


What

dlopen refused every flag outside the mode and RTLD_GLOBAL. It now accepts RTLD_NODELETE (0x1000) and RTLD_NOLOAD (0x2000), with the meanings FreeBSD 11 rtld gives them through RTLD_LO_NODELETE and RTLD_LO_NOLOAD:

  • RTLD_NOLOAD returns a new referenced handle only for an image the process already has loaded (GetModuleHandleExW on Windows, the host RTLD_NOLOAD elsewhere). As rtld load_object does, a miss on an existing file returns NULL and leaves dlerror untouched; a file that does not exist sets a "was not found" message.
  • RTLD_NODELETE pins the host image (GET_MODULE_HANDLE_EX_FLAG_PIN on Windows, the host RTLD_NODELETE elsewhere), and the last dlclose keeps its guest image registration.

Other bits, such as RTLD_TRACE, still return NULL with a dlerror message. A new libkernel Functional debt entry records them, together with the Windows RTLD_NOLOAD lookup that matches by path or base name rather than by file identity.

Tested

Windows 11, MinGW-w64 GCC 16.2, Release: guest_dynamic_loader and guest_dynamic_loader_variant_names pass. The new checks in GuestDynamicLoader.cpp cover:

  • RTLD_NOLOAD before the module is loaded returns NULL with no dlerror, also with RTLD_NODELETE.
  • RTLD_NOLOAD on a missing file sets "was not found".
  • RTLD_TRACE, 0x4000 and mode 3 with RTLD_NOLOAD are still refused with a message.
  • RTLD_NOLOAD on a loaded module returns a second handle that resolves the same symbol and keeps the image alive after the first handle is closed.
  • After RTLD_NODELETE, closing every handle leaves the code callable and the guest image registration unchanged, and a later RTLD_NOLOAD finds it.

DynamicLoader.cpp and the test were syntax-checked with g++ 11 on Linux (WSL Ubuntu); the Linux and macOS paths have not been run here.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5497484140 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27297). Originally posted by [kiansaeidnia](https://github.com/kiansaeidnia) on 2026-11-25T19:08:57Z. --- ### What `dlopen` refused every flag outside the mode and `RTLD_GLOBAL`. It now accepts `RTLD_NODELETE` (0x1000) and `RTLD_NOLOAD` (0x2000), with the meanings FreeBSD 11 rtld gives them through `RTLD_LO_NODELETE` and `RTLD_LO_NOLOAD`: - `RTLD_NOLOAD` returns a new referenced handle only for an image the process already has loaded (`GetModuleHandleExW` on Windows, the host `RTLD_NOLOAD` elsewhere). As rtld `load_object` does, a miss on an existing file returns NULL and leaves `dlerror` untouched; a file that does not exist sets a "was not found" message. - `RTLD_NODELETE` pins the host image (`GET_MODULE_HANDLE_EX_FLAG_PIN` on Windows, the host `RTLD_NODELETE` elsewhere), and the last `dlclose` keeps its guest image registration. Other bits, such as `RTLD_TRACE`, still return NULL with a `dlerror` message. A new libkernel Functional debt entry records them, together with the Windows `RTLD_NOLOAD` lookup that matches by path or base name rather than by file identity. ### Tested Windows 11, MinGW-w64 GCC 16.2, Release: `guest_dynamic_loader` and `guest_dynamic_loader_variant_names` pass. The new checks in `GuestDynamicLoader.cpp` cover: - `RTLD_NOLOAD` before the module is loaded returns NULL with no `dlerror`, also with `RTLD_NODELETE`. - `RTLD_NOLOAD` on a missing file sets "was not found". - `RTLD_TRACE`, 0x4000 and mode 3 with `RTLD_NOLOAD` are still refused with a message. - `RTLD_NOLOAD` on a loaded module returns a second handle that resolves the same symbol and keeps the image alive after the first handle is closed. - After `RTLD_NODELETE`, closing every handle leaves the code callable and the guest image registration unchanged, and a later `RTLD_NOLOAD` finds it. `DynamicLoader.cpp` and the test were syntax-checked with g++ 11 on Linux (WSL Ubuntu); the Linux and macOS paths have not been run here. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-25 19:17:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T19:17:42Z.

Review: COMMENTED


Reviewed — no blocking findings

No verified blocking defect was found in the inspected changes; the reported Windows tests were not run in this review.

What I ran

Reviewed head 1f4afa20c9048ac96ce421dc88436891153124f8 using the prepared diff and repo_read.py at the pinned head. No commands or tests were run.

Results

Check Result Note
Diff review passed Three changed files inspected
Programmatic checks not run Windows results are author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

The test suite and runtime behavior were not independently verified. The PR description reports Windows 11 tests and Linux syntax checks; Linux and macOS runtime paths were not reported as run. The full contents of the changed files were not read; targeted portions relevant to the diff were inspected. files.json was not available through the reader, so its excluded-file list was not verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6063568083 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/27297#pullrequestreview-6063568083). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T19:17:42Z. **Review:** COMMENTED --- # Reviewed — no blocking findings No verified blocking defect was found in the inspected changes; the reported Windows tests were not run in this review. ## What I ran Reviewed head `1f4afa20c9048ac96ce421dc88436891153124f8` using the prepared diff and `repo_read.py` at the pinned head. No commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff review | passed | Three changed files inspected | | Programmatic checks | not run | Windows results are author-reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The test suite and runtime behavior were not independently verified. The PR description reports Windows 11 tests and Linux syntax checks; Linux and macOS runtime paths were not reported as run. The full contents of the changed files were not read; targeted portions relevant to the diff were inspected. `files.json` was not available through the reader, so its excluded-file list was not verified. ## To get this to a good state Nothing is required.
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!27297
No description provided.