Windows: scoped kernel variant imports miss canonical libkernel providers #8853

Closed
opened 2026-10-21 03:13:08 +00:00 by UnhealthyKraken · 6 comments
UnhealthyKraken commented 2026-10-21 03:13:08 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-21T03:13:08Z.


What fails

A synthetic Windows startup import of getpagesize (k+AXqu2-eBc) resolves when qualified to libkernel.prx, but fails when qualified to libkernel_sys.prx or libkernel_web.prx, even with canonical libkernel and libc explicitly loaded. Unqualified lookup with those same modules succeeds. The guest entry only returns zero; it does not invoke the import. No title, firmware binary or proprietary trace was used.

Reproduction and results

Windows x86-64, GCC 15.2 Release. Relinker source is current main e0e57a3270d3de4466266c06254a516cfe1cd7e2; local head aae12fa111174f7d27af06c96ec0e47ccae3c2c1 additionally contains unrelated cfsetspeed changes, with no relinker changes. Libraries built locally from public source.

Generate a PE using the existing WindowsImportBuilder, WindowsEntryStubBuilder and WindowsPeWriter. Set a strong PeImport to {.Name="k+AXqu2-eBc", .TargetRva=got.Rva, .Addend=0, .Library=scope} and load {requested, "libkernel.prx", "libc.prx"} (deduplicating canonical libkernel). Use eager binding, a writable eight-byte GOT, and an executable guest entry {0x31,0xc0,0xc3}. The current builders supply all startup code. The complete generator is below.

Import scope Result
libkernel.prx exit 0, transfers control to guest entry
libkernel_sys.prx exit 0xc0000139, unresolved import
libkernel_web.prx exit 0xc0000139, unresolved import
empty scope, web/kernel/libc loaded exit 0, transfers control to guest entry

Both failures report GetLastError: 127 and searched libraries containing only the requested variant and libc. PE inspection confirms the NID exists in canonical libkernel and is absent from the variants/libc. An initial attempt failed earlier with missing compiler runtime DLLs; after copying the three MinGW runtime DLLs into this isolated libs directory, the controls and failures above were obtained. Sandbox image loading also required rerunning the generated probes outside the sandbox. Those initial failures are not evidence for this issue.

Evidence and scope

  • Public firmware function inventories list the same name/NID in libkernel_sys and libkernel_web. Public SDK tables also list getpagesize in those variants. These inventories do not establish module/library versions or complete ABI equivalence.
  • WindowsImportBuilder loads canonical kernel for web, but the entry stub search table restricts qualified host imports to their declared module plus libc.
  • #684 deliberately introduced module isolation to prevent wrong guest-provider interception; #6697 adds name-to-NID resolution for unqualified imports. Neither establishes a scoped host kernel-variant alias policy. A broad search of all loaded modules would undo that protection.
  • This demonstrates one NID in two module variants. Thousands of static other-provider associations are only candidates and are not all claimed broken. No Linux execution or PS5 hardware measurement.

Before implementing a fix, the host kernel-variant provider policy needs to be explicit: module-specific forwarding or a narrowly defined host-only alias must preserve requested-provider precedence, guest-module isolation, missing-symbol failure, and initialization/ownership semantics. I have not added duplicate implementations or assumed firmware modules are globally interchangeable.

AI-assisted investigation and reproduction.

Standalone generator (public AnyPS5 headers and relinker_core)
#include <elfpatcher/windows/WindowsEntryStubBuilder.hpp>
#include <elfpatcher/windows/WindowsImportBuilder.hpp>
#include <elfpatcher/windows/WindowsPeWriter.hpp>
#include <io/BufferUtils.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>

