set up 1mb of static kernel-allocable memory

This commit is contained in:
Quinten Kock 2020-12-23 04:09:38 +01:00
parent a740f46ec3
commit 29bc4daf9e
1 changed files with 3 additions and 17 deletions

View File

@ -1,19 +1,5 @@
const std = @import("std");
var GlobAlloc: ?std.heap.FixedBufferAllocator = null;
pub export fn kalloc_init(start: usize, len: usize) void {
// const aligned = std.mem.alignForward(start, 8);
const ptr = @intToPtr([*]u8, start);
const buf = ptr[0..len];
GlobAlloc = std.heap.FixedBufferAllocator.init(buf);
}
// export fn kalloc(bytes: usize, a: usize) void {
// var a = GlobAlloc.?.allocator.allocAdvanced(u8, a, bytes, std.mem.Allocator.Exact.at_least);
// return a catch unreachable;
// }
pub fn kallocNop() void {
std.log.err("calling kallocNop", .{});
}
var buf: [1024*1024]u8 = undefined;
pub var KAlloc = std.heap.FixedBufferAllocator.init(&buf);
// pub var KAlloc = std.heap.GeneralPurposeAllocator(.{.thread_safe=false}){.backing_allocator = &GlobAlloc.allocator};