The 200-line implementation of green threads from this tutorial with comments about the details I learned.
- Growable stacks
- x86-64 psABI stack layout and calling convention
- Q: how %rsp register works in stack construction in
spawn()
- when
ret
- when to move to next byte
- when
- A: Princeton COS217 slide on "Assembly Langauge: Function Calls"
- Q: how %rsp register works in stack construction in
- why
#[inline(never)]
forswitch()
?-
It's for stack alignment.
In the perspective of one task,
call switch
sub%rsp
for storing the%rip
when suspended. When it's resumed,ret
add%rsp
back to the original aligned address.
-