WEBVTT

00:00.000 --> 00:05.577
Week 15: Shipped Without an Edit, for exercise 53k_ship_your_commands.

00:06.177 --> 00:12.593
A script steps this explainer, it was built with Claude, and its numbers are examples, not the lecture's.

00:13.120 --> 00:17.075
After the Week 15 reading on fork, wait, and the user shell:

00:17.675 --> 00:23.275
on Friday, December 4, your September commands run on your own kernel, unedited.

00:23.875 --> 00:28.757
No solution code here: the machine's state, not the lines that make it so.

00:29.280 --> 00:32.596
In September you wrote wc for your laptop.

00:33.196 --> 00:38.559
The course's reference wc builds for rv6 with no line changed.

00:39.159 --> 00:45.709
Each build is drawn by its target triple, the machine it is for, and by what its read call became.

00:46.240 --> 00:48.627
The file it counts is the page's own.

00:49.227 --> 00:58.081
At rv6$, the prompt of the shell inside the kernel, an echo line makes pantry: 38 bytes, one line of eight words.

00:58.681 --> 01:01.681
On the laptop, wc got the same bytes.

01:02.200 --> 01:05.149
One source file, unedited, for both builds.

01:05.749 --> 01:13.951
For the lab's laptop, the target triple is aarch64-apple-darwin, and read is a C library file read.

01:14.551 --> 01:18.548
There, wc pantry prints 1, 8, 38, pantry.

01:19.080 --> 01:26.735
For rv6, the triple is riscv64gc-unknown-none-elf, and read is a system call:

01:27.335 --> 01:32.305
its number, 5, goes into a7, and an ecall traps into the kernel.

01:32.905 --> 01:34.335
The gap is not drawn.

01:34.840 --> 01:37.889
The stepper starts on the reference, the solved kernel.

01:38.489 --> 01:42.029
Its strip names the steps, from the source to run's answer.

01:43.029 --> 01:44.405
The laptop build.

01:45.405 --> 01:49.703
The rv6 build: the same two lanes as the first figure.

01:51.200 --> 01:55.960
Next, what oslings ship, a course tool, makes of the rv6 build.

01:56.560 --> 02:08.371
The lab's rv6 build leaves an ELF file, the compiled program: entry point 0, and 2 loadable segments, each described by a PT_LOAD program header.

02:08.880 --> 02:13.151
.text, the code, is R X, read and execute, at 0.

02:13.751 --> 02:18.985
.rodata, the constants, is read only, R, after .text.

02:19.585 --> 02:26.281
PT_GNU_STACK describes no memory; there is no .data or .bss.

02:27.800 --> 02:33.571
The flat image: each segment's bytes at its own address from 0, and zeros in the gap.

02:34.171 --> 02:40.886
It ends after .rodata, in one page; the rest of that page is not part of the image.

02:42.400 --> 02:52.639
oslings ship writes userbin.rs, the shipped table: a row for each command it shipped, and mywc, the shipped wc, is last.

02:53.239 --> 02:57.407
Each entry's bytes come from its image file, through include_bytes!.

02:58.920 --> 03:07.949
At rv6$, these keys were typed into the kernel that cargo run boots: the pantry line, then run mywc pantry.

03:08.549 --> 03:15.321
The kernel shell's start command, run, asks lookup, the kernel's search by name, for mywc.

03:15.840 --> 03:19.883
Of the kernel's own 12 programs, none is mywc.

03:20.483 --> 03:24.650
The rest of lookup answers mywc, from the shipped table,

03:25.250 --> 03:28.704
and lookup gives back mywc, its shipped image.

03:30.200 --> 03:37.131
The user pages: the image's page at 0 is R X U, the U for reachable from user mode.

03:37.731 --> 03:44.323
The pages between are unmapped, and the stack page at 0x1_0000 is R W U.

03:44.840 --> 03:50.993
The system calls mywc makes, each with its number in a7 and the kernel's answer:

03:51.593 --> 03:54.631
open of pantry answers 3, a file descriptor;

03:55.231 --> 03:58.878
read on fd 3 answers 38, and then 0.

03:59.400 --> 04:05.623
Then 32 bytes in small writes, as this wc writes; yours may write differently.

04:06.223 --> 04:11.443
close answers 0, and it exits. It printed 1, 8, 38, pantry,

04:12.043 --> 04:16.809
and run reports pid 1, mywc, exited with status 0.

04:17.320 --> 04:24.635
Now the skeleton, the kernel as you receive it, with the same commands shipped into its userbin.rs.

04:25.235 --> 04:28.497
Up to the table entry, its steps are the reference's.

04:29.497 --> 04:33.059
At lookup, none of its 12 programs is mywc.

04:33.560 --> 04:35.823
The rest of lookup has not answered yet.

04:36.423 --> 04:43.931
The skeleton's kernel: its own table has no mywc. What does run mywc pantry print?

04:45.431 --> 04:46.605
Keep your answer.

04:48.120 --> 04:54.795
The rest of lookup answers nothing; lookup gives back nothing: nothing is loaded, and no program runs.

04:55.395 --> 04:59.746
These keys were typed into the skeleton's cargo run kernel, which printed:

05:00.346 --> 05:04.893
run: no such program: mywc (try progs), then the prompt.

05:05.400 --> 05:12.411
When the fallback is missing: the fallback is the part of lookup you write, and in the skeleton it is a placeholder.

05:13.011 --> 05:18.771
The skeleton's last step is drawn beside these keys, typed into its cargo run kernel.

05:19.280 --> 05:23.815
The test runs in its own world, with files and arguments of its own.

05:24.415 --> 05:32.517
For the skeleton, the test prints this line, quoted alone: [fail] exec::lookup("myecho") found nothing, but it is.

05:33.117 --> 05:35.112
The lines after it are not shown.

05:35.640 --> 05:44.297
The test runs four of the five commands shipped in the lab, myecho, mycat, mygrep and myhead, and never runs mywc:

05:44.897 --> 05:47.797
the run on this page is not in the test's world.

05:48.320 --> 05:53.158
You write lookup's fallback, in exec.rs, at its IMPLEMENT marker.

05:53.758 --> 05:58.213
The start of lookup, the function programs, and the type Program are given.

05:58.720 --> 06:06.363
oslings ship writes userbin.rs for you, and oslings run ships your commands too, before it builds.

06:06.963 --> 06:13.267
Until one of them has run, the shipped table is the empty one you receive: there is nothing to find.

06:13.800 --> 06:15.761
When it is written, this must be true:

06:16.361 --> 06:20.299
exec finds a command you shipped by its name, and run starts it.

06:20.899 --> 06:25.741
In the stepper, lookup found mywc for run mywc pantry.

06:26.240 --> 06:31.303
In the lab's run, when every check passes, the test prints its last ok line:

06:31.903 --> 06:36.148
[ok] 4 of your own programs run on your own operating system.

06:37.680 --> 06:46.703
One unedited source builds twice, and oslings ship turns the rv6 build into a flat image that exec finds by name.

06:47.303 --> 06:49.773
Next, the explainer From Keypress to Exit;

06:50.373 --> 06:52.783
then Friday's session, December 4.