int main(int argc, char** argv) {
    if (argc != 3) return 2;
    using namespace Elfpatcher::Windows;
    const auto directory = std::filesystem::absolute(argv[1]);
    const auto runtime = std::filesystem::absolute(argv[2]).string();
    for (const std::string variant : {"libkernel", "libkernel_sys", "libkernel_web", "unscoped_web"}) {
        const auto requested = variant == "unscoped_web" ? "libkernel_web.prx" : variant + ".prx";
        const auto scope = variant == "unscoped_web" ? "" : requested;
        std::vector<std::string> libraries{requested};
        if (requested != "libkernel.prx") libraries.push_back("libkernel.prx");
        libraries.push_back("libc.prx");
        PeSection entry{".guest", LoadRva, SectionRead | SectionExecute | 0x20u, {0x31, 0xc0, 0xc3}};
        PeSection got{".got", LoadRva + 0x1000, SectionRead | SectionWrite | 0x40u, std::vector<std::uint8_t>(8)};
        const auto imports = WindowsImportBuilder().Build(LoadRva + 0x2000);
        const auto startup = WindowsEntryStubBuilder().Build(LoadRva + 0x3000, entry.Rva, imports, libraries,
            {{.Name="k+AXqu2-eBc", .TargetRva=got.Rva, .Addend=0, .Library=scope}}, runtime, false, false);
        std::array<PeDirectory, 16> directories{};
        directories[1] = imports.Directory;
        directories[3] = startup.ExceptionDirectory;
        directories[12] = imports.AddressTable;
        const auto pe = WindowsPeWriter().Write({entry, got, imports.Section, startup.Data, startup.Code}, startup.Code.Rva, directories, false, ImageBase, false);
        std::ofstream file(directory / (variant + ".exe"), std::ios::binary);
        file.write(reinterpret_cast<const char*>(pe.data()), pe.size());
        if (!file) return 3;
        std::cout << variant << ": generated " << pe.size() << " bytes\n";
    }
}

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5953624746 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8853). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-21T03:13:08Z. --- ### What fails A synthetic Windows startup import of `getpagesize` (`k+AXqu2-eBc`) resolves when qualified to `libkernel.prx`, but fails when qualified to `libkernel_sys.prx` or `libkernel_web.prx`, even with canonical libkernel and libc explicitly loaded. Unqualified lookup with those same modules succeeds. The guest entry only returns zero; it does not invoke the import. No title, firmware binary or proprietary trace was used. ### Reproduction and results Windows x86-64, GCC 15.2 Release. Relinker source is current main `e0e57a3270d3de4466266c06254a516cfe1cd7e2`; local head `aae12fa111174f7d27af06c96ec0e47ccae3c2c1` additionally contains unrelated cfsetspeed changes, with no relinker changes. Libraries built locally from public source. Generate a PE using the existing WindowsImportBuilder, WindowsEntryStubBuilder and WindowsPeWriter. Set a strong PeImport to `{.Name="k+AXqu2-eBc", .TargetRva=got.Rva, .Addend=0, .Library=scope}` and load `{requested, "libkernel.prx", "libc.prx"}` (deduplicating canonical libkernel). Use eager binding, a writable eight-byte GOT, and an executable guest entry `{0x31,0xc0,0xc3}`. The current builders supply all startup code. The complete generator is below. | Import scope | Result | | --- | --- | | libkernel.prx | exit 0, transfers control to guest entry | | libkernel_sys.prx | exit 0xc0000139, unresolved import | | libkernel_web.prx | exit 0xc0000139, unresolved import | | empty scope, web/kernel/libc loaded | exit 0, transfers control to guest entry | Both failures report `GetLastError: 127` and searched libraries containing only the requested variant and libc. PE inspection confirms the NID exists in canonical libkernel and is absent from the variants/libc. An initial attempt failed earlier with missing compiler runtime DLLs; after copying the three MinGW runtime DLLs into this isolated libs directory, the controls and failures above were obtained. Sandbox image loading also required rerunning the generated probes outside the sandbox. Those initial failures are not evidence for this issue. ### Evidence and scope - Public firmware function inventories list the same name/NID in [libkernel_sys](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libkernel_sys.c) and [libkernel_web](https://github.com/DNNDHH/PS5-3.20_Libs/blob/b2a77c09cd71c01f34c790cfbe98c751a13262ad/libkernel_web.c). Public SDK tables also list getpagesize in those variants. These inventories do not establish module/library versions or complete ABI equivalence. - [WindowsImportBuilder](https://github.com/boykopovar/AnyPS5/blob/e0e57a3270d3de4466266c06254a516cfe1cd7e2/core/relinker/elfpatcher/src/windows/WindowsImportBuilder.cpp) loads canonical kernel for web, but the [entry stub search table](https://github.com/boykopovar/AnyPS5/blob/e0e57a3270d3de4466266c06254a516cfe1cd7e2/core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp) restricts qualified host imports to their declared module plus libc. - #684 deliberately introduced module isolation to prevent wrong guest-provider interception; #6697 adds name-to-NID resolution for unqualified imports. Neither establishes a scoped host kernel-variant alias policy. A broad search of all loaded modules would undo that protection. - This demonstrates one NID in two module variants. Thousands of static other-provider associations are only candidates and are not all claimed broken. No Linux execution or PS5 hardware measurement. Before implementing a fix, the host kernel-variant provider policy needs to be explicit: module-specific forwarding or a narrowly defined host-only alias must preserve requested-provider precedence, guest-module isolation, missing-symbol failure, and initialization/ownership semantics. I have not added duplicate implementations or assumed firmware modules are globally interchangeable. AI-assisted investigation and reproduction. <details><summary>Standalone generator (public AnyPS5 headers and relinker_core)</summary> ```cpp #include <elfpatcher/windows/WindowsEntryStubBuilder.hpp> #include <elfpatcher/windows/WindowsImportBuilder.hpp> #include <elfpatcher/windows/WindowsPeWriter.hpp> #include <io/BufferUtils.hpp> #include <filesystem> #include <fstream> #include <iostream> int main(int argc, char** argv) { if (argc != 3) return 2; using namespace Elfpatcher::Windows; const auto directory = std::filesystem::absolute(argv[1]); const auto runtime = std::filesystem::absolute(argv[2]).string(); for (const std::string variant : {"libkernel", "libkernel_sys", "libkernel_web", "unscoped_web"}) { const auto requested = variant == "unscoped_web" ? "libkernel_web.prx" : variant + ".prx"; const auto scope = variant == "unscoped_web" ? "" : requested; std::vector<std::string> libraries{requested}; if (requested != "libkernel.prx") libraries.push_back("libkernel.prx"); libraries.push_back("libc.prx"); PeSection entry{".guest", LoadRva, SectionRead | SectionExecute | 0x20u, {0x31, 0xc0, 0xc3}}; PeSection got{".got", LoadRva + 0x1000, SectionRead | SectionWrite | 0x40u, std::vector<std::uint8_t>(8)}; const auto imports = WindowsImportBuilder().Build(LoadRva + 0x2000); const auto startup = WindowsEntryStubBuilder().Build(LoadRva + 0x3000, entry.Rva, imports, libraries, {{.Name="k+AXqu2-eBc", .TargetRva=got.Rva, .Addend=0, .Library=scope}}, runtime, false, false); std::array<PeDirectory, 16> directories{}; directories[1] = imports.Directory; directories[3] = startup.ExceptionDirectory; directories[12] = imports.AddressTable; const auto pe = WindowsPeWriter().Write({entry, got, imports.Section, startup.Data, startup.Code}, startup.Code.Rva, directories, false, ImageBase, false); std::ofstream file(directory / (variant + ".exe"), std::ios::binary); file.write(reinterpret_cast<const char*>(pe.data()), pe.size()); if (!file) return 3; std::cout << variant << ": generated " << pe.size() << " bytes\n"; } } ``` </details>
MarcZX10 commented 2026-10-21 03:34:53 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T03:34:53Z.


