This commit is contained in:
2024-12-05 21:22:19 +01:00
parent cc23753573
commit b6c66136f7
14 changed files with 452 additions and 0 deletions

18
stdlib/include/arena.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include <common.h>
typedef struct arena {
void* ptr;
usize available;
usize capacity;
} arena;
// The capacity has to be page-aligned
arena arena_init(usize capacity);
// The available size will be rounded up to a page boundary
// Will not grow beyond its capacity
void arena_ensure(arena* arena, usize available);
#define ARENA_ENSURE(T, arena, available) arena_ensure(arena, (available) * sizeof(T))

6
stdlib/include/buffer.h Normal file
View File

@@ -0,0 +1,6 @@
#pragma once
#include <common.h>
// The size has to be page-aligned
void* buffer_init(usize size);

27
stdlib/include/common.h Normal file
View File

@@ -0,0 +1,27 @@
#pragma once
typedef char c8;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long u64;
typedef signed char i8;
typedef signed short i16;
typedef signed int i32;
typedef signed long i64;
typedef unsigned long int usize;
typedef signed long isize;
#define asm __asm__
#define null ((void*)0)
#define bool _Bool
#define false 0
#define true 1
#define COUNT(array) (sizeof(array) / sizeof(array[0]))
#define PAGE_SIZE 4096UL

24
stdlib/include/syscall.h Normal file
View File

@@ -0,0 +1,24 @@
#pragma once
#include <common.h>
#define stdin 0
#define stdout 1
#define stderr 2
#define PROT_NONE 0x0
#define PROT_READ 0x1
#define PROT_WRITE 0x2
#define PROT_EXEC 0x4
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_FIXED 0x10
#define MAP_ANONYMOUS 0x20
isize read(i32 fd, void* buf, usize size);
isize write(i32 fd, const void* buf, usize size);
void* mmap(void* addr, usize length, i32 prot, i32 flags, i32 fd, isize offset);
i32 mprotect(void* addr, usize len, i32 prot);
i32 ftruncate(i32 fd, isize length);
i32 memfd_create(const char* name, u32 flags);