summaryrefslogtreecommitdiff
path: root/src/os.h
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2026-05-10 14:51:46 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2026-10-10 04:23:05 +0100
commite66dbc42d523ec6d1a4e1b4fec21fb211eb660bb (patch)
tree4e6a4b88ff960b552fd77a43ba8902fe1295188b /src/os.h
parentc219ee378c374ceaf576ac477ccbe34a73e65d94 (diff)
downloadsst-e66dbc42d523ec6d1a4e1b4fec21fb211eb660bb.tar.gz
sst-e66dbc42d523ec6d1a4e1b4fec21fb211eb660bb.zip
Abstract page allocation and locking in os.c
Simplifies ac.c just a little bit.
Diffstat (limited to 'src/os.h')
-rw-r--r--src/os.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/os.h b/src/os.h
index 6466e45..9f8295f 100644
--- a/src/os.h
+++ b/src/os.h
@@ -228,6 +228,18 @@ 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
* and false on failure.
@@ -235,6 +247,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.
*/