aoc2024/stdlib/src/buffer.c

15 lines
402 B
C
Raw Normal View History

2024-12-05 20:22:19 +00:00
#include <common.h>
#include <syscall.h>
void* buffer_init(usize size)
{
i32 fd = memfd_create("buffer", 0);
ftruncate(fd, size);
void* ptr = mmap(null, 2 * size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
mmap( ptr, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0);
mmap((c8*)ptr + size, size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0);
return ptr;
}