From 7fb99f50bc152988b75f21628b9350c677f60192 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 30 Jun 2017 15:08:11 -0400 Subject: [PATCH] cleaning up linux layer --- platform_linux/linux_4ed.cpp | 57 ++++++---------------------- platform_unix/unix_4ed_functions.cpp | 15 ++++++++ 2 files changed, 27 insertions(+), 45 deletions(-) create mode 100644 platform_unix/unix_4ed_functions.cpp diff --git a/platform_linux/linux_4ed.cpp b/platform_linux/linux_4ed.cpp index 27bc619f..4923e8f6 100644 --- a/platform_linux/linux_4ed.cpp +++ b/platform_linux/linux_4ed.cpp @@ -36,6 +36,7 @@ #include "4ed_math.h" #include "4ed_system.h" +#include "4ed_log.h" #include "4ed_rendering.h" #include "4ed.h" @@ -89,8 +90,6 @@ #define FPS 60L #define frame_useconds (1000000UL / FPS) -#define LinuxGetMemory(size) LinuxGetMemory_(size, __LINE__, __FILE__) - #if FRED_INTERNAL #define LINUX_FN_DEBUG(fmt, ...) do { \ fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__); \ @@ -216,6 +215,8 @@ struct Linux_Vars{ Linux_Coroutine coroutine_data[18]; Linux_Coroutine *coroutine_free; + + u32 log_position; }; // @@ -251,34 +252,6 @@ internal void system_signal_cv(i32, i32); // Shared system functions (system_shared.h) // -internal void* -LinuxGetMemory_(i32 size, i32 line_number, char *file_name){ - void *result = 0; - - Assert(size != 0); - - size_t real_size = size + sizeof(size_t); - result = mmap(0, real_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if(result == MAP_FAILED){ - perror("mmap"); - result = NULL; - } else { - memcpy(result, &real_size, sizeof(size_t)); - result = (char*)result + sizeof(size_t); - } - - return(result); -} - -internal void -LinuxFreeMemory(void *block){ - if (block){ - block = (char*)block - sizeof(size_t); - size_t size = *(size_t*)block; - munmap(block, size); - } -} - internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made){ b32 result = access((char*)filename, W_OK) == 0; @@ -319,17 +292,11 @@ Sys_Memory_Allocate_Sig(system_memory_allocate){ internal Sys_Memory_Set_Protection_Sig(system_memory_set_protection){ - // NOTE(allen): - // There is no such thing as "write only" in windows - // so I just made write = write + read in all cases. - bool32 result = 1; + bool32 result = true; + int protect = 0; - - flags = flags & 0x7; - - switch (flags){ - case 0: - protect = PROT_NONE; break; + switch (flags & 0x7){ + case 0: protect = PROT_NONE; break; case MemProtect_Read: protect = PROT_READ; break; @@ -987,7 +954,7 @@ JobThreadProc(void* lpParameter){ if (thread_memory->size == 0){ i32 new_size = KB(64); - thread_memory->data = LinuxGetMemory(new_size); + thread_memory->data = system_memory_allocate(new_size); thread_memory->size = new_size; } @@ -1924,12 +1891,12 @@ LinuxHandleToFD(Plat_Handle h){ internal void LinuxStringDup(String* str, void* data, size_t size){ - if(str->memory_size < size){ - if(str->str){ - LinuxFreeMemory(str->str); + if (str->memory_size < size){ + if (str->str){ + system_memory_free(str->str, str->memory_size); } str->memory_size = size; - str->str = (char*)LinuxGetMemory(size); + str->str = (char*)system_memory_allocate(size); //TODO(inso): handle alloc failure case } diff --git a/platform_unix/unix_4ed_functions.cpp b/platform_unix/unix_4ed_functions.cpp new file mode 100644 index 00000000..7bd59ab6 --- /dev/null +++ b/platform_unix/unix_4ed_functions.cpp @@ -0,0 +1,15 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 06.30.2017 + * + * General unix functions + * + */ + +// TOP + + + +// BOTTOM +