modus
Menu
On this page

The context of a process

The one record that a process receives when it starts: 20 handles and 24 values. A role is a place of the record with a meaning.

The context: the one record that a process receives when it starts, in place of text arguments that it must parse. The address of the record is the parameter of the entry.

The record has 18 handles and 24 values of 64 bits. Its starter writes it and maps it read-write at CONTEXT_ADDRESS before the first thread runs (the kernel does both for the root service, which has no starter). A process finds each thing at a fixed place: the index of a handle or of a value is its role. So a process needs no name, no path and no parser to find what it was given: ctx.handles[CONTEXT_LOG] is its log, and a handle that its starter did not give is 0. A process that starts with a context of zeros has no handle: it can compute and stop, and reach nothing.

Three groups of places exist:

  • The places that the system fixes for every process: the log, the budget, the wiring ring, the seed, the fixed ranges that the starter mapped. Every starter writes them in the same way.
  • The places of the first process, the root service: the kernel writes them at boot, with every handle that exists then (the machine, the framebuffer, the boot image, the records of the log).
  • The places that a starter and its process agree on: the handles 0 to 13 and the values 0 to 8. The root service gives each process the handles of its grants there (src/library/modus/system, GRANT_...); a call host receives its call ring at 0 and its call region at 1.

A handle of the context has the rights that the starter chose, never more than the starter holds. Who starts a process decides what it can reach: the context is the whole of its authority at its start. The design:.

The handles 0 to 13 are the places of a starter and its process, and each is taken by some role. The handles 14 to 18 have the roles of the system below; a new role of the system takes the handle 19, never under

  1. 14. The handle 19 has no role yet.

See: Module contract: The context

The comment above CONTEXT_HANDLES in src/library/modus/contract/operation/operation.odin.

The roles that the system fixes for each process

The values 0 to 15 began as free values, and the roles of the system took 9 to 15 one after the other until two roles wanted one number. The values 16 to 23 are for the roles that the system fixes for every process: a new role of the system takes a number there, never under 16. A starter and its process use 0 to 8 for their own values.

The comment above CONTEXT_VALUES in src/library/modus/contract/operation/operation.odin.

ConstantPlaceHandle or valueWhat the file says
CONTEXT_LOG14handle

The roles of the handles that the system fixes for each process. A handle that the process was not granted is 0.

The handle 14: the log of the kernel, with the right Write. A process writes its lines with the kernel operation Log on it (system.log does). The starter gives it, and the root service gives it to each process that has the grant log; a call host gets it from the console. With no log handle, a line of the process goes nowhere. The log of the kernel.

CONTEXT_VALUE_SEED9value

The values 9 to 12: the random seed of the process, 32 bytes, that its starter writes. A start with a seed of zeros is refused. The root service has none: it gathers its own. A process does not use the values 9 to 12 for another role.

The generator of the process (src/library/modus/random) reads the seed, then writes zeros over the four values: a copy of the context made later holds no seed. A starter makes the seed of each child from its own generator (random.values_with_seed).

See: Randomness
CONTEXT_VALUE_SEED_STRENGTH16value

The value 16: the strength of the seed of the system, from which the seed of the process comes: the word of a Seed_Strength. The starter writes it with the seed.

The seed itself cannot say how it was made: the generator of the process keeps this value. The handshake of src/library/modus/quic refuses a seed weaker than its least strength, and the process randomness shows it.

CONTEXT_VALUE_SETTINGS_PASS17value

The value 17: the pass that the process settings runs with no window, the word of a settings.Pass: 1 for the pass at boot (it reads the settings kept in its store, writes the settings page, and stops), 2 for the next appearance that the Control Center asks (modus:contract/settings).

The root service writes it when it starts settings for a pass; each other start of settings has 0 and opens its window. No other process reads this value.

CONTEXT_VALUE_SECOND_POINTER_THEME_ADDRESS18value

The values 18 and 19: the address and the size of the second pointer theme file that the root service gives the compositor (the theme of the system, beside the theme of the owner at the values 6 and 7 of the compositor). The setting "pointer_theme" chooses between the two.

The value 18 is the address where the root service mapped the file, read-only, in the compositor; 0 when it mapped none.

CONTEXT_VALUE_SECOND_POINTER_THEME_SIZE19valueThe value 19: the size in bytes of the second pointer theme file at the address of the value 18. The compositor reads no byte past it.
CONTEXT_VALUE_FIXED_RANGES_MAPPED20valueThe value 20: a set of bits, bit n for the member n of the fixed ranges (modus:contract/fixed_addresses, Fixed_Range): the ranges that the starter mapped for this process. A set bit is the statement of the starter that the range is mapped; a process reads nothing at a fixed range whose bit is clear. It is a value of the context, which only the starter writes, and not a field of a shared page, which another process can write.
CONTEXT_VALUE_DEBUG_IMAGE_SIZE21value

