diff --git a/platform_linux/linux_4ed.cpp b/platform_linux/linux_4ed.cpp index 28e9f7a0..5091a2a8 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__); \ @@ -212,6 +211,8 @@ struct Linux_Vars{ Linux_Coroutine coroutine_data[18]; Linux_Coroutine *coroutine_free; + + u32 log_position; }; // @@ -247,34 +248,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; @@ -315,17 +288,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; @@ -983,7 +950,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; } @@ -1920,12 +1887,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 +