modus
Menu
On this page

The module probe

A module of commands that tests the sandbox of an isolated call. A call to a module that is not trusted runs the module as its own process, and its arguments travel as records. Each export does what a module must not be able to do to its caller: read any address, take all the processor time, use a handle that it did not receive. The console calls it with isolate("probe"). Do not load it directly: then it runs with the memory and the handles of the console.

What it is for. It shows the limits of a sandbox from the inside. A reader calls the exports one by one and sees that each harm stays in the sandboxed process: the console goes on, and the next call gets a new process with new data.

Example, in the console:

isolate("probe")        probe: 8 commands in a sandboxed process
count() + count() * 10  21
stop_machine(1)         2: the sandbox holds no handle
peek(0)                 error: the process probe stopped: a fault, page fault
count()                 1: a new process
spin()                  Escape stops the call

probe module with no entry

Hash
c6c297aa502c76042ba3363ed692acc45490bcbeb6b39d9d60bbd1c99e721d4a
Size
36864 bytes
Exports
8
Imports
0
Imported by
0
License
MIT

A module of commands that tests the sandbox of an isolated call

FactValue
KindModules with no entry
Sourcesrc/modules/tests/probe
Boot imageyes: in the boot image, 36864 bytes in this build
Build settingsnone: the defaults of the source
Importsnone
Imported bynone

Neighbours

It imports no module, and no module imports it. The module graph shows it with the other modules that have no edge.

Exports

ExportWhat it does
peek(address: Integer) -> Integerreads 8 bytes at an address
count() -> Integergives the number of calls of count
spin() -> Integernever returns
stop_machine(handle: Integer) -> Integerasks the kernel to stop the machine with a handle
checksum(text: Text) -> Integeradds the bytes of a text
shout(text: Text) -> Textgives a text in capital letters
lie(count: Integer) -> Textwrites no text, and gives a false count of bytes
log_long(count: Integer) -> Integerwrites one text of count bytes on the log (at most 2000): digits, then the words "the end of the long text"

peek

peek(address: ) -> 

peek reads 8 bytes at an address. In a call host, the address space has only the module, the call ring and the call region.

An address outside these stops the sandboxed process on a page fault; the console reports it, and its own memory is not reachable. After load("probe") the same call reads the memory of the console.

Parameters
  • address:
Result
Source
src/modules/tests/probe/probe.odin:36

count

count() -> 

count gives the number of calls of count. The data of a module is private to the process that runs it.

It starts at 1 in each new sandboxed process: a fault in an earlier call resets it.

Parameters
none
Result
Source
src/modules/tests/probe/probe.odin:47

spin

spin() -> 

spin never returns.

The console runs the line in its second thread, keeps the keys of the next line, and stops the call when the input presses Escape: "error: Escape stopped the call of spin". The sandbox has its own budget of processor time, so other processes go on.

Parameters
none
Result
Source
src/modules/tests/probe/probe.odin:58

stop_machine

stop_machine(handle: ) -> 

stop_machine asks the kernel to stop the machine with a handle. The result is the status of the kernel operation.

In a sandbox the handle names nothing: the result is 2, "no handle", for each value. The machine never stops through this export unless the caller loaded the module directly and passes the number of a handle of the machine that it holds.

Parameters
  • handle:
Result
Source
src/modules/tests/probe/probe.odin:76

checksum

checksum(text: ) -> 

checksum adds the bytes of a text. The bytes are in the call region.

Parameters
  • text:
Result
Source
src/modules/tests/probe/probe.odin:83

shout

shout(text: ) -> 

shout gives a text in capital letters. In a call host, the buffer of the result is in the call region: the caller reads the text there.

Parameters
  • text:
Result
Source
src/modules/tests/probe/probe.odin:94

lie

lie(count: ) -> 

lie writes no text, and gives a false count of bytes. The caller must not read more than its buffer.

lie(100000) gives "error: the result of lie has 100000 bytes: it does not fit"; length(lie(3)) gives 3: the console reads the bytes that the call region holds, never more.

Parameters
  • count:
Result
Source
src/modules/tests/probe/probe.odin:108

log_long

log_long(count: ) -> 

log_long writes one text of count bytes on the log (at most 2000): digits, then the words "the end of the long text". The log keeps a text whole: a text longer than its part of 512 bytes goes in several lines, never cut in silence. The result is the count of bytes of the text.

Parameters
  • count:
Result
Source
src/modules/tests/probe/probe.odin:118

Read from the source of the module, as the build reads it to describe the exports (tools/modustool/build/describe.odin).

Integer wire form

A wire form of the module contract: one word of a call. A signed integer of 64 bits, in a register.

Text wire form

A wire form of the module contract: one word of a call. The address of a slice record {address, count} of UTF-8 bytes.