tiny.stabilizer.Runtime
Defined in tiny.stabilizer.
API (31)
Actions
Public operations.
adjustAddressadjustBacktracecallocconstructorCountdeinitenterFunctionfreefreeIfOwnedinitmallocnextStackPadownsPointerrandomizedAllocatorreallocregisterConstructorregisterFunctionRangeregisterStackPadregisteredStackPadCountrerandomizererandomizeAtrunConstructorsrunProgramtrapFunction
Fields and members
Public fields and members.
Source
Source: lib/stabilizer/src/runtime.zig:14
zig
pub const Runtime = struct { allocator: Allocator, config: config.Config, heap: ShuffleAllocator, stack: stack.StackPads, code: CodeRandomizer, rng: Marsaglia, stack_pad_slots: std.ArrayListUnmanaged(*u8) = .empty, constructors: std.ArrayListUnmanaged(ConstructorFn) = .empty, pub fn init(allocator: Allocator, runtime_config: config.Config) !Runtime { var rng = Marsaglia.init(runtime_config.seed); var stack_pads = try stack.StackPads.init(allocator, runtime_config.stack, &rng); errdefer stack_pads.deinit(); return .{ .allocator = allocator, .config = runtime_config, .heap = ShuffleAllocator.init(allocator, runtime_config.heap, runtime_config.seed ^ 0x4845_4150), .stack = stack_pads, .code = CodeRandomizer.init(allocator, runtime_config.code, runtime_config.seed ^ 0x434f_4445), .rng = rng, }; } pub fn deinit(self: *Runtime) void { self.constructors.deinit(self.allocator); self.stack_pad_slots.deinit(self.allocator); self.code.deinit(); self.stack.deinit(); self.heap.deinit(); self.* = undefined; } pub fn randomizedAllocator(self: *Runtime) Allocator { return self.heap.allocator(); } pub fn malloc(self: *Runtime, len: usize) ![*]u8 { return self.heap.malloc(len); } pub fn calloc(self: *Runtime, count: usize, len: usize) ![*]u8 { return self.heap.calloc(count, len); } pub fn realloc(self: *Runtime, ptr: ?[*]u8, new_len: usize) !?[*]u8 { return self.heap.realloc(ptr, new_len); } pub fn free(self: *Runtime, ptr: ?[*]u8) void { self.heap.freePointer(ptr); } pub fn freeIfOwned(self: *Runtime, ptr: ?[*]u8) bool { return self.heap.freePointerIfOwned(ptr); } pub fn ownsPointer(self: *const Runtime, ptr: ?[*]u8) bool { return self.heap.ownsPointer(ptr); } pub fn registerStackPad(self: *Runtime, slot: *u8) !void { for (self.stack_pad_slots.items) |existing| { if (existing == slot) return; } try self.stack_pad_slots.append(self.allocator, slot); } pub fn registeredStackPadCount(self: *const Runtime) usize { return self.stack_pad_slots.items.len; } pub fn registerConstructor(self: *Runtime, constructor: ConstructorFn) !void { try self.constructors.append(self.allocator, constructor); } pub fn constructorCount(self: *const Runtime) usize { return self.constructors.items.len; } pub fn runConstructors(self: *Runtime) void { for (self.constructors.items) |constructor| constructor(); } pub fn registerFunctionRange(self: *Runtime, options: code_mod.FunctionRangeOptions) !code_mod.FunctionId { return self.code.registerFunctionRange(options); } pub fn enterFunction(self: *Runtime, id: code_mod.FunctionId, roots: []const usize) !?usize { const location = try self.code.enterFunction(id, roots); return if (location) |active| active.base else null; } pub fn trapFunction(self: *Runtime, id: code_mod.FunctionId, roots: []const usize) !usize { const location = try self.code.trap(id, roots); return location.base; } pub fn adjustAddress(self: *const Runtime, address: usize) usize { return self.code.adjustAddress(address); } pub fn adjustBacktrace(self: *const Runtime, adjusted: []usize, real: []const usize) []usize { const count = @min(adjusted.len, real.len); for (real[0..count], adjusted[0..count]) |address, *out| { out.* = self.adjustAddress(address); } return adjusted[0..count]; } pub fn runProgram(self: *Runtime, main: anytype, args: anytype) @TypeOf(@call(.auto, main, args)) { self.code.trapRegisteredFunctions(); self.runConstructors(); return @call(.auto, main, args); } pub fn nextStackPad(self: *Runtime) stack.StackPad { return self.stack.next(&self.rng); } pub fn rerandomize(self: *Runtime) void { _ = self.rerandomizeAt(0); } pub fn rerandomizeAt(self: *Runtime, instruction_pointer: usize) usize { if (self.config.code.enabled) { if (self.code.functionCount() == 0) self.rerandomizeStackPads(); return self.code.beginRerandomizationAt(instruction_pointer); } else { self.rerandomizeStackPads(); return instruction_pointer; } } fn rerandomizeStackPads(self: *Runtime) void { if (!self.config.stack.enabled) return; self.stack.refill(&self.rng); for (self.stack_pad_slots.items) |slot| { slot.* = self.rng.nextByte(); } }};Source: lib/stabilizer/src/root.zig:72
zig
pub const Runtime = runtime_mod.Runtime;Complete caller list for Runtime.deinit
7 direct callers.
lib.stabilizer.src.runtime.test_runtime_adjusts_relocated_addresses_back_to_original_code[function] — test source atlib/stabilizer/src/runtime.zig:253in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_arms_code_and_runs_constructors_before_program_main[function] — test source atlib/stabilizer/src/runtime.zig:343in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_enterFunction_relocates_traps_and_preserves_rooted_code_locations[function] — test source atlib/stabilizer/src/runtime.zig:226in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_rerandomizeAt_preserves_instruction_pointer_in_stack-only_mode[function] — test source atlib/stabilizer/src/runtime.zig:209in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_rerandomize_forwards_interrupts_at_live_function_entries[function] — test source atlib/stabilizer/src/runtime.zig:187in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_rerandomizes_registered_stack_pad_slots[function] — test source atlib/stabilizer/src/runtime.zig:157in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_runs_registered_constructors_in_insertion_order[function] — test source atlib/stabilizer/src/runtime.zig:326in nearest public ownerlib.stabilizer.src.runtime
Complete caller list for Runtime.init
7 direct callers.
lib.stabilizer.src.runtime.test_runtime_adjusts_relocated_addresses_back_to_original_code[function] — test source atlib/stabilizer/src/runtime.zig:253in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_arms_code_and_runs_constructors_before_program_main[function] — test source atlib/stabilizer/src/runtime.zig:343in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_enterFunction_relocates_traps_and_preserves_rooted_code_locations[function] — test source atlib/stabilizer/src/runtime.zig:226in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_rerandomizeAt_preserves_instruction_pointer_in_stack-only_mode[function] — test source atlib/stabilizer/src/runtime.zig:209in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_rerandomize_forwards_interrupts_at_live_function_entries[function] — test source atlib/stabilizer/src/runtime.zig:187in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_rerandomizes_registered_stack_pad_slots[function] — test source atlib/stabilizer/src/runtime.zig:157in nearest public ownerlib.stabilizer.src.runtimelib.stabilizer.src.runtime.test_runtime_runs_registered_constructors_in_insertion_order[function] — test source atlib/stabilizer/src/runtime.zig:326in nearest public ownerlib.stabilizer.src.runtime
Audit
| Definitions | 24 |
|---|---|
| Public names | 24 |
| Members | 8 |
| Version | 26.7.0 |
| Revision | daab053ee433 |