I traced the Windows search-table construction. A narrowly testable policy could be: for a scoped import whose requested host library is exactly libkernel_sys.prx or libkernel_web.prx, search that requested module first, then canonical host libkernel.prx if it is loaded, then the existing libc.prx fallback. Keep guest modules out of this alias path and leave unqualified import ordering unchanged. Tests should prove (1) requested variant wins when it has the export, (2) canonical fallback resolves getpagesize when the variant lacks it, (3) missing in both still fails, and (4) a guest provider cannot satisfy this scoped import.

That defines a host-provider fallback rule rather than claiming the firmware variants are interchangeable. The remaining policy question is whether this fallback is acceptable for all canonical libkernel exports or should be restricted to a reviewed allowlist; the current reproduction establishes only getpagesize.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307385952 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8853#issuecomment-6307385952). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T03:34:53Z. --- I traced the Windows search-table construction. A narrowly testable policy could be: for a scoped import whose requested host library is exactly `libkernel_sys.prx` or `libkernel_web.prx`, search that requested module first, then canonical host `libkernel.prx` if it is loaded, then the existing `libc.prx` fallback. Keep guest modules out of this alias path and leave unqualified import ordering unchanged. Tests should prove (1) requested variant wins when it has the export, (2) canonical fallback resolves `getpagesize` when the variant lacks it, (3) missing in both still fails, and (4) a guest provider cannot satisfy this scoped import. That defines a host-provider fallback rule rather than claiming the firmware variants are interchangeable. The remaining policy question is whether this fallback is acceptable for all canonical libkernel exports or should be restricted to a reviewed allowlist; the current reproduction establishes only `getpagesize`.
MarcZX10 commented 2026-10-21 03:43:36 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T03:43:36Z.


