initial pass done for os

This commit is contained in:
ed
2025-02-08 00:52:54 -05:00
parent ee6a43e136
commit e8809a243f
12 changed files with 1886 additions and 1788 deletions
+14 -1
View File
@@ -52,7 +52,20 @@
"os_win32.h": "c", "os_win32.h": "c",
"windows.h": "c", "windows.h": "c",
"base.h": "c", "base.h": "c",
"os_linux.h": "c" "os_linux.h": "c",
"array": "c",
"vector": "c",
"dbghelp.h": "c",
"namespace.h": "c",
"space.h": "c",
"logger.h": "c",
"entry_point.h": "c",
"markup.h": "c",
"generic_macros.h": "c",
"profiling.h": "c",
"ring.h": "c",
"debug.h": "c",
"arena.h": "c"
}, },
"workbench.colorCustomizations": { "workbench.colorCustomizations": {
"activityBar.activeBackground": "#713fb8", "activityBar.activeBackground": "#713fb8",
+47
View File
@@ -13,6 +13,53 @@
# define BUILD_SUPPLEMENTARY_UNIT 0 # define BUILD_SUPPLEMENTARY_UNIT 0
#endif #endif
#if !defined(BUILD_ENTRY_DEFINING_UNIT)
# define BUILD_ENTRY_DEFINING_UNIT 0
#endif
#if !defined(BUILD_CONSOLE_INTERFACE)
# define BUILD_CONSOLE_INTERFACE 0
#endif
#if !defined(BUILD_VERSION_MAJOR)
# define BUILD_VERSION_MAJOR 0
#endif
#if !defined(BUILD_VERSION_MINOR)
# define BUILD_VERSION_MINOR 1
#endif
#if !defined(BUILD_VERSION_PATCH)
# define BUILD_VERSION_PATCH 0
#endif
#define BUILD_VERSION_STRING_LITERAL stringify(BUILD_VERSION_MAJOR) "." stringify(BUILD_VERSION_MINOR) "." stringify(BUILD_VERSION_PATCH)
#if BUILD_DEBUG
# define BUILD_MODE_STRING_LITERAL_APPEND " [Debug]"
#else
# define BUILD_MODE_STRING_LITERAL_APPEND ""
#endif
#if defined(BUILD_GIT_HASH)
# define BUILD_GIT_HASH_STRING_LITERAL_APPEND " [" BUILD_GIT_HASH "]"
#else
# define BUILD_GIT_HASH_STRING_LITERAL_APPEND ""
#endif
#if !defined(BUILD_TITLE)
# define BUILD_TITLE "Untitled"
#endif
#if !defined(BUILD_RELEASE_PHASE_STRING_LITERAL)
# define BUILD_RELEASE_PHASE_STRING_LITERAL "ALPHA"
#endif
#if !defined(BUILD_ISSUES_LINK_STRING_LITERAL)
# define BUILD_ISSUES_LINK_STRING_LITERAL "ADD_BUILD_ISSUES_LINK"
#endif
#define BUILD_TITLE_STRING_LITERAL BUILD_TITLE " (" BUILD_VERSION_STRING_LITERAL " " BUILD_RELEASE_PHASE_STRING_LITERAL ") - " __DATE__ "" BUILD_GIT_HASH_STRING_LITERAL_APPEND BUILD_MODE_STRING_LITERAL_APPEND
#pragma region Compiler Vendor #pragma region Compiler Vendor
#if defined( _MSC_VER ) #if defined( _MSC_VER )
+1 -1
View File
@@ -28,7 +28,7 @@
{ \ { \
if ( ! ( cond ) ) \ if ( ! ( cond ) ) \
{ \ { \
assert_handler( #cond, __FILE__, __func__, scast( s64, __LINE__ ), msg, ##__VA_ARGS__ ); \ assert_handler( #cond, __FILE__, __func__, scast( S64, __LINE__ ), msg, ##__VA_ARGS__ ); \
GEN_DEBUG_TRAP(); \ GEN_DEBUG_TRAP(); \
} \ } \
} while ( 0 ) } while ( 0 )
-1
View File
@@ -10,7 +10,6 @@
# include <intrin.h> # include <intrin.h>
# include <tmmintrin.h> # include <tmmintrin.h>
# include <wmmintrin.h> # include <wmmintrin.h>
#endif #endif
#if LANG_C #if LANG_C
+12
View File
@@ -287,6 +287,18 @@ str8_is_integer(String8 string, U32 radix){
return(result); return(result);
} }
U64
u64_from_str8(String8 string, U32 radix) {
U64 x = 0;
if (1 < radix && radix <= 16) {
for (U64 i = 0; i < string.size; i += 1) {
x *= radix;
x += integer_symbol_reverse[string.str[i]&0x7F];
}
}
return(x);
}
B32 B32
try_u64_from_str8_c_rules(String8 string, U64 *x) try_u64_from_str8_c_rules(String8 string, U64 *x)
{ {
-12
View File
@@ -349,18 +349,6 @@ MD_API String8 str8_from_allocator_size(AllocatorInfo ainfo, U64 z);
MD_API String8 str8_from_allocator_u64 (AllocatorInfo ainfo, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator); MD_API String8 str8_from_allocator_u64 (AllocatorInfo ainfo, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
MD_API String8 str8_from_alloctor_s64 (AllocatorInfo ainfo, S64 u64, U32 radix, U8 min_digits, U8 digit_group_separator); MD_API String8 str8_from_alloctor_s64 (AllocatorInfo ainfo, S64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
inline U64
u64_from_str8(String8 string, U32 radix) {
U64 x = 0;
if (1 < radix && radix <= 16) {
for (U64 i = 0; i < string.size; i += 1) {
x *= radix;
x += integer_symbol_reverse[string.str[i]&0x7F];
}
}
return(x);
}
inline S64 inline S64
s64_from_str8(String8 string, U32 radix) { s64_from_str8(String8 string, U32 radix) {
S64 sign = sign_from_str8(string, &string); S64 sign = sign_from_str8(string, &string);
+3
View File
@@ -0,0 +1,3 @@
# Metagen
+179 -175
View File
@@ -45,7 +45,7 @@ os_lnx_entity_release(OS_LNX_Entity *entity) {
//////////////////////////////// ////////////////////////////////
//~ rjf: Thread Entry Point //~ rjf: Thread Entry Point
internal void * void*
os_lnx_thread_entry_point(void *ptr) os_lnx_thread_entry_point(void *ptr)
{ {
OS_LNX_Entity* entity = (OS_LNX_Entity *)ptr; OS_LNX_Entity* entity = (OS_LNX_Entity *)ptr;
@@ -87,6 +87,11 @@ os_set_thread_name(String8 name)
scratch_end(scratch); scratch_end(scratch);
} }
////////////////////////////////
//~ rjf: @os_hooks Aborting (Implemented Per-OS)
void os_abort(S32 exit_code) { exit(exit_code); }
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks File System (Implemented Per-OS) //~ rjf: @os_hooks File System (Implemented Per-OS)
@@ -115,8 +120,7 @@ os_file_open(OS_AccessFlags flags, String8 path)
} }
void void
os_file_close(OS_Handle file) os_file_close(OS_Handle file) {
{
if (os_handle_match(file, os_handle_zero())) { return; } if (os_handle_match(file, os_handle_zero())) { return; }
int fd = (int)file.u64[0]; int fd = (int)file.u64[0];
close(fd); close(fd);
@@ -189,22 +193,22 @@ os_file_set_times(OS_Handle file, DateTime date_time)
return good; return good;
} }
internal FileProperties FileProperties
os_properties_from_file(OS_Handle file) os_properties_from_file(OS_Handle file)
{ {
if(os_handle_match(file, os_handle_zero())) { return (FileProperties){0}; } if(os_handle_match(file, os_handle_zero())) { return (FileProperties){0}; }
int fd = (int)file.u64[0]; int fd = (int)file.u64[0];
struct stat fd_stat = {0}; struct stat fd_stat = {0};
int fstat_result = fstat(fd, &fd_stat); int fstat_result = fstat(fd, &fd_stat);
FileProperties props = {0}; FileProperties props = {0};
if(fstat_result != -1) if (fstat_result != -1) {
{
props = os_lnx_file_properties_from_stat(&fd_stat); props = os_lnx_file_properties_from_stat(&fd_stat);
} }
return props; return props;
} }
internal OS_FileID OS_FileID
os_id_from_file(OS_Handle file) os_id_from_file(OS_Handle file)
{ {
if (os_handle_match(file, os_handle_zero())) { return (OS_FileID){0}; } if (os_handle_match(file, os_handle_zero())) { return (OS_FileID){0}; }
@@ -212,29 +216,27 @@ os_id_from_file(OS_Handle file)
struct stat fd_stat = {0}; struct stat fd_stat = {0};
int fstat_result = fstat(fd, &fd_stat); int fstat_result = fstat(fd, &fd_stat);
OS_FileID id = {0}; OS_FileID id = {0};
if(fstat_result != -1) if(fstat_result != -1) {
{
id.v[0] = fd_stat.st_dev; id.v[0] = fd_stat.st_dev;
id.v[1] = fd_stat.st_ino; id.v[1] = fd_stat.st_ino;
} }
return id; return id;
} }
internal B32 B32
os_delete_file_at_path(String8 path) os_delete_file_at_path(String8 path)
{ {
Temp scratch = scratch_begin(0, 0); TempArena scratch = scratch_begin(0, 0);
B32 result = 0; B32 result = 0;
String8 path_copy = push_str8_copy(scratch.arena, path); String8 path_copy = push_str8_copy(scratch.arena, path);
if(remove((char*)path_copy.str) != -1) if (remove((char*)path_copy.str) != -1) {
{
result = 1; result = 1;
} }
scratch_end(scratch); scratch_end(scratch);
return result; return result;
} }
internal B32 B32
os_copy_file_path(String8 dst, String8 src) os_copy_file_path(String8 dst, String8 src)
{ {
B32 result = 0; B32 result = 0;
@@ -244,12 +246,14 @@ os_copy_file_path(String8 dst, String8 src)
!os_handle_match(dst_h, os_handle_zero()) ) !os_handle_match(dst_h, os_handle_zero()) )
{ {
FileProperties src_props = os_properties_from_file(src_h); FileProperties src_props = os_properties_from_file(src_h);
U64 size = src_props.size; U64 size = src_props.size;
U64 total_bytes_copied = 0; U64 total_bytes_copied = 0;
U64 bytes_left_to_copy = size; U64 bytes_left_to_copy = size;
for (;bytes_left_to_copy > 0;) for (;bytes_left_to_copy > 0;)
{ {
Temp scratch = scratch_begin(0, 0); TempArena scratch = scratch_begin(0, 0);
U64 buffer_size = Min(bytes_left_to_copy, MB(8)); U64 buffer_size = Min(bytes_left_to_copy, MB(8));
U8 *buffer = push_array_no_zero(scratch.arena, U8, buffer_size); U8 *buffer = push_array_no_zero(scratch.arena, U8, buffer_size);
U64 bytes_read = os_file_read (src_h, r1u64(total_bytes_copied, total_bytes_copied+buffer_size), buffer); U64 bytes_read = os_file_read (src_h, r1u64(total_bytes_copied, total_bytes_copied+buffer_size), buffer);
@@ -257,9 +261,9 @@ os_copy_file_path(String8 dst, String8 src)
U64 bytes_copied = Min(bytes_read, bytes_written); U64 bytes_copied = Min(bytes_read, bytes_written);
bytes_left_to_copy -= bytes_copied; bytes_left_to_copy -= bytes_copied;
total_bytes_copied += bytes_copied; total_bytes_copied += bytes_copied;
scratch_end(scratch); scratch_end(scratch);
if(bytes_copied == 0) if(bytes_copied == 0) {
{
break; break;
} }
} }
@@ -269,27 +273,40 @@ os_copy_file_path(String8 dst, String8 src)
return result; return result;
} }
internal String8 String8
os_full_path_from_path(Arena* arena, String8 path) os_full_path_from_path(Arena* arena, String8 path)
{ {
Temp scratch = scratch_begin(&arena, 1);
String8 path_copy = push_str8_copy(scratch.arena, path);
char buffer[PATH_MAX] = {0}; char buffer[PATH_MAX] = {0};
TempArena scratch = scratch_begin(&arena, 1); {
String8 path_copy = push_str8_copy(scratch.arena, path);
realpath((char *)path_copy.str, buffer); realpath((char *)path_copy.str, buffer);
String8 result = push_str8_copy(arena, str8_cstring(buffer)); }
scratch_end(scratch); scratch_end(scratch);
String8 result = push_str8_copy(arena, str8_cstring(buffer));
return result; return result;
} }
internal B32 String8
os_full_path_from_path_alloc(AllocatorInfo ainfo, String8 path)
{
char buffer[PATH_MAX] = {0};
TempArena scratch = scratch_begin(0, 0); {
String8 path_copy = push_str8_copy(scratch.arena, path);
realpath((char *)path_copy.str, buffer);
}
scratch_end(scratch);
String8 result = str8_copy(ainfo, str8_cstring(buffer));
return result;
}
B32
os_file_path_exists(String8 path) os_file_path_exists(String8 path)
{ {
Temp scratch = scratch_begin(0, 0); B32 result = 0;
TempArena scratch = scratch_begin(0, 0);
String8 path_copy = push_str8_copy(scratch.arena, path); String8 path_copy = push_str8_copy(scratch.arena, path);
int access_result = access((char *)path_copy.str, F_OK); int access_result = access((char *)path_copy.str, F_OK);
B32 result = 0; if (access_result == 0) {
if(access_result == 0)
{
result = 1; result = 1;
} }
scratch_end(scratch); scratch_end(scratch);
@@ -299,13 +316,12 @@ os_file_path_exists(String8 path)
internal FileProperties internal FileProperties
os_properties_from_file_path(String8 path) os_properties_from_file_path(String8 path)
{ {
Temp scratch = scratch_begin(0, 0); FileProperties props = {0};
TempArena scratch = scratch_begin(0, 0);
String8 path_copy = push_str8_copy(scratch.arena, path); String8 path_copy = push_str8_copy(scratch.arena, path);
struct stat f_stat = {0}; struct stat f_stat = {0};
int stat_result = stat((char *)path_copy.str, &f_stat); int stat_result = stat((char *)path_copy.str, &f_stat);
FileProperties props = {0}; if (stat_result != -1) {
if(stat_result != -1)
{
props = os_lnx_file_properties_from_stat(&f_stat); props = os_lnx_file_properties_from_stat(&f_stat);
} }
scratch_end(scratch); scratch_end(scratch);
@@ -314,46 +330,45 @@ os_properties_from_file_path(String8 path)
//- rjf: file maps //- rjf: file maps
internal OS_Handle OS_Handle
os_file_map_open(OS_AccessFlags flags, OS_Handle file) os_file_map_open(OS_AccessFlags flags, OS_Handle file) {
{
OS_Handle map = file; OS_Handle map = file;
return map; return map;
} }
internal void void
os_file_map_close(OS_Handle map) os_file_map_close(OS_Handle map) {
{
// NOTE(rjf): nothing to do; `map` handles are the same as `file` handles in // NOTE(rjf): nothing to do; `map` handles are the same as `file` handles in
// the linux implementation (on Windows they require separate handles) // the linux implementation (on Windows they require separate handles)
} }
internal void * void*
os_file_map_view_open(OS_Handle map, OS_AccessFlags flags, Rng1U64 range) os_file_map_view_open(OS_Handle map, OS_AccessFlags flags, Rng1U64 range)
{ {
if (os_handle_match(map, os_handle_zero())) { return 0; } if (os_handle_match(map, os_handle_zero())) { return 0; }
int fd = (int)map.u64[0];
int prot_flags = 0; int prot_flags = 0;
if (flags & OS_AccessFlag_Write) { prot_flags |= PROT_WRITE; } if (flags & OS_AccessFlag_Write) { prot_flags |= PROT_WRITE; }
if (flags & OS_AccessFlag_Read) { prot_flags |= PROT_READ; } if (flags & OS_AccessFlag_Read) { prot_flags |= PROT_READ; }
int fd = (int)map.u64[0];
int map_flags = MAP_PRIVATE; int map_flags = MAP_PRIVATE;
void* base = mmap(0, dim_1u64(range), prot_flags, map_flags, fd, range.min); void* base = mmap(0, dim_1u64(range), prot_flags, map_flags, fd, range.min);
return base; return base;
} }
internal void void
os_file_map_view_close(OS_Handle map, void *ptr, Rng1U64 range) os_file_map_view_close(OS_Handle map, void* ptr, Rng1U64 range) {
{
munmap(ptr, dim_1u64(range)); munmap(ptr, dim_1u64(range));
} }
//- rjf: directory iteration //- rjf: directory iteration
internal OS_FileIter * OS_FileIter*
os_file_iter_begin(Arena* arena, String8 path, OS_FileIterFlags flags) os_file_iter_begin(Arena* arena, String8 path, OS_FileIterFlags flags)
{ {
OS_FileIter *base_iter = push_array(arena, OS_FileIter, 1); OS_FileIter*
base_iter = push_array(arena, OS_FileIter, 1);
base_iter->flags = flags; base_iter->flags = flags;
OS_LNX_FileIter* iter = (OS_LNX_FileIter*)base_iter->memory; OS_LNX_FileIter* iter = (OS_LNX_FileIter*)base_iter->memory;
{ {
String8 path_copy = push_str8_copy(arena, path); String8 path_copy = push_str8_copy(arena, path);
@@ -363,7 +378,7 @@ os_file_iter_begin(Arena *arena, String8 path, OS_FileIterFlags flags)
return base_iter; return base_iter;
} }
internal B32 B32
os_file_iter_next(Arena* arena, OS_FileIter* iter, OS_FileInfo* info_out) os_file_iter_next(Arena* arena, OS_FileIter* iter, OS_FileInfo* info_out)
{ {
B32 good = 0; B32 good = 0;
@@ -379,7 +394,7 @@ os_file_iter_next(Arena *arena, OS_FileIter *iter, OS_FileInfo *info_out)
int stat_result = 0; int stat_result = 0;
if(good) if(good)
{ {
Temp scratch = scratch_begin(&arena, 1); TempArena scratch = scratch_begin(&arena, 1);
String8 full_path = push_str8f(scratch.arena, "%S/%s", lnx_iter->path, lnx_iter->dp->d_name); String8 full_path = push_str8f(scratch.arena, "%S/%s", lnx_iter->path, lnx_iter->dp->d_name);
stat_result = stat((char *)full_path.str, &st); stat_result = stat((char *)full_path.str, &st);
scratch_end(scratch); scratch_end(scratch);
@@ -399,8 +414,7 @@ os_file_iter_next(Arena *arena, OS_FileIter *iter, OS_FileInfo *info_out)
if (good && !filtered) if (good && !filtered)
{ {
info_out->name = push_str8_copy(arena, str8_cstring(lnx_iter->dp->d_name)); info_out->name = push_str8_copy(arena, str8_cstring(lnx_iter->dp->d_name));
if(stat_result != -1) if (stat_result != -1) {
{
info_out->props = os_lnx_file_properties_from_stat(&st); info_out->props = os_lnx_file_properties_from_stat(&st);
} }
break; break;
@@ -415,23 +429,21 @@ os_file_iter_next(Arena *arena, OS_FileIter *iter, OS_FileInfo *info_out)
return good; return good;
} }
internal void void
os_file_iter_end(OS_FileIter *iter) os_file_iter_end(OS_FileIter* iter) {
{
OS_LNX_FileIter* lnx_iter = (OS_LNX_FileIter*)iter->memory; OS_LNX_FileIter* lnx_iter = (OS_LNX_FileIter*)iter->memory;
closedir(lnx_iter->dir); closedir(lnx_iter->dir);
} }
//- rjf: directory creation //- rjf: directory creation
internal B32 B32
os_make_directory(String8 path) os_make_directory(String8 path)
{ {
Temp scratch = scratch_begin(0, 0);
B32 result = 0; B32 result = 0;
TempArena scratch = scratch_begin(0, 0);
String8 path_copy = push_str8_copy(scratch.arena, path); String8 path_copy = push_str8_copy(scratch.arena, path);
if(mkdir((char*)path_copy.str, 0777) != -1) if (mkdir((char*)path_copy.str, 0777) != -1) {
{
result = 1; result = 1;
} }
scratch_end(scratch); scratch_end(scratch);
@@ -441,49 +453,46 @@ os_make_directory(String8 path)
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Shared Memory (Implemented Per-OS) //~ rjf: @os_hooks Shared Memory (Implemented Per-OS)
internal OS_Handle OS_Handle
os_shared_memory_alloc(U64 size, String8 name) os_shared_memory_alloc(U64 size, String8 name)
{ {
Temp scratch = scratch_begin(0, 0); TempArena scratch = scratch_begin(0, 0);
String8 name_copy = push_str8_copy(scratch.arena, name); String8 name_copy = push_str8_copy(scratch.arena, name);
int id = shm_open((char *)name_copy.str, O_RDWR, 0); int id = shm_open((char *)name_copy.str, O_RDWR, 0);
ftruncate(id, size); ftruncate(id, size);
OS_Handle result = {(U64)id};
scratch_end(scratch); scratch_end(scratch);
OS_Handle result = {(U64)id};
return result; return result;
} }
internal OS_Handle OS_Handle
os_shared_memory_open(String8 name) os_shared_memory_open(String8 name)
{ {
Temp scratch = scratch_begin(0, 0); TempArena scratch = scratch_begin(0, 0);
String8 name_copy = push_str8_copy(scratch.arena, name); String8 name_copy = push_str8_copy(scratch.arena, name);
int id = shm_open((char *)name_copy.str, O_RDWR, 0); int id = shm_open((char *)name_copy.str, O_RDWR, 0);
OS_Handle result = {(U64)id};
scratch_end(scratch); scratch_end(scratch);
OS_Handle result = {(U64)id};
return result; return result;
} }
internal void void
os_shared_memory_close(OS_Handle handle) os_shared_memory_close(OS_Handle handle) {
{
if (os_handle_match(handle, os_handle_zero())) { return; } if (os_handle_match(handle, os_handle_zero())) { return; }
int id = (int)handle.u64[0]; int id = (int)handle.u64[0];
close(id); close(id);
} }
internal void * void*
os_shared_memory_view_open(OS_Handle handle, Rng1U64 range) os_shared_memory_view_open(OS_Handle handle, Rng1U64 range) {
{
if (os_handle_match(handle, os_handle_zero())) { return 0; } if (os_handle_match(handle, os_handle_zero())) { return 0; }
int id = (int)handle.u64[0]; int id = (int)handle.u64[0];
void* base = mmap(0, dim_1u64(range), PROT_READ|PROT_WRITE, MAP_SHARED, id, range.min); void* base = mmap(0, dim_1u64(range), PROT_READ|PROT_WRITE, MAP_SHARED, id, range.min);
return base; return base;
} }
internal void void
os_shared_memory_view_close(OS_Handle handle, void *ptr, Rng1U64 range) os_shared_memory_view_close(OS_Handle handle, void* ptr, Rng1U64 range) {
{
if (os_handle_match(handle, os_handle_zero())) { return; } if (os_handle_match(handle, os_handle_zero())) { return; }
munmap(ptr, dim_1u64(range)); munmap(ptr, dim_1u64(range));
} }
@@ -491,23 +500,21 @@ os_shared_memory_view_close(OS_Handle handle, void *ptr, Rng1U64 range)
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Time (Implemented Per-OS) //~ rjf: @os_hooks Time (Implemented Per-OS)
internal U64 U64
os_now_microseconds(void) os_now_microseconds(void) {
{
struct timespec t; struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t); clock_gettime(CLOCK_MONOTONIC, &t);
U64 result = t.tv_sec*Million(1) + (t.tv_nsec/Thousand(1)); U64 result = t.tv_sec * million(1) + (t.tv_nsec / thousand(1));
return result; return result;
} }
internal U32 U32
os_now_unix(void) os_now_unix(void) {
{
time_t t = time(0); time_t t = time(0);
return (U32)t; return (U32)t;
} }
internal DateTime DateTime
os_now_universal_time(void) os_now_universal_time(void)
{ {
time_t t = 0; time_t t = 0;
@@ -518,7 +525,7 @@ os_now_universal_time(void)
return result; return result;
} }
internal DateTime DateTime
os_universal_time_from_local(DateTime* date_time) os_universal_time_from_local(DateTime* date_time)
{ {
// rjf: local DateTime -> universal time_t // rjf: local DateTime -> universal time_t
@@ -533,7 +540,7 @@ os_universal_time_from_local(DateTime *date_time)
return result; return result;
} }
internal DateTime DateTime
os_local_time_from_universal(DateTime* date_time) os_local_time_from_universal(DateTime* date_time)
{ {
// rjf: universal DateTime -> local time_t // rjf: universal DateTime -> local time_t
@@ -548,28 +555,27 @@ os_local_time_from_universal(DateTime *date_time)
return result; return result;
} }
internal void void
os_sleep_milliseconds(U32 msec) os_sleep_milliseconds(U32 msec) {
{ usleep(msec * thousand(1));
usleep(msec*Thousand(1));
} }
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Child Processes (Implemented Per-OS) //~ rjf: @os_hooks Child Processes (Implemented Per-OS)
internal OS_Handle OS_Handle
os_process_launch(OS_ProcessLaunchParams* params) os_process_launch(OS_ProcessLaunchParams* params)
{ {
NotImplemented; NotImplemented;
} }
internal B32 B32
os_process_join(OS_Handle handle, U64 endt_us) os_process_join(OS_Handle handle, U64 endt_us)
{ {
NotImplemented; NotImplemented;
} }
internal void void
os_process_detach(OS_Handle handle) os_process_detach(OS_Handle handle)
{ {
NotImplemented; NotImplemented;
@@ -578,7 +584,7 @@ os_process_detach(OS_Handle handle)
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Threads (Implemented Per-OS) //~ rjf: @os_hooks Threads (Implemented Per-OS)
internal OS_Handle OS_Handle
os_thread_launch(OS_ThreadFunctionType* func, void* ptr, void* params) os_thread_launch(OS_ThreadFunctionType* func, void* ptr, void* params)
{ {
OS_LNX_Entity* entity = os_lnx_entity_alloc(OS_LNX_EntityKind_Thread); OS_LNX_Entity* entity = os_lnx_entity_alloc(OS_LNX_EntityKind_Thread);
@@ -587,6 +593,7 @@ os_thread_launch(OS_ThreadFunctionType *func, void *ptr, void *params)
{ {
pthread_attr_t attr; pthread_attr_t attr;
pthread_attr_init(&attr); pthread_attr_init(&attr);
int pthread_result = pthread_create(&entity->thread.handle, &attr, os_lnx_thread_entry_point, entity); int pthread_result = pthread_create(&entity->thread.handle, &attr, os_lnx_thread_entry_point, entity);
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
if (pthread_result == -1) if (pthread_result == -1)
@@ -599,7 +606,7 @@ os_thread_launch(OS_ThreadFunctionType *func, void *ptr, void *params)
return handle; return handle;
} }
internal B32 B32
os_thread_join(OS_Handle handle, U64 endt_us) os_thread_join(OS_Handle handle, U64 endt_us)
{ {
if (os_handle_match(handle, os_handle_zero())) { return 0; } if (os_handle_match(handle, os_handle_zero())) { return 0; }
@@ -610,9 +617,8 @@ os_thread_join(OS_Handle handle, U64 endt_us)
return result; return result;
} }
internal void void
os_thread_detach(OS_Handle handle) os_thread_detach(OS_Handle handle) {
{
if(os_handle_match(handle, os_handle_zero())) { return; } if(os_handle_match(handle, os_handle_zero())) { return; }
OS_LNX_Entity* entity = (OS_LNX_Entity*)handle.u64[0]; OS_LNX_Entity* entity = (OS_LNX_Entity*)handle.u64[0];
os_lnx_entity_release(entity); os_lnx_entity_release(entity);
@@ -623,17 +629,19 @@ os_thread_detach(OS_Handle handle)
//- rjf: mutexes //- rjf: mutexes
internal OS_Handle OS_Handle
os_mutex_alloc(void) os_mutex_alloc(void)
{ {
OS_LNX_Entity *entity = os_lnx_entity_alloc(OS_LNX_EntityKind_Mutex); OS_LNX_Entity *entity = os_lnx_entity_alloc(OS_LNX_EntityKind_Mutex);
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr); pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
int init_result = pthread_mutex_init(&entity->mutex_handle, &attr); int init_result = pthread_mutex_init(&entity->mutex_handle, &attr);
pthread_mutexattr_destroy(&attr); pthread_mutexattr_destroy(&attr);
if(init_result == -1)
{ if (init_result == -1) {
os_lnx_entity_release(entity); os_lnx_entity_release(entity);
entity = 0; entity = 0;
} }
@@ -641,26 +649,23 @@ os_mutex_alloc(void)
return handle; return handle;
} }
internal void void
os_mutex_release(OS_Handle mutex) os_mutex_release(OS_Handle mutex) {
{
if (os_handle_match(mutex, os_handle_zero())) { return; } if (os_handle_match(mutex, os_handle_zero())) { return; }
OS_LNX_Entity* entity = (OS_LNX_Entity *)mutex.u64[0]; OS_LNX_Entity* entity = (OS_LNX_Entity *)mutex.u64[0];
pthread_mutex_destroy(&entity->mutex_handle); pthread_mutex_destroy(&entity->mutex_handle);
os_lnx_entity_release(entity); os_lnx_entity_release(entity);
} }
internal void void
os_mutex_take(OS_Handle mutex) os_mutex_take(OS_Handle mutex) {
{
if (os_handle_match(mutex, os_handle_zero())) { return; } if (os_handle_match(mutex, os_handle_zero())) { return; }
OS_LNX_Entity* entity = (OS_LNX_Entity *)mutex.u64[0]; OS_LNX_Entity* entity = (OS_LNX_Entity *)mutex.u64[0];
pthread_mutex_lock(&entity->mutex_handle); pthread_mutex_lock(&entity->mutex_handle);
} }
internal void void
os_mutex_drop(OS_Handle mutex) os_mutex_drop(OS_Handle mutex) {
{
if (os_handle_match(mutex, os_handle_zero())) { return; } if (os_handle_match(mutex, os_handle_zero())) { return; }
OS_LNX_Entity* entity = (OS_LNX_Entity *)mutex.u64[0]; OS_LNX_Entity* entity = (OS_LNX_Entity *)mutex.u64[0];
pthread_mutex_unlock(&entity->mutex_handle); pthread_mutex_unlock(&entity->mutex_handle);
@@ -668,13 +673,12 @@ os_mutex_drop(OS_Handle mutex)
//- rjf: reader/writer mutexes //- rjf: reader/writer mutexes
internal OS_Handle OS_Handle
os_rw_mutex_alloc(void) os_rw_mutex_alloc(void)
{ {
OS_LNX_Entity* entity = os_lnx_entity_alloc(OS_LNX_EntityKind_RWMutex); OS_LNX_Entity* entity = os_lnx_entity_alloc(OS_LNX_EntityKind_RWMutex);
int init_result = pthread_rwlock_init(&entity->rwmutex_handle, 0); int init_result = pthread_rwlock_init(&entity->rwmutex_handle, 0);
if(init_result == -1) if (init_result == -1) {
{
os_lnx_entity_release(entity); os_lnx_entity_release(entity);
entity = 0; entity = 0;
} }
@@ -682,42 +686,37 @@ os_rw_mutex_alloc(void)
return handle; return handle;
} }
internal void void
os_rw_mutex_release(OS_Handle rw_mutex) os_rw_mutex_release(OS_Handle rw_mutex) {
{
if (os_handle_match(rw_mutex, os_handle_zero())) { return; } if (os_handle_match(rw_mutex, os_handle_zero())) { return; }
OS_LNX_Entity* entity = (OS_LNX_Entity*)rw_mutex.u64[0]; OS_LNX_Entity* entity = (OS_LNX_Entity*)rw_mutex.u64[0];
pthread_rwlock_destroy(&entity->rwmutex_handle); pthread_rwlock_destroy(&entity->rwmutex_handle);
os_lnx_entity_release(entity); os_lnx_entity_release(entity);
} }
internal void void
os_rw_mutex_take_r(OS_Handle rw_mutex) os_rw_mutex_take_r(OS_Handle rw_mutex) {
{
if (os_handle_match(rw_mutex, os_handle_zero())) { return; } if (os_handle_match(rw_mutex, os_handle_zero())) { return; }
OS_LNX_Entity* entity = (OS_LNX_Entity*)rw_mutex.u64[0]; OS_LNX_Entity* entity = (OS_LNX_Entity*)rw_mutex.u64[0];
pthread_rwlock_rdlock(&entity->rwmutex_handle); pthread_rwlock_rdlock(&entity->rwmutex_handle);
} }
internal void void
os_rw_mutex_drop_r(OS_Handle rw_mutex) os_rw_mutex_drop_r(OS_Handle rw_mutex) {
{
if (os_handle_match(rw_mutex, os_handle_zero())) { return; } if (os_handle_match(rw_mutex, os_handle_zero())) { return; }
OS_LNX_Entity* entity = (OS_LNX_Entity*)rw_mutex.u64[0]; OS_LNX_Entity* entity = (OS_LNX_Entity*)rw_mutex.u64[0];
pthread_rwlock_unlock(&entity->rwmutex_handle); pthread_rwlock_unlock(&entity->rwmutex_handle);
} }
internal void void
os_rw_mutex_take_w(OS_Handle rw_mutex) os_rw_mutex_take_w(OS_Handle rw_mutex) {
{
if (os_handle_match(rw_mutex, os_handle_zero())) { return; } if (os_handle_match(rw_mutex, os_handle_zero())) { return; }
OS_LNX_Entity* entity = (OS_LNX_Entity*)rw_mutex.u64[0]; OS_LNX_Entity* entity = (OS_LNX_Entity*)rw_mutex.u64[0];
pthread_rwlock_wrlock(&entity->rwmutex_handle); pthread_rwlock_wrlock(&entity->rwmutex_handle);
} }
internal void void
os_rw_mutex_drop_w(OS_Handle rw_mutex) os_rw_mutex_drop_w(OS_Handle rw_mutex) {
{
if (os_handle_match(rw_mutex, os_handle_zero())) { return; } if (os_handle_match(rw_mutex, os_handle_zero())) { return; }
OS_LNX_Entity* entity = (OS_LNX_Entity*)rw_mutex.u64[0]; OS_LNX_Entity* entity = (OS_LNX_Entity*)rw_mutex.u64[0];
pthread_rwlock_unlock(&entity->rwmutex_handle); pthread_rwlock_unlock(&entity->rwmutex_handle);
@@ -725,23 +724,20 @@ os_rw_mutex_drop_w(OS_Handle rw_mutex)
//- rjf: condition variables //- rjf: condition variables
internal OS_Handle OS_Handle
os_condition_variable_alloc(void) os_condition_variable_alloc(void)
{ {
OS_LNX_Entity* entity = os_lnx_entity_alloc(OS_LNX_EntityKind_ConditionVariable); OS_LNX_Entity* entity = os_lnx_entity_alloc(OS_LNX_EntityKind_ConditionVariable);
int init_result = pthread_cond_init(&entity->cv.cond_handle, 0); int init_result = pthread_cond_init(&entity->cv.cond_handle, 0);
if(init_result == -1) if (init_result == -1) {
{
os_lnx_entity_release(entity); os_lnx_entity_release(entity);
entity = 0; entity = 0;
} }
int init2_result = 0; int init2_result = 0;
if(entity) if (entity) {
{
init2_result = pthread_mutex_init(&entity->cv.rwlock_mutex_handle, 0); init2_result = pthread_mutex_init(&entity->cv.rwlock_mutex_handle, 0);
} }
if(init2_result == -1) if (init2_result == -1) {
{
pthread_cond_destroy(&entity->cv.cond_handle); pthread_cond_destroy(&entity->cv.cond_handle);
os_lnx_entity_release(entity); os_lnx_entity_release(entity);
entity = 0; entity = 0;
@@ -750,9 +746,8 @@ os_condition_variable_alloc(void)
return handle; return handle;
} }
internal void void
os_condition_variable_release(OS_Handle cv) os_condition_variable_release(OS_Handle cv) {
{
if (os_handle_match(cv, os_handle_zero())) { return; } if (os_handle_match(cv, os_handle_zero())) { return; }
OS_LNX_Entity* entity = (OS_LNX_Entity *)cv.u64[0]; OS_LNX_Entity* entity = (OS_LNX_Entity *)cv.u64[0];
pthread_cond_destroy(&entity->cv.cond_handle); pthread_cond_destroy(&entity->cv.cond_handle);
@@ -760,22 +755,25 @@ os_condition_variable_release(OS_Handle cv)
os_lnx_entity_release(entity); os_lnx_entity_release(entity);
} }
internal B32 B32
os_condition_variable_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us) os_condition_variable_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us)
{ {
if (os_handle_match(cv, os_handle_zero())) { return 0; } if (os_handle_match(cv, os_handle_zero())) { return 0; }
if (os_handle_match(mutex, os_handle_zero())) { return 0; } if (os_handle_match(mutex, os_handle_zero())) { return 0; }
OS_LNX_Entity* cv_entity = (OS_LNX_Entity*)cv.u64[0]; OS_LNX_Entity* cv_entity = (OS_LNX_Entity*)cv.u64[0];
OS_LNX_Entity* mutex_entity = (OS_LNX_Entity*)mutex.u64[0]; OS_LNX_Entity* mutex_entity = (OS_LNX_Entity*)mutex.u64[0];
struct timespec endt_timespec; struct timespec endt_timespec;
endt_timespec.tv_sec = endt_us/Million(1); endt_timespec.tv_sec = endt_us / million(1);
endt_timespec.tv_nsec = Thousand(1) * (endt_us - (endt_us/Million(1))*Million(1)); endt_timespec.tv_nsec = thousand(1) * (endt_us - (endt_us / million(1)) * million(1));
int wait_result = pthread_cond_timedwait(&cv_entity->cv.cond_handle, &mutex_entity->mutex_handle, &endt_timespec); int wait_result = pthread_cond_timedwait(&cv_entity->cv.cond_handle, &mutex_entity->mutex_handle, &endt_timespec);
B32 result = (wait_result != ETIMEDOUT); B32 result = (wait_result != ETIMEDOUT);
return result; return result;
} }
internal B32 B32
os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us) os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
{ {
// TODO(rjf): because pthread does not supply cv/rw natively, I had to hack // TODO(rjf): because pthread does not supply cv/rw natively, I had to hack
@@ -784,11 +782,14 @@ os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
// //
if(os_handle_match(cv, os_handle_zero())) { return 0; } if(os_handle_match(cv, os_handle_zero())) { return 0; }
if(os_handle_match(mutex_rw, os_handle_zero())) { return 0; } if(os_handle_match(mutex_rw, os_handle_zero())) { return 0; }
OS_LNX_Entity* cv_entity = (OS_LNX_Entity*)cv.u64[0]; OS_LNX_Entity* cv_entity = (OS_LNX_Entity*)cv.u64[0];
OS_LNX_Entity* rw_mutex_entity = (OS_LNX_Entity*)mutex_rw.u64[0]; OS_LNX_Entity* rw_mutex_entity = (OS_LNX_Entity*)mutex_rw.u64[0];
struct timespec endt_timespec; struct timespec endt_timespec;
endt_timespec.tv_sec = endt_us/Million(1); endt_timespec.tv_sec = endt_us / million(1);
endt_timespec.tv_nsec = Thousand(1) * (endt_us - (endt_us/Million(1))*Million(1)); endt_timespec.tv_nsec = thousand(1) * (endt_us - (endt_us / million(1)) * million(1));
B32 result = 0; B32 result = 0;
for(;;) for(;;)
{ {
@@ -801,6 +802,7 @@ os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
result = 1; result = 1;
break; break;
} }
pthread_mutex_unlock(&cv_entity->cv.rwlock_mutex_handle); pthread_mutex_unlock(&cv_entity->cv.rwlock_mutex_handle);
if (wait_result == ETIMEDOUT) if (wait_result == ETIMEDOUT)
{ {
@@ -810,7 +812,7 @@ os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
return result; return result;
} }
internal B32 B32
os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us) os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
{ {
// TODO(rjf): because pthread does not supply cv/rw natively, I had to hack // TODO(rjf): because pthread does not supply cv/rw natively, I had to hack
@@ -819,11 +821,14 @@ os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
// //
if (os_handle_match(cv, os_handle_zero())) { return 0; } if (os_handle_match(cv, os_handle_zero())) { return 0; }
if (os_handle_match(mutex_rw, os_handle_zero())) { return 0; } if (os_handle_match(mutex_rw, os_handle_zero())) { return 0; }
OS_LNX_Entity* cv_entity = (OS_LNX_Entity*)cv.u64[0]; OS_LNX_Entity* cv_entity = (OS_LNX_Entity*)cv.u64[0];
OS_LNX_Entity* rw_mutex_entity = (OS_LNX_Entity*)mutex_rw.u64[0]; OS_LNX_Entity* rw_mutex_entity = (OS_LNX_Entity*)mutex_rw.u64[0];
struct timespec endt_timespec; struct timespec endt_timespec;
endt_timespec.tv_sec = endt_us/Million(1); endt_timespec.tv_sec = endt_us / million(1);
endt_timespec.tv_nsec = Thousand(1) * (endt_us - (endt_us/Million(1))*Million(1)); endt_timespec.tv_nsec = thousand(1) * (endt_us - (endt_us / million(1)) * million(1));
B32 result = 0; B32 result = 0;
for(;;) for(;;)
{ {
@@ -836,6 +841,7 @@ os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
result = 1; result = 1;
break; break;
} }
pthread_mutex_unlock(&cv_entity->cv.rwlock_mutex_handle); pthread_mutex_unlock(&cv_entity->cv.rwlock_mutex_handle);
if (wait_result == ETIMEDOUT) if (wait_result == ETIMEDOUT)
{ {
@@ -845,17 +851,15 @@ os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us)
return result; return result;
} }
internal void void
os_condition_variable_signal(OS_Handle cv) os_condition_variable_signal(OS_Handle cv) {
{
if (os_handle_match(cv, os_handle_zero())) { return; } if (os_handle_match(cv, os_handle_zero())) { return; }
OS_LNX_Entity* cv_entity = (OS_LNX_Entity *)cv.u64[0]; OS_LNX_Entity* cv_entity = (OS_LNX_Entity *)cv.u64[0];
pthread_cond_signal(&cv_entity->cv.cond_handle); pthread_cond_signal(&cv_entity->cv.cond_handle);
} }
internal void void
os_condition_variable_broadcast(OS_Handle cv) os_condition_variable_broadcast(OS_Handle cv) {
{
if (os_handle_match(cv, os_handle_zero())) { return; } if (os_handle_match(cv, os_handle_zero())) { return; }
OS_LNX_Entity* cv_entity = (OS_LNX_Entity *)cv.u64[0]; OS_LNX_Entity* cv_entity = (OS_LNX_Entity *)cv.u64[0];
pthread_cond_broadcast(&cv_entity->cv.cond_handle); pthread_cond_broadcast(&cv_entity->cv.cond_handle);
@@ -863,37 +867,37 @@ os_condition_variable_broadcast(OS_Handle cv)
//- rjf: cross-process semaphores //- rjf: cross-process semaphores
internal OS_Handle OS_Handle
os_semaphore_alloc(U32 initial_count, U32 max_count, String8 name) os_semaphore_alloc(U32 initial_count, U32 max_count, String8 name)
{ {
NotImplemented; NotImplemented;
} }
internal void void
os_semaphore_release(OS_Handle semaphore) os_semaphore_release(OS_Handle semaphore)
{ {
NotImplemented; NotImplemented;
} }
internal OS_Handle OS_Handle
os_semaphore_open(String8 name) os_semaphore_open(String8 name)
{ {
NotImplemented; NotImplemented;
} }
internal void void
os_semaphore_close(OS_Handle semaphore) os_semaphore_close(OS_Handle semaphore)
{ {
NotImplemented; NotImplemented;
} }
internal B32 B32
os_semaphore_take(OS_Handle semaphore, U64 endt_us) os_semaphore_take(OS_Handle semaphore, U64 endt_us)
{ {
NotImplemented; NotImplemented;
} }
internal void void
os_semaphore_drop(OS_Handle semaphore) os_semaphore_drop(OS_Handle semaphore)
{ {
NotImplemented; NotImplemented;
@@ -902,10 +906,9 @@ os_semaphore_drop(OS_Handle semaphore)
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Dynamically-Loaded Libraries (Implemented Per-OS) //~ rjf: @os_hooks Dynamically-Loaded Libraries (Implemented Per-OS)
internal OS_Handle OS_Handle
os_library_open(String8 path) os_library_open(String8 path) {
{ TempArena scratch = scratch_begin(0, 0);
Temp scratch = scratch_begin(0, 0);
char* path_cstr = (char *)push_str8_copy(scratch.arena, path).str; char* path_cstr = (char *)push_str8_copy(scratch.arena, path).str;
void* so = dlopen(path_cstr, RTLD_LAZY); void* so = dlopen(path_cstr, RTLD_LAZY);
OS_Handle lib = { (U64)so }; OS_Handle lib = { (U64)so };
@@ -913,10 +916,9 @@ os_library_open(String8 path)
return lib; return lib;
} }
internal VoidProc* VoidProc*
os_library_load_proc(OS_Handle lib, String8 name) os_library_load_proc(OS_Handle lib, String8 name) {
{ TempArena scratch = scratch_begin(0, 0);
Temp scratch = scratch_begin(0, 0);
void* so = (void*)lib.u64; void* so = (void*)lib.u64;
char* name_cstr = (char*)push_str8_copy(scratch.arena, name).str; char* name_cstr = (char*)push_str8_copy(scratch.arena, name).str;
VoidProc* proc = (VoidProc*)dlsym(so, name_cstr); VoidProc* proc = (VoidProc*)dlsym(so, name_cstr);
@@ -924,9 +926,8 @@ os_library_load_proc(OS_Handle lib, String8 name)
return proc; return proc;
} }
internal void void
os_library_close(OS_Handle lib) os_library_close(OS_Handle lib) {
{
void* so = (void*)lib.u64; void* so = (void*)lib.u64;
dlclose(so); dlclose(so);
} }
@@ -934,7 +935,7 @@ os_library_close(OS_Handle lib)
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Safe Calls (Implemented Per-OS) //~ rjf: @os_hooks Safe Calls (Implemented Per-OS)
internal void void
os_safe_call(OS_ThreadFunctionType* func, OS_ThreadFunctionType* fail_handler, void* ptr) os_safe_call(OS_ThreadFunctionType* func, OS_ThreadFunctionType* fail_handler, void* ptr)
{ {
// rjf: push handler to chain // rjf: push handler to chain
@@ -946,15 +947,13 @@ os_safe_call(OS_ThreadFunctionType *func, OS_ThreadFunctionType *fail_handler, v
// rjf: set up sig handler info // rjf: set up sig handler info
struct sigaction new_act = {0}; struct sigaction new_act = {0};
new_act.sa_handler = os_lnx_safe_call_sig_handler; new_act.sa_handler = os_lnx_safe_call_sig_handler;
int signals_to_handle[] = int signals_to_handle[] = {
{
SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP, SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP,
}; };
struct sigaction og_act[ArrayCount(signals_to_handle)] = {0}; struct sigaction og_act[ArrayCount(signals_to_handle)] = {0};
// rjf: attach handler info for all signals // rjf: attach handler info for all signals
for(U32 i = 0; i < ArrayCount(signals_to_handle); i += 1) for(U32 i = 0; i < ArrayCount(signals_to_handle); i += 1) {
{
sigaction(signals_to_handle[i], &new_act, &og_act[i]); sigaction(signals_to_handle[i], &new_act, &og_act[i]);
} }
@@ -962,8 +961,7 @@ os_safe_call(OS_ThreadFunctionType *func, OS_ThreadFunctionType *fail_handler, v
func(ptr); func(ptr);
// rjf: reset handler info for all signals // rjf: reset handler info for all signals
for(U32 i = 0; i < ArrayCount(signals_to_handle); i += 1) for (U32 i = 0; i < ArrayCount(signals_to_handle); i += 1) {
{
sigaction(signals_to_handle[i], &og_act[i], 0); sigaction(signals_to_handle[i], &og_act[i], 0);
} }
} }
@@ -971,14 +969,15 @@ os_safe_call(OS_ThreadFunctionType *func, OS_ThreadFunctionType *fail_handler, v
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks GUIDs (Implemented Per-OS) //~ rjf: @os_hooks GUIDs (Implemented Per-OS)
internal OS_Guid OS_Guid
os_make_guid(void) os_make_guid(void)
{ {
U8 random_bytes[16] = {0}; U8 random_bytes[16] = {0};
StaticAssert(sizeof(random_bytes) == sizeof(OS_Guid), os_lnx_guid_size_check); md_static_assert(sizeof(random_bytes) == sizeof(OS_Guid), os_lnx_guid_size_check);
getrandom(random_bytes, sizeof(random_bytes), 0); getrandom(random_bytes, sizeof(random_bytes), 0);
OS_Guid guid = {0}; OS_Guid guid = {0};
MemoryCopy(&guid, random_bytes, sizeof(random_bytes)); memory_copy(&guid, random_bytes, sizeof(random_bytes));
guid.data3 &= 0x0fff; guid.data3 &= 0x0fff;
guid.data3 |= (4 << 12); guid.data3 |= (4 << 12);
guid.data4[0] &= 0x3f; guid.data4[0] &= 0x3f;
@@ -989,6 +988,8 @@ os_make_guid(void)
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Entry Points (Implemented Per-OS) //~ rjf: @os_hooks Entry Points (Implemented Per-OS)
#if BUILD_ENTRY_DEFINING_UNIT || 1
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
@@ -1018,7 +1019,7 @@ main(int argc, char **argv)
//- rjf: grab dynamically allocated system info //- rjf: grab dynamically allocated system info
{ {
Temp scratch = scratch_begin(0, 0); TempArena scratch = scratch_begin(0, 0);
OS_SystemInfo* info = &os_lnx_state.system_info; OS_SystemInfo* info = &os_lnx_state.system_info;
// rjf: get machine name // rjf: get machine name
@@ -1051,7 +1052,7 @@ main(int argc, char **argv)
//- rjf: grab dynamically allocated process info //- rjf: grab dynamically allocated process info
{ {
Temp scratch = scratch_begin(0, 0); TempArena scratch = scratch_begin(0, 0);
OS_ProcessInfo* info = &os_lnx_state.process_info; OS_ProcessInfo* info = &os_lnx_state.process_info;
// rjf: grab binary path // rjf: grab binary path
@@ -1099,3 +1100,6 @@ main(int argc, char **argv)
//- rjf: call into "real" entry point //- rjf: call into "real" entry point
main_thread_base_entry_point(entry_point, argv, (U64)argc); main_thread_base_entry_point(entry_point, argv, (U64)argc);
} }
// BUILD_ENTRY_POINT
#endif
+9 -9
View File
@@ -196,18 +196,25 @@ MD_API void os_lnx_entity_release(OS_LNX_Entity* entity);
//////////////////////////////// ////////////////////////////////
//~ rjf: Thread Entry Point //~ rjf: Thread Entry Point
void* os_lnx_thread_entry_point(void* ptr); MD_API void* os_lnx_thread_entry_point(void* ptr);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks System/Process Info (Implemented Per-OS) //~ rjf: @os_hooks System/Process Info (Implemented Per-OS)
String8 inline String8
os_get_current_path(Arena* arena) { os_get_current_path(Arena* arena) {
char* cwdir = getcwd(0, 0); char* cwdir = getcwd(0, 0);
String8 string = push_str8_copy(arena, str8_cstring(cwdir)); String8 string = push_str8_copy(arena, str8_cstring(cwdir));
return string; return string;
} }
inline String8
os_get_current_path(AllocatorInfo ainfo) {
char* cwdir = getcwd(0, 0);
String8 string = str8_copy(ainfo, str8_cstring(cwdir));
return string;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Memory Allocation (Implemented Per-OS) //~ rjf: @os_hooks Memory Allocation (Implemented Per-OS)
@@ -236,10 +243,3 @@ os_tid(void) {
#endif #endif
return result; return result;
} }
////////////////////////////////
//~ rjf: @os_hooks Aborting (Implemented Per-OS)
inline void os_abort(S32 exit_code) { exit(exit_code); }
+117 -84
View File
@@ -231,6 +231,17 @@ os_string_list_from_argcv(Arena* arena, int argc, char** argv) {
return result; return result;
} }
inline String8List
os_string_list_from_argcv(AllocatorInfo ainfo, int argc, char** argv) {
String8List result = {0};
for(int i = 0; i < argc; i += 1)
{
String8 str = str8_cstring(argv[i]);
str8_list_alloc(ainfo, &result, str);
}
return result;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: Filesystem Helpers (Helpers, Implemented Once) //~ rjf: Filesystem Helpers (Helpers, Implemented Once)
@@ -285,7 +296,8 @@ inline S64 os_file_id_compare(OS_FileID a, OS_FileID b) { S64 cmp = memory_compa
inline String8 inline String8
os_string_from_guid(Arena* arena, OS_Guid guid) { os_string_from_guid(Arena* arena, OS_Guid guid) {
String8 result = push_str8f(arena, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", String8 result = push_str8f(arena,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
guid.data1, guid.data1,
guid.data2, guid.data2,
guid.data3, guid.data3,
@@ -296,162 +308,183 @@ os_string_from_guid(Arena* arena, OS_Guid guid) {
guid.data4[4], guid.data4[4],
guid.data4[5], guid.data4[5],
guid.data4[6], guid.data4[6],
guid.data4[7]); guid.data4[7]
);
return result;
}
inline String8
os_string_from_guid(AllocatorInfo ainfo, OS_Guid guid) {
String8 result = str8f(ainfo,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
guid.data1,
guid.data2,
guid.data3,
guid.data4[0],
guid.data4[1],
guid.data4[2],
guid.data4[3],
guid.data4[4],
guid.data4[5],
guid.data4[6],
guid.data4[7]
);
return result; return result;
} }
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks System/Process Info (Implemented Per-OS) //~ rjf: @os_hooks System/Process Info (Implemented Per-OS)
internal OS_SystemInfo* os_get_system_info(void); MD_API OS_SystemInfo* os_get_system_info (void);
internal OS_ProcessInfo* os_get_process_info(void); MD_API OS_ProcessInfo* os_get_process_info(void);
internal String8 os_get_current_path(Arena *arena);
String8 os_get_current_path(Arena* arena);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Memory Allocation (Implemented Per-OS) //~ rjf: @os_hooks Memory Allocation (Implemented Per-OS)
//- rjf: basic //- rjf: basic
internal void *os_reserve(U64 size); void* os_reserve ( U64 size);
internal B32 os_commit(void *ptr, U64 size); B32 os_commit (void* ptr, U64 size);
internal void os_decommit(void *ptr, U64 size); void os_decommit(void* ptr, U64 size);
internal void os_release(void *ptr, U64 size); void os_release (void* ptr, U64 size);
//- rjf: large pages //- rjf: large pages
internal void *os_reserve_large(U64 size); void* os_reserve_large( U64 size);
internal B32 os_commit_large(void *ptr, U64 size); B32 os_commit_large (void* ptr, U64 size);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Thread Info (Implemented Per-OS) //~ rjf: @os_hooks Thread Info (Implemented Per-OS)
internal U32 os_tid(void); U32 os_tid (void);
internal void os_set_thread_name(String8 string); MD_API void os_set_thread_name(String8 string);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Aborting (Implemented Per-OS) //~ rjf: @os_hooks Aborting (Implemented Per-OS)
internal void os_abort(S32 exit_code); MD_API void os_abort(S32 exit_code);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks File System (Implemented Per-OS) //~ rjf: @os_hooks File System (Implemented Per-OS)
//- rjf: files //- rjf: files
internal OS_Handle os_file_open(OS_AccessFlags flags, String8 path); MD_API OS_Handle os_file_open (OS_AccessFlags flags, String8 path);
internal void os_file_close(OS_Handle file); MD_API void os_file_close (OS_Handle file);
internal U64 os_file_read(OS_Handle file, Rng1U64 rng, void *out_data); MD_API U64 os_file_read (OS_Handle file, Rng1U64 rng, void *out_data);
internal U64 os_file_write(OS_Handle file, Rng1U64 rng, void *data); MD_API U64 os_file_write (OS_Handle file, Rng1U64 rng, void *data);
internal B32 os_file_set_times(OS_Handle file, DateTime time); MD_API B32 os_file_set_times (OS_Handle file, DateTime time);
internal FileProperties os_properties_from_file(OS_Handle file); MD_API FileProperties os_properties_from_file (OS_Handle file);
internal OS_FileID os_id_from_file(OS_Handle file); MD_API OS_FileID os_id_from_file (OS_Handle file);
internal B32 os_delete_file_at_path(String8 path); MD_API B32 os_delete_file_at_path (String8 path);
internal B32 os_copy_file_path(String8 dst, String8 src); MD_API B32 os_copy_file_path (String8 dst, String8 src);
internal String8 os_full_path_from_path(Arena *arena, String8 path); MD_API String8 os_full_path_from_path (Arena* arena, String8 path);
internal B32 os_file_path_exists(String8 path); MD_API B32 os_file_path_exists (String8 path);
internal FileProperties os_properties_from_file_path(String8 path); MD_API FileProperties os_properties_from_file_path(String8 path);
//- rjf: file maps //- rjf: file maps
internal OS_Handle os_file_map_open(OS_AccessFlags flags, OS_Handle file); MD_API OS_Handle os_file_map_open (OS_AccessFlags flags, OS_Handle file);
internal void os_file_map_close(OS_Handle map); MD_API void os_file_map_close (OS_Handle map);
internal void* os_file_map_view_open(OS_Handle map, OS_AccessFlags flags, Rng1U64 range); MD_API void* os_file_map_view_open (OS_Handle map, OS_AccessFlags flags, Rng1U64 range);
internal void os_file_map_view_close(OS_Handle map, void *ptr, Rng1U64 range); MD_API void os_file_map_view_close(OS_Handle map, void* ptr, Rng1U64 range);
//- rjf: directory iteration //- rjf: directory iteration
internal OS_FileIter* os_file_iter_begin(Arena *arena, String8 path, OS_FileIterFlags flags); MD_API OS_FileIter* os_file_iter_begin(Arena* arena, String8 path, OS_FileIterFlags flags);
internal B32 os_file_iter_next(Arena *arena, OS_FileIter *iter, OS_FileInfo *info_out); MD_API B32 os_file_iter_next (Arena* arena, OS_FileIter* iter, OS_FileInfo* info_out);
internal void os_file_iter_end(OS_FileIter *iter); MD_API void os_file_iter_end ( OS_FileIter* iter);
//- rjf: directory creation //- rjf: directory creation
internal B32 os_make_directory(String8 path); MD_API B32 os_make_directory(String8 path);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Shared Memory (Implemented Per-OS) //~ rjf: @os_hooks Shared Memory (Implemented Per-OS)
internal OS_Handle os_shared_memory_alloc(U64 size, String8 name); MD_API OS_Handle os_shared_memory_alloc (U64 size, String8 name);
internal OS_Handle os_shared_memory_open(String8 name); MD_API OS_Handle os_shared_memory_open (String8 name);
internal void os_shared_memory_close(OS_Handle handle); MD_API void os_shared_memory_close (OS_Handle handle);
internal void* os_shared_memory_view_open(OS_Handle handle, Rng1U64 range); MD_API void* os_shared_memory_view_open (OS_Handle handle, Rng1U64 range);
internal void os_shared_memory_view_close(OS_Handle handle, void *ptr, Rng1U64 range); MD_API void os_shared_memory_view_close(OS_Handle handle, void* ptr, Rng1U64 range);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Time (Implemented Per-OS) //~ rjf: @os_hooks Time (Implemented Per-OS)
internal U64 os_now_microseconds(void); MD_API U64 os_now_microseconds (void);
internal U32 os_now_unix(void); MD_API U32 os_now_unix (void);
internal DateTime os_now_universal_time(void); MD_API DateTime os_now_universal_time (void);
internal DateTime os_universal_time_from_local(DateTime *local_time); MD_API DateTime os_universal_time_from_local(DateTime* local_time);
internal DateTime os_local_time_from_universal(DateTime *universal_time); MD_API DateTime os_local_time_from_universal(DateTime* universal_time);
internal void os_sleep_milliseconds(U32 msec); MD_API void os_sleep_milliseconds (U32 msec);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Child Processes (Implemented Per-OS) //~ rjf: @os_hooks Child Processes (Implemented Per-OS)
internal OS_Handle os_process_launch(OS_ProcessLaunchParams *params); MD_API OS_Handle os_process_launch(OS_ProcessLaunchParams* params);
internal B32 os_process_join(OS_Handle handle, U64 endt_us); MD_API B32 os_process_join (OS_Handle handle, U64 endt_us);
internal void os_process_detach(OS_Handle handle); MD_API void os_process_detach(OS_Handle handle);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Threads (Implemented Per-OS) //~ rjf: @os_hooks Threads (Implemented Per-OS)
internal OS_Handle os_thread_launch(OS_ThreadFunctionType *func, void *ptr, void *params); MD_API OS_Handle os_thread_launch(OS_ThreadFunctionType* func, void* ptr, void* params);
internal B32 os_thread_join(OS_Handle handle, U64 endt_us); MD_API B32 os_thread_join (OS_Handle handle, U64 endt_us);
internal void os_thread_detach(OS_Handle handle); MD_API void os_thread_detach(OS_Handle handle);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Synchronization Primitives (Implemented Per-OS) //~ rjf: @os_hooks Synchronization Primitives (Implemented Per-OS)
//- rjf: recursive mutexes //- rjf: recursive mutexes
internal OS_Handle os_mutex_alloc(void); MD_API OS_Handle os_mutex_alloc (void);
internal void os_mutex_release(OS_Handle mutex); MD_API void os_mutex_release(OS_Handle mutex);
internal void os_mutex_take(OS_Handle mutex); MD_API void os_mutex_take (OS_Handle mutex);
internal void os_mutex_drop(OS_Handle mutex); MD_API void os_mutex_drop (OS_Handle mutex);
//- rjf: reader/writer mutexes //- rjf: reader/writer mutexes
internal OS_Handle os_rw_mutex_alloc(void); MD_API OS_Handle os_rw_mutex_alloc(void);
internal void os_rw_mutex_release(OS_Handle rw_mutex); MD_API void os_rw_mutex_release(OS_Handle rw_mutex);
internal void os_rw_mutex_take_r(OS_Handle mutex); MD_API void os_rw_mutex_take_r(OS_Handle mutex);
internal void os_rw_mutex_drop_r(OS_Handle mutex); MD_API void os_rw_mutex_drop_r(OS_Handle mutex);
internal void os_rw_mutex_take_w(OS_Handle mutex); MD_API void os_rw_mutex_take_w(OS_Handle mutex);
internal void os_rw_mutex_drop_w(OS_Handle mutex); MD_API void os_rw_mutex_drop_w(OS_Handle mutex);
//- rjf: condition variables //- rjf: condition variables
internal OS_Handle os_condition_variable_alloc(void); MD_API OS_Handle os_condition_variable_alloc (void);
internal void os_condition_variable_release(OS_Handle cv); MD_API void os_condition_variable_release(OS_Handle cv);
// returns false on timeout, true on signal, (max_wait_ms = max_U64) -> no timeout // returns false on timeout, true on signal, (max_wait_ms = max_U64) -> no timeout
internal B32 os_condition_variable_wait(OS_Handle cv, OS_Handle mutex, U64 endt_us); MD_API B32 os_condition_variable_wait (OS_Handle cv, OS_Handle mutex, U64 endt_us);
internal B32 os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us); MD_API B32 os_condition_variable_wait_rw_r(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us);
internal B32 os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us); MD_API B32 os_condition_variable_wait_rw_w(OS_Handle cv, OS_Handle mutex_rw, U64 endt_us);
internal void os_condition_variable_signal(OS_Handle cv); MD_API void os_condition_variable_signal (OS_Handle cv);
internal void os_condition_variable_broadcast(OS_Handle cv); MD_API void os_condition_variable_broadcast(OS_Handle cv);
//- rjf: cross-process semaphores //- rjf: cross-process semaphores
internal OS_Handle os_semaphore_alloc(U32 initial_count, U32 max_count, String8 name); MD_API OS_Handle os_semaphore_alloc (U32 initial_count, U32 max_count, String8 name);
internal void os_semaphore_release(OS_Handle semaphore); MD_API void os_semaphore_release(OS_Handle semaphore);
internal OS_Handle os_semaphore_open(String8 name); MD_API OS_Handle os_semaphore_open (String8 name);
internal void os_semaphore_close(OS_Handle semaphore); MD_API void os_semaphore_close (OS_Handle semaphore);
internal B32 os_semaphore_take(OS_Handle semaphore, U64 endt_us); MD_API B32 os_semaphore_take (OS_Handle semaphore, U64 endt_us);
internal void os_semaphore_drop(OS_Handle semaphore); MD_API void os_semaphore_drop (OS_Handle semaphore);
//- rjf: scope macros //- rjf: scope macros
#define OS_MutexScope(mutex) DeferLoop(os_mutex_take(mutex), os_mutex_drop(mutex)) #define OS_MutexScope(mutex) defer_loop( os_mutex_take (mutex), os_mutex_drop (mutex))
#define OS_MutexScopeR(mutex) DeferLoop(os_rw_mutex_take_r(mutex), os_rw_mutex_drop_r(mutex)) #define OS_MutexScopeR(mutex) defer_loop( os_rw_mutex_take_r(mutex), os_rw_mutex_drop_r(mutex))
#define OS_MutexScopeW(mutex) DeferLoop(os_rw_mutex_take_w(mutex), os_rw_mutex_drop_w(mutex)) #define OS_MutexScopeW(mutex) defer_loop( os_rw_mutex_take_w(mutex), os_rw_mutex_drop_w(mutex))
#define OS_MutexScopeRWPromote(mutex) DeferLoop((os_rw_mutex_drop_r(mutex), os_rw_mutex_take_w(mutex)), (os_rw_mutex_drop_w(mutex), os_rw_mutex_take_r(mutex))) #define OS_MutexScopeRWPromote(mutex) defer_loop((os_rw_mutex_drop_r(mutex), os_rw_mutex_take_w(mutex)), (os_rw_mutex_drop_w(mutex), os_rw_mutex_take_r(mutex)))
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Dynamically-Loaded Libraries (Implemented Per-OS) //~ rjf: @os_hooks Dynamically-Loaded Libraries (Implemented Per-OS)
internal OS_Handle os_library_open(String8 path); MD_API OS_Handle os_library_open (String8 path);
internal void os_library_close(OS_Handle lib); MD_API void os_library_close (OS_Handle lib);
internal VoidProc *os_library_load_proc(OS_Handle lib, String8 name); MD_API VoidProc* os_library_load_proc(OS_Handle lib, String8 name);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Safe Calls (Implemented Per-OS) //~ rjf: @os_hooks Safe Calls (Implemented Per-OS)
internal void os_safe_call(OS_ThreadFunctionType *func, OS_ThreadFunctionType *fail_handler, void *ptr); MD_API void os_safe_call(OS_ThreadFunctionType* func, OS_ThreadFunctionType* fail_handler, void* ptr);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks GUIDs (Implemented Per-OS) //~ rjf: @os_hooks GUIDs (Implemented Per-OS)
internal OS_Guid os_make_guid(void); MD_API OS_Guid os_make_guid(void);
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Entry Points (Implemented Per-OS) //~ rjf: @os_hooks Entry Points (Implemented Per-OS)
@@ -461,5 +494,5 @@ internal OS_Guid os_make_guid(void);
// into the standard codebase program entry points, named "entry_point". // into the standard codebase program entry points, named "entry_point".
#if BUILD_ENTRY_DEFINING_UNIT #if BUILD_ENTRY_DEFINING_UNIT
internal void entry_point(CmdLine *cmdline); void entry_point(CmdLine* cmdline);
#endif #endif
+223 -228
View File
File diff suppressed because it is too large Load Diff
+18 -14
View File
@@ -201,14 +201,29 @@ os_get_current_path(Arena* arena) {
return name; return name;
} }
inline String8
os_get_current_path(AllocatorInfo ainfo) {
String8 name;
// TODO(Ed): Review
TempArena scratch = scratch_begin(0, 0);
{
DWORD length = GetCurrentDirectoryW(0, 0);
U16* memory = push_array_no_zero(scratch.arena, U16, length + 1);
length = GetCurrentDirectoryW(length + 1, (WCHAR*)memory);
name = str8_from_16_alloc(ainfo, str16(memory, length));
}
scratch_end(scratch);
return name;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: @os_hooks Memory Allocation (Implemented Per-OS) //~ rjf: @os_hooks Memory Allocation (Implemented Per-OS)
//- rjf: basic //- rjf: basic
force_inline void* os_reserve ( U64 size) { void* result = VirtualAlloc( 0, size, MEM_RESERVE, PAGE_READWRITE); return result; } inline void* os_reserve ( U64 size) { void* result = VirtualAlloc( 0, size, MEM_RESERVE, PAGE_READWRITE); return result; }
force_inline B32 os_commit (void* ptr, U64 size) { B32 result = (VirtualAlloc(ptr, size, MEM_COMMIT, PAGE_READWRITE) != 0); return result; } inline B32 os_commit (void* ptr, U64 size) { B32 result = (VirtualAlloc(ptr, size, MEM_COMMIT, PAGE_READWRITE) != 0); return result; }
force_inline void os_decommit(void* ptr, U64 size) { VirtualFree (ptr, size, MEM_DECOMMIT); } inline void os_decommit(void* ptr, U64 size) { VirtualFree (ptr, size, MEM_DECOMMIT); }
inline void inline void
os_release(void* ptr, U64 size) { os_release(void* ptr, U64 size) {
@@ -231,14 +246,3 @@ inline B32 os_commit_large(void *ptr, U64 size) { return 1; }
//~ rjf: @os_hooks Thread Info (Implemented Per-OS) //~ rjf: @os_hooks Thread Info (Implemented Per-OS)
inline U32 os_tid(void) { DWORD id = GetCurrentThreadId(); return (U32)id; } inline U32 os_tid(void) { DWORD id = GetCurrentThreadId(); return (U32)id; }
////////////////////////////////
//~ rjf: @os_hooks Aborting (Implemented Per-OS)
inline void os_abort(S32 exit_code) { ExitProcess(exit_code); }
////////////////////////////////
//~ rjf: @os_hooks File System (Implemented Per-OS)
//- rjf: files