summaryrefslogtreecommitdiff
path: root/src/ac.c
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/ac.c
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/ac.c')
-rw-r--r--src/ac.c28
1 files changed, 5 insertions, 23 deletions
diff --git a/src/ac.c b/src/ac.c
index fc1d318..9d1430e 100644
--- a/src/ac.c
+++ b/src/ac.c
@@ -389,31 +389,18 @@ INIT {
struct hook_featsetup_ret_Key_Event h = hook_featsetup_Key_Event(Key_Event);
if_cold (h.err) return h.err;
-#ifdef _WIN32
- keybox = VirtualAlloc(0, 4096, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
+ keybox = os_pagealloc(4096, PAGE_READWRITE);
if_cold (!keybox) {
errmsg_errorsys("couldn't allocate memory for session state");
return FEAT_FAIL;
}
- if_cold (!VirtualLock(keybox, 4096)) {
+ if_cold (!os_mlock(keybox, 4096)) {
errmsg_errorsys("couldn't secure session state");
goto e;
}
+#ifdef _WIN32
if_cold (!win32_init()) goto e;
#else
- keybox = mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
- if_cold (keybox == MAP_FAILED) {
- errmsg_errorstd("couldn't allocate memory for session state");
- return FEAT_FAIL;
- }
- // linux-specific madvise stuff (there are some equivalents in OpenBSD and
- // FreeBSD, if anyone's wondering, but we don't need to worry about those)
- if_cold (madvise(keybox, 4096, MADV_DONTFORK) == -1 ||
- madvise(keybox, 4096, MADV_DONTDUMP) == - 1 ||
- mlock(keybox, 4096) == -1) {
- errmsg_errorstd("couldn't secure session state");
- goto e;
- }
// TODO(linux): call other init things
#endif
@@ -428,22 +415,17 @@ INIT {
hook_commit_Key_Event(h.hookpos, hookdest_Key_Event);
return FEAT_OK;
-#ifdef _WIN32
-e: VirtualFree(keybox, 4096, MEM_RELEASE);
-#else
-e: munmap(keybox, 4096);
-#endif
+e: os_pagefree(keybox, 4096);
return FEAT_FAIL;
}
END {
// TODO(opt): *maybe* do the skip-on-quit stuff here. feels a bit scary...
ac_disable();
+ os_pagefree(keybox, 4096);
#if defined(_WIN32)
- VirtualFree(keybox, 4096, MEM_RELEASE);
win32_end();
#else
- munmap(keybox, 4096);
// TODO(linux): call other cleanup things
#endif
unhook_Key_Event();