I opened #8867 with the narrowly scoped fallback discussed above. It searches the requested kernel variant first, then canonical host libkernel.prx, and adds canonical libkernel to Windows dependencies for both libkernel_sys and libkernel_web. The Linux relinker-only entry_stub test and convention checks pass; hosted checks are starting. The PR does not claim all firmware variant exports are interchangeable.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307496743 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8853#issuecomment-6307496743). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T03:43:36Z. --- I opened #8867 with the narrowly scoped fallback discussed above. It searches the requested kernel variant first, then canonical host `libkernel.prx`, and adds canonical libkernel to Windows dependencies for both `libkernel_sys` and `libkernel_web`. The Linux relinker-only `entry_stub` test and convention checks pass; hosted checks are starting. The PR does not claim all firmware variant exports are interchangeable.
UnhealthyKraken commented 2026-10-21 04:05:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-21T04:05:54Z.


Independently tested #8867 on Windows x86-64, GCC15.2 Release, at exact head fef2755c76cb1f567c82dfeaaf646b88e241c3a6 versus base 7ab4b2e5610c3d4328c83566cba488eb82972c9c in a separate checkout. Same generator source and locally built runtime libraries for both; no games or imported guest functions executed.

The original four generated startup cases now all exit0: canonical scoped, sys scoped, web scoped and unqualified control. With dependency inference from only the requested variant, both scoped getpagesize cases also now pass. The PR's entry_stub and windows_dependency_diagnostics suites pass on Windows (2/2).

Two added cases still fail with0xc0000139 on both base and candidate:

  • DT_NEEDED only libkernel_sys.prx, scoped __error (9BcDykPmo1I).
  • DT_NEEDED only libkernel_web.prx, same scoped import.

The SDK lists __error in all three kernel variants. The locally built provider is shared libc. Candidate ReadLibraries produces [variant, libkernel.prx] for these inputs, so the search table has no explicit libc handle even though the canonical module's dependency loads it. The canonical-only control produces [libkernel.prx, libc.prx] and resolves the same NID successfully.

The libc-insertion condition runs before the inferred canonical dependency is appended. Dependency closure for an inferred kernel therefore leaves the existing shared-runtime fallback unavailable. These are remaining pre-existing failures, not a newly introduced regression; getpagesize is fixed by the proposed patch.

To reproduce with the source generator in the issue, construct SysVDynamicSection with a single DT_NEEDED entry for the variant, obtain libraries from WindowsImportBuilder::ReadLibraries, and use PeImport {.Name="9BcDykPmo1I", .TargetRva=got.Rva, .Addend=0, .Library=variant}. The guest entry remains xor-eax/ret and does not call __error.

Across the nine cases: base3 pass/6 unresolved; candidate7 pass/2 unresolved. Requested-provider precedence has a generated-byte-pattern assertion for sys in the added tests. Guest isolation has no added fixture there, and neither property was independently exercised with colliding native fixture providers in this run. This does not establish equivalence of all firmware variant exports or settle the allowlist policy question.

