Skip to content

fix(libc): store the gamma sign in an exported signgam - #5495

Closed
Roojool wants to merge 1 commit into
boykopovar:mainfrom
Roojool:contrib/g13-lgamma-signgam
Closed

Roojool wants to merge 1 commit into
boykopovar:mainfrom
Roojool:contrib/g13-lgamma-signgam

Conversation

@Roojool

@Roojool Roojool commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

What

lgamma now fills the guest signgam, which libc also exports.

FreeBSD 11's e_lgamma_r.c derives the sign stored into signgam from the argument alone, and the Windows CRT has no lgamma_r, so that rule is evaluated here: +1 at a pole, at the infinities and for NaN, -1 for a negative zero and any tiny negative argument, and otherwise, for x < 0, the sign of sin(pi*x), which is negative exactly where ceil(x) is even. The magnitude still comes from the host's lgamma (last-bit differences from the console's msun code are possible). lgammaf and lgammal are not exported in this tree, so no other call fills signgam.

The export follows the library's own convention — every external global is exported and renamed to its NID, here 5gOOC0kzW0c. The libc.prx bundled with PPSA59322 and PPSA76677 exports that NID as a 4-byte STB_GLOBAL/STT_OBJECT, so the console does too. No title available here imports it today; this fixes the libc contract, and the debt entry keeps the caveats: signgam is a plain global, so concurrent lgamma calls and a guest reading it race exactly as they do on FreeBSD, and console behaviour of the whole pair is unverified.

Tested

  • guest_math gains signgam assertions around lgamma calls with both signs (-0.5 → -1, 1.5 → +1), poles and non-finite inputs. On unmodified main the extended test fails to link (undefined reference to 'signgam_nid_postfix'); with the change it passes (Windows 4 runs including reruns; WSL Ubuntu 3/3).
  • Export verified in the built artifacts: the patched libc.prx export table contains 5gOOC0kzW0c on Windows (objdump) and the ELF shows a 4-byte OBJECT GLOBAL on Linux (readelf); the helper that computes the sign stays internal.
  • Neighbouring guest_math cases and the nid_* patcher tests (6/6) pass; the full libs target with the real NID patcher builds on both platforms.
  • python tools/check_conventions.py --base upstream/main passes.

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; silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

Copilot AI balanced review requested due to automatic review settings October 13, 2026 21:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot mentioned this pull request Oct 14, 2026
11 tasks done
karimibrahim07 added a commit to karimibrahim07/AnyPS5 that referenced this pull request Oct 14, 2026
…r#5495 changes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title is known to reach this. With the queue at 480+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

adriadam10 pushed a commit to karimibrahim07/AnyPS5 that referenced this pull request Oct 14, 2026
…r#5495 changes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RINNECODER added a commit to RINNECODER/AnyPS5 that referenced this pull request Oct 14, 2026
* feat(relinker): hint at the MinGW runtime DLLs when a module fails to load with error 126

A relinked executable that cannot load a library reports
"GetLastError: 126 - The specified module could not be found.", which also
covers a library whose dependent DLLs are missing. On Windows a self-built
libs/ directory needs libgcc_s_seh-1.dll, libstdc++-6.dll and
libwinpthread-1.dll next to it. For error 126 the stub now adds a line naming
them.

Refs boykopovar#4482

(cherry picked from commit 1915039)

* fix(relinker): share guest modules between executables that need different system libraries

On Linux and macOS every guest module listed the converting executable's
own DT_NEEDED system libraries, so its bytes could depend on which
executable converted it. --executable then failed with "Guest modules
convert differently" when the executables need different system
libraries that the modules do not, or the same ones in another order.
It is the error a title reports on Linux (boykopovar#5268)
for its launcher and main executable. Guest modules now list
only the system libraries the guest modules themselves need, with the
libSceLibcInternal.prx to libc.prx rule. The executable's own DT_NEEDED
is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 6adf63c)

* feat(libc): implement swprintf_s

Add the missing wide secure formatting exports required by a title
whose load failed with `undefined symbol: Im55VJ-Bekc`:
swprintf_s and its va_list counterpart follow C11 Annex K.3.9.1.4
(the complete output, including the terminator, must fit), while
vsnwprintf_s is the va_list counterpart of snwprintf_s (K.3.9.1.3,
truncation with full length). The export names produce NIDs
Im55VJ-Bekc, oDoV9tyHTbA and 8SKVXgeK1wY respectively. Document
the new functions in docs/dev/debt/libc.md.

(cherry picked from commit a0bd257)

* feat(tools): unwrap decrypted SELF containers into clean ELF

The relinker reads a plain ELF executable and skips SELF containers with a
warning, so an eboot.bin or a *.prx taken from a title cannot be relinked
before it is unwrapped, and the repository has no tool for that.

The inner ELF program headers of a container carry stale offsets: a SELF
inserts its own metadata blocks between the segments, so the data sits at the
offsets of the SELF segment-record table at file offset 0x40. The segments are
also packed without honouring p_align, while ELF requires p_offset % p_align
== p_vaddr % p_align, which the relinker enforces on guest modules. The tool
places the segments from the records, falls back to the vaddr to file mapping
of the containing PT_LOAD for segments the table does not cover, copies every
region to an offset satisfying the alignment, and refuses a container whose
load segments all look encrypted.

(cherry picked from commit 2a01e9e)

* feat(libkernel): export sceKernelGetSocPowerConsumption

(cherry picked from commit 31abd1a)

* feat(libc): implement wcsnlen_s

(cherry picked from commit 6beefcc)

* feat(libkernel): support fixed anonymous mmap

Map fixed private anonymous ranges through the existing guest arena. Preserve occupied ranges for MAP_EXCL and use FreeBSD 11.4 errors.

Cover replacement, exclusivity, range validation, rounding, and memory access.

(cherry picked from commit 6215101)

* feat(libkernel): implement setpriority

A title imports setpriority and stops at start-up once getpriority is implemented. Accept PRIO_PROCESS, PRIO_PGRP and PRIO_USER for the guest's own process and fail with ESRCH for any other id and EINVAL for any other which, leaving errno unchanged on success like FreeBSD's libc; the value is not applied, since the guest nice is not the host's scheduling class.

(cherry picked from commit afc04c7)

* feat(libkernel): count committed ranges in sceKernelGetPageTableStats

Charge each recorded protection ranges 2 MiB granules to the gpu
pool when the range has GPU-access protection bits and to the cpu
pool otherwise, so the available counts reflect committed usage
instead of staying at the 2048-entry budget. Follows KytyPS5s
counting model.

(cherry picked from commit 975ed12)

* perf(relinker): stream scans and reuse executable buffers

Partial port: the streamed instruction scans (VisitCodeSection in the
instruction scanner, the syscall scanner and the call-site resolver) are
kept. The executable-buffer reuse and scan progress reporting are not,
because this fork's relinker pipeline has no progress reporting and a
different conversion entry point.

(cherry picked from commit 94ae3f1)

* feat(libkernel): map regular files with mmap on Linux

(cherry picked from commit bc71ffb)

* test(libkernel): cover shared and private mappings of a regular file

(cherry picked from commit e53268d)

* docs(debt): note regular file mappings of mmap

(cherry picked from commit 6b8ddfb)

* feat(libkernel): report RLIMIT_NOFILE through getrlimit

A title queries RLIMIT_NOFILE at start-up in QEMU's
os_setup_limits and stopped on the unsupported resource. It reports the
descriptor count after which AnyPS5 fails with EMFILE: the C runtime's
8192 low-level descriptors on Windows and the host limit on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 1aaec97)

