lib/os+selfhost: *u8→str path migration (#23)

Path-shaped entrypoints now take str: open, tryopen, access, remove,
mkdir, rmdir, mkdirs, stat, lstat, exists, execve (path arg only).
Each cites its Hare source (ref/hare/os/*.ha, ref/hare/sys/+linux/
*.ha).

New internal kpath(str) *u8 copies into module-level pathbuf: [4096]u8
and NUL-terminates; mirrors ref/hare/sys/+linux/syscalls.ha:25,53.
Non-reentrant — graduates with thread story. mkdirs flattens to one
kpath at entry then walks pathbuf invoking raw SYS_mkdir to avoid
nested kpath clobber.

One Hare divergence at kpath: ships *u8 with nil ENAMETOOLONG sentinel
instead of (*const u8 | errno). Reason: wwstage over-allocates
1-word-payload tagged returns to 24B (cstage emits 16B); filed as
follow-up. Repro at .ai/probe_tagged_return_pointer_payload.ww;
graduates when fix lands.

Each selfhost cmd grew a private pathstr(*u8) str (cstrlen + bs) for
remaining *u8 path sites; w6l shares via obj.ww. Probe 7 in smoke
updated.

Tests 975/976/981 cover migrated entrypoints; 976 extended with two
ENAMETOOLONG rows (-36 for stat, false for exists).
This commit is contained in:
2026-05-16 23:36:41 +09:00
parent 08ac5149e8
commit deaa777eb8
19 changed files with 963 additions and 451 deletions

View File

@@ -99,7 +99,7 @@ fn buildpathv(dst: *u8, dir: *u8, name: *u8, v: u64) u64 = {
// islinkable: read first 8 bytes; require !<arch>\n or \x7fELF.
fn islinkable(path: *u8) bool = {
let fd: i32 = os.open(path, os.flag.RDONLY, 0i32);
let fd: i32 = os.open(pathstr(path), os.flag.RDONLY, 0i32);
if (fd < 0) { return false; };
let mp: *u8 = os.alloc(8u64): *u8;
let n: i64 = os.read(fd, mp, 8u64);
@@ -168,7 +168,7 @@ fn resolvelib(a: *arena, name: *u8, libdirs: **u8, nlibdirs: i32) *u8 = {
// Read first 20 bytes; return 1 for ET_DYN .so, 0 for ar/.o.
fn isso(path: *u8) i32 = {
let fd: i32 = os.open(path, os.flag.RDONLY, 0i32);
let fd: i32 = os.open(pathstr(path), os.flag.RDONLY, 0i32);
if (fd < 0) { return 0; };
let mp: *u8 = os.alloc(20u64): *u8;
let n: i64 = os.read(fd, mp, 20u64);
@@ -315,7 +315,7 @@ export fn main(argc: i32, argv: **u8) i32 = {
};
let flags: os.flag = os.flag.WRONLY | os.flag.CREATE | os.flag.TRUNC;
let fd: i32 = os.open(outpath, flags, 493i32); // 0o755
let fd: i32 = os.open(pathstr(outpath), flags, 493i32); // 0o755
if (fd < 0) {
os.write(2, "w6l: cannot open output\n".ptr, 23u64);
return 1;