AI-assisted independent validation; no edits to the contributor's branch or changes to their authorship.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307773524 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8853#issuecomment-6307773524). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-21T04:05:54Z. --- Independently tested #8867 on Windows x86-64, GCC15.2 Release, at exact head `fef2755c76cb1f567c82dfeaaf646b88e241c3a6` versus base `7ab4b2e5610c3d4328c83566cba488eb82972c9c` in a separate checkout. Same generator source and locally built runtime libraries for both; no games or imported guest functions executed. The original four generated startup cases now all exit0: canonical scoped, sys scoped, web scoped and unqualified control. With dependency inference from only the requested variant, both scoped getpagesize cases also now pass. The PR's entry_stub and windows_dependency_diagnostics suites pass on Windows (2/2). Two added cases still fail with0xc0000139 on both base and candidate: - DT_NEEDED only `libkernel_sys.prx`, scoped `__error` (`9BcDykPmo1I`). - DT_NEEDED only `libkernel_web.prx`, same scoped import. The SDK lists __error in all three kernel variants. The locally built provider is shared libc. Candidate ReadLibraries produces `[variant, libkernel.prx]` for these inputs, so the search table has no explicit libc handle even though the canonical module's dependency loads it. The canonical-only control produces `[libkernel.prx, libc.prx]` and resolves the same NID successfully. The libc-insertion condition runs before the inferred canonical dependency is appended. Dependency closure for an inferred kernel therefore leaves the existing shared-runtime fallback unavailable. These are remaining pre-existing failures, not a newly introduced regression; getpagesize is fixed by the proposed patch. To reproduce with the source generator in the issue, construct `SysVDynamicSection` with a single DT_NEEDED entry for the variant, obtain `libraries` from WindowsImportBuilder::ReadLibraries, and use PeImport `{.Name="9BcDykPmo1I", .TargetRva=got.Rva, .Addend=0, .Library=variant}`. The guest entry remains xor-eax/ret and does not call __error. Across the nine cases: base3 pass/6 unresolved; candidate7 pass/2 unresolved. Requested-provider precedence has a generated-byte-pattern assertion for sys in the added tests. Guest isolation has no added fixture there, and neither property was independently exercised with colliding native fixture providers in this run. This does not establish equivalence of all firmware variant exports or settle the allowlist policy question. AI-assisted independent validation; no edits to the contributor's branch or changes to their authorship.
UnhealthyKraken commented 2026-10-21 04:10:55 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-21T04:10:55Z.


Follow-up at the same #8867 head: I added a separate native execution matrix with synthetic colliding DLL providers, using identical generator source for base and candidate. The expected return values are supplied by the fixtures, so these checks exercise binding policy without assuming firmware function behavior.

For each of sys and web, eight cases now execute:

  • Requested variant wins over canonical kernel and libc: returns17.
  • Canonical kernel wins over libc when the variant lacks the export: returns29.
  • Libc remains the last host fallback: returns43.
  • Missing everywhere fails with0xc0000139.
  • A symbol supplied only by an unrelated loaded guest still fails with0xc0000139.
  • With unrelated guest and canonical host both supplying the symbol, scoped import returns29 from the host.
  • Unqualified lookup retains the first guest provider: returns61.
  • A guest module explicitly declaring the variant alias retains its own scoped provider: returns61.

Candidate matches all16 expected outcomes; base matches12/16, returning libc's43 instead of canonical kernel's29 in the four canonical-fallback cases. This adds runtime evidence for requested-provider precedence and guest isolation beyond the PR's byte-pattern assertion. The two variant-only __error dependency-closure failures from the nine-case real-library probe remain separate and unresolved at this head.

The complete standalone generator below links against relinker_core. Run it with a new output directory, then execute each generated probe.exe with APS5_MIMALLOC unset. Each fixture lives in its own directory and imports no firmware or proprietary module. Native shell runtime APIs are the only platform dependencies. AI-assisted validation, no changes to the contributor's branch.

Standalone synthetic provider generator
#include <elfpatcher/windows/WindowsEntryStubBuilder.hpp>
#include <elfpatcher/windows/WindowsImportBuilder.hpp>
#include <elfpatcher/windows/WindowsPeWriter.hpp>
#include <io/BufferUtils.hpp>
#include <filesystem>
#include <fstream>
#include <iostream>

using namespace Elfpatcher::Windows;
namespace Fs = std::filesystem;

void Write(const Fs::path& path, const std::vector<std::uint8_t>& bytes) {
    std::ofstream stream(path, std::ios::binary);
    stream.write(reinterpret_cast<const char*>(bytes.data()), bytes.size());
    if (!stream) throw std::runtime_error("write fixture");
}

void Module(const Fs::path& path, bool provides, unsigned value) {
    PeSection section{".fixture", LoadRva, SectionRead | SectionExecute | 0x20u, std::vector<std::uint8_t>(0x1000)};
    auto& b = section.Data;
    Io::WriteU32(b,0x210,1);
    Io::WriteU32(b,0x214,1);
    Io::WriteU32(b,0x218,1);
    Io::WriteU32(b,0x21c,LoadRva+0x240);
    Io::WriteU32(b,0x220,LoadRva+0x248);
    Io::WriteU32(b,0x224,LoadRva+0x250);
    Io::WriteU32(b,0x240,LoadRva+0x400);
    Io::WriteU32(b,0x248,LoadRva+0x300);
    const std::string name = provides ? "ProbeExport" : "OtherExport";
    std::copy(name.begin(),name.end(),b.begin()+0x300);
    b[0x400]=0xb8;
    Io::WriteU32(b,0x401,value);
    b[0x405]=0xc3;
    std::array<PeDirectory,16> directories{};
    directories[0]={LoadRva+0x200,0x80};
    auto pe=WindowsPeWriter().Write({section},LoadRva+0x400,directories);
    const auto nt=Io::ReadU32(pe,0x3c);
    Io::WriteU16(pe,nt+22,0x2022);
    Io::WriteU32(pe,nt+24+16,0);
    Write(path,pe);
}

