Page MenuHomeFreeBSD

kris_tranception.com (Kristofer Peterson)
User

Projects

User does not belong to any projects.

User Details

User Since
Dec 23 2025, 3:43 PM (11 w, 6 d)

Recent Activity

Feb 8 2026

kris_tranception.com added a comment to D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.

I've implemented an improved encoding for large file descriptors that is efficient and only requires 16 additional bits from _flags2 instead of 31.
More importantly, when the file descriptor fits in a signed short, the 16 additional bits are all zero so the FILE struct data in memory is identical.
Given a 32-bit FD, compute FD ^ ((FD << 16) >> 16); the bottom word goes in_file, the top word goes in the new field.
I took inspiration from the AMD64 canonical virtual addresses scheme for this.
I've added the commit to the draft github pull request I mentioned earlier (URL below).
*https://github.com/freebsd/freebsd-src/pull/2005

Feb 8 2026, 7:53 PM
kris_tranception.com added a comment to D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.

I have reworked this change into a new branch off of CURRENT organised into three commits (with detailed, multi-line commit messages):

  • 2aa94c66b4a4 stdio: Support 32-bit file descriptors in FILE
  • 582805ad8d8d stdio: Remove fileno macros, add internal inline fileno get/set functions
  • 23897d36c606 stdio: Thread safety fixes, sanity checks, initialisation fixes
Feb 8 2026, 2:20 AM

Feb 6 2026

kris_tranception.com added a comment to D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.

I've reworked this (against releng/15.0) and put it in github here:
https://github.com/freebsd/freebsd-src/compare/releng/15.0...svenski123:freebsd-src:fd32compat

Feb 6 2026, 9:07 PM
kris_tranception.com added a comment to D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.

I can see that int _flags2 was added to FILE ten years ago and only one bit has been defined leaving 31 unused bits, precisely what's needed to represent any non-negative file descriptor.
So I'm reworking this to not add a new field but rather continue using short _file for <32768 and the high 31 bits of _flags2 for descriptors >32767 && <0x7fffffff; the size of FILE will not need to change.

I'd hold off on that and have more of a chat about it first.

Feb 6 2026, 6:05 PM
kris_tranception.com added a comment to D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.

I can see that int _flags2 was added to FILE ten years ago and only one bit has been defined leaving 31 unused bits, precisely what's needed to represent any non-negative file descriptor.
So I'm reworking this to not add a new field but rather continue using short _file for <32768 and the high 31 bits of _flags2 for descriptors >32767 && <0x7fffffff; the size of FILE will not need to change.
Where the descriptor fits in a short, _flags2[31:1] can be set to 0x00007fff so that _flags2[31:1] is always non-zero indicating a FILE object constructed by new stdio vs. one constructed by old stdio; (mind you I'm not entirely convinced this is needed or useful).
I'll remove the fileno macro to prevent _flags2 getting compiled in and I'll add the versioned fopen and friends so old binaries get old short-only FILEs.
Not sure how to hook stdin/stdout/stderr construction and version it, looks like it's initialised at load time; likely doesn't matter unless apps freopen stdin/out/err and likely not even then.
This will be a bit more intrusive than the older patch but will hopefully satisfy backwards compatibility requirements so that it could get back ported for 15.1 and/or 14.4.

Feb 6 2026, 4:34 PM

Feb 4 2026

kris_tranception.com added a comment to D54354: stdio: rename _file to _fileno in struct __sFILE.

I have opened the following report in respect of the games/xpipeman and games/xrobots ports, attaching a patch patching the patch files in the ports such that they call fileno() instead accessing _file directly.

Feb 4 2026, 7:40 PM
kris_tranception.com added a comment to D54354: stdio: rename _file to _fileno in struct __sFILE.

From the exp-run failure logs here...

Feb 4 2026, 4:20 PM
kris_tranception.com added a comment to D54354: stdio: rename _file to _fileno in struct __sFILE.

Renaming _file is merely to identify ports that attempt access _file directly so that the consequences of widening _file on them can be reviewed and appropriate action taken.

Feb 4 2026, 4:16 PM
kris_tranception.com added a comment to D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.
In D54355#1256017, @jhb wrote:

Oh, this is the sort of thing I really hoped to avoid, was exposing all of FILE as a new ABI. I was careful in my previous versions to figure out which parts of FILE were actually used (not _fileno which doesn't matter, but all the _other_ fields that things like gnulib abuse) and then tried to make FILE mostly opaque, and added the wider _fileno in a slot that was safe to reuse that was near the front still. I think I also used some #ifdef's to ensure that only the fields in FILE that were part of the public ABI were exposed outside of libc. This doesn't do any of that.

Feb 4 2026, 4:13 PM
kris_tranception.com added a comment to D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.

@jhb Thank you for taking a look at this and apologies for my delay in responding as I've been on holiday the past week.

Feb 4 2026, 3:29 PM

Jan 21 2026

kris_tranception.com added inline comments to D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.
Jan 21 2026, 12:01 AM

Jan 20 2026

kris_tranception.com updated the diff for D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.

rebased to freebsd/main

  • stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE
  • stdio: return error EBADF when fd < 0 in fdopen() and vdprintf()
  • stdio: check file descriptor opened for writing in vdprintf()
Jan 20 2026, 11:17 PM
kris_tranception.com updated the diff for D54354: stdio: rename _file to _fileno in struct __sFILE.

rebased to freebsd/main

Jan 20 2026, 11:15 PM

Jan 14 2026

kris_tranception.com added inline comments to D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.
Jan 14 2026, 9:02 PM
kris_tranception.com updated the test plan for D54354: stdio: rename _file to _fileno in struct __sFILE.
Jan 14 2026, 12:49 AM
kris_tranception.com updated the summary of D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.
Jan 14 2026, 12:49 AM
kris_tranception.com updated the test plan for D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.
Jan 14 2026, 12:49 AM
kris_tranception.com updated the summary of D54354: stdio: rename _file to _fileno in struct __sFILE.
Jan 14 2026, 12:49 AM

Dec 23 2025

kris_tranception.com updated the diff for D54354: stdio: rename _file to _fileno in struct __sFILE.

Remove inadvertent edit to comment (i.e. read_only_fileno should have remained file_only_file)

Dec 23 2025, 7:09 PM
kris_tranception.com requested review of D54355: stdio: rename short _fileno to _fileno_short for legacy abi compatibility, add new int _fileno in struct __sFILE.
Dec 23 2025, 6:03 PM
kris_tranception.com requested review of D54354: stdio: rename _file to _fileno in struct __sFILE.
Dec 23 2025, 6:03 PM