StuBS
context.h File Reference

Functionality required for context switching. More...

#include "types.h"
Include dependency graph for context.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  StackPointer
 Structure for saving the stack pointer when switching coroutines. More...
 

Functions

void * prepareContext (void *tos, void(*kickoff)(void *), void *param1=nullptr)
 Prepares a context for its first activation. More...
 
void context_switch (StackPointer &current, StackPointer &next)
 Executes the context switch. More...
 
void context_go (StackPointer &next)
 Executes a thread for the very first time. More...
 
void trampoline_go ()
 Helper function to prepare parameters for Thread::kickoff. More...
 

Detailed Description

Functionality required for context switching.

Function Documentation

◆ trampoline_go()

void trampoline_go ( )

Helper function to prepare parameters for Thread::kickoff.

This function will copy the first parameter for the kickoff function from the non-scratch register r15 into the register rdi (which is the first parameter according to the SystemV ABI).

context_switch as well as context_go jump to this function on the first execution of a new context. The value mentioned above was placed on the stack by prepareContext during initialization and loaded into the register r15 while restoring the context in context_switch or context_go.