Skip to content

[tmp] openkal 0.16 draft: least stack size, PASS_INPUT, enumeration release (verification only) - #36

Closed
Sunrisepeak wants to merge 5 commits into
mainfrom
tmp/three-reports
Closed

Sunrisepeak wants to merge 5 commits into
mainfrom
tmp/three-reports

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

Temporary draft for cross-platform verification. Not for merge.

One branch name, tmp/three-reports, across openkal, openkal-linux, openkal-macos, openkal-windows, openkal-emscripten and openkal-musl, so that each CI builds the others at the same branch. The commits are checkpoints; the final change will be one PR per repository after the design (.agents/docs/2026-10-25-three-reports-optimisation-design.md in openkal) is reviewed, and this draft will be closed.

What it carries: kal_task_start_sized (a least stack size), KAL_TERM_PASS_INPUT (whether input is altered), and what closing a directory does to its enumerations.

yspbwx2010 and others added 5 commits October 25, 2026 05:29
kal_fs_list_begin opens a descriptor of its own for each enumeration, and
only kal_fs_list_next released it, on reaching the end. kal_fs_close_dir
closed the directory's descriptor and nothing else, so an enumeration
abandoned part-way kept its descriptor and buffer until the program
exited, although fs.h says that closing the directory that produced an
iterator releases it.

Keep the listings not yet read to the end on a list, with the directory
each was begun on. kal_fs_close_dir ends that directory's listings before
the descriptor is closed, and kal_fs_list_next takes a listing off the
list when it reaches the end or fails. The close now frees the listing,
so an iterator used after its directory is closed uses freed memory
instead of going on with the directory.

The test begins and abandons 64 enumerations and compares the number of
open descriptors before and after. It fails without the change.
…ot free what another context is reading

The listing an iterator names is found among the open ones rather than read
through, so a closed directory (a released handle, clause 6.7) or a stale
iterator is refused with kal_err_invalid. A listing another context is inside
kal_fs_list_next with is marked by the close and released by that context on its
way out, so the close does not free a buffer a getdents64 is writing into
(clause 6.6). Two contexts reading one enumeration take turns.
…e is asked for, and kal_task_start_sized asks

The stack was one anonymous mapping from kal_alloc with nothing beneath it, and
the C library above cannot place a guard of its own. It is now mapped with a
256 KiB inaccessible guard below it, larger than the 69,008-byte frame measured
in that library at -O0. The default is the host's, 8 MiB, which costs address
space and not memory. kal_task_start_sized (openkal 0.16) gives at least the
size asked for and never less than the default; above a C runtime the request
is passed to it.
Read as set only where ISTRIP, INLCR, IGNCR and ICRNL are all clear; set, all
four are cleared; clear, ICRNL is restored, which is what this kernel ordinarily
applies. A position already at the requested value is not written.
The enumeration of a closed directory is refused and a close racing a read
ends it safely; a pseudo terminal this test makes delivers the return key and
Ctrl+J as two bytes once KAL_TERM_PASS_INPUT is set, and the kernel's ordinary
rewriting when it is clear; a context started with a least stack size is told
at least that size and has the room.
@Sunrisepeak

Copy link
Copy Markdown
Member Author

Temporary verification draft; carried into #37.

@Sunrisepeak
Sunrisepeak deleted the tmp/three-reports branch October 24, 2026 21:51
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