The unsafe modules of the standard library

A module is unsafe when its body says pragma Unsafe_Module;. Only an unsafe module may bind a C function (pragma Foreign_Import), paste C into the program (@embed), or import Hilde.Memory, the built-in module of addresses and raw memory. A safe module can do none of these, and the compiler checks it.

The modules a program imports are safe. Every call into C of the standard library is in one of the modules below, and a program cannot import them: only a module whose name begins with Standard. or Bindings. may import a Bindings. module (error H2045). Each binding begins with a short explanation of what it binds and which safe module is built on it.

The bindings

modulebindswhy it is unsafethe safe module built on it
Bindings.Libcryptolibcrypto (LibreSSL or OpenSSL)scratch buffers, the EVP calls and RAND_bytes, with addressesStandard.Libcrypto
Bindings.MlDsaML-DSA of FIPS 204 from libcrux, the C the compiler carriesthe addresses of keys, message, context, randomness and the buffers the results are written into, of the fixed sizes of FIPS 204Standard.MlDsa
Bindings.Argon2libargon2, the reference implementation of Argon2the buffer the tag is written into, the addresses of password, salt, secret and data, and the context the library reads them fromStandard.Password
Bindings.Bcryptthe check of a bcrypt hash through the runtime: crypt_checkpass of OpenBSD's libc, crypt_rn of libxcrypt on Linux, crypt_r of libcrypt on FreeBSDcalls into the runtime with @embedStandard.Password
Bindings.Tlslibtls, and the runtime's wait for a socket and its monotonic clockthe two handles of a client connection, the buffers of a send and a receive, and the socket's number it waits onStandard.Tls
Bindings.PcrePCRE2, and its JIT for Standard.PcreJita compiled pattern, the match slots and the JIT stack of one searchStandard.Pcre
Bindings.SqliteSQLitethe connection, its statements, the values handed in and read out, the migrationsStandard.Sqlite
Bindings.SqlCipherSQLCipheras Bindings.Sqlite, with the keyStandard.SqlCipher
Bindings.SqliteReplicaSQLitethe connection, statements prepared from text known only at run time, the values bound and the columns copied out, the online backup to and from a fileStandard.SqliteReplica
Bindings.Postgreslibpq, the client library of PostgreSQLthe connection, its results, the arrays of values, types, lengths and formats handed to PQexecParams, and the bytes read out of a resultStandard.Postgres
Bindings.MariaDBlibmariadb, MariaDB Connector/Cthe connection, its prepared statements, the MYSQL_BIND arrays of values and columns and the C memory they point at, and the options of the connection, written in @embed against mysql.hStandard.MariaDB
Bindings.DuckDBlibduckdb, DuckDB's release buildthe database, its connection and configuration, prepared statements, results and data chunks, the slots of out parameters, and values passed by value in @embed against duckdb.hStandard.DuckDB
Bindings.Databasenothing outside: abandon, and the box Erased with erase, unerase, reveal and revealWriteit ends the programme with a linear value that can no longer be ended the right way; it keeps a driver's connection, transaction or cursor in a box of bytes and casts it back to the type the driver names, which only the driver module that erased it does, Standard.Database.Sqlite, .Postgres and .MariaDBStandard.Database
Bindings.Arraynothing outside: the byte order of numbers, in plain Cthe address of a span and a byte offset into it, read or written as an Int32, Int64, Float32 or Float64 with @embedStandard.Array
Bindings.Timethe clocks of the C library, through the runtimecalls into the runtime with @embedStandard.Time
Bindings.BuildInfonothing outside: the macros and the table of values the compiler writes into a programme that compiles this modulespans made from the addresses of those C strings, with @embedStandard.BuildInfo
Bindings.Platformgethostname(3), asked once and kept; besides two functions of the runtime that answer from the macros of the C compilerspans made from the addresses of three C strings, with @embedStandard.Platform
Bindings.Bitsnothing outside the programme: a C union reads the bits of a binary64 or binary32 number, or of a two's complement integer, as an unsigned number of the same widtheight expressions with @embed over a union compound literal, no memory and no pointerStandard.Bits
Bindings.Secretthe terminal of the process with its echo off (readpassphrase on the BSDs and macOS, termios on Linux) and standard input, through the runtimea buffer of 1024 bytes from the allocator, its address handed to the runtime, wiped before it is freedStandard.Secret
Bindings.Accountthe password database through getpwnam_r(3), and geteuid(2), through the runtimea name copied into a buffer of 256 bytes on the stack of the runtime, refused when longer or holding a zero byteStandard.Account
Bindings.Resolvethe resolver of the C library, getaddrinfo, through the runtimethe buffer the runtime writes the addresses into, and calls into the runtime with @embedStandard.Resolve
Bindings.Terminalthe standard streams of the C library, a whole text written to standard error with write(2), and the terminal's echo, width and pending input, through the runtimecalls into the runtime, and the address of the text's bytesStandard.IO.Terminal
Bindings.SystemLogthe system log, openlog, syslog and closelog, through the runtimethe addresses of the bytes of the name and the text, and calls into the runtime with @embedStandard.Log
Bindings.Signalthe runtime's signal handler and its pipe, sigaction, kill, alarm and getpidcalls into the runtime with @embedStandard.Signal
Bindings.Arenathe runtime's arena, memory from the kernelthe arena's handle, and references and spans made from its addressesStandard.Arena
Bindings.Pollerthe runtime's poller, epoll on Linux and kqueue on OpenBSD, FreeBSD and macOSthe poller's handle and its callsStandard.Poller
Bindings.Taskthe runtime's fibers, scopes and channels, on threads of the processa task's argument and result, and a channel's values, in raw memoryStandard.Task
Bindings.Sharedthe runtime's mutexes, which park a waiting task, and its atomic operations on a word of 64 bitsthe value a mutex guards in one raw cell, moved out and back through a read reference, and the wordStandard.Shared
Bindings.Filethe file, directory, process, environment and socket calls of the C library, a TCP connection and reads and writes on a socket with a time limit among them, a file's status, owner, rename, link and sync and a temporary file, through the runtimethe addresses of the bytes of paths, buffers and network addresses, and a directory streamStandard.File
Bindings.Sandboxpledge with its execpromises, unveil and the child that measures its room on OpenBSD, no new privileges, Landlock and seccomp on Linux, the Seatbelt profile and the start under sandbox-exec on macOS, Capsicum on FreeBSD, through the runtimethe addresses of the bytes of promises, paths and permissionsStandard.Sandbox
Bindings.Seriala count shared by the whole process, kept in Ccalls into C with @embedStandard.Graph
Bindings.Resourcegetrlimit, setrlimit and getrusage, and the clock that counts from the system's start, through the runtimea buffer of slots the runtime writes the numbers into, and calls into the runtime with @embedStandard.Resource
Bindings.Watchinotify on Linux and kqueue on OpenBSD and FreeBSD, through the runtimethe address of a path's bytes, and calls into the runtime with @embedStandard.Watch
Bindings.Contexta pipe of the runtime, and the runtime's chain of reading ends with a count of references per level, which it waits on with pollthe address of a level of the chain, and calls into C with @embedStandard.Context
Bindings.X509libcrypto's keys, X.509 certificates and requests, PEM and DER, and the verification of a chain, called in @embed against the system's headers, the functions Bindings.C.Libcrypto imports called through it, and the two functions of ML-DSA found with dlsymmemory BIOs, the slots of out parameters, the buffers of signatures and DER, and the handles of keys and certificatesStandard.X509
Bindings.Entropygetentropy, for the keys of hash mapsa call into C with @embedStandard.HashMap
Bindings.Testingthe runtime's question whether the programme runs under valgrind, which only a build of hilde test --valgrind asks valgrinda call into the runtime with @embedStandard.Testing

The declarations of C

Only the bindings above use them.

moduleused by
Bindings.C.LibcryptoBindings.Libcrypto
Bindings.C.TlsBindings.Tls
Bindings.C.Pcre2Bindings.Pcre
Bindings.C.Sqlite3Bindings.Sqlite, Bindings.SqliteReplica
Bindings.C.SqlCipherBindings.SqlCipher
Bindings.C.LibpqBindings.Postgres
Bindings.C.MariadbBindings.MariaDB
Bindings.C.DuckdbBindings.DuckDB
Bindings.C.Argon2Bindings.Argon2
Bindings.C.Probenothing: the generator's own test, over libm
Bindings.C.ProbePPnothing: the generator's own test, over libm

Built into the compiler

Three modules are compiled into the compiler rather than read from the standard library. Hilde.Pervasive is the prelude every module sees; its spanPart checks the part it is asked for before it makes a span of it. Hilde.Memory holds addresses, pointers and raw memory, and only an unsafe module may import it (error H2028). Hilde.Array is the heap array: every one of its operations checks its index or its span and stops the program with a message when it is out of range, so a safe module may import it; Standard.Buffer and Standard.Box are built on it.