💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Vgmi › files › 38f69fc81b02b6344d5f2075b5e65… captured on 2024-02-05 at 09:59:29. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-12-28)
-=-=-=-=-=-=-
0 /*
1 * ISC License
2 * Copyright (c) 2023 RMF <rawmonk@firemail.cc>
3 */
4 #include <sys/mman.h>
5 #include <string.h>
6 #include "memory.h"
7 #include "error.h"
8
9 int readonly(const char *in, size_t length, char **out) {
10 void *ptr = mmap(NULL, length, PROT_READ|PROT_WRITE,
11 MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
12 if (!ptr) return ERROR_MEMORY_FAILURE;
13 memcpy(ptr, in, length);
14 if (mprotect(ptr, length, PROT_READ)) return ERROR_ERRNO;
15 *out = ptr;
16 return 0;
17 }
18
19 int free_readonly(void *ptr, size_t length) {
20 munmap(ptr, length);
21 return 0;
22 }
23