The value 21: the size in bytes of the debug image, which the starter mapped at the fixed range Debug_Image (modus:contract/fixed_addresses) when its bit of the value 20 is set. The value 23 has no role.

A process that prints a stop report (the console) reads the names of the procedures there; with no debug image, a report names offsets only.

CONTEXT_VALUE_MEASURE_RUN22value

The value 22: the machine runs for a measure (1), or not (0). See measure run.

The root service writes 1 in the context of each process that it starts when the boot image holds the resource measure_run: the tool puts it in the boot image of modustool measure only. A process that starts a child copies the value.

A process that measures a rate over a duration (reads in one second, records in one second) does so only when the value is 1 (system.measure_run). With 0 it runs its checks, which end after a count of work, and writes no rate.

CONTEXT_BUDGET15handleThe handle 15: the budget that pays for the process, with the rights Give, Read and Spend. Each page and each object that the process makes is paid from it; Memory_Create and Process_Create name it. The loader of the starter gives it, and a starter cannot put another handle at this place: the process receives its new budget here. The root service receives the root budget with Commit too. When the process stops, what the budget still holds returns to the budget of its starter. The budget of the process.
CONTEXT_WIRING_RING16handleThe handle 16: the wiring ring, a memory object with Read and Write, for a process whose module declares a record output or a record input; 0 for each other process. The root service gives each end of a wiring of the process on it (modus:contract/output, Wiring_Command), and gives the handle of each end through its memory, so the process proves that the handle came through it. See wiring ring. The wiring ring.
CONTEXT_LOG_OUTPUT17handleThe handle 17: the output ring of the record output log, a memory object with Read and Write, when the wiring list of the start of the process wires log; 0 for each other process. The library writes there each log record that the kernel took, or refused for its budget alone, after it gave it to the kernel (modus:contract/output, Log_Output_Record). The end of log never goes through the wiring ring: a process whose only wiring is log has none. See record output log. The output ring of the record output log.
CONTEXT_LOG_OUTPUT_END18handleThe handle 18: the end page of the wiring of log, with Read only: the root service alone writes its end words, so the writer learns that its reader stopped or closed, and no side forges the end of the other. 0 when the handle 17 is 0. The end page of the record output log.

Read from src/library/modus/contract/operation/operation.odin.

The roles of the first process, the root service

ConstantPlaceHandle or valueWhat the file says
ROOT_MACHINE0handle

The roles of the first process (the root service).

The handle 0: the machine, with every right of the machine. The kernel gives it at boot to the root service only. The root service gives a part of its rights to a process that has a grant for it (Inspect, Stop, Schedule, Physical): a machine handle reaches each process, so no other process receives it whole.

ROOT_FRAMEBUFFER1handleThe handle 1: the memory of the framebuffer that the firmware set up, with Give, Read and Write; 0 when the firmware gave no framebuffer. The root service draws the boot display there, then gives it to the compositor, which owns the screen.
ROOT_BOOT_IMAGE2handleThe handle 2: the memory of the boot image, with Give and Read: every module and resource that the boot program checked. The root service starts each process from it, and gives it read-only to a process that has the grant image.
ROOT_LOG_RECORDS3handleThe handle 3: the memory of the records of the log of the kernel, with Give and Read. The root service gives it, read-only, to a process that has the grant log_records, as the process that shows the log. Memory, with Read: the records of the log.
ROOT_DEBUG_IMAGE4handleThe handle 4: the memory of the debug image that the boot program read, with Give and Read: the names of the procedures for the stop reports. The kernel reads none of its pages. Memory, with Read: the debug image that the boot program read. 0: none.
ROOT_VALUE_WIDTH0valueThe value 0: the width of the framebuffer in pixels; 0 with no framebuffer. The values 0 to 3 describe the handle 1.
ROOT_VALUE_HEIGHT1valueThe value 1: the height of the framebuffer in pixels.
ROOT_VALUE_PIXELS_PER_LINE2valueThe value 2: the pixels from the start of one line of the framebuffer to the start of the next, which can be more than the width.
ROOT_VALUE_FORMAT3valueThe value 3: the order of the bytes of a pixel, a Pixel_Format of the boot information (red first or blue first).
ROOT_VALUE_BOOT_IMAGE_SIZE4valueThe value 4: the size in bytes of the boot image of the handle 2.
ROOT_VALUE_DEBUG_IMAGE_SIZE5valueThe value 5: the size in bytes of the debug image of the handle 4. 0: no debug image.

Read from src/library/modus/contract/operation/operation.odin.

The roles of a process that the root service starts

