1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/* date = December 6th 2025 2:34 pm */
#if !defined(OS_H)
#define OS_H
//~ Types
typedef struct entry_point_params entry_point_params;
struct entry_point_params
{
thread_context Context;
int ArgsCount;
char **Args;
char **Env;
};
typedef struct os_profiler os_profiler;
struct os_profiler
{
f64 Start;
f64 End;
};
typedef struct os_file_handle os_file_handle;
struct os_file_handle
{
u64 Handle;
};
typedef struct os_thread os_thread;
struct os_thread
{
void *Result;
entry_point_params Params;
};
//~ Globals
global_variable u8 LogBuffer[KB(64)];
global_variable os_profiler GlobalProfiler = {0};
global_variable char *GlobalProfilerPrefix = "";
#if BASE_PROFILE
global_variable b32 GlobalIsProfiling = true;
#else
global_variable b32 GlobalIsProfiling = false;
#endif
//~ Functions
#define ENTRY_POINT(Name) void *Name(entry_point_params *Params)
typedef ENTRY_POINT(entry_point_func);
C_LINKAGE ENTRY_POINT(EntryPoint);
#if OS_LINUX
# include "base_os_linux.h"
#endif
internal str8 OS_ReadEntireFileIntoMemory(char *FileName);
internal b32 OS_FileExists(char *FileName);
internal void OS_FreeFileMemory(str8 File);
internal b32 OS_WriteEntireFile(char *FileName, str8 File);
internal void OS_PrintFormat(char *Format, ...) PrintfFunc(1, 2);
internal void OS_BarrierWait(barrier Barrier);
internal void OS_SetThreadName(str8 ThreadName);
internal void *OS_AllocateAtOffset(u64 Size, u64 Offset);
internal void *OS_Allocate(u64 Size);
internal void OS_MarkReadonly(void *Memory, u64 Size);
internal void OS_BarrierWait(barrier Barrier);
internal f64 OS_GetWallClock(void);
internal void OS_Sleep(u32 MicroSeconds);
internal void OS_ChangeDirectory(char *Path);
//- OS agnostic, implemented in `base_os.c`.
internal f64 OS_SecondsElapsed(f64 Start, f64 End);
internal f64 OS_MSElapsed(f64 Start, f64 End);
internal void OS_ProfileInit(char *Prefix);
internal void OS_ProfileAndPrint(char *Label);
#define Log(Format, ...) OS_PrintFormat((char *)(Format), ##__VA_ARGS__)
// NOTE(luca): Append '\n', because this macro might be redefined into a visual error log.
#define ErrorLog(Format, ...) Log(ERROR_FMT Format "\n", ERROR_ARG, ##__VA_ARGS__)
#endif //OS_H
|