From e66dbc42d523ec6d1a4e1b4fec21fb211eb660bb Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sun, 10 May 2026 14:51:46 +0100 Subject: Abstract page allocation and locking in os.c Simplifies ac.c just a little bit. --- src/os.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/os.h') diff --git a/src/os.h b/src/os.h index 6466e45..9f8295f 100644 --- a/src/os.h +++ b/src/os.h @@ -227,6 +227,18 @@ void *os_dlhandle(const os_char *name); int os_dlfile(void *lib, os_char *buf, int sz); #endif +/* + * Allocates some memory from the operating system. Rounds the size up to the + * page size (4096). Returns an address on success, or null on failure. + */ +void *os_pagealloc(int sz, int prot); + +/* + * Frees a page range allocated using os_pagealloc(). Rounds the address and + * size to page boundaries (4096). + */ +void os_pagefree(void *addr, int sz); + /* * Changes memory protection for the address range given by addr and len, using * one of the Win32-style PAGE_* flags specified above. Returns true on success @@ -234,6 +246,13 @@ int os_dlfile(void *lib, os_char *buf, int sz); */ bool os_mprot(void *addr, int len, int mode); +/* + * Locks a page range in physical memory; prevents paging to disk. The address + * and size *must* be page-aligned, otherwise behaviour is undefined. + * Returns true on success, false on failure. + */ +bool os_mlock(void *addr, int sz); + /* * Fills buf with up to sz cryptographically random bytes. sz has an OS-specific * upper limit - a safe value across all major operating systems is 256. -- cgit v1.2.3-54-g00ecf