moving things over to unix file

master
Allen Webster 2017-06-30 17:28:09 -04:00
parent 9b93696870
commit a291c8c3d1
5 changed files with 123 additions and 77 deletions

View File

@ -152,7 +152,7 @@ init_build_line(Build_Line *line){
#define CL_X86 "-MACHINE:X86"
static void
build(u32 flags, char *code_path, char **code_files, char *out_path, char *out_file, char *exports, char *inc_flags){
build(u32 flags, char *code_path, char **code_files, char *out_path, char *out_file, char *exports, char **inc_folders){
Build_Line line;
init_build_line(&line);
@ -298,7 +298,7 @@ build(u32 flags, char *code_path, char **code_files, char *out_path, char *out_f
#define GCC_SITE_INCLUDES "-I../../foreign -I../../code"
static void
build(u32 flags, char *code_path, char **code_files, char *out_path, char *out_file, char *exports, char *inc_flags){
build(u32 flags, char *code_path, char **code_files, char *out_path, char *out_file, char *exports, char **inc_folders){
Build_Line line;
init_build_line(&line);
@ -335,8 +335,10 @@ build(u32 flags, char *code_path, char **code_files, char *out_path, char *out_f
build_ap(line, GCC_SITE_INCLUDES);
}
if (inc_flags != 0 && inc_flags[0] != 0){
build_ap(line, "%s", inc_flags);
if (inc_folders != 0){
for (u32 i = 0; inc_folders[i] != 0; ++i){
build_ap(line, "-I%s/%s", code_path, inc_folders[i]);
}
}
if (flags & DEBUG_INFO){
@ -388,12 +390,12 @@ build(u32 flags, char *code_path, char **code_files, char *out_path, char *out_f
#endif
static void
build(u32 flags, char *code_path, char *code_file, char *out_path, char *out_file, char *exports, char *inc_flags){
build(u32 flags, char *code_path, char *code_file, char *out_path, char *out_file, char *exports, char **inc_folders){
char *code_files[2];
code_files[0] = code_file;
code_files[1] = 0;
build(flags, code_path, code_files, out_path, out_file, exports, inc_flags);
build(flags, code_path, code_files, out_path, out_file, exports, inc_folders);
}
static void
@ -425,7 +427,11 @@ buildsuper(char *code_path, char *out_path, char *filename, b32 x86_build){
char *PLAT_LAYER[] = { "platform_win32\\win32_4ed.cpp", 0 };
# if defined(IS_CL)
# define PLAT_INC "/I..\\code /I..\\code\\platform_all"
char *PLAT_INC[] = {
".",
"platform_all",
0
};
# else
# error PLAT_INC not defines for this compiler/platform combo
# endif
@ -434,7 +440,11 @@ char *PLAT_LAYER[] = { "platform_win32\\win32_4ed.cpp", 0 };
char *PLAT_LAYER[] = { "platform_linux/linux_4ed.cpp", 0 };
# if defined(IS_GCC)
# define PLAT_INC "-I../code/platform_all -I../code/platform_unix"
char *PLAT_INC[] = {
"platform_all",
"platform_unix",
0
};
# else
# error PLAT_INC not defines for this compiler/platform combo
# endif
@ -446,9 +456,12 @@ char *PLAT_LAYER[] = {
"platform_mac/mac_4ed.cpp",
0
};
# if defined(IS_GCC)
# define PLAT_INC "-I../code/platform_all -I../code/platform_unix"
char *PLAT_INC[] = {
"platform_all",
"platform_unix",
0
};
# else
# error PLAT_INC not defines for this compiler/platform combo
# endif

View File

@ -10,6 +10,8 @@
// TOP
#define IS_PLAT_LAYER
#include <assert.h>
#include <string.h>
#include "4tech_defines.h"
@ -40,6 +42,8 @@
#include "4ed_rendering.h"
#include "4ed.h"
#include "unix_4ed_functions.cpp"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
@ -63,7 +67,6 @@
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/timerfd.h>
#include <sys/eventfd.h>
#include <sys/epoll.h>
@ -270,67 +273,6 @@ Sys_Get_Binary_Path_Sig(system_get_binary_path){
return size;
}
//
// custom.h
//
internal
Sys_Memory_Allocate_Sig(system_memory_allocate){
// NOTE(allen): This must return the exact base of the vpage.
// We will count on the user to keep track of size themselves.
void *result = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if(result == MAP_FAILED){
perror("mmap");
result = NULL;
}
return(result);
}
internal
Sys_Memory_Set_Protection_Sig(system_memory_set_protection){
bool32 result = true;
int protect = 0;
switch (flags & 0x7){
case 0: protect = PROT_NONE; break;
case MemProtect_Read:
protect = PROT_READ; break;
case MemProtect_Write:
case MemProtect_Read|MemProtect_Write:
protect = PROT_READ | PROT_WRITE; break;
case MemProtect_Execute:
protect = PROT_EXEC; break;
case MemProtect_Execute|MemProtect_Read:
protect = PROT_READ | PROT_EXEC; break;
// NOTE(inso): some W^X protection things might be unhappy about this one
case MemProtect_Execute|MemProtect_Write:
case MemProtect_Execute|MemProtect_Write|MemProtect_Read:
protect = PROT_READ | PROT_WRITE | PROT_EXEC; break;
}
if(mprotect(ptr, size, protect) == -1){
result = 0;
perror("mprotect");
}
return(result);
}
internal
Sys_Memory_Free_Sig(system_memory_free){
// NOTE(allen): This must take the exact base of the vpage.
munmap(ptr, size);
}
//
// System Functions (4ed_system.h)
//
//
// Files
//
@ -556,14 +498,12 @@ Sys_Load_Close_Sig(system_load_close){
internal
Sys_Save_File_Sig(system_save_file){
b32 result = 0;
int fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 00640);
LINUX_FN_DEBUG("%s %d", filename, size);
if(fd < 0){
fprintf(stderr, "system_save_file: open '%s': %s\n", filename, strerror(errno));
} else {
}
else{
do {
ssize_t written = write(fd, buffer, size);
if(written == -1){
@ -576,7 +516,6 @@ Sys_Save_File_Sig(system_save_file){
buffer += written;
}
} while(size);
close(fd);
}

View File

@ -9,6 +9,8 @@
// TOP
#define IS_PLAT_LAYER
#include "4tech_defines.h"
#include "4coder_API/version.h"

View File

@ -9,7 +9,97 @@
// TOP
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
struct Unix_Vars{
b32 do_logging;
};
static Unix_Vars unixvars;
//
// Logging
//
internal
Sys_Log_Sig(system_log){
if (unixvars.do_logging){
i32 fd = open("4coder_log.txt", O_WRONLY | O_CREAT, 00640);
if (fd >= 0){
do{
ssize_t written = write(fd, message, length);
if (written != -1){
length -= written;
message += written;
}
} while(length > 0);
close(fd);
}
}
}
//
// Memory
//
internal
Sys_Memory_Allocate_Sig(system_memory_allocate){
// NOTE(allen): This must return the exact base of the vpage.
// We will count on the user to keep track of size themselves.
void *result = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if(result == MAP_FAILED){
LOG("mmap failed\n");
result = NULL;
}
return(result);
}
internal
Sys_Memory_Set_Protection_Sig(system_memory_set_protection){
bool32 result = true;
int protect = 0;
switch (flags & 0x7){
case 0: protect = PROT_NONE; break;
case MemProtect_Read:
protect = PROT_READ; break;
case MemProtect_Write:
case MemProtect_Read|MemProtect_Write:
protect = PROT_READ | PROT_WRITE; break;
case MemProtect_Execute:
protect = PROT_EXEC; break;
case MemProtect_Execute|MemProtect_Read:
protect = PROT_READ | PROT_EXEC; break;
// NOTE(inso): some W^X protection things might be unhappy about this one
case MemProtect_Execute|MemProtect_Write:
case MemProtect_Execute|MemProtect_Write|MemProtect_Read:
protect = PROT_READ | PROT_WRITE | PROT_EXEC; break;
}
if(mprotect(ptr, size, protect) == -1){
result = 0;
LOG("mprotect");
}
return(result);
}
internal
Sys_Memory_Free_Sig(system_memory_free){
// NOTE(allen): This must take the exact base of the vpage.
munmap(ptr, size);
}
// BOTTOM

View File

@ -9,6 +9,8 @@
// TOP
#define IS_PLAT_LAYER
//
// Architecture cracking
//