From 57aca694cedacd303aedf1deb4e05472c459be0a Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Fri, 16 Oct 2026 21:59:54 +0100 Subject: [PATCH] Docs: the C library a target's choice; Sys's errors Linux's by name; CAbi Appendix A: which C library a program that uses C is linked against is the target's. Volume 2: Sys's errors are minus Linux's errnos on every target, with names (errNoEntry, ...), and Sys over C takes what a C library fixes from CAbi, which tools/cabi.c writes. PROPOSALS: Sys over any C library goes, being built; a note on Windows comes. --- diff --git a/PROPOSALS.md b/PROPOSALS.md index 766f388..60c7e1f 100644 --- a/PROPOSALS.md +++ b/PROPOSALS.md @@ -437,69 +437,18 @@ Pieces 1 and 2 are small and change no program; 3 is a mend; 4 needs a thaw. -## Sys over any C library +## Windows -`lib/Sys.raz` is the `Sys` of a target with no file of its own, which -is every target but Linux; it is written over C so that one file -serves them all. But it holds glibc's facts for x86-64 Linux, as its -opening comment says: where a name lies in struct dirent, struct stat -and statvfs, struct sigaction, sockaddr_un and sockaddr_in, open's, -socket's and send's flags, the terminal's requests, the signals' and -the limits' numbers. These are the kernel's more than glibc's: -checked on this machine against musl 1.2, every one Sys uses agrees, -and musl lacks only `close_range`. On FreeBSD, macOS, or Linux on -ARM, nearly all differ, so the file meant for other systems serves -none of them. There is more of the same: - -- `C.__errno_location` is glibc's and musl's name; the BSDs and macOS - call it `__error`. `close_range`, `memfd_create`, `getrandom`, - `accept4` and `cfmakeraw` aren't in every C library. -- `doc/raz-lib.md` says a failure is "minus an errno, as on Linux", - but `Sys` over C gives the C library's numbers, which elsewhere - aren't Linux's (EAGAIN is 11 on Linux, 35 on the BSDs); `Files` - writes -2 for ENOENT. -- A program that uses C needs `libc.so.6`, names - `/lib64/ld-linux-x86-64.so.2` as its loader, and starts through - `__libc_start_main`: constants of `Elf.raz` and `Raz.raz`. musl's - loader is `/lib/ld-musl-x86_64.so.1` and its library `libc.so` - (`__libc_start_main` is in both), so a raz program that uses C - doesn't run on Alpine. - -Four pieces, each standing on its own: - -**1. The facts in a module of their own.** `Sys.raz` keeps its code, -over POSIX's names; what C fixes for each system, the layouts, the -numbers and the names that differ, goes in a new module, `CAbi`, one -file per target (`CAbi.linux-x86_64.raz`, `CAbi.freebsd-x86_64.raz`), -as `Sys` has: offsets, sizes and constants, and the externs whose -names differ behind one raz name (`CAbi.errno(): ^I32`). `Sys` reads -a struct stat as bytes at `CAbi`'s offsets. Porting `Sys` to a C -library is then writing that file, about a hundred lines, and nothing -else. It adds a module and breaks no program. - -**2. The facts written by C.** `tools/cabi.c`, a C program that -prints `CAbi`'s file for the system it is compiled on, from its own -headers, with `offsetof`, `sizeof` and the constants: no fact is typed -by hand, and a porter runs it once. `make check`, where there is a C -compiler, runs it and compares with `lib/`'s file, and does the same -with `musl-gcc` where that is installed. - -**3. Errnos as Linux's.** `Sys` exports names for the errnos programs -test (`Sys.noEntry = -2`, `again`, `intr`, `exists`, ...), with -Linux's numbers, and `Sys` over C maps the C library's errno to them -through a table in `CAbi`, so that "as on Linux" holds everywhere. -`Files` and the programs use the names. It adds constants and breaks -no program. - -**4. The compiler's C library.** The loader's path, the library's -name and the start-up symbol become facts of the target, not -constants: `linux-x86_64` links against glibc or musl, by an option, -or by default by which loader the machine has. Appendix A says the -C library is the implementation's to choose under "The target", and -`test/libc` runs under each one installed. - -Piece 4 has a gain today: raz programs that use C run on Alpine. -Pieces 1 to 3 pay when a second system is ported, and 3 needs 1. +A Windows target would keep volume 2 as it is: it describes the +library on a Unix target. Windows has no stable system calls, no +signals, no fork, no termios, and fds that are handles, so its `Sys` +can't be the one volume 2 gives. Appendix A's core already lets a +target leave out all of `Sys` past writing, ending the program and +getting memory: a Windows target gives the core, and what else it has +in a module of its own (`Win`), told on a page of its own beside +volume 2. Volume 1 needs at most a sentence, that `link static;` +means no C library where there are no system calls to make. The +compiler needs a PE writer and Microsoft's calling convention. ## A slice's pointer diff --git a/doc/raz-lib.md b/doc/raz-lib.md index 6c126c8..c0f10a2 100644 --- a/doc/raz-lib.md +++ b/doc/raz-lib.md @@ -11,7 +11,7 @@ | Module | What | |---|---| | `Rt` | ending the program, `exit` and `atExit`; `stop`, which ends it with a message; `trace`, the calls under way; what the compiler's checks call when they fail | -| `Sys` | system calls: `open`, `openMode`, `openRead`, `create`, `read`, `write`, `seek`, `position`, `truncate`, `sync`, `syncAll`, `lock`, `close`, `dup`, `dupTo`, `dupAbove`, `keepOnExec`, `mmap`, `munmap`, `isTerminal`, `yield`, `exit`; files and directories, `rename`, `remove`, `removeDir`, `makeDir`, `chmod`, `access`, `umask`, `symlink`, `readLink`, `info`, `linkInfo`, `infoOf`, `openDir`, `nextEntry`, `entryKind`, `closeDir`; the terminal, `rawMode`, `restoreMode`, `getMode`, `setMode`, `termSize`, `ready`; the environment, `env`, `envAt`, `setEnv`, `workDir`, `setWorkDir`; programs, `spawn`, `exec` and `execve`, pipes and signals; the user, the machine, time used and limits; time, `clock`, `now`, `sleep`; `random`; what an errno means, `errorText`; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and `Sys.raz` over the C library for the others | +| `Sys` | system calls: `open`, `openMode`, `openRead`, `create`, `read`, `write`, `seek`, `position`, `truncate`, `sync`, `syncAll`, `lock`, `close`, `dup`, `dupTo`, `dupAbove`, `keepOnExec`, `mmap`, `munmap`, `isTerminal`, `yield`, `exit`; files and directories, `rename`, `remove`, `removeDir`, `makeDir`, `chmod`, `access`, `umask`, `symlink`, `readLink`, `info`, `linkInfo`, `infoOf`, `openDir`, `nextEntry`, `entryKind`, `closeDir`; the terminal, `rawMode`, `restoreMode`, `getMode`, `setMode`, `termSize`, `ready`; the environment, `env`, `envAt`, `setEnv`, `workDir`, `setWorkDir`; programs, `spawn`, `exec` and `execve`, pipes and signals; the user, the machine, time used and limits; time, `clock`, `now`, `sleep`; `random`; errors, by name, and what one means, `errorText`; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and `Sys.raz` over the C library for the others, which takes what each C library fixes from `CAbi` | | `Out` | writing text and numbers to standard output, buffered; safe to call from several threads | | `C` | the parts of the C library the others use, and `printf`, `fflush`, `stdout`, `pthread_create`; a program that imports it uses C | | `Lock` | a lock for short sections, for C's threads and `Thread`'s alike | @@ -164,7 +164,14 @@ **Sys** gives every target the same procedures, so that a program that needs only these runs wherever raz does: through system calls on Linux, through the C library elsewhere. A result that can fail is a -number, minus an errno, as on Linux; 0 is success. +number, minus an errno, as on Linux; 0 is success. The number is +Linux's on every target: `Sys` over another system's C library gives +the Linux errno of the same name, and a program tests it by the names +below; one with no Linux twin keeps its own number. `Sys.raz`, the +`Sys` over C, keeps to POSIX's names; what a C library fixes for its +target, the layouts of its structs, its numbers and the names that +differ, it takes from `CAbi`, one file per target, which +`tools/cabi.c`, compiled there, writes. ``` module Sys; @@ -179,6 +186,16 @@ (* the limits limit and setLimit take, by their numbers on Linux; each target has its own *) limitCpu* = 0; limitFileSize* = 1; limitData* = 2; limitStack* = 3; limitCore* = 4; limitProcs* = 6; limitFiles* = 7; limitMemory* = 9; + (* errors, minus Linux's errnos on every target *) + errPerm* = -1; errNoEntry* = -2; errNoProcess* = -3; errIntr* = -4; + errIo* = -5; errBadFd* = -9; errChild* = -10; errAgain* = -11; + errNoMemory* = -12; errDenied* = -13; errExists* = -17; + errNotDir* = -20; errIsDir* = -21; errInvalid* = -22; + errNotTerminal* = -25; errNoSpace* = -28; errPipe* = -32; + errNameTooLong* = -36; errNotEmpty* = -39; errLoop* = -40; + errAddrInUse* = -98; errNetUnreach* = -101; errConnReset* = -104; + errTimedOut* = -110; errRefused* = -111; errHostUnreach* = -113; + errInProgress* = -115; type Access* = (reading, writing, creating, exclusive, truncating, appending, executing); diff --git a/doc/raz.md b/doc/raz.md index 3999b5f..6ca55fc 100644 --- a/doc/raz.md +++ b/doc/raz.md @@ -1648,7 +1648,8 @@ - **The target.** Which machines and systems it compiles for, and the names of their files (`linux-x86_64`, section 3); for each, the size - of an address, and so of `INT`, and whether it has reals. + of an address, and so of `INT`, whether it has reals, and which C + library a program that uses C is linked against. - **Separate compilation.** Whether modules are compiled on their own, and if so into what: the object file, its format, the form of the code in it, when one is out of date, and how an instance is named so