* feat(libkernel): stop at start-up on a host CPU without the PS5's extensions

Titles run natively, so a host CPU without an extension that compiled Zen 2 code uses faults with an illegal instruction deep inside a title (boykopovar#3719: SHLX, BMI2). libkernel now reads CPUID and XCR0 when it loads on Linux and Windows, logs the host CPU's extensions and throws, naming the CPU and the missing extensions, before any title code runs.

(cherry picked from commit 83a268a)

* feat(libkernel): implement sysctlnametomib for the sysctl names AnyPS5 serves

Map hw.model, hw.ncpu, hw.physmem, hw.realmem, kern.arandom and
kern.proc.pathname to their FreeBSD MIBs with the size handling of
FreeBSD's libc wrapper over name2oid, fail with ENOENT and ENAMETOOLONG
as name2oid does, and throw for null pointers, which FreeBSD's wrapper
dereferences, and for names sysctl does not serve.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit cc3d25d)

* feat(relinker): report every unresolved ELF import before failing on Windows

The Windows startup stub stopped at the first import it could not
resolve, so a title missing several functions showed one
"FAIL: unresolved ELF import" line per run and needed a run per
missing function to list them all.

The stub now counts unresolved imports, writes the FAIL line of each
and goes on with the next import. After the last import it fails once,
with the searched library list and the last Windows error as before,
and exits with STATUS_ENTRYPOINT_NOT_FOUND. Weak imports, lazy binding
and a startup where every import resolves are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 4ae26f8)

* feat(libc): implement fegetenv

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 74b93ad)

* test(libc): cover fegetenv with a null environment and pending x87 flags

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 34cf0e2)

* refactor(libc): move fegetenv and its test out of the lines boykopovar#5495 changes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit f49c542)

* docs(libc): move the fegetenv debt line off the end of its section

(cherry picked from commit 32a11a5)

* docs(debt): port the getrlimit, hw.model, host CPU check and fegetenv debt lines

Upstream keeps these in docs/dev/debt/*.md; this fork keeps them in
docs/dev/TechnicalDebt.md. The Host CPU check does not run on macOS hosts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(debt): keep title names out of the ported debt lines

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: omurc4 <omurc4@gmail.com>
Co-authored-by: SandstromPL <paritoshlahre@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: alosta <mohammadalosta02@gmail.com>
Co-authored-by: ryyReid <ryy9033@gmail.com>
Co-authored-by: babyhuey <7751607+babyhuey@users.noreply.github.com>
Co-authored-by: Feuris <sebastian6@live.com.ar>
Co-authored-by: Evgeniy Kazarin <evgkaz0@gmail.com>
Co-authored-by: Nixitov <Nixitov@users.noreply.github.com>
Co-authored-by: akkadbakkad89 <best.dv1996@gmail.com>
Co-authored-by: Sanxchep Sharma <sanxchep@gmail.com>
Co-authored-by: Yossi Yadgar <yadgar360@gmail.com>
Co-authored-by: p3nicillin <lcmcclellan12@gmail.com>
Co-authored-by: Dean Galvin <dean.galvin@live.com>
Co-authored-by: Ahmad <ai.ahmad.3a4@gmail.com>
Co-authored-by: thibaut <thibaut-leaux-angeli@live.fr>
Co-authored-by: Karim Ibrahim <40270714+karimibrahim07@users.noreply.github.com>
Co-authored-by: Adrià Franch <adriadam10@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants