Skip to content

docs(debt): record that a PS5 takes SIGFPE for the minimum divided by -1 in div, ldiv, lldiv and imaxdiv - #1814

Open
Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/27935
Open

Thimo188 wants to merge 1 commit into
mainfrom
upstream-pr/27935

Conversation

@Thimo188

@Thimo188 Thimo188 commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Imported from boykopovar/AnyPS5#27935, originally opened by xXPBSXx.

Source commit: 7bfd50b09cdf043a6265c5baec1221f624f23c95. The import branch preserves this fetched upstream PR snapshot. The description and validation below are copied from upstream; no new code changes or test runs were made for this import. Original reviews, discussions, and attachments remain at the linked upstream PR.


What

The debt entry for div, ldiv, lldiv and imaxdiv (docs/dev/debt/libc.md:431 on main ea49f32e8982) says that with a divisor of -1 the result here is the two's-complement negation of the numerator with the remainder 0, and that the console result is unmeasured. A probe on a PS5 (firmware 11.60, payload process; a title process may differ) called the four functions of the system module libSceLibcInternal.sprx (line 2 of the raw output in the first comment: module=1 div=1 ldiv=1 lldiv=1 imaxdiv=1) with eight pairs each. The call with the minimum value and the divisor -1 took a SIGFPE in all four: div(-2147483648, -1) (case 1.6, line 8), ldiv(-9223372036854775808, -1) (case 2.6, line 16), lldiv (case 3.6, line 24) and imaxdiv (case 4.6, line 32), each with signal=8 (the probe's handler for SIGFPE is installed at probe.c:141; the printed quot=23130 rem=23130 is the preset 0x5a5a of the result structure, probe.c:163 and :176, not a result). The seven other pairs for each function returned the quotients and remainders that the arithmetic gives: 7 / 2 gave 3 remainder 1, -7 / 2 gave -3 remainder -1, 0 / -1 gave 0 remainder 0, the maximum / -1 gave its negation with remainder 0, the minimum / 2 gave half of it with remainder 0, -5 / -1 gave 5 with remainder 0 and 5 / -1 gave -5 with remainder 0 (lines 3 to 10 for div, 11 to 18 for ldiv, 19 to 26 for lldiv and 27 to 34 for imaxdiv, without the four lines named above). The run was made once (END 41, line 43).

On main a divisor of -1 returns the negated numerator and the remainder 0 without a division (core/libs/prx/libc/src/Strings.cpp:863 for div, core/libs/prx/libc/src/Math.cpp:517 to :535 for the three 64-bit functions), so the minimum / -1 returns the minimum and the process does not fault, where the console takes SIGFPE.

