feat(tools): generate Export.cpp skeletons from missing NIDs #552
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/552"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-04T19:08:56Z.
What
New contributor tool tools/stubgen.py: given a missing-NIDs list (one 11-char NID per line) plus a NID->name CSV mapping (NID name per line, as in aerolib.csv), it emits an Export.cpp skeleton of throwing stubs following repo conventions: a database name that recomputes to the NID (same SHA1+salt scheme as tools/nid_names.py) is emitted as the real name directly as a plain export, C/C++ runtime names (leading
_or bare CRT likewcstombs_s/swscanf_s) in<real>_nid_postfixplain-definition form, anything else (no DB hit or NID mismatch) as collision-freeUnknownNNexported throughAPS5_EXPORT, every body aNotImplemented_nid_no_patch("NID")throw with a dummy return. It also emits the TechnicalDebt line per stub (unknown signaturefor real names,unknown name, signaturefor UnknownNN) with the target path/lib derived from--module(--td-path/--td-liboverride,--td-out/--td-onlyfor TD output). Real bodies are intentionally out of scope and stay hand-written. Stdlib only, no new dependencies, no comments in code or output.Tested
sce*emits plain,_-leading and bare-CRT names (_Thrd_sleep,wcstombs_s,swscanf_s,__cxa_*,_ZTV*,pthread_*,malloc) emit_nid_postfix, unknown NIDs and mismatched DB names fall back toUnknownNN+APS5_EXPORT, TD lines use derivedcore/libs/prx/MODULE/Export.cpppaths (libc/libkernel mapped, overrides work), no// namelines in output.Checklist
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:19:36Z.
Thanks. Generating the throwing stubs from the NID database is useful, but the hardcoded bodies would spread semantics that don't match Sony's CRT into every Export.cpp made with it:
localeconvreturns the host struct (Sony's hasdecimal_pointat offset 0x48),wchar_tis the host width while the guest's is 16 bits, and__udivti3returns 0 for a zero divisor where the real one traps._Mtx_initignores the type. Sony's makes the mutex recursive whentype & 0x100, and_Mtx_lockmaps EDEADLK to 3 and other errors to 4 instead of always returning 0 (from libc.prx, also discussed in #492).vsnprintf/vsscanfpass the guestva_liststraight to the host, which is a different type on a Windows host.// namecomments and the tool itself has many comments; CONVENTIONS allows none outside TechnicalDebt.tools/nid_names.pyproduces, but #542 prints a table or JSON; it's the CSV that works as input.I'd keep the generator to stubs named from the database and leave real bodies to hand-written PRs with tests. @boykopovar, would you want a generator like that in
tools/at all?Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-05T00:04:45Z.
Reworked per review: the generator now emits throwing stubs only — the whole hardcoded CRT body table is gone, so no non-Sony semantics can spread. Database names become prefix+CamelCase throwing stubs, everything else collision-free UnknownNN. All comments and the module docstring are removed (shebang only), as is the generated // name line. The description now says the DB input is a plain NID-name CSV like aerolib.csv. Description also updated accordingly.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T01:18:14Z.
Thanks. The bodies and comments are gone, so the generator now only writes throwing stubs, and the description matches the input format (the same whitespace-separated file
tools/nid_names.pyreads).One thing about the names it generates: a NID with a database name becomes a made-up
prefix + CamelCasename exported throughAPS5_EXPORT(for examplesceAmprLocaleconv). In #301, #338 and #407 the stubs ended up with the real name as a plain export instead, since the patcher recomputes the NID from it. So it would be more consistent if the tool wrote the real name directly, and the_nid_postfixform for C and C++ runtime names. On #407 that also turned out to matter on Linux, where a plain export named like a libstdc++ symbol interposes the host's own. It could also write the TechnicalDebt line for each stub ("unknown signature" or "unknown name, signature"), since CONTRIBUTING asks for one.The open question is still @boykopovar's: whether a generator like this belongs in
tools/at all.Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-05T13:27:52Z.
Reworked per review:
APS5_EXPORT), NID verified with the same SHA1+salt scheme astools/nid_names.py._, or bare CRT likewcstombs_s/swscanf_s) use the<real>_nid_postfixplain-definition form, per the #407 precedent, avoiding host interposition on Linux.UnknownNNexported throughAPS5_EXPORT.NotImplemented_nid_no_patch("NID"); return 0;), no real bodies.unknown signaturefor real names,unknown name, signaturefor UnknownNN) with path/lib derived from--module(--td-path/--td-liboverride,--td-out/--td-onlyfor TD output); input documented as plainNID nameCSV like aerolib.csv.git diff --checkclean.The open question on whether a generator like this belongs in
tools/remains for @boykopovar.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-06T05:34:16Z.
Thanks, this covers what I asked. Recomputing names are written as plain exports, C and C++ runtime names get the
_nid_postfixform, the rest fall back toUnknownNNthroughAPS5_EXPORT, and each stub gets a TechnicalDebt line.Two small things:
compute_nid,SUFFIXandCHARSETare a copy oftools/nid_names.py. Importing them from there would keep a single definition of the NID scheme.--module libkerneliscore/libs/prx/libkernel/Export.cpp, which doesn't exist (libkernel's unknown stubs are inUnimplemented.cpp), so those links would be broken unless--td-pathis given.Whether the generator belongs in
tools/is still the open question from before.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T15:45:46Z.
Review: CHANGES_REQUESTED
Thanks for the rework. The two points from the last review are still open on the current head:
compute_nid,SUFFIXandCHARSET(tools/stubgen.py:8-10,:77-88) are still a copy oftools/nid_names.py. Import them from there so the NID scheme has a single definition.--module libkernel(tools/stubgen.py:107-108) iscore/libs/prx/libkernel/Export.cpp, which doesn't exist (libkernel's unknown stubs are inUnimplemented.cpp). Drop that special case or point it at the real file; thelibc/libkernelbranches oftd_libare the same as the default and can go too.Also, a small thing: please add a sample run (input NIDs, DB lines and the generated output) to the PR description, including one NID that falls back to
UnknownNN, so reviewers can check the output without running it.@boykopovar: the open question from Dean's review stands: should this generator live in
tools/at all?Imported from boykopovar/AnyPS5. Originally posted by Pouare514 on 2026-10-09T18:10:24Z.
Thanks for the follow-up — both done, rebased onto current origin/main (
f8c2f072).NID scheme dedup:
tools/stubgen.pyno longer definescompute_nid/SUFFIX/CHARSET; it imports them fromtools/nid_names.py(try: from tools.nid_names ... except ImportError: from nid_names ...), so both script (python tools/stubgen.py,cd tools && python stubgen.py) and module (python -m tools.stubgen,from tools import stubgen) runs work andstubgen.compute_nid is nid_names.compute_nid. Code output verified byte-identical on a sample DB;git diff --checkclean.libkernel TD path: default is now
core/libs/prx/libkernel/Unimplemented.cpp(verifiedExport.cppdoes not exist there)._default_td_path()checksExport.cpp, thenUnimplemented.cpp, thensrc/Unimplemented.cppon disk and falls back toExport.cpp, so other modules without a top-levelExport.cpp(e.g.libSceAgc,libSceFont/src) also resolve correctly.--td-path/--td-liboverrides unchanged.The
tools/placement question is still open for @boykopovar — no change made there.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:14:38Z.
Review: APPROVED
Checked
tools/stubgen.pyon a synthetic DB withlibkernelandlibSceAmpr, as a script and withpython -m tools.stubgen: real names plain,_/CRT names as_nid_postfix, unknown or non-recomputing NIDs asUnknownNNthroughAPS5_EXPORT, and the libkernel TechnicalDebt path now points toUnimplemented.cpp. NID scheme is imported fromtools/nid_names.py.The
conventionscheck was failing only on the uncheckedDepends on: none; I ticked it in the PR body (no dependencies). Merging once CI is green.