base: add memory placeholders and generic page fault handler

* Add windows and Linux demand-mapping backends
* Add exclusive file creation, sizing, flushing and replacement APIs
This commit is contained in:
Nikita Smith authored and Ryan Fleury committed 2026-09-21 09:08:07 -07:00
1 parent 4e12148910
commit 0ac6b35a98
18 files changed
+690 -101

No files matched your search

+1
View File
@@ -695,6 +695,7 @@ enum
AccessFlag_ShareRead = (1<<4),
AccessFlag_ShareWrite = (1<<5),
AccessFlag_Inherited = (1<<6),
AccessFlag_CreateNew = (1<<7), // fail if file already exists; never truncates
};
////////////////////////////////
+4
View File
@@ -89,9 +89,12 @@ internal B32 file_set_times(File file, DateTime time);
internal FileProperties properties_from_file(File file);
internal FileID id_from_file(File file);
internal B32 file_reserve_size(File file, U64 size);
internal B32 file_set_size(File file, U64 size);
internal B32 file_flush(File file);
internal B32 delete_file_at_path(String8 path);
internal B32 copy_file_path(String8 dst, String8 src);
internal B32 move_file_path(String8 dst, String8 src);
internal B32 replace_file_path(String8 dst, String8 src);
internal String8 full_path_from_path(Arena *arena, String8 path);
internal B32 file_path_exists(String8 path);
internal B32 folder_path_exists(String8 path);
@@ -101,6 +104,7 @@ internal FileProperties properties_from_file_path(String8 path);
internal FileMap file_map_open(AccessFlags flags, File file);
internal void file_map_close(FileMap map);
internal void * file_map_view_open(FileMap map, AccessFlags flags, Rng1U64 range);
internal void * file_map_view_replace_placeholder(FileMap map, void *ptr, Rng1U64 range);
internal void file_map_view_close(FileMap map, void *ptr, Rng1U64 range);
//- rjf: directory iteration
+3
View File
@@ -30,6 +30,9 @@
#include "base_test.c"
#include "base_entry_point.c"
// TODO: move x64 to base layer
#include "x64/x64.c"
#if OS_WINDOWS
# include "win32/base/win32_base.c"
#elif OS_LINUX
+1
View File
@@ -32,6 +32,7 @@
#include "base_test.h"
#include "base_entry_point.h"
#include "x64/x64.h"
#if OS_WINDOWS
# include "win32/base/win32_base.h"
#elif OS_LINUX
+14
View File
@@ -13,6 +13,20 @@ internal B32 commit_memory(void *ptr, U64 size);
internal void decommit_memory(void *ptr, U64 size);
internal void release_memory(void *ptr, U64 size);
// memory placeholders
internal B32 memory_placeholders_supported(void);
internal void *reserve_memory_placeholders(U64 size, U64 block_size);
internal void release_memory_placeholders(void *ptr, U64 size, U64 block_size);
internal B32 unmap_memory_preserve_placeholder(void *ptr, U64 size);
internal B32 split_memory_placeholder(void *ptr, U64 size, U64 first_size);
internal B32 coalesce_memory_placeholders(void *ptr, U64 size);
union Rng1U64;
internal void prefetch_memory_ranges(U64 count, union Rng1U64 *ranges);
// generic memory page fault handler (calls may run concurrently)
typedef B32 MemoryReadFaultFunction(void *address, void *user_data);
internal B32 memory_read_fault_handler_set(MemoryReadFaultFunction *func, void *user_data);
//- rjf: large pages
internal void *reserve_memory_large(U64 size);
internal B32 commit_memory_large(void *ptr, U64 size);
+1
View File
@@ -18,5 +18,6 @@ internal SharedMemory shared_memory_open(String8 name);
internal void shared_memory_close(SharedMemory handle);
internal void * shared_memory_view_open(SharedMemory handle, Rng1U64 range);
internal void shared_memory_view_close(SharedMemory handle, void *ptr, Rng1U64 range);
internal void * shared_memory_view_replace_placeholder(SharedMemory handle, void *ptr, Rng1U64 range, AccessFlags flags);
#endif // BASE_SHARED_MEMORY_H
+1
View File
@@ -11,6 +11,7 @@ struct SystemInfo
U64 page_size;
U64 large_page_size;
U64 allocation_granularity;
U64 physical_memory_size;
String8 machine_name;
};