ConstantPlaceHandle or valueWhat the file says
GRANT_DISPLAY0handleThe handle 0: the display ring to the compositor, a memory object with Read and Write. A process with a window sends its commands there, and receives its input as completion records (src/library/modus/display). Memory: the ring to the compositor.
GRANT_ROOT1handleThe handle 1: the root ring, a memory object with Read and Write, for a process with a start grant of root_ring.ROOT_RING_GRANTS, as the console. It sends Root_Command records on it: start, stop, connect, grants, revoke, replace, and the commands of the principals. The root service checks each command against the start grants of the sender. Memory: the ring to the root service, to start and stop processes.
GRANT_TERMINAL_PROCESS1handleThe handle 1 of a terminal, which has no root ring: the process that writes in it, with the right Read (package terminal). A terminal: the process that writes, with Read.
GRANT_TERMINAL_DEVICE0handleThe handle 0 of a terminal that draws no window (package terminal, renderer_context_of): the ports of the second serial port for serial_terminal, the framebuffer for grid_terminal. A terminal with a window has its display ring there. Ports, or memory: the device that the terminal draws on.
GRANT_TERMINAL_INPUT2handleThe handle 2 of grid_terminal: the input ring of the input service, which it reads in place of the compositor. Memory: the input ring.
GRANT_MACHINE2handleThe handle 2: the machine, with only the rights of the grants of the process: Inspect to read the reports of the processes and of the kernel, Stop to stop the machine, Schedule to change the scheduling strategy. The machine, with the rights of the start grant set: Inspect, or Inspect and Stop.
GRANT_IMAGE3handleThe handle 3: the memory of the boot image, with Read, for a process with the grant Image: it lists the modules, loads them, and reads the descriptions of their exports. Its size is the value 0. Memory: the boot image, to list the modules.
GRANT_LOG_RECORDS4handleThe handle 4: the memory of the records of the log of the kernel, with Read only, for a process with the grant Log_Records: it reads the lines of every process, and writes none. Memory, with Read: the records of the log.
GRANT_TERMINAL_TEXT4handleThe handle 4 of a process with the grant Terminal, and of its terminal: the text region (package terminal). The one process with Log_Records, the log service, has a window. Memory: the text region of a terminal.
GRANT_SERVICE5handleThe handle 5: the service ring of a service, a memory object with Read and Write. The root service names each new connection of a caller on it, with the call ring and the call region of that caller (src/library/modus/system/service.odin). The file of the service is at the value 1. Memory: the service ring. The root service names each connection of a caller on it.
GRANT_TERMINAL_RING6handleThe handle 6 of a process with the grant Terminal, and of its terminal: the terminal ring (package terminal). Memory: the terminal ring.
GRANT_DEVICE_RING6handleThe handle 6 of the client of a device service: the block ring of the grant Data_Disk or Scratch_Disk (modus:contract/block), the frame ring of the grant Network_Device (modus:contract/frame), or the stream ring of the grant Sound_Device (modus:contract/timed_stream). A client has one device service, and no terminal. Memory: the block ring, the frame ring or the stream ring.
GRANT_DATE_PAGE6handleThe handle 6 of the process date: the date page, with Write (modus:contract/date). Memory: the date page.
GRANT_STORAGE_RING7handleThe handle 7 of a process with the grant Store: the call ring of its private store (package storage). Memory: the call ring of the private store.
GRANT_DATE_PORTS7handleThe handle 7 of the process date: the two ports of the real-time clock. Ports: the real-time clock.
GRANT_STORAGE_REGION8handleThe handle 8 of a process with the grant Store: the call region of its private store. Memory: the call region of the private store.
GRANT_STORAGE_SERVICE9handleThe handle 9 of a process with the grant Store: the storage service, with the right Read: its state. The storage service, with Read.
GRANT_REPLACEMENTS10handleThe handle 10: the replacement table of the machine, with Read only, for a process that loads modules by itself: its loader reads the table before each load, so a replacement reaches the loads that follow. Memory, with Read: the replacement table of the machine (Replacement_Table).
GRANT_DEVICE_SERVICE10handleThe handle 10 of the client of a device service: the device service of its device ring, with the right Read. Its stop is an event of the client, so a wait for an answer of the device service ends when it stops. No client of a device service loads modules by itself. The device service of the device ring, with Read.
GRANT_DATAGRAM_RING11handleThe handle 11 of a process with the grant Network: the datagram ring of its endpoint (modus:contract/datagram). Memory: the datagram ring of the endpoint.
GRANT_TPM_RING11handleThe handle 11 of a process with the grant Tpm: the ring of the TPM service (modus:contract/tpm_service). Memory: the ring of the TPM service.
GRANT_NETWORK_CONTROL12handleThe handle 12 of the network service (the grant Network_Device): the control ring from the root service (modus:contract/datagram). Memory: the control ring of the network service.
GRANT_SETTINGS_PAGE12handleThe handle 12 of the process settings: the settings page, with Write (modus:contract/settings). Memory: the settings page.
GRANT_TPM_SERVICE12handleThe handle 12 of a process with the grant Tpm: the TPM service, with the right Read: its state. The TPM service, with Read.
GRANT_CLIENT_TABLE12handleThe handle 12 of the process with the grant Remote_Clients: the client table, with Read (modus:contract/remote). Memory, with Read: the client table.
GRANT_DATAGRAM_REGION13handleThe handle 13 of a process with the grant Network: the datagram region of its endpoint. Memory: the datagram region of the endpoint.
GRANT_TPM_REGION13handleThe handle 13 of a process with the grant Tpm: the region of the TPM service. Memory: the region of the TPM service.
GRANT_VALUE_IMAGE_SIZE0valueThe value 0: the size in bytes of the boot image of the handle 3.
GRANT_VALUE_TERMINAL_NAME0valueThe values 0 to 3 of a terminal: the name of the process that writes in it, its title (package terminal).
GRANT_VALUE_SEED_FACTS0valueThe values 0 to 7 of the process randomness: the facts of the seed of the system, which only the root service has (modus:random).
GRANT_VALUE_FILE_ADDRESS1valueThe value 1, for a service: the address where the root service mapped the file of the process, read-only. The service reads the descriptions of its exports there, to check each call; the value 2 is its size. A service: where the file of the process is, read-only (the descriptions of its exports).
GRANT_VALUE_FILE_SIZE2valueThe value 2, for a service: the size in bytes of its file at the address of the value 1.
GRANT_VALUE_STORAGE_FILE_SIZE3valueThe value 3 of a process with the grant Store: the size in bytes of the file of the storage service, which its client reads (package storage).
GRANT_VALUE_SERVICE_PRINCIPAL4valueThe value 4 of the module file service module_files: the principal of its store (modus:disk_process).
GRANT_VALUE_TERMINAL_COLUMNS4valueThe value 4 of a terminal: its columns.
GRANT_VALUE_UNLOCK_MODE5valueThe value 5 of unlock: what this start does, the word of an Unlock_Mode (modus:principals).
GRANT_VALUE_TERMINAL_ROWS5valueThe value 5 of a terminal: its rows.
GRANT_VALUE_UNLOCK_NAME6valueThe values 6 to 8 of unlock: the name of the principal to create.
GRANT_VALUE_UNLOCK_PRINCIPAL14valueThe value 14 of unlock: the number of the principal that asked for a change.
GRANT_VALUE_TERMINAL_MEASURE6valueThe value 6 of a terminal: 1 when it shows the rates of its process.
GRANT_VALUE_TERMINAL_SCREEN_WIDTH7valueThe values 7, 8 and 13 of grid_terminal: the width and the height of the framebuffer in pixels, and its pixels of a line. The values 9 to 12 are the seed.
GRANT_VALUE_TERMINAL_SCREEN_HEIGHT8value
GRANT_VALUE_TERMINAL_SCREEN_PIXELS_PER_LINE13value
GRANT_VALUE_SEAL_ALLOWED13valueThe value 13 of a process with the grant Tpm: 1 when a seal by the TPM is allowed, as the firmware verified the boot program.