int main(int argc,char** argv) {
    if(argc!=2)return 2;
    const auto root=Fs::absolute(argv[1]);
    for(const std::string variant:{"libkernel_sys.prx","libkernel_web.prx"}) {
        for(const std::string kind:{"variant_wins","canonical_fallback","libc_fallback","missing","guest_only","host_before_guest","unscoped_guest","guest_scoped_variant"}) {
            const auto directory=root/(variant+"-"+kind);
            Fs::create_directories(directory);
            const bool hasGuest=kind=="guest_only"||kind=="host_before_guest"||kind=="unscoped_guest"||kind=="guest_scoped_variant";
            Module(directory/variant,kind=="variant_wins",17);
            Module(directory/"libkernel.prx",kind=="variant_wins"||kind=="canonical_fallback"||kind=="host_before_guest"||kind=="unscoped_guest"||kind=="guest_scoped_variant",29);
            Module(directory/"libc.prx",kind!="missing"&&kind!="guest_only",43);
            std::vector<std::string> libraries;
            std::vector<Domain::GuestRuntime> guests;
            if(hasGuest) {
                Module(directory/"unrelated.guest.prx",true,61);
                libraries.push_back("unrelated.guest.prx");
                Domain::GuestRuntime guest;
                guest.Names={kind=="guest_scoped_variant"?variant:"unrelated.prx"};
                guests.push_back(guest);
            }
            if(kind!="guest_scoped_variant")libraries.push_back(variant);
            libraries.push_back("libkernel.prx");
            libraries.push_back("libc.prx");
            PeSection entry{".guest",LoadRva,SectionRead|SectionExecute|0x20u,{0x48,0x83,0xec,0x08,0xff,0x15,0,0,0,0,0x48,0x83,0xc4,0x08,0xc3}};
            PeSection got{".got",LoadRva+0x1000,SectionRead|SectionWrite|0x40u,std::vector<std::uint8_t>(8)};
            Io::WriteU32(entry.Data,6,got.Rva-(entry.Rva+10));
            const auto imports=WindowsImportBuilder().Build(LoadRva+0x2000);
            const auto startup=WindowsEntryStubBuilder().Build(LoadRva+0x3000,entry.Rva,imports,libraries,
                {{.Name="ProbeExport",.TargetRva=got.Rva,.Addend=0,.Library=kind=="unscoped_guest"?"":variant}},directory.string(),false,false,guests);
            std::array<PeDirectory,16> directories{};
            directories[1]=imports.Directory;
            directories[3]=startup.ExceptionDirectory;
            directories[12]=imports.AddressTable;
            Write(directory/"probe.exe",WindowsPeWriter().Write({entry,got,imports.Section,startup.Data,startup.Code},startup.Code.Rva,directories,false,ImageBase,false));
            std::cout<<variant<<' '<<kind<<'\n';
        }
    }
}

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307835246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8853#issuecomment-6307835246). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-21T04:10:55Z. --- Follow-up at the same #8867 head: I added a separate native execution matrix with synthetic colliding DLL providers, using identical generator source for base and candidate. The expected return values are supplied by the fixtures, so these checks exercise binding policy without assuming firmware function behavior. For each of sys and web, eight cases now execute: - Requested variant wins over canonical kernel and libc: returns17. - Canonical kernel wins over libc when the variant lacks the export: returns29. - Libc remains the last host fallback: returns43. - Missing everywhere fails with0xc0000139. - A symbol supplied only by an unrelated loaded guest still fails with0xc0000139. - With unrelated guest and canonical host both supplying the symbol, scoped import returns29 from the host. - Unqualified lookup retains the first guest provider: returns61. - A guest module explicitly declaring the variant alias retains its own scoped provider: returns61. Candidate matches all16 expected outcomes; base matches12/16, returning libc's43 instead of canonical kernel's29 in the four canonical-fallback cases. This adds runtime evidence for requested-provider precedence and guest isolation beyond the PR's byte-pattern assertion. The two variant-only __error dependency-closure failures from the nine-case real-library probe remain separate and unresolved at this head. The complete standalone generator below links against relinker_core. Run it with a new output directory, then execute each generated probe.exe with APS5_MIMALLOC unset. Each fixture lives in its own directory and imports no firmware or proprietary module. Native shell runtime APIs are the only platform dependencies. AI-assisted validation, no changes to the contributor's branch. <details><summary>Standalone synthetic provider generator</summary> ```cpp #include <elfpatcher/windows/WindowsEntryStubBuilder.hpp> #include <elfpatcher/windows/WindowsImportBuilder.hpp> #include <elfpatcher/windows/WindowsPeWriter.hpp> #include <io/BufferUtils.hpp> #include <filesystem> #include <fstream> #include <iostream> using namespace Elfpatcher::Windows; namespace Fs = std::filesystem; void Write(const Fs::path& path, const std::vector<std::uint8_t>& bytes) { std::ofstream stream(path, std::ios::binary); stream.write(reinterpret_cast<const char*>(bytes.data()), bytes.size()); if (!stream) throw std::runtime_error("write fixture"); } void Module(const Fs::path& path, bool provides, unsigned value) { PeSection section{".fixture", LoadRva, SectionRead | SectionExecute | 0x20u, std::vector<std::uint8_t>(0x1000)}; auto& b = section.Data; Io::WriteU32(b,0x210,1); Io::WriteU32(b,0x214,1); Io::WriteU32(b,0x218,1); Io::WriteU32(b,0x21c,LoadRva+0x240); Io::WriteU32(b,0x220,LoadRva+0x248); Io::WriteU32(b,0x224,LoadRva+0x250); Io::WriteU32(b,0x240,LoadRva+0x400); Io::WriteU32(b,0x248,LoadRva+0x300); const std::string name = provides ? "ProbeExport" : "OtherExport"; std::copy(name.begin(),name.end(),b.begin()+0x300); b[0x400]=0xb8; Io::WriteU32(b,0x401,value); b[0x405]=0xc3; std::array<PeDirectory,16> directories{}; directories[0]={LoadRva+0x200,0x80}; auto pe=WindowsPeWriter().Write({section},LoadRva+0x400,directories); const auto nt=Io::ReadU32(pe,0x3c); Io::WriteU16(pe,nt+22,0x2022); Io::WriteU32(pe,nt+24+16,0); Write(path,pe); } int main(int argc,char** argv) { if(argc!=2)return 2; const auto root=Fs::absolute(argv[1]); for(const std::string variant:{"libkernel_sys.prx","libkernel_web.prx"}) { for(const std::string kind:{"variant_wins","canonical_fallback","libc_fallback","missing","guest_only","host_before_guest","unscoped_guest","guest_scoped_variant"}) { const auto directory=root/(variant+"-"+kind); Fs::create_directories(directory); const bool hasGuest=kind=="guest_only"||kind=="host_before_guest"||kind=="unscoped_guest"||kind=="guest_scoped_variant"; Module(directory/variant,kind=="variant_wins",17); Module(directory/"libkernel.prx",kind=="variant_wins"||kind=="canonical_fallback"||kind=="host_before_guest"||kind=="unscoped_guest"||kind=="guest_scoped_variant",29); Module(directory/"libc.prx",kind!="missing"&&kind!="guest_only",43); std::vector<std::string> libraries; std::vector<Domain::GuestRuntime> guests; if(hasGuest) { Module(directory/"unrelated.guest.prx",true,61); libraries.push_back("unrelated.guest.prx"); Domain::GuestRuntime guest; guest.Names={kind=="guest_scoped_variant"?variant:"unrelated.prx"}; guests.push_back(guest); } if(kind!="guest_scoped_variant")libraries.push_back(variant); libraries.push_back("libkernel.prx"); libraries.push_back("libc.prx"); PeSection entry{".guest",LoadRva,SectionRead|SectionExecute|0x20u,{0x48,0x83,0xec,0x08,0xff,0x15,0,0,0,0,0x48,0x83,0xc4,0x08,0xc3}}; PeSection got{".got",LoadRva+0x1000,SectionRead|SectionWrite|0x40u,std::vector<std::uint8_t>(8)}; Io::WriteU32(entry.Data,6,got.Rva-(entry.Rva+10)); const auto imports=WindowsImportBuilder().Build(LoadRva+0x2000); const auto startup=WindowsEntryStubBuilder().Build(LoadRva+0x3000,entry.Rva,imports,libraries, {{.Name="ProbeExport",.TargetRva=got.Rva,.Addend=0,.Library=kind=="unscoped_guest"?"":variant}},directory.string(),false,false,guests); std::array<PeDirectory,16> directories{}; directories[1]=imports.Directory; directories[3]=startup.ExceptionDirectory; directories[12]=imports.AddressTable; Write(directory/"probe.exe",WindowsPeWriter().Write({entry,got,imports.Section,startup.Data,startup.Code},startup.Code.Rva,directories,false,ImageBase,false)); std::cout<<variant<<' '<<kind<<'\n'; } } } ``` </details>
adriadam10 commented 2026-10-21 19:24:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-21T19:24:04Z.


