rt+x86_64 +linux

rt: low-level runtime support

The rt (runtime) module provides support code for the Hare compiler. It is not guaranteed to be portable between different Hare compilers.

Index

Types

type abort_handler;
type chunk;
type meta;

// Undocumented types:
type arch_jmp_buf;
type jmp_buf;
type memory_heap;
type slice;

Constants

def EMPTY_HEAP = memory_heap {
	cur_allocs = 0,
	bins = [null...],
	cur_chunk = (null: *chunk, CHUNKSZ),
};

Globals

// Undocumented globals:
let argc: size;
let argv: *[*]*u8;
let envp: *[*]nullable *u8;

Functions

fn fini() void;
fn free_(p: nullable *opaque) void;
fn getmeta(p: *opaque) *meta;
fn init() void;
fn malloc(n: size) nullable *opaque;
fn onabort(handler: *abort_handler) *abort_handler;
fn realloc(p: nullable *opaque, n: size) nullable *opaque;
fn setheap(new_heap: *memory_heap) *memory_heap;

// Undocumented functions:
fn _abort(path: *str, line: u64, col: u64, msg: str) never;
fn abort_fixed(path: *str, line: u64, col: u64, i: u64) void;
fn ensure(s: *slice, membsz: size) bool;
fn longjmp(buf: *jmp_buf, n: int) never;
fn memcpy(dest: *opaque, src: *opaque, n: size) void;
fn memmove(dest: *opaque, src: *opaque, n: size) void;
fn memset(dest: *opaque, val: u8, n: size) void;
fn setjmp(buf: *jmp_buf) int;
fn start_ha() never;
fn start_linux(iv: *[*]uintptr) never;
fn strcmp(_a: str, _b: str) bool;
fn unensure(s: *slice, membsz: size) void;

Types

type abort_handler[permalink] [source]

type abort_handler = fn(path: *str, line: u64, col: u64, msg: str) never;

Signature for abort handler function.

type chunk[permalink] [source]

type chunk = union {
	// TODO: track number of active allocations here
	padding: size,
	data: [*]u8,
};

A group of blocks that were allocated together.

type meta[permalink] [source]

type meta = struct {
	union {
		sz: size,
		next: uintptr,
	},
	user: [*]u8,
};

Metadata for a block.

type arch_jmp_buf[permalink] [source]

Show undocumented member
type arch_jmp_buf = [8]u64;

type jmp_buf[permalink] [source]

Show undocumented member
type jmp_buf = struct {
	__jb: arch_jmp_buf,
	__fl: size,
	__ss: [128 / size(size)]size,
};

type memory_heap[permalink] [source]

Show undocumented member
type memory_heap = struct {
	// Number of allocations currently in flight.
	cur_allocs: size,
	// Freelists for blocks up to 2048 bytes.
	bins: [9]nullable *meta,
	// The chunk to allocate from if there are no blocks available in the
	// right freelist.
	cur_chunk: (*chunk, size),
};

type slice[permalink] [source]

Show undocumented member
type slice = struct {
	data: nullable *opaque,
	length: size,
	capacity: size,
};

Constants

def EMPTY_HEAP[permalink] [source]

def EMPTY_HEAP = memory_heap {
	cur_allocs = 0,
	bins = [null...],
	cur_chunk = (null: *chunk, CHUNKSZ),
};

An empty memory heap, used to initialize a memory_heap for use with setheap.

Globals

let argc[permalink] [source]

Show undocumented member
let argc: size;

let argv[permalink] [source]

Show undocumented member
let argv: *[*]*u8;

let envp[permalink] [source]

Show undocumented member
let envp: *[*]nullable *u8;

Functions

fn fini[permalink] [source]

fn fini() void;

Run all global finalization functions.

fn free_[permalink] [source]

fn free_(p: nullable *opaque) void;

Frees an allocation returned by malloc. Freeing any other pointer, or freeing a pointer that's already been freed, will cause an abort.

fn getmeta[permalink] [source]

fn getmeta(p: *opaque) *meta;

Gets the metadata for a given allocation. The provided pointer must have been returned by malloc or realloc and must not have been freed.

fn init[permalink] [source]

fn init() void;

Run all global initialization functions.

fn malloc[permalink] [source]

fn malloc(n: size) nullable *opaque;

Allocates n bytes of memory and returns a pointer to them, or null if there is insufficient memory.

fn onabort[permalink] [source]

fn onabort(handler: *abort_handler) *abort_handler;

Sets a new global runtime abort handler, returning the previous handler.

fn realloc[permalink] [source]

fn realloc(p: nullable *opaque, n: size) nullable *opaque;

Changes the allocation size of a pointer to n bytes. If n is smaller than the prior allocation, it is truncated; otherwise the allocation is expanded and the values of the new bytes are undefined. May return a different pointer than the one given if there is insufficient space to expand the pointer in-place. Returns null if there is insufficient memory to support the request.

fn setheap[permalink] [source]

fn setheap(new_heap: *memory_heap) *memory_heap;

Switches the internal runtime allocator to a new memory heap. The caller should provision a memory_heap initialized to EMPTY_HEAP somehow (statically, or in a second memory_heap, or even on the stack if you're brave enough) and pass it to this function to enable it. Returns a pointer to the heap which was previously in use, should you wish to restore it later.

The caller is responsible for ensuring that any use of free() or delete() makes use of an object which was allocated (via alloc(), insert(), or append()) from the same heap.

This function is designed for debugging use, and exists in particular to satisfy the needs of debug::.

fn _abort[permalink] [source]

Show undocumented member
fn _abort(path: *str, line: u64, col: u64, msg: str) never;

fn abort_fixed[permalink] [source]

Show undocumented member
fn abort_fixed(path: *str, line: u64, col: u64, i: u64) void;

fn ensure[permalink] [source]

Show undocumented member
fn ensure(s: *slice, membsz: size) bool;

fn longjmp[permalink] [source]

Show undocumented member
fn longjmp(buf: *jmp_buf, n: int) never;

fn memcpy[permalink] [source]

Show undocumented member
fn memcpy(dest: *opaque, src: *opaque, n: size) void;

fn memmove[permalink] [source]

Show undocumented member
fn memmove(dest: *opaque, src: *opaque, n: size) void;

fn memset[permalink] [source]

Show undocumented member
fn memset(dest: *opaque, val: u8, n: size) void;

fn setjmp[permalink] [source]

Show undocumented member
fn setjmp(buf: *jmp_buf) int;

fn start_ha[permalink] [source]

Show undocumented member
fn start_ha() never;

fn start_linux[permalink] [source]

Show undocumented member
fn start_linux(iv: *[*]uintptr) never;

fn strcmp[permalink] [source]

Show undocumented member
fn strcmp(_a: str, _b: str) bool;

fn unensure[permalink] [source]

Show undocumented member
fn unensure(s: *slice, membsz: size) void;