Read from src/library/modus/system/grants.odin.

Grant enum

An enum of the package start_grant on i64: 8 bytes, 34 members. What a process receives, by name.

  • Root_Ring0
  • Inspect1
  • Stop2
  • Image3
  • Log_Records4
  • Serve5
  • Terminal6
  • Store7

and 26 more

CONTEXT_ADDRESS constant of the package operation

CONTEXT_ADDRESS :: 0x0000_7FFF_FFF0_0000

The address of the context of the process (Context): the starter maps one.

src/library/modus/contract/operation/operation.odin:97

values_with_seed procedure of the package random

values_with_seed :: proc "contextless" (generator: ^Generator, values: [op.CONTEXT_VALUES]u64) -> (with_seed: [op.CONTEXT_VALUES]u64)

values_with_seed gives the values of a process to start with a seed for.

src/library/modus/random/generator.odin:276

measure_run procedure of the package system

measure_run :: proc "contextless" () -> bool

measure_run says if this process runs for a measure: its starter wrote 1.

src/library/modus/system/measure_run.odin:14

ROOT_RING_GRANTS constant of the package root_ring

ROOT_RING_GRANTS :: bit_set[start_grant.]{...}

The start grants that give a process a root ring.

src/library/modus/contract/root_ring/root_ring.odin:702

Root_Command type of the package root_ring

Root_Command :: enum u32 {...}

The ring to the root service.

src/library/modus/contract/root_ring/root_ring.odin:39