Skip to content

Latest commit

 

History

History
50 lines (32 loc) · 5.32 KB

UPCALL.md

File metadata and controls

50 lines (32 loc) · 5.32 KB

An upcall is an entrypoint to a Process. For more information about the semantics of a Process, see PROCESS. An entrypoint is the instruction that is jumped to when yielding to the Process. Every Process has at least one valid upcall to be functional: the onYield upcall. This is the entrypoint when the Process is simply the target of a yield call. This contains the value of the instruction pointer that will be established as the kernel yields CPU control to that Process.

An upcall does not necessarily follow a conventional ABI for the architecture. State is passed via the stack (and potentially by cooperative convention between processes via registers and other shared memory.) Main parameters that are meant to be assigned and used to understand the context of the upcall are stored on the stack page that is established by the Process or by its parent when the upcall entrypoint is registered.

Only the Process itself or its owning parent can establish the upcalls for a Process. It does so via the MAP_UPCALL system call which sets the given address into the corresponding entry in the kernel's Process metadata.

Here are the available enumerated upcalls securely faciliated by the exokernel (Upcall):

  • 1: YIELD - onYield upcall which is just a normal execution path.
  • 2: PAUSE - onPause upcall which happens when the Process is being pre-empted and should save its context.
  • 3: FREE - onFree upcall is a hint that the Process is about to be deallocated which can only be invoked by an owning Process.
  • 4: FAULT - onFault upcall happens on a page fault.

Here is a more detailed view of each upcall.

For the onYield upcall, the arguments are as follows:

  • processId - The processId of the process that yielded to the Process. Can be 0 (null) if the system yielded to the Process and not a particular Process that had done so.

For the onPause upcall, the arguments are as follows:

  • processId - The processId of the process pre-empting the Process. Can be 0 (null) if the system pre-empted and not a particular Process that had done so.

For the onFault upcall, the arguments are as follows:

  • address (address) - The virtual address that caused the fault.
  • location (address) - The virtual address of the instruction that caused the fault.
  • processId (ProcessId) - The identifier for the Process that caused the fault. When the onFault is issued to the parent Process, this can indicate a failure of the child Process to handle the fault, or allows the parent to handle the fault on behalf of a child Process. This also can be used to determine that another Process caused the fault, but we are handling it because the fault occurred within a Resource owned by our own Process.
  • reason (FaultReason) - The determined reason (type of fault) for the fault.

The possible enumerations of reasons (FaultReason) are as follows:

  • 0: NotPresent - The requested page is not present.
  • 1: NotWritable - The requested page was written to but was not authorized for writing.

The onFault upcall occurs when a page fault happens during the runtime of the Process or when a different Process faulted on an address of a Resource owned by the targeted Process. This upcall also gets the processId of the Process active during the fault. It then also has the normal context of the fault available by the conventions available on the particular hardware copied into the stack page assigned with the handler.

The kernel system calls related to upcall maintenance have an enumerated return value to indicate the error or 0 if successful. The UpcallError error codes are as follows:

  • 0: SUCCESS - Successful operation.
  • 1: Reserved - To provide parity with MemoryError::INVALID_FLAGS.
  • 2: Reserved - To provide parity with MemoryError::NOT_FREE.
  • 3: Reserved - To provide parity with MemoryError::NOT_ALLOCATED.
  • 4: INVALID_SOURCE - The upcall provided is not known.
  • 5: INVALID_TARGET - The given Process on behalf of which we will map the upcall is not valid or owned by the current Process.

The kernel offers several primitive functions to facilitate the maintenance of process upcalls:

  • MAP_UPCALL(upcall, entrypointAddress, stackAddress) -> UpcallError - Maps the given entrypointAddress to use when the upcall given by upcall is triggered. The upcall is one of the enumerated values found described above as Upcall. It will establish the stack with the stackAddress provided. Fails with INVALID_SOURCE if the upcall is unknown.
  • MAP_CHILD_UPCALL(processId, processAddress, upcall, entrypointAddress, stackAddress) -> UpcallError - Maps the given entrypointAddress to use when the upcall given by upcall is triggered. The upcall is one of the enumerated values found described above as Upcall. It will establish the stack with the stackAddress provided. The entrypointAddress and stackAddress must be correct from within the context of the address-space of the given Process, not the current Process. Fails with INVALID_TARGET if the calling Process is not the parent of the given Process (that is, processAddress does not point to the same physical page as the PML4 within the address space rooted at processId). It also fails with INVALID_TARGET if the given Process does not exist. Fails with INVALID_SOURCE if the upcall is unknown.