raz / commit 57aca694

commit
57aca694cedacd303aedf1deb4e05472c459be0a
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
1328b817
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.

patch · log

3 files changed, +32 -65

PROPOSALS.md modified +11 -62

@@ -437,69 +437,18 @@
437437 Pieces 1 and 2 are small and change no program; 3 is a mend; 4 needs
438438 a thaw.
439439
440-## Sys over any C library
440+## Windows
441441
442-`lib/Sys.raz` is the `Sys` of a target with no file of its own, which
443-is every target but Linux; it is written over C so that one file
444-serves them all. But it holds glibc's facts for x86-64 Linux, as its
445-opening comment says: where a name lies in struct dirent, struct stat
446-and statvfs, struct sigaction, sockaddr_un and sockaddr_in, open's,
447-socket's and send's flags, the terminal's requests, the signals' and
448-the limits' numbers. These are the kernel's more than glibc's:
449-checked on this machine against musl 1.2, every one Sys uses agrees,
450-and musl lacks only `close_range`. On FreeBSD, macOS, or Linux on
451-ARM, nearly all differ, so the file meant for other systems serves
452-none of them. There is more of the same:
453-
454-- `C.__errno_location` is glibc's and musl's name; the BSDs and macOS
455- call it `__error`. `close_range`, `memfd_create`, `getrandom`,
456- `accept4` and `cfmakeraw` aren't in every C library.
457-- `doc/raz-lib.md` says a failure is "minus an errno, as on Linux",
458- but `Sys` over C gives the C library's numbers, which elsewhere
459- aren't Linux's (EAGAIN is 11 on Linux, 35 on the BSDs); `Files`
460- writes -2 for ENOENT.
461-- A program that uses C needs `libc.so.6`, names
462- `/lib64/ld-linux-x86-64.so.2` as its loader, and starts through
463- `__libc_start_main`: constants of `Elf.raz` and `Raz.raz`. musl's
464- loader is `/lib/ld-musl-x86_64.so.1` and its library `libc.so`
465- (`__libc_start_main` is in both), so a raz program that uses C
466- doesn't run on Alpine.
467-
468-Four pieces, each standing on its own:
469-
470-**1. The facts in a module of their own.** `Sys.raz` keeps its code,
471-over POSIX's names; what C fixes for each system, the layouts, the
472-numbers and the names that differ, goes in a new module, `CAbi`, one
473-file per target (`CAbi.linux-x86_64.raz`, `CAbi.freebsd-x86_64.raz`),
474-as `Sys` has: offsets, sizes and constants, and the externs whose
475-names differ behind one raz name (`CAbi.errno(): ^I32`). `Sys` reads
476-a struct stat as bytes at `CAbi`'s offsets. Porting `Sys` to a C
477-library is then writing that file, about a hundred lines, and nothing
478-else. It adds a module and breaks no program.
479-
480-**2. The facts written by C.** `tools/cabi.c`, a C program that
481-prints `CAbi`'s file for the system it is compiled on, from its own
482-headers, with `offsetof`, `sizeof` and the constants: no fact is typed
483-by hand, and a porter runs it once. `make check`, where there is a C
484-compiler, runs it and compares with `lib/`'s file, and does the same
485-with `musl-gcc` where that is installed.
486-
487-**3. Errnos as Linux's.** `Sys` exports names for the errnos programs
488-test (`Sys.noEntry = -2`, `again`, `intr`, `exists`, ...), with
489-Linux's numbers, and `Sys` over C maps the C library's errno to them
490-through a table in `CAbi`, so that "as on Linux" holds everywhere.
491-`Files` and the programs use the names. It adds constants and breaks
492-no program.
493-
494-**4. The compiler's C library.** The loader's path, the library's
495-name and the start-up symbol become facts of the target, not
496-constants: `linux-x86_64` links against glibc or musl, by an option,
497-or by default by which loader the machine has. Appendix A says the
498-C library is the implementation's to choose under "The target", and
499-`test/libc` runs under each one installed.
500-
501-Piece 4 has a gain today: raz programs that use C run on Alpine.
502-Pieces 1 to 3 pay when a second system is ported, and 3 needs 1.
442+A Windows target would keep volume 2 as it is: it describes the
443+library on a Unix target. Windows has no stable system calls, no
444+signals, no fork, no termios, and fds that are handles, so its `Sys`
445+can't be the one volume 2 gives. Appendix A's core already lets a
446+target leave out all of `Sys` past writing, ending the program and
447+getting memory: a Windows target gives the core, and what else it has
448+in a module of its own (`Win`), told on a page of its own beside
449+volume 2. Volume 1 needs at most a sentence, that `link static;`
450+means no C library where there are no system calls to make. The
451+compiler needs a PE writer and Microsoft's calling convention.
503452
504453 ## A slice's pointer
505454

doc/raz-lib.md (history) modified +19 -2

@@ -11,7 +11,7 @@
1111 | Module | What |
1212 |---|---|
1313 | `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 |
14-| `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 |
14+| `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` |
1515 | `Out` | writing text and numbers to standard output, buffered; safe to call from several threads |
1616 | `C` | the parts of the C library the others use, and `printf`, `fflush`, `stdout`, `pthread_create`; a program that imports it uses C |
1717 | `Lock` | a lock for short sections, for C's threads and `Thread`'s alike |
@@ -164,7 +164,14 @@
164164 **Sys** gives every target the same procedures, so that a program
165165 that needs only these runs wherever raz does: through system calls on
166166 Linux, through the C library elsewhere. A result that can fail is a
167-number, minus an errno, as on Linux; 0 is success.
167+number, minus an errno, as on Linux; 0 is success. The number is
168+Linux's on every target: `Sys` over another system's C library gives
169+the Linux errno of the same name, and a program tests it by the names
170+below; one with no Linux twin keeps its own number. `Sys.raz`, the
171+`Sys` over C, keeps to POSIX's names; what a C library fixes for its
172+target, the layouts of its structs, its numbers and the names that
173+differ, it takes from `CAbi`, one file per target, which
174+`tools/cabi.c`, compiled there, writes.
168175
169176 ```
170177 module Sys;
@@ -179,6 +186,16 @@
179186 (* the limits limit and setLimit take, by their numbers on Linux; each target has its own *)
180187 limitCpu* = 0; limitFileSize* = 1; limitData* = 2; limitStack* = 3;
181188 limitCore* = 4; limitProcs* = 6; limitFiles* = 7; limitMemory* = 9;
189+ (* errors, minus Linux's errnos on every target *)
190+ errPerm* = -1; errNoEntry* = -2; errNoProcess* = -3; errIntr* = -4;
191+ errIo* = -5; errBadFd* = -9; errChild* = -10; errAgain* = -11;
192+ errNoMemory* = -12; errDenied* = -13; errExists* = -17;
193+ errNotDir* = -20; errIsDir* = -21; errInvalid* = -22;
194+ errNotTerminal* = -25; errNoSpace* = -28; errPipe* = -32;
195+ errNameTooLong* = -36; errNotEmpty* = -39; errLoop* = -40;
196+ errAddrInUse* = -98; errNetUnreach* = -101; errConnReset* = -104;
197+ errTimedOut* = -110; errRefused* = -111; errHostUnreach* = -113;
198+ errInProgress* = -115;
182199
183200 type
184201 Access* = (reading, writing, creating, exclusive, truncating, appending, executing);

doc/raz.md (history) modified +2 -1

@@ -1648,7 +1648,8 @@
16481648
16491649 - **The target.** Which machines and systems it compiles for, and the
16501650 names of their files (`linux-x86_64`, section 3); for each, the size
1651- of an address, and so of `INT`, and whether it has reals.
1651+ of an address, and so of `INT`, whether it has reals, and which C
1652+ library a program that uses C is linked against.
16521653 - **Separate compilation.** Whether modules are compiled on their own,
16531654 and if so into what: the object file, its format, the form of the
16541655 code in it, when one is out of date, and how an instance is named so