This pull request adds one entry in a new fragment (docs/dev/debt/changes/docs-libc-div-int-min-console-1160.md, ## change [div, ldiv, lldiv and imaxdiv]) that replaces the entry at libc.md:431; the entry grows from 551 to 927 characters with its list marker. It keeps the account of the negation and the remainder 0, replaces the sentence that the console result is unmeasured by the measurement (SIGFPE for the minimum / -1, in one run, for div with 32 bits and for the other three with 64 bits; the seven other pairs as the arithmetic gives them), says that the console faults where main returns the minimum, and keeps that a zero divisor is unchanged. No code changes.

Not measured: a zero divisor, a title process, other firmware.

Tested

Measured on a PS5 with firmware 11.60 from a homebrew payload process, one run at about 13:24 UTC on 2026-11-09 (probe build 3193c5be4339, END 41). This is a documentation change; no test was added or run.

On the head merged into main at ea49f32 (2026-11-27 20:14 UTC) I ran tools/check_conventions.py --base upstream/main with this title and description (All conventions checks passed, exit code 0) and tools/debt_fold.py --check (exit code 0, no message). The commit has one author, xXPBSXx with the noreply address, and adds one new file with the mode 100644.

Overlap: counted on 2026-11-27 from the 2088 open pull requests (file lists from the GitHub API, the pull requests with 100 or more files read in full through the files API and, for those and for the pull requests with an old base, the real diff against the merge base; the patches of the 1268 pull requests that change a file under docs/dev/debt/, Tsd.cpp, Strings.cpp or Math.cpp, or have pthread, key, div or tsd in the title or branch name, were searched for pthread_key_create, scePthreadKeyCreate, PthreadKeyCreate, ldiv, lldiv, imaxdiv, INT_MIN, INT64_MIN and the two fragment names, from 18:16 to 19:57 UTC). No open pull request changes the fragment docs/dev/debt/changes/docs-libc-div-int-min-console-1160.md or the entry for div, ldiv, lldiv and imaxdiv at docs/dev/debt/libc.md:431, and no commit on main since 13bf980d9659 (the base of this branch; 124 commits, up to ea49f32e8982) changed that entry, the entry libkernel.md:435, core/libs/prx/libc/src/Strings.cpp, core/libs/prx/libc/src/Math.cpp or the fragment of the first pthread entry. A search of the open pull requests for lldiv, imaxdiv and div_nid_postfix finds none. The patches that name INT_MIN or INT64_MIN do so in other code: boykopovar#27646, boykopovar#26796 and boykopovar#26764 (INT_MIN / 4 in the complex inverse trigonometric functions) and boykopovar#27244 and boykopovar#27229 (test tables of the x87 scaling functions); none names div, ldiv, lldiv or imaxdiv or changes the entry. The merges of this head with each of the 96 pull requests that change libc.md, libkernel.md, Math.cpp, Strings.cpp or Tsd.cpp or have a searched name, or have 100 or more files or an old base, were made with git merge-tree from 18:16 to 19:57 UTC (main at 9f12ec0e3840 at the start): 57 are clean; the other 39 already conflict with main alone, in at least as many files as with this head, so none of them conflicts because of this change. The count was repeated for the 613 pull requests that were opened or updated since 18:16 UTC (of the 2083 open pull requests, listed from 19:58 to 20:12 UTC; 394 of them were patch-scanned for the same names): no new hit beyond the ones named, and the 8 that change a searched file merge cleanly with this head. A merge of this head into main at ea49f32 was checked the same way at 19:59 UTC and is clean, and it merges with the first head of this series (the existing fragment of pthread_key_create) without a conflict. This pull request does not depend on any of them (Depends on: none).

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 (no graphics change)
  • AI-assisted: yes

Summary by CodeRabbit

  • Documentation
    • Added documentation describing division results when the divisor is -1, including minimum-integer inputs, and recording observed behavior on PS5 firmware 11.60. Zero-divisor behavior remains unchanged.

… -1 in div, ldiv, lldiv and imaxdiv

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

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Libc division behavior

Layer / File(s) Summary
Document division edge cases
docs/dev/debt/changes/docs-libc-div-int-min-console-1160.md
The document records results for four libc division functions with a divisor of -1, observed SIGFPE cases for minimum-integer inputs, and unchanged zero-divisor behavior.

Possibly related PRs

  • Thimo188/AnyPS5#1847: Addresses guest integer division errors for INT_MIN / -1, which this change documents for libc division functions.

Change: Other

Merge Risk: Minimal · up to 7bfd5

This is a documentation-only update recording division edge-case behavior and one PS5 firmware 11.60 observation. It changes no runtime behavior, so merge risk is minimal.

Architecture risk: Low · up to 7bfd5

The change adds an explicit written account of existing libc division behavior without changing the runtime contract.

Changed areas: docs

Review details

Systems and components

  • observed — 1 changed file mapped to docs.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 1
  • Waived: $0.25 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9358791b-6b41-4043-a865-4ec71dba3fbb
Commits

Reviewing files that changed from the base of the PR and between 4131f51 and 7bfd50b.

Files selected for processing: 1

  • docs/dev/debt/changes/docs-libc-div-int-min-console-1160.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants