The entry fault_ring
The faults of a process as records of a ring, case by case. The design: Architecture: The fault ring.
What it is for. A fault does not have to end a process. With a fault handler and a fault ring, a process repairs its own faults (a page that it commits on first use, a stack that grows, a debugger that steps a thread) with no code in the kernel that knows its policy. This process checks each rule of that mechanism, and of the thread control that a handler uses, against a real fault: 36 cases, each in a child process, each with a result that the process checks.
What a reader sees. Start it from the start menu, or with start("fault_ring") in the console. The window has one row for each case, which turns right or wrong as its child stops. The log has one line for each child: fault_ring: <case>: the child stopped: <stop cause>, the address <address>: as it must, or : WRONG. The last line is fault_ring: ok, 36 cases: ..., or fault_ring: failed: <count> cases of 36. Case 3 shows the time of one repaired fault, as a measure.
Why each case runs in a child. Several cases end in a stop of the process: a fault of the handler, a full ring, a handler that ends. A child is this same module, started from the boot image with a role in the value VALUE_ROLE of its context. When a child stops, the parent reads its stop cause and its stop report, and checks that the budget of the child got back every page and every thread. The parent and the child share one page (Shared_Page) for the values that a case reports, its result bits too: a stop carries no result.
Its grants: Image, to start its children from the boot image. Its log handle has the right Give: the child that repairs logs its own cases. Its budget holds one child at a time (512 pages, 20 threads) and one thread of its own that spins while a child tries to name it.
What it does not prove. The cases of the debug trap run on the processor of the test only: case 36 accepts two outcomes, and its line says which one the processor gave. The cases use one processor model, under QEMU.
How the mechanism works:
A process names one of its threads as its fault handler, with the fault kinds that it takes. A fault of such a kind of another thread then does not stop the process: the kernel writes a record in the ring of the handler, and the thread waits; the handler repairs with the operations of the virtual memory and answers. Each case of this process runs in a child process (this module, with a role), so that a case that stops its process stops only that child:
- 1. to 4. One child repairs: a read of a page that is not committed (the handler commits the page and writes a value in it; the thread reads that value), a write to a read-only page (the handler gives Write back), a stack that grows by 64 pages (the time of one repaired fault is measured), and an answer with a wrong serial (refused).
- 5. The handler answers Stop: the stop report is the one of a fault with no handler.
- 6. A fault of the handler itself: not delivered, the process stops.
- 7. A full ring: 17 threads fault, the handler reads none; the 17th fault stops the process, and the kernel counts it.
- 8. The process stops while a thread waits: its budget gets back every page and every thread.
- 9. The handler ends while a thread waits: the process stops with the stop cause of a fault that no thread can answer.
- 10. A thread with the entry of an earlier word wait still in the table of words faults, and the page of that word is decommitted while it waits: it still waits, with one record, and one answer resumes it.
- 11. A new handler while a thread waits: the ring with its record ends, and the process stops with the same stop cause as in case 9.
- 12. An answer from another process (this parent), with the thread number and the serial of the record of the child: refused.
- 13. 10 000 faults, each answered at once by a handler that spins on another processor, while the faulting thread can still be on its way out of its processor: each one resumes once, with the right value.
- 14. A divide error: one record of its kind; Resume is refused, Stop gives the stop report of the fault, at the instruction of the record.
- 15. An invalid opcode (ud2): the same, with its kind.
- 16. A breakpoint (int3), a trap: Resume lets the thread go on after it.
- 17. A divide error with a handler of page faults only: no record, and the process stops as with no handler.
- 18. A privileged instruction (cli): a protection fault, as in 14.
- 19. The kinds never delivered: Fault_Handler_Set refuses them; a divide error of the handler itself stops the process.
The control of a thread, cases 20 to 27 in one child:
- 20. A stop of a thread that spins: its instruction address is inside its loop, and the loop does not turn while it is stopped.
- 21. A write of a register (r12) that the thread then publishes.
- 22. Writes of a frame that a process cannot hold (the code selector of the kernel, the I/O privilege level, interrupts off, an instruction address that is not canonical): each refused, and the thread runs after its Resume.
- 23. Writes of an extended state that the processor refuses (a header that names a component that is not saved, a reserved bit of MXCSR): each refused; the area that was read is accepted.
- 24. A stop of a thread that waits, then its wake: it does not run until its Resume.
- 25. Two stops need two Resumes.
- 26. The rights of a thread handle: with Read and Control (the right to end it), each command is refused; with Inspect only, a stop, a read and a resume are accepted, and a write is refused; with Write only, a write is refused too: a write needs Inspect and Write.
- 27. A divide error whose handler adds the length of the div to the instruction address and writes rax: Resume, refused before the write, is accepted after it, and the thread goes on.
- 28. In its own child: no call names a thread of another process without a handle; the thread of the parent keeps running. The entries to the gates and the debug trap (cases 29 to 35, one child whose handler takes Debug, Breakpoint and General_Protection; case 36 in its own child):
- 29. int 3 in two bytes (CD 03): a breakpoint, at the address + 2.
- 30. int 14 (CD 0E): a protection fault with the error code 0x72, never a page fault; the handler skips its two bytes.
- 31. int1 (the byte F1): a debug trap at the address + 1.
- 32. The trap flag set with popfq: one debug record for each instruction until the popfq that clears it.
- 33. mov ss, then syscall, with the trap flag: on the processor of the test, the machine goes on, and each record is a debug trap of this process, in its code. It does not show that the processor gave no trap at the first instruction of the kernel entry: the kernel drops such a trap there.
- 34. mov ss, then int3, with the trap flag: one breakpoint record, and each other record is a debug trap in the code; a held trap at the stub of int3 is dropped by the kernel.
- 35. Two int1 in a row (F1 F1): two debug records, at the first + 1 and + 2. The kernel drops a debug exception with no status at an int1 that a hypervisor gave again before it ran; the trap of the first int1 is at an int1 too, and must stay.
- 36. mov ss, then int1, with the trap flag: either debug records in the code, or, on a processor that gives the held trap at the stub of int1, a stop of the child as a fault of a debug exception, with the instruction address 0. The line says which.
fault_ring module with an entry
- Hash
4fb1a8eb8a4641ba331e7c4938257a6fe3140dc1a48011af86edafa636202a6e- Size
385217 bytes- Exports
0- Imports
0- Imported by
0- License
- MIT
The faults of a process as records of a ring, case by case
| Fact | Value |
|---|---|
| Kind | Modules with an entry |
| Source | src/modules/demonstrations/fault_ring |
| Boot image | yes: in the boot image, 385217 bytes in this build |
| Build settings | none: the defaults of the source |
| Imports | none |
| Imported by | none |
Neighbours
It imports no module, and no module imports it. The module graph shows it with the other modules that have no edge.
Exports
| Export | What it does |
|---|---|
entry() | is the entry of the parent and of each child: the value VALUE_ROLE of the context says which |
entry
entry()
entry is the entry of the parent and of each child: the value VALUE_ROLE of the context says which.
A child waits until the parent sets the word go of the shared page, then runs its role (child). A child that checks writes one bit for each of its checks that held in the shared page, and stops itself with Done; a step that fails writes its line and stops with Failed.
The parent, in order:
- 1. It opens its window and maps the boot image.
- 2. It runs one child for the cases 1 to 4, then one child for each of the cases 5 to 19, and checks the stop cause, the stop report and the result bits of each (
child_run). - 3. It runs one child for the controls of a thread (cases 20 to 27), and one for case 28, while a thread of its own spins and must keep running.
- 4. It runs one child for the entries to the gates and the debug trap (cases 29 to 35), and one for case 36.
- 5. It writes the summary line, then draws the window each second.
The stop: with no random seed, or a role word that names no role, it stops with Refused; with no window or no boot image, with Failed. Else the parent never returns.
- Form
- The entry of the module: one parameter, an address, fixed by the contract.
src/modules/demonstrations/fault_ring/main.odin:1679
Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).
What the root service gives it
| What | Value | As the root service says |
|---|---|---|
| Grants | It starts its children from the boot image; the child that repairs logs its own cases. | |
| Other terms of its start grant set | log_gives = true | |
| Budget that it asks for |
| One child at a time: 512 pages and 20 threads (17 that fault in a full ring, its main thread and its handler); one thread of its own that spins while a child tries to name it: 2385 pages. And the glyph memory of the copy of the text rendering of the drawing module, which draws its text: 354 pages (display.TEXT_MEMORY_PAGES). 2385 + 354 = 2739. |
The start grant set is read from start_grant_sets in src/modules/system/root/start_grant_sets.odin. The stated budget is read from the constant MODULE_BUDGET of the source of the module (its line); the build adds the counted parts and writes the sum in the module (tools/modustool/build/budget_count.odin); the root service accepts it up to the largest budget of a process, and adds the limits of processor time and of log records (src/modules/system/root/budgets.odin).
