Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Imports and Mappings

Two declarations sit at the top of every .fi file: import brings an external C or Pancake source file into scope under a chosen alias, and Mapping puts a memory region declared in the .fis into the protection domain’s address space.

Imports

ImportDecl ::= 'import' '"' FilePath '"' 'as' ident ';'
FilePath   ::= any text up to the closing quote   -- one line, relative to the project

An import declaration names the external implementation that backs the PD’s computation events. The parser takes the path as written, up to the closing quote, and decides nothing about it; the front end reads it relative to the project directory (import "include/eth.h" as eth; is valid) and picks the reader from the extension: .c and .h are C, .pnk is Pancake. Any other extension is rejected when the project loads. Every alias.f(..) call then resolves to a function the file exports, or the build fails. The alias becomes the prefix on every external call inside the PD.

What counts as exported depends on the language. For C, fic reads the file with libclang: every function that is neither static nor inline. For Pancake it scans the source for export fun declarations, which take at most four word arguments and return one word; their /@ ... @/ contract blocks are read alongside.

import "include/eth.h" as eth;     // C header; src/eth.c is linked
import "pingpong.pnk" as io;       // Pancake source — same call shape

Multiple imports are allowed, and they may interleave with mappings — order does not matter for parsing. Each alias must be unique within the file.

Mappings

MappingDecl ::= SecurityLabel? 'Mapping' ident '(' region (',' vaddr)? ',' perms (',' cached)? ')' ';'

region      ::= ident                      -- a MemoryRegion declared in .fis
vaddr       ::= hex                        -- explicit virtual address (optional)
perms       ::= string_literal             -- 'r', 'rw', 'rx', 'rwx', 'x', 'wx'
cached      ::= bool_literal               -- default: true

A mapping declaration installs a MemoryRegion into the PD’s address space. The mapping’s name derives the symbols the generated C defines for it (<mapping>_vaddr, _size, and _paddr where it is read) — see Boot Initialisation.

Fields

  • Security label — High or Low prefix, default Low. A mapping’s label must be at least its region’s: a Low mapping of a High region is rejected. See Information-flow labels below.
  • Name — the mapping’s own identifier. Distinct from the region’s name; one region can have multiple mappings under different names.
  • Region — the MemoryRegion declared in the .fis file.
  • Vaddr (optional) — pin the mapping at a specific virtual address. If omitted, fic allocates one. Hex literal.
  • Permissions — a quoted string of r/w/x characters. Order and case are insensitive: "rw" and "WR" are equivalent. Write-only is rejected; at least r or x must be present. The accepted set is r, rw, rx, rwx, x, wx.
  • Cached (optional, default true) — whether the mapping is cached in the CPU MMU. Device MMIO regions should be set false explicitly.

Examples

// Anonymous shared buffer at allocator-chosen vaddr, read-write, uncached.
Low Mapping ring_buffer(ring_buffer_outer, "rw", false);

// Same region, default cached flag (true).
Mapping packet_buffer(packet_buffer_outer, "rw");

// Pinned vaddr — useful for debugging or for binding two PDs to a
// shared layout that pre-allocates virtual addresses.
Low Mapping eth0(eth0, 0x2_000_000, "rw");

// High-side mapping of a High MemoryRegion. A Low mapping of that region
// would be rejected.
High Mapping eth_clk(eth_clk, 0x2_200_000, "rw");

// Read-only mapping (data-diode input).
Low Mapping input_buf(eth_outer_output, "r");

Information-flow labels

Both MemoryRegion and Mapping declarations may carry a High or Low prefix. The two-level lattice is:

flows_to(Low,  Low)  = true
flows_to(Low,  High) = true       // upgrade is fine
flows_to(High, Low)  = false      // downgrade is rejected
flows_to(High, High) = true

In source: Low is the default — omitting the prefix is equivalent to writing Low. Place the prefix before the MemoryRegion / Mapping keyword; placing it elsewhere is a parse error.

This is the one information-flow rule: the information-flow check, run after typing, rejects any mapping that violates flows_to(region.label, mapping.label), so a High region is never read through a Low mapping. Protection domains carry no labels of their own. The data-diode demo uses this to enforce one-way information flow. The Information Flow chapter has the detail, and the Memory Region Declarations chapter states the same rule from the region’s side.

A mapping’s addresses

A mapping is a value only through its addresses:

  • m.vaddr is its virtual address, which fic chose (or you pinned). It compiles to that constant.
  • m.paddr is the physical address of its region. It may be known only when the system boots, so it compiles to the symbol m_paddr, which the loader patches. fic declares and patches m_paddr only in a PD that reads it. On Microkit, a region whose paddr is read must be physically contiguous; Microkit picks its address when the region declares none, and on x86-64 the region must declare one.

Validation

  • Each Mapping’s region must reference a declared MemoryRegion.
  • Permission strings must contain at least one of r or x. "w" alone is rejected.
  • A pinned vaddr must be aligned to the region’s page size.
  • Mapping names are unique within the same .fi file.