Fixed by #8867: scoped libkernel_sys/libkernel_web imports now search canonical libkernel and libc, covered by entry_stub and windows_dependency_diagnostics.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6324590238 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8853#issuecomment-6324590238). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-21T19:24:04Z. --- Fixed by #8867: scoped libkernel_sys/libkernel_web imports now search canonical libkernel and libc, covered by `entry_stub` and `windows_dependency_diagnostics`.
UnhealthyKraken commented 2026-10-22 14:20:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by UnhealthyKraken on 2026-10-22T14:20:29Z.


Confirmed that #8867 addressed the general scoped-provider fallback tracked here. The separate case where a variant's own throwing timed-join export shadows that fallback is covered by #9582 (depending on #8890), including actual sys/web-scoped import regressions. That follow-up does not require reopening this resolved general-loader issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6343066125 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8853#issuecomment-6343066125). Originally posted by [UnhealthyKraken](https://github.com/UnhealthyKraken) on 2026-10-22T14:20:29Z. --- Confirmed that #8867 addressed the general scoped-provider fallback tracked here. The separate case where a variant's own throwing timed-join export shadows that fallback is covered by #9582 (depending on #8890), including actual sys/web-scoped import regressions. That follow-up does not require reopening this resolved general-loader issue.
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#8853
No description provided.