hn.today

Understanding "You are not expected to understand this."

taniwha.com6 points0 comments
Screenshot of Understanding "You are not expected to understand this."

The explanation deciphers a cryptic comment in Unix V6’s PDP-11 context-switch code: “You are not expected to understand this.” Each process’s state was split between a process-table entry and a per-process structure called udot, mapped at a fixed kernel address and containing its kernel stack. The routines savu, retu, and aretu saved or restored the stack and frame pointers; retu also remapped udot. Because these operations changed the active stack while execution continued, the code depended on careful timing and on interrupts being disabled during the transition.

The unusual branch in swtch handles a process that was swapped out for lack of memory while fork was creating a child. Before swapping, newproc saved a second stack position in u_ssav and marked the process with SSWAP. When the process later resumed, swtch restored its udot and ordinary context, then aretu reset the stack to the saved point inside newproc. Execution could therefore continue through swtch’s return, delivering the value 1 to newproc - and thus to the new child’s fork path - even though the program counter remained in swtch. The account also explains why this works with old C conventions: register variables and PDP-11 calling rules preserved values such as rp across the context-restoration routines.

Read on taniwha.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Source Control from Hell

Source Control from Hell

An early software job relied on a shared folder, manual change descriptions, and a tech lead copying code by hand, with coworkers announcing when they needed access to avoid overwriting each other. Discovering Git showed Alex how version control could make collaboration faster and safer, but his company kept its old process for years because it worked well enough for them. (frantic.im)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.