diff --git a/project.4coder b/project.4coder index 497a4b4f..d796d70e 100644 --- a/project.4coder +++ b/project.4coder @@ -49,7 +49,7 @@ commands = // .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, // .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg debug telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, // .f1 = { .win = "raddbg_stable --ipc kill_all && build radbin", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, - .f1 = { .win = "wsl ./build.sh raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, + .f1 = { .win = "build raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, //- rjf: [raddbg wsl] // .f1 = { .win = "wsl ./build.sh raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, diff --git a/src/base/base_arena.c b/src/base/base_arena.c index 626a66fd..e754399d 100644 --- a/src/base/base_arena.c +++ b/src/base/base_arena.c @@ -51,7 +51,7 @@ arena_alloc_(ArenaParams *params) #if OS_FEATURE_GRAPHICAL if(Unlikely(base == 0)) { - os_graphical_message(1, str8_lit("Fatal Allocation Failure"), str8_lit("Unexpected memory allocation failure.")); + wm_graphical_message(1, str8_lit("Fatal Allocation Failure"), str8_lit("Unexpected memory allocation failure.")); abort_self(1); } #endif @@ -212,7 +212,7 @@ arena_push(Arena *arena, U64 size, U64 align, B32 zero) #if OS_FEATURE_GRAPHICAL if(Unlikely(result == 0)) { - os_graphical_message(1, str8_lit("Fatal Allocation Failure"), str8_lit("Unexpected memory allocation failure.")); + wm_graphical_message(1, str8_lit("Fatal Allocation Failure"), str8_lit("Unexpected memory allocation failure.")); abort_self(1); } #endif diff --git a/src/base/base_entry_point.c b/src/base/base_entry_point.c index 327e0a33..f7fdcf22 100644 --- a/src/base/base_entry_point.c +++ b/src/base/base_entry_point.c @@ -78,8 +78,8 @@ main_thread_base_entry_point(int arguments_count, char **arguments) #if defined(DBG_ENGINE_CORE_H) && !defined(D_INIT_MANUAL) d_init(); #endif -#if defined(OS_GFX_H) && !defined(OS_GFX_INIT_MANUAL) - os_gfx_init(); +#if defined(WINDOW_MANAGER_H) && !defined(WM_INIT_MANUAL) + wm_init(); #endif #if defined(FONT_PROVIDER_H) && !defined(FP_INIT_MANUAL) fp_init(); diff --git a/src/config/config_bindings.c b/src/config/config_bindings.c index 5d95b3a7..87315dba 100644 --- a/src/config/config_bindings.c +++ b/src/config/config_bindings.c @@ -24,21 +24,21 @@ cfg_key_map_from_cfg(Arena *arena) for(CFG_Node *child = keybinding->first; child != &cfg_nil_node; child = child->next) { if(0){} - else if(str8_match(child->string, str8_lit("ctrl"), 0)) { binding.modifiers |= OS_Modifier_Ctrl; } - else if(str8_match(child->string, str8_lit("alt"), 0)) { binding.modifiers |= OS_Modifier_Alt; } - else if(str8_match(child->string, str8_lit("shift"), 0)) { binding.modifiers |= OS_Modifier_Shift; } + else if(str8_match(child->string, str8_lit("ctrl"), 0)) { binding.modifiers |= WM_Modifier_Ctrl; } + else if(str8_match(child->string, str8_lit("alt"), 0)) { binding.modifiers |= WM_Modifier_Alt; } + else if(str8_match(child->string, str8_lit("shift"), 0)) { binding.modifiers |= WM_Modifier_Shift; } else { - OS_Key key = OS_Key_Null; - for EachEnumVal(OS_Key, k) + WM_Key key = WM_Key_Null; + for EachEnumVal(WM_Key, k) { - if(str8_match(child->string, os_g_key_cfg_string_table[k], StringMatchFlag_CaseInsensitive)) + if(str8_match(child->string, wm_key_cfg_name_table[k], StringMatchFlag_CaseInsensitive)) { key = k; break; } } - if(key != OS_Key_Null) + if(key != WM_Key_Null) { binding.key = key; } diff --git a/src/config/config_bindings.h b/src/config/config_bindings.h index 8bb875e3..4b283447 100644 --- a/src/config/config_bindings.h +++ b/src/config/config_bindings.h @@ -7,8 +7,8 @@ typedef struct CFG_Binding CFG_Binding; struct CFG_Binding { - OS_Key key; - OS_Modifiers modifiers; + WM_Key key; + WM_Modifiers modifiers; }; typedef struct CFG_KeyMapNode CFG_KeyMapNode; diff --git a/src/config/config_inc.c b/src/config/config_inc.c index f927a51d..e0820d64 100644 --- a/src/config/config_inc.c +++ b/src/config/config_inc.c @@ -3,6 +3,6 @@ #include "config_core.c" #include "config_panels.c" -#if defined(OS_GFX_H) +#if defined(WINDOW_MANAGER_H) # include "config_bindings.c" #endif diff --git a/src/config/config_inc.h b/src/config/config_inc.h index 0460d200..141e22ca 100644 --- a/src/config/config_inc.h +++ b/src/config/config_inc.h @@ -6,7 +6,7 @@ #include "config_core.h" #include "config_panels.h" -#if defined(OS_GFX_H) +#if defined(WINDOW_MANAGER_H) # include "config_bindings.h" #endif diff --git a/src/draw/draw.c b/src/draw/draw.c index 7ba72da1..517cad79 100644 --- a/src/draw/draw.c +++ b/src/draw/draw.c @@ -226,7 +226,7 @@ dr_begin_frame(FNT_Tag icon_font) } internal void -dr_submit_bucket(OS_Window os_window, R_Handle r_window, DR_Bucket *bucket) +dr_submit_bucket(WM_Window os_window, R_Handle r_window, DR_Bucket *bucket) { r_window_submit(os_window, r_window, &bucket->passes); } diff --git a/src/draw/draw.h b/src/draw/draw.h index c4ab7ab2..a971b6ad 100644 --- a/src/draw/draw.h +++ b/src/draw/draw.h @@ -134,7 +134,7 @@ internal Vec2F32 dr_dim_from_fstrs(F32 tab_size_px, DR_FStrList *fstrs); // (Frame boundaries & bucket submission) internal void dr_begin_frame(FNT_Tag icon_font); -internal void dr_submit_bucket(OS_Window os_window, R_Handle r_window, DR_Bucket *bucket); +internal void dr_submit_bucket(WM_Window os_window, R_Handle r_window, DR_Bucket *bucket); //////////////////////////////// //~ rjf: Bucket Construction & Selection API diff --git a/src/linux/base/linux_base.c b/src/linux/base/linux_base.c index eb4fb355..c4e31087 100644 --- a/src/linux/base/linux_base.c +++ b/src/linux/base/linux_base.c @@ -71,7 +71,7 @@ os_lnx_file_properties_from_stat(struct stat *s) internal void os_lnx_safe_call_sig_handler(int x) { - OS_LNX_SafeCallChain *chain = os_lnx_safe_call_chain; + LNX_SafeCallChain *chain = os_lnx_safe_call_chain; if(chain != 0 && chain->fail_handler != 0) { chain->fail_handler(chain->ptr); @@ -82,10 +82,10 @@ os_lnx_safe_call_sig_handler(int x) //////////////////////////////// //~ rjf: Entities -internal OS_LNX_Entity * -os_lnx_entity_alloc(OS_LNX_EntityKind kind) +internal LNX_Entity * +os_lnx_entity_alloc(LNX_EntityKind kind) { - OS_LNX_Entity *entity = 0; + LNX_Entity *entity = 0; DeferLoop(pthread_mutex_lock(&os_lnx_state.entity_mutex), pthread_mutex_unlock(&os_lnx_state.entity_mutex)) { @@ -96,7 +96,7 @@ os_lnx_entity_alloc(OS_LNX_EntityKind kind) } else { - entity = push_array_no_zero(os_lnx_state.entity_arena, OS_LNX_Entity, 1); + entity = push_array_no_zero(os_lnx_state.entity_arena, LNX_Entity, 1); } } MemoryZeroStruct(entity); @@ -105,7 +105,7 @@ os_lnx_entity_alloc(OS_LNX_EntityKind kind) } internal void -os_lnx_entity_release(OS_LNX_Entity *entity) +os_lnx_entity_release(LNX_Entity *entity) { DeferLoop(pthread_mutex_lock(&os_lnx_state.entity_mutex), pthread_mutex_unlock(&os_lnx_state.entity_mutex)) @@ -120,7 +120,7 @@ os_lnx_entity_release(OS_LNX_Entity *entity) internal void * os_lnx_thread_entry_point(void *ptr) { - OS_LNX_Entity *entity = (OS_LNX_Entity *)ptr; + LNX_Entity *entity = (LNX_Entity *)ptr; ThreadEntryPointFunctionType *func = entity->thread.func; void *thread_ptr = entity->thread.ptr; supplement_thread_base_entry_point(func, thread_ptr); @@ -353,7 +353,7 @@ set_platform_thread_name(String8 name) internal Thread thread_launch(ThreadEntryPointFunctionType *f, void *p) { - OS_LNX_Entity *entity = os_lnx_entity_alloc(OS_LNX_EntityKind_Thread); + LNX_Entity *entity = os_lnx_entity_alloc(LNX_EntityKind_Thread); entity->thread.func = f; entity->thread.ptr = p; { @@ -372,7 +372,7 @@ internal B32 thread_join(Thread thread, U64 endt_us) { if(MemoryIsZeroStruct(&thread)) { return 0; } - OS_LNX_Entity *entity = (OS_LNX_Entity *)thread.u64[0]; + LNX_Entity *entity = (LNX_Entity *)thread.u64[0]; int join_result = pthread_join(entity->thread.handle, 0); B32 result = (join_result == 0); os_lnx_entity_release(entity); @@ -383,7 +383,7 @@ internal void thread_detach(Thread thread) { if(MemoryIsZeroStruct(&thread)) { return; } - OS_LNX_Entity *entity = (OS_LNX_Entity *)thread.u64[0]; + LNX_Entity *entity = (LNX_Entity *)thread.u64[0]; os_lnx_entity_release(entity); } @@ -395,7 +395,7 @@ thread_detach(Thread thread) internal Mutex mutex_alloc(void) { - OS_LNX_Entity *entity = os_lnx_entity_alloc(OS_LNX_EntityKind_Mutex); + LNX_Entity *entity = os_lnx_entity_alloc(LNX_EntityKind_Mutex); int init_result = pthread_mutex_init(&entity->mutex_handle, 0); if(init_result == -1) { @@ -410,7 +410,7 @@ internal void mutex_release(Mutex mutex) { if(MemoryIsZeroStruct(&mutex)) { return; } - OS_LNX_Entity *entity = (OS_LNX_Entity *)mutex.u64[0]; + LNX_Entity *entity = (LNX_Entity *)mutex.u64[0]; pthread_mutex_destroy(&entity->mutex_handle); os_lnx_entity_release(entity); } @@ -419,7 +419,7 @@ internal void mutex_take(Mutex mutex) { if(MemoryIsZeroStruct(&mutex)) { return; } - OS_LNX_Entity *entity = (OS_LNX_Entity *)mutex.u64[0]; + LNX_Entity *entity = (LNX_Entity *)mutex.u64[0]; pthread_mutex_lock(&entity->mutex_handle); } @@ -427,7 +427,7 @@ internal void mutex_drop(Mutex mutex) { if(MemoryIsZeroStruct(&mutex)) { return; } - OS_LNX_Entity *entity = (OS_LNX_Entity *)mutex.u64[0]; + LNX_Entity *entity = (LNX_Entity *)mutex.u64[0]; pthread_mutex_unlock(&entity->mutex_handle); } @@ -436,7 +436,7 @@ mutex_drop(Mutex mutex) internal RWMutex rw_mutex_alloc(void) { - OS_LNX_Entity *entity = os_lnx_entity_alloc(OS_LNX_EntityKind_RWMutex); + LNX_Entity *entity = os_lnx_entity_alloc(LNX_EntityKind_RWMutex); int init_result = pthread_rwlock_init(&entity->rwmutex_handle, 0); if(init_result == -1) { @@ -451,7 +451,7 @@ internal void rw_mutex_release(RWMutex mutex) { if(MemoryIsZeroStruct(&mutex)) { return; } - OS_LNX_Entity *entity = (OS_LNX_Entity *)mutex.u64[0]; + LNX_Entity *entity = (LNX_Entity *)mutex.u64[0]; pthread_rwlock_destroy(&entity->rwmutex_handle); os_lnx_entity_release(entity); } @@ -460,7 +460,7 @@ internal void rw_mutex_take(RWMutex mutex, B32 write_mode) { if(MemoryIsZeroStruct(&mutex)) { return; } - OS_LNX_Entity *entity = (OS_LNX_Entity *)mutex.u64[0]; + LNX_Entity *entity = (LNX_Entity *)mutex.u64[0]; if(write_mode) { pthread_rwlock_wrlock(&entity->rwmutex_handle); @@ -475,7 +475,7 @@ internal void rw_mutex_drop(RWMutex mutex, B32 write_mode) { if(MemoryIsZeroStruct(&mutex)) { return; } - OS_LNX_Entity *entity = (OS_LNX_Entity *)mutex.u64[0]; + LNX_Entity *entity = (LNX_Entity *)mutex.u64[0]; pthread_rwlock_unlock(&entity->rwmutex_handle); } @@ -484,7 +484,7 @@ rw_mutex_drop(RWMutex mutex, B32 write_mode) internal CondVar cond_var_alloc(void) { - OS_LNX_Entity *entity = os_lnx_entity_alloc(OS_LNX_EntityKind_ConditionVariable); + LNX_Entity *entity = os_lnx_entity_alloc(LNX_EntityKind_ConditionVariable); int init_result = pthread_cond_init(&entity->cv.cond_handle, 0); if(init_result == -1) { @@ -510,7 +510,7 @@ internal void cond_var_release(CondVar cv) { if(MemoryIsZeroStruct(&cv)) { return; } - OS_LNX_Entity *entity = (OS_LNX_Entity *)cv.u64[0]; + LNX_Entity *entity = (LNX_Entity *)cv.u64[0]; pthread_cond_destroy(&entity->cv.cond_handle); pthread_mutex_destroy(&entity->cv.rwlock_mutex_handle); os_lnx_entity_release(entity); @@ -521,8 +521,8 @@ cond_var_wait(CondVar cv, Mutex mutex, U64 endt_us) { if(MemoryIsZeroStruct(&cv)) { return 0; } if(MemoryIsZeroStruct(&mutex)) { return 0; } - OS_LNX_Entity *cv_entity = (OS_LNX_Entity *)cv.u64[0]; - OS_LNX_Entity *mutex_entity = (OS_LNX_Entity *)mutex.u64[0]; + LNX_Entity *cv_entity = (LNX_Entity *)cv.u64[0]; + LNX_Entity *mutex_entity = (LNX_Entity *)mutex.u64[0]; struct timespec endt_timespec; endt_timespec.tv_sec = endt_us/Million(1); endt_timespec.tv_nsec = Thousand(1) * (endt_us - (endt_us/Million(1))*Million(1)); @@ -540,8 +540,8 @@ cond_var_wait_rw(CondVar cv, RWMutex mutex_rw, B32 write_mode, U64 endt_us) // if(MemoryIsZeroStruct(&cv)) { return 0; } if(MemoryIsZeroStruct(&mutex_rw)) { return 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]; + LNX_Entity *cv_entity = (LNX_Entity *)cv.u64[0]; + LNX_Entity *rw_mutex_entity = (LNX_Entity *)mutex_rw.u64[0]; struct timespec endt_timespec; endt_timespec.tv_sec = endt_us/Million(1); endt_timespec.tv_nsec = Thousand(1) * (endt_us - (endt_us/Million(1))*Million(1)); @@ -585,7 +585,7 @@ internal void cond_var_signal(CondVar cv) { if(MemoryIsZeroStruct(&cv)) { return; } - OS_LNX_Entity *cv_entity = (OS_LNX_Entity *)cv.u64[0]; + LNX_Entity *cv_entity = (LNX_Entity *)cv.u64[0]; pthread_cond_signal(&cv_entity->cv.cond_handle); } @@ -593,7 +593,7 @@ internal void cond_var_broadcast(CondVar cv) { if(MemoryIsZeroStruct(&cv)) { return; } - OS_LNX_Entity *cv_entity = (OS_LNX_Entity *)cv.u64[0]; + LNX_Entity *cv_entity = (LNX_Entity *)cv.u64[0]; pthread_cond_broadcast(&cv_entity->cv.cond_handle); } @@ -713,7 +713,7 @@ semaphore_drop(Semaphore semaphore) internal Barrier barrier_alloc(U64 count) { - OS_LNX_Entity *entity = os_lnx_entity_alloc(OS_LNX_EntityKind_Barrier); + LNX_Entity *entity = os_lnx_entity_alloc(LNX_EntityKind_Barrier); if(entity != 0) { pthread_barrier_init(&entity->barrier, 0, count); @@ -725,7 +725,7 @@ barrier_alloc(U64 count) internal void barrier_release(Barrier barrier) { - OS_LNX_Entity *entity = (OS_LNX_Entity*)PtrFromInt(barrier.u64[0]); + LNX_Entity *entity = (LNX_Entity*)PtrFromInt(barrier.u64[0]); if(entity != 0) { pthread_barrier_destroy(&entity->barrier); @@ -736,7 +736,7 @@ barrier_release(Barrier barrier) internal void barrier_wait(Barrier barrier) { - OS_LNX_Entity *entity = (OS_LNX_Entity*)PtrFromInt(barrier.u64[0]); + LNX_Entity *entity = (LNX_Entity*)PtrFromInt(barrier.u64[0]); if(entity != 0) { pthread_barrier_wait(&entity->barrier); @@ -750,7 +750,7 @@ internal void safe_call(ThreadEntryPointFunctionType *func, ThreadEntryPointFunctionType *fail_handler, void *ptr) { // rjf: push handler to chain - OS_LNX_SafeCallChain chain = {0}; + LNX_SafeCallChain chain = {0}; SLLStackPush(os_lnx_safe_call_chain, &chain); chain.fail_handler = fail_handler; chain.ptr = ptr; @@ -1088,7 +1088,7 @@ file_iter_begin(Arena *arena, String8 path, FileIterFlags flags) { FileIter *base_iter = push_array(arena, FileIter, 1); base_iter->flags = flags; - OS_LNX_FileIter *iter = (OS_LNX_FileIter *)base_iter->memory; + LNX_FileIter *iter = (LNX_FileIter *)base_iter->memory; { String8 path_copy = push_str8_copy(arena, path); iter->dir = opendir((char *)path_copy.str); @@ -1101,7 +1101,7 @@ internal B32 file_iter_next(Arena *arena, FileIter *iter, FileInfo *info_out) { B32 good = 0; - OS_LNX_FileIter *lnx_iter = (OS_LNX_FileIter *)iter->memory; + LNX_FileIter *lnx_iter = (LNX_FileIter *)iter->memory; for(;lnx_iter->dir != 0;) { // rjf: get next entry @@ -1152,7 +1152,7 @@ file_iter_next(Arena *arena, FileIter *iter, FileInfo *info_out) internal void file_iter_end(FileIter *iter) { - OS_LNX_FileIter *lnx_iter = (OS_LNX_FileIter *)iter->memory; + LNX_FileIter *lnx_iter = (LNX_FileIter *)iter->memory; closedir(lnx_iter->dir); } diff --git a/src/linux/base/linux_base.h b/src/linux/base/linux_base.h index a4b069da..b78cbdc3 100644 --- a/src/linux/base/linux_base.h +++ b/src/linux/base/linux_base.h @@ -41,7 +41,7 @@ typedef struct timespec timespec; //////////////////////////////// //~ rjf: Linux Call Interruption Retry Helper -#define OS_LNX_RETRY_ON_EINTR(expr) \ +#define LNX_RETRY_ON_EINTR(expr) \ (__extension__({ \ __typeof__(expr) __ret; \ do { \ @@ -54,22 +54,22 @@ __ret; \ //////////////////////////////// //~ rjf: File Iterator -typedef struct OS_LNX_FileIter OS_LNX_FileIter; -struct OS_LNX_FileIter +typedef struct LNX_FileIter LNX_FileIter; +struct LNX_FileIter { DIR *dir; struct dirent *dp; String8 path; }; -StaticAssert(sizeof(Member(FileIter, memory)) >= sizeof(OS_LNX_FileIter), os_lnx_file_iter_size_check); +StaticAssert(sizeof(Member(FileIter, memory)) >= sizeof(LNX_FileIter), os_lnx_file_iter_size_check); //////////////////////////////// //~ rjf: Safe Call Handler Chain -typedef struct OS_LNX_SafeCallChain OS_LNX_SafeCallChain; -struct OS_LNX_SafeCallChain +typedef struct LNX_SafeCallChain LNX_SafeCallChain; +struct LNX_SafeCallChain { - OS_LNX_SafeCallChain *next; + LNX_SafeCallChain *next; ThreadEntryPointFunctionType *fail_handler; void *ptr; }; @@ -77,21 +77,21 @@ struct OS_LNX_SafeCallChain //////////////////////////////// //~ rjf: Entities -typedef enum OS_LNX_EntityKind +typedef enum LNX_EntityKind { - OS_LNX_EntityKind_Thread, - OS_LNX_EntityKind_Mutex, - OS_LNX_EntityKind_RWMutex, - OS_LNX_EntityKind_ConditionVariable, - OS_LNX_EntityKind_Barrier, + LNX_EntityKind_Thread, + LNX_EntityKind_Mutex, + LNX_EntityKind_RWMutex, + LNX_EntityKind_ConditionVariable, + LNX_EntityKind_Barrier, } -OS_LNX_EntityKind; +LNX_EntityKind; -typedef struct OS_LNX_Entity OS_LNX_Entity; -struct OS_LNX_Entity +typedef struct LNX_Entity LNX_Entity; +struct LNX_Entity { - OS_LNX_Entity *next; - OS_LNX_EntityKind kind; + LNX_Entity *next; + LNX_EntityKind kind; union { struct @@ -114,15 +114,15 @@ struct OS_LNX_Entity //////////////////////////////// //~ rjf: State -typedef struct OS_LNX_State OS_LNX_State; -struct OS_LNX_State +typedef struct LNX_State LNX_State; +struct LNX_State { Arena *arena; SystemInfo system_info; ProcessInfo process_info; pthread_mutex_t entity_mutex; Arena *entity_arena; - OS_LNX_Entity *entity_free; + LNX_Entity *entity_free; U64 default_env_count; char **default_env; }; @@ -130,8 +130,8 @@ struct OS_LNX_State //////////////////////////////// //~ rjf: Globals -global OS_LNX_State os_lnx_state = {0}; -thread_static OS_LNX_SafeCallChain *os_lnx_safe_call_chain = 0; +global LNX_State os_lnx_state = {0}; +thread_static LNX_SafeCallChain *os_lnx_safe_call_chain = 0; //////////////////////////////// //~ rjf: Helpers @@ -146,8 +146,8 @@ internal void os_lnx_safe_call_sig_handler(int x); //////////////////////////////// //~ rjf: Entities -internal OS_LNX_Entity *os_lnx_entity_alloc(OS_LNX_EntityKind kind); -internal void os_lnx_entity_release(OS_LNX_Entity *entity); +internal LNX_Entity *os_lnx_entity_alloc(LNX_EntityKind kind); +internal void os_lnx_entity_release(LNX_Entity *entity); //////////////////////////////// //~ rjf: Thread Entry Point diff --git a/src/linux/demon/linux_demon.c b/src/linux/demon/linux_demon.c index 6c1767dc..0503c2de 100644 --- a/src/linux/demon/linux_demon.c +++ b/src/linux/demon/linux_demon.c @@ -11,13 +11,13 @@ //////////////////////////////// internal U64 -dmn_lnx_size_from_fd(int memory_fd, U64 cap) +lnx_dmn_size_from_fd(int memory_fd, U64 cap) { U8 temp[4096]; size_t cursor = 0; while(cursor < cap) { - ssize_t actual_read = OS_LNX_RETRY_ON_EINTR(pread(memory_fd, temp, sizeof(temp), cursor)); + ssize_t actual_read = LNX_RETRY_ON_EINTR(pread(memory_fd, temp, sizeof(temp), cursor)); if(actual_read <= 0) { break; } cursor += (U64)actual_read; } @@ -25,13 +25,13 @@ dmn_lnx_size_from_fd(int memory_fd, U64 cap) } internal U64 -dmn_lnx_read(int memory_fd, Rng1U64 range, void *dst) +lnx_dmn_read(int memory_fd, Rng1U64 range, void *dst) { size_t cursor = 0, size = dim_1u64(range); while(cursor < size) { size_t to_read = size - cursor; - ssize_t actual_read = OS_LNX_RETRY_ON_EINTR(pread(memory_fd, (U8 *)dst + cursor, to_read, range.min + cursor)); + ssize_t actual_read = LNX_RETRY_ON_EINTR(pread(memory_fd, (U8 *)dst + cursor, to_read, range.min + cursor)); if(actual_read < 0) { break; } if(actual_read == 0) { break; } cursor += actual_read; @@ -40,13 +40,13 @@ dmn_lnx_read(int memory_fd, Rng1U64 range, void *dst) } internal B32 -dmn_lnx_write(int memory_fd, Rng1U64 range, void *src) +lnx_dmn_write(int memory_fd, Rng1U64 range, void *src) { size_t cursor = 0, size = dim_1u64(range); while(cursor < size) { size_t to_write = size - cursor; - ssize_t actual_write = OS_LNX_RETRY_ON_EINTR(pwrite(memory_fd, (U8 *)src + cursor, to_write, range.min + cursor)); + ssize_t actual_write = LNX_RETRY_ON_EINTR(pwrite(memory_fd, (U8 *)src + cursor, to_write, range.min + cursor)); if(actual_write <= 0) { break; } cursor += actual_write; } @@ -55,14 +55,14 @@ dmn_lnx_write(int memory_fd, Rng1U64 range, void *src) } internal String8 -dmn_lnx_read_string_capped(Arena *arena, int memory_fd, U64 base_vaddr, U64 cap_size) +lnx_dmn_read_string_capped(Arena *arena, int memory_fd, U64 base_vaddr, U64 cap_size) { String8 result = {0}; U64 string_size = 0; for(U64 vaddr = base_vaddr; string_size < cap_size; vaddr += 1, string_size += 1) { char byte = 0; - if(OS_LNX_RETRY_ON_EINTR(pread(memory_fd, &byte, sizeof(byte), vaddr) <= 0)) + if(LNX_RETRY_ON_EINTR(pread(memory_fd, &byte, sizeof(byte), vaddr) <= 0)) { break; } @@ -74,7 +74,7 @@ dmn_lnx_read_string_capped(Arena *arena, int memory_fd, U64 base_vaddr, U64 cap_ if(string_size != 0) { char *buf = push_array_no_zero(arena, char, string_size+1); - OS_LNX_RETRY_ON_EINTR(pread(memory_fd, buf, string_size, base_vaddr)); + LNX_RETRY_ON_EINTR(pread(memory_fd, buf, string_size, base_vaddr)); buf[string_size] = '\0'; result = str8((U8 *)buf, string_size); } @@ -82,27 +82,27 @@ dmn_lnx_read_string_capped(Arena *arena, int memory_fd, U64 base_vaddr, U64 cap_ } internal String8 -dmn_lnx_read_string(Arena *arena, int memory_fd, U64 vaddr) +lnx_dmn_read_string(Arena *arena, int memory_fd, U64 vaddr) { - return dmn_lnx_read_string_capped(arena, memory_fd, vaddr, 4096); + return lnx_dmn_read_string_capped(arena, memory_fd, vaddr, 4096); } internal -MACHINE_OP_MEM_READ(dmn_lnx_machine_op_mem_read) +MACHINE_OP_MEM_READ(lnx_dmn_machine_op_mem_read) { - U64 read_size = dmn_lnx_read(*(int *)ud, r1u64(addr, addr + buffer_size), buffer); + U64 read_size = lnx_dmn_read(*(int *)ud, r1u64(addr, addr + buffer_size), buffer); return read_size == buffer_size ? MachineOpResult_Ok : MachineOpResult_Fail; } internal int -dmn_lnx_ptrace_seize(pid_t pid) +lnx_dmn_ptrace_seize(pid_t pid) { // TODO: PTRACE_O_TRACEVFORK | PTRACE_O_TRACEVFORKDONE | PTRACE_O_TRACEFORK - return OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_SEIZE, pid, 0, PTRACE_O_TRACEEXEC | PTRACE_O_EXITKILL | PTRACE_O_TRACECLONE)); + return LNX_RETRY_ON_EINTR(ptrace(PTRACE_SEIZE, pid, 0, PTRACE_O_TRACEEXEC | PTRACE_O_EXITKILL | PTRACE_O_TRACECLONE)); } internal String8 -dmn_lnx_exe_path_from_pid(Arena *arena, pid_t pid) +lnx_dmn_exe_path_from_pid(Arena *arena, pid_t pid) { Temp scratch = scratch_begin(&arena, 1); @@ -133,19 +133,19 @@ dmn_lnx_exe_path_from_pid(Arena *arena, pid_t pid) } internal String8 -dmn_lnx_dl_path_from_pid(Arena *arena, pid_t pid, U64 auxv_base) +lnx_dmn_dl_path_from_pid(Arena *arena, pid_t pid, U64 auxv_base) { Temp scratch = scratch_begin(&arena, 1); String8 dl_path = {0}; - int maps_fd = OS_LNX_RETRY_ON_EINTR(open((char *)str8f(scratch.arena, "/proc/%d/maps", pid).str, O_RDONLY)); + int maps_fd = LNX_RETRY_ON_EINTR(open((char *)str8f(scratch.arena, "/proc/%d/maps", pid).str, O_RDONLY)); if(maps_fd != -1) { // read entire /proc/pid/maps - U64 maps_size = dmn_lnx_size_from_fd(maps_fd, MB(1)); + U64 maps_size = lnx_dmn_size_from_fd(maps_fd, MB(1)); U8 *maps_ptr = push_array(scratch.arena, U8, maps_size); - U64 read_size = dmn_lnx_read(maps_fd, r1u64(0, maps_size), maps_ptr); + U64 read_size = lnx_dmn_read(maps_fd, r1u64(0, maps_size), maps_ptr); // split map file on lines String8List lines = str8_split_by_string_chars(scratch.arena, str8(maps_ptr, maps_size), str8_lit("\n"), 0); @@ -195,7 +195,7 @@ dmn_lnx_dl_path_from_pid(Arena *arena, pid_t pid, U64 auxv_base) } } - OS_LNX_RETRY_ON_EINTR(close(maps_fd)); + LNX_RETRY_ON_EINTR(close(maps_fd)); } else { Assert(0 && "failed to open DL fd"); } @@ -205,7 +205,7 @@ dmn_lnx_dl_path_from_pid(Arena *arena, pid_t pid, U64 auxv_base) } internal ELF_Hdr64 -dmn_lnx_ehdr_from_pid(pid_t pid) +lnx_dmn_ehdr_from_pid(pid_t pid) { Temp scratch = scratch_begin(0, 0); @@ -213,12 +213,12 @@ dmn_lnx_ehdr_from_pid(pid_t pid) B32 is_read = 0; char *exe_path = (char *)str8f(scratch.arena, "/proc/%d/exe", pid).str; - int exe_fd = OS_LNX_RETRY_ON_EINTR(open(exe_path, O_RDONLY)); + int exe_fd = LNX_RETRY_ON_EINTR(open(exe_path, O_RDONLY)); if(exe_fd >= 0) { - is_read = elf_read_ehdr(dmn_lnx_machine_op_mem_read, &exe_fd, 0, &exe); - OS_LNX_RETRY_ON_EINTR(close(exe_fd)); + is_read = elf_read_ehdr(lnx_dmn_machine_op_mem_read, &exe_fd, 0, &exe); + LNX_RETRY_ON_EINTR(close(exe_fd)); } Assert(is_read); @@ -226,15 +226,15 @@ dmn_lnx_ehdr_from_pid(pid_t pid) return exe; } -internal DMN_LNX_Auxv -dmn_lnx_auxv_from_pid(pid_t pid, ELF_Class elf_class) +internal LNX_DMN_Auxv +lnx_dmn_auxv_from_pid(pid_t pid, ELF_Class elf_class) { Temp scratch = scratch_begin(0, 0); - DMN_LNX_Auxv result = {0}; + LNX_DMN_Auxv result = {0}; // rjf: open aux data String8 auxv_path = str8f(scratch.arena, "/proc/%d/auxv", pid); - int auxv_fd = OS_LNX_RETRY_ON_EINTR(open((char *)auxv_path.str, O_RDONLY)); + int auxv_fd = LNX_RETRY_ON_EINTR(open((char *)auxv_path.str, O_RDONLY)); // rjf: scan aux data if(auxv_fd >= 0) @@ -273,34 +273,34 @@ dmn_lnx_auxv_from_pid(pid_t pid, ELF_Class elf_class) } } brkloop:; - OS_LNX_RETRY_ON_EINTR(close(auxv_fd)); + LNX_RETRY_ON_EINTR(close(auxv_fd)); } scratch_end(scratch); return result; } -internal DMN_LNX_Thread * -dmn_lnx_thread_from_pid(pid_t tid) +internal LNX_DMN_Thread * +lnx_dmn_thread_from_pid(pid_t tid) { - return hash_table_search_u64_raw(dmn_lnx_state->tid_ht, tid); + return hash_table_search_u64_raw(lnx_dmn_state->tid_ht, tid); } -internal DMN_LNX_Process * -dmn_lnx_process_from_pid(pid_t pid) +internal LNX_DMN_Process * +lnx_dmn_process_from_pid(pid_t pid) { - return hash_table_search_u64_raw(dmn_lnx_state->pid_ht, pid); + return hash_table_search_u64_raw(lnx_dmn_state->pid_ht, pid); } internal Rng1U64 -dmn_lnx_compute_image_vrange(int memory_fd, ELF_Class elf_class, U64 rebase, U64 e_phaddr, U64 e_phentsize, U64 e_phnum) +lnx_dmn_compute_image_vrange(int memory_fd, ELF_Class elf_class, U64 rebase, U64 e_phaddr, U64 e_phentsize, U64 e_phnum) { Rng1U64 result = { .min = max_U64 }; for(U64 ph_cursor = e_phaddr, ph_opl = (e_phaddr + e_phentsize * e_phnum); ph_cursor < ph_opl; ph_cursor += e_phentsize) { ELF_Phdr64 phdr = {0}; - if(elf_read_phdr(dmn_lnx_machine_op_mem_read, &memory_fd, ph_cursor, elf_class, &phdr) != MachineOpResult_Ok) + if(elf_read_phdr(lnx_dmn_machine_op_mem_read, &memory_fd, ph_cursor, elf_class, &phdr) != MachineOpResult_Ok) { Assert(0 && "unable to read a program header"); } @@ -317,15 +317,15 @@ dmn_lnx_compute_image_vrange(int memory_fd, ELF_Class elf_class, U64 rebase, U64 return result; } -internal DMN_LNX_DynamicInfo -dmn_lnx_dynamic_info_from_memory(int memory_fd, ELF_Class elf_class, U64 rebase, U64 dynamic_vaddr) +internal LNX_DMN_DynamicInfo +lnx_dmn_dynamic_info_from_memory(int memory_fd, ELF_Class elf_class, U64 rebase, U64 dynamic_vaddr) { - DMN_LNX_DynamicInfo dynamic_info = {0}; + LNX_DMN_DynamicInfo dynamic_info = {0}; for(U64 dynamic_cursor = dynamic_vaddr; ; dynamic_cursor += elf_dyn_size_from_class(elf_class)) { // rjf: read next dyn entry ELF_Dyn64 dyn = {0}; - if(elf_read_dyn(dmn_lnx_machine_op_mem_read, &memory_fd, dynamic_cursor, elf_class, &dyn) != MachineOpResult_Ok) { Assert(0 && "unable to read dynamic"); } + if(elf_read_dyn(lnx_dmn_machine_op_mem_read, &memory_fd, dynamic_cursor, elf_class, &dyn) != MachineOpResult_Ok) { Assert(0 && "unable to read dynamic"); } // rjf: break on zero if(dyn.tag == ELF_DynTag_Null) { break; } @@ -360,14 +360,14 @@ dmn_lnx_dynamic_info_from_memory(int memory_fd, ELF_Class elf_class, U64 rebase, } internal U64 -dmn_lnx_find_dynamic_phdr(int memory_fd, ELF_Class elf_class, U64 rebase, U64 e_phaddr, U64 e_phentsize, U64 e_phnum) +lnx_dmn_find_dynamic_phdr(int memory_fd, ELF_Class elf_class, U64 rebase, U64 e_phaddr, U64 e_phentsize, U64 e_phnum) { U64 result = max_U64; for(U64 ph_cursor = e_phaddr, ph_opl = (e_phaddr + e_phentsize * e_phnum); ph_cursor < ph_opl; ph_cursor += e_phentsize) { ELF_Phdr64 phdr = {0}; - if(elf_read_phdr(dmn_lnx_machine_op_mem_read, &memory_fd, ph_cursor, elf_class, &phdr) != MachineOpResult_Ok) + if(elf_read_phdr(lnx_dmn_machine_op_mem_read, &memory_fd, ph_cursor, elf_class, &phdr) != MachineOpResult_Ok) { Assert(0 && "unable to read a program header"); } @@ -383,7 +383,7 @@ dmn_lnx_find_dynamic_phdr(int memory_fd, ELF_Class elf_class, U64 rebase, U64 e_ } internal U64 -dmn_lnx_rdebug_vaddr_from_memory(int memory_fd, U64 loader_vbase, B32 is_rebased) +lnx_dmn_rdebug_vaddr_from_memory(int memory_fd, U64 loader_vbase, B32 is_rebased) { Temp scratch = scratch_begin(0, 0); @@ -391,18 +391,18 @@ dmn_lnx_rdebug_vaddr_from_memory(int memory_fd, U64 loader_vbase, B32 is_rebased // load DL's header ELF_Hdr64 ehdr = {0}; - if(elf_read_ehdr(dmn_lnx_machine_op_mem_read, &memory_fd, loader_vbase, &ehdr) != MachineOpResult_Ok) { Assert(0 && "failed to read interp's header"); goto exit; } + if(elf_read_ehdr(lnx_dmn_machine_op_mem_read, &memory_fd, loader_vbase, &ehdr) != MachineOpResult_Ok) { Assert(0 && "failed to read interp's header"); goto exit; } U64 rebase = ehdr.e_type == ELF_Type_Dyn ? loader_vbase : 0; ELF_Class elf_class = ehdr.e_ident[ELF_Identifier_Class]; // find dynamic program header U64 phdr_vaddr = loader_vbase + ehdr.e_phoff; - U64 dynamic_vaddr = dmn_lnx_find_dynamic_phdr(memory_fd, elf_class, rebase, phdr_vaddr, ehdr.e_phentsize, ehdr.e_phentsize); + U64 dynamic_vaddr = lnx_dmn_find_dynamic_phdr(memory_fd, elf_class, rebase, phdr_vaddr, ehdr.e_phentsize, ehdr.e_phentsize); // extract necessary info out of dynamic program header U64 dynamic_info_rebase = is_rebased ? 0 : rebase; - DMN_LNX_DynamicInfo dynamic_info = dmn_lnx_dynamic_info_from_memory(memory_fd, elf_class, dynamic_info_rebase, dynamic_vaddr); + LNX_DMN_DynamicInfo dynamic_info = lnx_dmn_dynamic_info_from_memory(memory_fd, elf_class, dynamic_info_rebase, dynamic_vaddr); // extract symbol table count from available options U64 symbol_count = 0; @@ -415,7 +415,7 @@ dmn_lnx_rdebug_vaddr_from_memory(int memory_fd, U64 loader_vbase, B32 is_rebased } U64 chain_count = 0; - if(dmn_lnx_read(memory_fd, r1u64(dynamic_info.hash_vaddr, dynamic_info.hash_vaddr + hash_entry_size), &chain_count) == hash_entry_size) + if(lnx_dmn_read(memory_fd, r1u64(dynamic_info.hash_vaddr, dynamic_info.hash_vaddr + hash_entry_size), &chain_count) == hash_entry_size) { symbol_count = chain_count; } @@ -436,7 +436,7 @@ dmn_lnx_rdebug_vaddr_from_memory(int memory_fd, U64 loader_vbase, B32 is_rebased for EachIndex(symbol_idx, symbol_count) { ELF_Sym64 symbol = {0}; - if(elf_read_symbol(dmn_lnx_machine_op_mem_read, &memory_fd, dynamic_info.symtab_vaddr + symbol_idx * dynamic_info.symtab_entry_size, elf_class, &symbol) != MachineOpResult_Ok) + if(elf_read_symbol(lnx_dmn_machine_op_mem_read, &memory_fd, dynamic_info.symtab_vaddr + symbol_idx * dynamic_info.symtab_entry_size, elf_class, &symbol) != MachineOpResult_Ok) { Assert(0 && "failed to read symbol table"); break; @@ -448,7 +448,7 @@ dmn_lnx_rdebug_vaddr_from_memory(int memory_fd, U64 loader_vbase, B32 is_rebased if(symbol.st_name < dynamic_info.strtab_size) { U64 cap = dynamic_info.strtab_size - symbol.st_name; - symbol_name = dmn_lnx_read_string_capped(temp.arena, memory_fd, dynamic_info.strtab_vaddr + symbol.st_name, cap); + symbol_name = lnx_dmn_read_string_capped(temp.arena, memory_fd, dynamic_info.strtab_vaddr + symbol.st_name, cap); } if(str8_match(symbol_name, str8_lit("_r_debug"), 0)) @@ -470,19 +470,19 @@ dmn_lnx_rdebug_vaddr_from_memory(int memory_fd, U64 loader_vbase, B32 is_rebased return rdebug_vaddr; } -internal DMN_LNX_ProbeList -dmn_lnx_read_probes(Arena *arena, int fd, U64 offset, U64 image_base) +internal LNX_DMN_ProbeList +lnx_dmn_read_probes(Arena *arena, int fd, U64 offset, U64 image_base) { Temp scratch = scratch_begin(&arena, 1); - DMN_LNX_ProbeList probes = {0}; + LNX_DMN_ProbeList probes = {0}; ELF_Hdr64 ehdr = {0}; - if(elf_read_ehdr(dmn_lnx_machine_op_mem_read, &fd, offset, &ehdr) != MachineOpResult_Ok) { goto exit; } + if(elf_read_ehdr(lnx_dmn_machine_op_mem_read, &fd, offset, &ehdr) != MachineOpResult_Ok) { goto exit; } U64 strtab_shdr_offset = offset + ehdr.e_shoff + ehdr.e_shstrndx * ehdr.e_shentsize; ELF_Shdr64 strtab_shdr = {0}; - if(elf_read_shdr(dmn_lnx_machine_op_mem_read, &fd, strtab_shdr_offset, ehdr.e_ident[ELF_Identifier_Class], &strtab_shdr) != MachineOpResult_Ok) { goto exit; } + if(elf_read_shdr(lnx_dmn_machine_op_mem_read, &fd, strtab_shdr_offset, ehdr.e_ident[ELF_Identifier_Class], &strtab_shdr) != MachineOpResult_Ok) { goto exit; } B32 found_probes = 0; B32 found_probes_base = 0; @@ -493,13 +493,13 @@ dmn_lnx_read_probes(Arena *arena, int fd, U64 offset, U64 image_base) shdr_off < shdr_opl; shdr_off += ehdr.e_shentsize) { ELF_Shdr64 shdr = {0}; - if(elf_read_shdr(dmn_lnx_machine_op_mem_read, &fd, shdr_off, ehdr.e_ident[ELF_Identifier_Class], &shdr) != MachineOpResult_Ok) { goto exit; } + if(elf_read_shdr(lnx_dmn_machine_op_mem_read, &fd, shdr_off, ehdr.e_ident[ELF_Identifier_Class], &shdr) != MachineOpResult_Ok) { goto exit; } if(shdr.sh_type == ELF_ShType_Note) { U64 name_offset = offset + strtab_shdr.sh_offset + shdr.sh_name; U64 name_cap = offset + strtab_shdr.sh_offset + strtab_shdr.sh_size; - String8 name = dmn_lnx_read_string_capped(scratch.arena, fd, name_offset, name_cap); + String8 name = lnx_dmn_read_string_capped(scratch.arena, fd, name_offset, name_cap); if(str8_match(name, str8_lit(".note.stapsdt"), 0)) { @@ -511,7 +511,7 @@ dmn_lnx_read_probes(Arena *arena, int fd, U64 offset, U64 image_base) { U64 name_offset = offset + strtab_shdr.sh_offset + shdr.sh_name; U64 name_cap = offset + strtab_shdr.sh_offset + strtab_shdr.sh_size; - String8 name = dmn_lnx_read_string_capped(scratch.arena, fd, name_offset, name_cap); + String8 name = lnx_dmn_read_string_capped(scratch.arena, fd, name_offset, name_cap); if(str8_match(name, str8_lit(".stapsdt.base"), 0)) { @@ -532,7 +532,7 @@ dmn_lnx_read_probes(Arena *arena, int fd, U64 offset, U64 image_base) Rng1U64 note_range = shift_1u64(r1u64(stapsdt_shdr.sh_offset, stapsdt_shdr.sh_offset + stapsdt_shdr.sh_size), offset); void *raw_note = push_array(arena, U8, stapsdt_shdr.sh_size); - U64 note_read_size = dmn_lnx_read(fd, note_range, raw_note); + U64 note_read_size = lnx_dmn_read(fd, note_range, raw_note); if(note_read_size != dim_1u64(note_range)) { goto exit; } Arch arch = arch_from_elf_machine(ehdr.e_machine); @@ -544,7 +544,7 @@ dmn_lnx_read_probes(Arena *arena, int fd, U64 offset, U64 image_base) if(!str8_match(note->owner, str8_lit("stapsdt"), 0)) { continue; } if(note->type != ELF_NoteType_STapSdt) { continue; } - DMN_LNX_Probe probe = {0}; + LNX_DMN_Probe probe = {0}; { U64 cursor = 0; U64 addr_size = ehdr.e_ident[ELF_Identifier_Class] == ELF_Class_64 ? 8 : 4; @@ -585,7 +585,7 @@ dmn_lnx_read_probes(Arena *arena, int fd, U64 offset, U64 image_base) probe.semaphore = semaphore ? semaphore + probe_rebase : 0; } - DMN_LNX_ProbeNode *n = push_array(arena, DMN_LNX_ProbeNode, 1); + LNX_DMN_ProbeNode *n = push_array(arena, LNX_DMN_ProbeNode, 1); n->v = probe; SLLQueuePush(probes.first, probes.last, n); probes.count += 1; @@ -597,25 +597,25 @@ dmn_lnx_read_probes(Arena *arena, int fd, U64 offset, U64 image_base) } internal -STAP_MEMORY_READ(dmn_lnx_stap_memory_read) +STAP_MEMORY_READ(lnx_dmn_stap_memory_read) { - DMN_LNX_Process *process = raw_ctx; - U64 bytes_read = dmn_lnx_read(process->fd, r1u64(addr, addr + read_size), buffer); + LNX_DMN_Process *process = raw_ctx; + U64 bytes_read = lnx_dmn_read(process->fd, r1u64(addr, addr + read_size), buffer); return bytes_read == read_size; } -internal DMN_LNX_Entity * -dmn_lnx_entity_alloc(DMN_LNX_EntityKind kind) +internal LNX_DMN_Entity * +lnx_dmn_entity_alloc(LNX_DMN_EntityKind kind) { - DMN_LNX_Entity *entity = dmn_lnx_state->free_entity; + LNX_DMN_Entity *entity = lnx_dmn_state->free_entity; if(entity != 0) { - SLLStackPop(dmn_lnx_state->free_entity); + SLLStackPop(lnx_dmn_state->free_entity); } else { - entity = push_array(dmn_lnx_state->entities_arena, DMN_LNX_Entity, 1); - dmn_lnx_state->entities_count += 1; + entity = push_array(lnx_dmn_state->entities_arena, LNX_DMN_Entity, 1); + lnx_dmn_state->entities_count += 1; } U32 gen = entity->gen; entity->gen += 1; @@ -623,54 +623,54 @@ dmn_lnx_entity_alloc(DMN_LNX_EntityKind kind) return entity; } -internal DMN_LNX_Process * -dmn_lnx_process_alloc(pid_t pid, DMN_LNX_ProcessState state, DMN_LNX_Process *parent_process, B32 debug_subprocesses, B32 is_cow) +internal LNX_DMN_Process * +lnx_dmn_process_alloc(pid_t pid, LNX_DMN_ProcessState state, LNX_DMN_Process *parent_process, B32 debug_subprocesses, B32 is_cow) { Temp scratch = scratch_begin(0, 0); - DMN_LNX_Process *process = &dmn_lnx_entity_alloc(DMN_LNX_EntityKind_Process)->process; + LNX_DMN_Process *process = &lnx_dmn_entity_alloc(LNX_DMN_EntityKind_Process)->process; process->pid = pid; - process->fd = OS_LNX_RETRY_ON_EINTR(open((char *)str8f(scratch.arena, "/proc/%d/mem", pid).str, O_RDWR)); + process->fd = LNX_RETRY_ON_EINTR(open((char *)str8f(scratch.arena, "/proc/%d/mem", pid).str, O_RDWR)); process->state = state; process->debug_subprocesses = debug_subprocesses; process->is_cow = is_cow; process->parent_process = parent_process; // update pending process tracker - if(state != DMN_LNX_ProcessState_Normal) + if(state != LNX_DMN_ProcessState_Normal) { - dmn_lnx_state->process_pending_creation += 1; + lnx_dmn_state->process_pending_creation += 1; } // add process to the list - DLLPushBack(dmn_lnx_state->first_process, dmn_lnx_state->last_process, process); - dmn_lnx_state->process_count += 1; + DLLPushBack(lnx_dmn_state->first_process, lnx_dmn_state->last_process, process); + lnx_dmn_state->process_count += 1; - // push pid -> DMN_LNX_Process mapping - hash_table_push_u64_raw(dmn_lnx_state->arena, dmn_lnx_state->pid_ht, pid, process); + // push pid -> LNX_DMN_Process mapping + hash_table_push_u64_raw(lnx_dmn_state->arena, lnx_dmn_state->pid_ht, pid, process); scratch_end(scratch); return process; } -internal DMN_LNX_ProcessCtx * -dmn_lnx_process_ctx_alloc(DMN_LNX_Process *process, B32 is_rebased) +internal LNX_DMN_ProcessCtx * +lnx_dmn_process_ctx_alloc(LNX_DMN_Process *process, B32 is_rebased) { - DMN_LNX_ProcessCtx *ctx = &dmn_lnx_entity_alloc(DMN_LNX_EntityKind_ProcessCtx)->process_ctx; + LNX_DMN_ProcessCtx *ctx = &lnx_dmn_entity_alloc(LNX_DMN_EntityKind_ProcessCtx)->process_ctx; - ELF_Hdr64 exe_ehdr = dmn_lnx_ehdr_from_pid(process->pid); - DMN_LNX_Auxv auxv = dmn_lnx_auxv_from_pid(process->pid, exe_ehdr.e_ident[ELF_Identifier_Class]); + ELF_Hdr64 exe_ehdr = lnx_dmn_ehdr_from_pid(process->pid); + LNX_DMN_Auxv auxv = lnx_dmn_auxv_from_pid(process->pid, exe_ehdr.e_ident[ELF_Identifier_Class]); Arch arch = arch_from_elf_machine(exe_ehdr.e_machine); - U64 rdebug_vaddr = dmn_lnx_rdebug_vaddr_from_memory(process->fd, auxv.base, is_rebased); + U64 rdebug_vaddr = lnx_dmn_rdebug_vaddr_from_memory(process->fd, auxv.base, is_rebased); U64 base_vaddr = (auxv.phdr & ~(auxv.pagesz-1)); U64 rebase = exe_ehdr.e_type == ELF_Type_Dyn ? base_vaddr : 0; - Rng1U64 image_vrange = dmn_lnx_compute_image_vrange(process->fd, exe_ehdr.e_ident[ELF_Identifier_Class], rebase, auxv.phdr, auxv.phent, auxv.phnum); + Rng1U64 image_vrange = lnx_dmn_compute_image_vrange(process->fd, exe_ehdr.e_ident[ELF_Identifier_Class], rebase, auxv.phdr, auxv.phent, auxv.phnum); Arena *ctx_arena = arena_alloc(); ELF_Class dl_class; { ELF_Hdr64 ehdr = {0}; - if(elf_read_ehdr(dmn_lnx_machine_op_mem_read, &process->fd, auxv.base, &ehdr) != MachineOpResult_Ok) { Assert(0 && "failed to read interp's header"); } + if(elf_read_ehdr(lnx_dmn_machine_op_mem_read, &process->fd, auxv.base, &ehdr) != MachineOpResult_Ok) { Assert(0 && "failed to read interp's header"); } dl_class = ehdr.e_ident[ELF_Identifier_Class]; } @@ -681,7 +681,7 @@ dmn_lnx_process_ctx_alloc(DMN_LNX_Process *process, B32 is_rebased) if(arch == Arch_x64) { X64_XSave xsave = {0}; - if(OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETREGSET, process->pid, (void *)NT_X86_XSTATE, &(struct iovec){.iov_base = &xsave, .iov_len = sizeof(xsave) }) >= 0)) + if(LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETREGSET, process->pid, (void *)NT_X86_XSTATE, &(struct iovec){.iov_base = &xsave, .iov_len = sizeof(xsave) }) >= 0)) { // Linux stores xcr0 bits in fxstate padding, // see https://github.com/torvalds/linux/blob/6548d364a3e850326831799d7e3ea2d7bb97ba08/arch/x86/include/asm/user.h#L25 @@ -693,27 +693,27 @@ dmn_lnx_process_ctx_alloc(DMN_LNX_Process *process, B32 is_rebased) } // gather probes - DMN_LNX_Probe **known_probes = push_array(ctx_arena, DMN_LNX_Probe *, DMN_LNX_ProbeType_Count); + LNX_DMN_Probe **known_probes = push_array(ctx_arena, LNX_DMN_Probe *, LNX_DMN_ProbeType_Count); { Temp scratch = scratch_begin(0, 0); - String8 dl_path = dmn_lnx_dl_path_from_pid(scratch.arena, process->pid, auxv.base); - int dl_fd = OS_LNX_RETRY_ON_EINTR(open((char *)dl_path.str, O_RDONLY)); + String8 dl_path = lnx_dmn_dl_path_from_pid(scratch.arena, process->pid, auxv.base); + int dl_fd = LNX_RETRY_ON_EINTR(open((char *)dl_path.str, O_RDONLY)); - DMN_LNX_ProbeList probes = {0}; + LNX_DMN_ProbeList probes = {0}; if(dl_fd >= 0) { - probes = dmn_lnx_read_probes(ctx_arena, dl_fd, 0, auxv.base); - OS_LNX_RETRY_ON_EINTR(close(dl_fd)); + probes = lnx_dmn_read_probes(ctx_arena, dl_fd, 0, auxv.base); + LNX_RETRY_ON_EINTR(close(dl_fd)); } - for EachNode(n, DMN_LNX_ProbeNode, probes.first) + for EachNode(n, LNX_DMN_ProbeNode, probes.first) { - DMN_LNX_Probe *p = &n->v; + LNX_DMN_Probe *p = &n->v; if(str8_match(p->provider, str8_lit("rtld"), 0)) { -#define X(_N,_A,_S) if(str8_match(p->name, str8_lit(_S), 0)) { AssertAlways(p->args.count == _A); known_probes[DMN_LNX_ProbeType_##_N] = p; continue ; } - DMN_LNX_Probe_XList +#define X(_N,_A,_S) if(str8_match(p->name, str8_lit(_S), 0)) { AssertAlways(p->args.count == _A); known_probes[LNX_DMN_ProbeType_##_N] = p; continue ; } + LNX_DMN_Probe_XList #undef X } } @@ -721,7 +721,7 @@ dmn_lnx_process_ctx_alloc(DMN_LNX_Process *process, B32 is_rebased) scratch_end(scratch); } - ctx = &dmn_lnx_entity_alloc(DMN_LNX_EntityKind_ProcessCtx)->process_ctx; + ctx = &lnx_dmn_entity_alloc(LNX_DMN_EntityKind_ProcessCtx)->process_ctx; ctx->arena = arena_alloc(); ctx->arch = arch; ctx->rdebug_vaddr = rdebug_vaddr; @@ -733,7 +733,7 @@ dmn_lnx_process_ctx_alloc(DMN_LNX_Process *process, B32 is_rebased) ctx->xsave_layout = xsave_layout; // create main module - DMN_LNX_Module *main_module = dmn_lnx_module_alloc(ctx, process->fd, base_vaddr, auxv.execfn, 1, 1); + LNX_DMN_Module *main_module = lnx_dmn_module_alloc(ctx, process->fd, base_vaddr, auxv.execfn, 1, 1); // glibc has a shortcut mapping for the main module hash_table_push_u64_raw(ctx->arena, ctx->loaded_modules_ht, 0, main_module); @@ -741,8 +741,8 @@ dmn_lnx_process_ctx_alloc(DMN_LNX_Process *process, B32 is_rebased) return ctx; } -internal DMN_LNX_Thread * -dmn_lnx_thread_alloc(DMN_LNX_Process *process, DMN_LNX_ThreadState thread_state, pid_t tid) +internal LNX_DMN_Thread * +lnx_dmn_thread_alloc(LNX_DMN_Process *process, LNX_DMN_ThreadState thread_state, pid_t tid) { void *reg_block; if(process->ctx->free_reg_blocks.node_count) @@ -758,14 +758,14 @@ dmn_lnx_thread_alloc(DMN_LNX_Process *process, DMN_LNX_ThreadState thread_state, reg_block = push_array(process->ctx->arena, U8, reg_block_size); } - DMN_LNX_Thread *thread = &dmn_lnx_entity_alloc(DMN_LNX_EntityKind_Thread)->thread; + LNX_DMN_Thread *thread = &lnx_dmn_entity_alloc(LNX_DMN_EntityKind_Thread)->thread; thread->tid = tid; thread->state = thread_state; thread->process = process; thread->reg_block = reg_block; - if(thread_state == DMN_LNX_ThreadState_Stopped) + if(thread_state == LNX_DMN_ThreadState_Stopped) { - thread->is_reg_block_dirty = !dmn_lnx_thread_read_reg_block(thread); + thread->is_reg_block_dirty = !lnx_dmn_thread_read_reg_block(thread); } // add thread to the list @@ -773,31 +773,31 @@ dmn_lnx_thread_alloc(DMN_LNX_Process *process, DMN_LNX_ThreadState thread_state, process->thread_count += 1; // push tid -> thread mapping - hash_table_push_u64_raw(dmn_lnx_state->arena, dmn_lnx_state->tid_ht, thread->tid, thread); + hash_table_push_u64_raw(lnx_dmn_state->arena, lnx_dmn_state->tid_ht, thread->tid, thread); // update global thread counter - if(thread_state == DMN_LNX_ThreadState_PendingCreation) + if(thread_state == LNX_DMN_ThreadState_PendingCreation) { - dmn_lnx_state->threads_pending_creation += 1; + lnx_dmn_state->threads_pending_creation += 1; } return thread; } -internal DMN_LNX_Module * -dmn_lnx_module_alloc(DMN_LNX_ProcessCtx *ctx, int memory_fd, U64 base_vaddr, U64 name_vaddr, U64 name_space_id, B32 is_main) +internal LNX_DMN_Module * +lnx_dmn_module_alloc(LNX_DMN_ProcessCtx *ctx, int memory_fd, U64 base_vaddr, U64 name_vaddr, U64 name_space_id, B32 is_main) { - DMN_LNX_Module *module = hash_table_search_u64_raw(ctx->loaded_modules_ht, base_vaddr); + LNX_DMN_Module *module = hash_table_search_u64_raw(ctx->loaded_modules_ht, base_vaddr); if(module) { goto exit; } // parse out module's ELF header ELF_Hdr64 module_ehdr = {0}; - if(elf_read_ehdr(dmn_lnx_machine_op_mem_read, &memory_fd, base_vaddr, &module_ehdr) != MachineOpResult_Ok) { goto exit; } + if(elf_read_ehdr(lnx_dmn_machine_op_mem_read, &memory_fd, base_vaddr, &module_ehdr) != MachineOpResult_Ok) { goto exit; } // gather info about module U64 module_rebase = module_ehdr.e_type == ELF_Type_Dyn ? base_vaddr : 0; U64 module_phdr_vaddr = module_rebase + module_ehdr.e_phoff; - Rng1U64 module_vrange = dmn_lnx_compute_image_vrange(memory_fd, module_ehdr.e_ident[ELF_Identifier_Class], module_rebase, module_phdr_vaddr, module_ehdr.e_phentsize, module_ehdr.e_phnum); + Rng1U64 module_vrange = lnx_dmn_compute_image_vrange(memory_fd, module_ehdr.e_ident[ELF_Identifier_Class], module_rebase, module_phdr_vaddr, module_ehdr.e_phentsize, module_ehdr.e_phnum); // read TLS index and TLS offset U64 tls_index = max_U64; @@ -809,18 +809,18 @@ dmn_lnx_module_alloc(DMN_LNX_ProcessCtx *ctx, int memory_fd, U64 base_vaddr, U64 } else { - if(dmn_lnx_state->is_tls_detected) + if(lnx_dmn_state->is_tls_detected) { - Rng1U64 tls_modid_range = r1u64(dmn_lnx_state->tls_modid_desc.offset, dmn_lnx_state->tls_modid_desc.offset + dmn_lnx_state->tls_modid_desc.bit_size / 8); - Rng1U64 tls_offset_range = r1u64(dmn_lnx_state->tls_offset_desc.offset, dmn_lnx_state->tls_offset_desc.offset + dmn_lnx_state->tls_offset_desc.bit_size / 8); + Rng1U64 tls_modid_range = r1u64(lnx_dmn_state->tls_modid_desc.offset, lnx_dmn_state->tls_modid_desc.offset + lnx_dmn_state->tls_modid_desc.bit_size / 8); + Rng1U64 tls_offset_range = r1u64(lnx_dmn_state->tls_offset_desc.offset, lnx_dmn_state->tls_offset_desc.offset + lnx_dmn_state->tls_offset_desc.bit_size / 8); tls_modid_range = shift_1u64(tls_modid_range, base_vaddr); tls_offset_range = shift_1u64(tls_offset_range, base_vaddr); - if(!dmn_lnx_read(memory_fd, tls_modid_range, &tls_index)) { Assert(0 && "failed to read TLS index"); } - if(!dmn_lnx_read(memory_fd, tls_offset_range, &tls_offset)) { Assert(0 && "failed to read TLS offset"); } + if(!lnx_dmn_read(memory_fd, tls_modid_range, &tls_index)) { Assert(0 && "failed to read TLS index"); } + if(!lnx_dmn_read(memory_fd, tls_offset_range, &tls_offset)) { Assert(0 && "failed to read TLS offset"); } } } - module = &dmn_lnx_entity_alloc(DMN_LNX_EntityKind_Module)->module; + module = &lnx_dmn_entity_alloc(LNX_DMN_EntityKind_Module)->module; module->base_vaddr = base_vaddr; module->name_vaddr = name_vaddr; module->name_space_id = name_space_id; @@ -844,47 +844,47 @@ dmn_lnx_module_alloc(DMN_LNX_ProcessCtx *ctx, int memory_fd, U64 base_vaddr, U64 } internal void -dmn_lnx_entity_release(DMN_LNX_Entity *entity) +lnx_dmn_entity_release(LNX_DMN_Entity *entity) { U32 gen = entity->gen + 1; MemoryZeroStruct(entity); entity->gen = gen; - SLLStackPush(dmn_lnx_state->free_entity, entity); + SLLStackPush(lnx_dmn_state->free_entity, entity); } internal void -dmn_lnx_process_release(DMN_LNX_Process *process) +lnx_dmn_process_release(LNX_DMN_Process *process) { // update global state - AssertAlways(dmn_lnx_state->process_count > 0); - DLLRemove(dmn_lnx_state->first_process, dmn_lnx_state->last_process, process); - dmn_lnx_state->process_count -= 1; + AssertAlways(lnx_dmn_state->process_count > 0); + DLLRemove(lnx_dmn_state->first_process, lnx_dmn_state->last_process, process); + lnx_dmn_state->process_count -= 1; // update pending process tracker - if(process->state != DMN_LNX_ProcessState_Normal) + if(process->state != LNX_DMN_ProcessState_Normal) { - Assert(dmn_lnx_state->process_pending_creation > 0); - dmn_lnx_state->process_pending_creation -= 1; + Assert(lnx_dmn_state->process_pending_creation > 0); + lnx_dmn_state->process_pending_creation -= 1; } // close memory handle - if(OS_LNX_RETRY_ON_EINTR(close(process->fd)) < 0) { Assert(0 && "failed to close memory descriptor"); } + if(LNX_RETRY_ON_EINTR(close(process->fd)) < 0) { Assert(0 && "failed to close memory descriptor"); } // remove pid mapping - hash_table_purge_u64(dmn_lnx_state->pid_ht, process->pid); + hash_table_purge_u64(lnx_dmn_state->pid_ht, process->pid); // release the context if(process->ctx) { - dmn_lnx_process_ctx_release(process->ctx); + lnx_dmn_process_ctx_release(process->ctx); } // release process entity - dmn_lnx_entity_release((DMN_LNX_Entity *)process); + lnx_dmn_entity_release((LNX_DMN_Entity *)process); } internal void -dmn_lnx_process_ctx_release(DMN_LNX_ProcessCtx *ctx) +lnx_dmn_process_ctx_release(LNX_DMN_ProcessCtx *ctx) { Assert(ctx->ref_count > 0); ctx->ref_count -= 1; @@ -892,23 +892,23 @@ dmn_lnx_process_ctx_release(DMN_LNX_ProcessCtx *ctx) if(ctx->ref_count == 0) { arena_release(ctx->arena); - dmn_lnx_entity_release((DMN_LNX_Entity *)ctx); + lnx_dmn_entity_release((LNX_DMN_Entity *)ctx); } } internal void -dmn_lnx_thread_release(DMN_LNX_Thread *thread) +lnx_dmn_thread_release(LNX_DMN_Thread *thread) { - DMN_LNX_Process *process = thread->process; + LNX_DMN_Process *process = thread->process; // purge tid mapping - hash_table_purge_u64(dmn_lnx_state->tid_ht, thread->tid); + hash_table_purge_u64(lnx_dmn_state->tid_ht, thread->tid); // update global thread counter - if(thread->state == DMN_LNX_ThreadState_PendingCreation) + if(thread->state == LNX_DMN_ThreadState_PendingCreation) { - AssertAlways(dmn_lnx_state->threads_pending_creation > 0); - dmn_lnx_state->threads_pending_creation -= 1; + AssertAlways(lnx_dmn_state->threads_pending_creation > 0); + lnx_dmn_state->threads_pending_creation -= 1; } // remove thread from the list @@ -929,11 +929,11 @@ dmn_lnx_thread_release(DMN_LNX_Thread *thread) reg_block_node->string = str8(thread->reg_block, 0); str8_list_push_node(&process->ctx->free_reg_blocks, reg_block_node); - dmn_lnx_entity_release((DMN_LNX_Entity *)thread); + lnx_dmn_entity_release((LNX_DMN_Entity *)thread); } internal void -dmn_lnx_module_release(DMN_LNX_ProcessCtx *ctx, DMN_LNX_Module *module) +lnx_dmn_module_release(LNX_DMN_ProcessCtx *ctx, LNX_DMN_Module *module) { // remove module from the list Assert(ctx->module_count > 0); @@ -943,13 +943,13 @@ dmn_lnx_module_release(DMN_LNX_ProcessCtx *ctx, DMN_LNX_Module *module) // purge base addr -> module mapping hash_table_purge_u64(ctx->loaded_modules_ht, module->base_vaddr); - dmn_lnx_entity_release((DMN_LNX_Entity *)module); + lnx_dmn_entity_release((LNX_DMN_Entity *)module); } -internal DMN_LNX_ProcessCtx * -dmn_lnx_process_ctx_clone(DMN_LNX_Process *new_owner, DMN_LNX_ProcessCtx *ctx) +internal LNX_DMN_ProcessCtx * +lnx_dmn_process_ctx_clone(LNX_DMN_Process *new_owner, LNX_DMN_ProcessCtx *ctx) { - DMN_LNX_ProcessCtx *result = &dmn_lnx_entity_alloc(DMN_LNX_EntityKind_ProcessCtx)->process_ctx; + LNX_DMN_ProcessCtx *result = &lnx_dmn_entity_alloc(LNX_DMN_EntityKind_ProcessCtx)->process_ctx; result->arena = arena_alloc(); result->arch = ctx->arch; @@ -961,11 +961,11 @@ dmn_lnx_process_ctx_clone(DMN_LNX_Process *new_owner, DMN_LNX_ProcessCtx *ctx) result->xsave_layout = ctx->xsave_layout; // clone probes - result->probes = push_array(result->arena, DMN_LNX_Probe *, DMN_LNX_ProbeType_Count); - for EachIndex(probe_idx, DMN_LNX_ProbeType_Count) + result->probes = push_array(result->arena, LNX_DMN_Probe *, LNX_DMN_ProbeType_Count); + for EachIndex(probe_idx, LNX_DMN_ProbeType_Count) { - DMN_LNX_Probe *dst = result->probes[probe_idx]; - DMN_LNX_Probe *src = ctx->probes[probe_idx]; + LNX_DMN_Probe *dst = result->probes[probe_idx]; + LNX_DMN_Probe *src = ctx->probes[probe_idx]; dst->provider = str8_copy(result->arena, src->provider); dst->name = str8_copy(result->arena, src->name); @@ -980,7 +980,7 @@ dmn_lnx_process_ctx_clone(DMN_LNX_Process *new_owner, DMN_LNX_ProcessCtx *ctx) { DMN_Trap *src_trap = src->trap; DMN_Trap *dst_trap = push_array(result->arena, DMN_Trap, 1); - dst_trap->process = dmn_lnx_handle_from_process(new_owner); + dst_trap->process = lnx_dmn_handle_from_process(new_owner); dst_trap->vaddr = src_trap->vaddr; dst_trap->id = src_trap->id; dst_trap->flags = src_trap->flags; @@ -994,18 +994,18 @@ dmn_lnx_process_ctx_clone(DMN_LNX_Process *new_owner, DMN_LNX_ProcessCtx *ctx) } // clone modules - for EachNode(module, DMN_LNX_Module, ctx->first_module) + for EachNode(module, LNX_DMN_Module, ctx->first_module) { - dmn_lnx_module_clone(result, module); + lnx_dmn_module_clone(result, module); } return result; } -internal DMN_LNX_Module * -dmn_lnx_module_clone(DMN_LNX_ProcessCtx *process_ctx, DMN_LNX_Module *module) +internal LNX_DMN_Module * +lnx_dmn_module_clone(LNX_DMN_ProcessCtx *process_ctx, LNX_DMN_Module *module) { - DMN_LNX_Module *result = &dmn_lnx_entity_alloc(DMN_LNX_EntityKind_Module)->module; + LNX_DMN_Module *result = &lnx_dmn_entity_alloc(LNX_DMN_EntityKind_Module)->module; *result = *module; result->next = result->prev = 0; @@ -1020,10 +1020,10 @@ dmn_lnx_module_clone(DMN_LNX_ProcessCtx *process_ctx, DMN_LNX_Module *module) } internal DMN_Handle -dmn_lnx_handle_from_entity(DMN_LNX_Entity *entity) +lnx_dmn_handle_from_entity(LNX_DMN_Entity *entity) { DMN_Handle handle = {0}; - U64 index = IntFromPtr(entity - dmn_lnx_state->entities_base); + U64 index = IntFromPtr(entity - lnx_dmn_state->entities_base); if(index <= max_U32) { handle.u32[0] = index; @@ -1037,78 +1037,78 @@ dmn_lnx_handle_from_entity(DMN_LNX_Entity *entity) } internal DMN_Handle -dmn_lnx_handle_from_process(DMN_LNX_Process *process) +lnx_dmn_handle_from_process(LNX_DMN_Process *process) { - return dmn_lnx_handle_from_entity((DMN_LNX_Entity *)process); + return lnx_dmn_handle_from_entity((LNX_DMN_Entity *)process); } internal DMN_Handle -dmn_lnx_handle_from_process_ctx(DMN_LNX_ProcessCtx *process_ctx) +lnx_dmn_handle_from_process_ctx(LNX_DMN_ProcessCtx *process_ctx) { - return dmn_lnx_handle_from_entity((DMN_LNX_Entity *)process_ctx); + return lnx_dmn_handle_from_entity((LNX_DMN_Entity *)process_ctx); } internal DMN_Handle -dmn_lnx_handle_from_thread(DMN_LNX_Thread *thread) +lnx_dmn_handle_from_thread(LNX_DMN_Thread *thread) { - return dmn_lnx_handle_from_entity((DMN_LNX_Entity *)thread); + return lnx_dmn_handle_from_entity((LNX_DMN_Entity *)thread); } internal DMN_Handle -dmn_lnx_handle_from_module(DMN_LNX_Module *module) +lnx_dmn_handle_from_module(LNX_DMN_Module *module) { - return dmn_lnx_handle_from_entity((DMN_LNX_Entity *)module); + return lnx_dmn_handle_from_entity((LNX_DMN_Entity *)module); } -internal DMN_LNX_Entity * -dmn_lnx_entity_from_handle(DMN_Handle handle, DMN_LNX_EntityKind expected_kind) +internal LNX_DMN_Entity * +lnx_dmn_entity_from_handle(DMN_Handle handle, LNX_DMN_EntityKind expected_kind) { - DMN_LNX_Entity *result = 0; + LNX_DMN_Entity *result = 0; U32 index = handle.u32[0]; U32 gen = handle.u32[1]; - if(index < dmn_lnx_state->entities_count && dmn_lnx_state->entities_base[index].gen == gen) + if(index < lnx_dmn_state->entities_count && lnx_dmn_state->entities_base[index].gen == gen) { - if(dmn_lnx_state->entities_base[index].kind == expected_kind) + if(lnx_dmn_state->entities_base[index].kind == expected_kind) { - result = &dmn_lnx_state->entities_base[index]; + result = &lnx_dmn_state->entities_base[index]; } } return result; } -internal DMN_LNX_Process * -dmn_lnx_process_from_handle(DMN_Handle process_handle) +internal LNX_DMN_Process * +lnx_dmn_process_from_handle(DMN_Handle process_handle) { - return (DMN_LNX_Process *)dmn_lnx_entity_from_handle(process_handle, DMN_LNX_EntityKind_Process); + return (LNX_DMN_Process *)lnx_dmn_entity_from_handle(process_handle, LNX_DMN_EntityKind_Process); } -internal DMN_LNX_ProcessCtx * -dmn_lnx_process_ctx_from_handle(DMN_Handle process_ctx_handle) +internal LNX_DMN_ProcessCtx * +lnx_dmn_process_ctx_from_handle(DMN_Handle process_ctx_handle) { - return (DMN_LNX_ProcessCtx *)dmn_lnx_entity_from_handle(process_ctx_handle, DMN_LNX_EntityKind_ProcessCtx); + return (LNX_DMN_ProcessCtx *)lnx_dmn_entity_from_handle(process_ctx_handle, LNX_DMN_EntityKind_ProcessCtx); } -internal DMN_LNX_Thread * -dmn_lnx_thread_from_handle(DMN_Handle thread_handle) +internal LNX_DMN_Thread * +lnx_dmn_thread_from_handle(DMN_Handle thread_handle) { - return (DMN_LNX_Thread *)dmn_lnx_entity_from_handle(thread_handle, DMN_LNX_EntityKind_Thread); + return (LNX_DMN_Thread *)lnx_dmn_entity_from_handle(thread_handle, LNX_DMN_EntityKind_Thread); } -internal DMN_LNX_Module * -dmn_lnx_module_from_handle(DMN_Handle module_handle) +internal LNX_DMN_Module * +lnx_dmn_module_from_handle(DMN_Handle module_handle) { - return (DMN_LNX_Module *)dmn_lnx_entity_from_handle(module_handle, DMN_LNX_EntityKind_Module); + return (LNX_DMN_Module *)lnx_dmn_entity_from_handle(module_handle, LNX_DMN_EntityKind_Module); } internal void -dmn_lnx_process_trap_probes(DMN_LNX_Process *process) +lnx_dmn_process_trap_probes(LNX_DMN_Process *process) { - for EachIndex(i, DMN_LNX_ProbeType_Count) + for EachIndex(i, LNX_DMN_ProbeType_Count) { if(process->ctx->probes[i] == 0) { continue; } DMN_Trap *trap = push_array(process->ctx->arena, DMN_Trap, 1); - trap->process = dmn_lnx_handle_from_process(process); + trap->process = lnx_dmn_handle_from_process(process); trap->vaddr = process->ctx->probes[i]->pc; trap->id = i; @@ -1123,13 +1123,13 @@ dmn_lnx_process_trap_probes(DMN_LNX_Process *process) } internal void -dmn_lnx_process_untrap_probes(DMN_LNX_Process *process) +lnx_dmn_process_untrap_probes(LNX_DMN_Process *process) { NotImplemented; } internal U64 -dmn_lnx_thread_read_ip(DMN_LNX_Thread *thread) +lnx_dmn_thread_read_ip(LNX_DMN_Thread *thread) { ARCH_Info *arch_info = arch_info_from_arch(thread->process->ctx->arch); U64 result = arch_ip_from_reg_block(arch_info, thread->reg_block); @@ -1137,7 +1137,7 @@ dmn_lnx_thread_read_ip(DMN_LNX_Thread *thread) } internal U64 -dmn_lnx_thread_read_sp(DMN_LNX_Thread *thread) +lnx_dmn_thread_read_sp(LNX_DMN_Thread *thread) { ARCH_Info *arch_info = arch_info_from_arch(thread->process->ctx->arch); U64 result = arch_sp_from_reg_block(arch_info, thread->reg_block); @@ -1145,7 +1145,7 @@ dmn_lnx_thread_read_sp(DMN_LNX_Thread *thread) } internal void -dmn_lnx_thread_write_ip(DMN_LNX_Thread *thread, U64 ip) +lnx_dmn_thread_write_ip(LNX_DMN_Thread *thread, U64 ip) { ARCH_Info *arch_info = arch_info_from_arch(thread->process->ctx->arch); arch_reg_block_write_ip(arch_info, thread->reg_block, ip); @@ -1153,7 +1153,7 @@ dmn_lnx_thread_write_ip(DMN_LNX_Thread *thread, U64 ip) } internal void -dmn_lnx_thread_write_sp(DMN_LNX_Thread *thread, U64 sp) +lnx_dmn_thread_write_sp(LNX_DMN_Thread *thread, U64 sp) { ARCH_Info *arch_info = arch_info_from_arch(thread->process->ctx->arch); arch_reg_block_write_sp(arch_info, thread->reg_block, sp); @@ -1161,23 +1161,23 @@ dmn_lnx_thread_write_sp(DMN_LNX_Thread *thread, U64 sp) } internal B32 -dmn_lnx_thread_read_reg_block(DMN_LNX_Thread *thread) +lnx_dmn_thread_read_reg_block(LNX_DMN_Thread *thread) { B32 is_reg_block_read = 0; - if(thread->state == DMN_LNX_ThreadState_Stopped) + if(thread->state == LNX_DMN_ThreadState_Stopped) { switch(thread->process->ctx->arch) { default:{}break; case Arch_x64: { - DMN_LNX_ProcessCtx *process_ctx = thread->process->ctx; + LNX_DMN_ProcessCtx *process_ctx = thread->process->ctx; X64_RegBlock *dst = thread->reg_block; // general purpose registers { - OS_LNX_GprsX64 src; - int ptrace_result = OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETREGSET, thread->tid, (void *)NT_PRSTATUS, &(struct iovec){ .iov_len = sizeof(src), .iov_base = &src })); + LNX_DMN_GprsX64 src; + int ptrace_result = LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETREGSET, thread->tid, (void *)NT_PRSTATUS, &(struct iovec){ .iov_len = sizeof(src), .iov_base = &src })); if(ptrace_result < 0) { goto exit; } dst->r15 = src.r15; @@ -1220,7 +1220,7 @@ dmn_lnx_thread_read_reg_block(DMN_LNX_Thread *thread) if(x64_is_xsave_supported()) { void *xsave_raw = push_array(scratch.arena, U8, process_ctx->xsave_size); - int ptrace_result = OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETREGSET, thread->tid, (void *)NT_X86_XSTATE, &(struct iovec){ .iov_len = process_ctx->xsave_size, .iov_base = xsave_raw })); + int ptrace_result = LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETREGSET, thread->tid, (void *)NT_X86_XSTATE, &(struct iovec){ .iov_len = process_ctx->xsave_size, .iov_base = xsave_raw })); if(ptrace_result < 0) { goto exit; } xsave = xsave_raw; fxsave = &xsave->fxsave; @@ -1230,7 +1230,7 @@ dmn_lnx_thread_read_reg_block(DMN_LNX_Thread *thread) if(fxsave == 0) { fxsave = push_array(scratch.arena, X64_FXSave, 1); - int ptrace_result = OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETREGSET, thread->tid, (void *)NT_FPREGSET, &(struct iovec){ .iov_len = sizeof(*fxsave), .iov_base = fxsave })); + int ptrace_result = LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETREGSET, thread->tid, (void *)NT_FPREGSET, &(struct iovec){ .iov_len = sizeof(*fxsave), .iov_base = fxsave })); if(ptrace_result < 0) { goto exit; } fxsave = 0; } @@ -1334,9 +1334,9 @@ dmn_lnx_thread_read_reg_block(DMN_LNX_Thread *thread) { if(n != 4 && n != 5) { - U64 offset = OffsetOf(OS_LNX_UserX64, u_debugreg[n]); + U64 offset = OffsetOf(LNX_DMN_UserX64, u_debugreg[n]); errno = 0; - long peek_result = OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_PEEKUSER, thread->tid, PtrFromInt(offset), 0)); + long peek_result = LNX_RETRY_ON_EINTR(ptrace(PTRACE_PEEKUSER, thread->tid, PtrFromInt(offset), 0)); if(errno != 0) { goto exit; } dr_d[n] = peek_result; } @@ -1352,9 +1352,9 @@ dmn_lnx_thread_read_reg_block(DMN_LNX_Thread *thread) } internal B32 -dmn_lnx_thread_write_reg_block(DMN_LNX_Thread *thread) +lnx_dmn_thread_write_reg_block(LNX_DMN_Thread *thread) { - AssertAlways(thread->state == DMN_LNX_ThreadState_Stopped); + AssertAlways(thread->state == LNX_DMN_ThreadState_Stopped); B32 is_reg_block_written = 0; @@ -1363,12 +1363,12 @@ dmn_lnx_thread_write_reg_block(DMN_LNX_Thread *thread) case Arch_Null: {} break; case Arch_x64: { - DMN_LNX_ProcessCtx *process_ctx = thread->process->ctx; + LNX_DMN_ProcessCtx *process_ctx = thread->process->ctx; X64_RegBlock *src = thread->reg_block; // general purpose registers { - OS_LNX_GprsX64 dst; + LNX_DMN_GprsX64 dst; dst.r15 = src->r15; dst.r14 = src->r14; dst.r13 = src->r13; @@ -1396,7 +1396,7 @@ dmn_lnx_thread_write_reg_block(DMN_LNX_Thread *thread) dst.es = src->es; dst.fs = src->fs; dst.gs = src->gs; - int ptrace_result = OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_SETREGSET, thread->tid, (void *)NT_PRSTATUS, &(struct iovec){ .iov_base = &dst, .iov_len = sizeof(dst) })); + int ptrace_result = LNX_RETRY_ON_EINTR(ptrace(PTRACE_SETREGSET, thread->tid, (void *)NT_PRSTATUS, &(struct iovec){ .iov_base = &dst, .iov_len = sizeof(dst) })); if(ptrace_result < 0) { goto exit; } } @@ -1511,7 +1511,7 @@ dmn_lnx_thread_write_reg_block(DMN_LNX_Thread *thread) // xsave Assert(dst->header.xcomp_bv == 0); // must always be zero - int ptrace_result = OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_SETREGSET, thread->tid, (void *)NT_X86_XSTATE, &(struct iovec){ .iov_base = dst, .iov_len = process_ctx->xsave_size })); + int ptrace_result = LNX_RETRY_ON_EINTR(ptrace(PTRACE_SETREGSET, thread->tid, (void *)NT_X86_XSTATE, &(struct iovec){ .iov_base = dst, .iov_len = process_ctx->xsave_size })); if(ptrace_result < 0) { goto exit; } } @@ -1527,8 +1527,8 @@ dmn_lnx_thread_write_reg_block(DMN_LNX_Thread *thread) { if(n != 4 && n != 5) { - U64 offset = OffsetOf(OS_LNX_UserX64, u_debugreg[n]); - int ptrace_result = OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_POKEUSER, thread->tid, PtrFromInt(offset), (void*)(uintptr_t)dr_s[n])); + U64 offset = OffsetOf(LNX_DMN_UserX64, u_debugreg[n]); + int ptrace_result = LNX_RETRY_ON_EINTR(ptrace(PTRACE_POKEUSER, thread->tid, PtrFromInt(offset), (void*)(uintptr_t)dr_s[n])); if(ptrace_result < 0) { goto exit; } } } @@ -1547,7 +1547,7 @@ dmn_lnx_thread_write_reg_block(DMN_LNX_Thread *thread) } internal B32 -dmn_lnx_set_single_step_flag(DMN_LNX_Thread *thread, B32 is_on) +lnx_dmn_set_single_step_flag(LNX_DMN_Thread *thread, B32 is_on) { B32 is_flag_set = 0; switch(thread->process->ctx->arch) @@ -1571,42 +1571,42 @@ dmn_lnx_set_single_step_flag(DMN_LNX_Thread *thread, B32 is_on) } internal void -dmn_lnx_thread_ptr_list_push_node(DMN_LNX_ThreadPtrList *list, DMN_LNX_ThreadPtrNode *n) +lnx_dmn_thread_ptr_list_push_node(LNX_DMN_ThreadPtrList *list, LNX_DMN_ThreadPtrNode *n) { DLLPushBack(list->first, list->last, n); list->count += 1; } -internal DMN_LNX_ThreadPtrNode * -dmn_lnx_thread_ptr_list_push(Arena *arena, DMN_LNX_ThreadPtrList *list, DMN_LNX_Thread *v) +internal LNX_DMN_ThreadPtrNode * +lnx_dmn_thread_ptr_list_push(Arena *arena, LNX_DMN_ThreadPtrList *list, LNX_DMN_Thread *v) { - DMN_LNX_ThreadPtrNode *n = push_array(arena, DMN_LNX_ThreadPtrNode, 1); + LNX_DMN_ThreadPtrNode *n = push_array(arena, LNX_DMN_ThreadPtrNode, 1); n->v = v; - dmn_lnx_thread_ptr_list_push_node(list, n); + lnx_dmn_thread_ptr_list_push_node(list, n); return n; } internal void -dmn_lnx_thread_ptr_list_remove(DMN_LNX_ThreadPtrList *list, DMN_LNX_ThreadPtrNode *n) +lnx_dmn_thread_ptr_list_remove(LNX_DMN_ThreadPtrList *list, LNX_DMN_ThreadPtrNode *n) { DLLRemove(list->first, list->last, n); list->count -= 1; } -internal DMN_LNX_ModulePtrNode * -dmn_lnx_module_ptr_list_push(Arena *arena, DMN_LNX_ModulePtrList *list, DMN_LNX_Module *v) +internal LNX_DMN_ModulePtrNode * +lnx_dmn_module_ptr_list_push(Arena *arena, LNX_DMN_ModulePtrList *list, LNX_DMN_Module *v) { - DMN_LNX_ModulePtrNode *n = push_array(arena, DMN_LNX_ModulePtrNode, 1); + LNX_DMN_ModulePtrNode *n = push_array(arena, LNX_DMN_ModulePtrNode, 1); n->v = v; SLLQueuePush(list->first, list->last, n); list->count += 1; return n; } -internal DMN_LNX_ProcessPtrNode * -dmn_lnx_process_ptr_list_push(Arena *arena, DMN_LNX_ProcessPtrList *list, DMN_LNX_Process *v) +internal LNX_DMN_ProcessPtrNode * +lnx_dmn_process_ptr_list_push(Arena *arena, LNX_DMN_ProcessPtrList *list, LNX_DMN_Process *v) { - DMN_LNX_ProcessPtrNode *n = push_array(arena, DMN_LNX_ProcessPtrNode, 1); + LNX_DMN_ProcessPtrNode *n = push_array(arena, LNX_DMN_ProcessPtrNode, 1); n->v = v; SLLQueuePush(list->first, list->last, n); list->count += 1; @@ -1614,59 +1614,59 @@ dmn_lnx_process_ptr_list_push(Arena *arena, DMN_LNX_ProcessPtrList *list, DMN_LN } internal void -dmn_lnx_push_event_create_process(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process) +lnx_dmn_push_event_create_process(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process) { // push create process event DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_CreateProcess; - e->process = dmn_lnx_handle_from_process(process); + e->process = lnx_dmn_handle_from_process(process); e->arch = process->ctx->arch; e->code = process->pid; e->tls_model = DMN_TlsModel_Gnu; // TODO: use dynamic linker path to figure out correct enum here } internal void -dmn_lnx_push_event_exit_process(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process) +lnx_dmn_push_event_exit_process(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process) { DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_ExitProcess; - e->process = dmn_lnx_handle_from_process(process); + e->process = lnx_dmn_handle_from_process(process); e->code = process->main_thread_exit_code; } internal void -dmn_lnx_push_event_create_thread(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread) +lnx_dmn_push_event_create_thread(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread) { DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_CreateThread; - e->process = dmn_lnx_handle_from_process(thread->process); - e->thread = dmn_lnx_handle_from_thread(thread); + e->process = lnx_dmn_handle_from_process(thread->process); + e->thread = lnx_dmn_handle_from_thread(thread); e->arch = thread->process->ctx->arch; e->code = thread->tid; } internal void -dmn_lnx_push_event_exit_thread(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread, U64 exit_code) +lnx_dmn_push_event_exit_thread(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread, U64 exit_code) { DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_ExitThread; - e->process = dmn_lnx_handle_from_process(thread->process); - e->thread = dmn_lnx_handle_from_thread(thread); + e->process = lnx_dmn_handle_from_process(thread->process); + e->thread = lnx_dmn_handle_from_thread(thread); e->code = exit_code; } internal void -dmn_lnx_push_event_load_module(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread, DMN_LNX_Module *module) +lnx_dmn_push_event_load_module(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread, LNX_DMN_Module *module) { // TODO: reporting this module breaks ctrl thread - String8 module_name = dmn_lnx_read_string(arena, thread->process->fd, module->name_vaddr); + String8 module_name = lnx_dmn_read_string(arena, thread->process->fd, module->name_vaddr); if(!str8_match(module_name, str8_lit("linux-vdso.so.1"), 0)) { DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_LoadModule; - e->process = dmn_lnx_handle_from_process(thread->process); - e->thread = dmn_lnx_handle_from_thread(thread); - e->module = dmn_lnx_handle_from_module(module); + e->process = lnx_dmn_handle_from_process(thread->process); + e->thread = lnx_dmn_handle_from_thread(thread); + e->module = lnx_dmn_handle_from_module(module); e->arch = thread->process->ctx->arch; e->address = module->base_vaddr; e->size = module->size; @@ -1679,46 +1679,46 @@ dmn_lnx_push_event_load_module(Arena *arena, DMN_EventList *events, DMN_LNX_Thre } internal void -dmn_lnx_push_event_unload_module(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process, DMN_LNX_Module *module) +lnx_dmn_push_event_unload_module(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process, LNX_DMN_Module *module) { DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_UnloadModule; - e->process = dmn_lnx_handle_from_process(process); - e->module = dmn_lnx_handle_from_module(module); + e->process = lnx_dmn_handle_from_process(process); + e->module = lnx_dmn_handle_from_module(module); } internal void -dmn_lnx_push_event_handshake_complete(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process) +lnx_dmn_push_event_handshake_complete(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process) { DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_HandshakeComplete; - e->process = dmn_lnx_handle_from_process(process); - e->thread = dmn_lnx_handle_from_thread(process->first_thread); + e->process = lnx_dmn_handle_from_process(process); + e->thread = lnx_dmn_handle_from_thread(process->first_thread); e->arch = process->ctx->arch; } internal void -dmn_lnx_push_event_breakpoint(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread, U64 address) +lnx_dmn_push_event_breakpoint(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread, U64 address) { DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_Breakpoint; - e->process = dmn_lnx_handle_from_process(thread->process); - e->thread = dmn_lnx_handle_from_thread(thread); + e->process = lnx_dmn_handle_from_process(thread->process); + e->thread = lnx_dmn_handle_from_thread(thread); e->instruction_pointer = address; } internal void -dmn_lnx_push_event_single_step(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread) +lnx_dmn_push_event_single_step(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread) { DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_SingleStep; - e->process = dmn_lnx_handle_from_process(thread->process); - e->thread = dmn_lnx_handle_from_thread(thread); - e->instruction_pointer = dmn_lnx_thread_read_ip(thread); + e->process = lnx_dmn_handle_from_process(thread->process); + e->thread = lnx_dmn_handle_from_thread(thread); + e->instruction_pointer = lnx_dmn_thread_read_ip(thread); } internal void -dmn_lnx_push_event_exception(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread, U64 signo) +lnx_dmn_push_event_exception(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread, U64 signo) { local_persist B8 is_repeatable[] = { @@ -1759,48 +1759,48 @@ dmn_lnx_push_event_exception(Arena *arena, DMN_EventList *events, DMN_LNX_Thread DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_Exception; - e->process = dmn_lnx_handle_from_process(thread->process); - e->thread = dmn_lnx_handle_from_thread(thread); - e->instruction_pointer = dmn_lnx_thread_read_ip(thread); + e->process = lnx_dmn_handle_from_process(thread->process); + e->thread = lnx_dmn_handle_from_thread(thread); + e->instruction_pointer = lnx_dmn_thread_read_ip(thread); e->signo = signo; e->exception_repeated = signo < ArrayCount(is_repeatable) ? is_repeatable[signo] : 0; if(signo == SIGSEGV) { siginfo_t si = {0}; - OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETSIGINFO, thread->tid, 0, &si)); + LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETSIGINFO, thread->tid, 0, &si)); e->address = (U64)si.si_addr; } } internal void -dmn_lnx_push_event_halt(Arena *arena, DMN_EventList *events) +lnx_dmn_push_event_halt(Arena *arena, DMN_EventList *events) { DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_Halt; } internal void -dmn_lnx_push_event_not_attached(Arena *arena, DMN_EventList *events) +lnx_dmn_push_event_not_attached(Arena *arena, DMN_EventList *events) { DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_Error; e->error_kind = DMN_ErrorKind_NotAttached; } -internal DMN_LNX_Thread * -dmn_lnx_event_create_thread(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process, pid_t tid) +internal LNX_DMN_Thread * +lnx_dmn_event_create_thread(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process, pid_t tid) { - DMN_LNX_Thread *thread = dmn_lnx_thread_alloc(process, DMN_LNX_ThreadState_Stopped, tid); - dmn_lnx_push_event_create_thread(arena, events, thread); + LNX_DMN_Thread *thread = lnx_dmn_thread_alloc(process, LNX_DMN_ThreadState_Stopped, tid); + lnx_dmn_push_event_create_thread(arena, events, thread); return thread; } internal void -dmn_lnx_event_exit_thread(Arena *arena, DMN_EventList *events, pid_t tid, U64 exit_code) +lnx_dmn_event_exit_thread(Arena *arena, DMN_EventList *events, pid_t tid, U64 exit_code) { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_pid(tid); - DMN_LNX_Process *process = thread->process; + LNX_DMN_Thread *thread = lnx_dmn_thread_from_pid(tid); + LNX_DMN_Process *process = thread->process; // store main thread's exit code if(thread->tid == thread->process->pid) @@ -1809,139 +1809,139 @@ dmn_lnx_event_exit_thread(Arena *arena, DMN_EventList *events, pid_t tid, U64 ex } // push exit event - dmn_lnx_push_event_exit_thread(arena, events, thread, exit_code); + lnx_dmn_push_event_exit_thread(arena, events, thread, exit_code); // release entity - dmn_lnx_thread_release(thread); + lnx_dmn_thread_release(thread); // auto exit process on last thread if(process->thread_count == 0) { - dmn_lnx_event_exit_process(arena, events, process->pid); + lnx_dmn_event_exit_process(arena, events, process->pid); } } -internal DMN_LNX_Process * -dmn_lnx_event_create_process(Arena *arena, DMN_EventList *events, pid_t pid, DMN_LNX_Process *parent_process, DMN_LNX_CreateProcessFlags flags) +internal LNX_DMN_Process * +lnx_dmn_event_create_process(Arena *arena, DMN_EventList *events, pid_t pid, LNX_DMN_Process *parent_process, LNX_DMN_CreateProcessFlags flags) { - DMN_LNX_Process *process = dmn_lnx_process_alloc(pid, DMN_LNX_ProcessState_Normal, parent_process, !!(flags & DMN_LNX_CreateProcessFlag_DebugSubprocesses), !!(flags & DMN_LNX_CreateProcessFlag_Cow)); + LNX_DMN_Process *process = lnx_dmn_process_alloc(pid, LNX_DMN_ProcessState_Normal, parent_process, !!(flags & LNX_DMN_CreateProcessFlag_DebugSubprocesses), !!(flags & LNX_DMN_CreateProcessFlag_Cow)); - if(flags & DMN_LNX_CreateProcessFlag_ClonedMemory) + if(flags & LNX_DMN_CreateProcessFlag_ClonedMemory) { process->ctx = parent_process->ctx; } else { - process->ctx = dmn_lnx_process_ctx_alloc(process, !!(flags & DMN_LNX_CreateProcessFlag_Rebased)); + process->ctx = lnx_dmn_process_ctx_alloc(process, !!(flags & LNX_DMN_CreateProcessFlag_Rebased)); } process->ctx->ref_count += 1; // install probes in a process that does not have a cloned memory - if(!(flags & DMN_LNX_CreateProcessFlag_ClonedMemory)) + if(!(flags & LNX_DMN_CreateProcessFlag_ClonedMemory)) { - dmn_lnx_process_trap_probes(process); + lnx_dmn_process_trap_probes(process); } // create main thread - dmn_lnx_thread_alloc(process, DMN_LNX_ThreadState_Stopped, pid); + lnx_dmn_thread_alloc(process, LNX_DMN_ThreadState_Stopped, pid); // push events - dmn_lnx_push_event_create_process(arena, events, process); - for EachNode(thread, DMN_LNX_Thread, process->first_thread) + lnx_dmn_push_event_create_process(arena, events, process); + for EachNode(thread, LNX_DMN_Thread, process->first_thread) { - dmn_lnx_push_event_create_thread(arena, events, thread); + lnx_dmn_push_event_create_thread(arena, events, thread); } - for EachNode(module, DMN_LNX_Module, process->ctx->first_module) + for EachNode(module, LNX_DMN_Module, process->ctx->first_module) { - dmn_lnx_push_event_load_module(arena, events, process->first_thread, module); + lnx_dmn_push_event_load_module(arena, events, process->first_thread, module); } - dmn_lnx_push_event_handshake_complete(arena, events, process); + lnx_dmn_push_event_handshake_complete(arena, events, process); return process; } internal void -dmn_lnx_event_exit_process(Arena *arena, DMN_EventList *events, pid_t pid) +lnx_dmn_event_exit_process(Arena *arena, DMN_EventList *events, pid_t pid) { - DMN_LNX_Process *process = dmn_lnx_process_from_pid(pid); + LNX_DMN_Process *process = lnx_dmn_process_from_pid(pid); AssertAlways(process->thread_count == 0); // push module events - for EachNode(module, DMN_LNX_Module, process->ctx->first_module) + for EachNode(module, LNX_DMN_Module, process->ctx->first_module) { - dmn_lnx_push_event_unload_module(arena, events, process, module); + lnx_dmn_push_event_unload_module(arena, events, process, module); } // push process exit event - dmn_lnx_push_event_exit_process(arena, events, process); + lnx_dmn_push_event_exit_process(arena, events, process); // release process - dmn_lnx_process_release(process); + lnx_dmn_process_release(process); } internal void -dmn_lnx_event_load_module(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread, U64 name_space_id, U64 new_link_map_vaddr) +lnx_dmn_event_load_module(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread, U64 name_space_id, U64 new_link_map_vaddr) { - DMN_LNX_Process *process = thread->process; + LNX_DMN_Process *process = thread->process; GNU_LinkMap64 map = {0}; for(U64 map_vaddr = new_link_map_vaddr; map_vaddr != 0; map_vaddr = map.next_vaddr) { // read out new link map item - if(gnu_read_link_map(dmn_lnx_machine_op_mem_read, &process->fd, map_vaddr, process->ctx->dl_class, &map) != MachineOpResult_Ok) { break; } + if(gnu_read_link_map(lnx_dmn_machine_op_mem_read, &process->fd, map_vaddr, process->ctx->dl_class, &map) != MachineOpResult_Ok) { break; } // was module already loaded? - DMN_LNX_Module *module = hash_table_search_u64_raw(process->ctx->loaded_modules_ht, map.addr_vaddr); + LNX_DMN_Module *module = hash_table_search_u64_raw(process->ctx->loaded_modules_ht, map.addr_vaddr); if(module) { continue; } // clone process ctx if(process->is_cow) { process->is_cow = 0; - process->ctx = dmn_lnx_process_ctx_clone(process, process->ctx); + process->ctx = lnx_dmn_process_ctx_clone(process, process->ctx); } // alloc module - module = dmn_lnx_module_alloc(process->ctx, process->fd, map.addr_vaddr, map.name_vaddr, name_space_id, 0); + module = lnx_dmn_module_alloc(process->ctx, process->fd, map.addr_vaddr, map.name_vaddr, name_space_id, 0); // push load module event - dmn_lnx_push_event_load_module(arena, events, thread, module); + lnx_dmn_push_event_load_module(arena, events, thread, module); } } internal void -dmn_lnx_event_unload_module(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process, U64 rdebug_vaddr) +lnx_dmn_event_unload_module(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process, U64 rdebug_vaddr) { Temp scratch = scratch_begin(&arena, 1); - DMN_LNX_ProcessCtx *ctx = process->ctx; + LNX_DMN_ProcessCtx *ctx = process->ctx; // flag every module as inactive - for EachNode(module, DMN_LNX_Module, ctx->first_module) + for EachNode(module, LNX_DMN_Module, ctx->first_module) { module->is_live = 0; } // mark live modules B32 is_64bit = ctx->dl_class == ELF_Class_64; - GNU_RDebugInfoList rdebug_list = gnu_parse_rdebug(scratch.arena, is_64bit, rdebug_vaddr, dmn_lnx_machine_op_mem_read, &process->fd); + GNU_RDebugInfoList rdebug_list = gnu_parse_rdebug(scratch.arena, is_64bit, rdebug_vaddr, lnx_dmn_machine_op_mem_read, &process->fd); for EachNode(rdebug_n, GNU_RDebugInfoNode, rdebug_list.first) { - GNU_LinkMapList link_map_list = gnu_parse_link_map_list(scratch.arena, is_64bit, rdebug_n->v.r_map, dmn_lnx_machine_op_mem_read, &process->fd); + GNU_LinkMapList link_map_list = gnu_parse_link_map_list(scratch.arena, is_64bit, rdebug_n->v.r_map, lnx_dmn_machine_op_mem_read, &process->fd); for EachNode(link_map_n, GNU_LinkMapNode, link_map_list.first) { - DMN_LNX_Module *module = hash_table_search_u64_raw(ctx->loaded_modules_ht, link_map_n->v.addr_vaddr); + LNX_DMN_Module *module = hash_table_search_u64_raw(ctx->loaded_modules_ht, link_map_n->v.addr_vaddr); module->is_live = 1; } } // collect unloaded modules - DMN_LNX_ModulePtrList to_release = {0}; - for EachNode(module, DMN_LNX_Module, ctx->first_module) + LNX_DMN_ModulePtrList to_release = {0}; + for EachNode(module, LNX_DMN_Module, ctx->first_module) { if(!module->is_live) { - dmn_lnx_module_ptr_list_push(scratch.arena, &to_release, module); + lnx_dmn_module_ptr_list_push(scratch.arena, &to_release, module); } } @@ -1951,31 +1951,31 @@ dmn_lnx_event_unload_module(Arena *arena, DMN_EventList *events, DMN_LNX_Process if(process->is_cow) { process->is_cow = 0; - process->ctx = dmn_lnx_process_ctx_clone(process, process->ctx); + process->ctx = lnx_dmn_process_ctx_clone(process, process->ctx); } } // push events and clean up unloaded modules - for EachNode(module_n, DMN_LNX_ModulePtrNode, to_release.first) + for EachNode(module_n, LNX_DMN_ModulePtrNode, to_release.first) { - dmn_lnx_push_event_unload_module(arena, events, process, module_n->v); - dmn_lnx_module_release(process->ctx, module_n->v); + lnx_dmn_push_event_unload_module(arena, events, process, module_n->v); + lnx_dmn_module_release(process->ctx, module_n->v); } scratch_end(scratch); } internal void -dmn_lnx_event_breakpoint(Arena *arena, DMN_EventList *events, DMN_ActiveTrap *user_traps, pid_t tid) +lnx_dmn_event_breakpoint(Arena *arena, DMN_EventList *events, DMN_ActiveTrap *user_traps, pid_t tid) { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_pid(tid); - DMN_LNX_Process *process = thread->process; - U64 ip = dmn_lnx_thread_read_ip(thread); + LNX_DMN_Thread *thread = lnx_dmn_thread_from_pid(tid); + LNX_DMN_Process *process = thread->process; + U64 ip = lnx_dmn_thread_read_ip(thread); // is this user trap? DMN_ActiveTrap *hit_user_trap = 0; { - DMN_Handle process_handle = dmn_lnx_handle_from_process(process); + DMN_Handle process_handle = lnx_dmn_handle_from_process(process); for EachNode(active_trap, DMN_ActiveTrap, user_traps) { if(MemoryCompare(&active_trap->trap->process, &process_handle, sizeof(DMN_Handle)) == 0) @@ -1990,7 +1990,7 @@ dmn_lnx_event_breakpoint(Arena *arena, DMN_EventList *events, DMN_ActiveTrap *us } // is this a probe trap? - DMN_LNX_ProbeType probe_type = DMN_LNX_ProbeType_Null; + LNX_DMN_ProbeType probe_type = LNX_DMN_ProbeType_Null; if(hit_user_trap == 0) { for EachNode(active_trap, DMN_ActiveTrap, process->ctx->first_probe_trap) @@ -2003,77 +2003,77 @@ dmn_lnx_event_breakpoint(Arena *arena, DMN_EventList *events, DMN_ActiveTrap *us } } - if(probe_type == DMN_LNX_ProbeType_InitComplete) + if(probe_type == LNX_DMN_ProbeType_InitComplete) { B32 is_init_completed = 0; - DMN_LNX_Probe *probe = process->ctx->probes[DMN_LNX_ProbeType_InitComplete]; + LNX_DMN_Probe *probe = process->ctx->probes[LNX_DMN_ProbeType_InitComplete]; U64 name_space_id = 0, rdebug_addr = 0; - if(!stap_read_arg_u(probe->args.v[0], process->ctx->arch, thread->reg_block, dmn_lnx_stap_memory_read, process, &name_space_id)) { goto init_complete_exit; } - if(!stap_read_arg_u(probe->args.v[1], process->ctx->arch, thread->reg_block, dmn_lnx_stap_memory_read, process, &rdebug_addr)) { goto init_complete_exit; } + if(!stap_read_arg_u(probe->args.v[0], process->ctx->arch, thread->reg_block, lnx_dmn_stap_memory_read, process, &name_space_id)) { goto init_complete_exit; } + if(!stap_read_arg_u(probe->args.v[1], process->ctx->arch, thread->reg_block, lnx_dmn_stap_memory_read, process, &rdebug_addr)) { goto init_complete_exit; } GNU_RDebugInfo64 rdebug = {0}; - if(gnu_read_r_debug(dmn_lnx_machine_op_mem_read, &process->fd, rdebug_addr, process->ctx->arch, &rdebug) != MachineOpResult_Ok) { goto init_complete_exit; } + if(gnu_read_r_debug(lnx_dmn_machine_op_mem_read, &process->fd, rdebug_addr, process->ctx->arch, &rdebug) != MachineOpResult_Ok) { goto init_complete_exit; } if(rdebug.r_version < 1) { goto init_complete_exit; } - dmn_lnx_event_load_module(arena, events, thread, name_space_id, rdebug.r_map); + lnx_dmn_event_load_module(arena, events, thread, name_space_id, rdebug.r_map); is_init_completed = 1; init_complete_exit:; AssertAlways(is_init_completed); } - else if(probe_type == DMN_LNX_ProbeType_RelocComplete) + else if(probe_type == LNX_DMN_ProbeType_RelocComplete) { B32 is_reloc_completed = 0; - DMN_LNX_Probe *probe = process->ctx->probes[DMN_LNX_ProbeType_RelocComplete]; + LNX_DMN_Probe *probe = process->ctx->probes[LNX_DMN_ProbeType_RelocComplete]; U64 name_space_id = 0, new_link_map_addr = 0; - if(!stap_read_arg_u(probe->args.v[0], process->ctx->arch, thread->reg_block, dmn_lnx_stap_memory_read, process, &name_space_id)) { goto reloc_complete_exit; } - if(!stap_read_arg_u(probe->args.v[2], process->ctx->arch, thread->reg_block, dmn_lnx_stap_memory_read, process, &new_link_map_addr)) { goto reloc_complete_exit; } + if(!stap_read_arg_u(probe->args.v[0], process->ctx->arch, thread->reg_block, lnx_dmn_stap_memory_read, process, &name_space_id)) { goto reloc_complete_exit; } + if(!stap_read_arg_u(probe->args.v[2], process->ctx->arch, thread->reg_block, lnx_dmn_stap_memory_read, process, &new_link_map_addr)) { goto reloc_complete_exit; } - dmn_lnx_event_load_module(arena, events, thread, name_space_id, new_link_map_addr); + lnx_dmn_event_load_module(arena, events, thread, name_space_id, new_link_map_addr); is_reloc_completed = 1; reloc_complete_exit:; AssertAlways(is_reloc_completed); } - else if(probe_type == DMN_LNX_ProbeType_UnmapComplete) + else if(probe_type == LNX_DMN_ProbeType_UnmapComplete) { B32 is_unmap_completed = 0; - DMN_LNX_Probe *probe = process->ctx->probes[DMN_LNX_ProbeType_UnmapComplete]; + LNX_DMN_Probe *probe = process->ctx->probes[LNX_DMN_ProbeType_UnmapComplete]; U64 name_space_id = 0, rdebug_vaddr = 0; - if(!stap_read_arg_u(probe->args.v[0], process->ctx->arch, thread->reg_block, dmn_lnx_stap_memory_read, process, &name_space_id)) { goto unmap_complete_exit; } - if(!stap_read_arg_u(probe->args.v[1], process->ctx->arch, thread->reg_block, dmn_lnx_stap_memory_read, process, &rdebug_vaddr)) { goto unmap_complete_exit; } + if(!stap_read_arg_u(probe->args.v[0], process->ctx->arch, thread->reg_block, lnx_dmn_stap_memory_read, process, &name_space_id)) { goto unmap_complete_exit; } + if(!stap_read_arg_u(probe->args.v[1], process->ctx->arch, thread->reg_block, lnx_dmn_stap_memory_read, process, &rdebug_vaddr)) { goto unmap_complete_exit; } - dmn_lnx_event_unload_module(arena, events, process, rdebug_vaddr); + lnx_dmn_event_unload_module(arena, events, process, rdebug_vaddr); is_unmap_completed = 1; unmap_complete_exit:; AssertAlways(is_unmap_completed); } - if(probe_type == DMN_LNX_ProbeType_Null) + if(probe_type == LNX_DMN_ProbeType_Null) { // rollback IP on user traps if(hit_user_trap) { - U64 ip = dmn_lnx_thread_read_ip(thread); - dmn_lnx_thread_write_ip(thread, ip - 1); + U64 ip = lnx_dmn_thread_read_ip(thread); + lnx_dmn_thread_write_ip(thread, ip - 1); } DMN_Event *e = dmn_event_list_push(arena, events); e->kind = DMN_EventKind_Breakpoint; - e->process = dmn_lnx_handle_from_process(process); - e->thread = dmn_lnx_handle_from_thread(thread); - e->instruction_pointer = dmn_lnx_thread_read_ip(thread); + e->process = lnx_dmn_handle_from_process(process); + e->thread = lnx_dmn_handle_from_thread(thread); + e->instruction_pointer = lnx_dmn_thread_read_ip(thread); } } internal void -dmn_lnx_event_data_breakpoint(Arena *arena, DMN_EventList *events, pid_t tid) +lnx_dmn_event_data_breakpoint(Arena *arena, DMN_EventList *events, pid_t tid) { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_pid(tid); + LNX_DMN_Thread *thread = lnx_dmn_thread_from_pid(tid); B32 is_valid = 1; U64 address = 0; @@ -2108,46 +2108,46 @@ dmn_lnx_event_data_breakpoint(Arena *arena, DMN_EventList *events, pid_t tid) if(is_valid) { - dmn_lnx_push_event_breakpoint(arena, events, thread, address); + lnx_dmn_push_event_breakpoint(arena, events, thread, address); } } internal void -dmn_lnx_event_halt(Arena *arena, DMN_EventList *events) +lnx_dmn_event_halt(Arena *arena, DMN_EventList *events) { - dmn_lnx_push_event_halt(arena, events); + lnx_dmn_push_event_halt(arena, events); } internal void -dmn_lnx_event_single_step(Arena *arena, DMN_EventList *events, pid_t tid) +lnx_dmn_event_single_step(Arena *arena, DMN_EventList *events, pid_t tid) { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_pid(tid); + LNX_DMN_Thread *thread = lnx_dmn_thread_from_pid(tid); // clear single step flag - dmn_lnx_set_single_step_flag(thread, 0); + lnx_dmn_set_single_step_flag(thread, 0); // push event - dmn_lnx_push_event_single_step(arena, events, thread); + lnx_dmn_push_event_single_step(arena, events, thread); } internal void -dmn_lnx_event_exception(Arena *arena, DMN_EventList *events, pid_t tid, U64 signo) +lnx_dmn_event_exception(Arena *arena, DMN_EventList *events, pid_t tid, U64 signo) { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_pid(tid); + LNX_DMN_Thread *thread = lnx_dmn_thread_from_pid(tid); thread->pass_through_signal = 1; thread->pass_through_signo = signo; - dmn_lnx_push_event_exception(arena, events, thread, signo); + lnx_dmn_push_event_exception(arena, events, thread, signo); } -internal DMN_LNX_Process * -dmn_lnx_event_attach(Arena *arena, DMN_EventList *events, pid_t pid) +internal LNX_DMN_Process * +lnx_dmn_event_attach(Arena *arena, DMN_EventList *events, pid_t pid) { Temp scratch = scratch_begin(&arena, 1); // create process - DMN_LNX_Process *process = dmn_lnx_event_create_process(arena, events, pid, 0, DMN_LNX_CreateProcessFlag_DebugSubprocesses|DMN_LNX_CreateProcessFlag_Rebased); + LNX_DMN_Process *process = lnx_dmn_event_create_process(arena, events, pid, 0, LNX_DMN_CreateProcessFlag_DebugSubprocesses|LNX_DMN_CreateProcessFlag_Rebased); // extract threads from /proc/pid/task { @@ -2167,27 +2167,27 @@ dmn_lnx_event_attach(Arena *arena, DMN_EventList *events, pid_t pid) AssertAlways(tid == tid_64); if(tid == pid) { continue; } // main thread was created during create process sequence - dmn_lnx_event_create_thread(arena, events, process, tid); + lnx_dmn_event_create_thread(arena, events, process, tid); } - OS_LNX_RETRY_ON_EINTR(closedir(task_dirp)); + LNX_RETRY_ON_EINTR(closedir(task_dirp)); } } // extract modules from r_debug { B32 is_64bit = process->ctx->dl_class == ELF_Class_64; - GNU_RDebugInfoList rdebug_list = gnu_parse_rdebug(scratch.arena, is_64bit, process->ctx->rdebug_vaddr, dmn_lnx_machine_op_mem_read, &process->fd); + GNU_RDebugInfoList rdebug_list = gnu_parse_rdebug(scratch.arena, is_64bit, process->ctx->rdebug_vaddr, lnx_dmn_machine_op_mem_read, &process->fd); U64 name_space_id = 0; for EachNode(rdebug_n, GNU_RDebugInfoNode, rdebug_list.first) { - dmn_lnx_event_load_module(arena, events, process->first_thread, name_space_id, rdebug_n->v.r_map); + lnx_dmn_event_load_module(arena, events, process->first_thread, name_space_id, rdebug_n->v.r_map); name_space_id += 1; } } // handshake complete - dmn_lnx_push_event_handshake_complete(arena, events, process); + lnx_dmn_push_event_handshake_complete(arena, events, process); scratch_end(scratch); return process; @@ -2199,33 +2199,33 @@ dmn_lnx_event_attach(Arena *arena, DMN_EventList *events, pid_t pid) internal void dmn_init(void) { - if(dmn_lnx_state == 0) + if(lnx_dmn_state == 0) { - local_persist DMN_LNX_State state; - dmn_lnx_state = &state; + local_persist LNX_DMN_State state; + lnx_dmn_state = &state; - dmn_lnx_state->arena = arena_alloc(); - dmn_lnx_state->access_mutex = mutex_alloc(); - dmn_lnx_state->entities_arena = arena_alloc(.reserve_size = GB(32), .commit_size = KB(64), .flags = ArenaFlag_NoChain); - dmn_lnx_state->entities_base = push_array(dmn_lnx_state->entities_arena, DMN_LNX_Entity, 0); - dmn_lnx_state->tid_ht = hash_table_init(dmn_lnx_state->arena, 0x2000); - dmn_lnx_state->pid_ht = hash_table_init(dmn_lnx_state->arena, 0x400); - dmn_lnx_state->halter_mutex = mutex_alloc(); - dmn_lnx_entity_alloc(DMN_LNX_EntityKind_Null); + lnx_dmn_state->arena = arena_alloc(); + lnx_dmn_state->access_mutex = mutex_alloc(); + lnx_dmn_state->entities_arena = arena_alloc(.reserve_size = GB(32), .commit_size = KB(64), .flags = ArenaFlag_NoChain); + lnx_dmn_state->entities_base = push_array(lnx_dmn_state->entities_arena, LNX_DMN_Entity, 0); + lnx_dmn_state->tid_ht = hash_table_init(lnx_dmn_state->arena, 0x2000); + lnx_dmn_state->pid_ht = hash_table_init(lnx_dmn_state->arena, 0x400); + lnx_dmn_state->halter_mutex = mutex_alloc(); + lnx_dmn_entity_alloc(LNX_DMN_EntityKind_Null); // find offsets of TLS index and TLS offset in the link_map struct // // TODO: assuming that target is using same libc version as debugger { - DMN_LNX_DbDesc *tls_modid_desc = dlsym(RTLD_DEFAULT, "_thread_db_link_map_l_tls_modid"); - DMN_LNX_DbDesc *tls_offset_desc = dlsym(RTLD_DEFAULT, "_thread_db_link_map_l_tls_offset"); + LNX_DMN_DbDesc *tls_modid_desc = dlsym(RTLD_DEFAULT, "_thread_db_link_map_l_tls_modid"); + LNX_DMN_DbDesc *tls_offset_desc = dlsym(RTLD_DEFAULT, "_thread_db_link_map_l_tls_offset"); if(tls_modid_desc && tls_offset_desc) { if(tls_modid_desc->bit_size <= 64 && tls_offset_desc->bit_size <= 64) { - dmn_lnx_state->tls_modid_desc = *tls_modid_desc; - dmn_lnx_state->tls_offset_desc = *tls_offset_desc; - dmn_lnx_state->is_tls_detected = 1; + lnx_dmn_state->tls_modid_desc = *tls_modid_desc; + lnx_dmn_state->tls_offset_desc = *tls_offset_desc; + lnx_dmn_state->is_tls_detected = 1; } else { Assert(0 && "invalid TLS desc"); } } @@ -2240,25 +2240,25 @@ internal DMN_CtrlCtx * dmn_ctrl_begin(void) { DMN_CtrlCtx *ctx = (DMN_CtrlCtx *)1; - dmn_lnx_ctrl_thread = 1; + lnx_dmn_ctrl_thread = 1; return ctx; } internal void dmn_ctrl_exclusive_access_begin(void) { - MutexScope(dmn_lnx_state->access_mutex) + MutexScope(lnx_dmn_state->access_mutex) { - dmn_lnx_state->access_run_state = 1; + lnx_dmn_state->access_run_state = 1; } } internal void dmn_ctrl_exclusive_access_end(void) { - MutexScope(dmn_lnx_state->access_mutex) + MutexScope(lnx_dmn_state->access_mutex) { - dmn_lnx_state->access_run_state = 0; + lnx_dmn_state->access_run_state = 0; } } @@ -2305,13 +2305,13 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, ProcessLaunchParams *params) if(pid == 0) { // wait for seize - if(OS_LNX_RETRY_ON_EINTR(raise(SIGSTOP)) < 0) { goto child_exit; } + if(LNX_RETRY_ON_EINTR(raise(SIGSTOP)) < 0) { goto child_exit; } // change work directory to tracee - if(OS_LNX_RETRY_ON_EINTR(chdir(work_dir_path)) < 0) { goto child_exit; } + if(LNX_RETRY_ON_EINTR(chdir(work_dir_path)) < 0) { goto child_exit; } // replace process with target program - if(OS_LNX_RETRY_ON_EINTR(execve(argv[0], argv, envp)) < 0) { goto child_exit; } + if(LNX_RETRY_ON_EINTR(execve(argv[0], argv, envp)) < 0) { goto child_exit; } child_exit:; exit(0); @@ -2320,16 +2320,16 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, ProcessLaunchParams *params) else if(pid > 0) { // try to seize child process - if(dmn_lnx_ptrace_seize(pid) >= 0) + if(lnx_dmn_ptrace_seize(pid) >= 0) { // tracee was successfully seized, create process - dmn_lnx_process_alloc(pid, DMN_LNX_ProcessState_Launch, 0, params->debug_subprocesses, 0); + lnx_dmn_process_alloc(pid, LNX_DMN_ProcessState_Launch, 0, params->debug_subprocesses, 0); } else { Assert(0 && "failed to ptrace child process"); - OS_LNX_RETRY_ON_EINTR(kill(SIGKILL, pid)); - OS_LNX_RETRY_ON_EINTR(waitpid(pid, 0, WNOHANG)); + LNX_RETRY_ON_EINTR(kill(SIGKILL, pid)); + LNX_RETRY_ON_EINTR(waitpid(pid, 0, WNOHANG)); pid = 0; } } @@ -2342,16 +2342,16 @@ internal B32 dmn_ctrl_attach(DMN_CtrlCtx *ctx, U32 pid) { B32 is_attached = 0; - if(dmn_lnx_ptrace_seize(pid) >= 0) + if(lnx_dmn_ptrace_seize(pid) >= 0) { - if(OS_LNX_RETRY_ON_EINTR(kill(pid, SIGSTOP)) >= 0) + if(LNX_RETRY_ON_EINTR(kill(pid, SIGSTOP)) >= 0) { - dmn_lnx_process_alloc(pid, DMN_LNX_ProcessState_Attach, 0, 1, 0); + lnx_dmn_process_alloc(pid, LNX_DMN_ProcessState_Attach, 0, 1, 0); is_attached = 1; } else { - OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_DETACH, pid, 0, 0)); + LNX_RETRY_ON_EINTR(ptrace(PTRACE_DETACH, pid, 0, 0)); } } return is_attached; @@ -2361,13 +2361,13 @@ internal B32 dmn_ctrl_kill(DMN_CtrlCtx *ctx, DMN_Handle process_handle, U32 exit_code) { B32 result = 0; - mutex_take(dmn_lnx_state->halter_mutex); - DMN_LNX_Process *process = dmn_lnx_process_from_handle(process_handle); + mutex_take(lnx_dmn_state->halter_mutex); + LNX_DMN_Process *process = lnx_dmn_process_from_handle(process_handle); if(process) { - result = OS_LNX_RETRY_ON_EINTR(kill(process->pid, SIGKILL)) >= 0; + result = LNX_RETRY_ON_EINTR(kill(process->pid, SIGKILL)) >= 0; } - mutex_drop(dmn_lnx_state->halter_mutex); + mutex_drop(lnx_dmn_state->halter_mutex); return result; } @@ -2375,13 +2375,13 @@ internal B32 dmn_ctrl_detach(DMN_CtrlCtx *ctx, DMN_Handle process_handle) { B32 result = 0; - mutex_take(dmn_lnx_state->halter_mutex); - DMN_LNX_Process *process = dmn_lnx_process_from_handle(process_handle); + mutex_take(lnx_dmn_state->halter_mutex); + LNX_DMN_Process *process = lnx_dmn_process_from_handle(process_handle); if(process) { - result = OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_DETACH, process->pid, 0, 0)) >= 0; + result = LNX_RETRY_ON_EINTR(ptrace(PTRACE_DETACH, process->pid, 0, 0)) >= 0; } - mutex_drop(dmn_lnx_state->halter_mutex); + mutex_drop(lnx_dmn_state->halter_mutex); return result; } @@ -2391,15 +2391,15 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) Temp scratch = scratch_begin(&arena, 1); DMN_EventList events = {0}; - mutex_take(dmn_lnx_state->halter_mutex); + mutex_take(lnx_dmn_state->halter_mutex); // wait for signals from the running threads - if(dmn_lnx_state->process_count > 0) + if(lnx_dmn_state->process_count > 0) { // write traps to memory DMN_ActiveTrap *active_trap_first = 0, *active_trap_last = 0; { - HashTable *process_ht = hash_table_init(scratch.arena, dmn_lnx_state->process_count); + HashTable *process_ht = hash_table_init(scratch.arena, lnx_dmn_state->process_count); for EachNode(n, DMN_TrapChunkNode, ctrls->traps.first) { for EachIndex(n_idx, n->count) @@ -2420,7 +2420,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) if(is_set) { continue; } // TODO: ctrl sends down traps for exited process - DMN_LNX_Process *process = dmn_lnx_process_from_handle(trap->process); + LNX_DMN_Process *process = lnx_dmn_process_from_handle(trap->process); if(!process) { continue; } // trap instruction @@ -2438,10 +2438,10 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // enable single stepping if(!dmn_handle_match(ctrls->single_step_thread, dmn_handle_zero())) { - DMN_LNX_Thread *single_step_thread = dmn_lnx_thread_from_handle(ctrls->single_step_thread); + LNX_DMN_Thread *single_step_thread = lnx_dmn_thread_from_handle(ctrls->single_step_thread); if(single_step_thread) { - dmn_lnx_set_single_step_flag(single_step_thread, 1); + lnx_dmn_set_single_step_flag(single_step_thread, 1); } else { @@ -2450,9 +2450,9 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } // schedule threads to run - DMN_LNX_ThreadPtrList running_threads = {0}; + LNX_DMN_ThreadPtrList running_threads = {0}; { - for EachNode(process, DMN_LNX_Process, dmn_lnx_state->first_process) + for EachNode(process, LNX_DMN_Process, lnx_dmn_state->first_process) { //- rjf: determine if this process is frozen B32 process_is_frozen = 0; @@ -2460,7 +2460,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { for EachIndex(idx, ctrls->run_entity_count) { - if(dmn_handle_match(ctrls->run_entities[idx], dmn_lnx_handle_from_process(process))) + if(dmn_handle_match(ctrls->run_entities[idx], lnx_dmn_handle_from_process(process))) { process_is_frozen = 1; break; @@ -2468,7 +2468,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } } - for EachNode(thread, DMN_LNX_Thread, process->first_thread) + for EachNode(thread, LNX_DMN_Thread, process->first_thread) { //- rjf: determine if this thread is frozen B32 is_frozen = 0; @@ -2484,7 +2484,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { for EachIndex(idx, ctrls->run_entity_count) { - if(dmn_handle_match(ctrls->run_entities[idx], dmn_lnx_handle_from_thread(thread))) + if(dmn_handle_match(ctrls->run_entities[idx], lnx_dmn_handle_from_thread(thread))) { is_frozen = 1; break; @@ -2499,18 +2499,18 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // rjf: single-step? freeze if not the single-step thread. else { - is_frozen = !dmn_handle_match(dmn_lnx_handle_from_thread(thread), ctrls->single_step_thread); + is_frozen = !dmn_handle_match(lnx_dmn_handle_from_thread(thread), ctrls->single_step_thread); } // resume thread if(!is_frozen) { - AssertAlways(thread->state == DMN_LNX_ThreadState_Stopped); + AssertAlways(thread->state == LNX_DMN_ThreadState_Stopped); // write registers if(thread->is_reg_block_dirty) { - thread->is_reg_block_dirty = !dmn_lnx_thread_write_reg_block(thread); + thread->is_reg_block_dirty = !lnx_dmn_thread_write_reg_block(thread); } // pass signal to the child process @@ -2525,11 +2525,11 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } // resume thread - if(OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_CONT, thread->tid, 0, sig_code)) >= 0) + if(LNX_RETRY_ON_EINTR(ptrace(PTRACE_CONT, thread->tid, 0, sig_code)) >= 0) { - thread->state = DMN_LNX_ThreadState_Running; + thread->state = LNX_DMN_ThreadState_Running; thread->is_reg_block_dirty = 1; - dmn_lnx_thread_ptr_list_push(scratch.arena, &running_threads, thread); + lnx_dmn_thread_ptr_list_push(scratch.arena, &running_threads, thread); } else { @@ -2555,27 +2555,27 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // hash running threads tids HashTable *running_threads_ht = hash_table_init(scratch.arena, running_threads.count * 2); - for EachNode(n, DMN_LNX_ThreadPtrNode, running_threads.first) + for EachNode(n, LNX_DMN_ThreadPtrNode, running_threads.first) { hash_table_push_u64_raw(scratch.arena, running_threads_ht, n->v->tid, n); } B32 is_halt_done = 0; - DMN_LNX_ThreadPtrList stopped_threads = {0}; + LNX_DMN_ThreadPtrList stopped_threads = {0}; do { // wait for a signal int status = 0; pid_t wait_id = 0; { - mutex_drop(dmn_lnx_state->halter_mutex); + mutex_drop(lnx_dmn_state->halter_mutex); for(;;) { - wait_id = OS_LNX_RETRY_ON_EINTR(waitpid(-1, &status, __WALL|__WNOTHREAD)); + wait_id = LNX_RETRY_ON_EINTR(waitpid(-1, &status, __WALL|__WNOTHREAD)); if(wait_id == -1) { InvalidPath; } // TODO: graceful exit break; } - mutex_take(dmn_lnx_state->halter_mutex); + mutex_take(lnx_dmn_state->halter_mutex); } // unpack status @@ -2587,57 +2587,57 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // intercept initing processes { - DMN_LNX_Process *process = dmn_lnx_process_from_pid(wait_id); + LNX_DMN_Process *process = lnx_dmn_process_from_pid(wait_id); - if(process && process->state != DMN_LNX_ProcessState_Normal) + if(process && process->state != LNX_DMN_ProcessState_Normal) { switch(process->state) { - case DMN_LNX_ProcessState_Null: - case DMN_LNX_ProcessState_Normal: + case LNX_DMN_ProcessState_Null: + case LNX_DMN_ProcessState_Normal: { InvalidPath; } break; - case DMN_LNX_ProcessState_Launch: + case LNX_DMN_ProcessState_Launch: { if(wstopsig == SIGSTOP) { - if(OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_CONT, process->pid, 0, 0)) >= 0) + if(LNX_RETRY_ON_EINTR(ptrace(PTRACE_CONT, process->pid, 0, 0)) >= 0) { - process->state = DMN_LNX_ProcessState_WaitForExec; + process->state = LNX_DMN_ProcessState_WaitForExec; goto wait_for_signal; } else { Assert(0 && "failed to resume tracee"); } } // else { Assert(0 && "unexpected signal"); } } break; - case DMN_LNX_ProcessState_WaitForExec: + case LNX_DMN_ProcessState_WaitForExec: { if(wstopsig == SIGTRAP && event_code == PTRACE_EVENT_EXEC) { - DMN_LNX_CreateProcessFlags create_flags = process->debug_subprocesses ? DMN_LNX_CreateProcessFlag_DebugSubprocesses : 0; - dmn_lnx_process_release(process); - dmn_lnx_event_create_process(arena, &events, wait_id, 0, create_flags); + LNX_DMN_CreateProcessFlags create_flags = process->debug_subprocesses ? LNX_DMN_CreateProcessFlag_DebugSubprocesses : 0; + lnx_dmn_process_release(process); + lnx_dmn_event_create_process(arena, &events, wait_id, 0, create_flags); goto wait_for_signal; } //else { Assert(0 && "unexpected signal"); } } break; - case DMN_LNX_ProcessState_ExecFailedDoExit: + case LNX_DMN_ProcessState_ExecFailedDoExit: { if(wifexited) { - dmn_lnx_process_release(process); + lnx_dmn_process_release(process); goto wait_for_signal; } else { Assert(0 && "unexpected signal"); } } break; - case DMN_LNX_ProcessState_Attach: + case LNX_DMN_ProcessState_Attach: { if(wstopsig == SIGSTOP) { - DMN_LNX_CreateProcessFlags create_flags = process->debug_subprocesses ? DMN_LNX_CreateProcessFlag_DebugSubprocesses : 0; - dmn_lnx_process_release(process); - dmn_lnx_event_create_process(arena, &events, wait_id, 0, create_flags); + LNX_DMN_CreateProcessFlags create_flags = process->debug_subprocesses ? LNX_DMN_CreateProcessFlag_DebugSubprocesses : 0; + lnx_dmn_process_release(process); + lnx_dmn_event_create_process(arena, &events, wait_id, 0, create_flags); goto wait_for_signal; } else { Assert(0 && "unexpected signal"); } @@ -2646,14 +2646,14 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // shutdown process { - if(OS_LNX_RETRY_ON_EINTR(kill(wait_id, SIGKILL)) >= 0) + if(LNX_RETRY_ON_EINTR(kill(wait_id, SIGKILL)) >= 0) { - process->state = DMN_LNX_ProcessState_ExecFailedDoExit; + process->state = LNX_DMN_ProcessState_ExecFailedDoExit; } else { //Assert(0 && "failed to send kill signal to the tracee"); - dmn_lnx_process_release(process); + lnx_dmn_process_release(process); } } @@ -2664,36 +2664,36 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) if(wifstopped || wifsignaled || wifexited) { - DMN_LNX_ThreadPtrNode *thread_n = hash_table_search_u64_raw(running_threads_ht, wait_id); + LNX_DMN_ThreadPtrNode *thread_n = hash_table_search_u64_raw(running_threads_ht, wait_id); if(thread_n) { - DMN_LNX_Thread *thread = thread_n->v; - AssertAlways(thread->state == DMN_LNX_ThreadState_Running); + LNX_DMN_Thread *thread = thread_n->v; + AssertAlways(thread->state == LNX_DMN_ThreadState_Running); // remove mapping hash_table_purge_u64(running_threads_ht, thread->tid); // move thread to the stopped list - dmn_lnx_thread_ptr_list_remove(&running_threads, thread_n); - dmn_lnx_thread_ptr_list_push_node(&stopped_threads, thread_n); + lnx_dmn_thread_ptr_list_remove(&running_threads, thread_n); + lnx_dmn_thread_ptr_list_push_node(&stopped_threads, thread_n); // update thread state if(wifstopped && !wifsignaled && !wifexited) { - thread->state = DMN_LNX_ThreadState_Stopped; + thread->state = LNX_DMN_ThreadState_Stopped; } else if(!wifstopped && (wifsignaled || wifexited)) { - thread->state = DMN_LNX_ThreadState_Exited; + thread->state = LNX_DMN_ThreadState_Exited; } else { InvalidPath; } // stop all other threads if(stopped_threads.count == 1) { - for EachNode(n, DMN_LNX_ThreadPtrNode, running_threads.first) + for EachNode(n, LNX_DMN_ThreadPtrNode, running_threads.first) { - if(OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_INTERRUPT, n->v->tid, 0, 0)) < 0) { Assert(0 && "failed to interrupt process"); } + if(LNX_RETRY_ON_EINTR(ptrace(PTRACE_INTERRUPT, n->v->tid, 0, 0)) < 0) { Assert(0 && "failed to interrupt process"); } } } } @@ -2702,23 +2702,23 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // normal child exit via _exit or exit() if(wifexited) { - dmn_lnx_event_exit_thread(arena, &events, wait_id, WEXITSTATUS(status)); + lnx_dmn_event_exit_thread(arena, &events, wait_id, WEXITSTATUS(status)); } // exit because child did not handle a signal else if(wifsignaled) { - dmn_lnx_event_exit_thread(arena, &events, wait_id, WTERMSIG(status)); + lnx_dmn_event_exit_thread(arena, &events, wait_id, WTERMSIG(status)); } // thread or group stop else if(wifstopped) { // read thread registers { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_pid(wait_id); - if(thread && thread->state != DMN_LNX_ThreadState_PendingCreation) + LNX_DMN_Thread *thread = lnx_dmn_thread_from_pid(wait_id); + if(thread && thread->state != LNX_DMN_ThreadState_PendingCreation) { - thread->is_reg_block_dirty = !dmn_lnx_thread_read_reg_block(thread); + thread->is_reg_block_dirty = !lnx_dmn_thread_read_reg_block(thread); Assert(!thread->is_reg_block_dirty); } } @@ -2731,14 +2731,14 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { // translate signal code to DEMON event siginfo_t siginfo = {0}; - if(OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETSIGINFO, wait_id, 0, &siginfo)) >= 0) + if(LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETSIGINFO, wait_id, 0, &siginfo)) >= 0) { switch(siginfo.si_code) { - case SI_KERNEL: { dmn_lnx_event_breakpoint(arena, &events, active_trap_first, wait_id); } break; - case TRAP_BRKPT: { dmn_lnx_event_breakpoint(arena, &events, active_trap_first, wait_id); } break; - case TRAP_TRACE: { dmn_lnx_event_single_step(arena, &events, wait_id); } break; - case TRAP_HWBKPT: { dmn_lnx_event_data_breakpoint(arena, &events, wait_id); } break; + case SI_KERNEL: { lnx_dmn_event_breakpoint(arena, &events, active_trap_first, wait_id); } break; + case TRAP_BRKPT: { lnx_dmn_event_breakpoint(arena, &events, active_trap_first, wait_id); } break; + case TRAP_TRACE: { lnx_dmn_event_single_step(arena, &events, wait_id); } break; + case TRAP_HWBKPT: { lnx_dmn_event_data_breakpoint(arena, &events, wait_id); } break; case TRAP_BRANCH: { NotImplemented; }break; case TRAP_UNK: { NotImplemented; }break; default: { InvalidPath; } break; @@ -2764,29 +2764,29 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // will be a PTRACE_EVENT_STOP pid_t new_tid; - if(OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETEVENTMSG, wait_id, 0, &new_tid)) >= 0) + if(LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETEVENTMSG, wait_id, 0, &new_tid)) >= 0) { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_pid(wait_id); + LNX_DMN_Thread *thread = lnx_dmn_thread_from_pid(wait_id); // create a new partially inited thread - dmn_lnx_thread_alloc(thread->process, DMN_LNX_ThreadState_PendingCreation, new_tid); + lnx_dmn_thread_alloc(thread->process, LNX_DMN_ThreadState_PendingCreation, new_tid); } else { Assert(0 && "failed to get new tid"); } }break; case PTRACE_EVENT_EXEC: { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_pid(wait_id); - DMN_LNX_Process *process = thread->process; + LNX_DMN_Thread *thread = lnx_dmn_thread_from_pid(wait_id); + LNX_DMN_Process *process = thread->process; if(process->debug_subprocesses) { - dmn_lnx_event_exit_thread(arena, &events, wait_id, 0); - dmn_lnx_event_create_process(arena, &events, wait_id, 0, DMN_LNX_CreateProcessFlag_DebugSubprocesses); + lnx_dmn_event_exit_thread(arena, &events, wait_id, 0); + lnx_dmn_event_create_process(arena, &events, wait_id, 0, LNX_DMN_CreateProcessFlag_DebugSubprocesses); } else { - if(OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_DETACH, wait_id, 0, 0)) >= 0) + if(LNX_RETRY_ON_EINTR(ptrace(PTRACE_DETACH, wait_id, 0, 0)) >= 0) { - dmn_lnx_event_exit_thread(arena, &events, wait_id, 0); + lnx_dmn_event_exit_thread(arena, &events, wait_id, 0); } else { Assert(0 && "failed to detach"); } } @@ -2801,16 +2801,16 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) }break; case PTRACE_EVENT_STOP: { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_pid(wait_id); - if(thread->state == DMN_LNX_ThreadState_PendingCreation) + LNX_DMN_Thread *thread = lnx_dmn_thread_from_pid(wait_id); + if(thread->state == LNX_DMN_ThreadState_PendingCreation) { - DMN_LNX_Process *process = thread->process; - dmn_lnx_thread_release(thread); - thread = dmn_lnx_event_create_thread(arena, &events, process, wait_id); + LNX_DMN_Process *process = thread->process; + lnx_dmn_thread_release(thread); + thread = lnx_dmn_event_create_thread(arena, &events, process, wait_id); } else { - AssertAlways(thread->state == DMN_LNX_ThreadState_Stopped); + AssertAlways(thread->state == LNX_DMN_ThreadState_Stopped); } }break; default: { Assert(0 && "unexpected ptrace code"); } break; @@ -2819,10 +2819,10 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) else if(wstopsig == SIGSTOP) { siginfo_t siginfo = {0}; - if(OS_LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETSIGINFO, wait_id, 0, &siginfo)) >= 0) + if(LNX_RETRY_ON_EINTR(ptrace(PTRACE_GETSIGINFO, wait_id, 0, &siginfo)) >= 0) { // finish halting if this is our SIGSTOP - if(siginfo.si_pid == dmn_lnx_state->halter_tid) + if(siginfo.si_pid == lnx_dmn_state->halter_tid) { is_halt_done = 1; } @@ -2834,30 +2834,30 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } else { - dmn_lnx_event_exception(arena, &events, wait_id, wstopsig); + lnx_dmn_event_exception(arena, &events, wait_id, wstopsig); } } else { Assert(0 && "unexpected stop code"); } - } while(running_threads.count > 0 || dmn_lnx_state->process_pending_creation > 0 || dmn_lnx_state->threads_pending_creation > 0); + } while(running_threads.count > 0 || lnx_dmn_state->process_pending_creation > 0 || lnx_dmn_state->threads_pending_creation > 0); // finalize halter state if(is_halt_done) { // push event - dmn_lnx_event_halt(arena, &events); + lnx_dmn_event_halt(arena, &events); // reset state - dmn_lnx_state->halter_tid = 0; - dmn_lnx_state->halt_code = 0; - dmn_lnx_state->halt_user_data = 0; - dmn_lnx_state->is_halting = 0; + lnx_dmn_state->halter_tid = 0; + lnx_dmn_state->halt_code = 0; + lnx_dmn_state->halt_user_data = 0; + lnx_dmn_state->is_halting = 0; } // restore original instruction bytes for EachNode(active_trap, DMN_ActiveTrap, active_trap_first) { // skip process that exited during the wait - DMN_LNX_Process *process = dmn_lnx_process_from_handle(active_trap->trap->process); + LNX_DMN_Process *process = lnx_dmn_process_from_handle(active_trap->trap->process); if(!process) { continue; } if(!dmn_process_write(active_trap->trap->process, r1u64(active_trap->trap->vaddr, active_trap->trap->vaddr + active_trap->swap_bytes.size), active_trap->swap_bytes.str) && @@ -2870,12 +2870,12 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } } - if(events.count == 0 && dmn_lnx_state->process_count == 0) + if(events.count == 0 && lnx_dmn_state->process_count == 0) { - dmn_lnx_push_event_not_attached(arena, &events); + lnx_dmn_push_event_not_attached(arena, &events); } - mutex_drop(dmn_lnx_state->halter_mutex); + mutex_drop(lnx_dmn_state->halter_mutex); scratch_end(scratch); return events; } @@ -2886,18 +2886,18 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) internal void dmn_halt(U64 code, U64 user_data) { - mutex_take(dmn_lnx_state->halter_mutex); - if(dmn_lnx_state->process_count) + mutex_take(lnx_dmn_state->halter_mutex); + if(lnx_dmn_state->process_count) { - dmn_lnx_state->halter_tid = gettid(); - dmn_lnx_state->halt_code = code; - dmn_lnx_state->halt_user_data = user_data; - for EachNode(process, DMN_LNX_Process, dmn_lnx_state->first_process) + lnx_dmn_state->halter_tid = gettid(); + lnx_dmn_state->halt_code = code; + lnx_dmn_state->halt_user_data = user_data; + for EachNode(process, LNX_DMN_Process, lnx_dmn_state->first_process) { - if(OS_LNX_RETRY_ON_EINTR(kill(process->pid, SIGSTOP)) < 0) { Assert(0 && "failed to send SIGSTOP"); } + if(LNX_RETRY_ON_EINTR(kill(process->pid, SIGSTOP)) < 0) { Assert(0 && "failed to send SIGSTOP"); } } } - mutex_drop(dmn_lnx_state->halter_mutex); + mutex_drop(lnx_dmn_state->halter_mutex); } //////////////////////////////// @@ -2909,14 +2909,14 @@ internal B32 dmn_access_open(void) { B32 result = 0; - if(dmn_lnx_ctrl_thread) + if(lnx_dmn_ctrl_thread) { result = 1; } else { - mutex_take(dmn_lnx_state->access_mutex); - result = !dmn_lnx_state->access_run_state; + mutex_take(lnx_dmn_state->access_mutex); + result = !lnx_dmn_state->access_run_state; } return result; } @@ -2924,9 +2924,9 @@ dmn_access_open(void) internal void dmn_access_close(void) { - if(!dmn_lnx_ctrl_thread) + if(!lnx_dmn_ctrl_thread) { - mutex_drop(dmn_lnx_state->access_mutex); + mutex_drop(lnx_dmn_state->access_mutex); } } @@ -2961,11 +2961,11 @@ dmn_process_memory_protect(DMN_Handle process, U64 vaddr, U64 size, AccessFlags internal U64 dmn_process_read(DMN_Handle process_handle, Rng1U64 range, void *dst) { - DMN_LNX_Process *process = dmn_lnx_process_from_handle(process_handle); + LNX_DMN_Process *process = lnx_dmn_process_from_handle(process_handle); U64 result = 0; if(process) { - result = dmn_lnx_read(process->fd, range, dst); + result = lnx_dmn_read(process->fd, range, dst); } return result; } @@ -2973,11 +2973,11 @@ dmn_process_read(DMN_Handle process_handle, Rng1U64 range, void *dst) internal B32 dmn_process_write(DMN_Handle process_handle, Rng1U64 range, void *src) { - DMN_LNX_Process *process = dmn_lnx_process_from_handle(process_handle); + LNX_DMN_Process *process = lnx_dmn_process_from_handle(process_handle); B32 result = 0; if(process) { - result = dmn_lnx_write(process->fd, range, src); + result = lnx_dmn_write(process->fd, range, src); } return result; } @@ -2988,7 +2988,7 @@ internal Arch dmn_arch_from_thread(DMN_Handle thread_handle) { Arch arch = Arch_Null; - DMN_LNX_Thread *thread = dmn_lnx_thread_from_handle(thread_handle); + LNX_DMN_Thread *thread = lnx_dmn_thread_from_handle(thread_handle); if(thread) { arch = thread->process->ctx->arch; @@ -3008,7 +3008,7 @@ dmn_tls_root_vaddr_from_thread(DMN_Handle thread_handle) U64 tls_root_vaddr = max_U64; DMN_AccessScope { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_handle(thread_handle); + LNX_DMN_Thread *thread = lnx_dmn_thread_from_handle(thread_handle); if(thread) { switch(thread->process->ctx->arch) @@ -3018,7 +3018,7 @@ dmn_tls_root_vaddr_from_thread(DMN_Handle thread_handle) { X64_RegBlock *reg_block = thread->reg_block; U64 dtv_pointer = 0; - if(dmn_lnx_read_struct(thread->process->fd, reg_block->fsbase + 8, &dtv_pointer)) + if(lnx_dmn_read_struct(thread->process->fd, reg_block->fsbase + 8, &dtv_pointer)) { tls_root_vaddr = dtv_pointer; } @@ -3042,7 +3042,7 @@ dmn_thread_read_reg_block(DMN_Handle thread_handle, void *reg_block) B32 result = 0; DMN_AccessScope { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_handle(thread_handle); + LNX_DMN_Thread *thread = lnx_dmn_thread_from_handle(thread_handle); if(thread) { ARCH_Info *arch_info = arch_info_from_arch(thread->process->ctx->arch); @@ -3060,7 +3060,7 @@ dmn_thread_write_reg_block(DMN_Handle thread_handle, void *reg_block) B32 result = 0; DMN_AccessScope { - DMN_LNX_Thread *thread = dmn_lnx_thread_from_handle(thread_handle); + LNX_DMN_Thread *thread = lnx_dmn_thread_from_handle(thread_handle); if(thread) { ARCH_Info *arch_info = arch_info_from_arch(thread->process->ctx->arch); @@ -3122,7 +3122,7 @@ dmn_process_iter_next(Arena *arena, DMN_ProcessIter *iter, DMN_ProcessInfo *info if(got_pid) { pid_t pid = u64_from_str8(pid_string, 10); - String8 name = dmn_lnx_exe_path_from_pid(arena, pid); + String8 name = lnx_dmn_exe_path_from_pid(arena, pid); if(name.size == 0) { name = str8_lit("(unknown process)"); diff --git a/src/linux/demon/linux_demon.h b/src/linux/demon/linux_demon.h index d4308d52..128b34f1 100644 --- a/src/linux/demon/linux_demon.h +++ b/src/linux/demon/linux_demon.h @@ -1,16 +1,16 @@ // Copyright (c) Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -#ifndef DEMON_CORE_LINUX_H -#define DEMON_CORE_LINUX_H +#ifndef LINUX_DEMON_H +#define LINUX_DEMON_H //////////////////////////////// //~ rjf: Register Layouts // // These are defined in , but only for one architecture at a time -typedef struct OS_LNX_GprsX64 OS_LNX_GprsX64; -struct OS_LNX_GprsX64 +typedef struct LNX_DMN_GprsX64 LNX_DMN_GprsX64; +struct LNX_DMN_GprsX64 { U64 r15; U64 r14; @@ -41,10 +41,10 @@ struct OS_LNX_GprsX64 U64 gs; }; -typedef struct OS_LNX_UserX64 OS_LNX_UserX64; -struct OS_LNX_UserX64 +typedef struct LNX_DMN_UserX64 LNX_DMN_UserX64; +struct LNX_DMN_UserX64 { - OS_LNX_GprsX64 regs; + LNX_DMN_GprsX64 regs; S32 u_fpvalid; U32 _pad0; X64_FXSave i387; @@ -62,22 +62,22 @@ struct OS_LNX_UserX64 U8 u_comm[32]; U64 u_debugreg[8]; }; -StaticAssert(sizeof(OS_LNX_UserX64) == 912, g_os_lnx_user_x64_size_check); +StaticAssert(sizeof(LNX_DMN_UserX64) == 912, lnx_user_x64_size_check); //////////////////////////////// //~ TLS -typedef struct DMN_LNX_DbDesc +typedef struct LNX_DMN_DbDesc { U32 bit_size; U32 count; U32 offset; -} DMN_LNX_DbDesc; +} LNX_DMN_DbDesc; //////////////////////////////// //~ SDT Probes -typedef struct DMN_LNX_Probe +typedef struct LNX_DMN_Probe { String8 provider; String8 name; @@ -85,22 +85,22 @@ typedef struct DMN_LNX_Probe STAP_ArgArray args; U64 pc; U64 semaphore; -} DMN_LNX_Probe; +} LNX_DMN_Probe; -typedef struct DMN_LNX_ProbeNode +typedef struct LNX_DMN_ProbeNode { - DMN_LNX_Probe v; - struct DMN_LNX_ProbeNode *next; -} DMN_LNX_ProbeNode; + LNX_DMN_Probe v; + struct LNX_DMN_ProbeNode *next; +} LNX_DMN_ProbeNode; -typedef struct DMN_LNX_ProbeList +typedef struct LNX_DMN_ProbeList { U64 count; - DMN_LNX_ProbeNode *first; - DMN_LNX_ProbeNode *last; -} DMN_LNX_ProbeList; + LNX_DMN_ProbeNode *first; + LNX_DMN_ProbeNode *last; +} LNX_DMN_ProbeList; -#define DMN_LNX_Probe_XList \ +#define LNX_DMN_Probe_XList \ X(InitStart, 2, "init_start") \ X(InitComplete, 2, "init_complete") \ X(RelocStart, 2, "reloc_start") \ @@ -115,17 +115,17 @@ X(SetJmp, 3, "setjmp") typedef enum { - DMN_LNX_ProbeType_Null, -#define X(_N,...) DMN_LNX_ProbeType_##_N, - DMN_LNX_Probe_XList + LNX_DMN_ProbeType_Null, +#define X(_N,...) LNX_DMN_ProbeType_##_N, + LNX_DMN_Probe_XList #undef X - DMN_LNX_ProbeType_Count, -} DMN_LNX_ProbeType; + LNX_DMN_ProbeType_Count, +} LNX_DMN_ProbeType; //////////////////////////////// //~ Process Info -typedef struct DMN_LNX_Auxv +typedef struct LNX_DMN_Auxv { U64 base; U64 phnum; @@ -133,9 +133,9 @@ typedef struct DMN_LNX_Auxv U64 phdr; U64 execfn; U64 pagesz; -} DMN_LNX_Auxv; +} LNX_DMN_Auxv; -typedef struct DMN_LNX_DynamicInfo +typedef struct LNX_DMN_DynamicInfo { U64 hash_vaddr; U64 gnu_hash_vaddr; @@ -143,59 +143,59 @@ typedef struct DMN_LNX_DynamicInfo U64 strtab_size; U64 symtab_vaddr; U64 symtab_entry_size; -} DMN_LNX_DynamicInfo; +} LNX_DMN_DynamicInfo; //////////////////////////////// //~ Entities -typedef enum DMN_LNX_EntityKind +typedef enum LNX_DMN_EntityKind { - DMN_LNX_EntityKind_Null, - DMN_LNX_EntityKind_Process, - DMN_LNX_EntityKind_ProcessCtx, - DMN_LNX_EntityKind_Thread, - DMN_LNX_EntityKind_Module, -} DMN_LNX_EntityKind; + LNX_DMN_EntityKind_Null, + LNX_DMN_EntityKind_Process, + LNX_DMN_EntityKind_ProcessCtx, + LNX_DMN_EntityKind_Thread, + LNX_DMN_EntityKind_Module, +} LNX_DMN_EntityKind; -typedef enum DMN_LNX_ThreadState +typedef enum LNX_DMN_ThreadState { - DMN_LNX_ThreadState_Null, - DMN_LNX_ThreadState_Running, - DMN_LNX_ThreadState_Stopped, - DMN_LNX_ThreadState_Exited, - DMN_LNX_ThreadState_PendingCreation, -} DMN_LNX_ThreadState; + LNX_DMN_ThreadState_Null, + LNX_DMN_ThreadState_Running, + LNX_DMN_ThreadState_Stopped, + LNX_DMN_ThreadState_Exited, + LNX_DMN_ThreadState_PendingCreation, +} LNX_DMN_ThreadState; -typedef struct DMN_LNX_Thread +typedef struct LNX_DMN_Thread { pid_t tid; - DMN_LNX_ThreadState state; - struct DMN_LNX_Process *process; + LNX_DMN_ThreadState state; + struct LNX_DMN_Process *process; void *reg_block; B32 is_reg_block_dirty; B32 pass_through_signal; U64 pass_through_signo; U64 orig_rax; - struct DMN_LNX_Thread *next; - struct DMN_LNX_Thread *prev; -} DMN_LNX_Thread; + struct LNX_DMN_Thread *next; + struct LNX_DMN_Thread *prev; +} LNX_DMN_Thread; -typedef struct DMN_LNX_ThreadPtrNode +typedef struct LNX_DMN_ThreadPtrNode { - DMN_LNX_Thread *v; - struct DMN_LNX_ThreadPtrNode *next; - struct DMN_LNX_ThreadPtrNode *prev; -} DMN_LNX_ThreadPtrNode; + LNX_DMN_Thread *v; + struct LNX_DMN_ThreadPtrNode *next; + struct LNX_DMN_ThreadPtrNode *prev; +} LNX_DMN_ThreadPtrNode; -typedef struct DMN_LNX_ThreadPtrList +typedef struct LNX_DMN_ThreadPtrList { U64 count; - DMN_LNX_ThreadPtrNode *first; - DMN_LNX_ThreadPtrNode *last; -} DMN_LNX_ThreadPtrList; + LNX_DMN_ThreadPtrNode *first; + LNX_DMN_ThreadPtrNode *last; +} LNX_DMN_ThreadPtrList; -typedef struct DMN_LNX_Module +typedef struct LNX_DMN_Module { U64 name_vaddr; U64 base_vaddr; @@ -209,86 +209,86 @@ typedef struct DMN_LNX_Module B8 is_live; B8 is_main; - struct DMN_LNX_Module *next; - struct DMN_LNX_Module *prev; -} DMN_LNX_Module; + struct LNX_DMN_Module *next; + struct LNX_DMN_Module *prev; +} LNX_DMN_Module; -typedef struct DMN_LNX_ModulePtrNode +typedef struct LNX_DMN_ModulePtrNode { - DMN_LNX_Module *v; - struct DMN_LNX_ModulePtrNode *next; -} DMN_LNX_ModulePtrNode; + LNX_DMN_Module *v; + struct LNX_DMN_ModulePtrNode *next; +} LNX_DMN_ModulePtrNode; -typedef struct DMN_LNX_ModulePtrList +typedef struct LNX_DMN_ModulePtrList { U64 count; - DMN_LNX_ModulePtrNode *first; - DMN_LNX_ModulePtrNode *last; -} DMN_LNX_ModulePtrList; + LNX_DMN_ModulePtrNode *first; + LNX_DMN_ModulePtrNode *last; +} LNX_DMN_ModulePtrList; typedef enum { - DMN_LNX_ProcessState_Null, - DMN_LNX_ProcessState_Launch, - DMN_LNX_ProcessState_Attach, - DMN_LNX_ProcessState_WaitForExec, - DMN_LNX_ProcessState_ExecFailedDoExit, - DMN_LNX_ProcessState_Normal, -} DMN_LNX_ProcessState; + LNX_DMN_ProcessState_Null, + LNX_DMN_ProcessState_Launch, + LNX_DMN_ProcessState_Attach, + LNX_DMN_ProcessState_WaitForExec, + LNX_DMN_ProcessState_ExecFailedDoExit, + LNX_DMN_ProcessState_Normal, +} LNX_DMN_ProcessState; typedef enum { - DMN_LNX_CreateProcessFlag_DebugSubprocesses = (1 << 0), - DMN_LNX_CreateProcessFlag_Rebased = (1 << 1), - DMN_LNX_CreateProcessFlag_Cow = (1 << 2), - DMN_LNX_CreateProcessFlag_ClonedMemory = (1 << 3), -} DMN_LNX_CreateProcessFlags; + LNX_DMN_CreateProcessFlag_DebugSubprocesses = (1 << 0), + LNX_DMN_CreateProcessFlag_Rebased = (1 << 1), + LNX_DMN_CreateProcessFlag_Cow = (1 << 2), + LNX_DMN_CreateProcessFlag_ClonedMemory = (1 << 3), +} LNX_DMN_CreateProcessFlags; -typedef struct DMN_LNX_Process +typedef struct LNX_DMN_Process { pid_t pid; int fd; - DMN_LNX_ProcessState state; + LNX_DMN_ProcessState state; B32 debug_subprocesses; B32 is_cow; B32 vfork_with_spoof; U64 thread_count; - DMN_LNX_Thread *first_thread; - DMN_LNX_Thread *last_thread; + LNX_DMN_Thread *first_thread; + LNX_DMN_Thread *last_thread; U64 main_thread_exit_code; - struct DMN_LNX_Process *parent_process; - struct DMN_LNX_ProcessCtx *ctx; + struct LNX_DMN_Process *parent_process; + struct LNX_DMN_ProcessCtx *ctx; - struct DMN_LNX_Process *next; - struct DMN_LNX_Process *prev; -} DMN_LNX_Process; + struct LNX_DMN_Process *next; + struct LNX_DMN_Process *prev; +} LNX_DMN_Process; -typedef struct DMN_LNX_ProcessPtrNode +typedef struct LNX_DMN_ProcessPtrNode { - DMN_LNX_Process *v; - struct DMN_LNX_ProcessPtrNode *next; -} DMN_LNX_ProcessPtrNode; + LNX_DMN_Process *v; + struct LNX_DMN_ProcessPtrNode *next; +} LNX_DMN_ProcessPtrNode; -typedef struct DMN_LNX_ProcessPtrList +typedef struct LNX_DMN_ProcessPtrList { U64 count; - DMN_LNX_ProcessPtrNode *first; - DMN_LNX_ProcessPtrNode *last; -} DMN_LNX_ProcessPtrList; + LNX_DMN_ProcessPtrNode *first; + LNX_DMN_ProcessPtrNode *last; +} LNX_DMN_ProcessPtrList; -typedef struct DMN_LNX_ProcessCtx +typedef struct LNX_DMN_ProcessCtx { Arena *arena; Arch arch; U64 rdebug_vaddr; ELF_Class dl_class; HashTable *loaded_modules_ht; - DMN_LNX_Probe **probes; + LNX_DMN_Probe **probes; DMN_ActiveTrap *first_probe_trap; DMN_ActiveTrap *last_probe_trap; - DMN_LNX_Module *first_module; - DMN_LNX_Module *last_module; + LNX_DMN_Module *first_module; + LNX_DMN_Module *last_module; U64 module_count; U64 ref_count; @@ -299,42 +299,42 @@ typedef struct DMN_LNX_ProcessCtx U64 xcr0; U64 xsave_size; X64_XSaveLayout xsave_layout; -} DMN_LNX_ProcessCtx; +} LNX_DMN_ProcessCtx; -typedef struct DMN_LNX_Entity +typedef struct LNX_DMN_Entity { union { - DMN_LNX_Process process; - DMN_LNX_ProcessCtx process_ctx; - DMN_LNX_Thread thread; - DMN_LNX_Module module; + LNX_DMN_Process process; + LNX_DMN_ProcessCtx process_ctx; + LNX_DMN_Thread thread; + LNX_DMN_Module module; struct { - struct DMN_LNX_Entity *next; + struct LNX_DMN_Entity *next; }; }; U32 gen; - DMN_LNX_EntityKind kind; -} DMN_LNX_Entity; + LNX_DMN_EntityKind kind; +} LNX_DMN_Entity; -typedef struct DMN_LNX_EntityNode +typedef struct LNX_DMN_EntityNode { - DMN_LNX_Entity *v; - struct DMN_LNX_EntityNode *next; -} DMN_LNX_EntityNode; + LNX_DMN_Entity *v; + struct LNX_DMN_EntityNode *next; +} LNX_DMN_EntityNode; -typedef struct DMN_LNX_EntityList +typedef struct LNX_DMN_EntityList { U64 count; - DMN_LNX_EntityNode *first; - DMN_LNX_EntityNode *last; -} DMN_LNX_EntityList; + LNX_DMN_EntityNode *first; + LNX_DMN_EntityNode *last; +} LNX_DMN_EntityList; //////////////////////////////// //~ Global State -typedef struct DMN_LNX_State +typedef struct LNX_DMN_State { Arena *arena; @@ -344,8 +344,8 @@ typedef struct DMN_LNX_State // rjf: entity storage Arena *entities_arena; - DMN_LNX_Entity *entities_base; - DMN_LNX_Entity *free_entity; + LNX_DMN_Entity *entities_base; + LNX_DMN_Entity *free_entity; U64 entities_count; HashTable *tid_ht; // thread id -> thread entity @@ -353,8 +353,8 @@ typedef struct DMN_LNX_State // process tracking U64 process_count; - DMN_LNX_Process *first_process; - DMN_LNX_Process *last_process; + LNX_DMN_Process *first_process; + LNX_DMN_Process *last_process; // process/thread creation tracking U64 process_pending_creation; @@ -369,134 +369,133 @@ typedef struct DMN_LNX_State // TLS B32 is_tls_detected; - DMN_LNX_DbDesc tls_modid_desc; - DMN_LNX_DbDesc tls_offset_desc; -} DMN_LNX_State; + LNX_DMN_DbDesc tls_modid_desc; + LNX_DMN_DbDesc tls_offset_desc; +} LNX_DMN_State; //////////////////////////////// //~ Globals -global B32 dmn_lnx_ctrl_thread; -global DMN_LNX_State *dmn_lnx_state; +global B32 lnx_dmn_ctrl_thread; +global LNX_DMN_State *lnx_dmn_state; //////////////////////////////// //~ Memory R/W -internal U64 dmn_lnx_read(int memory_fd, Rng1U64 range, void *dst); -internal B32 dmn_lnx_write(int memory_fd, Rng1U64 range, void *src); -internal String8 dmn_lnx_read_string_capped(Arena *arena, int memory_fd, U64 base_vaddr, U64 cap_size); -internal String8 dmn_lnx_read_string(Arena *arena, int memory_fd, U64 base_vaddr); -#define dmn_lnx_read_struct(fd, vaddr, ptr) dmn_lnx_read((fd), r1u64((vaddr), (vaddr)+sizeof(*(ptr))), (ptr)) -#define dmn_lnx_write_struct(fd, vaddr, ptr) dmn_lnx_write((fd), r1u64((vaddr), (vaddr)+sizeof(*(ptr))), (ptr)) +internal U64 lnx_dmn_read(int memory_fd, Rng1U64 range, void *dst); +internal B32 lnx_dmn_write(int memory_fd, Rng1U64 range, void *src); +internal String8 lnx_dmn_read_string_capped(Arena *arena, int memory_fd, U64 base_vaddr, U64 cap_size); +internal String8 lnx_dmn_read_string(Arena *arena, int memory_fd, U64 base_vaddr); +#define lnx_dmn_read_struct(fd, vaddr, ptr) lnx_dmn_read((fd), r1u64((vaddr), (vaddr)+sizeof(*(ptr))), (ptr)) +#define lnx_dmn_write_struct(fd, vaddr, ptr) lnx_dmn_write((fd), r1u64((vaddr), (vaddr)+sizeof(*(ptr))), (ptr)) //////////////////////////////// //~ ELF/GNU info -internal Rng1U64 dmn_lnx_compute_image_vrange(int memory_fd, ELF_Class elf_class, U64 rebase, U64 e_phaddr, U64 e_phentsize, U64 e_phnum); -internal DMN_LNX_DynamicInfo dmn_lnx_dynamic_info_from_memory(int memory_fd, ELF_Class elf_Class, U64 rebase, U64 dynamic_vaddr); -internal U64 dmn_lnx_rdebug_vaddr_from_memory(int memory_fd, U64 loader_vaddr, B32 is_rebased); +internal Rng1U64 lnx_dmn_compute_image_vrange(int memory_fd, ELF_Class elf_class, U64 rebase, U64 e_phaddr, U64 e_phentsize, U64 e_phnum); +internal LNX_DMN_DynamicInfo lnx_dmn_dynamic_info_from_memory(int memory_fd, ELF_Class elf_Class, U64 rebase, U64 dynamic_vaddr); +internal U64 lnx_dmn_rdebug_vaddr_from_memory(int memory_fd, U64 loader_vaddr, B32 is_rebased); //////////////////////////////// //~ Process Info -internal String8 dmn_lnx_exe_path_from_pid(Arena *arena, pid_t pid); -internal String8 dmn_lnx_dl_path_from_pid(Arena *arena, pid_t pid, U64 auxv_base); -internal ELF_Hdr64 dmn_lnx_ehdr_from_pid(pid_t pid); -internal DMN_LNX_Auxv dmn_lnx_auxv_from_pid(pid_t pid, ELF_Class elf_class); -internal DMN_LNX_Thread * dmn_lnx_thread_from_pid(pid_t pid); -internal DMN_LNX_Process * dmn_lnx_process_from_pid(pid_t pid); +internal String8 lnx_dmn_exe_path_from_pid(Arena *arena, pid_t pid); +internal String8 lnx_dmn_dl_path_from_pid(Arena *arena, pid_t pid, U64 auxv_base); +internal ELF_Hdr64 lnx_dmn_ehdr_from_pid(pid_t pid); +internal LNX_DMN_Auxv lnx_dmn_auxv_from_pid(pid_t pid, ELF_Class elf_class); +internal LNX_DMN_Thread * lnx_dmn_thread_from_pid(pid_t pid); +internal LNX_DMN_Process * lnx_dmn_process_from_pid(pid_t pid); //////////////////////////////// //~ Entity // alloc -internal DMN_LNX_Entity * dmn_lnx_entity_alloc(DMN_LNX_EntityKind kind); -internal DMN_LNX_Process * dmn_lnx_process_alloc(pid_t pid, DMN_LNX_ProcessState state, DMN_LNX_Process *parent_process, B32 debug_subprocess, B32 is_cow); -internal DMN_LNX_ProcessCtx * dmn_lnx_process_ctx_alloc(DMN_LNX_Process *process, B32 is_rebased); -internal DMN_LNX_Thread * dmn_lnx_thread_alloc(DMN_LNX_Process *process, DMN_LNX_ThreadState thread_state, pid_t tid); -internal DMN_LNX_Module * dmn_lnx_module_alloc(DMN_LNX_ProcessCtx *ctx, int memory_fd, U64 base_vaddr, U64 name_vaddr, U64 name_space_id, B32 is_main); +internal LNX_DMN_Entity * lnx_dmn_entity_alloc(LNX_DMN_EntityKind kind); +internal LNX_DMN_Process * lnx_dmn_process_alloc(pid_t pid, LNX_DMN_ProcessState state, LNX_DMN_Process *parent_process, B32 debug_subprocess, B32 is_cow); +internal LNX_DMN_ProcessCtx * lnx_dmn_process_ctx_alloc(LNX_DMN_Process *process, B32 is_rebased); +internal LNX_DMN_Thread * lnx_dmn_thread_alloc(LNX_DMN_Process *process, LNX_DMN_ThreadState thread_state, pid_t tid); +internal LNX_DMN_Module * lnx_dmn_module_alloc(LNX_DMN_ProcessCtx *ctx, int memory_fd, U64 base_vaddr, U64 name_vaddr, U64 name_space_id, B32 is_main); // release -internal void dmn_lnx_entity_release(DMN_LNX_Entity *entity); -internal void dmn_lnx_process_release(DMN_LNX_Process *process); -internal void dmn_lnx_process_ctx_release(DMN_LNX_ProcessCtx *process_ctx); -internal void dmn_lnx_thread_release(DMN_LNX_Thread *thread); -internal void dmn_lnx_module_release(DMN_LNX_ProcessCtx *ctx, DMN_LNX_Module *module); +internal void lnx_dmn_entity_release(LNX_DMN_Entity *entity); +internal void lnx_dmn_process_release(LNX_DMN_Process *process); +internal void lnx_dmn_process_ctx_release(LNX_DMN_ProcessCtx *process_ctx); +internal void lnx_dmn_thread_release(LNX_DMN_Thread *thread); +internal void lnx_dmn_module_release(LNX_DMN_ProcessCtx *ctx, LNX_DMN_Module *module); // clone -internal DMN_LNX_ProcessCtx * dmn_lnx_process_ctx_clone(DMN_LNX_Process *process, DMN_LNX_ProcessCtx *ctx); -internal DMN_LNX_Module * dmn_lnx_module_clone(DMN_LNX_ProcessCtx *process_ctx, DMN_LNX_Module *module); +internal LNX_DMN_ProcessCtx * lnx_dmn_process_ctx_clone(LNX_DMN_Process *process, LNX_DMN_ProcessCtx *ctx); +internal LNX_DMN_Module * lnx_dmn_module_clone(LNX_DMN_ProcessCtx *process_ctx, LNX_DMN_Module *module); // entity -> handle -internal DMN_Handle dmn_lnx_handle_from_entity(DMN_LNX_Entity *entity); -internal DMN_Handle dmn_lnx_handle_from_process(DMN_LNX_Process *process); -internal DMN_Handle dmn_lnx_handle_from_process_ctx(DMN_LNX_ProcessCtx *process_ctx); -internal DMN_Handle dmn_lnx_handle_from_thread(DMN_LNX_Thread *thread); -internal DMN_Handle dmn_lnx_handle_from_module(DMN_LNX_Module *module); +internal DMN_Handle lnx_dmn_handle_from_entity(LNX_DMN_Entity *entity); +internal DMN_Handle lnx_dmn_handle_from_process(LNX_DMN_Process *process); +internal DMN_Handle lnx_dmn_handle_from_process_ctx(LNX_DMN_ProcessCtx *process_ctx); +internal DMN_Handle lnx_dmn_handle_from_thread(LNX_DMN_Thread *thread); +internal DMN_Handle lnx_dmn_handle_from_module(LNX_DMN_Module *module); // handle -> entity -internal DMN_LNX_Entity * dmn_lnx_entity_from_handle(DMN_Handle handle, DMN_LNX_EntityKind expected_kind); -internal DMN_LNX_Process * dmn_lnx_process_from_handle(DMN_Handle process_handle); -internal DMN_LNX_ProcessCtx * dmn_lnx_process_ctx_from_handle(DMN_Handle process_ctx_handle); -internal DMN_LNX_Thread * dmn_lnx_thread_from_handle(DMN_Handle thread_handle); -internal DMN_LNX_Module * dmn_lnx_module_from_handle(DMN_Handle module_handle); +internal LNX_DMN_Entity * lnx_dmn_entity_from_handle(DMN_Handle handle, LNX_DMN_EntityKind expected_kind); +internal LNX_DMN_Process * lnx_dmn_process_from_handle(DMN_Handle process_handle); +internal LNX_DMN_ProcessCtx * lnx_dmn_process_ctx_from_handle(DMN_Handle process_ctx_handle); +internal LNX_DMN_Thread * lnx_dmn_thread_from_handle(DMN_Handle thread_handle); +internal LNX_DMN_Module * lnx_dmn_module_from_handle(DMN_Handle module_handle); //////////////////////////////// //~ Process Helpers -internal void dmn_lnx_process_trap_probes(DMN_LNX_Process *process); -internal void dmn_lnx_process_untrap_probes(DMN_LNX_Process *process); +internal void lnx_dmn_process_trap_probes(LNX_DMN_Process *process); +internal void lnx_dmn_process_untrap_probes(LNX_DMN_Process *process); //////////////////////////////// //~ Thread Helpers -internal U64 dmn_lnx_thread_read_ip(DMN_LNX_Thread *thread); -internal U64 dmn_lnx_thread_read_sp(DMN_LNX_Thread *thread); -internal void dmn_lnx_thread_write_ip(DMN_LNX_Thread *thread, U64 ip); -internal void dmn_lnx_thread_write_sp(DMN_LNX_Thread *thread, U64 sp); -internal B32 dmn_lnx_thread_read_reg_block(DMN_LNX_Thread *thread); -internal B32 dmn_lnx_thread_write_reg_block(DMN_LNX_Thread *thread); -internal B32 dmn_lnx_set_single_step_flag(DMN_LNX_Thread *thread, B32 is_on); +internal U64 lnx_dmn_thread_read_ip(LNX_DMN_Thread *thread); +internal U64 lnx_dmn_thread_read_sp(LNX_DMN_Thread *thread); +internal void lnx_dmn_thread_write_ip(LNX_DMN_Thread *thread, U64 ip); +internal void lnx_dmn_thread_write_sp(LNX_DMN_Thread *thread, U64 sp); +internal B32 lnx_dmn_thread_read_reg_block(LNX_DMN_Thread *thread); +internal B32 lnx_dmn_thread_write_reg_block(LNX_DMN_Thread *thread); +internal B32 lnx_dmn_set_single_step_flag(LNX_DMN_Thread *thread, B32 is_on); //////////////////////////////// //~ List Helpers -internal void dmn_lnx_thread_ptr_list_push_node(DMN_LNX_ThreadPtrList *list, DMN_LNX_ThreadPtrNode *n); -internal DMN_LNX_ThreadPtrNode * dmn_lnx_thread_ptr_list_push(Arena *arena, DMN_LNX_ThreadPtrList *list, DMN_LNX_Thread *v); -internal DMN_LNX_ModulePtrNode * dmn_lnx_module_ptr_list_push(Arena *arena, DMN_LNX_ModulePtrList *list, DMN_LNX_Module *v); -internal DMN_LNX_ProcessPtrNode * dmn_lnx_process_ptr_list_push(Arena *arena, DMN_LNX_ProcessPtrList *list, DMN_LNX_Process *v); +internal void lnx_dmn_thread_ptr_list_push_node(LNX_DMN_ThreadPtrList *list, LNX_DMN_ThreadPtrNode *n); +internal LNX_DMN_ThreadPtrNode * lnx_dmn_thread_ptr_list_push(Arena *arena, LNX_DMN_ThreadPtrList *list, LNX_DMN_Thread *v); +internal LNX_DMN_ModulePtrNode * lnx_dmn_module_ptr_list_push(Arena *arena, LNX_DMN_ModulePtrList *list, LNX_DMN_Module *v); +internal LNX_DMN_ProcessPtrNode * lnx_dmn_process_ptr_list_push(Arena *arena, LNX_DMN_ProcessPtrList *list, LNX_DMN_Process *v); //////////////////////////////// //~ Debug Event Pushers -internal void dmn_lnx_push_event_create_process(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process); -internal void dmn_lnx_push_event_exit_process(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process); -internal void dmn_lnx_push_event_create_thread(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread); -internal void dmn_lnx_push_event_exit_thread(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread, U64 exit_code); -internal void dmn_lnx_push_event_load_module(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread, DMN_LNX_Module *module); -internal void dmn_lnx_push_event_unload_module(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process, DMN_LNX_Module *module); -internal void dmn_lnx_push_event_handshake_complete(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process); -internal void dmn_lnx_push_event_breakpoint(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread, U64 address); -internal void dmn_lnx_push_event_single_step(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread); -internal void dmn_lnx_push_event_exception(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread, U64 signo); -internal void dmn_lnx_push_event_halt(Arena *arena, DMN_EventList *events); -internal void dmn_lnx_push_event_not_attached(Arena *arena, DMN_EventList *events); +internal void lnx_dmn_push_event_create_process(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process); +internal void lnx_dmn_push_event_exit_process(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process); +internal void lnx_dmn_push_event_create_thread(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread); +internal void lnx_dmn_push_event_exit_thread(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread, U64 exit_code); +internal void lnx_dmn_push_event_load_module(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread, LNX_DMN_Module *module); +internal void lnx_dmn_push_event_unload_module(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process, LNX_DMN_Module *module); +internal void lnx_dmn_push_event_handshake_complete(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process); +internal void lnx_dmn_push_event_breakpoint(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread, U64 address); +internal void lnx_dmn_push_event_single_step(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread); +internal void lnx_dmn_push_event_exception(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread, U64 signo); +internal void lnx_dmn_push_event_halt(Arena *arena, DMN_EventList *events); +internal void lnx_dmn_push_event_not_attached(Arena *arena, DMN_EventList *events); //////////////////////////////// //~ Debug Event -internal DMN_LNX_Thread * dmn_lnx_event_create_thread(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process, pid_t tid); -internal void dmn_lnx_event_exit_thread(Arena *arena, DMN_EventList *events, pid_t tid, U64 exit_code); -internal DMN_LNX_Process * dmn_lnx_event_create_process(Arena *arena, DMN_EventList *events, pid_t pid, DMN_LNX_Process *parent_process, DMN_LNX_CreateProcessFlags flags); -internal void dmn_lnx_event_exit_process(Arena *arena, DMN_EventList *events, pid_t pid); -internal void dmn_lnx_event_load_module(Arena *arena, DMN_EventList *events, DMN_LNX_Thread *thread, U64 name_space_id, U64 new_link_map_vaddr); -internal void dmn_lnx_event_unload_module(Arena *arena, DMN_EventList *events, DMN_LNX_Process *process, U64 rdebug_vaddr); -internal void dmn_lnx_event_breakpoint(Arena *arena, DMN_EventList *events, DMN_ActiveTrap *user_traps, pid_t tid); -internal void dmn_lnx_event_data_breakpoint(Arena *arena, DMN_EventList *events, pid_t tid); -internal void dmn_lnx_event_halt(Arena *arena, DMN_EventList *events); -internal void dmn_lnx_event_single_step(Arena *arena, DMN_EventList *events, pid_t tid); -internal void dmn_lnx_event_exception(Arena *arena, DMN_EventList *events, pid_t tid, U64 signo); -internal DMN_LNX_Process * dmn_lnx_event_attach(Arena *arena, DMN_EventList *events, pid_t pid); - -#endif // DEMON_CORE_LINUX_H +internal LNX_DMN_Thread * lnx_dmn_event_create_thread(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process, pid_t tid); +internal void lnx_dmn_event_exit_thread(Arena *arena, DMN_EventList *events, pid_t tid, U64 exit_code); +internal LNX_DMN_Process * lnx_dmn_event_create_process(Arena *arena, DMN_EventList *events, pid_t pid, LNX_DMN_Process *parent_process, LNX_DMN_CreateProcessFlags flags); +internal void lnx_dmn_event_exit_process(Arena *arena, DMN_EventList *events, pid_t pid); +internal void lnx_dmn_event_load_module(Arena *arena, DMN_EventList *events, LNX_DMN_Thread *thread, U64 name_space_id, U64 new_link_map_vaddr); +internal void lnx_dmn_event_unload_module(Arena *arena, DMN_EventList *events, LNX_DMN_Process *process, U64 rdebug_vaddr); +internal void lnx_dmn_event_breakpoint(Arena *arena, DMN_EventList *events, DMN_ActiveTrap *user_traps, pid_t tid); +internal void lnx_dmn_event_data_breakpoint(Arena *arena, DMN_EventList *events, pid_t tid); +internal void lnx_dmn_event_halt(Arena *arena, DMN_EventList *events); +internal void lnx_dmn_event_single_step(Arena *arena, DMN_EventList *events, pid_t tid); +internal void lnx_dmn_event_exception(Arena *arena, DMN_EventList *events, pid_t tid, U64 signo); +internal LNX_DMN_Process * lnx_dmn_event_attach(Arena *arena, DMN_EventList *events, pid_t pid); +#endif // LINUX_DEMON_H diff --git a/src/linux/window_manager/linux_window_manager.c b/src/linux/window_manager/linux_window_manager.c index 905ddef6..f3726fa0 100644 --- a/src/linux/window_manager/linux_window_manager.c +++ b/src/linux/window_manager/linux_window_manager.c @@ -4,11 +4,11 @@ //////////////////////////////// //~ rjf: Helpers -internal OS_LNX_Window * +internal LNX_WM_Window * os_lnx_window_from_x11window(Window window) { - OS_LNX_Window *result = 0; - for(OS_LNX_Window *w = os_lnx_gfx_state->first_window; w != 0; w = w->next) + LNX_WM_Window *result = 0; + for(LNX_WM_Window *w = os_lnx_gfx_state->first_window; w != 0; w = w->next) { if(w->window == window) { @@ -23,11 +23,11 @@ os_lnx_window_from_x11window(Window window) //~ rjf: @os_hooks Main Initialization API (Implemented Per-OS) internal void -os_gfx_init(void) +wm_init(void) { //- rjf: initialize basics Arena *arena = arena_alloc(); - os_lnx_gfx_state = push_array(arena, OS_LNX_GfxState, 1); + os_lnx_gfx_state = push_array(arena, LNX_WM_GfxState, 1); os_lnx_gfx_state->arena = arena; os_lnx_gfx_state->display = XOpenDisplay(0); @@ -48,20 +48,20 @@ os_gfx_init(void) { struct { - OS_Cursor cursor; + WM_Cursor cursor; unsigned int id; } map[] = { - {OS_Cursor_Pointer, XC_left_ptr}, - {OS_Cursor_IBar, XC_xterm}, - {OS_Cursor_LeftRight, XC_sb_h_double_arrow}, - {OS_Cursor_UpDown, XC_sb_v_double_arrow}, - {OS_Cursor_DownRight, XC_bottom_right_corner}, - {OS_Cursor_UpRight, XC_top_right_corner}, - {OS_Cursor_UpDownLeftRight, XC_fleur}, - {OS_Cursor_HandPoint, XC_hand1}, - {OS_Cursor_Disabled, XC_X_cursor}, + {WM_Cursor_Pointer, XC_left_ptr}, + {WM_Cursor_IBar, XC_xterm}, + {WM_Cursor_LeftRight, XC_sb_h_double_arrow}, + {WM_Cursor_UpDown, XC_sb_v_double_arrow}, + {WM_Cursor_DownRight, XC_bottom_right_corner}, + {WM_Cursor_UpRight, XC_top_right_corner}, + {WM_Cursor_UpDownLeftRight, XC_fleur}, + {WM_Cursor_HandPoint, XC_hand1}, + {WM_Cursor_Disabled, XC_X_cursor}, }; for EachElement(idx, map) { @@ -73,8 +73,8 @@ os_gfx_init(void) //////////////////////////////// //~ rjf: @os_hooks Graphics System Info (Implemented Per-OS) -internal OS_GfxInfo * -os_get_gfx_info(void) +internal WM_SystemInfo * +wm_get_system_info(void) { return &os_lnx_gfx_state->gfx_info; } @@ -83,13 +83,13 @@ os_get_gfx_info(void) //~ rjf: @os_hooks Clipboards (Implemented Per-OS) internal void -os_set_clipboard_text(String8 string) +wm_set_clipboard_text(String8 string) { } internal String8 -os_get_clipboard_text(Arena *arena) +wm_get_clipboard_text(Arena *arena) { String8 result = {0}; return result; @@ -98,20 +98,20 @@ os_get_clipboard_text(Arena *arena) //////////////////////////////// //~ rjf: @os_hooks Windows (Implemented Per-OS) -internal OS_Window -os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title) +internal WM_Window +wm_window_open(Rng2F32 rect, WM_WindowFlags flags, String8 title) { Vec2F32 resolution = dim_2f32(rect); //- rjf: allocate window - OS_LNX_Window *w = os_lnx_gfx_state->free_window; + LNX_WM_Window *w = os_lnx_gfx_state->free_window; if(w) { SLLStackPop(os_lnx_gfx_state->free_window); } else { - w = push_array_no_zero(os_lnx_gfx_state->arena, OS_LNX_Window, 1); + w = push_array_no_zero(os_lnx_gfx_state->arena, LNX_WM_Window, 1); } MemoryZeroStruct(w); DLLPushBack(os_lnx_gfx_state->first_window, os_lnx_gfx_state->last_window, w); @@ -161,50 +161,50 @@ os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title) scratch_end(scratch); //- rjf: convert to handle & return - OS_Window handle = {(U64)w}; + WM_Window handle = {(U64)w}; return handle; } internal void -os_window_close(OS_Window handle) +wm_window_close(WM_Window handle) { - if(os_window_match(handle, os_window_zero())) {return;} - OS_LNX_Window *w = (OS_LNX_Window *)handle.u64[0]; + if(wm_window_match(handle, wm_window_zero())) {return;} + LNX_WM_Window *w = (LNX_WM_Window *)handle.u64[0]; XDestroyWindow(os_lnx_gfx_state->display, w->window); } internal void -os_window_set_title(OS_Window handle, String8 title) +wm_window_set_title(WM_Window handle, String8 title) { - if(os_window_match(handle, os_window_zero())) {return;} + if(wm_window_match(handle, wm_window_zero())) {return;} Temp scratch = scratch_begin(0, 0); - OS_LNX_Window *w = (OS_LNX_Window *)handle.u64[0]; + LNX_WM_Window *w = (LNX_WM_Window *)handle.u64[0]; String8 title_copy = push_str8_copy(scratch.arena, title); XStoreName(os_lnx_gfx_state->display, w->window, (char *)title_copy.str); scratch_end(scratch); } internal void -os_window_first_paint(OS_Window handle) +wm_window_first_paint(WM_Window handle) { - if(os_window_match(handle, os_window_zero())) {return;} - OS_LNX_Window *w = (OS_LNX_Window *)handle.u64[0]; + if(wm_window_match(handle, wm_window_zero())) {return;} + LNX_WM_Window *w = (LNX_WM_Window *)handle.u64[0]; XMapWindow(os_lnx_gfx_state->display, w->window); } internal void -os_window_focus(OS_Window handle) +wm_window_focus(WM_Window handle) { - if(os_window_match(handle, os_window_zero())) {return;} - OS_LNX_Window *w = (OS_LNX_Window *)handle.u64[0]; + if(wm_window_match(handle, wm_window_zero())) {return;} + LNX_WM_Window *w = (LNX_WM_Window *)handle.u64[0]; XSetInputFocus(os_lnx_gfx_state->display, w->window, RevertToNone, CurrentTime); } internal B32 -os_window_is_focused(OS_Window handle) +wm_window_is_focused(WM_Window handle) { - if(os_window_match(handle, os_window_zero())) {return 0;} - OS_LNX_Window *w = (OS_LNX_Window *)handle.u64[0]; + if(wm_window_match(handle, wm_window_zero())) {return 0;} + LNX_WM_Window *w = (LNX_WM_Window *)handle.u64[0]; Window focused_window = 0; int revert_to = 0; XGetInputFocus(os_lnx_gfx_state->display, &focused_window, &revert_to); @@ -213,97 +213,97 @@ os_window_is_focused(OS_Window handle) } internal B32 -os_window_is_fullscreen(OS_Window handle) +wm_window_is_fullscreen(WM_Window handle) { - if(os_window_match(handle, os_window_zero())) {return 0;} + if(wm_window_match(handle, wm_window_zero())) {return 0;} // TODO(rjf) return 0; } internal void -os_window_set_fullscreen(OS_Window handle, B32 fullscreen) +wm_window_set_fullscreen(WM_Window handle, B32 fullscreen) { - if(os_window_match(handle, os_window_zero())) {return;} + if(wm_window_match(handle, wm_window_zero())) {return;} // TODO(rjf) } internal B32 -os_window_is_maximized(OS_Window handle) +wm_window_is_maximized(WM_Window handle) { - if(os_window_match(handle, os_window_zero())) {return 0;} + if(wm_window_match(handle, wm_window_zero())) {return 0;} // TODO(rjf) return 0; } internal void -os_window_set_maximized(OS_Window handle, B32 maximized) +wm_window_set_maximized(WM_Window handle, B32 maximized) { - if(os_window_match(handle, os_window_zero())) {return;} + if(wm_window_match(handle, wm_window_zero())) {return;} // TODO(rjf) } internal B32 -os_window_is_minimized(OS_Window handle) +wm_window_is_minimized(WM_Window handle) { - if(os_window_match(handle, os_window_zero())) {return 0;} + if(wm_window_match(handle, wm_window_zero())) {return 0;} // TODO(rjf) return 0; } internal void -os_window_set_minimized(OS_Window handle, B32 minimized) +wm_window_set_minimized(WM_Window handle, B32 minimized) { - if(os_window_match(handle, os_window_zero())) {return;} + if(wm_window_match(handle, wm_window_zero())) {return;} // TODO(rjf) } internal void -os_window_bring_to_front(OS_Window handle) +wm_window_bring_to_front(WM_Window handle) { - if(os_window_match(handle, os_window_zero())) {return;} + if(wm_window_match(handle, wm_window_zero())) {return;} // TODO(rjf) } internal void -os_window_set_monitor(OS_Window handle, OS_Monitor monitor) +wm_window_set_monitor(WM_Window handle, WM_Monitor monitor) { - if(os_window_match(handle, os_window_zero())) {return;} + if(wm_window_match(handle, wm_window_zero())) {return;} // TODO(rjf) } internal void -os_window_clear_custom_border_data(OS_Window handle) +wm_window_clear_custom_border_data(WM_Window handle) { - if(os_window_match(handle, os_window_zero())) {return;} + if(wm_window_match(handle, wm_window_zero())) {return;} // TODO(rjf) } internal void -os_window_push_custom_title_bar(OS_Window handle, F32 thickness) +wm_window_push_custom_title_bar(WM_Window handle, F32 thickness) { - if(os_window_match(handle, os_window_zero())) {return;} + if(wm_window_match(handle, wm_window_zero())) {return;} // TODO(rjf) } internal void -os_window_push_custom_edges(OS_Window handle, F32 thickness) +wm_window_push_custom_edges(WM_Window handle, F32 thickness) { - if(os_window_match(handle, os_window_zero())) {return;} + if(wm_window_match(handle, wm_window_zero())) {return;} // TODO(rjf) } internal void -os_window_push_custom_title_bar_client_area(OS_Window handle, Rng2F32 rect) +wm_window_push_custom_title_bar_client_area(WM_Window handle, Rng2F32 rect) { - if(os_window_match(handle, os_window_zero())) {return;} + if(wm_window_match(handle, wm_window_zero())) {return;} // TODO(rjf) } internal Rng2F32 -os_rect_from_window(OS_Window handle) +wm_rect_from_window(WM_Window handle) { - if(os_window_match(handle, os_window_zero())) {return r2f32p(0, 0, 0, 0);} - OS_LNX_Window *w = (OS_LNX_Window *)handle.u64[0]; + if(wm_window_match(handle, wm_window_zero())) {return r2f32p(0, 0, 0, 0);} + LNX_WM_Window *w = (LNX_WM_Window *)handle.u64[0]; XWindowAttributes atts = {0}; Status s = XGetWindowAttributes(os_lnx_gfx_state->display, w->window, &atts); Rng2F32 result = r2f32p((F32)atts.x, (F32)atts.y, (F32)atts.x + (F32)atts.width, (F32)atts.y + (F32)atts.height); @@ -311,9 +311,9 @@ os_rect_from_window(OS_Window handle) } internal Rng2F32 -os_client_rect_from_window(OS_Window handle) +wm_client_rect_from_window(WM_Window handle) { - OS_LNX_Window *w = (OS_LNX_Window *)handle.u64[0]; + LNX_WM_Window *w = (LNX_WM_Window *)handle.u64[0]; XWindowAttributes atts = {0}; Status s = XGetWindowAttributes(os_lnx_gfx_state->display, w->window, &atts); Rng2F32 result = r2f32p(0, 0, (F32)atts.width, (F32)atts.height); @@ -321,7 +321,7 @@ os_client_rect_from_window(OS_Window handle) } internal F32 -os_dpi_from_window(OS_Window handle) +wm_dpi_from_window(WM_Window handle) { // TODO(rjf) return 96.f; @@ -330,16 +330,16 @@ os_dpi_from_window(OS_Window handle) //////////////////////////////// //~ rjf: @os_hooks External Windows (Implemented Per-OS) -internal OS_ExternalWindow -os_focused_external_window(void) +internal WM_ExtWindow +wm_focused_external_window(void) { - OS_ExternalWindow result = {0}; + WM_ExtWindow result = {0}; // TODO(rjf) return result; } internal void -os_focus_external_window(OS_ExternalWindow handle) +wm_focus_external_window(WM_ExtWindow handle) { // TODO(rjf) } @@ -347,46 +347,46 @@ os_focus_external_window(OS_ExternalWindow handle) //////////////////////////////// //~ rjf: @os_hooks Monitors (Implemented Per-OS) -internal OS_MonitorArray -os_push_monitors_array(Arena *arena) +internal WM_MonitorArray +wm_push_monitors_array(Arena *arena) { - OS_MonitorArray result = {0}; + WM_MonitorArray result = {0}; // TODO(rjf) return result; } -internal OS_Monitor -os_primary_monitor(void) +internal WM_Monitor +wm_primary_monitor(void) { - OS_Monitor result = {0}; + WM_Monitor result = {0}; // TODO(rjf) return result; } -internal OS_Monitor -os_monitor_from_window(OS_Window window) +internal WM_Monitor +wm_monitor_from_window(WM_Window window) { - OS_Monitor result = {0}; + WM_Monitor result = {0}; // TODO(rjf) return result; } internal String8 -os_name_from_monitor(Arena *arena, OS_Monitor monitor) +wm_name_from_monitor(Arena *arena, WM_Monitor monitor) { // TODO(rjf) return str8_zero(); } internal Vec2F32 -os_dim_from_monitor(OS_Monitor monitor) +wm_dim_from_monitor(WM_Monitor monitor) { // TODO(rjf) return v2f32(0, 0); } internal F32 -os_dpi_from_monitor(OS_Monitor monitor) +wm_dpi_from_monitor(WM_Monitor monitor) { // TODO(rjf) return 96.f; @@ -396,15 +396,15 @@ os_dpi_from_monitor(OS_Monitor monitor) //~ rjf: @os_hooks Events (Implemented Per-OS) internal void -os_send_wakeup_event(void) +wm_send_wakeup_event(void) { // TODO(rjf) } -internal OS_EventList -os_get_events(Arena *arena, B32 wait) +internal WM_EventList +wm_get_events(Arena *arena, B32 wait) { - OS_EventList evts = {0}; + WM_EventList evts = {0}; for(;XPending(os_lnx_gfx_state->display) > 0 || (wait && evts.count == 0);) { XEvent evt = {0}; @@ -419,86 +419,86 @@ os_get_events(Arena *arena, B32 wait) case KeyRelease: { // rjf: determine flags - OS_Modifiers modifiers = 0; - if(evt.xkey.state & ShiftMask) { modifiers |= OS_Modifier_Shift; } - if(evt.xkey.state & ControlMask) { modifiers |= OS_Modifier_Ctrl; } - if(evt.xkey.state & Mod1Mask) { modifiers |= OS_Modifier_Alt; } + WM_Modifiers modifiers = 0; + if(evt.xkey.state & ShiftMask) { modifiers |= WM_Modifier_Shift; } + if(evt.xkey.state & ControlMask) { modifiers |= WM_Modifier_Ctrl; } + if(evt.xkey.state & Mod1Mask) { modifiers |= WM_Modifier_Alt; } // rjf: map keycode -> keysym & codepoint - OS_LNX_Window *window = os_lnx_window_from_x11window(evt.xkey.window); + LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xkey.window); KeySym keysym = 0; U8 text[256] = {0}; U64 text_size = Xutf8LookupString(window->xic, &evt.xkey, (char *)text, sizeof(text), &keysym, 0); - // rjf: map keysym -> OS_Key + // rjf: map keysym -> WM_Key B32 is_right_sided = 0; - OS_Key key = OS_Key_Null; + WM_Key key = WM_Key_Null; switch(keysym) { default: { if(0){} - else if(XK_F1 <= keysym && keysym <= XK_F24) { key = (OS_Key)(OS_Key_F1 + (keysym - XK_F1)); } - else if('0' <= keysym && keysym <= '9') { key = OS_Key_0 + (keysym-'0'); } + else if(XK_F1 <= keysym && keysym <= XK_F24) { key = (WM_Key)(WM_Key_F1 + (keysym - XK_F1)); } + else if('0' <= keysym && keysym <= '9') { key = WM_Key_0 + (keysym-'0'); } }break; - case XK_Escape:{key = OS_Key_Esc;};break; - case XK_BackSpace:{key = OS_Key_Backspace;}break; - case XK_Delete:{key = OS_Key_Delete;}break; - case XK_Return:{key = OS_Key_Return;}break; - case XK_Pause:{key = OS_Key_Pause;}break; - case XK_Tab:{key = OS_Key_Tab;}break; - case XK_Left:{key = OS_Key_Left;}break; - case XK_Right:{key = OS_Key_Right;}break; - case XK_Up:{key = OS_Key_Up;}break; - case XK_Down:{key = OS_Key_Down;}break; - case XK_Home:{key = OS_Key_Home;}break; - case XK_End:{key = OS_Key_End;}break; - case XK_Page_Up:{key = OS_Key_PageUp;}break; - case XK_Page_Down:{key = OS_Key_PageDown;}break; - case XK_Alt_L:{ key = OS_Key_Alt; }break; - case XK_Alt_R:{ key = OS_Key_Alt; is_right_sided = 1;}break; - case XK_Shift_L:{ key = OS_Key_Shift; }break; - case XK_Shift_R:{ key = OS_Key_Shift; is_right_sided = 1;}break; - case XK_Control_L:{ key = OS_Key_Ctrl; }break; - case XK_Control_R:{ key = OS_Key_Ctrl; is_right_sided = 1;}break; - case '-':{key = OS_Key_Minus;}break; - case '=':{key = OS_Key_Equal;}break; - case '[':{key = OS_Key_LeftBracket;}break; - case ']':{key = OS_Key_RightBracket;}break; - case ';':{key = OS_Key_Semicolon;}break; - case '\'':{key = OS_Key_Quote;}break; - case '.':{key = OS_Key_Period;}break; - case ',':{key = OS_Key_Comma;}break; - case '/':{key = OS_Key_Slash;}break; - case '\\':{key = OS_Key_BackSlash;}break; - case '\t':{key = OS_Key_Tab;}break; - case 'a':case 'A':{key = OS_Key_A;}break; - case 'b':case 'B':{key = OS_Key_B;}break; - case 'c':case 'C':{key = OS_Key_C;}break; - case 'd':case 'D':{key = OS_Key_D;}break; - case 'e':case 'E':{key = OS_Key_E;}break; - case 'f':case 'F':{key = OS_Key_F;}break; - case 'g':case 'G':{key = OS_Key_G;}break; - case 'h':case 'H':{key = OS_Key_H;}break; - case 'i':case 'I':{key = OS_Key_I;}break; - case 'j':case 'J':{key = OS_Key_J;}break; - case 'k':case 'K':{key = OS_Key_K;}break; - case 'l':case 'L':{key = OS_Key_L;}break; - case 'm':case 'M':{key = OS_Key_M;}break; - case 'n':case 'N':{key = OS_Key_N;}break; - case 'o':case 'O':{key = OS_Key_O;}break; - case 'p':case 'P':{key = OS_Key_P;}break; - case 'q':case 'Q':{key = OS_Key_Q;}break; - case 'r':case 'R':{key = OS_Key_R;}break; - case 's':case 'S':{key = OS_Key_S;}break; - case 't':case 'T':{key = OS_Key_T;}break; - case 'u':case 'U':{key = OS_Key_U;}break; - case 'v':case 'V':{key = OS_Key_V;}break; - case 'w':case 'W':{key = OS_Key_W;}break; - case 'x':case 'X':{key = OS_Key_X;}break; - case 'y':case 'Y':{key = OS_Key_Y;}break; - case 'z':case 'Z':{key = OS_Key_Z;}break; - case ' ':{key = OS_Key_Space;}break; + case XK_Escape:{key = WM_Key_Esc;};break; + case XK_BackSpace:{key = WM_Key_Backspace;}break; + case XK_Delete:{key = WM_Key_Delete;}break; + case XK_Return:{key = WM_Key_Return;}break; + case XK_Pause:{key = WM_Key_Pause;}break; + case XK_Tab:{key = WM_Key_Tab;}break; + case XK_Left:{key = WM_Key_Left;}break; + case XK_Right:{key = WM_Key_Right;}break; + case XK_Up:{key = WM_Key_Up;}break; + case XK_Down:{key = WM_Key_Down;}break; + case XK_Home:{key = WM_Key_Home;}break; + case XK_End:{key = WM_Key_End;}break; + case XK_Page_Up:{key = WM_Key_PageUp;}break; + case XK_Page_Down:{key = WM_Key_PageDown;}break; + case XK_Alt_L:{ key = WM_Key_Alt; }break; + case XK_Alt_R:{ key = WM_Key_Alt; is_right_sided = 1;}break; + case XK_Shift_L:{ key = WM_Key_Shift; }break; + case XK_Shift_R:{ key = WM_Key_Shift; is_right_sided = 1;}break; + case XK_Control_L:{ key = WM_Key_Ctrl; }break; + case XK_Control_R:{ key = WM_Key_Ctrl; is_right_sided = 1;}break; + case '-':{key = WM_Key_Minus;}break; + case '=':{key = WM_Key_Equal;}break; + case '[':{key = WM_Key_LeftBracket;}break; + case ']':{key = WM_Key_RightBracket;}break; + case ';':{key = WM_Key_Semicolon;}break; + case '\'':{key = WM_Key_Quote;}break; + case '.':{key = WM_Key_Period;}break; + case ',':{key = WM_Key_Comma;}break; + case '/':{key = WM_Key_Slash;}break; + case '\\':{key = WM_Key_BackSlash;}break; + case '\t':{key = WM_Key_Tab;}break; + case 'a':case 'A':{key = WM_Key_A;}break; + case 'b':case 'B':{key = WM_Key_B;}break; + case 'c':case 'C':{key = WM_Key_C;}break; + case 'd':case 'D':{key = WM_Key_D;}break; + case 'e':case 'E':{key = WM_Key_E;}break; + case 'f':case 'F':{key = WM_Key_F;}break; + case 'g':case 'G':{key = WM_Key_G;}break; + case 'h':case 'H':{key = WM_Key_H;}break; + case 'i':case 'I':{key = WM_Key_I;}break; + case 'j':case 'J':{key = WM_Key_J;}break; + case 'k':case 'K':{key = WM_Key_K;}break; + case 'l':case 'L':{key = WM_Key_L;}break; + case 'm':case 'M':{key = WM_Key_M;}break; + case 'n':case 'N':{key = WM_Key_N;}break; + case 'o':case 'O':{key = WM_Key_O;}break; + case 'p':case 'P':{key = WM_Key_P;}break; + case 'q':case 'Q':{key = WM_Key_Q;}break; + case 'r':case 'R':{key = WM_Key_R;}break; + case 's':case 'S':{key = WM_Key_S;}break; + case 't':case 'T':{key = WM_Key_T;}break; + case 'u':case 'U':{key = WM_Key_U;}break; + case 'v':case 'V':{key = WM_Key_V;}break; + case 'w':case 'W':{key = WM_Key_W;}break; + case 'x':case 'X':{key = WM_Key_X;}break; + case 'y':case 'Y':{key = WM_Key_Y;}break; + case 'z':case 'Z':{key = WM_Key_Z;}break; + case ' ':{key = WM_Key_Space;}break; } // rjf: push text event @@ -509,7 +509,7 @@ os_get_events(Arena *arena, B32 wait) UnicodeDecode decode = utf8_decode(text+off, text_size-off); if(decode.codepoint != 0 && (decode.codepoint >= 32 || decode.codepoint == '\t')) { - OS_Event *e = os_event_list_push_new(arena, &evts, OS_EventKind_Text); + WM_Event *e = wm_event_list_push_new(arena, &evts, WM_EventKind_Text); e->window.u64[0] = (U64)window; e->character = decode.codepoint; } @@ -523,7 +523,7 @@ os_get_events(Arena *arena, B32 wait) // rjf: push key event { - OS_Event *e = os_event_list_push_new(arena, &evts, evt.type == KeyPress ? OS_EventKind_Press : OS_EventKind_Release); + WM_Event *e = wm_event_list_push_new(arena, &evts, evt.type == KeyPress ? WM_EventKind_Press : WM_EventKind_Release); e->window.u64[0] = (U64)window; e->modifiers = modifiers; e->key = key; @@ -536,26 +536,26 @@ os_get_events(Arena *arena, B32 wait) case ButtonRelease: { // rjf: determine flags - OS_Modifiers modifiers = 0; - if(evt.xbutton.state & ShiftMask) { modifiers |= OS_Modifier_Shift; } - if(evt.xbutton.state & ControlMask) { modifiers |= OS_Modifier_Ctrl; } - if(evt.xbutton.state & Mod1Mask) { modifiers |= OS_Modifier_Alt; } + WM_Modifiers modifiers = 0; + if(evt.xbutton.state & ShiftMask) { modifiers |= WM_Modifier_Shift; } + if(evt.xbutton.state & ControlMask) { modifiers |= WM_Modifier_Ctrl; } + if(evt.xbutton.state & Mod1Mask) { modifiers |= WM_Modifier_Alt; } - // rjf: map button -> OS_Key - OS_Key key = OS_Key_Null; + // rjf: map button -> WM_Key + WM_Key key = WM_Key_Null; switch(evt.xbutton.button) { default:{}break; - case Button1:{key = OS_Key_LeftMouseButton;}break; - case Button2:{key = OS_Key_MiddleMouseButton;}break; - case Button3:{key = OS_Key_RightMouseButton;}break; + case Button1:{key = WM_Key_LeftMouseButton;}break; + case Button2:{key = WM_Key_MiddleMouseButton;}break; + case Button3:{key = WM_Key_RightMouseButton;}break; } // rjf: push event - OS_LNX_Window *window = os_lnx_window_from_x11window(evt.xbutton.window); - if(key != OS_Key_Null) + LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xbutton.window); + if(key != WM_Key_Null) { - OS_Event *e = os_event_list_push_new(arena, &evts, evt.type == ButtonPress ? OS_EventKind_Press : OS_EventKind_Release); + WM_Event *e = wm_event_list_push_new(arena, &evts, evt.type == ButtonPress ? WM_EventKind_Press : WM_EventKind_Release); e->window.u64[0] = (U64)window; e->modifiers = modifiers; e->key = key; @@ -564,7 +564,7 @@ os_get_events(Arena *arena, B32 wait) else if(evt.xbutton.button == Button4 || evt.xbutton.button == Button5) { - OS_Event *e = os_event_list_push_new(arena, &evts, OS_EventKind_Scroll); + WM_Event *e = wm_event_list_push_new(arena, &evts, WM_EventKind_Scroll); e->window.u64[0] = (U64)window; e->modifiers = modifiers; e->delta = v2f32(0, evt.xbutton.button == Button4 ? -1.f : +1.f); @@ -575,8 +575,8 @@ os_get_events(Arena *arena, B32 wait) //- rjf: mouse motion case MotionNotify: { - OS_LNX_Window *window = os_lnx_window_from_x11window(evt.xclient.window); - OS_Event *e = os_event_list_push_new(arena, &evts, OS_EventKind_MouseMove); + LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xclient.window); + WM_Event *e = wm_event_list_push_new(arena, &evts, WM_EventKind_MouseMove); e->window.u64[0] = (U64)window; e->pos.x = (F32)evt.xmotion.x; e->pos.y = (F32)evt.xmotion.y; @@ -589,8 +589,8 @@ os_get_events(Arena *arena, B32 wait) }break; case FocusOut: { - OS_LNX_Window *window = os_lnx_window_from_x11window(evt.xfocus.window); - OS_Event *e = os_event_list_push_new(arena, &evts, OS_EventKind_WindowLoseFocus); + LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xfocus.window); + WM_Event *e = wm_event_list_push_new(arena, &evts, WM_EventKind_WindowLoseFocus); e->window.u64[0] = (U64)window; }break; @@ -599,13 +599,13 @@ os_get_events(Arena *arena, B32 wait) { if((Atom)evt.xclient.data.l[0] == os_lnx_gfx_state->wm_delete_window_atom) { - OS_LNX_Window *window = os_lnx_window_from_x11window(evt.xclient.window); - OS_Event *e = os_event_list_push_new(arena, &evts, OS_EventKind_WindowClose); + LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xclient.window); + WM_Event *e = wm_event_list_push_new(arena, &evts, WM_EventKind_WindowClose); e->window.u64[0] = (U64)window; } else if((Atom)evt.xclient.data.l[0] == os_lnx_gfx_state->wm_sync_request_atom) { - OS_LNX_Window *window = os_lnx_window_from_x11window(evt.xclient.window); + LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xclient.window); if(window != 0) { window->counter_value = 0; @@ -637,25 +637,25 @@ os_get_events(Arena *arena, B32 wait) return evts; } -internal OS_Modifiers -os_get_modifiers(void) +internal WM_Modifiers +wm_get_modifiers(void) { // TODO(rjf) return 0; } internal B32 -os_key_is_down(OS_Key key) +wm_key_is_down(WM_Key key) { // TODO(rjf) return 0; } internal Vec2F32 -os_mouse_from_window(OS_Window handle) +wm_mouse_from_window(WM_Window handle) { - if(os_window_match(handle, os_window_zero())) {return v2f32(0, 0);} - OS_LNX_Window *w = (OS_LNX_Window *)handle.u64[0]; + if(wm_window_match(handle, wm_window_zero())) {return v2f32(0, 0);} + LNX_WM_Window *w = (LNX_WM_Window *)handle.u64[0]; Vec2F32 result = {0}; { Window root_window = 0; @@ -678,7 +678,7 @@ os_mouse_from_window(OS_Window handle) //~ rjf: @os_hooks Cursors (Implemented Per-OS) internal void -os_set_cursor(OS_Cursor cursor) +wm_set_cursor(WM_Cursor cursor) { os_lnx_gfx_state->last_set_cursor = cursor; } @@ -687,7 +687,7 @@ os_set_cursor(OS_Cursor cursor) //~ rjf: @os_hooks Native User-Facing Graphical Messages (Implemented Per-OS) internal void -os_graphical_message(B32 error, String8 title, String8 message) +wm_graphical_message(B32 error, String8 title, String8 message) { if(error) { @@ -698,7 +698,7 @@ os_graphical_message(B32 error, String8 title, String8 message) } internal String8 -os_graphical_pick_file(Arena *arena, String8 initial_path) +wm_graphical_pick_file(Arena *arena, String8 initial_path) { return str8_zero(); } @@ -707,13 +707,13 @@ os_graphical_pick_file(Arena *arena, String8 initial_path) //~ rjf: @os_hooks Shell Operations internal void -os_show_in_filesystem_ui(String8 path) +wm_show_in_filesystem_ui(String8 path) { // TODO(rjf) } internal void -os_open_in_browser(String8 url) +wm_open_in_browser(String8 url) { // TODO(rjf) } diff --git a/src/linux/window_manager/linux_window_manager.h b/src/linux/window_manager/linux_window_manager.h index 0034adde..80b5da01 100644 --- a/src/linux/window_manager/linux_window_manager.h +++ b/src/linux/window_manager/linux_window_manager.h @@ -17,11 +17,11 @@ //////////////////////////////// //~ rjf: Window State -typedef struct OS_LNX_Window OS_LNX_Window; -struct OS_LNX_Window +typedef struct LNX_WM_Window LNX_WM_Window; +struct LNX_WM_Window { - OS_LNX_Window *next; - OS_LNX_Window *prev; + LNX_WM_Window *next; + LNX_WM_Window *prev; Window window; XIC xic; XID counter_xid; @@ -31,31 +31,31 @@ struct OS_LNX_Window //////////////////////////////// //~ rjf: State Bundle -typedef struct OS_LNX_GfxState OS_LNX_GfxState; -struct OS_LNX_GfxState +typedef struct LNX_WM_GfxState LNX_WM_GfxState; +struct LNX_WM_GfxState { Arena *arena; Display *display; XIM xim; - OS_LNX_Window *first_window; - OS_LNX_Window *last_window; - OS_LNX_Window *free_window; + LNX_WM_Window *first_window; + LNX_WM_Window *last_window; + LNX_WM_Window *free_window; Atom wm_delete_window_atom; Atom wm_sync_request_atom; Atom wm_sync_request_counter_atom; - Cursor cursors[OS_Cursor_COUNT]; - OS_Cursor last_set_cursor; - OS_GfxInfo gfx_info; + Cursor cursors[WM_Cursor_COUNT]; + WM_Cursor last_set_cursor; + WM_SystemInfo gfx_info; }; //////////////////////////////// //~ rjf: Globals -global OS_LNX_GfxState *os_lnx_gfx_state = 0; +global LNX_WM_GfxState *os_lnx_gfx_state = 0; //////////////////////////////// //~ rjf: Helpers -internal OS_LNX_Window *os_lnx_window_from_x11window(Window window); +internal LNX_WM_Window *os_lnx_window_from_x11window(Window window); #endif // OS_GFX_LINUX_H diff --git a/src/raddbg/generated/raddbg.meta.c b/src/raddbg/generated/raddbg.meta.c index 6dc53ee3..f85947ff 100644 --- a/src/raddbg/generated/raddbg.meta.c +++ b/src/raddbg/generated/raddbg.meta.c @@ -212,7 +212,7 @@ RD_VocabInfo rd_vocab_info_table[360] = {str8_lit_comp("open_palette"), str8_lit_comp(""), str8_lit_comp("Open Palette"), str8_lit_comp(""), RD_IconKind_List}, {str8_lit_comp("run_command"), str8_lit_comp(""), str8_lit_comp("Run Command"), str8_lit_comp(""), RD_IconKind_Null}, {str8_lit_comp("run_ext_driver_text_command"), str8_lit_comp(""), str8_lit_comp("Run External Driver Text Command"), str8_lit_comp(""), RD_IconKind_Null}, -{str8_lit_comp("os_event"), str8_lit_comp(""), str8_lit_comp("OS Event"), str8_lit_comp(""), RD_IconKind_Null}, +{str8_lit_comp("wm_event"), str8_lit_comp(""), str8_lit_comp("OS Event"), str8_lit_comp(""), RD_IconKind_Null}, {str8_lit_comp("select_thread"), str8_lit_comp(""), str8_lit_comp("Select Thread"), str8_lit_comp(""), RD_IconKind_Thread}, {str8_lit_comp("select_unwind"), str8_lit_comp(""), str8_lit_comp("Select Unwind"), str8_lit_comp(""), RD_IconKind_Null}, {str8_lit_comp("up_one_frame"), str8_lit_comp(""), str8_lit_comp("Up One Frame"), str8_lit_comp(""), RD_IconKind_UpArrow}, @@ -520,7 +520,7 @@ str8_lit_comp("activate_with_single_click"), str8_lit_comp("dir2"), str8_lit_comp("string"), str8_lit_comp("cmd_name"), -str8_lit_comp("os_event"), +str8_lit_comp("wm_event"), }; Rng1U64 rd_reg_slot_range_table[49] = @@ -573,7 +573,7 @@ Rng1U64 rd_reg_slot_range_table[49] = {OffsetOf(RD_Regs, dir2), OffsetOf(RD_Regs, dir2) + sizeof(Dir2)}, {OffsetOf(RD_Regs, string), OffsetOf(RD_Regs, string) + sizeof(String8)}, {OffsetOf(RD_Regs, cmd_name), OffsetOf(RD_Regs, cmd_name) + sizeof(String8)}, -{OffsetOf(RD_Regs, os_event), OffsetOf(RD_Regs, os_event) + sizeof(OS_Event *)}, +{OffsetOf(RD_Regs, wm_event), OffsetOf(RD_Regs, wm_event) + sizeof(WM_Event *)}, }; RD_CmdKindInfo rd_cmd_kind_info_table[249] = @@ -615,7 +615,7 @@ RD_CmdKindInfo rd_cmd_kind_info_table[249] = { str8_lit_comp("open_palette"), str8_lit_comp("Opens the palette."), str8_lit_comp("help,cmd,lister"), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*0)|(RD_QueryFlag_Required*0), RD_RegSlot_Null, str8_lit_comp(""), str8_lit_comp(""), D_EntityKind_Null}}, { str8_lit_comp("run_command"), str8_lit_comp("Runs a command from the command palette."), str8_lit_comp("help,cmd"), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_CmdName, str8_lit_comp("query:commands"), str8_lit_comp("commands"), D_EntityKind_Null}}, { str8_lit_comp("run_ext_driver_text_command"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*0)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_Null, str8_lit_comp(""), str8_lit_comp(""), D_EntityKind_Null}}, -{ str8_lit_comp("os_event"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*0)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*0)|(RD_QueryFlag_Required*0), RD_RegSlot_Null, str8_lit_comp(""), str8_lit_comp(""), D_EntityKind_Null}}, +{ str8_lit_comp("wm_event"), str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*0)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*0)|(RD_QueryFlag_Required*0), RD_RegSlot_Null, str8_lit_comp(""), str8_lit_comp(""), D_EntityKind_Null}}, { str8_lit_comp("select_thread"), str8_lit_comp("Selects a thread."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*1)|(RD_QueryFlag_Required*1), RD_RegSlot_Thread, str8_lit_comp("query:threads"), str8_lit_comp(""), D_EntityKind_Thread}}, { str8_lit_comp("select_unwind"), str8_lit_comp("Selects an unwind frame number for the selected thread."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*0)|(RD_CmdKindFlag_ListInIPCDocs*1)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*0)|(RD_QueryFlag_Required*0), RD_RegSlot_Null, str8_lit_comp("query:call_stack"), str8_lit_comp(""), D_EntityKind_Null}}, { str8_lit_comp("up_one_frame"), str8_lit_comp("Selects the call stack frame above the currently selected."), str8_lit_comp(""), str8_lit_comp(""), (RD_CmdKindFlag_ListInUI*1)|(RD_CmdKindFlag_ListInIPCDocs*1)|(RD_CmdKindFlag_ListInTextPt*0)|(RD_CmdKindFlag_ListInTextRng*0), {(RD_QueryFlag_AllowFiles*0)|(RD_QueryFlag_AllowFolders*0)|(RD_QueryFlag_CodeInput*0)|(RD_QueryFlag_KeepOldInput*0)|(RD_QueryFlag_SelectOldInput*0)|(RD_QueryFlag_Floating*0)|(RD_QueryFlag_Required*0), RD_RegSlot_Null, str8_lit_comp(""), str8_lit_comp(""), D_EntityKind_Null}}, @@ -831,124 +831,124 @@ RD_CmdKindInfo rd_cmd_kind_info_table[249] = struct {String8 string; CFG_Binding binding;} rd_default_binding_table[118] = { -{str8_lit_comp("kill_all"), {OS_Key_F5, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("step_into_inst"), {OS_Key_F11, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("step_over_inst"), {OS_Key_F10, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("step_out"), {OS_Key_F11, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("halt"), {OS_Key_X, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("halt"), {OS_Key_Pause, 0 }}, -{str8_lit_comp("run"), {OS_Key_F5, 0 }}, -{str8_lit_comp("restart"), {OS_Key_F5, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("step_into"), {OS_Key_F11, 0 }}, -{str8_lit_comp("step_over"), {OS_Key_F10, 0 }}, -{str8_lit_comp("run_to_line"), {OS_Key_F10, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("set_next_statement"), {OS_Key_F10, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("inc_window_font_size"), {OS_Key_Equal, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("dec_window_font_size"), {OS_Key_Minus, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("window"), {OS_Key_N, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("toggle_fullscreen"), {OS_Key_Return, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("new_panel_right"), {OS_Key_P, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("new_panel_down"), {OS_Key_Minus, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("rotate_panel_columns"), {OS_Key_2, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("next_panel"), {OS_Key_Comma, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("prev_panel"), {OS_Key_Comma, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("focus_panel_right"), {OS_Key_Right, 0 |OS_Modifier_Ctrl |OS_Modifier_Alt}}, -{str8_lit_comp("focus_panel_left"), {OS_Key_Left, 0 |OS_Modifier_Ctrl |OS_Modifier_Alt}}, -{str8_lit_comp("focus_panel_up"), {OS_Key_Up, 0 |OS_Modifier_Ctrl |OS_Modifier_Alt}}, -{str8_lit_comp("focus_panel_down"), {OS_Key_Down, 0 |OS_Modifier_Ctrl |OS_Modifier_Alt}}, -{str8_lit_comp("undo"), {OS_Key_Z, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("redo"), {OS_Key_Y, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("go_back"), {OS_Key_Left, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("go_forward"), {OS_Key_Right, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("close_panel"), {OS_Key_P, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift |OS_Modifier_Alt}}, -{str8_lit_comp("next_tab"), {OS_Key_PageDown, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("prev_tab"), {OS_Key_PageUp, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("next_tab"), {OS_Key_Tab, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("prev_tab"), {OS_Key_Tab, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("move_tab_right"), {OS_Key_PageDown, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("move_tab_left"), {OS_Key_PageUp, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("close_tab"), {OS_Key_W, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("tab_bar_top"), {OS_Key_Up, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift |OS_Modifier_Alt}}, -{str8_lit_comp("tab_bar_bottom"), {OS_Key_Down, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift |OS_Modifier_Alt}}, -{str8_lit_comp("open_tab"), {OS_Key_T, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("tab_settings"), {OS_Key_T, 0 |OS_Modifier_Ctrl |OS_Modifier_Alt}}, -{str8_lit_comp("open"), {OS_Key_O, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("switch"), {OS_Key_I, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("switch_to_partner_file"), {OS_Key_O, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("open_user"), {OS_Key_N, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift |OS_Modifier_Alt}}, -{str8_lit_comp("open_project"), {OS_Key_N, 0 |OS_Modifier_Ctrl |OS_Modifier_Alt}}, -{str8_lit_comp("open_user"), {OS_Key_O, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift |OS_Modifier_Alt}}, -{str8_lit_comp("open_project"), {OS_Key_O, 0 |OS_Modifier_Ctrl |OS_Modifier_Alt}}, -{str8_lit_comp("save_user"), {OS_Key_S, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift |OS_Modifier_Alt}}, -{str8_lit_comp("save_project"), {OS_Key_S, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("edit"), {OS_Key_F2, 0 }}, -{str8_lit_comp("accept"), {OS_Key_Return, 0 }}, -{str8_lit_comp("accept"), {OS_Key_Space, 0 }}, -{str8_lit_comp("cancel"), {OS_Key_Esc, 0 }}, -{str8_lit_comp("focus_menu"), {OS_Key_D, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("move_left"), {OS_Key_Left, 0 }}, -{str8_lit_comp("move_right"), {OS_Key_Right, 0 }}, -{str8_lit_comp("move_up"), {OS_Key_Up, 0 }}, -{str8_lit_comp("move_down"), {OS_Key_Down, 0 }}, -{str8_lit_comp("move_left_select"), {OS_Key_Left, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("move_right_select"), {OS_Key_Right, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("move_up_select"), {OS_Key_Up, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("move_down_select"), {OS_Key_Down, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("move_left_chunk"), {OS_Key_Left, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("move_right_chunk"), {OS_Key_Right, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("move_up_chunk"), {OS_Key_Up, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("move_down_chunk"), {OS_Key_Down, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("move_up_page"), {OS_Key_PageUp, 0 }}, -{str8_lit_comp("move_down_page"), {OS_Key_PageDown, 0 }}, -{str8_lit_comp("move_up_whole"), {OS_Key_Home, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("move_down_whole"), {OS_Key_End, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("move_left_chunk_select"), {OS_Key_Left, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("move_right_chunk_select"), {OS_Key_Right, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("move_up_chunk_select"), {OS_Key_Up, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("move_down_chunk_select"), {OS_Key_Down, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("move_up_page_select"), {OS_Key_PageUp, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("move_down_page_select"), {OS_Key_PageDown, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("move_up_whole_select"), {OS_Key_Home, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("move_down_whole_select"), {OS_Key_End, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("move_up_reorder"), {OS_Key_Up, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("move_down_reorder"), {OS_Key_Down, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("move_home"), {OS_Key_Home, 0 }}, -{str8_lit_comp("move_end"), {OS_Key_End, 0 }}, -{str8_lit_comp("move_home_select"), {OS_Key_Home, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("move_end_select"), {OS_Key_End, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("select_all"), {OS_Key_A, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("delete_single"), {OS_Key_Delete, 0 }}, -{str8_lit_comp("delete_chunk"), {OS_Key_Delete, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("backspace_single"), {OS_Key_Backspace, 0 }}, -{str8_lit_comp("backspace_chunk"), {OS_Key_Backspace, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("copy"), {OS_Key_C, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("copy"), {OS_Key_Insert, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("cut"), {OS_Key_X, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("paste"), {OS_Key_V, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("paste"), {OS_Key_Insert, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("insert_text"), {OS_Key_Null, 0 }}, -{str8_lit_comp("move_next"), {OS_Key_Tab, 0 }}, -{str8_lit_comp("move_prev"), {OS_Key_Tab, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("goto_line"), {OS_Key_G, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("goto_address"), {OS_Key_G, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("search"), {OS_Key_F, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("search_backwards"), {OS_Key_R, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("find_next"), {OS_Key_F3, 0 }}, -{str8_lit_comp("find_prev"), {OS_Key_F3, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("find_selected_thread"), {OS_Key_F4, 0 }}, -{str8_lit_comp("goto_name"), {OS_Key_J, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("goto_name_at_cursor"), {OS_Key_F12, 0 }}, -{str8_lit_comp("toggle_watch_expr_at_cursor"), {OS_Key_W, 0 |OS_Modifier_Alt}}, -{str8_lit_comp("toggle_watch_expr_at_mouse"), {OS_Key_D, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("toggle_watch_pin"), {OS_Key_F9, 0 |OS_Modifier_Ctrl }}, -{str8_lit_comp("toggle_breakpoint"), {OS_Key_F9, 0 }}, -{str8_lit_comp("add_address_breakpoint"), {OS_Key_F9, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("add_function_breakpoint"), {OS_Key_F9, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("attach"), {OS_Key_F6, 0 |OS_Modifier_Shift }}, -{str8_lit_comp("open_palette"), {OS_Key_F1, 0 }}, -{str8_lit_comp("open_palette"), {OS_Key_P, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift }}, -{str8_lit_comp("log_marker"), {OS_Key_M, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift |OS_Modifier_Alt}}, -{str8_lit_comp("toggle_dev_menu"), {OS_Key_D, 0 |OS_Modifier_Ctrl |OS_Modifier_Shift |OS_Modifier_Alt}}, +{str8_lit_comp("kill_all"), {WM_Key_F5, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("step_into_inst"), {WM_Key_F11, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("step_over_inst"), {WM_Key_F10, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("step_out"), {WM_Key_F11, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("halt"), {WM_Key_X, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("halt"), {WM_Key_Pause, 0 }}, +{str8_lit_comp("run"), {WM_Key_F5, 0 }}, +{str8_lit_comp("restart"), {WM_Key_F5, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("step_into"), {WM_Key_F11, 0 }}, +{str8_lit_comp("step_over"), {WM_Key_F10, 0 }}, +{str8_lit_comp("run_to_line"), {WM_Key_F10, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("set_next_statement"), {WM_Key_F10, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("inc_window_font_size"), {WM_Key_Equal, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("dec_window_font_size"), {WM_Key_Minus, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("window"), {WM_Key_N, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("toggle_fullscreen"), {WM_Key_Return, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("new_panel_right"), {WM_Key_P, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("new_panel_down"), {WM_Key_Minus, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("rotate_panel_columns"), {WM_Key_2, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("next_panel"), {WM_Key_Comma, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("prev_panel"), {WM_Key_Comma, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("focus_panel_right"), {WM_Key_Right, 0 |WM_Modifier_Ctrl |WM_Modifier_Alt}}, +{str8_lit_comp("focus_panel_left"), {WM_Key_Left, 0 |WM_Modifier_Ctrl |WM_Modifier_Alt}}, +{str8_lit_comp("focus_panel_up"), {WM_Key_Up, 0 |WM_Modifier_Ctrl |WM_Modifier_Alt}}, +{str8_lit_comp("focus_panel_down"), {WM_Key_Down, 0 |WM_Modifier_Ctrl |WM_Modifier_Alt}}, +{str8_lit_comp("undo"), {WM_Key_Z, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("redo"), {WM_Key_Y, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("go_back"), {WM_Key_Left, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("go_forward"), {WM_Key_Right, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("close_panel"), {WM_Key_P, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift |WM_Modifier_Alt}}, +{str8_lit_comp("next_tab"), {WM_Key_PageDown, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("prev_tab"), {WM_Key_PageUp, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("next_tab"), {WM_Key_Tab, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("prev_tab"), {WM_Key_Tab, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("move_tab_right"), {WM_Key_PageDown, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("move_tab_left"), {WM_Key_PageUp, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("close_tab"), {WM_Key_W, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("tab_bar_top"), {WM_Key_Up, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift |WM_Modifier_Alt}}, +{str8_lit_comp("tab_bar_bottom"), {WM_Key_Down, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift |WM_Modifier_Alt}}, +{str8_lit_comp("open_tab"), {WM_Key_T, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("tab_settings"), {WM_Key_T, 0 |WM_Modifier_Ctrl |WM_Modifier_Alt}}, +{str8_lit_comp("open"), {WM_Key_O, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("switch"), {WM_Key_I, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("switch_to_partner_file"), {WM_Key_O, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("open_user"), {WM_Key_N, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift |WM_Modifier_Alt}}, +{str8_lit_comp("open_project"), {WM_Key_N, 0 |WM_Modifier_Ctrl |WM_Modifier_Alt}}, +{str8_lit_comp("open_user"), {WM_Key_O, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift |WM_Modifier_Alt}}, +{str8_lit_comp("open_project"), {WM_Key_O, 0 |WM_Modifier_Ctrl |WM_Modifier_Alt}}, +{str8_lit_comp("save_user"), {WM_Key_S, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift |WM_Modifier_Alt}}, +{str8_lit_comp("save_project"), {WM_Key_S, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("edit"), {WM_Key_F2, 0 }}, +{str8_lit_comp("accept"), {WM_Key_Return, 0 }}, +{str8_lit_comp("accept"), {WM_Key_Space, 0 }}, +{str8_lit_comp("cancel"), {WM_Key_Esc, 0 }}, +{str8_lit_comp("focus_menu"), {WM_Key_D, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("move_left"), {WM_Key_Left, 0 }}, +{str8_lit_comp("move_right"), {WM_Key_Right, 0 }}, +{str8_lit_comp("move_up"), {WM_Key_Up, 0 }}, +{str8_lit_comp("move_down"), {WM_Key_Down, 0 }}, +{str8_lit_comp("move_left_select"), {WM_Key_Left, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("move_right_select"), {WM_Key_Right, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("move_up_select"), {WM_Key_Up, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("move_down_select"), {WM_Key_Down, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("move_left_chunk"), {WM_Key_Left, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("move_right_chunk"), {WM_Key_Right, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("move_up_chunk"), {WM_Key_Up, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("move_down_chunk"), {WM_Key_Down, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("move_up_page"), {WM_Key_PageUp, 0 }}, +{str8_lit_comp("move_down_page"), {WM_Key_PageDown, 0 }}, +{str8_lit_comp("move_up_whole"), {WM_Key_Home, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("move_down_whole"), {WM_Key_End, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("move_left_chunk_select"), {WM_Key_Left, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("move_right_chunk_select"), {WM_Key_Right, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("move_up_chunk_select"), {WM_Key_Up, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("move_down_chunk_select"), {WM_Key_Down, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("move_up_page_select"), {WM_Key_PageUp, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("move_down_page_select"), {WM_Key_PageDown, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("move_up_whole_select"), {WM_Key_Home, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("move_down_whole_select"), {WM_Key_End, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("move_up_reorder"), {WM_Key_Up, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("move_down_reorder"), {WM_Key_Down, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("move_home"), {WM_Key_Home, 0 }}, +{str8_lit_comp("move_end"), {WM_Key_End, 0 }}, +{str8_lit_comp("move_home_select"), {WM_Key_Home, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("move_end_select"), {WM_Key_End, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("select_all"), {WM_Key_A, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("delete_single"), {WM_Key_Delete, 0 }}, +{str8_lit_comp("delete_chunk"), {WM_Key_Delete, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("backspace_single"), {WM_Key_Backspace, 0 }}, +{str8_lit_comp("backspace_chunk"), {WM_Key_Backspace, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("copy"), {WM_Key_C, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("copy"), {WM_Key_Insert, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("cut"), {WM_Key_X, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("paste"), {WM_Key_V, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("paste"), {WM_Key_Insert, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("insert_text"), {WM_Key_Null, 0 }}, +{str8_lit_comp("move_next"), {WM_Key_Tab, 0 }}, +{str8_lit_comp("move_prev"), {WM_Key_Tab, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("goto_line"), {WM_Key_G, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("goto_address"), {WM_Key_G, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("search"), {WM_Key_F, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("search_backwards"), {WM_Key_R, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("find_next"), {WM_Key_F3, 0 }}, +{str8_lit_comp("find_prev"), {WM_Key_F3, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("find_selected_thread"), {WM_Key_F4, 0 }}, +{str8_lit_comp("goto_name"), {WM_Key_J, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("goto_name_at_cursor"), {WM_Key_F12, 0 }}, +{str8_lit_comp("toggle_watch_expr_at_cursor"), {WM_Key_W, 0 |WM_Modifier_Alt}}, +{str8_lit_comp("toggle_watch_expr_at_mouse"), {WM_Key_D, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("toggle_watch_pin"), {WM_Key_F9, 0 |WM_Modifier_Ctrl }}, +{str8_lit_comp("toggle_breakpoint"), {WM_Key_F9, 0 }}, +{str8_lit_comp("add_address_breakpoint"), {WM_Key_F9, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("add_function_breakpoint"), {WM_Key_F9, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("attach"), {WM_Key_F6, 0 |WM_Modifier_Shift }}, +{str8_lit_comp("open_palette"), {WM_Key_F1, 0 }}, +{str8_lit_comp("open_palette"), {WM_Key_P, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift }}, +{str8_lit_comp("log_marker"), {WM_Key_M, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift |WM_Modifier_Alt}}, +{str8_lit_comp("toggle_dev_menu"), {WM_Key_D, 0 |WM_Modifier_Ctrl |WM_Modifier_Shift |WM_Modifier_Alt}}, }; String8 rd_binding_version_remap_old_name_table[8] = diff --git a/src/raddbg/generated/raddbg.meta.h b/src/raddbg/generated/raddbg.meta.h index b4aee778..74d7fad6 100644 --- a/src/raddbg/generated/raddbg.meta.h +++ b/src/raddbg/generated/raddbg.meta.h @@ -56,7 +56,7 @@ RD_RegSlot_ActivateWithSingleClick, RD_RegSlot_Dir2, RD_RegSlot_String, RD_RegSlot_CmdName, -RD_RegSlot_OSEvent, +RD_RegSlot_WMEvent, RD_RegSlot_COUNT, } RD_RegSlot; @@ -99,7 +99,7 @@ RD_CmdKind_Exit, RD_CmdKind_OpenPalette, RD_CmdKind_RunCommand, RD_CmdKind_RunExternalDriverTextCommand, -RD_CmdKind_OSEvent, +RD_CmdKind_WMEvent, RD_CmdKind_SelectThread, RD_CmdKind_SelectUnwind, RD_CmdKind_UpOneFrame, @@ -498,7 +498,7 @@ B32 activate_with_single_click; Dir2 dir2; String8 string; String8 cmd_name; -OS_Event * os_event; +WM_Event * wm_event; }; typedef struct RD_Query RD_Query; @@ -598,7 +598,7 @@ Z(getting_started)\ .dir2 = rd_regs()->dir2,\ .string = rd_regs()->string,\ .cmd_name = rd_regs()->cmd_name,\ -.os_event = rd_regs()->os_event,\ +.wm_event = rd_regs()->wm_event,\ C_LINKAGE_BEGIN extern String8 rd_tab_fast_path_view_name_table[25]; diff --git a/src/raddbg/raddbg.mdesk b/src/raddbg/raddbg.mdesk index 35d08264..08c492b1 100644 --- a/src/raddbg/raddbg.mdesk +++ b/src/raddbg/raddbg.mdesk @@ -831,68 +831,68 @@ RD_VocabTable: RD_RegTable: { // rjf: ctrl entities - {D_Handle machine Machine } - {D_Handle module Module } - {D_Handle process Process } - {D_Handle thread Thread } - {D_Handle ctrl_entity CtrlEntity } + {D_Handle machine Machine } + {D_Handle module Module } + {D_Handle process Process } + {D_Handle thread Thread } + {D_Handle ctrl_entity CtrlEntity } // rjf: cfgs - {CFG_ID window Window } - {CFG_ID panel Panel } - {CFG_ID tab Tab } - {CFG_ID view View } - {CFG_ID prev_tab PrevTab } - {CFG_ID dst_panel DstPanel } - {CFG_ID cfg Cfg } - {CFG_IDList cfg_list CfgList } + {CFG_ID window Window } + {CFG_ID panel Panel } + {CFG_ID tab Tab } + {CFG_ID view View } + {CFG_ID prev_tab PrevTab } + {CFG_ID dst_panel DstPanel } + {CFG_ID cfg Cfg } + {CFG_IDList cfg_list CfgList } // rjf: evaluation space - {E_Space eval_space EvalSpace } + {E_Space eval_space EvalSpace } // rjf: frame selection - {U64 unwind_count UnwindCount } - {U64 inline_depth InlineDepth } + {U64 unwind_count UnwindCount } + {U64 inline_depth InlineDepth } // rjf: code / address location info - {String8 file_path FilePath } - {TxtPt cursor Cursor } - {TxtPt mark Mark } - {C_Key text_key TextKey } - {TXT_LangKind lang_kind LangKind } - {D_LineList lines Lines } - {DI_Key dbgi_key DbgiKey } - {U64 vaddr Vaddr } - {U64 voff Voff } - {Rng1U64 vaddr_range VaddrRange } - {Rng1U64 voff_range VoffRange } + {String8 file_path FilePath } + {TxtPt cursor Cursor } + {TxtPt mark Mark } + {C_Key text_key TextKey } + {TXT_LangKind lang_kind LangKind } + {D_LineList lines Lines } + {DI_Key dbgi_key DbgiKey } + {U64 vaddr Vaddr } + {U64 voff Voff } + {Rng1U64 vaddr_range VaddrRange } + {Rng1U64 voff_range VoffRange } // rjf: evaluation - {String8 expr Expr } + {String8 expr Expr } // rjf: ui context - {UI_Key ui_key UIKey } - {UI_Key src_ui_key SrcUIKey } - {Vec2F32 off_px OffPx } - {RD_RegSlot reg_slot RegSlot } + {UI_Key ui_key UIKey } + {UI_Key src_ui_key SrcUIKey } + {Vec2F32 off_px OffPx } + {RD_RegSlot reg_slot RegSlot } // rjf: general parameters - {U32 pid PID } - {B32 force_confirm ForceConfirm } - {B32 force_focus ForceFocus } - {B32 prefer_disasm PreferDisasm } - {B32 no_rich_tooltip NoRichTooltip } - {B32 do_implicit_root DoImplicitRoot} - {B32 do_lister DoLister } - {B32 do_big_rows DoBigRows } - {B32 all_windows AllWindows } - {B32 non_graphical NonGraphical } - {B32 prefer_new_tab PreferNewTab } - {B32 activate_with_single_click ActivateWithSingleClick } - {Dir2 dir2 Dir2 } - {String8 string String } - {String8 cmd_name CmdName } - {`OS_Event *` os_event OSEvent } + {U32 pid PID } + {B32 force_confirm ForceConfirm } + {B32 force_focus ForceFocus } + {B32 prefer_disasm PreferDisasm } + {B32 no_rich_tooltip NoRichTooltip } + {B32 do_implicit_root DoImplicitRoot } + {B32 do_lister DoLister } + {B32 do_big_rows DoBigRows } + {B32 all_windows AllWindows } + {B32 non_graphical NonGraphical } + {B32 prefer_new_tab PreferNewTab } + {B32 activate_with_single_click ActivateWithSingleClick } + {Dir2 dir2 Dir2 } + {String8 string String } + {String8 cmd_name CmdName } + {`WM_Event *` wm_event WMEvent } } @enum RD_RegSlot: @@ -945,7 +945,7 @@ RD_CmdTable: // | | | | {RunExternalDriverTextCommand 0 0 0 0 "" Null null Nil Null 0 0 0 0 0 1 1 Null "run_ext_driver_text_command" "Run External Driver Text Command" "" "" "" } //- rjf: os event passthrough - {OSEvent 0 0 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Null "os_event" "OS Event" "" "" "" } + {WMEvent 0 0 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Null "wm_event" "OS Event" "" "" "" } //- rjf: thread/frame selection {SelectThread 1 1 0 0 "query:threads" Thread null Nil Thread 0 0 0 0 0 1 1 Thread "select_thread" "Select Thread" "Selects a thread." "" "" } @@ -1437,7 +1437,7 @@ RD_DefaultBindingTable: @data(`struct {String8 string; CFG_Binding binding;}`) @c_file rd_default_binding_table: { - @expand(RD_DefaultBindingTable a) ```{str8_lit_comp("$(a.name)"), {OS_Key_$(a.key), 0 $(a.ctrl != 0 -> `|OS_Modifier_Ctrl`) $(a.shift != 0 -> `|OS_Modifier_Shift`) $(a.alt != 0 -> `|OS_Modifier_Alt`)}}```; + @expand(RD_DefaultBindingTable a) ```{str8_lit_comp("$(a.name)"), {WM_Key_$(a.key), 0 $(a.ctrl != 0 -> `|WM_Modifier_Ctrl`) $(a.shift != 0 -> `|WM_Modifier_Shift`) $(a.alt != 0 -> `|WM_Modifier_Alt`)}}```; } //////////////////////////////// diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 334826b6..b89d6efc 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -2625,7 +2625,7 @@ rd_view_ui(Rng2F32 rect) // rjf: copy if(op.flags & UI_TxtOpFlag_Copy && selection_tbl.min.x == selection_tbl.max.x && selection_tbl.min.y == selection_tbl.max.y) { - os_set_clipboard_text(op.copy); + wm_set_clipboard_text(op.copy); } // rjf: any valid *additive* op & autocomplete hint? -> perform autocomplete first, then re-compute op @@ -2776,7 +2776,7 @@ rd_view_ui(Rng2F32 rect) } } String8 string = str8_list_join(scratch.arena, &strs, 0); - os_set_clipboard_text(string); + wm_set_clipboard_text(string); } ////////////////////////// @@ -3221,7 +3221,7 @@ rd_view_ui(Rng2F32 rect) boundary_start_idx*row_height_px, next_cell_x_px + ui_top_font_size()*0.4f, idx*row_height_px); - UI_Rect(rect) UI_HoverCursor(OS_Cursor_LeftRight) + UI_Rect(rect) UI_HoverCursor(WM_Cursor_LeftRight) { UI_Box *box = ui_build_box_from_stringf(UI_BoxFlag_Clickable|UI_BoxFlag_Floating, "boundary_%I64x_%I64x", row_hash, cell_id); UI_Signal sig = ui_signal_from_box(box); @@ -4381,7 +4381,7 @@ rd_view_ui(Rng2F32 rect) U64 value = e_value_from_string(loc.expr).u64; rd_cmd(RD_CmdKind_FindCodeLocation, .vaddr = value); } - else if(str8_match(cfg->string, str8_lit("target"), 0) && sig.event_flags & OS_Modifier_Ctrl) + else if(str8_match(cfg->string, str8_lit("target"), 0) && sig.event_flags & WM_Modifier_Ctrl) { rd_cmd(RD_CmdKind_EnableCfg, .cfg = cfg->id); } @@ -4937,7 +4937,7 @@ rd_window_state_from_cfg(CFG_Node *cfg) B32 has_pos = 0; Vec2F32 pos = {0}; Vec2F32 size = {0}; - OS_Monitor preferred_monitor = {0}; + WM_Monitor preferred_monitor = {0}; { CFG_Node *pos_cfg = cfg_node_child_from_string(window_cfg, str8_lit("pos")); has_pos = (pos_cfg != &cfg_nil_node); @@ -4947,10 +4947,10 @@ rd_window_state_from_cfg(CFG_Node *cfg) pos.y = (F32)f64_from_str8(pos_cfg->first->next->string); size.x = (F32)f64_from_str8(size_cfg->first->string); size.y = (F32)f64_from_str8(size_cfg->first->next->string); - OS_MonitorArray monitors = os_push_monitors_array(scratch.arena); + WM_MonitorArray monitors = wm_push_monitors_array(scratch.arena); for EachIndex(idx, monitors.count) { - String8 monitor_name = os_name_from_monitor(scratch.arena, monitors.v[idx]); + String8 monitor_name = wm_name_from_monitor(scratch.arena, monitors.v[idx]); if(str8_match(monitor_name, monitor_cfg->first->string, StringMatchFlag_CaseInsensitive)) { preferred_monitor = monitors.v[idx]; @@ -4976,7 +4976,7 @@ rd_window_state_from_cfg(CFG_Node *cfg) ws->arena = arena_alloc(); { String8 title = rd_push_window_title(scratch.arena); - ws->os = os_window_open(r2f32p(pos.x, pos.y, pos.x+size.x, pos.y+size.y), (!has_pos*OS_WindowFlag_UseDefaultPosition)|OS_WindowFlag_CustomBorder, title); + ws->os = wm_window_open(r2f32p(pos.x, pos.y, pos.x+size.x, pos.y+size.y), (!has_pos*WM_WindowFlag_UseDefaultPosition)|WM_WindowFlag_CustomBorder, title); } ws->r = r_window_equip(ws->os); ws->ui = ui_state_alloc(); @@ -4984,19 +4984,19 @@ rd_window_state_from_cfg(CFG_Node *cfg) ws->query_arena = arena_alloc(); ws->hover_eval_arena = arena_alloc(); ws->autocomp_arena = arena_alloc(); - ws->last_dpi = os_dpi_from_window(ws->os); - OS_Monitor zero_monitor = {0}; - if(!os_monitor_match(zero_monitor, preferred_monitor)) + ws->last_dpi = wm_dpi_from_window(ws->os); + WM_Monitor zero_monitor = {0}; + if(!wm_monitor_match(zero_monitor, preferred_monitor)) { - os_window_set_monitor(ws->os, preferred_monitor); + wm_window_set_monitor(ws->os, preferred_monitor); } if(cfg_node_child_from_string(window_cfg, str8_lit("fullscreen")) != &cfg_nil_node) { - os_window_set_fullscreen(ws->os, 1); + wm_window_set_fullscreen(ws->os, 1); } if(cfg_node_child_from_string(window_cfg, str8_lit("maximized")) != &cfg_nil_node) { - os_window_set_maximized(ws->os, 1); + wm_window_set_maximized(ws->os, 1); } // rjf: hook up window links @@ -5021,7 +5021,7 @@ rd_window_state_from_cfg(CFG_Node *cfg) } internal RD_WindowState * -rd_window_state_from_os_handle(OS_Window os) +rd_window_state_from_os_handle(WM_Window os) { RD_WindowState *ws = &rd_nil_window_state; { @@ -5029,7 +5029,7 @@ rd_window_state_from_os_handle(OS_Window os) w != &rd_nil_window_state; w = w->order_next) { - if(os_window_match(w->os, os)) + if(wm_window_match(w->os, os)) { ws = w; break; @@ -5055,7 +5055,7 @@ rd_window_frame(void) CFG_Node *window = cfg_node_from_id(rd_regs()->window); RD_WindowState *ws = rd_window_state_from_cfg(cfg_node_from_id(rd_regs()->window)); CFG_PanelTree panel_tree = cfg_panel_tree_from_cfg(scratch.arena, window); - B32 window_is_focused = (os_window_is_focused(ws->os) || ws->window_temporarily_focused_ipc); + B32 window_is_focused = (wm_window_is_focused(ws->os) || ws->window_temporarily_focused_ipc); B32 popup_is_open = (rd_state->popup_active); B32 query_is_open = (ws->query_is_active); U64 hover_eval_open_delay_us = 400000; @@ -5258,9 +5258,9 @@ rd_window_frame(void) // { Temp scratch = scratch_begin(0, 0); - B32 is_fullscreen = os_window_is_fullscreen(ws->os); - B32 is_maximized = os_window_is_maximized(ws->os); - B32 is_minimized = os_window_is_minimized(ws->os); + B32 is_fullscreen = wm_window_is_fullscreen(ws->os); + B32 is_maximized = wm_window_is_maximized(ws->os); + B32 is_minimized = wm_window_is_minimized(ws->os); if(is_fullscreen) { cfg_node_child_from_string_or_alloc(rd_state->cfg, window, str8_lit("fullscreen")); @@ -5279,7 +5279,7 @@ rd_window_frame(void) } //- rjf: DPI changes -> xform font size / window size - F32 dpi = os_dpi_from_window(ws->os); + F32 dpi = wm_dpi_from_window(ws->os); if(dpi != ws->last_dpi) { fnt_reset(); @@ -5292,7 +5292,7 @@ rd_window_frame(void) } //- rjf: commit position - Rng2F32 window_rect = os_rect_from_window(ws->os); + Rng2F32 window_rect = wm_rect_from_window(ws->os); if(!is_fullscreen && !is_maximized && !is_minimized) { Vec2F32 pos = window_rect.p0; @@ -5345,8 +5345,8 @@ rd_window_frame(void) //- rjf: commit monitor if(!is_minimized) { - OS_Monitor monitor = os_monitor_from_window(ws->os); - String8 monitor_name = os_name_from_monitor(scratch.arena, monitor); + WM_Monitor monitor = wm_monitor_from_window(ws->os); + String8 monitor_name = wm_name_from_monitor(scratch.arena, monitor); CFG_Node *monitor_root = cfg_node_child_from_string_or_alloc(rd_state->cfg, window, str8_lit("monitor")); if(!str8_match(monitor_root->first->string, monitor_name, 0)) { @@ -5422,13 +5422,13 @@ rd_window_frame(void) //////////////////////////// //- rjf: @window_ui_part calculate top-level rectangles/sizes // - Rng2F32 window_rect = os_client_rect_from_window(ws->os); + Rng2F32 window_rect = wm_client_rect_from_window(ws->os); Vec2F32 window_rect_dim = dim_2f32(window_rect); F32 top_bar_dim_px = floor_f32(ui_top_font_size()*3.f); Rng2F32 top_bar_rect = r2f32p(window_rect.x0, window_rect.y0, window_rect.x0+window_rect_dim.x+1, window_rect.y0+top_bar_dim_px); Rng2F32 bottom_bar_rect = r2f32p(window_rect.x0, window_rect_dim.y - top_bar_dim_px, window_rect.x0+window_rect_dim.x, window_rect.y0+window_rect_dim.y); Rng2F32 content_rect = r2f32p(window_rect.x0, top_bar_rect.y1, window_rect.x0+window_rect_dim.x, bottom_bar_rect.y0); - F32 window_edge_px = os_dpi_from_window(ws->os)*0.035f; + F32 window_edge_px = wm_dpi_from_window(ws->os)*0.035f; content_rect = pad_2f32(content_rect, -window_edge_px); //////////////////////////// @@ -6436,7 +6436,7 @@ rd_window_frame(void) if(t->force_inside_window_x || t->force_inside_window_y) { B32 axis_mask[] = {t->force_inside_window_x, t->force_inside_window_y}; - Rng2F32 window_rect = os_client_rect_from_window(ws->os); + Rng2F32 window_rect = wm_client_rect_from_window(ws->os); for EachEnumVal(Axis2, axis) { if(!axis_mask[axis]) { continue; } @@ -6497,7 +6497,7 @@ rd_window_frame(void) for(UI_Event *evt = 0; ui_next_event(&evt);) { if(evt->kind == UI_EventKind_Press && - evt->key == OS_Key_LeftMouseButton) + evt->key == WM_Key_LeftMouseButton) { if(contains_2f32(container->rect, evt->pos)) { @@ -6645,9 +6645,9 @@ rd_window_frame(void) // ProfScope("build top bar") { - os_window_clear_custom_border_data(ws->os); - os_window_push_custom_edges(ws->os, window_edge_px); - os_window_push_custom_title_bar(ws->os, dim_2f32(top_bar_rect).y); + wm_window_clear_custom_border_data(ws->os); + wm_window_push_custom_edges(ws->os, window_edge_px); + wm_window_push_custom_title_bar(ws->os, dim_2f32(top_bar_rect).y); ui_set_next_flags(UI_BoxFlag_DefaultFocusNav|UI_BoxFlag_DisableFocusOverlay); UI_Focus((ws->menu_bar_focused && window_is_focused && !ui_any_ctx_menu_is_open()) ? UI_FocusKind_On : UI_FocusKind_Null) UI_TagF("menu_bar") @@ -6911,7 +6911,7 @@ rd_window_frame(void) if(key_map_nodes.first != 0) { binding = key_map_nodes.first->v->binding; - binding_str = os_string_from_modifiers_key(scratch.arena, binding.modifiers, binding.key); + binding_str = wm_string_from_modifiers_key(scratch.arena, binding.modifiers, binding.key); } UI_TagF(".") UI_Row @@ -6945,7 +6945,7 @@ rd_window_frame(void) UI_Signal sig = ui_button(str8_lit("Submit request, issue, or bug report")); if(ui_clicked(sig)) { - os_open_in_browser(url); + wm_open_in_browser(url); } } ui_spacer(ui_em(0.5f, 1.f)); @@ -6959,18 +6959,18 @@ rd_window_frame(void) { String8 name; U32 codepoint; - OS_Key key; + WM_Key key; UI_Key menu_key; } items[] = { - {str8_lit("File"), 'f', OS_Key_F, file_menu_key}, - {str8_lit("Window"), 'w', OS_Key_W, window_menu_key}, - {str8_lit("Panel"), 'p', OS_Key_P, panel_menu_key}, - {str8_lit("Tab"), 'b', OS_Key_V, tab_menu_key}, - {str8_lit("Targets"), 't', OS_Key_T, targets_menu_key}, - {str8_lit("Control"), 'c', OS_Key_C, ctrl_menu_key}, - {str8_lit("Help"), 'h', OS_Key_H, help_menu_key}, + {str8_lit("File"), 'f', WM_Key_F, file_menu_key}, + {str8_lit("Window"), 'w', WM_Key_W, window_menu_key}, + {str8_lit("Panel"), 'p', WM_Key_P, panel_menu_key}, + {str8_lit("Tab"), 'b', WM_Key_V, tab_menu_key}, + {str8_lit("Targets"), 't', WM_Key_T, targets_menu_key}, + {str8_lit("Control"), 'c', WM_Key_C, ctrl_menu_key}, + {str8_lit("Help"), 'h', WM_Key_H, help_menu_key}, }; // rjf: determine if one of the menus is already open @@ -7016,7 +7016,7 @@ rd_window_frame(void) { ui_set_next_fastpath_codepoint(items[idx].codepoint); B32 alt_fastpath_key = 0; - if(rd_setting_b32_from_name(str8_lit("focus_menu_bar_with_alt")) && ui_key_press(OS_Modifier_Alt, items[idx].key)) + if(rd_setting_b32_from_name(str8_lit("focus_menu_bar_with_alt")) && ui_key_press(WM_Modifier_Alt, items[idx].key)) { alt_fastpath_key = 1; } @@ -7025,7 +7025,7 @@ rd_window_frame(void) ui_set_next_flags(UI_BoxFlag_DrawTextFastpathCodepoint); } UI_Signal sig = rd_menu_bar_button(items[idx].name); - os_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); + wm_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); if(menu_open) { if((ui_hovering(sig) && !ui_ctx_menu_is_open(items[idx].menu_key)) || (open_menu_idx_prime == idx && open_menu_idx_prime != open_menu_idx)) @@ -7086,7 +7086,7 @@ rd_window_frame(void) { String8 cmd_name = center_button_tasks[idx].cmd_name; UI_Signal sig = ui_button(rd_icon_kind_text_table[rd_icon_kind_from_code_name(cmd_name)]); - os_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); + wm_window_push_custom_title_bar_client_area(ws->os, sig.box->rect); if(ui_hovering(sig)) { RD_RegsScope(.cmd_name = cmd_name, .ui_key = sig.box->key) rd_set_hover_regs(RD_RegSlot_CmdName); @@ -7119,7 +7119,7 @@ rd_window_frame(void) UI_BoxFlag_DrawHotEffects| UI_BoxFlag_DrawActiveEffects, "###loaded_user_button"); - os_window_push_custom_title_bar_client_area(ws->os, user_box->rect); + wm_window_push_custom_title_bar_client_area(ws->os, user_box->rect); UI_Parent(user_box) UI_PrefWidth(ui_text_dim(10, 0)) UI_TextAlignment(UI_TextAlign_Center) { String8 user_path = rd_state->user_path; @@ -7153,7 +7153,7 @@ rd_window_frame(void) UI_BoxFlag_DrawHotEffects| UI_BoxFlag_DrawActiveEffects, "###loaded_project_button"); - os_window_push_custom_title_bar_client_area(ws->os, prof_box->rect); + wm_window_push_custom_title_bar_client_area(ws->os, prof_box->rect); UI_Parent(prof_box) UI_PrefWidth(ui_text_dim(10, 0)) UI_TextAlignment(UI_TextAlign_Center) UI_Padding(ui_em(0.5f, 1.f)) { CFG_Node *root = cfg_node_root(); @@ -7207,7 +7207,7 @@ rd_window_frame(void) UI_FontSize(ui_top_font_size()*0.75f) { min_sig = rd_icon_buttonf(RD_IconKind_WindowMinimize, 0, "##minimize"); - max_sig = rd_icon_buttonf(os_window_is_maximized(ws->os) ? RD_IconKind_WindowRestore : RD_IconKind_Window, 0, "##maximize"); + max_sig = rd_icon_buttonf(wm_window_is_maximized(ws->os) ? RD_IconKind_WindowRestore : RD_IconKind_Window, 0, "##maximize"); } UI_PrefWidth(ui_px(button_dim, 1.f)) UI_TagF("bad_pop") @@ -7216,11 +7216,11 @@ rd_window_frame(void) } if(ui_clicked(min_sig)) { - os_window_set_minimized(ws->os, 1); + wm_window_set_minimized(ws->os, 1); } if(ui_clicked(max_sig)) { - os_window_set_maximized(ws->os, !os_window_is_maximized(ws->os)); + wm_window_set_maximized(ws->os, !wm_window_is_maximized(ws->os)); } if(ui_clicked(cls_sig)) { @@ -7234,9 +7234,9 @@ rd_window_frame(void) rd_cmd(RD_CmdKind_Exit); } } - os_window_push_custom_title_bar_client_area(ws->os, min_sig.box->rect); - os_window_push_custom_title_bar_client_area(ws->os, max_sig.box->rect); - os_window_push_custom_title_bar_client_area(ws->os, pad_2f32(cls_sig.box->rect, 2.f)); + wm_window_push_custom_title_bar_client_area(ws->os, min_sig.box->rect); + wm_window_push_custom_title_bar_client_area(ws->os, max_sig.box->rect); + wm_window_push_custom_title_bar_client_area(ws->os, pad_2f32(cls_sig.box->rect, 2.f)); } } } @@ -7629,7 +7629,7 @@ rd_window_frame(void) UI_Rect(boundary_rect) { - ui_set_next_hover_cursor(split_axis == Axis2_X ? OS_Cursor_LeftRight : OS_Cursor_UpDown); + ui_set_next_hover_cursor(split_axis == Axis2_X ? WM_Cursor_LeftRight : WM_Cursor_UpDown); UI_Box *box = ui_build_box_from_stringf(UI_BoxFlag_Clickable, "###%p_%p", min_child->cfg, max_child->cfg); UI_Signal sig = ui_signal_from_box(box); if(ui_double_clicked(sig)) @@ -8569,7 +8569,7 @@ rd_window_frame(void) // for(UI_Event *evt = 0; ui_next_event(&evt);) { - if(evt->kind == UI_EventKind_Scroll && evt->modifiers == OS_Modifier_Ctrl) + if(evt->kind == UI_EventKind_Scroll && evt->modifiers == WM_Modifier_Ctrl) { ui_eat_event(evt); if(evt->delta_2f32.y < 0) @@ -8614,7 +8614,7 @@ rd_window_frame(void) { Temp scratch = scratch_begin(0, 0); F32 box_squish_epsilon = 0.001f; - Rng2F32 window_rect = os_client_rect_from_window(ws->os); + Rng2F32 window_rect = wm_client_rect_from_window(ws->os); //- rjf: unpack settings F32 rounded_corner_amount = rd_setting_f32_from_name(str8_lit("rounded_corner_amount")); @@ -8634,7 +8634,7 @@ rd_window_frame(void) U64 heatmap_bucket_count = 0; if(DEV_draw_ui_box_heatmap) { - Rng2F32 rect = os_client_rect_from_window(ws->os); + Rng2F32 rect = wm_client_rect_from_window(ws->os); Vec2F32 size = dim_2f32(rect); Vec2S32 buckets_dim = {(S32)(size.x/heatmap_bucket_size), (S32)(size.y/heatmap_bucket_size)}; heatmap_bucket_pitch = buckets_dim.x; @@ -8644,12 +8644,12 @@ rd_window_frame(void) //- rjf: draw background color { - dr_rect(os_client_rect_from_window(ws->os), base_background_color, 0, 0, 0); + dr_rect(wm_client_rect_from_window(ws->os), base_background_color, 0, 0, 0); } //- rjf: draw window border { - dr_rect(os_client_rect_from_window(ws->os), base_border_color, 0, 1.f, border_softness*0.5f); + dr_rect(wm_client_rect_from_window(ws->os), base_border_color, 0, 1.f, border_softness*0.5f); } //- rjf: recurse & draw @@ -9117,7 +9117,7 @@ rd_window_frame(void) { Vec4F32 color = ui_color_from_name(str8_lit("text")); color.w *= ws->error_t; - Rng2F32 rect = os_client_rect_from_window(ws->os); + Rng2F32 rect = wm_client_rect_from_window(ws->os); dr_rect(pad_2f32(rect, 24.f), color, 0, 16.f, 12.f); dr_rect(rect, v4f32(color.x, color.y, color.z, color.w*0.025f), 0, 0, 0); } @@ -9126,7 +9126,7 @@ rd_window_frame(void) if(rd_state->bind_change_active) UI_TagF("pop") { Vec4F32 color = ui_color_from_name(str8_lit("background")); - Rng2F32 rect = os_client_rect_from_window(ws->os); + Rng2F32 rect = wm_client_rect_from_window(ws->os); dr_rect(pad_2f32(rect, 24.f), color, 0, 16.f, 12.f); dr_rect(rect, v4f32(color.x, color.y, color.z, color.w*0.025f), 0, 0, 0); } @@ -9138,7 +9138,7 @@ rd_window_frame(void) //- rjf: @window_frame_part update per-window frame counters/info // ws->frames_alive += 1; - ws->last_window_rect = os_client_rect_from_window(ws->os); + ws->last_window_rect = wm_client_rect_from_window(ws->os); ProfEnd(); scratch_end(scratch); @@ -10707,7 +10707,7 @@ rd_frame(void) B32 any_window_is_focused = 0; for(RD_WindowState *w = rd_state->first_window_state; w != &rd_nil_window_state; w = w->order_next) { - if(os_window_is_focused(w->os)) + if(wm_window_is_focused(w->os)) { any_window_is_focused = 1; break; @@ -10757,10 +10757,10 @@ rd_frame(void) ////////////////////////////// //- rjf: get events from the OS // - OS_EventList events = {0}; + WM_EventList events = {0}; if(rd_state->frame_depth == 1) { - events = os_get_events(scratch.arena, rd_state->num_frames_requested == 0 && !DEV_always_refresh); + events = wm_get_events(scratch.arena, rd_state->num_frames_requested == 0 && !DEV_always_refresh); } ////////////////////////////// @@ -10794,7 +10794,7 @@ rd_frame(void) // // TODO(rjf): maximize target, given all windows and their monitors // - F32 target_hz = os_get_gfx_info()->default_refresh_rate; + F32 target_hz = wm_get_system_info()->default_refresh_rate; if(rd_state->frame_index > 32) { F32 possible_alternate_hz_targets[] = {target_hz, 60.f, 75.f, 120.f, 144.f, 165.f, 240.f, 360.f}; @@ -10847,30 +10847,30 @@ rd_frame(void) // if(!rd_state->popup_active && rd_state->bind_change_active) { - if(os_key_press(&events, os_window_zero(), 0, OS_Key_Esc)) + if(wm_key_press(&events, wm_window_zero(), 0, WM_Key_Esc)) { rd_request_frame(); rd_state->bind_change_active = 0; } - if(os_key_press(&events, os_window_zero(), 0, OS_Key_Delete)) + if(wm_key_press(&events, wm_window_zero(), 0, WM_Key_Delete)) { rd_request_frame(); cfg_node_release(rd_state->cfg, cfg_node_from_id(rd_state->bind_change_binding_id)); rd_state->bind_change_active = 0; } - for(OS_Event *event = events.first, *next = 0; event != 0; event = next) + for(WM_Event *event = events.first, *next = 0; event != 0; event = next) { - if(event->kind == OS_EventKind_Press && - event->key != OS_Key_Esc && - event->key != OS_Key_Return && - event->key != OS_Key_Backspace && - event->key != OS_Key_Delete && - event->key != OS_Key_LeftMouseButton && - event->key != OS_Key_RightMouseButton && - event->key != OS_Key_MiddleMouseButton && - event->key != OS_Key_Ctrl && - event->key != OS_Key_Alt && - event->key != OS_Key_Shift) + if(event->kind == WM_EventKind_Press && + event->key != WM_Key_Esc && + event->key != WM_Key_Return && + event->key != WM_Key_Backspace && + event->key != WM_Key_Delete && + event->key != WM_Key_LeftMouseButton && + event->key != WM_Key_RightMouseButton && + event->key != WM_Key_MiddleMouseButton && + event->key != WM_Key_Ctrl && + event->key != WM_Key_Alt && + event->key != WM_Key_Shift) { rd_state->bind_change_active = 0; CFG_Node *binding = cfg_node_from_id(rd_state->bind_change_binding_id); @@ -10882,13 +10882,13 @@ rd_frame(void) } cfg_node_release_all_children(rd_state->cfg, binding); cfg_node_new(rd_state->cfg, binding, rd_state->bind_change_cmd_name); - cfg_node_new(rd_state->cfg, binding, os_g_key_cfg_string_table[event->key]); - if(event->modifiers & OS_Modifier_Ctrl) { cfg_node_new(rd_state->cfg, binding, str8_lit("ctrl")); } - if(event->modifiers & OS_Modifier_Shift) { cfg_node_new(rd_state->cfg, binding, str8_lit("shift")); } - if(event->modifiers & OS_Modifier_Alt) { cfg_node_new(rd_state->cfg, binding, str8_lit("alt")); } - U32 codepoint = os_codepoint_from_modifiers_and_key(event->modifiers, event->key); - os_text(&events, event->window, codepoint); - os_eat_event(&events, event); + cfg_node_new(rd_state->cfg, binding, wm_key_cfg_name_table[event->key]); + if(event->modifiers & WM_Modifier_Ctrl) { cfg_node_new(rd_state->cfg, binding, str8_lit("ctrl")); } + if(event->modifiers & WM_Modifier_Shift) { cfg_node_new(rd_state->cfg, binding, str8_lit("shift")); } + if(event->modifiers & WM_Modifier_Alt) { cfg_node_new(rd_state->cfg, binding, str8_lit("alt")); } + U32 codepoint = wm_codepoint_from_modifiers_and_key(event->modifiers, event->key); + wm_text(&events, event->window, codepoint); + wm_eat_event(&events, event); rd_request_frame(); break; } @@ -10928,7 +10928,7 @@ rd_frame(void) // ProfScope("consume events") { - for(OS_Event *event = events.first, *next = 0; + for(WM_Event *event = events.first, *next = 0; event != 0; event = next) RD_RegsScope() @@ -10948,13 +10948,13 @@ rd_frame(void) B32 take = 0; //- rjf: try drag/drop drop-kickoff - if(rd_drag_is_active() && event->kind == OS_EventKind_Release && event->key == OS_Key_LeftMouseButton) + if(rd_drag_is_active() && event->kind == WM_EventKind_Release && event->key == WM_Key_LeftMouseButton) { rd_state->drag_drop_state = RD_DragDropState_Dropping; } //- rjf: try window close - if(!take && event->kind == OS_EventKind_WindowClose && ws != 0) + if(!take && event->kind == WM_EventKind_WindowClose && ws != 0) { take = 1; rd_cmd(RD_CmdKind_Exit); @@ -10963,7 +10963,7 @@ rd_frame(void) //- rjf: try menu bar operations if(rd_state->alt_menu_bar_enabled) { - if(!take && event->kind == OS_EventKind_Press && event->key == OS_Key_Alt && event->modifiers == 0 && event->is_repeat == 0) + if(!take && event->kind == WM_EventKind_Press && event->key == WM_Key_Alt && event->modifiers == 0 && event->is_repeat == 0) { take = 1; rd_request_frame(); @@ -10971,26 +10971,26 @@ rd_frame(void) ws->menu_bar_key_held = 1; ws->menu_bar_focus_press_started = 1; } - if(!take && event->kind == OS_EventKind_Release && event->key == OS_Key_Alt && event->modifiers == 0 && event->is_repeat == 0) + if(!take && event->kind == WM_EventKind_Release && event->key == WM_Key_Alt && event->modifiers == 0 && event->is_repeat == 0) { take = 1; rd_request_frame(); ws->menu_bar_key_held = 0; } - if(ws->menu_bar_focused && event->kind == OS_EventKind_Press && event->key == OS_Key_Alt && event->modifiers == 0 && event->is_repeat == 0) + if(ws->menu_bar_focused && event->kind == WM_EventKind_Press && event->key == WM_Key_Alt && event->modifiers == 0 && event->is_repeat == 0) { take = 1; rd_request_frame(); ws->menu_bar_focused = 0; } - else if(ws->menu_bar_focus_press_started && !ws->menu_bar_focused && event->kind == OS_EventKind_Release && event->modifiers == 0 && event->key == OS_Key_Alt && event->is_repeat == 0) + else if(ws->menu_bar_focus_press_started && !ws->menu_bar_focused && event->kind == WM_EventKind_Release && event->modifiers == 0 && event->key == WM_Key_Alt && event->is_repeat == 0) { take = 1; rd_request_frame(); ws->menu_bar_focused = !ws->menu_bar_focused_on_press; ws->menu_bar_focus_press_started = 0; } - else if(event->kind == OS_EventKind_Press && event->key == OS_Key_Esc && ws->menu_bar_focused && !ui_any_ctx_menu_is_open()) + else if(event->kind == WM_EventKind_Press && event->key == WM_Key_Esc && ws->menu_bar_focused && !ui_any_ctx_menu_is_open()) { take = 1; rd_request_frame(); @@ -10999,13 +10999,13 @@ rd_frame(void) } //- rjf: try hotkey presses - if(!take && event->kind == OS_EventKind_Press) + if(!take && event->kind == WM_EventKind_Press) { CFG_Binding binding = {event->key, event->modifiers}; CFG_KeyMapNodePtrList key_map_nodes = cfg_key_map_node_ptr_list_from_binding(scratch.arena, rd_state->key_map, binding); if(key_map_nodes.first != 0) { - U32 hit_char = os_codepoint_from_modifiers_and_key(event->modifiers, event->key); + U32 hit_char = wm_codepoint_from_modifiers_and_key(event->modifiers, event->key); if(hit_char == 0 || allow_text_hotkeys) { String8 cmd_name = key_map_nodes.first->v->name; @@ -11019,17 +11019,17 @@ rd_frame(void) rd_cmd(RD_CmdKind_RunCommand, .cmd_name = cmd_name); if(allow_text_hotkeys) { - os_text(&events, event->window, hit_char); + wm_text(&events, event->window, hit_char); next = event->next; } take = 1; - if(event->modifiers & OS_Modifier_Alt) + if(event->modifiers & WM_Modifier_Alt) { ws->menu_bar_focus_press_started = 0; } } } - else if(OS_Key_F1 <= event->key && event->key <= OS_Key_F19) + else if(WM_Key_F1 <= event->key && event->key <= WM_Key_F19) { ws->menu_bar_focus_press_started = 0; } @@ -11037,14 +11037,14 @@ rd_frame(void) } //- rjf: try text events - if(!take && event->kind == OS_EventKind_Text) + if(!take && event->kind == WM_EventKind_Text) { String32 insertion32 = str32(&event->character, 1); String8 insertion8 = str8_from_32(scratch.arena, insertion32); rd_cmd(RD_CmdKind_InsertText, .string = insertion8); rd_request_frame(); take = 1; - if(event->modifiers & OS_Modifier_Alt) + if(event->modifiers & WM_Modifier_Alt) { ws->menu_bar_focus_press_started = 0; } @@ -11054,13 +11054,13 @@ rd_frame(void) if(!take) { take = 1; - rd_cmd(RD_CmdKind_OSEvent, .os_event = event); + rd_cmd(RD_CmdKind_WMEvent, .wm_event = event); } //- rjf: take if(take) { - os_eat_event(&events, event); + wm_eat_event(&events, event); } } } @@ -12146,7 +12146,7 @@ rd_frame(void) // rjf: run -> refocus pre-stop focused window if(kind == RD_CmdKind_Run) { - os_focus_external_window(rd_state->prestop_focused_window); + wm_focus_external_window(rd_state->prestop_focused_window); } // rjf: run -> no active targets, no processes, but we only have one target? -> just launch it, then select it @@ -12278,7 +12278,7 @@ rd_frame(void) { current_path_string = path_normalized_from_string(scratch.arena, get_current_path(scratch.arena)); } - String8 file_path = os_graphical_pick_file(scratch.arena, current_path_string); + String8 file_path = wm_graphical_pick_file(scratch.arena, current_path_string); file_path = path_normalized_from_string(scratch.arena, file_path); if(file_path.size != 0) { @@ -12418,7 +12418,7 @@ rd_frame(void) RD_WindowState *ws = rd_window_state_from_cfg(wcfg); if(ws != &rd_nil_window_state) { - os_window_set_fullscreen(ws->os, !os_window_is_fullscreen(ws->os)); + wm_window_set_fullscreen(ws->os, !wm_window_is_fullscreen(ws->os)); } }break; case RD_CmdKind_BringToFront: @@ -12431,8 +12431,8 @@ rd_frame(void) } if(last_focused_ws != &rd_nil_window_state) { - os_window_set_minimized(last_focused_ws->os, 0); - os_window_focus(last_focused_ws->os); + wm_window_set_minimized(last_focused_ws->os, 0); + wm_window_focus(last_focused_ws->os); } }break; @@ -12468,10 +12468,10 @@ rd_frame(void) CFG_Binding binding = rd_default_binding_table[idx].binding; CFG_Node *binding_root = cfg_node_new(rd_state->cfg, keybindings, str8_zero()); cfg_node_new(rd_state->cfg, binding_root, name); - cfg_node_new(rd_state->cfg, binding_root, os_g_key_cfg_string_table[binding.key]); - if(binding.modifiers & OS_Modifier_Ctrl) {cfg_node_newf(rd_state->cfg, binding_root, "ctrl");} - if(binding.modifiers & OS_Modifier_Shift) {cfg_node_newf(rd_state->cfg, binding_root, "shift");} - if(binding.modifiers & OS_Modifier_Alt) {cfg_node_newf(rd_state->cfg, binding_root, "alt");} + cfg_node_new(rd_state->cfg, binding_root, wm_key_cfg_name_table[binding.key]); + if(binding.modifiers & WM_Modifier_Ctrl) {cfg_node_newf(rd_state->cfg, binding_root, "ctrl");} + if(binding.modifiers & WM_Modifier_Shift) {cfg_node_newf(rd_state->cfg, binding_root, "shift");} + if(binding.modifiers & WM_Modifier_Alt) {cfg_node_newf(rd_state->cfg, binding_root, "alt");} } }break; @@ -12583,10 +12583,10 @@ rd_frame(void) CFG_NodePtrList all_user_windows = cfg_node_child_list_from_string(scratch.arena, file_root, str8_lit("window")); if(all_user_windows.count == 0) { - OS_Monitor monitor = os_primary_monitor(); - String8 monitor_name = os_name_from_monitor(scratch.arena, monitor); - Vec2F32 monitor_dim = os_dim_from_monitor(monitor); - F32 monitor_dpi = os_dpi_from_monitor(monitor); + WM_Monitor monitor = wm_primary_monitor(); + String8 monitor_name = wm_name_from_monitor(scratch.arena, monitor); + Vec2F32 monitor_dim = wm_dim_from_monitor(monitor); + F32 monitor_dpi = wm_dpi_from_monitor(monitor); Vec2F32 window_dim = v2f32(monitor_dim.x*4/5, monitor_dim.y*4/5); if(window_dim.x == 0 || window_dim.y == 0) { @@ -13546,7 +13546,7 @@ rd_frame(void) CFG_Node *tab = cfg_node_from_id(rd_regs()->tab); String8 expr = rd_expr_from_cfg(tab); String8 full_path = rd_file_path_from_eval_string(scratch.arena, expr); - os_set_clipboard_text(full_path); + wm_set_clipboard_text(full_path); }break; case RD_CmdKind_CloseTab: { @@ -13720,7 +13720,7 @@ rd_frame(void) if(rd_regs()->file_path.size != 0) { String8 full_path = rd_regs()->file_path; - os_show_in_filesystem_ui(full_path); + wm_show_in_filesystem_ui(full_path); }break; //- rjf: source <-> disasm @@ -15580,34 +15580,34 @@ rd_frame(void) }break; //- rjf: os event passthrough - case RD_CmdKind_OSEvent: + case RD_CmdKind_WMEvent: { - OS_Event *os_event = rd_regs()->os_event; - RD_WindowState *ws = rd_window_state_from_os_handle(os_event->window); - if(os_event != 0 && ws != &rd_nil_window_state) + WM_Event *wm_event = rd_regs()->wm_event; + RD_WindowState *ws = rd_window_state_from_os_handle(wm_event->window); + if(wm_event != 0 && ws != &rd_nil_window_state) { UI_Event ui_event = zero_struct; UI_EventKind kind = UI_EventKind_Null; { - switch(os_event->kind) + switch(wm_event->kind) { default:{}break; - case OS_EventKind_Press: {kind = UI_EventKind_Press;}break; - case OS_EventKind_Release: {kind = UI_EventKind_Release;}break; - case OS_EventKind_MouseMove: {kind = UI_EventKind_MouseMove;}break; - case OS_EventKind_Text: {kind = UI_EventKind_Text;}break; - case OS_EventKind_Scroll: {kind = UI_EventKind_Scroll;}break; - case OS_EventKind_FileDrop: {kind = UI_EventKind_FileDrop;}break; + case WM_EventKind_Press: {kind = UI_EventKind_Press;}break; + case WM_EventKind_Release: {kind = UI_EventKind_Release;}break; + case WM_EventKind_MouseMove: {kind = UI_EventKind_MouseMove;}break; + case WM_EventKind_Text: {kind = UI_EventKind_Text;}break; + case WM_EventKind_Scroll: {kind = UI_EventKind_Scroll;}break; + case WM_EventKind_FileDrop: {kind = UI_EventKind_FileDrop;}break; } } ui_event.kind = kind; - ui_event.key = os_event->key; - ui_event.modifiers = os_event->modifiers; - ui_event.string = os_event->character ? str8_from_32(ui_build_arena(), str32(&os_event->character, 1)) : str8_zero(); - ui_event.paths = str8_list_copy(ui_build_arena(), &os_event->strings); - ui_event.pos = os_event->pos; - ui_event.delta_2f32 = os_event->delta; - ui_event.timestamp_us = os_event->timestamp_us; + ui_event.key = wm_event->key; + ui_event.modifiers = wm_event->modifiers; + ui_event.string = wm_event->character ? str8_from_32(ui_build_arena(), str32(&wm_event->character, 1)) : str8_zero(); + ui_event.paths = str8_list_copy(ui_build_arena(), &wm_event->strings); + ui_event.pos = wm_event->pos; + ui_event.delta_2f32 = wm_event->delta; + ui_event.timestamp_us = wm_event->timestamp_us; ui_event_list_push(scratch.arena, &ws->ui_events, &ui_event); } }break; @@ -16138,7 +16138,7 @@ rd_frame(void) UI_Event evt = zero_struct; evt.kind = UI_EventKind_Text; evt.flags = UI_EventFlag_Paste; - evt.string = os_get_clipboard_text(scratch.arena); + evt.string = wm_get_clipboard_text(scratch.arena); ui_event_list_push(scratch.arena, &ws->ui_events, &evt); }break; case RD_CmdKind_InsertText: @@ -16483,7 +16483,7 @@ rd_frame(void) B32 any_window_is_focused = 0; for(RD_WindowState *ws = rd_state->first_window_state; ws != &rd_nil_window_state; ws = ws->order_next) { - if(os_window_is_focused(ws->os)) + if(wm_window_is_focused(ws->os)) { any_window_is_focused = 1; break; @@ -16499,10 +16499,10 @@ rd_frame(void) } if(ws != &rd_nil_window_state) { - rd_state->prestop_focused_window = os_focused_external_window(); - os_window_set_minimized(ws->os, 0); - os_window_bring_to_front(ws->os); - os_window_focus(ws->os); + rd_state->prestop_focused_window = wm_focused_external_window(); + wm_window_set_minimized(ws->os, 0); + wm_window_bring_to_front(ws->os); + wm_window_focus(ws->os); } } } @@ -16538,7 +16538,7 @@ rd_frame(void) { for(RD_WindowState *ws = rd_state->first_window_state; ws != &rd_nil_window_state; ws = ws->order_next) { - os_window_set_title(ws->os, window_title); + wm_window_set_title(ws->os, window_title); } } rd_state->last_window_title = str8_copy(rd_frame_arena(), window_title); @@ -16689,7 +16689,7 @@ rd_frame(void) { CFG_Node *window = n->v; RD_WindowState *w = rd_window_state_from_cfg(window); - B32 window_is_focused = os_window_is_focused(w->os); + B32 window_is_focused = wm_window_is_focused(w->os); if(window_is_focused) { rd_state->last_focused_window = w->cfg_id; @@ -16720,7 +16720,7 @@ rd_frame(void) { ui_state_release(ws->ui); r_window_unequip(ws->os, ws->r); - os_window_close(ws->os); + wm_window_close(ws->os); arena_release(ws->drop_completion_arena); arena_release(ws->query_arena); arena_release(ws->hover_eval_arena); @@ -16800,7 +16800,7 @@ rd_frame(void) { CFG_Node *window = cfg_node_from_id(n->v); RD_WindowState *ws = rd_window_state_from_cfg(window); - os_window_first_paint(ws->os); + wm_window_first_paint(ws->os); } } diff --git a/src/raddbg/raddbg_core.h b/src/raddbg/raddbg_core.h index 417ccd7a..f554f260 100644 --- a/src/raddbg/raddbg_core.h +++ b/src/raddbg/raddbg_core.h @@ -283,7 +283,7 @@ struct RD_WindowState // rjf: top-level info & handles Arena *arena; - OS_Window os; + WM_Window os; R_Handle r; UI_State *ui; F32 last_dpi; @@ -543,7 +543,7 @@ struct RD_State String8 bind_change_cmd_name; // rjf: pre-stop focused window - OS_ExternalWindow prestop_focused_window; + WM_ExtWindow prestop_focused_window; }; //////////////////////////////// @@ -730,7 +730,7 @@ internal void rd_store_view_paramf(String8 key, char *fmt, ...); internal String8 rd_push_window_title(Arena *arena); internal CFG_Node *rd_window_from_cfg(CFG_Node *cfg); internal RD_WindowState *rd_window_state_from_cfg(CFG_Node *cfg); -internal RD_WindowState *rd_window_state_from_os_handle(OS_Window os); +internal RD_WindowState *rd_window_state_from_os_handle(WM_Window os); internal void rd_window_frame(void); //////////////////////////////// diff --git a/src/raddbg/raddbg_eval.c b/src/raddbg/raddbg_eval.c index 0bed5d80..28c88fa9 100644 --- a/src/raddbg/raddbg_eval.c +++ b/src/raddbg/raddbg_eval.c @@ -46,7 +46,7 @@ E_TYPE_EXPAND_INFO_FUNCTION_DEF(commands) CFG_KeyMapNodePtrList bindings = cfg_key_map_node_ptr_list_from_name(scratch.arena, rd_state->key_map, code_name); for(CFG_KeyMapNodePtr *n = bindings.first; n != 0; n = n->next) { - String8 binding_text = os_string_from_modifiers_key(scratch.arena, n->v->binding.modifiers, n->v->binding.key); + String8 binding_text = wm_string_from_modifiers_key(scratch.arena, n->v->binding.modifiers, n->v->binding.key); FuzzyMatchRangeList matches = fuzzy_match_find(scratch.arena, filter, binding_text); if(matches.count == matches.needle_part_count) { diff --git a/src/raddbg/raddbg_main.c b/src/raddbg/raddbg_main.c index a6c1d83f..b3da3aef 100644 --- a/src/raddbg/raddbg_main.c +++ b/src/raddbg/raddbg_main.c @@ -250,7 +250,7 @@ #define DMN_INIT_MANUAL 1 #define D_INIT_MANUAL 1 -#define OS_GFX_INIT_MANUAL 1 +#define WM_INIT_MANUAL 1 #define FP_INIT_MANUAL 1 #define R_INIT_MANUAL 1 #define FNT_INIT_MANUAL 1 @@ -430,7 +430,7 @@ ipc_signaler_thread__entry_point(void *p) cond_var_wait(ipc_s2m_ring_cv, ipc_s2m_ring_mutex, max_U64); } cond_var_broadcast(ipc_s2m_ring_cv); - os_send_wakeup_event(); + wm_send_wakeup_event(); ipc_info->msg_size = 0; semaphore_drop(ipc_sender2main_lock_semaphore); } @@ -443,7 +443,7 @@ ipc_signaler_thread__entry_point(void *p) internal D_WAKEUP_FUNCTION_DEF(wakeup_hook_ctrl) { - os_send_wakeup_event(); + wm_send_wakeup_event(); } //////////////////////////////// @@ -544,7 +544,7 @@ entry_point(CmdLine *cmd_line) { dmn_init(); d_init(); - os_gfx_init(); + wm_init(); fp_init(); r_init(cmd_line); fnt_init(); @@ -621,7 +621,7 @@ entry_point(CmdLine *cmd_line) RD_WindowState *dst_ws = rd_state->first_window_state; for(RD_WindowState *ws = dst_ws; ws != &rd_nil_window_state; ws = ws->order_next) { - if(os_window_is_focused(ws->os)) + if(wm_window_is_focused(ws->os)) { dst_ws = ws; break; @@ -810,7 +810,7 @@ entry_point(CmdLine *cmd_line) //- rjf: help message box case ExecMode_Help: { - os_graphical_message(0, + wm_graphical_message(0, str8_lit("The RAD Debugger - Help"), str8_lit("The following options may be used when starting the RAD Debugger from the command line:\n\n" "--user:\n" diff --git a/src/raddbg/raddbg_views.c b/src/raddbg/raddbg_views.c index 05f96794..5f98d4ee 100644 --- a/src/raddbg/raddbg_views.c +++ b/src/raddbg/raddbg_views.c @@ -641,7 +641,7 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla } //- rjf: ctrl+pressed? -> go to name - if(ui_pressed(sig.base) && sig.base.event_flags & OS_Modifier_Ctrl) + if(ui_pressed(sig.base) && sig.base.event_flags & WM_Modifier_Ctrl) { ui_kill_action(); rd_cmd(RD_CmdKind_GoToName, .string = txt_string_from_info_data_txt_rng(text_info, text_data, sig.mouse_expr_rng)); @@ -792,7 +792,7 @@ rd_code_view_build(Arena *arena, RD_CodeViewState *cv, RD_CodeViewBuildFlags fla { for(UI_Event *evt = 0; ui_next_event(&evt);) { - if(evt->kind == UI_EventKind_Scroll && evt->modifiers & OS_Modifier_Ctrl && evt->modifiers & OS_Modifier_Shift) + if(evt->kind == UI_EventKind_Scroll && evt->modifiers & WM_Modifier_Ctrl && evt->modifiers & WM_Modifier_Shift) { ui_eat_event(evt); if(evt->delta_2f32.y < 0) @@ -2888,7 +2888,7 @@ RD_VIEW_UI_FUNCTION_DEF(memory) } } String8 data_textified = str8_list_join(scratch.arena, &data_textified_parts, 0); - os_set_clipboard_text(data_textified); + wm_set_clipboard_text(data_textified); } good_action = 1; } @@ -4089,7 +4089,7 @@ RD_VIEW_UI_FUNCTION_DEF(memory) { for(UI_Event *evt = 0; ui_next_event(&evt);) { - if(evt->kind == UI_EventKind_Scroll && evt->modifiers & OS_Modifier_Ctrl) + if(evt->kind == UI_EventKind_Scroll && evt->modifiers & WM_Modifier_Ctrl) { ui_eat_event(evt); if(evt->delta_2f32.y < 0) diff --git a/src/raddbg/raddbg_widgets.c b/src/raddbg/raddbg_widgets.c index a1db6221..9febbbea 100644 --- a/src/raddbg/raddbg_widgets.c +++ b/src/raddbg/raddbg_widgets.c @@ -783,9 +783,9 @@ rd_cmd_binding_buttons(String8 name, String8 filter, B32 add_new) //- rjf: form binding string String8 keybinding_str = {0}; { - if(binding.key != OS_Key_Null) + if(binding.key != WM_Key_Null) { - keybinding_str = os_string_from_modifiers_key(scratch.arena, binding.modifiers, binding.key); + keybinding_str = wm_string_from_modifiers_key(scratch.arena, binding.modifiers, binding.key); } else { @@ -820,7 +820,7 @@ rd_cmd_binding_buttons(String8 name, String8 filter, B32 add_new) // rjf: click => toggle activity if(!rd_state->bind_change_active && ui_clicked(sig)) { - if((binding.key == OS_Key_Esc || binding.key == OS_Key_Delete) && binding.modifiers == 0) + if((binding.key == WM_Key_Esc || binding.key == WM_Key_Delete) && binding.modifiers == 0) { log_user_error(str8_lit("Cannot rebind; this command uses a reserved keybinding.")); } @@ -1262,7 +1262,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe D_Event stop_event = d_ctrl_last_stop_event(); D_Entity *stopper_thread = d_entity_from_handle(&d_user_state->ctrl_entity_store->ctx, stop_event.entity); B32 is_focused = ui_is_focus_active(); - B32 ctrlified = (os_get_modifiers() & OS_Modifier_Ctrl); + B32 ctrlified = (wm_get_modifiers() & WM_Modifier_Ctrl); Vec4F32 code_line_bgs[] = { ui_color_from_name(str8_lit("line_info_0")), @@ -1406,7 +1406,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe line_num += 1, line_idx += 1) { D_EntityList line_ips = params->line_ips[line_idx]; - ui_set_next_hover_cursor(OS_Cursor_HandPoint); + ui_set_next_hover_cursor(WM_Cursor_HandPoint); UI_Box *line_margin_box = ui_build_box_from_stringf(UI_BoxFlag_Clickable*!!(params->flags & RD_CodeSliceFlag_Clickable)|UI_BoxFlag_DrawActiveEffects, "line_margin_%I64x", line_num); UI_Parent(line_margin_box) { @@ -1455,7 +1455,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe } // rjf: build thread box - ui_set_next_hover_cursor(OS_Cursor_UpDownLeftRight); + ui_set_next_hover_cursor(WM_Cursor_UpDownLeftRight); ui_set_next_font(rd_font_from_slot(RD_FontSlot_Icons)); ui_set_next_font_size(params->font_size); ui_set_next_text_raster_flags(FNT_RasterFlag_Smooth); @@ -1561,7 +1561,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe D_EntityList line_ips = params->line_ips[line_idx]; CFG_NodePtrList line_bps = params->line_bps[line_idx]; CFG_NodePtrList line_pins = params->line_pins[line_idx]; - ui_set_next_hover_cursor(OS_Cursor_HandPoint); + ui_set_next_hover_cursor(WM_Cursor_HandPoint); ui_set_next_background_color(v4f32(0, 0, 0, 0)); UI_Box *line_margin_box = ui_build_box_from_stringf(UI_BoxFlag_Clickable*!!(params->flags & RD_CodeSliceFlag_Clickable)|UI_BoxFlag_DrawBackground|UI_BoxFlag_DrawActiveEffects, "line_margin_%I64x", line_num); UI_Parent(line_margin_box) @@ -1611,7 +1611,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe } // rjf: build thread box - ui_set_next_hover_cursor(OS_Cursor_UpDownLeftRight); + ui_set_next_hover_cursor(WM_Cursor_UpDownLeftRight); ui_set_next_font(rd_font_from_slot(RD_FontSlot_Icons)); ui_set_next_font_size(params->font_size); ui_set_next_text_raster_flags(FNT_RasterFlag_Smooth); @@ -1760,7 +1760,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe } // rjf: shift+click => enable breakpoint - if(ui_clicked(bp_sig) && bp_sig.event_flags & OS_Modifier_Shift) + if(ui_clicked(bp_sig) && bp_sig.event_flags & WM_Modifier_Shift) { rd_cmd(bp_is_disabled ? RD_CmdKind_EnableCfg : RD_CmdKind_DisableCfg, .cfg = bp->id); } @@ -1914,7 +1914,7 @@ rd_code_slice(RD_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *prefe UI_Box *text_container_box = &ui_nil_box; UI_Parent(top_container_box) UI_Focus(UI_FocusKind_Off) { - ui_set_next_hover_cursor(ctrlified ? OS_Cursor_HandPoint : OS_Cursor_IBar); + ui_set_next_hover_cursor(ctrlified ? WM_Cursor_HandPoint : WM_Cursor_IBar); ui_set_next_pref_height(ui_px(params->line_height_px*(dim_1s64(params->line_num_range)+1), 1.f)); text_container_box = ui_build_box_from_string(UI_BoxFlag_Clickable*!!(params->flags & RD_CodeSliceFlag_Clickable), str8_lit("text_container")); } @@ -3049,7 +3049,7 @@ rd_do_txt_controls(TXT_TextInfo *info, String8 data, U64 line_count_per_page, Tx if(evt->flags & UI_EventFlag_Copy) { String8 text = txt_string_from_info_data_txt_rng(info, data, txt_rng(*cursor, *mark)); - os_set_clipboard_text(text); + wm_set_clipboard_text(text); taken = 1; } @@ -3447,7 +3447,7 @@ rd_cell(RD_CellParams *params, String8 string) // if(is_focus_active || is_focus_active_disabled) { - ui_set_next_hover_cursor(OS_Cursor_IBar); + ui_set_next_hover_cursor(WM_Cursor_IBar); } UI_Box *box = ui_build_box_from_key(UI_BoxFlag_MouseClickable| (!!build_lhs_name_desc*UI_BoxFlag_DisableFocusBorder)| @@ -3807,7 +3807,7 @@ rd_cell(RD_CellParams *params, String8 string) { F32 extratoggler_padding_px = floor_f32(ui_top_font_size()*0.35f); F32 toggler_size_px = ceil_f32(height_px - extratoggler_padding_px*2.f) - 1.f; - ui_set_next_hover_cursor(OS_Cursor_LeftRight); + ui_set_next_hover_cursor(WM_Cursor_LeftRight); UI_Box *slider_box = ui_build_box_from_stringf(UI_BoxFlag_DrawHotEffects|UI_BoxFlag_DrawBorder|UI_BoxFlag_DrawBackground|UI_BoxFlag_Clickable, "slider"); UI_Parent(slider_box) UI_TagF("pop") { @@ -3883,7 +3883,7 @@ rd_cell(RD_CellParams *params, String8 string) { if(evt->flags & UI_EventFlag_Copy) { - os_set_clipboard_text(params->pre_edit_value); + wm_set_clipboard_text(params->pre_edit_value); } if(evt->flags & UI_EventFlag_Delete) { @@ -4003,7 +4003,7 @@ rd_cell(RD_CellParams *params, String8 string) // rjf: perform copy if(op.flags & UI_TxtOpFlag_Copy) { - os_set_clipboard_text(op.copy); + wm_set_clipboard_text(op.copy); } // rjf: commit op's changed cursor & mark to caller-provided state diff --git a/src/render/d3d11/render_d3d11.c b/src/render/d3d11/render_d3d11.c index 9d80584e..deb28141 100644 --- a/src/render/d3d11/render_d3d11.c +++ b/src/render/d3d11/render_d3d11.c @@ -198,7 +198,7 @@ r_init(CmdLine *cmdln) { char buffer[256] = {0}; raddbg_snprintf(buffer, sizeof(buffer), "D3D11 device creation failure (%lx). The process is terminating.", error); - os_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer)); + wm_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer)); abort_self(1); } ProfEnd(); @@ -370,7 +370,7 @@ r_init(CmdLine *cmdln) { errors = str8((U8 *)vshad_source_errors->lpVtbl->GetBufferPointer(vshad_source_errors), (U64)vshad_source_errors->lpVtbl->GetBufferSize(vshad_source_errors)); - os_graphical_message(1, str8_lit("Vertex Shader Compilation Failure"), errors); + wm_graphical_message(1, str8_lit("Vertex Shader Compilation Failure"), errors); } else { @@ -425,7 +425,7 @@ r_init(CmdLine *cmdln) { errors = str8((U8 *)pshad_source_errors->lpVtbl->GetBufferPointer(pshad_source_errors), (U64)pshad_source_errors->lpVtbl->GetBufferSize(pshad_source_errors)); - os_graphical_message(1, str8_lit("Pixel Shader Compilation Failure"), errors); + wm_graphical_message(1, str8_lit("Pixel Shader Compilation Failure"), errors); } else { @@ -483,7 +483,7 @@ r_init(CmdLine *cmdln) //- rjf: window setup/teardown r_hook R_Handle -r_window_equip(OS_Window handle) +r_window_equip(WM_Window handle) { ProfBeginFunction(); R_Handle result = {0}; @@ -509,8 +509,8 @@ r_window_equip(OS_Window handle) //- rjf: map os window handle -> hwnd HWND hwnd = {0}; { - OS_W32_Window *w32_layer_window = os_w32_window_from_handle(handle); - hwnd = os_w32_hwnd_from_window(w32_layer_window); + W32_WM_Window *w32_layer_window = w32_wm_window_from_handle(handle); + hwnd = w32_wm_hwnd_from_window(w32_layer_window); } //- rjf: create swapchain @@ -534,7 +534,7 @@ r_window_equip(OS_Window handle) { char buffer[256] = {0}; raddbg_snprintf(buffer, sizeof(buffer), "DXGI swap chain creation failure (%lx). The process is terminating.", error); - os_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer)); + wm_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer)); abort_self(1); } @@ -556,7 +556,7 @@ r_window_equip(OS_Window handle) } r_hook void -r_window_unequip(OS_Window handle, R_Handle equip_handle) +r_window_unequip(WM_Window handle, R_Handle equip_handle) { ProfBeginFunction(); MutexScopeW(r_d3d11_state->device_rw_mutex) @@ -861,7 +861,7 @@ r_end_frame(void) } r_hook void -r_window_begin_frame(OS_Window window, R_Handle window_equip) +r_window_begin_frame(WM_Window window, R_Handle window_equip) { ProfBeginFunction(); MutexScopeW(r_d3d11_state->device_rw_mutex) @@ -870,7 +870,7 @@ r_window_begin_frame(OS_Window window, R_Handle window_equip) ID3D11DeviceContext1 *d_ctx = r_d3d11_state->device_ctx; //- rjf: get resolution - Rng2F32 client_rect = os_client_rect_from_window(window); + Rng2F32 client_rect = wm_client_rect_from_window(window); Vec2S32 resolution = {(S32)(client_rect.x1 - client_rect.x0), (S32)(client_rect.y1 - client_rect.y0)}; //- rjf: resolution change @@ -993,7 +993,7 @@ r_window_begin_frame(OS_Window window, R_Handle window_equip) } r_hook void -r_window_end_frame(OS_Window window, R_Handle window_equip) +r_window_end_frame(WM_Window window, R_Handle window_equip) { ProfBeginFunction(); MutexScopeW(r_d3d11_state->device_rw_mutex) @@ -1052,7 +1052,7 @@ r_window_end_frame(OS_Window window, R_Handle window_equip) { char buffer[256] = {0}; raddbg_snprintf(buffer, sizeof(buffer), "D3D11 present failure (%lx). The process is terminating.", error); - os_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer)); + wm_graphical_message(1, str8_lit("Fatal Error"), str8_cstring(buffer)); abort_self(1); } d_ctx->lpVtbl->ClearState(d_ctx); @@ -1063,7 +1063,7 @@ r_window_end_frame(OS_Window window, R_Handle window_equip) //- rjf: render pass submission r_hook void -r_window_submit(OS_Window window, R_Handle window_equip, R_PassList *passes) +r_window_submit(WM_Window window, R_Handle window_equip, R_PassList *passes) { ProfBeginFunction(); MutexScopeW(r_d3d11_state->device_rw_mutex) diff --git a/src/render/opengl/linux/egl/render_opengl_linux_egl.c b/src/render/opengl/linux/egl/render_opengl_linux_egl.c index 2df7024b..165ffc3e 100644 --- a/src/render/opengl/linux/egl/render_opengl_linux_egl.c +++ b/src/render/opengl/linux/egl/render_opengl_linux_egl.c @@ -23,7 +23,7 @@ r_ogl_os_init(CmdLine *cmdln) r_ogl_lnx_state->display = eglGetDisplay((EGLNativeDisplayType)os_lnx_gfx_state->display); if(r_ogl_lnx_state->display == EGL_NO_DISPLAY) { - os_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Failed to get EGL display.")); + wm_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Failed to get EGL display.")); abort_self(1); } } @@ -33,14 +33,14 @@ r_ogl_os_init(CmdLine *cmdln) EGLint egl_version_minor = 0; if(!eglInitialize(r_ogl_lnx_state->display, &egl_version_major, &egl_version_minor)) { - os_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't initialize EGL display.")); + wm_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't initialize EGL display.")); abort_self(1); } if(egl_version_major < 1 || (egl_version_major == 1 && egl_version_minor < 5)) { Temp scratch = scratch_begin(0, 0); String8 message = push_str8f(scratch.arena, "Unsupported EGL version (%i.%i, need at least 1.5)", egl_version_major, egl_version_minor); - os_graphical_message(1, str8_lit("Fatal Error"), message); + wm_graphical_message(1, str8_lit("Fatal Error"), message); abort_self(1); scratch_end(scratch); } @@ -48,7 +48,7 @@ r_ogl_os_init(CmdLine *cmdln) //- rjf: pick GL API if(!eglBindAPI(EGL_OPENGL_API)) { - os_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't initialize EGL API to OpenGL.")); + wm_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't initialize EGL API to OpenGL.")); abort_self(1); } @@ -69,7 +69,7 @@ r_ogl_os_init(CmdLine *cmdln) r_ogl_lnx_state->context = eglCreateContext(r_ogl_lnx_state->display, 0, EGL_NO_CONTEXT, options); if(r_ogl_lnx_state->context == EGL_NO_CONTEXT) { - os_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't create OpenGL context with EGL.")); + wm_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't create OpenGL context with EGL.")); abort_self(1); } } @@ -79,9 +79,9 @@ r_ogl_os_init(CmdLine *cmdln) } internal R_Handle -r_ogl_os_window_equip(OS_Window window) +r_ogl_os_window_equip(WM_Window window) { - OS_LNX_Window *window_os = (OS_LNX_Window *)window.u64[0]; + LNX_WM_Window *window_os = (LNX_WM_Window *)window.u64[0]; R_OGL_LNX_Window *w = r_ogl_lnx_state->free_window; if(w != 0) { @@ -120,7 +120,7 @@ r_ogl_os_window_equip(OS_Window window) }; if(!eglChooseConfig(r_ogl_lnx_state->display, options, configs, ArrayCount(configs), &configs_count) || configs_count == 0) { - os_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't choose EGL configuration.")); + wm_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't choose EGL configuration.")); abort_self(1); } } @@ -143,7 +143,7 @@ r_ogl_os_window_equip(OS_Window window) } if(r_ogl_lnx_state->config == 0) { - os_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't find a suitable EGL configuration.")); + wm_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't find a suitable EGL configuration.")); abort_self(1); } } @@ -154,7 +154,7 @@ r_ogl_os_window_equip(OS_Window window) } if(w->surface == EGL_NO_SURFACE) { - os_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't create EGL surface.")); + wm_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Couldn't create EGL surface.")); abort_self(1); } } @@ -163,7 +163,7 @@ r_ogl_os_window_equip(OS_Window window) } internal void -r_ogl_os_window_unequip(OS_Window os, R_Handle r) +r_ogl_os_window_unequip(WM_Window os, R_Handle r) { R_OGL_LNX_Window *w = (R_OGL_LNX_Window *)r.u64[0]; { @@ -173,17 +173,17 @@ r_ogl_os_window_unequip(OS_Window os, R_Handle r) } internal void -r_ogl_os_select_window(OS_Window os, R_Handle r) +r_ogl_os_select_window(WM_Window os, R_Handle r) { - OS_LNX_Window *w = (OS_LNX_Window *)os.u64[0]; + LNX_WM_Window *w = (LNX_WM_Window *)os.u64[0]; R_OGL_LNX_Window *w_r = (R_OGL_LNX_Window *)r.u64[0]; eglMakeCurrent(r_ogl_lnx_state->display, w_r->surface, w_r->surface, r_ogl_lnx_state->context); } internal void -r_ogl_os_window_swap(OS_Window os, R_Handle r) +r_ogl_os_window_swap(WM_Window os, R_Handle r) { - OS_LNX_Window *w = (OS_LNX_Window *)os.u64[0]; + LNX_WM_Window *w = (LNX_WM_Window *)os.u64[0]; R_OGL_LNX_Window *w_r = (R_OGL_LNX_Window *)r.u64[0]; eglSwapBuffers(r_ogl_lnx_state->display, w_r->surface); } diff --git a/src/render/opengl/linux/glx/render_opengl_linux_glx.c b/src/render/opengl/linux/glx/render_opengl_linux_glx.c index 665403ea..8b0a34a7 100644 --- a/src/render/opengl/linux/glx/render_opengl_linux_glx.c +++ b/src/render/opengl/linux/glx/render_opengl_linux_glx.c @@ -20,7 +20,7 @@ r_ogl_os_init(CmdLine *cmdln) { Temp scratch = scratch_begin(0, 0); String8 message = push_str8f(scratch.arena, "Unsupported GLX version (%i.%i, need at least 1.3)", glx_version_major, glx_version_minor); - os_graphical_message(1, str8_lit("Fatal Error"), message); + wm_graphical_message(1, str8_lit("Fatal Error"), message); abort_self(1); scratch_end(scratch); } @@ -45,7 +45,7 @@ r_ogl_os_init(CmdLine *cmdln) GLXFBConfig *framebuffer_configs = glXChooseFBConfig(os_lnx_gfx_state->display, DefaultScreen(os_lnx_gfx_state->display), framebuffer_config_options, &framebuffer_configs_count); if(framebuffer_configs == 0) { - os_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Could not find a suitable framebuffer configuration.")); + wm_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Could not find a suitable framebuffer configuration.")); abort_self(1); } GLXFBConfig framebuffer_config = framebuffer_configs[0]; @@ -79,28 +79,28 @@ r_ogl_os_init(CmdLine *cmdln) } internal R_Handle -r_ogl_os_window_equip(OS_Window window) +r_ogl_os_window_equip(WM_Window window) { R_Handle result = {0}; return result; } internal void -r_ogl_os_window_unequip(OS_Window os, R_Handle r) +r_ogl_os_window_unequip(WM_Window os, R_Handle r) { } internal void -r_ogl_os_select_window(OS_Window os, R_Handle r) +r_ogl_os_select_window(WM_Window os, R_Handle r) { - OS_LNX_Window *w = (OS_LNX_Window *)os.u64[0]; + LNX_WM_Window *w = (LNX_WM_Window *)os.u64[0]; glXMakeCurrent(os_lnx_gfx_state->display, w->window, r_ogl_lnx_ctx); } internal void -r_ogl_os_window_swap(OS_Window os, R_Handle r) +r_ogl_os_window_swap(WM_Window os, R_Handle r) { - OS_LNX_Window *w = (OS_LNX_Window *)os.u64[0]; + LNX_WM_Window *w = (LNX_WM_Window *)os.u64[0]; glXSwapBuffers(os_lnx_gfx_state->display, w->window); } diff --git a/src/render/opengl/render_opengl.c b/src/render/opengl/render_opengl.c index f985ae0b..d3f413ff 100644 --- a/src/render/opengl/render_opengl.c +++ b/src/render/opengl/render_opengl.c @@ -201,14 +201,14 @@ r_init(CmdLine *cmdln) //- rjf: window setup/teardown r_hook R_Handle -r_window_equip(OS_Window window) +r_window_equip(WM_Window window) { R_Handle result = r_ogl_os_window_equip(window); return result; } r_hook void -r_window_unequip(OS_Window window, R_Handle window_equip) +r_window_unequip(WM_Window window, R_Handle window_equip) { r_ogl_os_window_unequip(window, window_equip); } @@ -341,12 +341,12 @@ r_end_frame(void) } r_hook void -r_window_begin_frame(OS_Window os, R_Handle r) +r_window_begin_frame(WM_Window os, R_Handle r) { r_ogl_os_select_window(os, r); //- rjf: unpack window viewport info - Rng2F32 client_rect = os_client_rect_from_window(os); + Rng2F32 client_rect = wm_client_rect_from_window(os); Vec2F32 client_rect_dim = dim_2f32(client_rect); //- rjf: clear and reset state @@ -358,7 +358,7 @@ r_window_begin_frame(OS_Window os, R_Handle r) } r_hook void -r_window_end_frame(OS_Window os, R_Handle r) +r_window_end_frame(WM_Window os, R_Handle r) { for(R_OGL_FlushBuffer *flush_buffer = r_ogl_state->first_buffer_to_flush; flush_buffer != 0; flush_buffer = flush_buffer->next) { @@ -372,9 +372,9 @@ r_window_end_frame(OS_Window os, R_Handle r) //- rjf: render pass submission r_hook void -r_window_submit(OS_Window window, R_Handle window_equip, R_PassList *passes) +r_window_submit(WM_Window window, R_Handle window_equip, R_PassList *passes) { - Rng2F32 viewport_rect = os_client_rect_from_window(window); + Rng2F32 viewport_rect = wm_client_rect_from_window(window); Vec2F32 viewport_dim = dim_2f32(viewport_rect); for(R_PassNode *pass_n = passes->first; pass_n != 0; pass_n = pass_n->next) { diff --git a/src/render/opengl/render_opengl.h b/src/render/opengl/render_opengl.h index cd7c3f2f..0414d724 100644 --- a/src/render/opengl/render_opengl.h +++ b/src/render/opengl/render_opengl.h @@ -224,9 +224,9 @@ internal void r_ogl_debug_message_callback(GLenum source, GLenum type, GLuint id internal VoidProc *r_ogl_os_load_procedure(char *name); internal void r_ogl_os_init(CmdLine *cmdln); -internal R_Handle r_ogl_os_window_equip(OS_Window window); -internal void r_ogl_os_window_unequip(OS_Window os, R_Handle r); -internal void r_ogl_os_select_window(OS_Window os, R_Handle r); -internal void r_ogl_os_window_swap(OS_Window os, R_Handle r); +internal R_Handle r_ogl_os_window_equip(WM_Window window); +internal void r_ogl_os_window_unequip(WM_Window os, R_Handle r); +internal void r_ogl_os_select_window(WM_Window os, R_Handle r); +internal void r_ogl_os_window_swap(WM_Window os, R_Handle r); #endif // RENDER_OPENGL_H diff --git a/src/render/opengl/win32/render_opengl_win32.c b/src/render/opengl/win32/render_opengl_win32.c index 53b4641b..aefb4ae0 100644 --- a/src/render/opengl/win32/render_opengl_win32.c +++ b/src/render/opengl/win32/render_opengl_win32.c @@ -101,10 +101,10 @@ r_ogl_os_init(CmdLine *cmdline) } internal R_Handle -r_ogl_os_window_equip(OS_Window window) +r_ogl_os_window_equip(WM_Window window) { //- rjf: unpack window - OS_W32_Window *w = os_w32_window_from_handle(window); + W32_WM_Window *w = w32_wm_window_from_handle(window); HWND hwnd = w->hwnd; HDC hdc = w->hdc; @@ -155,14 +155,14 @@ r_ogl_os_window_equip(OS_Window window) } internal void -r_ogl_os_window_unequip(OS_Window os, R_Handle r) +r_ogl_os_window_unequip(WM_Window os, R_Handle r) { } internal void -r_ogl_os_select_window(OS_Window os, R_Handle r) +r_ogl_os_select_window(WM_Window os, R_Handle r) { - OS_W32_Window *w = os_w32_window_from_handle(os); + W32_WM_Window *w = w32_wm_window_from_handle(os); if(w != 0) { HWND hwnd = w->hwnd; @@ -172,9 +172,9 @@ r_ogl_os_select_window(OS_Window os, R_Handle r) } internal void -r_ogl_os_window_swap(OS_Window os, R_Handle r) +r_ogl_os_window_swap(WM_Window os, R_Handle r) { - OS_W32_Window *w = os_w32_window_from_handle(os); + W32_WM_Window *w = w32_wm_window_from_handle(os); if(w != 0) { HDC dc = w->hdc; diff --git a/src/render/render_core.h b/src/render/render_core.h index 6aa8decb..26d2ac37 100644 --- a/src/render/render_core.h +++ b/src/render/render_core.h @@ -281,8 +281,8 @@ internal R_Pass *r_pass_from_kind(Arena *arena, R_PassList *list, R_PassKind kin r_hook void r_init(CmdLine *cmdln); //- rjf: window setup/teardown -r_hook R_Handle r_window_equip(OS_Window window); -r_hook void r_window_unequip(OS_Window window, R_Handle window_equip); +r_hook R_Handle r_window_equip(WM_Window window); +r_hook void r_window_unequip(WM_Window window, R_Handle window_equip); //- rjf: textures r_hook R_Handle r_tex2d_alloc(R_ResourceKind kind, Vec2S32 size, R_Tex2DFormat format, void *data); @@ -299,10 +299,10 @@ r_hook void r_buffer_release(R_Handle buffer); //- rjf: frame markers r_hook void r_begin_frame(void); r_hook void r_end_frame(void); -r_hook void r_window_begin_frame(OS_Window window, R_Handle window_equip); -r_hook void r_window_end_frame(OS_Window window, R_Handle window_equip); +r_hook void r_window_begin_frame(WM_Window window, R_Handle window_equip); +r_hook void r_window_end_frame(WM_Window window, R_Handle window_equip); //- rjf: render pass submission -r_hook void r_window_submit(OS_Window window, R_Handle window_equip, R_PassList *passes); +r_hook void r_window_submit(WM_Window window, R_Handle window_equip, R_PassList *passes); #endif // RENDER_CORE_H diff --git a/src/scratch/textperf.c b/src/scratch/textperf.c index 3821698a..3bac8971 100644 --- a/src/scratch/textperf.c +++ b/src/scratch/textperf.c @@ -39,10 +39,10 @@ frame(void) ProfBeginFunction(); B32 quit = 0; Temp scratch = scratch_begin(0, 0); - OS_EventList events = os_get_events(scratch.arena, 0); - for(OS_Event *evt = events.first; evt != 0; evt = evt->next) + WM_EventList events = wm_get_events(scratch.arena, 0); + for(WM_Event *evt = events.first; evt != 0; evt = evt->next) { - if(evt->kind == OS_EventKind_WindowClose) + if(evt->kind == WM_EventKind_WindowClose) { quit = 1; break; @@ -54,7 +54,7 @@ frame(void) DR_Bucket *bucket = dr_bucket_make(); DR_BucketScope(bucket) ProfScope("draw") { - Vec2F32 mouse = os_mouse_from_window(os_window); + Vec2F32 mouse = wm_mouse_from_window(os_window); FNT_Tag font = fnt_tag_from_path(str8_lit("C:/devel/raddebugger/data/Inconsolata-Regular.ttf")); for(F32 x = 0; x < 500; x += 5.f) { @@ -75,8 +75,8 @@ frame(void) internal void entry_point(CmdLine *cmdline) { - os_window = os_window_open(r2f32p(0, 0, 1600, 900), OS_WindowFlag_UseDefaultPosition, str8_lit("textperf")); + os_window = wm_window_open(r2f32p(0, 0, 1600, 900), WM_WindowFlag_UseDefaultPosition, str8_lit("textperf")); r_window = r_window_equip(os_window); - os_window_first_paint(os_window); + wm_window_first_paint(os_window); for(;!update();); } diff --git a/src/torture/torture_main.c b/src/torture/torture_main.c index 71f530d8..238ae6e7 100644 --- a/src/torture/torture_main.c +++ b/src/torture/torture_main.c @@ -10,7 +10,7 @@ #define OS_FEATURE_GRAPHICAL 1 #define DMN_INIT_MANUAL 1 #define D_INIT_MANUAL 1 -#define OS_GFX_INIT_MANUAL 1 +#define WM_INIT_MANUAL 1 #define FP_INIT_MANUAL 1 #define R_INIT_MANUAL 1 #define FNT_INIT_MANUAL 1 diff --git a/src/ui/generated/ui.meta.c b/src/ui/generated/ui.meta.c index 9bc7c017..96ea8755 100644 --- a/src/ui/generated/ui.meta.c +++ b/src/ui/generated/ui.meta.c @@ -62,7 +62,7 @@ internal Vec4F32 ui_top_background_color(void) { UI_StackTopImpl(ui_state, Backg internal Vec4F32 ui_top_text_color(void) { UI_StackTopImpl(ui_state, TextColor, text_color) } internal Vec4F32 ui_top_border_color(void) { UI_StackTopImpl(ui_state, BorderColor, border_color) } internal F32 ui_top_squish(void) { UI_StackTopImpl(ui_state, Squish, squish) } -internal OS_Cursor ui_top_hover_cursor(void) { UI_StackTopImpl(ui_state, HoverCursor, hover_cursor) } +internal WM_Cursor ui_top_hover_cursor(void) { UI_StackTopImpl(ui_state, HoverCursor, hover_cursor) } internal FNT_Tag ui_top_font(void) { UI_StackTopImpl(ui_state, Font, font) } internal F32 ui_top_font_size(void) { UI_StackTopImpl(ui_state, FontSize, font_size) } internal FNT_RasterFlags ui_top_text_raster_flags(void) { UI_StackTopImpl(ui_state, TextRasterFlags, text_raster_flags) } @@ -96,7 +96,7 @@ internal Vec4F32 ui_bottom_background_color(void) { UI_StackBottomImpl(ui_state, internal Vec4F32 ui_bottom_text_color(void) { UI_StackBottomImpl(ui_state, TextColor, text_color) } internal Vec4F32 ui_bottom_border_color(void) { UI_StackBottomImpl(ui_state, BorderColor, border_color) } internal F32 ui_bottom_squish(void) { UI_StackBottomImpl(ui_state, Squish, squish) } -internal OS_Cursor ui_bottom_hover_cursor(void) { UI_StackBottomImpl(ui_state, HoverCursor, hover_cursor) } +internal WM_Cursor ui_bottom_hover_cursor(void) { UI_StackBottomImpl(ui_state, HoverCursor, hover_cursor) } internal FNT_Tag ui_bottom_font(void) { UI_StackBottomImpl(ui_state, Font, font) } internal F32 ui_bottom_font_size(void) { UI_StackBottomImpl(ui_state, FontSize, font_size) } internal FNT_RasterFlags ui_bottom_text_raster_flags(void) { UI_StackBottomImpl(ui_state, TextRasterFlags, text_raster_flags) } @@ -130,7 +130,7 @@ internal Vec4F32 ui_push_background_color(Vec4F32 v) { UI_StackPushImpl(ui_state internal Vec4F32 ui_push_text_color(Vec4F32 v) { UI_StackPushImpl(ui_state, TextColor, text_color, Vec4F32, v) } internal Vec4F32 ui_push_border_color(Vec4F32 v) { UI_StackPushImpl(ui_state, BorderColor, border_color, Vec4F32, v) } internal F32 ui_push_squish(F32 v) { UI_StackPushImpl(ui_state, Squish, squish, F32, v) } -internal OS_Cursor ui_push_hover_cursor(OS_Cursor v) { UI_StackPushImpl(ui_state, HoverCursor, hover_cursor, OS_Cursor, v) } +internal WM_Cursor ui_push_hover_cursor(WM_Cursor v) { UI_StackPushImpl(ui_state, HoverCursor, hover_cursor, WM_Cursor, v) } internal FNT_Tag ui_push_font(FNT_Tag v) { UI_StackPushImpl(ui_state, Font, font, FNT_Tag, v) } internal F32 ui_push_font_size(F32 v) { UI_StackPushImpl(ui_state, FontSize, font_size, F32, v) } internal FNT_RasterFlags ui_push_text_raster_flags(FNT_RasterFlags v) { UI_StackPushImpl(ui_state, TextRasterFlags, text_raster_flags, FNT_RasterFlags, v) } @@ -164,7 +164,7 @@ internal Vec4F32 ui_pop_background_color(void) { UI_StackPopImpl(ui_state, Backg internal Vec4F32 ui_pop_text_color(void) { UI_StackPopImpl(ui_state, TextColor, text_color) } internal Vec4F32 ui_pop_border_color(void) { UI_StackPopImpl(ui_state, BorderColor, border_color) } internal F32 ui_pop_squish(void) { UI_StackPopImpl(ui_state, Squish, squish) } -internal OS_Cursor ui_pop_hover_cursor(void) { UI_StackPopImpl(ui_state, HoverCursor, hover_cursor) } +internal WM_Cursor ui_pop_hover_cursor(void) { UI_StackPopImpl(ui_state, HoverCursor, hover_cursor) } internal FNT_Tag ui_pop_font(void) { UI_StackPopImpl(ui_state, Font, font) } internal F32 ui_pop_font_size(void) { UI_StackPopImpl(ui_state, FontSize, font_size) } internal FNT_RasterFlags ui_pop_text_raster_flags(void) { UI_StackPopImpl(ui_state, TextRasterFlags, text_raster_flags) } @@ -198,7 +198,7 @@ internal Vec4F32 ui_set_next_background_color(Vec4F32 v) { UI_StackSetNextImpl(u internal Vec4F32 ui_set_next_text_color(Vec4F32 v) { UI_StackSetNextImpl(ui_state, TextColor, text_color, Vec4F32, v) } internal Vec4F32 ui_set_next_border_color(Vec4F32 v) { UI_StackSetNextImpl(ui_state, BorderColor, border_color, Vec4F32, v) } internal F32 ui_set_next_squish(F32 v) { UI_StackSetNextImpl(ui_state, Squish, squish, F32, v) } -internal OS_Cursor ui_set_next_hover_cursor(OS_Cursor v) { UI_StackSetNextImpl(ui_state, HoverCursor, hover_cursor, OS_Cursor, v) } +internal WM_Cursor ui_set_next_hover_cursor(WM_Cursor v) { UI_StackSetNextImpl(ui_state, HoverCursor, hover_cursor, WM_Cursor, v) } internal FNT_Tag ui_set_next_font(FNT_Tag v) { UI_StackSetNextImpl(ui_state, Font, font, FNT_Tag, v) } internal F32 ui_set_next_font_size(F32 v) { UI_StackSetNextImpl(ui_state, FontSize, font_size, F32, v) } internal FNT_RasterFlags ui_set_next_text_raster_flags(FNT_RasterFlags v) { UI_StackSetNextImpl(ui_state, TextRasterFlags, text_raster_flags, FNT_RasterFlags, v) } diff --git a/src/ui/generated/ui.meta.h b/src/ui/generated/ui.meta.h index a3a1648b..852fbe0c 100644 --- a/src/ui/generated/ui.meta.h +++ b/src/ui/generated/ui.meta.h @@ -29,7 +29,7 @@ typedef struct UI_BackgroundColorNode UI_BackgroundColorNode; struct UI_Backgrou typedef struct UI_TextColorNode UI_TextColorNode; struct UI_TextColorNode{UI_TextColorNode *next; Vec4F32 v;}; typedef struct UI_BorderColorNode UI_BorderColorNode; struct UI_BorderColorNode{UI_BorderColorNode *next; Vec4F32 v;}; typedef struct UI_SquishNode UI_SquishNode; struct UI_SquishNode{UI_SquishNode *next; F32 v;}; -typedef struct UI_HoverCursorNode UI_HoverCursorNode; struct UI_HoverCursorNode{UI_HoverCursorNode *next; OS_Cursor v;}; +typedef struct UI_HoverCursorNode UI_HoverCursorNode; struct UI_HoverCursorNode{UI_HoverCursorNode *next; WM_Cursor v;}; typedef struct UI_FontNode UI_FontNode; struct UI_FontNode{UI_FontNode *next; FNT_Tag v;}; typedef struct UI_FontSizeNode UI_FontSizeNode; struct UI_FontSizeNode{UI_FontSizeNode *next; F32 v;}; typedef struct UI_TextRasterFlagsNode UI_TextRasterFlagsNode; struct UI_TextRasterFlagsNode{UI_TextRasterFlagsNode *next; FNT_RasterFlags v;}; @@ -104,7 +104,7 @@ state->background_color_nil_stack_top.v = v4f32(0, 0, 0, 0);\ state->text_color_nil_stack_top.v = v4f32(0, 0, 0, 0);\ state->border_color_nil_stack_top.v = v4f32(0, 0, 0, 0);\ state->squish_nil_stack_top.v = 0;\ -state->hover_cursor_nil_stack_top.v = OS_Cursor_Pointer;\ +state->hover_cursor_nil_stack_top.v = WM_Cursor_Pointer;\ state->font_nil_stack_top.v = fnt_tag_zero();\ state->font_size_nil_stack_top.v = 24.f;\ state->text_raster_flags_nil_stack_top.v = FNT_RasterFlag_Hinted;\ @@ -143,7 +143,7 @@ struct { UI_BackgroundColorNode *top; Vec4F32 bottom_val; UI_BackgroundColorNode struct { UI_TextColorNode *top; Vec4F32 bottom_val; UI_TextColorNode *free; U64 gen; B32 auto_pop; } text_color_stack;\ struct { UI_BorderColorNode *top; Vec4F32 bottom_val; UI_BorderColorNode *free; U64 gen; B32 auto_pop; } border_color_stack;\ struct { UI_SquishNode *top; F32 bottom_val; UI_SquishNode *free; U64 gen; B32 auto_pop; } squish_stack;\ -struct { UI_HoverCursorNode *top; OS_Cursor bottom_val; UI_HoverCursorNode *free; U64 gen; B32 auto_pop; } hover_cursor_stack;\ +struct { UI_HoverCursorNode *top; WM_Cursor bottom_val; UI_HoverCursorNode *free; U64 gen; B32 auto_pop; } hover_cursor_stack;\ struct { UI_FontNode *top; FNT_Tag bottom_val; UI_FontNode *free; U64 gen; B32 auto_pop; } font_stack;\ struct { UI_FontSizeNode *top; F32 bottom_val; UI_FontSizeNode *free; U64 gen; B32 auto_pop; } font_size_stack;\ struct { UI_TextRasterFlagsNode *top; FNT_RasterFlags bottom_val; UI_TextRasterFlagsNode *free; U64 gen; B32 auto_pop; } text_raster_flags_stack;\ @@ -180,7 +180,7 @@ state->background_color_stack.top = &state->background_color_nil_stack_top; stat state->text_color_stack.top = &state->text_color_nil_stack_top; state->text_color_stack.bottom_val = v4f32(0, 0, 0, 0); state->text_color_stack.free = 0; state->text_color_stack.auto_pop = 0;\ state->border_color_stack.top = &state->border_color_nil_stack_top; state->border_color_stack.bottom_val = v4f32(0, 0, 0, 0); state->border_color_stack.free = 0; state->border_color_stack.auto_pop = 0;\ state->squish_stack.top = &state->squish_nil_stack_top; state->squish_stack.bottom_val = 0; state->squish_stack.free = 0; state->squish_stack.auto_pop = 0;\ -state->hover_cursor_stack.top = &state->hover_cursor_nil_stack_top; state->hover_cursor_stack.bottom_val = OS_Cursor_Pointer; state->hover_cursor_stack.free = 0; state->hover_cursor_stack.auto_pop = 0;\ +state->hover_cursor_stack.top = &state->hover_cursor_nil_stack_top; state->hover_cursor_stack.bottom_val = WM_Cursor_Pointer; state->hover_cursor_stack.free = 0; state->hover_cursor_stack.auto_pop = 0;\ state->font_stack.top = &state->font_nil_stack_top; state->font_stack.bottom_val = fnt_tag_zero(); state->font_stack.free = 0; state->font_stack.auto_pop = 0;\ state->font_size_stack.top = &state->font_size_nil_stack_top; state->font_size_stack.bottom_val = 24.f; state->font_size_stack.free = 0; state->font_size_stack.auto_pop = 0;\ state->text_raster_flags_stack.top = &state->text_raster_flags_nil_stack_top; state->text_raster_flags_stack.bottom_val = FNT_RasterFlag_Hinted; state->text_raster_flags_stack.free = 0; state->text_raster_flags_stack.auto_pop = 0;\ @@ -253,7 +253,7 @@ internal Vec4F32 ui_top_background_color(void); internal Vec4F32 ui_top_text_color(void); internal Vec4F32 ui_top_border_color(void); internal F32 ui_top_squish(void); -internal OS_Cursor ui_top_hover_cursor(void); +internal WM_Cursor ui_top_hover_cursor(void); internal FNT_Tag ui_top_font(void); internal F32 ui_top_font_size(void); internal FNT_RasterFlags ui_top_text_raster_flags(void); @@ -288,7 +288,7 @@ internal Vec4F32 ui_bottom_background_color(void); internal Vec4F32 ui_bottom_text_color(void); internal Vec4F32 ui_bottom_border_color(void); internal F32 ui_bottom_squish(void); -internal OS_Cursor ui_bottom_hover_cursor(void); +internal WM_Cursor ui_bottom_hover_cursor(void); internal FNT_Tag ui_bottom_font(void); internal F32 ui_bottom_font_size(void); internal FNT_RasterFlags ui_bottom_text_raster_flags(void); @@ -323,7 +323,7 @@ internal Vec4F32 ui_push_background_color(Vec4F32 v); internal Vec4F32 ui_push_text_color(Vec4F32 v); internal Vec4F32 ui_push_border_color(Vec4F32 v); internal F32 ui_push_squish(F32 v); -internal OS_Cursor ui_push_hover_cursor(OS_Cursor v); +internal WM_Cursor ui_push_hover_cursor(WM_Cursor v); internal FNT_Tag ui_push_font(FNT_Tag v); internal F32 ui_push_font_size(F32 v); internal FNT_RasterFlags ui_push_text_raster_flags(FNT_RasterFlags v); @@ -358,7 +358,7 @@ internal Vec4F32 ui_pop_background_color(void); internal Vec4F32 ui_pop_text_color(void); internal Vec4F32 ui_pop_border_color(void); internal F32 ui_pop_squish(void); -internal OS_Cursor ui_pop_hover_cursor(void); +internal WM_Cursor ui_pop_hover_cursor(void); internal FNT_Tag ui_pop_font(void); internal F32 ui_pop_font_size(void); internal FNT_RasterFlags ui_pop_text_raster_flags(void); @@ -393,7 +393,7 @@ internal Vec4F32 ui_set_next_background_color(Vec4F32 v); internal Vec4F32 ui_set_next_text_color(Vec4F32 v); internal Vec4F32 ui_set_next_border_color(Vec4F32 v); internal F32 ui_set_next_squish(F32 v); -internal OS_Cursor ui_set_next_hover_cursor(OS_Cursor v); +internal WM_Cursor ui_set_next_hover_cursor(WM_Cursor v); internal FNT_Tag ui_set_next_font(FNT_Tag v); internal F32 ui_set_next_font_size(F32 v); internal FNT_RasterFlags ui_set_next_text_raster_flags(FNT_RasterFlags v); diff --git a/src/ui/ui.mdesk b/src/ui/ui.mdesk index 0617f18a..b8636dac 100644 --- a/src/ui/ui.mdesk +++ b/src/ui/ui.mdesk @@ -44,7 +44,7 @@ UI_StackTable: { Squish squish F32 0 } //- rjf: hover cursor - { HoverCursor hover_cursor OS_Cursor OS_Cursor_Pointer } + { HoverCursor hover_cursor WM_Cursor WM_Cursor_Pointer } //- rjf: font { Font font FNT_Tag `fnt_tag_zero()` } diff --git a/src/ui/ui_basic_widgets.c b/src/ui/ui_basic_widgets.c index 8723c6cd..eea5eae1 100644 --- a/src/ui/ui_basic_widgets.c +++ b/src/ui/ui_basic_widgets.c @@ -212,7 +212,7 @@ ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size, B32 is_focus_active_disabled = (!is_focus_active && ui_top_focus_active() == UI_FocusKind_On); //- rjf: build top-level box - ui_set_next_hover_cursor(is_focus_active ? OS_Cursor_IBar : OS_Cursor_Pointer); + ui_set_next_hover_cursor(is_focus_active ? WM_Cursor_IBar : WM_Cursor_Pointer); UI_Box *box = ui_build_box_from_key(UI_BoxFlag_DrawBackground| UI_BoxFlag_DrawBorder| UI_BoxFlag_MouseClickable| @@ -252,7 +252,7 @@ ui_line_edit(TxtPt *cursor, TxtPt *mark, U8 *edit_buffer, U64 edit_buffer_size, // rjf: perform copy if(op.flags & UI_TxtOpFlag_Copy) { - os_set_clipboard_text(op.copy); + wm_set_clipboard_text(op.copy); } // rjf: commit op's changed cursor & mark to caller-provided state @@ -436,7 +436,7 @@ ui_imagef(R_Handle texture, R_Tex2DSampleKind sample_kind, Rng2F32 region, Vec4F internal UI_Signal ui_expander(B32 is_expanded, String8 string) { - ui_set_next_hover_cursor(OS_Cursor_HandPoint); + ui_set_next_hover_cursor(WM_Cursor_HandPoint); ui_set_next_text_alignment(UI_TextAlign_Center); ui_set_next_font(ui_icon_font()); UI_Box *box = ui_build_box_from_string(UI_BoxFlag_Clickable|UI_BoxFlag_DrawText, string); @@ -462,7 +462,7 @@ internal UI_Signal ui_sort_header(B32 sorting, B32 ascending, String8 string) { ui_set_next_child_layout_axis(Axis2_X); - ui_set_next_hover_cursor(OS_Cursor_HandPoint); + ui_set_next_hover_cursor(WM_Cursor_HandPoint); UI_Box *box = ui_build_box_from_string(UI_BoxFlag_Clickable|UI_BoxFlag_DrawBackground|UI_BoxFlag_DrawActiveEffects, string); ui_push_parent(box); @@ -649,7 +649,7 @@ internal UI_Signal ui_sat_val_picker(F32 hue, F32 *out_sat, F32 *out_val, String8 string) { // rjf: build & interact - ui_set_next_hover_cursor(OS_Cursor_HandPoint); + ui_set_next_hover_cursor(WM_Cursor_HandPoint); UI_Box *box = ui_build_box_from_string(UI_BoxFlag_Clickable, string); UI_SatValDrawData *user = push_array(ui_build_arena(), UI_SatValDrawData, 1); ui_box_equip_custom_draw(box, ui_sat_val_picker_draw, user); @@ -758,7 +758,7 @@ internal UI_Signal ui_hue_picker(F32 *out_hue, F32 sat, F32 val, String8 string) { // rjf: build & interact - ui_set_next_hover_cursor(OS_Cursor_HandPoint); + ui_set_next_hover_cursor(WM_Cursor_HandPoint); UI_Box *box = ui_build_box_from_string(UI_BoxFlag_Clickable, string); UI_HueDrawData *user = push_array(ui_build_arena(), UI_HueDrawData, 1); ui_box_equip_custom_draw(box, ui_hue_picker_draw, user); @@ -845,7 +845,7 @@ internal UI_Signal ui_alpha_picker(F32 *out_alpha, String8 string) { // rjf: build & interact - ui_set_next_hover_cursor(OS_Cursor_HandPoint); + ui_set_next_hover_cursor(WM_Cursor_HandPoint); UI_Box *box = ui_build_box_from_string(UI_BoxFlag_Clickable, string); UI_AlphaDrawData *user = push_array(ui_build_arena(), UI_AlphaDrawData, 1); ui_box_equip_custom_draw(box, ui_alpha_picker_draw, user); @@ -1006,7 +1006,7 @@ ui_table_begin(U64 column_pct_count, F32 **column_pcts, String8 string) // rjf: make column boundary widget UI_Rect(rect) { - ui_set_next_hover_cursor(OS_Cursor_LeftRight); + ui_set_next_hover_cursor(WM_Cursor_LeftRight); UI_Box *box = ui_build_box_from_stringf(UI_BoxFlag_Clickable, "###%S_boundary_%I64u", table->string, column_idx); F32 *left_pct_ptr = column_idx < ui_ts_col_pct_count ? column_pcts[column_idx-1] : 0; diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index b181f976..0504e490 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -233,7 +233,7 @@ ui_single_line_txt_op_from_event(Arena *arena, UI_Event *event, String8 string, if(event->flags & UI_EventFlag_Paste) { range = txt_rng(cursor, mark); - replace = os_get_clipboard_text(arena); + replace = wm_get_clipboard_text(arena); next_cursor = next_mark = txt_pt(cursor.line, cursor.column+replace.size); } @@ -471,7 +471,7 @@ ui_build_arena(void) return result; } -internal OS_Window +internal WM_Window ui_window(void) { return ui_state->window; @@ -523,25 +523,25 @@ ui_next_event(UI_Event **ev) if(!(perms & UI_PermissionFlag_ClicksLeft) && (n->v.kind == UI_EventKind_Press || n->v.kind == UI_EventKind_Release) && - (n->v.key == OS_Key_LeftMouseButton)) + (n->v.key == WM_Key_LeftMouseButton)) { good = 0; } if(!(perms & UI_PermissionFlag_ClicksMiddle) && (n->v.kind == UI_EventKind_Press || n->v.kind == UI_EventKind_Release) && - (n->v.key == OS_Key_MiddleMouseButton)) + (n->v.key == WM_Key_MiddleMouseButton)) { good = 0; } if(!(perms & UI_PermissionFlag_ClicksRight) && (n->v.kind == UI_EventKind_Press || n->v.kind == UI_EventKind_Release) && - (n->v.key == OS_Key_RightMouseButton)) + (n->v.key == WM_Key_RightMouseButton)) { good = 0; } - if(!(perms & UI_PermissionFlag_ScrollX) && (n->v.kind == UI_EventKind_Scroll) && (n->v.delta_2f32.x != 0 || n->v.modifiers == OS_Modifier_Shift)) + if(!(perms & UI_PermissionFlag_ScrollX) && (n->v.kind == UI_EventKind_Scroll) && (n->v.delta_2f32.x != 0 || n->v.modifiers == WM_Modifier_Shift)) { good = 0; } @@ -553,9 +553,9 @@ ui_next_event(UI_Event **ev) n->v.kind == UI_EventKind_Release || n->v.kind == UI_EventKind_Navigate || n->v.kind == UI_EventKind_Edit) && - (n->v.key != OS_Key_LeftMouseButton && - n->v.key != OS_Key_MiddleMouseButton && - n->v.key != OS_Key_RightMouseButton)) + (n->v.key != WM_Key_LeftMouseButton && + n->v.key != WM_Key_MiddleMouseButton && + n->v.key != WM_Key_RightMouseButton)) { if((perms & UI_PermissionFlag_Keyboard) == UI_PermissionFlag_KeyboardSecondary) { @@ -594,7 +594,7 @@ ui_eat_event(UI_Event *ev) //- rjf: event consumption helpers internal B32 -ui_key_press(OS_Modifiers mods, OS_Key key) +ui_key_press(WM_Modifiers mods, WM_Key key) { B32 result = 0; for(UI_Event *evt = 0; ui_next_event(&evt);) @@ -610,7 +610,7 @@ ui_key_press(OS_Modifiers mods, OS_Key key) } internal B32 -ui_key_release(OS_Modifiers mods, OS_Key key) +ui_key_release(WM_Modifiers mods, WM_Key key) { B32 result = 0; for(UI_Event *evt = 0; ui_next_event(&evt);) @@ -796,7 +796,7 @@ ui_box_from_key(UI_Key key) //~ rjf: Top-Level Building API internal void -ui_begin_build(OS_Window window, UI_EventList *events, UI_IconInfo *icon_info, UI_Theme *theme, UI_AnimationInfo *animation_info, F32 real_dt, F32 animation_dt) +ui_begin_build(WM_Window window, UI_EventList *events, UI_IconInfo *icon_info, UI_Theme *theme, UI_AnimationInfo *animation_info, F32 real_dt, F32 animation_dt) { //- rjf: reset per-build ui state { @@ -872,11 +872,11 @@ ui_begin_build(OS_Window window, UI_EventList *events, UI_IconInfo *icon_info, U //- rjf: detect external press & holds for EachEnumVal(UI_MouseButtonKind, k) { - if(ui_key_match(ui_state->active_box_key[k], ui_key_zero()) && os_key_is_down(OS_Key_LeftMouseButton+k)) + if(ui_key_match(ui_state->active_box_key[k], ui_key_zero()) && wm_key_is_down(WM_Key_LeftMouseButton+k)) { ui_state->active_box_key[k] = ui_state->external_key; } - else if(ui_key_match(ui_state->active_box_key[k], ui_state->external_key) && !os_key_is_down(OS_Key_LeftMouseButton+k)) + else if(ui_key_match(ui_state->active_box_key[k], ui_state->external_key) && !wm_key_is_down(WM_Key_LeftMouseButton+k)) { ui_state->active_box_key[k] = ui_key_zero(); } @@ -887,7 +887,7 @@ ui_begin_build(OS_Window window, UI_EventList *events, UI_IconInfo *icon_info, U ui_state->theme = theme; ui_state->events = events; ui_state->window = window; - ui_state->mouse = (os_window_is_focused(window) || ui_state->last_time_mousemoved_us+500000 >= now_time_us()) ? os_mouse_from_window(window) : v2f32(-100, -100); + ui_state->mouse = (wm_window_is_focused(window) || ui_state->last_time_mousemoved_us+500000 >= now_time_us()) ? wm_mouse_from_window(window) : v2f32(-100, -100); ui_state->animation_dt = animation_dt; MemoryZeroStruct(&ui_state->icon_info); ui_state->icon_info.icon_font = icon_info->icon_font; @@ -921,11 +921,11 @@ ui_begin_build(OS_Window window, UI_EventList *events, UI_IconInfo *icon_info, U B32 nav_next = 0; B32 nav_prev = 0; Axis2 axis_lock = Axis2_Invalid; - if(ui_key_press(0, OS_Key_Tab)) + if(ui_key_press(0, WM_Key_Tab)) { nav_next = 1; } - if(ui_key_press(OS_Modifier_Shift, OS_Key_Tab)) + if(ui_key_press(WM_Modifier_Shift, WM_Key_Tab)) { nav_prev = 1; } @@ -1123,7 +1123,7 @@ ui_begin_build(OS_Window window, UI_EventList *events, UI_IconInfo *icon_info, U //- rjf: build top-level root { - Rng2F32 window_rect = os_client_rect_from_window(window); + Rng2F32 window_rect = wm_client_rect_from_window(window); Vec2F32 window_rect_size = dim_2f32(window_rect); ui_set_next_fixed_width(window_rect_size.x); ui_set_next_fixed_height(window_rect_size.y); @@ -1306,7 +1306,7 @@ ui_end_build(void) UI_Box *root = floating_roots[idx]; if(!ui_box_is_nil(root)) { - Rng2F32 window_rect = os_client_rect_from_window(ui_window()); + Rng2F32 window_rect = wm_client_rect_from_window(ui_window()); Vec2F32 window_dim = dim_2f32(window_rect); Rng2F32 root_rect = root->rect; Vec2F32 shift_down = @@ -1538,7 +1538,7 @@ ui_end_build(void) for(UI_Event *evt = 0; ui_next_event(&evt);) { if(evt->kind == UI_EventKind_Press && - (evt->key == OS_Key_LeftMouseButton || evt->key == OS_Key_RightMouseButton)) + (evt->key == WM_Key_LeftMouseButton || evt->key == WM_Key_RightMouseButton)) { ui_ctx_menu_close(); } @@ -1551,14 +1551,14 @@ ui_end_build(void) UI_Box *hot = ui_box_from_key(ui_state->hot_box_key); UI_Box *active = ui_box_from_key(ui_state->active_box_key[UI_MouseButtonKind_Left]); UI_Box *box = ui_box_is_nil(active) ? hot : active; - OS_Cursor cursor = box->hover_cursor; + WM_Cursor cursor = box->hover_cursor; if(box->flags & UI_BoxFlag_Disabled && box->flags & UI_BoxFlag_Clickable) { - cursor = OS_Cursor_Disabled; + cursor = WM_Cursor_Disabled; } - if(os_window_is_focused(ui_state->window) || !ui_box_is_nil(active)) + if(wm_window_is_focused(ui_state->window) || !ui_box_is_nil(active)) { - os_set_cursor(cursor); + wm_set_cursor(cursor); } } @@ -1583,7 +1583,7 @@ ui_end_build(void) StringJoin join = {0}; join.sep = str8_lit(" "); String8 string = str8_list_join(scratch.arena, &strs, &join); - os_set_clipboard_text(string); + wm_set_clipboard_text(string); } scratch_end(scratch); } @@ -2451,7 +2451,7 @@ ui_build_box_from_key(UI_BoxFlags flags, UI_Key key) box->first = box->last = box->next = box->prev = box->parent = &ui_nil_box; box->child_count = 0; box->flags = 0; - box->hover_cursor = OS_Cursor_Pointer; + box->hover_cursor = WM_Cursor_Pointer; MemoryZeroArray(box->pref_size); MemoryZeroStruct(&box->draw_bucket); } @@ -2809,7 +2809,7 @@ ui_signal_from_box(UI_Box *box) { B32 is_focus_hot = box->flags & UI_BoxFlag_FocusHot && !(box->flags & UI_BoxFlag_FocusHotDisabled); UI_Signal sig = {box}; - sig.event_flags |= os_get_modifiers(); + sig.event_flags |= wm_get_modifiers(); ////////////////////////////// //- rjf: calculate possibly-clipped box rectangle @@ -2858,13 +2858,13 @@ ui_signal_from_box(UI_Box *box) //- rjf: unpack event Vec2F32 evt_mouse = evt->pos; B32 evt_mouse_in_bounds = !contains_2f32(blacklist_rect, evt_mouse) && contains_2f32(rect, evt_mouse); - UI_MouseButtonKind evt_mouse_button_kind = (evt->key == OS_Key_LeftMouseButton ? UI_MouseButtonKind_Left : - evt->key == OS_Key_MiddleMouseButton ? UI_MouseButtonKind_Middle : - evt->key == OS_Key_RightMouseButton ? UI_MouseButtonKind_Right : + UI_MouseButtonKind evt_mouse_button_kind = (evt->key == WM_Key_LeftMouseButton ? UI_MouseButtonKind_Left : + evt->key == WM_Key_MiddleMouseButton ? UI_MouseButtonKind_Middle : + evt->key == WM_Key_RightMouseButton ? UI_MouseButtonKind_Right : UI_MouseButtonKind_Left); - B32 evt_key_is_mouse = (evt->key == OS_Key_LeftMouseButton || - evt->key == OS_Key_MiddleMouseButton || - evt->key == OS_Key_RightMouseButton); + B32 evt_key_is_mouse = (evt->key == WM_Key_LeftMouseButton || + evt->key == WM_Key_MiddleMouseButton || + evt->key == WM_Key_RightMouseButton); sig.event_flags |= evt->modifiers; //- rjf: mouse presses in box -> set hot/active; mark signal accordingly @@ -2878,14 +2878,14 @@ ui_signal_from_box(UI_Box *box) sig.f |= (UI_SignalFlag_LeftPressed<drag_start_mouse = evt->pos; if(ui_key_match(box->key, ui_state->press_key_history[evt_mouse_button_kind][0]) && - evt->timestamp_us-ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] <= 1000000*os_get_gfx_info()->double_click_time) + evt->timestamp_us-ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] <= 1000000*wm_get_system_info()->double_click_time) { sig.f |= (UI_SignalFlag_LeftDoubleClicked<key, ui_state->press_key_history[evt_mouse_button_kind][0]) && ui_key_match(box->key, ui_state->press_key_history[evt_mouse_button_kind][1]) && - evt->timestamp_us-ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] <= 1000000*os_get_gfx_info()->double_click_time && - ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] - ui_state->press_timestamp_history_us[evt_mouse_button_kind][1] <= 1000000*os_get_gfx_info()->double_click_time) + evt->timestamp_us-ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] <= 1000000*wm_get_system_info()->double_click_time && + ui_state->press_timestamp_history_us[evt_mouse_button_kind][0] - ui_state->press_timestamp_history_us[evt_mouse_button_kind][1] <= 1000000*wm_get_system_info()->double_click_time) { sig.f |= (UI_SignalFlag_LeftTripleClicked<flags & UI_BoxFlag_Scroll && evt->kind == UI_EventKind_Scroll && - (evt->modifiers == 0 || evt->modifiers == OS_Modifier_Shift) && + (evt->modifiers == 0 || evt->modifiers == WM_Modifier_Shift) && evt_mouse_in_bounds) { Vec2F32 delta = evt->delta_2f32; - if(evt->modifiers & OS_Modifier_Shift) + if(evt->modifiers & WM_Modifier_Shift) { Swap(F32, delta.x, delta.y); } @@ -3001,11 +3001,11 @@ ui_signal_from_box(UI_Box *box) //- rjf: view scrolling if(box->flags & UI_BoxFlag_ViewScroll && box->first_touched_build_index != box->last_touched_build_index && evt->kind == UI_EventKind_Scroll && - (evt->modifiers == 0 || evt->modifiers == OS_Modifier_Shift) && + (evt->modifiers == 0 || evt->modifiers == WM_Modifier_Shift) && evt_mouse_in_bounds) { Vec2F32 delta = evt->delta_2f32; - if(evt->modifiers & OS_Modifier_Shift) + if(evt->modifiers & WM_Modifier_Shift) { Swap(F32, delta.x, delta.y); } @@ -3077,7 +3077,7 @@ ui_signal_from_box(UI_Box *box) if(sig.f & (UI_SignalFlag_LeftDragging<press_key_history[k][0], box->key) && ui_key_match(ui_state->press_key_history[k][1], box->key) && - ui_state->press_timestamp_history_us[k][0] - ui_state->press_timestamp_history_us[k][1] <= 1000000*os_get_gfx_info()->double_click_time && + ui_state->press_timestamp_history_us[k][0] - ui_state->press_timestamp_history_us[k][1] <= 1000000*wm_get_system_info()->double_click_time && length_2f32(sub_2f32(ui_state->press_pos_history[k][0], ui_state->press_pos_history[k][1])) < 10.f) { sig.f |= (UI_SignalFlag_LeftDoubleDragging<press_key_history[k][0], box->key) && ui_key_match(ui_state->press_key_history[k][1], box->key) && ui_key_match(ui_state->press_key_history[k][2], box->key) && - ui_state->press_timestamp_history_us[k][0] - ui_state->press_timestamp_history_us[k][1] <= 1000000*os_get_gfx_info()->double_click_time && - ui_state->press_timestamp_history_us[k][1] - ui_state->press_timestamp_history_us[k][2] <= 1000000*os_get_gfx_info()->double_click_time && + ui_state->press_timestamp_history_us[k][0] - ui_state->press_timestamp_history_us[k][1] <= 1000000*wm_get_system_info()->double_click_time && + ui_state->press_timestamp_history_us[k][1] - ui_state->press_timestamp_history_us[k][2] <= 1000000*wm_get_system_info()->double_click_time && length_2f32(sub_2f32(ui_state->press_pos_history[k][0], ui_state->press_pos_history[k][1])) < 10.f && length_2f32(sub_2f32(ui_state->press_pos_history[k][1], ui_state->press_pos_history[k][2])) < 10.f) { diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 85fdbe53..5bd3e875 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -142,8 +142,8 @@ struct UI_Event UI_EventActionSlot slot; UI_EventFlags flags; UI_EventDeltaUnit delta_unit; - OS_Key key; - OS_Modifiers modifiers; + WM_Key key; + WM_Modifiers modifiers; String8 string; String8List paths; Vec2F32 pos; @@ -389,7 +389,7 @@ struct UI_Box Vec2F32 min_size; UI_Size pref_size[Axis2_COUNT]; Axis2 child_layout_axis; - OS_Cursor hover_cursor; + WM_Cursor hover_cursor; U32 fastpath_codepoint; UI_Key group_key; DR_Bucket *draw_bucket; @@ -524,7 +524,7 @@ typedef struct UI_Signal UI_Signal; struct UI_Signal { UI_Box *box; - OS_Modifiers event_flags; + WM_Modifiers event_flags; Vec2S16 scroll; UI_SignalFlags f; }; @@ -705,7 +705,7 @@ struct UI_State UI_IconInfo icon_info; UI_Theme *theme; UI_AnimationInfo animation_info; - OS_Window window; + WM_Window window; UI_EventList *events; Vec2F32 mouse; F32 animation_dt; @@ -826,7 +826,7 @@ internal UI_State *ui_get_selected_state(void); //- rjf: per-frame info internal Arena * ui_build_arena(void); -internal OS_Window ui_window(void); +internal WM_Window ui_window(void); internal Vec2F32 ui_mouse(void); internal FNT_Tag ui_icon_font(void); internal String8 ui_icon_string_from_kind(UI_IconKind icon_kind); @@ -837,8 +837,8 @@ internal B32 ui_next_event(UI_Event **ev); internal void ui_eat_event(UI_Event *ev); //- rjf: event consumption helpers -internal B32 ui_key_press(OS_Modifiers mods, OS_Key key); -internal B32 ui_key_release(OS_Modifiers mods, OS_Key key); +internal B32 ui_key_press(WM_Modifiers mods, WM_Key key); +internal B32 ui_key_release(WM_Modifiers mods, WM_Key key); internal B32 ui_text(U32 character); internal B32 ui_slot_press(UI_EventActionSlot slot); @@ -873,7 +873,7 @@ internal UI_Box * ui_box_from_key(UI_Key key); //////////////////////////////// //~ rjf: Top-Level Building API -internal void ui_begin_build(OS_Window window, UI_EventList *events, UI_IconInfo *icon_info, UI_Theme *theme, UI_AnimationInfo *animation_info, F32 real_dt, F32 animation_dt); +internal void ui_begin_build(WM_Window window, UI_EventList *events, UI_IconInfo *icon_info, UI_Theme *theme, UI_AnimationInfo *animation_info, F32 real_dt, F32 animation_dt); internal void ui_end_build(void); internal void ui_calc_sizes_standalone__in_place(UI_Box *root, Axis2 axis); internal void ui_calc_sizes_upwards_dependent__in_place(UI_Box *root, Axis2 axis); @@ -985,7 +985,7 @@ internal Vec4F32 ui_top_background_color(void); internal Vec4F32 ui_top_text_color(void); internal Vec4F32 ui_top_border_color(void); internal F32 ui_top_squish(void); -internal OS_Cursor ui_top_hover_cursor(void); +internal WM_Cursor ui_top_hover_cursor(void); internal FNT_Tag ui_top_font(void); internal F32 ui_top_font_size(void); internal FNT_RasterFlags ui_top_text_raster_flags(void); @@ -1020,7 +1020,7 @@ internal Vec4F32 ui_bottom_background_color(void); internal Vec4F32 ui_bottom_text_color(void); internal Vec4F32 ui_bottom_border_color(void); internal F32 ui_bottom_squish(void); -internal OS_Cursor ui_bottom_hover_cursor(void); +internal WM_Cursor ui_bottom_hover_cursor(void); internal FNT_Tag ui_bottom_font(void); internal F32 ui_bottom_font_size(void); internal FNT_RasterFlags ui_bottom_text_raster_flags(void); @@ -1055,7 +1055,7 @@ internal Vec4F32 ui_push_background_color(Vec4F32 v); internal Vec4F32 ui_push_text_color(Vec4F32 v); internal Vec4F32 ui_push_border_color(Vec4F32 v); internal F32 ui_push_squish(F32 v); -internal OS_Cursor ui_push_hover_cursor(OS_Cursor v); +internal WM_Cursor ui_push_hover_cursor(WM_Cursor v); internal FNT_Tag ui_push_font(FNT_Tag v); internal F32 ui_push_font_size(F32 v); internal FNT_RasterFlags ui_push_text_raster_flags(FNT_RasterFlags v); @@ -1090,7 +1090,7 @@ internal Vec4F32 ui_pop_background_color(void); internal Vec4F32 ui_pop_text_color(void); internal Vec4F32 ui_pop_border_color(void); internal F32 ui_pop_squish(void); -internal OS_Cursor ui_pop_hover_cursor(void); +internal WM_Cursor ui_pop_hover_cursor(void); internal FNT_Tag ui_pop_font(void); internal F32 ui_pop_font_size(void); internal FNT_RasterFlags ui_pop_text_raster_flags(void); @@ -1125,7 +1125,7 @@ internal Vec4F32 ui_set_next_background_color(Vec4F32 v); internal Vec4F32 ui_set_next_text_color(Vec4F32 v); internal Vec4F32 ui_set_next_border_color(Vec4F32 v); internal F32 ui_set_next_squish(F32 v); -internal OS_Cursor ui_set_next_hover_cursor(OS_Cursor v); +internal WM_Cursor ui_set_next_hover_cursor(WM_Cursor v); internal FNT_Tag ui_set_next_font(FNT_Tag v); internal F32 ui_set_next_font_size(F32 v); internal FNT_RasterFlags ui_set_next_text_raster_flags(FNT_RasterFlags v); diff --git a/src/win32/base/win32_base.c b/src/win32/base/win32_base.c index 9e98025f..e55504ad 100644 --- a/src/win32/base/win32_base.c +++ b/src/win32/base/win32_base.c @@ -14,7 +14,7 @@ global RIO_EXTENSION_FUNCTION_TABLE w32_rio_functions = {0}; //~ rjf: File Info Conversion Helpers internal FilePropertyFlags -os_w32_file_property_flags_from_dwFileAttributes(DWORD dwFileAttributes) +w32_file_property_flags_from_dwFileAttributes(DWORD dwFileAttributes) { FilePropertyFlags flags = 0; if(dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) @@ -25,19 +25,19 @@ os_w32_file_property_flags_from_dwFileAttributes(DWORD dwFileAttributes) } internal void -os_w32_file_properties_from_attribute_data(FileProperties *properties, WIN32_FILE_ATTRIBUTE_DATA *attributes) +w32_file_properties_from_attribute_data(FileProperties *properties, WIN32_FILE_ATTRIBUTE_DATA *attributes) { properties->size = Compose64Bit(attributes->nFileSizeHigh, attributes->nFileSizeLow); - os_w32_dense_time_from_file_time(&properties->created, &attributes->ftCreationTime); - os_w32_dense_time_from_file_time(&properties->modified, &attributes->ftLastWriteTime); - properties->flags = os_w32_file_property_flags_from_dwFileAttributes(attributes->dwFileAttributes); + w32_dense_time_from_file_time(&properties->created, &attributes->ftCreationTime); + w32_dense_time_from_file_time(&properties->modified, &attributes->ftLastWriteTime); + properties->flags = w32_file_property_flags_from_dwFileAttributes(attributes->dwFileAttributes); } //////////////////////////////// //~ rjf: Time Conversion Helpers internal void -os_w32_date_time_from_system_time(DateTime *out, SYSTEMTIME *in) +w32_date_time_from_system_time(DateTime *out, SYSTEMTIME *in) { out->year = in->wYear; out->mon = in->wMonth - 1; @@ -50,7 +50,7 @@ os_w32_date_time_from_system_time(DateTime *out, SYSTEMTIME *in) } internal void -os_w32_system_time_from_date_time(SYSTEMTIME *out, DateTime *in) +w32_system_time_from_date_time(SYSTEMTIME *out, DateTime *in) { out->wYear = (WORD)(in->year); out->wMonth = in->mon + 1; @@ -62,17 +62,17 @@ os_w32_system_time_from_date_time(SYSTEMTIME *out, DateTime *in) } internal void -os_w32_dense_time_from_file_time(DenseTime *out, FILETIME *in) +w32_dense_time_from_file_time(DenseTime *out, FILETIME *in) { SYSTEMTIME systime = {0}; FileTimeToSystemTime(in, &systime); DateTime date_time = {0}; - os_w32_date_time_from_system_time(&date_time, &systime); + w32_date_time_from_system_time(&date_time, &systime); *out = dense_time_from_date_time(date_time); } internal U32 -os_w32_sleep_ms_from_endt_us(U64 endt_us) +w32_sleep_ms_from_endt_us(U64 endt_us) { U32 sleep_ms = 0; if(endt_us == max_U64) @@ -92,7 +92,7 @@ os_w32_sleep_ms_from_endt_us(U64 endt_us) } internal U32 -os_w32_unix_time_from_file_time(FILETIME file_time) +w32_unix_time_from_file_time(FILETIME file_time) { U64 win32_time = ((U64)file_time.dwHighDateTime << 32) | file_time.dwLowDateTime; U64 unix_time64 = ((win32_time - 0x19DB1DED53E8000ULL) / 10000000); @@ -106,44 +106,44 @@ os_w32_unix_time_from_file_time(FILETIME file_time) //////////////////////////////// //~ rjf: Entity Functions -internal OS_W32_Entity * -os_w32_entity_alloc(OS_W32_EntityKind kind) +internal W32_Entity * +w32_entity_alloc(W32_EntityKind kind) { - OS_W32_Entity *result = 0; - EnterCriticalSection(&os_w32_state.entity_mutex); + W32_Entity *result = 0; + EnterCriticalSection(&w32_state.entity_mutex); { - result = os_w32_state.entity_free; + result = w32_state.entity_free; if(result) { - SLLStackPop(os_w32_state.entity_free); + SLLStackPop(w32_state.entity_free); } else { - result = push_array_no_zero(os_w32_state.entity_arena, OS_W32_Entity, 1); + result = push_array_no_zero(w32_state.entity_arena, W32_Entity, 1); } MemoryZeroStruct(result); } - LeaveCriticalSection(&os_w32_state.entity_mutex); + LeaveCriticalSection(&w32_state.entity_mutex); result->kind = kind; return result; } internal void -os_w32_entity_release(OS_W32_Entity *entity) +w32_entity_release(W32_Entity *entity) { - entity->kind = OS_W32_EntityKind_Null; - EnterCriticalSection(&os_w32_state.entity_mutex); - SLLStackPush(os_w32_state.entity_free, entity); - LeaveCriticalSection(&os_w32_state.entity_mutex); + entity->kind = W32_EntityKind_Null; + EnterCriticalSection(&w32_state.entity_mutex); + SLLStackPush(w32_state.entity_free, entity); + LeaveCriticalSection(&w32_state.entity_mutex); } //////////////////////////////// //~ rjf: Thread Entry Point internal DWORD -os_w32_thread_entry_point(void *ptr) +w32_thread_entry_point(void *ptr) { - OS_W32_Entity *entity = (OS_W32_Entity *)ptr; + W32_Entity *entity = (W32_Entity *)ptr; ThreadEntryPointFunctionType *func = entity->thread.func; void *thread_ptr = entity->thread.ptr; supplement_thread_base_entry_point(func, thread_ptr); @@ -160,7 +160,7 @@ now_time_us(void) LARGE_INTEGER large_int_counter; if(QueryPerformanceCounter(&large_int_counter)) { - result = (large_int_counter.QuadPart*Million(1))/os_w32_state.microsecond_resolution; + result = (large_int_counter.QuadPart*Million(1))/w32_state.microsecond_resolution; } return result; } @@ -170,7 +170,7 @@ now_time_unix(void) { FILETIME file_time; GetSystemTimeAsFileTime(&file_time); - U32 unix_time = os_w32_unix_time_from_file_time(file_time); + U32 unix_time = w32_unix_time_from_file_time(file_time); return unix_time; } @@ -180,7 +180,7 @@ now_time_universal(void) SYSTEMTIME systime = {0}; GetSystemTime(&systime); DateTime result = {0}; - os_w32_date_time_from_system_time(&result, &systime); + w32_date_time_from_system_time(&result, &systime); return result; } @@ -188,14 +188,14 @@ internal DateTime universal_from_local_time(DateTime *date_time) { SYSTEMTIME systime = {0}; - os_w32_system_time_from_date_time(&systime, date_time); + w32_system_time_from_date_time(&systime, date_time); FILETIME ftime = {0}; SystemTimeToFileTime(&systime, &ftime); FILETIME ftime_local = {0}; LocalFileTimeToFileTime(&ftime, &ftime_local); FileTimeToSystemTime(&ftime_local, &systime); DateTime result = {0}; - os_w32_date_time_from_system_time(&result, &systime); + w32_date_time_from_system_time(&result, &systime); return result; } @@ -203,14 +203,14 @@ internal DateTime local_from_universal_time(DateTime *date_time) { SYSTEMTIME systime = {0}; - os_w32_system_time_from_date_time(&systime, date_time); + w32_system_time_from_date_time(&systime, date_time); FILETIME ftime = {0}; SystemTimeToFileTime(&systime, &ftime); FILETIME ftime_local = {0}; FileTimeToLocalFileTime(&ftime, &ftime_local); FileTimeToSystemTime(&ftime_local, &systime); DateTime result = {0}; - os_w32_date_time_from_system_time(&result, &systime); + w32_date_time_from_system_time(&result, &systime); return result; } @@ -361,7 +361,7 @@ shared_memory_view_close(SharedMemory handle, void *ptr, Rng1U64 range) internal SystemInfo * get_system_info(void) { - return &os_w32_state.system_info; + return &w32_state.system_info; } //////////////////////////////// @@ -425,10 +425,10 @@ set_platform_thread_name(String8 name) internal Thread thread_launch(ThreadEntryPointFunctionType *f, void *p) { - OS_W32_Entity *entity = os_w32_entity_alloc(OS_W32_EntityKind_Thread); + W32_Entity *entity = w32_entity_alloc(W32_EntityKind_Thread); entity->thread.func = f; entity->thread.ptr = p; - entity->thread.handle = CreateThread(0, 0, os_w32_thread_entry_point, entity, 0, &entity->thread.tid); + entity->thread.handle = CreateThread(0, 0, w32_thread_entry_point, entity, 0, &entity->thread.tid); Thread result = {IntFromPtr(entity)}; return result; } @@ -436,14 +436,14 @@ thread_launch(ThreadEntryPointFunctionType *f, void *p) internal B32 thread_join(Thread thread, U64 endt_us) { - DWORD sleep_ms = os_w32_sleep_ms_from_endt_us(endt_us); - OS_W32_Entity *entity = (OS_W32_Entity *)PtrFromInt(thread.u64[0]); + DWORD sleep_ms = w32_sleep_ms_from_endt_us(endt_us); + W32_Entity *entity = (W32_Entity *)PtrFromInt(thread.u64[0]); DWORD wait_result = WAIT_OBJECT_0; if(entity != 0) { wait_result = WaitForSingleObject(entity->thread.handle, sleep_ms); CloseHandle(entity->thread.handle); - os_w32_entity_release(entity); + w32_entity_release(entity); } return (wait_result == WAIT_OBJECT_0); } @@ -451,11 +451,11 @@ thread_join(Thread thread, U64 endt_us) internal void thread_detach(Thread thread) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(thread.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(thread.u64[0]); if(entity != 0) { CloseHandle(entity->thread.handle); - os_w32_entity_release(entity); + w32_entity_release(entity); } } @@ -486,7 +486,7 @@ safe_call(ThreadEntryPointFunctionType *func, ThreadEntryPointFunctionType *fail internal Mutex mutex_alloc(void) { - OS_W32_Entity *entity = os_w32_entity_alloc(OS_W32_EntityKind_Mutex); + W32_Entity *entity = w32_entity_alloc(W32_EntityKind_Mutex); InitializeCriticalSection(&entity->mutex); Mutex result = {IntFromPtr(entity)}; return result; @@ -495,22 +495,22 @@ mutex_alloc(void) internal void mutex_release(Mutex mutex) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(mutex.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(mutex.u64[0]); DeleteCriticalSection(&entity->mutex); - os_w32_entity_release(entity); + w32_entity_release(entity); } internal void mutex_take(Mutex mutex) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(mutex.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(mutex.u64[0]); EnterCriticalSection(&entity->mutex); } internal void mutex_drop(Mutex mutex) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(mutex.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(mutex.u64[0]); LeaveCriticalSection(&entity->mutex); } @@ -519,7 +519,7 @@ mutex_drop(Mutex mutex) internal RWMutex rw_mutex_alloc(void) { - OS_W32_Entity *entity = os_w32_entity_alloc(OS_W32_EntityKind_RWMutex); + W32_Entity *entity = w32_entity_alloc(W32_EntityKind_RWMutex); InitializeSRWLock(&entity->rw_mutex); RWMutex result = {IntFromPtr(entity)}; return result; @@ -528,14 +528,14 @@ rw_mutex_alloc(void) internal void rw_mutex_release(RWMutex rw_mutex) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(rw_mutex.u64[0]); - os_w32_entity_release(entity); + W32_Entity *entity = (W32_Entity*)PtrFromInt(rw_mutex.u64[0]); + w32_entity_release(entity); } internal void rw_mutex_take(RWMutex rw_mutex, B32 write_mode) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(rw_mutex.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(rw_mutex.u64[0]); if(write_mode) { AcquireSRWLockExclusive(&entity->rw_mutex); @@ -549,7 +549,7 @@ rw_mutex_take(RWMutex rw_mutex, B32 write_mode) internal void rw_mutex_drop(RWMutex rw_mutex, B32 write_mode) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(rw_mutex.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(rw_mutex.u64[0]); if(write_mode) { ReleaseSRWLockExclusive(&entity->rw_mutex); @@ -565,7 +565,7 @@ rw_mutex_drop(RWMutex rw_mutex, B32 write_mode) internal CondVar cond_var_alloc(void) { - OS_W32_Entity *entity = os_w32_entity_alloc(OS_W32_EntityKind_ConditionVariable); + W32_Entity *entity = w32_entity_alloc(W32_EntityKind_ConditionVariable); InitializeConditionVariable(&entity->cv); CondVar result = {IntFromPtr(entity)}; return result; @@ -574,19 +574,19 @@ cond_var_alloc(void) internal void cond_var_release(CondVar cv) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(cv.u64[0]); - os_w32_entity_release(entity); + W32_Entity *entity = (W32_Entity*)PtrFromInt(cv.u64[0]); + w32_entity_release(entity); } internal B32 cond_var_wait(CondVar cv, Mutex mutex, U64 endt_us) { - U32 sleep_ms = os_w32_sleep_ms_from_endt_us(endt_us); + U32 sleep_ms = w32_sleep_ms_from_endt_us(endt_us); BOOL result = 0; if(sleep_ms > 0) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(cv.u64[0]); - OS_W32_Entity *mutex_entity = (OS_W32_Entity*)PtrFromInt(mutex.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(cv.u64[0]); + W32_Entity *mutex_entity = (W32_Entity*)PtrFromInt(mutex.u64[0]); result = SleepConditionVariableCS(&entity->cv, &mutex_entity->mutex, sleep_ms); } return result; @@ -595,12 +595,12 @@ cond_var_wait(CondVar cv, Mutex mutex, U64 endt_us) internal B32 cond_var_wait_rw(CondVar cv, RWMutex mutex_rw, B32 write_mode, U64 endt_us) { - U32 sleep_ms = os_w32_sleep_ms_from_endt_us(endt_us); + U32 sleep_ms = w32_sleep_ms_from_endt_us(endt_us); BOOL result = 0; if(sleep_ms > 0) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(cv.u64[0]); - OS_W32_Entity *mutex_entity = (OS_W32_Entity*)PtrFromInt(mutex_rw.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(cv.u64[0]); + W32_Entity *mutex_entity = (W32_Entity*)PtrFromInt(mutex_rw.u64[0]); result = SleepConditionVariableSRW(&entity->cv, &mutex_entity->rw_mutex, sleep_ms, write_mode ? 0 : CONDITION_VARIABLE_LOCKMODE_SHARED); } @@ -610,14 +610,14 @@ cond_var_wait_rw(CondVar cv, RWMutex mutex_rw, B32 write_mode, U64 endt_us) internal void cond_var_signal(CondVar cv) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(cv.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(cv.u64[0]); WakeConditionVariable(&entity->cv); } internal void cond_var_broadcast(CondVar cv) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(cv.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(cv.u64[0]); WakeAllConditionVariable(&entity->cv); } @@ -662,7 +662,7 @@ semaphore_close(Semaphore semaphore) internal B32 semaphore_take(Semaphore semaphore, U64 endt_us) { - U32 sleep_ms = os_w32_sleep_ms_from_endt_us(endt_us); + U32 sleep_ms = w32_sleep_ms_from_endt_us(endt_us); HANDLE handle = (HANDLE)semaphore.u64[0]; DWORD wait_result = WaitForSingleObject(handle, sleep_ms); B32 result = (wait_result == WAIT_OBJECT_0); @@ -681,7 +681,7 @@ semaphore_drop(Semaphore semaphore) internal Barrier barrier_alloc(U64 count) { - OS_W32_Entity *entity = os_w32_entity_alloc(OS_W32_EntityKind_Barrier); + W32_Entity *entity = w32_entity_alloc(W32_EntityKind_Barrier); if(entity != 0) { BOOL init_good = InitializeSynchronizationBarrier(&entity->sb, count, -1); @@ -694,18 +694,18 @@ barrier_alloc(U64 count) internal void barrier_release(Barrier barrier) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(barrier.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(barrier.u64[0]); if(entity != 0) { DeleteSynchronizationBarrier(&entity->sb); - os_w32_entity_release(entity); + w32_entity_release(entity); } } internal void barrier_wait(Barrier barrier) { - OS_W32_Entity *entity = (OS_W32_Entity*)PtrFromInt(barrier.u64[0]); + W32_Entity *entity = (W32_Entity*)PtrFromInt(barrier.u64[0]); if(entity != 0) { EnterSynchronizationBarrier(&entity->sb, 0); @@ -826,7 +826,7 @@ file_set_time(File file, DateTime time) B32 result = 0; HANDLE handle = (HANDLE)file.u64[0]; SYSTEMTIME system_time = {0}; - os_w32_system_time_from_date_time(&system_time, &time); + w32_system_time_from_date_time(&system_time, &time); FILETIME file_time = {0}; result = (SystemTimeToFileTime(&system_time, &file_time) && SetFileTime(handle, &file_time, &file_time, &file_time)); @@ -846,9 +846,9 @@ properties_from_file(File file) U32 size_lo = info.nFileSizeLow; U32 size_hi = info.nFileSizeHigh; props.size = (U64)size_lo | (((U64)size_hi)<<32); - os_w32_dense_time_from_file_time(&props.modified, &info.ftLastWriteTime); - os_w32_dense_time_from_file_time(&props.created, &info.ftCreationTime); - props.flags = os_w32_file_property_flags_from_dwFileAttributes(info.dwFileAttributes); + w32_dense_time_from_file_time(&props.modified, &info.ftLastWriteTime); + w32_dense_time_from_file_time(&props.created, &info.ftCreationTime); + props.flags = w32_file_property_flags_from_dwFileAttributes(info.dwFileAttributes); } return props; } @@ -968,9 +968,9 @@ properties_from_file_path(String8 path) if(handle != INVALID_HANDLE_VALUE) { props.size = Compose64Bit(find_data.nFileSizeHigh, find_data.nFileSizeLow); - os_w32_dense_time_from_file_time(&props.created, &find_data.ftCreationTime); - os_w32_dense_time_from_file_time(&props.modified, &find_data.ftLastWriteTime); - props.flags = os_w32_file_property_flags_from_dwFileAttributes(find_data.dwFileAttributes); + w32_dense_time_from_file_time(&props.created, &find_data.ftCreationTime); + w32_dense_time_from_file_time(&props.modified, &find_data.ftLastWriteTime); + props.flags = w32_file_property_flags_from_dwFileAttributes(find_data.dwFileAttributes); } else { @@ -1093,7 +1093,7 @@ file_iter_begin(Arena *arena, String8 path, FileIterFlags flags) String16 path16 = str16_from_8(scratch.arena, path_with_wildcard); FileIter *iter = push_array(arena, FileIter, 1); iter->flags = flags; - OS_W32_FileIter *w32_iter = (OS_W32_FileIter*)iter->memory; + W32_FileIter *w32_iter = (W32_FileIter*)iter->memory; if(path.size == 0) { w32_iter->is_volume_iter = 1; @@ -1124,7 +1124,7 @@ file_iter_next(Arena *arena, FileIter *iter, FileInfo *info_out) { B32 result = 0; FileIterFlags flags = iter->flags; - OS_W32_FileIter *w32_iter = (OS_W32_FileIter*)iter->memory; + W32_FileIter *w32_iter = (W32_FileIter*)iter->memory; switch(w32_iter->is_volume_iter) { //- rjf: file iteration @@ -1166,9 +1166,9 @@ file_iter_next(Arena *arena, FileIter *iter, FileInfo *info_out) if (usable_file){ info_out->name = str8_from_16(arena, str16_cstring((U16*)file_name)); info_out->props.size = (U64)w32_iter->find_data.nFileSizeLow | (((U64)w32_iter->find_data.nFileSizeHigh)<<32); - os_w32_dense_time_from_file_time(&info_out->props.created, &w32_iter->find_data.ftCreationTime); - os_w32_dense_time_from_file_time(&info_out->props.modified, &w32_iter->find_data.ftLastWriteTime); - info_out->props.flags = os_w32_file_property_flags_from_dwFileAttributes(attributes); + w32_dense_time_from_file_time(&info_out->props.created, &w32_iter->find_data.ftCreationTime); + w32_dense_time_from_file_time(&info_out->props.modified, &w32_iter->find_data.ftLastWriteTime); + info_out->props.flags = w32_file_property_flags_from_dwFileAttributes(attributes); result = 1; if (!FindNextFileW(w32_iter->handle, &w32_iter->find_data)){ iter->flags |= FileIterFlag_Done; @@ -1202,7 +1202,7 @@ file_iter_next(Arena *arena, FileIter *iter, FileInfo *info_out) internal void file_iter_end(FileIter *iter) { - OS_W32_FileIter *w32_iter = (OS_W32_FileIter*)iter->memory; + W32_FileIter *w32_iter = (W32_FileIter*)iter->memory; HANDLE zero_handle; MemoryZeroStruct(&zero_handle); if(!MemoryMatchStruct(&zero_handle, &w32_iter->handle)) @@ -1248,7 +1248,7 @@ abort_self(S32 exit_code) internal ProcessInfo * get_process_info(void) { - return &os_w32_state.process_info; + return &w32_state.process_info; } internal String8 @@ -1274,7 +1274,7 @@ get_process_start_time_unix(void) FILETIME user_time; if(GetProcessTimes(handle, &start_time, &exit_time, &kernel_time, &user_time)) { - result = os_w32_unix_time_from_file_time(start_time); + result = w32_unix_time_from_file_time(start_time); } return result; } @@ -1315,7 +1315,7 @@ process_launch(ProcessLaunchParams *params) { str8_list_push(scratch.arena, &all_opts, n->string); } - for(String8Node *n = os_w32_state.process_info.environment.first; n != 0; n = n->next) + for(String8Node *n = w32_state.process_info.environment.first; n != 0; n = n->next) { str8_list_push(scratch.arena, &all_opts, n->string); } @@ -1386,7 +1386,7 @@ internal B32 process_join(Process process, U64 endt_us, U64 *exit_code_out) { HANDLE process_handle = (HANDLE)(process.u64[0]); - DWORD sleep_ms = os_w32_sleep_ms_from_endt_us(endt_us); + DWORD sleep_ms = w32_sleep_ms_from_endt_us(endt_us); DWORD result = WaitForSingleObject(process_handle, sleep_ms); B32 process_joined = (result == WAIT_OBJECT_0); if(process_joined && exit_code_out) @@ -1784,22 +1784,22 @@ w32_entry_point_caller(int argc, WCHAR **wargv) // (we need to set up some basics before this layer can supply // memory allocation primitives) { - os_w32_state.microsecond_resolution = 1; + w32_state.microsecond_resolution = 1; LARGE_INTEGER large_int_resolution; if(QueryPerformanceFrequency(&large_int_resolution)) { - os_w32_state.microsecond_resolution = large_int_resolution.QuadPart; + w32_state.microsecond_resolution = large_int_resolution.QuadPart; } } { - SystemInfo *info = &os_w32_state.system_info; + SystemInfo *info = &w32_state.system_info; info->logical_processor_count = (U64)sysinfo.dwNumberOfProcessors; info->page_size = sysinfo.dwPageSize; info->large_page_size = GetLargePageMinimum(); info->allocation_granularity = sysinfo.dwAllocationGranularity; } { - ProcessInfo *info = &os_w32_state.process_info; + ProcessInfo *info = &w32_state.process_info; info->large_pages_allowed = large_pages_allowed; info->pid = GetCurrentProcessId(); } @@ -1820,7 +1820,7 @@ w32_entry_point_caller(int argc, WCHAR **wargv) str8_match(arg8, str8_lit("-large_pages"), StringMatchFlag_CaseInsensitive)) { arena_default_flags = ArenaFlag_LargePages; - arena_default_reserve_size = Max(MB(64), os_w32_state.system_info.large_page_size); + arena_default_reserve_size = Max(MB(64), w32_state.system_info.large_page_size); arena_default_commit_size = arena_default_reserve_size; } if(str8_match(arg8, str8_lit("--gen_crash_dump"), StringMatchFlag_CaseInsensitive) || @@ -1838,9 +1838,9 @@ w32_entry_point_caller(int argc, WCHAR **wargv) //- rjf: set up dynamically-alloc'd state Arena *arena = arena_alloc(); { - os_w32_state.arena = arena; + w32_state.arena = arena; { - SystemInfo *info = &os_w32_state.system_info; + SystemInfo *info = &w32_state.system_info; U8 buffer[MAX_COMPUTERNAME_LENGTH + 1] = {0}; DWORD size = MAX_COMPUTERNAME_LENGTH + 1; if(GetComputerNameA((char*)buffer, &size)) @@ -1850,7 +1850,7 @@ w32_entry_point_caller(int argc, WCHAR **wargv) } } { - ProcessInfo *info = &os_w32_state.process_info; + ProcessInfo *info = &w32_state.process_info; { Temp scratch = scratch_begin(0, 0); DWORD size = KB(32); @@ -1896,8 +1896,8 @@ w32_entry_point_caller(int argc, WCHAR **wargv) } //- rjf: set up entity storage - InitializeCriticalSection(&os_w32_state.entity_mutex); - os_w32_state.entity_arena = arena_alloc(); + InitializeCriticalSection(&w32_state.entity_mutex); + w32_state.entity_arena = arena_alloc(); //- rjf: call into "real" entry point main_thread_base_entry_point(argc, argv); diff --git a/src/win32/base/win32_base.h b/src/win32/base/win32_base.h index f03113ee..9940e51d 100644 --- a/src/win32/base/win32_base.h +++ b/src/win32/base/win32_base.h @@ -28,8 +28,8 @@ //////////////////////////////// //~ rjf: File Iterator Types -typedef struct OS_W32_FileIter OS_W32_FileIter; -struct OS_W32_FileIter +typedef struct W32_FileIter W32_FileIter; +struct W32_FileIter { HANDLE handle; WIN32_FIND_DATAW find_data; @@ -37,27 +37,27 @@ struct OS_W32_FileIter String8Array drive_strings; U64 drive_strings_iter_idx; }; -StaticAssert(sizeof(Member(FileIter, memory)) >= sizeof(OS_W32_FileIter), file_iter_memory_size); +StaticAssert(sizeof(Member(FileIter, memory)) >= sizeof(W32_FileIter), file_iter_memory_size); //////////////////////////////// //~ rjf: Entity Types -typedef enum OS_W32_EntityKind +typedef enum W32_EntityKind { - OS_W32_EntityKind_Null, - OS_W32_EntityKind_Thread, - OS_W32_EntityKind_Mutex, - OS_W32_EntityKind_RWMutex, - OS_W32_EntityKind_ConditionVariable, - OS_W32_EntityKind_Barrier, + W32_EntityKind_Null, + W32_EntityKind_Thread, + W32_EntityKind_Mutex, + W32_EntityKind_RWMutex, + W32_EntityKind_ConditionVariable, + W32_EntityKind_Barrier, } -OS_W32_EntityKind; +W32_EntityKind; -typedef struct OS_W32_Entity OS_W32_Entity; -struct OS_W32_Entity +typedef struct W32_Entity W32_Entity; +struct W32_Entity { - OS_W32_Entity *next; - OS_W32_EntityKind kind; + W32_Entity *next; + W32_EntityKind kind; union { struct @@ -77,8 +77,8 @@ struct OS_W32_Entity //////////////////////////////// //~ rjf: State -typedef struct OS_W32_State OS_W32_State; -struct OS_W32_State +typedef struct W32_State W32_State; +struct W32_State { Arena *arena; @@ -90,37 +90,37 @@ struct OS_W32_State // rjf: entity storage CRITICAL_SECTION entity_mutex; Arena *entity_arena; - OS_W32_Entity *entity_free; + W32_Entity *entity_free; }; //////////////////////////////// //~ rjf: Globals -global OS_W32_State os_w32_state = {0}; +global W32_State w32_state = {0}; //////////////////////////////// //~ rjf: File Info Conversion Helpers -internal FilePropertyFlags os_w32_file_property_flags_from_dwFileAttributes(DWORD dwFileAttributes); -internal void os_w32_file_properties_from_attribute_data(FileProperties *properties, WIN32_FILE_ATTRIBUTE_DATA *attributes); +internal FilePropertyFlags w32_file_property_flags_from_dwFileAttributes(DWORD dwFileAttributes); +internal void w32_file_properties_from_attribute_data(FileProperties *properties, WIN32_FILE_ATTRIBUTE_DATA *attributes); //////////////////////////////// //~ rjf: Time Conversion Helpers -internal void os_w32_date_time_from_system_time(DateTime *out, SYSTEMTIME *in); -internal void os_w32_system_time_from_date_time(SYSTEMTIME *out, DateTime *in); -internal void os_w32_dense_time_from_file_time(DenseTime *out, FILETIME *in); -internal U32 os_w32_sleep_ms_from_endt_us(U64 endt_us); +internal void w32_date_time_from_system_time(DateTime *out, SYSTEMTIME *in); +internal void w32_system_time_from_date_time(SYSTEMTIME *out, DateTime *in); +internal void w32_dense_time_from_file_time(DenseTime *out, FILETIME *in); +internal U32 w32_sleep_ms_from_endt_us(U64 endt_us); //////////////////////////////// //~ rjf: Entity Functions -internal OS_W32_Entity *os_w32_entity_alloc(OS_W32_EntityKind kind); -internal void os_w32_entity_release(OS_W32_Entity *entity); +internal W32_Entity *w32_entity_alloc(W32_EntityKind kind); +internal void w32_entity_release(W32_Entity *entity); //////////////////////////////// //~ rjf: Thread Entry Point -internal DWORD os_w32_thread_entry_point(void *ptr); +internal DWORD w32_thread_entry_point(void *ptr); #endif // WIN32_BASE_H diff --git a/src/win32/demon/win32_demon.c b/src/win32/demon/win32_demon.c index 528f01e5..890404d7 100644 --- a/src/win32/demon/win32_demon.c +++ b/src/win32/demon/win32_demon.c @@ -1,71 +1,51 @@ // Copyright (c) Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -//////////////////////////////// -//~ rjf: Basic Helpers - -internal U64 -dmn_w32_hash_from_string(String8 string) -{ - U64 result = 5381; - for(U64 i = 0; i < string.size; i += 1) - { - result = ((result << 5) + result) + string.str[i]; - } - return result; -} - -internal U64 -dmn_w32_hash_from_id(U64 id) -{ - return dmn_w32_hash_from_string(str8_struct(&id)); -} - //////////////////////////////// //~ rjf: Entity Helpers //- rjf: entity <-> handle internal DMN_Handle -dmn_w32_handle_from_entity(DMN_W32_Entity *entity) +w32_dmn_handle_from_entity(W32_DMN_Entity *entity) { - U32 idx = (U32)(entity - dmn_w32_shared->entities_base); + U32 idx = (U32)(entity - w32_dmn_shared->entities_base); U32 gen = entity->gen; DMN_Handle handle = {idx, gen}; return handle; } -internal DMN_W32_Entity * -dmn_w32_entity_from_handle(DMN_Handle handle) +internal W32_DMN_Entity * +w32_dmn_entity_from_handle(DMN_Handle handle) { U32 idx = handle.u32[0]; U32 gen = handle.u32[1]; - DMN_W32_Entity *entity = dmn_w32_shared->entities_base + idx; + W32_DMN_Entity *entity = w32_dmn_shared->entities_base + idx; if(entity->gen != gen) { - entity = &dmn_w32_entity_nil; + entity = &w32_dmn_entity_nil; } return entity; } //- rjf: entity allocation/deallocation -internal DMN_W32_Entity * -dmn_w32_entity_alloc(DMN_W32_Entity *parent, DMN_W32_EntityKind kind, U64 id) +internal W32_DMN_Entity * +w32_dmn_entity_alloc(W32_DMN_Entity *parent, W32_DMN_EntityKind kind, U64 id) { // rjf: allocate - DMN_W32_Entity *e = dmn_w32_shared->entities_first_free; + W32_DMN_Entity *e = w32_dmn_shared->entities_first_free; { U32 gen = 0; if(e != 0) { - SLLStackPop(dmn_w32_shared->entities_first_free); + SLLStackPop(w32_dmn_shared->entities_first_free); gen = e->gen; } else { - e = push_array_no_zero(dmn_w32_shared->entities_arena, DMN_W32_Entity, 1); - dmn_w32_shared->entities_count += 1; + e = push_array_no_zero(w32_dmn_shared->entities_arena, W32_DMN_Entity, 1); + w32_dmn_shared->entities_count += 1; } MemoryZeroStruct(e); e->gen = gen+1; @@ -76,21 +56,21 @@ dmn_w32_entity_alloc(DMN_W32_Entity *parent, DMN_W32_EntityKind kind, U64 id) e->kind = kind; e->id = id; e->parent = parent; - e->next = e->prev = e->first = e->last = &dmn_w32_entity_nil; - if(parent != &dmn_w32_entity_nil) + e->next = e->prev = e->first = e->last = &w32_dmn_entity_nil; + if(parent != &w32_dmn_entity_nil) { - DLLPushBack_NPZ(&dmn_w32_entity_nil, parent->first, parent->last, e, next, prev); + DLLPushBack_NPZ(&w32_dmn_entity_nil, parent->first, parent->last, e, next, prev); } } // rjf: insert into id -> entity map if(id != 0) { - U64 hash = dmn_w32_hash_from_id(id); - U64 slot_idx = hash%dmn_w32_shared->entities_id_hash_slots_count; - DMN_W32_EntityIDHashSlot *slot = &dmn_w32_shared->entities_id_hash_slots[slot_idx]; - DMN_W32_EntityIDHashNode *node = 0; - for(DMN_W32_EntityIDHashNode *n = slot->first; n != 0; n = n->next) + U64 hash = u64_hash_from_str8(str8_struct(&id)); + U64 slot_idx = hash%w32_dmn_shared->entities_id_hash_slots_count; + W32_DMN_EntityIDHashSlot *slot = &w32_dmn_shared->entities_id_hash_slots[slot_idx]; + W32_DMN_EntityIDHashNode *node = 0; + for(W32_DMN_EntityIDHashNode *n = slot->first; n != 0; n = n->next) { if(n->id == id) { @@ -100,14 +80,14 @@ dmn_w32_entity_alloc(DMN_W32_Entity *parent, DMN_W32_EntityKind kind, U64 id) } if(node == 0) { - node = dmn_w32_shared->entities_id_hash_node_free; + node = w32_dmn_shared->entities_id_hash_node_free; if(node != 0) { - SLLStackPop(dmn_w32_shared->entities_id_hash_node_free); + SLLStackPop(w32_dmn_shared->entities_id_hash_node_free); } else { - node = push_array(dmn_w32_shared->arena, DMN_W32_EntityIDHashNode, 1); + node = push_array(w32_dmn_shared->arena, W32_DMN_EntityIDHashNode, 1); } DLLPushBack(slot->first, slot->last, node); } @@ -119,30 +99,30 @@ dmn_w32_entity_alloc(DMN_W32_Entity *parent, DMN_W32_EntityKind kind, U64 id) } internal void -dmn_w32_entity_release(DMN_W32_Entity *entity) +w32_dmn_entity_release(W32_DMN_Entity *entity) { // rjf: unhook root - if(entity->parent != &dmn_w32_entity_nil) + if(entity->parent != &w32_dmn_entity_nil) { - DLLRemove_NPZ(&dmn_w32_entity_nil, entity->parent->first, entity->parent->last, entity, next, prev); + DLLRemove_NPZ(&w32_dmn_entity_nil, entity->parent->first, entity->parent->last, entity, next, prev); } // rjf: walk every entity in this tree, free each - if(entity != &dmn_w32_entity_nil) + if(entity != &w32_dmn_entity_nil) { Temp scratch = scratch_begin(0, 0); typedef struct Task Task; struct Task { Task *next; - DMN_W32_Entity *e; + W32_DMN_Entity *e; }; Task start_task = {0, entity}; Task *first_task = &start_task; Task *last_task = &start_task; for(Task *t = first_task; t != 0; t = t->next) { - for(DMN_W32_Entity *child = t->e->first; child != &dmn_w32_entity_nil; child = child->next) + for(W32_DMN_Entity *child = t->e->first; child != &w32_dmn_entity_nil; child = child->next) { Task *t = push_array(scratch.arena, Task, 1); t->e = child; @@ -150,27 +130,27 @@ dmn_w32_entity_release(DMN_W32_Entity *entity) } // rjf: free entity - SLLStackPush(dmn_w32_shared->entities_first_free, t->e); + SLLStackPush(w32_dmn_shared->entities_first_free, t->e); t->e->gen += 1; - if(t->e->kind == DMN_W32_EntityKind_Module) + if(t->e->kind == W32_DMN_EntityKind_Module) { CloseHandle(t->e->handle); } - t->e->kind = DMN_W32_EntityKind_Null; + t->e->kind = W32_DMN_EntityKind_Null; // rjf: remove from id -> entity map if(t->e->id != 0) { - U64 hash = dmn_w32_hash_from_id(t->e->id); - U64 slot_idx = hash%dmn_w32_shared->entities_id_hash_slots_count; - DMN_W32_EntityIDHashSlot *slot = &dmn_w32_shared->entities_id_hash_slots[slot_idx]; - DMN_W32_EntityIDHashNode *node = 0; - for(DMN_W32_EntityIDHashNode *n = slot->first; n != 0; n = n->next) + U64 hash = u64_hash_from_str8(str8_struct(&t->e->id)); + U64 slot_idx = hash%w32_dmn_shared->entities_id_hash_slots_count; + W32_DMN_EntityIDHashSlot *slot = &w32_dmn_shared->entities_id_hash_slots[slot_idx]; + W32_DMN_EntityIDHashNode *node = 0; + for(W32_DMN_EntityIDHashNode *n = slot->first; n != 0; n = n->next) { if(n->id == t->e->id && n->entity == t->e) { DLLRemove(slot->first, slot->last, n); - SLLStackPush(dmn_w32_shared->entities_id_hash_node_free, n); + SLLStackPush(w32_dmn_shared->entities_id_hash_node_free, n); break; } } @@ -182,15 +162,15 @@ dmn_w32_entity_release(DMN_W32_Entity *entity) //- rjf: kind*id -> entity -internal DMN_W32_Entity * -dmn_w32_entity_from_kind_id(DMN_W32_EntityKind kind, U64 id) +internal W32_DMN_Entity * +w32_dmn_entity_from_kind_id(W32_DMN_EntityKind kind, U64 id) { - DMN_W32_Entity *result = &dmn_w32_entity_nil; - U64 hash = dmn_w32_hash_from_id(id); - U64 slot_idx = hash%dmn_w32_shared->entities_id_hash_slots_count; - DMN_W32_EntityIDHashSlot *slot = &dmn_w32_shared->entities_id_hash_slots[slot_idx]; - DMN_W32_EntityIDHashNode *node = 0; - for(DMN_W32_EntityIDHashNode *n = slot->first; n != 0; n = n->next) + W32_DMN_Entity *result = &w32_dmn_entity_nil; + U64 hash = u64_hash_from_str8(str8_struct(&id)); + U64 slot_idx = hash%w32_dmn_shared->entities_id_hash_slots_count; + W32_DMN_EntityIDHashSlot *slot = &w32_dmn_shared->entities_id_hash_slots[slot_idx]; + W32_DMN_EntityIDHashNode *node = 0; + for(W32_DMN_EntityIDHashNode *n = slot->first; n != 0; n = n->next) { if(n->entity->kind == kind && n->id == id) { @@ -209,7 +189,7 @@ dmn_w32_entity_from_kind_id(DMN_W32_EntityKind kind, U64 id) //~ rjf: Module Info Extraction internal String8 -dmn_w32_full_path_from_module(Arena *arena, DMN_W32_Entity *module) +w32_dmn_full_path_from_module(Arena *arena, W32_DMN_Entity *module) { Temp scratch = scratch_begin(&arena, 1); @@ -229,7 +209,7 @@ dmn_w32_full_path_from_module(Arena *arena, DMN_W32_Entity *module) // rjf: fallback (main module only): process -> full path if(path16.size == 0 && module->module.is_main) { - DMN_W32_Entity *process = module->parent; + W32_DMN_Entity *process = module->parent; DWORD size = KB(4); U16 *buf = push_array_no_zero(scratch.arena, U16, size); if(QueryFullProcessImageNameW(process->handle, 0, (WCHAR*)buf, &size)) @@ -241,20 +221,20 @@ dmn_w32_full_path_from_module(Arena *arena, DMN_W32_Entity *module) // rjf: fallback (any module - no guarantee): address_of_name -> full path if(path16.size == 0 && module->module.address_of_name_pointer != 0) { - DMN_W32_Entity *process = module->parent; + W32_DMN_Entity *process = module->parent; U64 ptr_size = bit_size_from_arch(process->arch)/8; U64 name_pointer = 0; - if(dmn_w32_process_read(process->handle, r1u64(module->module.address_of_name_pointer, module->module.address_of_name_pointer+ptr_size), &name_pointer)) + if(w32_dmn_process_read(process->handle, r1u64(module->module.address_of_name_pointer, module->module.address_of_name_pointer+ptr_size), &name_pointer)) { if(name_pointer != 0) { if(module->module.name_is_unicode) { - path16 = dmn_w32_read_memory_str16(scratch.arena, process->handle, name_pointer); + path16 = w32_dmn_read_memory_str16(scratch.arena, process->handle, name_pointer); } else { - path8 = dmn_w32_read_memory_str(scratch.arena, process->handle, name_pointer); + path8 = w32_dmn_read_memory_str(scratch.arena, process->handle, name_pointer); } } } @@ -308,7 +288,7 @@ dmn_w32_full_path_from_module(Arena *arena, DMN_W32_Entity *module) //- rjf: processes internal U64 -dmn_w32_process_read(HANDLE process, Rng1U64 range, void *dst) +w32_dmn_process_read(HANDLE process, Rng1U64 range, void *dst) { U64 bytes_read = 0; U8 *ptr = (U8*)dst; @@ -336,7 +316,7 @@ dmn_w32_process_read(HANDLE process, Rng1U64 range, void *dst) } internal B32 -dmn_w32_process_write(HANDLE process, Rng1U64 range, void *src) +w32_dmn_process_write(HANDLE process, Rng1U64 range, void *src) { B32 result = 1; U8 *ptr = (U8*)src; @@ -358,14 +338,14 @@ dmn_w32_process_write(HANDLE process, Rng1U64 range, void *src) } internal String8 -dmn_w32_read_memory_str(Arena *arena, HANDLE process_handle, U64 address) +w32_dmn_read_memory_str(Arena *arena, HANDLE process_handle, U64 address) { // TODO(rjf): @rewrite // // OLD: this could be done better with a demon_w32_read_memory // that returns a read amount instead of a success/fail. // - // (dmn_w32_process_read now does this, so we can switch to it) + // (w32_dmn_process_read now does this, so we can switch to it) // scan piece by piece Temp scratch = scratch_begin(&arena, 1); @@ -377,7 +357,7 @@ dmn_w32_read_memory_str(Arena *arena, HANDLE process_handle, U64 address) for (;;){ U8 *block = push_array(scratch.arena, U8, cap); for (;cap > 0;){ - if (dmn_w32_process_read(process_handle, r1u64(read_p, read_p+cap), block)){ + if (w32_dmn_process_read(process_handle, r1u64(read_p, read_p+cap), block)){ break; } cap /= 2; @@ -407,14 +387,14 @@ dmn_w32_read_memory_str(Arena *arena, HANDLE process_handle, U64 address) } internal String16 -dmn_w32_read_memory_str16(Arena *arena, HANDLE process_handle, U64 address) +w32_dmn_read_memory_str16(Arena *arena, HANDLE process_handle, U64 address) { // TODO(rjf): @rewrite // // OLD: this could be done better with a demon_w32_read_memory // that returns a read amount instead of a success/fail. // - // (dmn_w32_process_read now does this, so we can switch to it) + // (w32_dmn_process_read now does this, so we can switch to it) // scan piece by piece Temp scratch = scratch_begin(&arena, 1); @@ -426,7 +406,7 @@ dmn_w32_read_memory_str16(Arena *arena, HANDLE process_handle, U64 address) for (;;){ U8 *block = push_array(scratch.arena, U8, cap); for (;cap > 1;){ - if (dmn_w32_process_read(process_handle, r1u64(read_p, read_p+cap), block)){ + if (w32_dmn_process_read(process_handle, r1u64(read_p, read_p+cap), block)){ break; } cap /= 2; @@ -458,19 +438,19 @@ dmn_w32_read_memory_str16(Arena *arena, HANDLE process_handle, U64 address) return(result); } -internal DMN_W32_ImageInfo -dmn_w32_image_info_from_process_base_vaddr(HANDLE process, U64 base_vaddr) +internal W32_DMN_ImageInfo +w32_dmn_image_info_from_process_base_vaddr(HANDLE process, U64 base_vaddr) { // rjf: find PE offset U32 pe_offset = 0; { U64 dos_magic_off = base_vaddr; U16 dos_magic = 0; - dmn_w32_process_read_struct(process, dos_magic_off, &dos_magic); + w32_dmn_process_read_struct(process, dos_magic_off, &dos_magic); if(dos_magic == PE_DOS_MAGIC) { U64 pe_offset_off = base_vaddr + OffsetOf(PE_DosHeader, coff_file_offset); - dmn_w32_process_read_struct(process, pe_offset_off, &pe_offset); + w32_dmn_process_read_struct(process, pe_offset_off, &pe_offset); } } @@ -482,15 +462,15 @@ dmn_w32_image_info_from_process_base_vaddr(HANDLE process, U64 base_vaddr) { U64 pe_magic_off = base_vaddr + pe_offset; U32 pe_magic = 0; - dmn_w32_process_read_struct(process, pe_magic_off, &pe_magic); + w32_dmn_process_read_struct(process, pe_magic_off, &pe_magic); if(pe_magic == PE_MAGIC) { coff_header_off = pe_magic_off + sizeof(pe_magic); - got_coff_header = dmn_w32_process_read_struct(process, coff_header_off, &coff_header); + got_coff_header = w32_dmn_process_read_struct(process, coff_header_off, &coff_header); } } - DMN_W32_ImageInfo result = zero_struct; + W32_DMN_ImageInfo result = zero_struct; if(got_coff_header) { U64 optional_off = coff_header_off + sizeof(COFF_FileHeader); @@ -505,7 +485,7 @@ dmn_w32_image_info_from_process_base_vaddr(HANDLE process, U64 base_vaddr) if(pe_has_plus_header(coff_header.machine)) { PE_OptionalHeader32Plus opt_header = {0}; - if(dmn_w32_process_read_struct(process, optional_off, &opt_header)) + if(w32_dmn_process_read_struct(process, optional_off, &opt_header)) { image_size = opt_header.sizeof_image; data_dir_count = opt_header.data_dir_count; @@ -516,7 +496,7 @@ dmn_w32_image_info_from_process_base_vaddr(HANDLE process, U64 base_vaddr) else { PE_OptionalHeader32 opt_header = {0}; - if(dmn_w32_process_read_struct(process, optional_off, &opt_header)) + if(w32_dmn_process_read_struct(process, optional_off, &opt_header)) { image_size = opt_header.sizeof_image; data_dir_count = opt_header.data_dir_count; @@ -530,17 +510,17 @@ dmn_w32_image_info_from_process_base_vaddr(HANDLE process, U64 base_vaddr) { U64 tls_dir_vaddr = data_dir_off + PE_DataDirectoryIndex_TLS * sizeof(PE_DataDirectory); PE_DataDirectory tls_dir = {0}; - if(dmn_w32_process_read_struct(process, tls_dir_vaddr, &tls_dir)) + if(w32_dmn_process_read_struct(process, tls_dir_vaddr, &tls_dir)) { if(pe_has_plus_header(coff_header.machine)) { if(tls_dir.virt_size == sizeof(PE_TLSHeader64)) { PE_TLSHeader64 tls_header = {0}; - if(dmn_w32_process_read_struct(process, base_vaddr + tls_dir.virt_off, &tls_header)) + if(w32_dmn_process_read_struct(process, base_vaddr + tls_dir.virt_off, &tls_header)) { U64 tls_index64 = 0; - if(dmn_w32_process_read_struct(process, tls_header.index_address, &tls_index64)) + if(w32_dmn_process_read_struct(process, tls_header.index_address, &tls_index64)) { tls_index = tls_index64; } @@ -554,10 +534,10 @@ dmn_w32_image_info_from_process_base_vaddr(HANDLE process, U64 base_vaddr) if(tls_dir.virt_size == sizeof(PE_TLSHeader32)) { PE_TLSHeader32 tls_header = {0}; - if(dmn_w32_process_read_struct(process, base_vaddr + tls_dir.virt_off, &tls_header)) + if(w32_dmn_process_read_struct(process, base_vaddr + tls_dir.virt_off, &tls_header)) { U32 tls_index32 = 0; - if(dmn_w32_process_read_struct(process, tls_header.index_address, &tls_index32)) + if(w32_dmn_process_read_struct(process, tls_header.index_address, &tls_index32)) { tls_index = tls_index32; } @@ -583,7 +563,7 @@ dmn_w32_image_info_from_process_base_vaddr(HANDLE process, U64 base_vaddr) //- rjf: threads internal B32 -dmn_w32_thread_read_reg_block(Arch arch, HANDLE thread, void *reg_block) +w32_dmn_thread_read_reg_block(Arch arch, HANDLE thread, void *reg_block) { B32 result = 0; ProfBeginFunction(); @@ -614,7 +594,7 @@ dmn_w32_thread_read_reg_block(Arch arch, HANDLE thread, void *reg_block) //- rjf: set up context CONTEXT *ctx = 0; - U32 ctx_flags = DMN_W32_CTX_X64_ALL | (xstate_enabled ? DMN_W32_CTX_INTEL_XSTATE : 0); + U32 ctx_flags = W32_DMN_CTX_X64_ALL | (xstate_enabled ? W32_DMN_CTX_INTEL_XSTATE : 0); DWORD size = 0; InitializeContext(0, ctx_flags, 0, &size); if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) @@ -810,7 +790,7 @@ dmn_w32_thread_read_reg_block(Arch arch, HANDLE thread, void *reg_block) } internal B32 -dmn_w32_thread_write_reg_block(Arch arch, HANDLE thread, void *reg_block) +w32_dmn_thread_write_reg_block(Arch arch, HANDLE thread, void *reg_block) { B32 result = 0; ProfBeginFunction(); @@ -841,7 +821,7 @@ dmn_w32_thread_write_reg_block(Arch arch, HANDLE thread, void *reg_block) //- rjf: set up context CONTEXT *ctx = 0; - U32 ctx_flags = DMN_W32_CTX_X64_ALL | (xstate_enabled ? DMN_W32_CTX_INTEL_XSTATE : 0); + U32 ctx_flags = W32_DMN_CTX_X64_ALL | (xstate_enabled ? W32_DMN_CTX_INTEL_XSTATE : 0); DWORD size = 0; InitializeContext(0, ctx_flags, 0, &size); if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) @@ -991,7 +971,7 @@ dmn_w32_thread_write_reg_block(Arch arch, HANDLE thread, void *reg_block) //- rjf: remote thread injection internal DWORD -dmn_w32_inject_thread(HANDLE process, U64 start_address) +w32_dmn_inject_thread(HANDLE process, U64 start_address) { LPTHREAD_START_ROUTINE start = (LPTHREAD_START_ROUTINE)start_address; DWORD thread_id = 0; @@ -1010,18 +990,18 @@ internal void dmn_init(void) { Arena *arena = arena_alloc(); - dmn_w32_shared = push_array(arena, DMN_W32_Shared, 1); - dmn_w32_shared->arena = arena; - dmn_w32_shared->access_mutex = mutex_alloc(); - dmn_w32_shared->detach_arena = arena_alloc(); - dmn_w32_shared->entities_arena = arena_alloc(.reserve_size = GB(8), .commit_size = KB(64)); - dmn_w32_shared->entities_base = dmn_w32_entity_alloc(&dmn_w32_entity_nil, DMN_W32_EntityKind_Root, 0); - dmn_w32_shared->entities_id_hash_slots_count = 4096; - dmn_w32_shared->entities_id_hash_slots = push_array(arena, DMN_W32_EntityIDHashSlot, dmn_w32_shared->entities_id_hash_slots_count); + w32_dmn_shared = push_array(arena, W32_DMN_Shared, 1); + w32_dmn_shared->arena = arena; + w32_dmn_shared->access_mutex = mutex_alloc(); + w32_dmn_shared->detach_arena = arena_alloc(); + w32_dmn_shared->entities_arena = arena_alloc(.reserve_size = GB(8), .commit_size = KB(64)); + w32_dmn_shared->entities_base = w32_dmn_entity_alloc(&w32_dmn_entity_nil, W32_DMN_EntityKind_Root, 0); + w32_dmn_shared->entities_id_hash_slots_count = 4096; + w32_dmn_shared->entities_id_hash_slots = push_array(arena, W32_DMN_EntityIDHashSlot, w32_dmn_shared->entities_id_hash_slots_count); // rjf: load Windows 10+ GetThreadDescription API { - dmn_w32_GetThreadDescription = (DMN_W32_GetThreadDescriptionFunctionType *)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "GetThreadDescription"); + w32_dmn_GetThreadDescription = (W32_DMN_GetThreadDescriptionFunctionType *)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "GetThreadDescription"); } // rjf: setup environment variables @@ -1039,8 +1019,8 @@ dmn_init(void) else { String16 string16 = str16((U16 *)this_proc_env + start_idx, idx - start_idx); - String8 string = str8_from_16(dmn_w32_shared->arena, string16); - str8_list_push(dmn_w32_shared->arena, &dmn_w32_shared->env_strings, string); + String8 string = str8_from_16(w32_dmn_shared->arena, string16); + str8_list_push(w32_dmn_shared->arena, &w32_dmn_shared->env_strings, string); start_idx = idx+1; } } @@ -1055,25 +1035,25 @@ internal DMN_CtrlCtx * dmn_ctrl_begin(void) { DMN_CtrlCtx *ctx = (DMN_CtrlCtx *)1; - dmn_w32_ctrl_thread = 1; + w32_dmn_ctrl_thread = 1; return ctx; } internal void dmn_ctrl_exclusive_access_begin(void) { - MutexScope(dmn_w32_shared->access_mutex) + MutexScope(w32_dmn_shared->access_mutex) { - dmn_w32_shared->access_run_state = 1; + w32_dmn_shared->access_run_state = 1; } } internal void dmn_ctrl_exclusive_access_end(void) { - MutexScope(dmn_w32_shared->access_mutex) + MutexScope(w32_dmn_shared->access_mutex) { - dmn_w32_shared->access_run_state = 0; + w32_dmn_shared->access_run_state = 0; } } @@ -1114,7 +1094,7 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, ProcessLaunchParams *params) { str8_list_push(scratch.arena, &all_opts, n->string); } - for(String8Node *n = dmn_w32_shared->env_strings.first; n != 0; n = n->next) + for(String8Node *n = w32_dmn_shared->env_strings.first; n != 0; n = n->next) { str8_list_push(scratch.arena, &all_opts, n->string); } @@ -1178,7 +1158,7 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, ProcessLaunchParams *params) else { result = process_info.dwProcessId; - dmn_w32_shared->new_process_pending = 1; + w32_dmn_shared->new_process_pending = 1; } CloseHandle(process_info.hProcess); CloseHandle(process_info.hThread); @@ -1205,7 +1185,7 @@ dmn_ctrl_attach(DMN_CtrlCtx *ctx, U32 pid) DMN_AccessScope if(DebugActiveProcess((DWORD)pid)) { result = 1; - dmn_w32_shared->new_process_pending = 1; + w32_dmn_shared->new_process_pending = 1; #if 0 // TODO(rjf): JIT debugging info @@ -1233,7 +1213,7 @@ dmn_ctrl_kill(DMN_CtrlCtx *ctx, DMN_Handle process, U32 exit_code) B32 result = 0; DMN_AccessScope { - DMN_W32_Entity *process_entity = dmn_w32_entity_from_handle(process); + W32_DMN_Entity *process_entity = w32_dmn_entity_from_handle(process); if(TerminateProcess(process_entity->handle, exit_code)) { result = 1; @@ -1248,14 +1228,14 @@ dmn_ctrl_detach(DMN_CtrlCtx *ctx, DMN_Handle process) B32 result = 0; DMN_AccessScope { - DMN_W32_Entity *process_entity = dmn_w32_entity_from_handle(process); + W32_DMN_Entity *process_entity = w32_dmn_entity_from_handle(process); // rjf: resume threads - for(DMN_W32_Entity *child = process_entity->first; - child != &dmn_w32_entity_nil; + for(W32_DMN_Entity *child = process_entity->first; + child != &w32_dmn_entity_nil; child = child->next) { - if(child->kind == DMN_W32_EntityKind_Thread) + if(child->kind == W32_DMN_EntityKind_Thread) { DWORD resume_result = ResumeThread(child->handle); (void)resume_result; @@ -1274,7 +1254,7 @@ dmn_ctrl_detach(DMN_CtrlCtx *ctx, DMN_Handle process) // rjf: push into list of processes to generate events for later if(result != 0) { - dmn_handle_list_push(dmn_w32_shared->detach_arena, &dmn_w32_shared->detach_processes, process); + dmn_handle_list_push(w32_dmn_shared->detach_arena, &w32_dmn_shared->detach_processes, process); } } return result; @@ -1289,28 +1269,28 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) ////////////////////////////// //- rjf: determine event generation path // - typedef enum DMN_W32_EventGenPath + typedef enum W32_DMN_EventGenPath { - DMN_W32_EventGenPath_NotAttached, - DMN_W32_EventGenPath_Run, - DMN_W32_EventGenPath_DetachProcesses, + W32_DMN_EventGenPath_NotAttached, + W32_DMN_EventGenPath_Run, + W32_DMN_EventGenPath_DetachProcesses, } - DMN_W32_EventGenPath; - DMN_W32_EventGenPath event_gen_path = DMN_W32_EventGenPath_Run; - if(dmn_w32_shared->detach_processes.first != 0) + W32_DMN_EventGenPath; + W32_DMN_EventGenPath event_gen_path = W32_DMN_EventGenPath_Run; + if(w32_dmn_shared->detach_processes.first != 0) { - event_gen_path = DMN_W32_EventGenPath_DetachProcesses; + event_gen_path = W32_DMN_EventGenPath_DetachProcesses; } else { - B32 any_processes_live = dmn_w32_shared->new_process_pending; + B32 any_processes_live = w32_dmn_shared->new_process_pending; if(!any_processes_live) { - for(DMN_W32_Entity *process = dmn_w32_shared->entities_base->first; - process != &dmn_w32_entity_nil; + for(W32_DMN_Entity *process = w32_dmn_shared->entities_base->first; + process != &w32_dmn_entity_nil; process = process->next) { - if(process->kind == DMN_W32_EntityKind_Process) + if(process->kind == W32_DMN_EntityKind_Process) { any_processes_live = 1; break; @@ -1319,7 +1299,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } if(!any_processes_live) { - event_gen_path = DMN_W32_EventGenPath_NotAttached; + event_gen_path = W32_DMN_EventGenPath_NotAttached; } } @@ -1331,7 +1311,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) //////////////////////////// //- rjf: produce not-attached error events // - case DMN_W32_EventGenPath_NotAttached: + case W32_DMN_EventGenPath_NotAttached: { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_Error; @@ -1341,7 +1321,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) //////////////////////////// //- rjf: produce debug events from regular running // - case DMN_W32_EventGenPath_Run: + case W32_DMN_EventGenPath_Run: { Temp scratch = scratch_begin(&arena, 1); @@ -1351,14 +1331,14 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) CONTEXT *single_step_thread_ctx = 0; if(!dmn_handle_match(ctrls->single_step_thread, dmn_handle_zero())) { - DMN_W32_Entity *thread = dmn_w32_entity_from_handle(ctrls->single_step_thread); + W32_DMN_Entity *thread = w32_dmn_entity_from_handle(ctrls->single_step_thread); Arch arch = thread->arch; switch(arch) { default:{}break; case Arch_x64: { - U32 ctx_flags = DMN_W32_CTX_X64|DMN_W32_CTX_INTEL_CONTROL; + U32 ctx_flags = W32_DMN_CTX_X64|W32_DMN_CTX_INTEL_CONTROL; DWORD size = 0; InitializeContext(0, ctx_flags, 0, &size); if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) @@ -1378,7 +1358,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // if(!dmn_handle_match(ctrls->single_step_thread, dmn_handle_zero())) ProfScope("set single step bit") { - DMN_W32_Entity *thread = dmn_w32_entity_from_handle(ctrls->single_step_thread); + W32_DMN_Entity *thread = w32_dmn_entity_from_handle(ctrls->single_step_thread); Arch arch = thread->arch; switch(arch) { @@ -1497,12 +1477,12 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) for(DMN_FlaggedTrapTask *t = first_flagged_trap_task; t != 0; t = t->next) { DMN_Handle process = t->process; - DMN_W32_Entity *process_entity = dmn_w32_entity_from_handle(process); - for(DMN_W32_Entity *child = process_entity->first; - child != &dmn_w32_entity_nil; + W32_DMN_Entity *process_entity = w32_dmn_entity_from_handle(process); + for(W32_DMN_Entity *child = process_entity->first; + child != &w32_dmn_entity_nil; child = child->next) { - if(child->kind == DMN_W32_EntityKind_Thread) + if(child->kind == W32_DMN_EntityKind_Thread) { switch(child->arch) { @@ -1512,7 +1492,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) case Arch_x64: { X64_RegBlock regs = {0}; - dmn_w32_thread_read_reg_block(child->arch, child->handle, ®s); + w32_dmn_thread_read_reg_block(child->arch, child->handle, ®s); { U64 trap_idx = 0; for(DMN_TrapChunkNode *n = t->traps.first; n != 0; n = n->next) @@ -1573,7 +1553,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } } } - dmn_w32_thread_write_reg_block(child->arch, child->handle, ®s); + w32_dmn_thread_write_reg_block(child->arch, child->handle, ®s); }break; } } @@ -1584,16 +1564,16 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) ////////////////////////// //- rjf: produce list of threads which will run // - DMN_W32_EntityNode *first_run_thread = 0; - DMN_W32_EntityNode *last_run_thread = 0; + W32_DMN_EntityNode *first_run_thread = 0; + W32_DMN_EntityNode *last_run_thread = 0; ProfScope("produce list of threads which will run") { //- rjf: scan all processes - for(DMN_W32_Entity *process = dmn_w32_shared->entities_base->first; - process != &dmn_w32_entity_nil; + for(W32_DMN_Entity *process = w32_dmn_shared->entities_base->first; + process != &w32_dmn_entity_nil; process = process->next) { - if(process->kind != DMN_W32_EntityKind_Process) {continue;} + if(process->kind != W32_DMN_EntityKind_Process) {continue;} //- rjf: determine if this process is frozen B32 process_is_frozen = 0; @@ -1601,7 +1581,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { for(U64 idx = 0; idx < ctrls->run_entity_count; idx += 1) { - if(dmn_handle_match(ctrls->run_entities[idx], dmn_w32_handle_from_entity(process))) + if(dmn_handle_match(ctrls->run_entities[idx], w32_dmn_handle_from_entity(process))) { process_is_frozen = 1; break; @@ -1610,11 +1590,11 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } //- rjf: scan all threads in this process - for(DMN_W32_Entity *thread = process->first; - thread != &dmn_w32_entity_nil; + for(W32_DMN_Entity *thread = process->first; + thread != &w32_dmn_entity_nil; thread = thread->next) { - if(thread->kind != DMN_W32_EntityKind_Thread) {continue;} + if(thread->kind != W32_DMN_EntityKind_Thread) {continue;} //- rjf: determine if this thread is frozen B32 is_frozen = 0; @@ -1622,7 +1602,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // rjf: single-step? freeze if not the single-step thread. if(!dmn_handle_match(dmn_handle_zero(), ctrls->single_step_thread)) { - is_frozen = !dmn_handle_match(dmn_w32_handle_from_entity(thread), ctrls->single_step_thread); + is_frozen = !dmn_handle_match(w32_dmn_handle_from_entity(thread), ctrls->single_step_thread); } // rjf: not single-stepping? determine based on run controls freezing info @@ -1634,7 +1614,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } else for(U64 idx = 0; idx < ctrls->run_entity_count; idx += 1) { - if(dmn_handle_match(ctrls->run_entities[idx], dmn_w32_handle_from_entity(thread))) + if(dmn_handle_match(ctrls->run_entities[idx], w32_dmn_handle_from_entity(thread))) { is_frozen = 1; break; @@ -1648,7 +1628,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } //- rjf: disregard all other rules if this is the halter thread - if(dmn_w32_shared->halter_tid == thread->id) + if(w32_dmn_shared->halter_tid == thread->id) { is_frozen = 0; } @@ -1656,7 +1636,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) //- rjf: add to list if(!is_frozen) { - DMN_W32_EntityNode *n = push_array(scratch.arena, DMN_W32_EntityNode, 1); + W32_DMN_EntityNode *n = push_array(scratch.arena, W32_DMN_EntityNode, 1); n->v = thread; SLLQueuePush(first_run_thread, last_run_thread, n); } @@ -1670,8 +1650,8 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) B32 priority_mode = !dmn_handle_match(dmn_handle_zero(), ctrls->priority_thread); B32 did_priority_mode = priority_mode; B32 do_threads_resume = 1; - DMN_W32_EntityNode *first_ran_thread = 0; - DMN_W32_EntityNode *last_ran_thread = 0; + W32_DMN_EntityNode *first_ran_thread = 0; + W32_DMN_EntityNode *last_ran_thread = 0; U64 begin_time = now_time_us(); String8List debug_strings = {0}; DMN_Event *debug_strings_event = 0; @@ -1688,17 +1668,17 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) if(do_threads_resume) ProfScope("resume threads that we want to run") { do_threads_resume = 0; - for(DMN_W32_EntityNode *n = first_run_thread; n != 0; n = n->next) + for(W32_DMN_EntityNode *n = first_run_thread; n != 0; n = n->next) { - DMN_W32_Entity *thread = n->v; - B32 thread_is_priority = dmn_handle_match(dmn_w32_handle_from_entity(thread), ctrls->priority_thread); + W32_DMN_Entity *thread = n->v; + B32 thread_is_priority = dmn_handle_match(w32_dmn_handle_from_entity(thread), ctrls->priority_thread); if((priority_mode && !thread_is_priority) || (!priority_mode && did_priority_mode && thread_is_priority)) { continue; } DWORD resume_result = ResumeThread(thread->handle); - DMN_W32_EntityNode *n = push_array(scratch.arena, DMN_W32_EntityNode, 1); + W32_DMN_EntityNode *n = push_array(scratch.arena, W32_DMN_EntityNode, 1); SLLQueuePush(first_ran_thread, last_ran_thread, n); n->v = thread; switch(resume_result) @@ -1732,7 +1712,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // DWORD resume_code = DBG_CONTINUE; { - if(dmn_w32_shared->exception_not_handled && !ctrls->ignore_previous_exception) + if(w32_dmn_shared->exception_not_handled && !ctrls->ignore_previous_exception) { log_infof("using DBG_EXCEPTION_NOT_HANDLED\n"); resume_code = DBG_EXCEPTION_NOT_HANDLED; @@ -1741,7 +1721,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { log_infof("using DBG_CONTINUE\n"); } - dmn_w32_shared->exception_not_handled = 0; + w32_dmn_shared->exception_not_handled = 0; } //////////////////////// @@ -1752,14 +1732,14 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) ProfScope("inform windows that we're resuming, run, & obtain next debug event") { B32 resume_good = 1; - if(dmn_w32_shared->resume_needed) + if(w32_dmn_shared->resume_needed) { - dmn_w32_shared->resume_needed = 0; - resume_good = !!ContinueDebugEvent(dmn_w32_shared->resume_pid, dmn_w32_shared->resume_tid, resume_code); + w32_dmn_shared->resume_needed = 0; + resume_good = !!ContinueDebugEvent(w32_dmn_shared->resume_pid, w32_dmn_shared->resume_tid, resume_code); DWORD error = GetLastError(); - dmn_w32_shared->resume_needed = 0; - dmn_w32_shared->resume_tid = 0; - dmn_w32_shared->resume_pid = 0; + w32_dmn_shared->resume_needed = 0; + w32_dmn_shared->resume_tid = 0; + w32_dmn_shared->resume_pid = 0; } if(resume_good) { @@ -1771,9 +1751,9 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) evt_good = !!WaitForDebugEvent(&evt, wait_ms); if(evt_good) { - dmn_w32_shared->resume_needed = 1; - dmn_w32_shared->resume_pid = evt.dwProcessId; - dmn_w32_shared->resume_tid = evt.dwThreadId; + w32_dmn_shared->resume_needed = 1; + w32_dmn_shared->resume_pid = evt.dwProcessId; + w32_dmn_shared->resume_tid = evt.dwThreadId; } else { @@ -1802,7 +1782,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) case CREATE_PROCESS_DEBUG_EVENT: { // rjf: zero out "process pending" state - dmn_w32_shared->new_process_pending = 0; + w32_dmn_shared->new_process_pending = 0; // rjf: unpack event HANDLE process_handle = evt.u.CreateProcessInfo.hProcess; @@ -1812,12 +1792,12 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) U64 module_base = (U64)evt.u.CreateProcessInfo.lpBaseOfImage; U64 module_name_vaddr = (U64)evt.u.CreateProcessInfo.lpImageName; B32 module_name_is_unicode = (evt.u.CreateProcessInfo.fUnicode != 0); - DMN_W32_ImageInfo image_info = dmn_w32_image_info_from_process_base_vaddr(process_handle, module_base); + W32_DMN_ImageInfo image_info = w32_dmn_image_info_from_process_base_vaddr(process_handle, module_base); // rjf: create entities (thread/module are implied for initial - they are not reported by win32) - DMN_W32_Entity *process = dmn_w32_entity_alloc(dmn_w32_shared->entities_base, DMN_W32_EntityKind_Process, evt.dwProcessId); - DMN_W32_Entity *thread = dmn_w32_entity_alloc(process, DMN_W32_EntityKind_Thread, evt.dwThreadId); - DMN_W32_Entity *module = dmn_w32_entity_alloc(process, DMN_W32_EntityKind_Module, module_base); + W32_DMN_Entity *process = w32_dmn_entity_alloc(w32_dmn_shared->entities_base, W32_DMN_EntityKind_Process, evt.dwProcessId); + W32_DMN_Entity *thread = w32_dmn_entity_alloc(process, W32_DMN_EntityKind_Thread, evt.dwThreadId); + W32_DMN_Entity *module = w32_dmn_entity_alloc(process, W32_DMN_EntityKind_Module, module_base); { process->handle = process_handle; process->arch = image_info.arch; @@ -1837,12 +1817,12 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // rjf: set up per-process injected code (to run halter threads on & // generate debug events) { - U8 injection_code[DMN_W32_INJECTED_CODE_SIZE]; - MemorySet(injection_code, 0xCC, DMN_W32_INJECTED_CODE_SIZE); + U8 injection_code[W32_DMN_INJECTED_CODE_SIZE]; + MemorySet(injection_code, 0xCC, W32_DMN_INJECTED_CODE_SIZE); injection_code[0] = 0xC3; - U64 injection_size = DMN_W32_INJECTED_CODE_SIZE + sizeof(DMN_W32_InjectedBreak); + U64 injection_size = W32_DMN_INJECTED_CODE_SIZE + sizeof(W32_DMN_InjectedBreak); U64 injection_address = (U64)VirtualAllocEx(process_handle, 0, injection_size, MEM_COMMIT|MEM_RESERVE, PAGE_EXECUTE); - dmn_w32_process_write(process_handle, r1u64(injection_address, injection_address+sizeof(injection_code)), injection_code); + w32_dmn_process_write(process_handle, r1u64(injection_address, injection_address+sizeof(injection_code)), injection_code); process->proc.injection_address = injection_address; } @@ -1852,7 +1832,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_CreateProcess; - e->process = dmn_w32_handle_from_entity(process); + e->process = w32_dmn_handle_from_entity(process); e->arch = image_info.arch; e->code = evt.dwProcessId; e->tls_model = DMN_TlsModel_WinodwsNt; @@ -1862,8 +1842,8 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_CreateThread; - e->process = dmn_w32_handle_from_entity(process); - e->thread = dmn_w32_handle_from_entity(thread); + e->process = w32_dmn_handle_from_entity(process); + e->thread = w32_dmn_handle_from_entity(thread); e->arch = image_info.arch; e->code = evt.dwThreadId; } @@ -1872,12 +1852,12 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_LoadModule; - e->process = dmn_w32_handle_from_entity(process); - e->module = dmn_w32_handle_from_entity(module); + e->process = w32_dmn_handle_from_entity(process); + e->module = w32_dmn_handle_from_entity(module); e->arch = image_info.arch; e->address = module_base; e->size = image_info.size; - e->string = dmn_w32_full_path_from_module(arena, module); + e->string = w32_dmn_full_path_from_module(arena, module); e->tls_index = image_info.tls_index; } } @@ -1888,37 +1868,37 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // case EXIT_PROCESS_DEBUG_EVENT: { - DMN_W32_Entity *process = dmn_w32_entity_from_kind_id(DMN_W32_EntityKind_Process, evt.dwProcessId); + W32_DMN_Entity *process = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Process, evt.dwProcessId); // rjf: if this was the process we were going to resume, then we will // just not resume, and wait for another debug event - if(evt.dwProcessId == dmn_w32_shared->resume_pid) + if(evt.dwProcessId == w32_dmn_shared->resume_pid) { - dmn_w32_shared->resume_needed = 0; - dmn_w32_shared->resume_tid = 0; - dmn_w32_shared->resume_pid = 0; + w32_dmn_shared->resume_needed = 0; + w32_dmn_shared->resume_tid = 0; + w32_dmn_shared->resume_pid = 0; } // rjf: generate events for children - for(DMN_W32_Entity *child = process->first; child != &dmn_w32_entity_nil; child = child->next) + for(W32_DMN_Entity *child = process->first; child != &w32_dmn_entity_nil; child = child->next) { switch(child->kind) { default:{}break; - case DMN_W32_EntityKind_Thread: + case W32_DMN_EntityKind_Thread: { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_ExitThread; - e->process = dmn_w32_handle_from_entity(process); - e->thread = dmn_w32_handle_from_entity(child); + e->process = w32_dmn_handle_from_entity(process); + e->thread = w32_dmn_handle_from_entity(child); }break; - case DMN_W32_EntityKind_Module: + case W32_DMN_EntityKind_Module: { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_UnloadModule; - e->process = dmn_w32_handle_from_entity(process); - e->module = dmn_w32_handle_from_entity(child); - e->string = dmn_w32_full_path_from_module(arena, child); + e->process = w32_dmn_handle_from_entity(process); + e->module = w32_dmn_handle_from_entity(child); + e->string = w32_dmn_full_path_from_module(arena, child); }break; } } @@ -1927,12 +1907,12 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_ExitProcess; - e->process = dmn_w32_handle_from_entity(process); + e->process = w32_dmn_handle_from_entity(process); e->code = evt.u.ExitProcess.dwExitCode; } // rjf: release entity storage - dmn_w32_entity_release(process); + w32_dmn_entity_release(process); // rjf: detach DebugActiveProcessStop(evt.dwProcessId); @@ -1943,10 +1923,10 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // case CREATE_THREAD_DEBUG_EVENT: { - DMN_W32_Entity *process = dmn_w32_entity_from_kind_id(DMN_W32_EntityKind_Process, evt.dwProcessId); + W32_DMN_Entity *process = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Process, evt.dwProcessId); // rjf: create thread entity - DMN_W32_Entity *thread = dmn_w32_entity_alloc(process, DMN_W32_EntityKind_Thread, evt.dwThreadId); + W32_DMN_Entity *thread = w32_dmn_entity_alloc(process, W32_DMN_EntityKind_Thread, evt.dwThreadId); { thread->handle = evt.u.CreateThread.hThread; thread->arch = process->arch; @@ -1959,10 +1939,10 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // rjf: unpack thread name String8 thread_name = {0}; - if(dmn_w32_GetThreadDescription != 0) + if(w32_dmn_GetThreadDescription != 0) { WCHAR *thread_name_w = 0; - HRESULT hr = dmn_w32_GetThreadDescription(thread->handle, &thread_name_w); + HRESULT hr = w32_dmn_GetThreadDescription(thread->handle, &thread_name_w); if(SUCCEEDED(hr)) { thread_name = str8_from_16(arena, str16_cstring((U16 *)thread_name_w)); @@ -1971,15 +1951,15 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } // rjf: determine if this is a "halter thread" - the threads we spawn to halt processes - B32 is_halter = (evt.dwThreadId == dmn_w32_shared->halter_tid); + B32 is_halter = (evt.dwThreadId == w32_dmn_shared->halter_tid); // rjf: generate events for non-halter threads if(!is_halter) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_CreateThread; - e->process = dmn_w32_handle_from_entity(process); - e->thread = dmn_w32_handle_from_entity(thread); + e->process = w32_dmn_handle_from_entity(process); + e->thread = w32_dmn_handle_from_entity(thread); e->arch = thread->arch; e->code = evt.dwThreadId; e->string = thread_name; @@ -1991,19 +1971,19 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // case EXIT_THREAD_DEBUG_EVENT: { - DMN_W32_Entity *thread = dmn_w32_entity_from_kind_id(DMN_W32_EntityKind_Thread, evt.dwThreadId); - DMN_W32_Entity *process = thread->parent; + W32_DMN_Entity *thread = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Thread, evt.dwThreadId); + W32_DMN_Entity *process = thread->parent; // rjf: determine if this is the halter thread - B32 is_halter = (evt.dwThreadId == dmn_w32_shared->halter_tid); + B32 is_halter = (evt.dwThreadId == w32_dmn_shared->halter_tid); // rjf: generate a halt event if this thread is the halter if(is_halter) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_Halt; - dmn_w32_shared->halter_process = dmn_handle_zero(); - dmn_w32_shared->halter_tid = 0; + w32_dmn_shared->halter_process = dmn_handle_zero(); + w32_dmn_shared->halter_tid = 0; keep_going = 0; } @@ -2012,13 +1992,13 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_ExitThread; - e->process = dmn_w32_handle_from_entity(process); - e->thread = dmn_w32_handle_from_entity(thread); + e->process = w32_dmn_handle_from_entity(process); + e->thread = w32_dmn_handle_from_entity(thread); e->code = evt.u.ExitThread.dwExitCode; } // rjf: release entity storage - dmn_w32_entity_release(thread); + w32_dmn_entity_release(thread); }break; ////////////////////// @@ -2026,14 +2006,14 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // case LOAD_DLL_DEBUG_EVENT: { - DMN_W32_Entity *process = dmn_w32_entity_from_kind_id(DMN_W32_EntityKind_Process, evt.dwProcessId); + W32_DMN_Entity *process = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Process, evt.dwProcessId); // rjf: extract image info U64 module_base = (U64)evt.u.LoadDll.lpBaseOfDll; - DMN_W32_ImageInfo image_info = dmn_w32_image_info_from_process_base_vaddr(process->handle, module_base); + W32_DMN_ImageInfo image_info = w32_dmn_image_info_from_process_base_vaddr(process->handle, module_base); // rjf: create module entity - DMN_W32_Entity *module = dmn_w32_entity_alloc(process, DMN_W32_EntityKind_Module, module_base); + W32_DMN_Entity *module = w32_dmn_entity_alloc(process, W32_DMN_EntityKind_Module, module_base); { module->handle = evt.u.LoadDll.hFile; module->arch = image_info.arch; @@ -2046,12 +2026,12 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_LoadModule; - e->process = dmn_w32_handle_from_entity(process); - e->module = dmn_w32_handle_from_entity(module); + e->process = w32_dmn_handle_from_entity(process); + e->module = w32_dmn_handle_from_entity(module); e->arch = module->arch; e->address = module_base; e->size = image_info.size; - e->string = dmn_w32_full_path_from_module(arena, module); + e->string = w32_dmn_full_path_from_module(arena, module); e->tls_index = image_info.tls_index; } }break; @@ -2062,20 +2042,20 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) case UNLOAD_DLL_DEBUG_EVENT: { U64 module_base = (U64)evt.u.UnloadDll.lpBaseOfDll; - DMN_W32_Entity *module = dmn_w32_entity_from_kind_id(DMN_W32_EntityKind_Module, module_base); - DMN_W32_Entity *process = module->parent; + W32_DMN_Entity *module = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Module, module_base); + W32_DMN_Entity *process = module->parent; // rjf: generate event { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_UnloadModule; - e->process = dmn_w32_handle_from_entity(process); - e->module = dmn_w32_handle_from_entity(module); - e->string = dmn_w32_full_path_from_module(arena, module); + e->process = w32_dmn_handle_from_entity(process); + e->module = w32_dmn_handle_from_entity(module); + e->string = w32_dmn_full_path_from_module(arena, module); } // rjf: release entity storage - dmn_w32_entity_release(module); + w32_dmn_entity_release(module); }break; ////////////////////// @@ -2125,8 +2105,8 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // 64-bit version. We only currently handle the 64-bit version. //- rjf: unpack - DMN_W32_Entity *thread = dmn_w32_entity_from_kind_id(DMN_W32_EntityKind_Thread, evt.dwThreadId); - DMN_W32_Entity *process = thread->parent; + W32_DMN_Entity *thread = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Thread, evt.dwThreadId); + W32_DMN_Entity *process = thread->parent; EXCEPTION_DEBUG_INFO *edi = &evt.u.Exception; EXCEPTION_RECORD *exception = &edi->ExceptionRecord; U64 instruction_pointer = (U64)exception->ExceptionAddress; @@ -2134,7 +2114,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) //- rjf: determine if this is the first breakpoint in a process // (breakpoint notifying us that the debugger is attached) B32 first_bp = 0; - if(!process->proc.did_first_bp && exception->ExceptionCode == DMN_W32_EXCEPTION_BREAKPOINT) + if(!process->proc.did_first_bp && exception->ExceptionCode == W32_DMN_EXCEPTION_BREAKPOINT) { process->proc.did_first_bp = 1; first_bp = 1; @@ -2142,8 +2122,8 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) //- rjf: determine if this exception is a trap B32 is_trap = (!first_bp && - (exception->ExceptionCode == DMN_W32_EXCEPTION_BREAKPOINT || - exception->ExceptionCode == DMN_W32_EXCEPTION_STACK_BUFFER_OVERRUN)); + (exception->ExceptionCode == W32_DMN_EXCEPTION_BREAKPOINT || + exception->ExceptionCode == W32_DMN_EXCEPTION_STACK_BUFFER_OVERRUN)); //- rjf: check if this trap is a usage-code-specified trap or something else B32 hit_user_trap = 0; @@ -2154,7 +2134,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { for(U64 idx = 0; idx < n->count; idx += 1) { - if(dmn_handle_match(n->v[idx].process, dmn_w32_handle_from_entity(process)) && n->v[idx].vaddr == instruction_pointer) + if(dmn_handle_match(n->v[idx].process, w32_dmn_handle_from_entity(process)) && n->v[idx].vaddr == instruction_pointer) { hit_user_trap = 1; user_trap_id = n->v[idx].id; @@ -2169,7 +2149,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) if(is_trap && !hit_user_trap) { U8 instruction_byte = 0; - if(dmn_w32_process_read_struct(process->handle, instruction_pointer, &instruction_byte)) + if(w32_dmn_process_read_struct(process->handle, instruction_pointer, &instruction_byte)) { hit_explicit_trap = (instruction_byte == 0xCC || instruction_byte == 0xCD); } @@ -2190,10 +2170,10 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) ARCH_Info *arch_info = arch_info_from_arch(thread->arch); U64 regs_block_size = arch_info->reg_block_size; void *regs_block = push_array(scratch.arena, U8, regs_block_size); - if(dmn_w32_thread_read_reg_block(thread->arch, thread->handle, regs_block)) + if(w32_dmn_thread_read_reg_block(thread->arch, thread->handle, regs_block)) { arch_reg_block_write_ip(arch_info, regs_block, instruction_pointer); - dmn_w32_thread_write_reg_block(thread->arch, thread->handle, regs_block); + w32_dmn_thread_write_reg_block(thread->arch, thread->handle, regs_block); } temp_end(temp); }break; @@ -2202,7 +2182,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) case Arch_x64: { CONTEXT *ctx = 0; - U32 ctx_flags = DMN_W32_CTX_X64|DMN_W32_CTX_INTEL_CONTROL; + U32 ctx_flags = W32_DMN_CTX_X64|W32_DMN_CTX_INTEL_CONTROL; DWORD size = 0; InitializeContext(0, ctx_flags, 0, &size); if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) @@ -2241,8 +2221,8 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // rjf: fill top-level info DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_Exception; - e->process = dmn_w32_handle_from_entity(process); - e->thread = dmn_w32_handle_from_entity(thread); + e->process = w32_dmn_handle_from_entity(process); + e->thread = w32_dmn_handle_from_entity(thread); e->code = exception->ExceptionCode; e->flags = exception->ExceptionFlags; e->instruction_pointer = (U64)exception->ExceptionAddress; @@ -2252,7 +2232,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) switch(exception->ExceptionCode) { //- rjf: fill breakpoint event info - case DMN_W32_EXCEPTION_BREAKPOINT: + case W32_DMN_EXCEPTION_BREAKPOINT: { DMN_EventKind report_event_kind = DMN_EventKind_Trap; if(first_bp) @@ -2267,10 +2247,10 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) }break; //- rjf: fill stack buffer overrun event info - case DMN_W32_EXCEPTION_STACK_BUFFER_OVERRUN: + case W32_DMN_EXCEPTION_STACK_BUFFER_OVERRUN: { e->kind = DMN_EventKind_Trap; - if(exception->ExceptionInformation[0] == DMN_W32_FAST_FAIL_CONTROL_INVALID_RETURN_ADDRESS) + if(exception->ExceptionInformation[0] == W32_DMN_FAST_FAIL_CONTROL_INVALID_RETURN_ADDRESS) { // TODO(rjf): this is a shadow stack violation - this can imply that the spoof was hit. // need to handle this correctly in the ctrl layer when stepping w/ a spoof set. @@ -2280,7 +2260,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) }break; //- rjf: fill single-step event info - case DMN_W32_EXCEPTION_SINGLE_STEP: + case W32_DMN_EXCEPTION_SINGLE_STEP: { e->kind = DMN_EventKind_SingleStep; @@ -2298,7 +2278,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) case Arch_x64: { X64_RegBlock regs = {0}; - dmn_w32_thread_read_reg_block(thread->arch, thread->handle, ®s); + w32_dmn_thread_read_reg_block(thread->arch, thread->handle, ®s); if(regs.dr6 & 0xF) { e->kind = DMN_EventKind_Breakpoint; @@ -2312,11 +2292,11 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) } // rjf: find the flagged trap task for this thread's process - DMN_W32_Entity *process = thread->parent; + W32_DMN_Entity *process = thread->parent; DMN_FlaggedTrapTask *task = 0; for(DMN_FlaggedTrapTask *t = first_flagged_trap_task; t != 0; t = t->next) { - if(dmn_handle_match(t->process, dmn_w32_handle_from_entity(process))) + if(dmn_handle_match(t->process, w32_dmn_handle_from_entity(process))) { task = t; break; @@ -2351,7 +2331,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) }break; //- rjf: fill throw info - case DMN_W32_EXCEPTION_THROW: + case W32_DMN_EXCEPTION_THROW: { U64 exception_sp = 0; U64 exception_ip = 0; @@ -2363,12 +2343,12 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) e->stack_pointer = exception_sp; e->exception_kind = DMN_ExceptionKind_CppThrow; e->exception_repeated = (edi->dwFirstChance == 0); - dmn_w32_shared->exception_not_handled = (edi->dwFirstChance != 0); + w32_dmn_shared->exception_not_handled = (edi->dwFirstChance != 0); }break; //- rjf: fill access violation info - case DMN_W32_EXCEPTION_ACCESS_VIOLATION: - case DMN_W32_EXCEPTION_IN_PAGE_ERROR: + case W32_DMN_EXCEPTION_ACCESS_VIOLATION: + case W32_DMN_EXCEPTION_IN_PAGE_ERROR: { U64 exception_address = 0; DMN_ExceptionKind exception_kind = DMN_ExceptionKind_Null; @@ -2385,15 +2365,15 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) e->address = exception_address; e->exception_kind = exception_kind; e->exception_repeated = (edi->dwFirstChance == 0); - dmn_w32_shared->exception_not_handled = (edi->dwFirstChance != 0); + w32_dmn_shared->exception_not_handled = (edi->dwFirstChance != 0); }break; //- rjf: fill set-thread-name info - case DMN_W32_EXCEPTION_SET_THREAD_NAME: + case W32_DMN_EXCEPTION_SET_THREAD_NAME: if(exception->NumberParameters >= 2) { U64 thread_name_address = exception->ExceptionInformation[1]; - DMN_W32_Entity *process = dmn_w32_entity_from_kind_id(DMN_W32_EntityKind_Process, evt.dwProcessId); + W32_DMN_Entity *process = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Process, evt.dwProcessId); String8List thread_name_strings = {0}; { U64 read_addr = thread_name_address; @@ -2401,7 +2381,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) for(;total_string_size < KB(4);) { U8 *buffer = push_array(scratch.arena, U8, 256); - B32 good_read = dmn_w32_process_read(process->handle, r1u64(read_addr, read_addr+256), buffer); + B32 good_read = w32_dmn_process_read(process->handle, r1u64(read_addr, read_addr+256), buffer); if(good_read) { U64 size = 256; @@ -2437,7 +2417,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) }break; //- rjf: fill set-thread-color info - case DMN_W32_EXCEPTION_RADDBG_SET_THREAD_COLOR: + case W32_DMN_EXCEPTION_RADDBG_SET_THREAD_COLOR: { e->kind = DMN_EventKind_SetThreadColor; e->code = exception->ExceptionInformation[0]; @@ -2445,7 +2425,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) }break; //- rjf: fill set-data-breakpoint info - case DMN_W32_EXCEPTION_RADDBG_SET_BREAKPOINT: + case W32_DMN_EXCEPTION_RADDBG_SET_BREAKPOINT: { U64 vaddr = exception->ExceptionInformation[0]; U64 size = exception->ExceptionInformation[1]; @@ -2462,14 +2442,14 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) }break; //- rjf: fill set-vaddr-range-note info - case DMN_W32_EXCEPTION_RADDBG_SET_VADDR_RANGE_NOTE: + case W32_DMN_EXCEPTION_RADDBG_SET_VADDR_RANGE_NOTE: { U64 vaddr = exception->ExceptionInformation[0]; U64 size = exception->ExceptionInformation[1]; U64 name_vaddr = exception->ExceptionInformation[2]; U64 name_size = exception->ExceptionInformation[3]; U8 *name_buffer = push_array(arena, U8, name_size); - dmn_w32_process_read(process->handle, r1u64(name_vaddr, name_vaddr+name_size), name_buffer), + w32_dmn_process_read(process->handle, r1u64(name_vaddr, name_vaddr+name_size), name_buffer), e->kind = DMN_EventKind_SetVAddrRangeNote; e->address = vaddr; e->size = size; @@ -2480,7 +2460,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) default: { e->exception_repeated = (edi->dwFirstChance == 0); - dmn_w32_shared->exception_not_handled = (edi->dwFirstChance != 0); + w32_dmn_shared->exception_not_handled = (edi->dwFirstChance != 0); }break; } } @@ -2492,14 +2472,14 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) case OUTPUT_DEBUG_STRING_EVENT: { // rjf: unpack event - DMN_W32_Entity *process = dmn_w32_entity_from_kind_id(DMN_W32_EntityKind_Process, evt.dwProcessId); - DMN_W32_Entity *thread = dmn_w32_entity_from_kind_id(DMN_W32_EntityKind_Thread, evt.dwThreadId); + W32_DMN_Entity *process = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Process, evt.dwProcessId); + W32_DMN_Entity *thread = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Thread, evt.dwThreadId); U64 string_address = (U64)evt.u.DebugString.lpDebugStringData; U64 string_size = (U64)evt.u.DebugString.nDebugStringLength; // rjf: read memory U8 *buffer = push_array_no_zero(scratch.arena, U8, string_size + 1); - dmn_w32_process_read(process->handle, r1u64(string_address, string_address+string_size), buffer); + w32_dmn_process_read(process->handle, r1u64(string_address, string_address+string_size), buffer); buffer[string_size] = 0; // rjf: extract into string @@ -2529,12 +2509,12 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // case RIP_EVENT: { - DMN_W32_Entity *process = dmn_w32_entity_from_kind_id(DMN_W32_EntityKind_Process, evt.dwProcessId); - DMN_W32_Entity *thread = dmn_w32_entity_from_kind_id(DMN_W32_EntityKind_Thread, evt.dwThreadId); + W32_DMN_Entity *process = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Process, evt.dwProcessId); + W32_DMN_Entity *thread = w32_dmn_entity_from_kind_id(W32_DMN_EntityKind_Thread, evt.dwThreadId); DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_Exception; - e->process = dmn_w32_handle_from_entity(process); - e->thread = dmn_w32_handle_from_entity(thread); + e->process = w32_dmn_handle_from_entity(process); + e->thread = w32_dmn_handle_from_entity(thread); }break; ////////////////////// @@ -2570,10 +2550,10 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // ProfScope("suspend threads which ran") { - for(DMN_W32_EntityNode *n = first_ran_thread; n != 0; n = n->next) + for(W32_DMN_EntityNode *n = first_ran_thread; n != 0; n = n->next) { - DMN_W32_Entity *thread = n->v; - if(thread->kind != DMN_W32_EntityKind_Thread) + W32_DMN_Entity *thread = n->v; + if(thread->kind != W32_DMN_EntityKind_Thread) { continue; } @@ -2608,38 +2588,38 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) //////////////////////// //- rjf: gather new thread-names // - ProfScope("gather new thread names") if(dmn_w32_GetThreadDescription != 0) + ProfScope("gather new thread names") if(w32_dmn_GetThreadDescription != 0) { - for(DMN_W32_Entity *process = dmn_w32_shared->entities_base->first; - process != &dmn_w32_entity_nil; + for(W32_DMN_Entity *process = w32_dmn_shared->entities_base->first; + process != &w32_dmn_entity_nil; process = process->next) { - if(process->kind != DMN_W32_EntityKind_Process) { continue; } - for(DMN_W32_Entity *thread = process->first; - thread != &dmn_w32_entity_nil; + if(process->kind != W32_DMN_EntityKind_Process) { continue; } + for(W32_DMN_Entity *thread = process->first; + thread != &w32_dmn_entity_nil; thread = thread->next) { - if(thread->kind != DMN_W32_EntityKind_Thread) { continue; } + if(thread->kind != W32_DMN_EntityKind_Thread) { continue; } if(thread->thread.last_name_hash == 0 || thread->thread.name_gather_time_us+1000000 <= now_time_us()) { String8 name = {0}; { WCHAR *thread_name_w = 0; - HRESULT hr = dmn_w32_GetThreadDescription(thread->handle, &thread_name_w); + HRESULT hr = w32_dmn_GetThreadDescription(thread->handle, &thread_name_w); if(SUCCEEDED(hr)) { name = str8_from_16(scratch.arena, str16_cstring((U16 *)thread_name_w)); LocalFree(thread_name_w); } } - U64 name_hash = dmn_w32_hash_from_string(name); + U64 name_hash = u64_hash_from_str8(name); if(name.size != 0 && name_hash != thread->thread.last_name_hash) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_SetThreadName; - e->process = dmn_w32_handle_from_entity(process); - e->thread = dmn_w32_handle_from_entity(thread); + e->process = w32_dmn_handle_from_entity(process); + e->thread = w32_dmn_handle_from_entity(thread); e->string = push_str8_copy(arena, name); } thread->thread.name_gather_time_us = now_time_us(); @@ -2680,12 +2660,12 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) for(DMN_FlaggedTrapTask *t = first_flagged_trap_task; t != 0; t = t->next) { DMN_Handle process = t->process; - DMN_W32_Entity *process_entity = dmn_w32_entity_from_handle(process); - for(DMN_W32_Entity *child = process_entity->first; - child != &dmn_w32_entity_nil; + W32_DMN_Entity *process_entity = w32_dmn_entity_from_handle(process); + for(W32_DMN_Entity *child = process_entity->first; + child != &w32_dmn_entity_nil; child = child->next) { - if(child->kind == DMN_W32_EntityKind_Thread) + if(child->kind == W32_DMN_EntityKind_Thread) { switch(child->arch) { @@ -2695,9 +2675,9 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) case Arch_x64: { X64_RegBlock regs = {0}; - dmn_w32_thread_read_reg_block(child->arch, child->handle, ®s); + w32_dmn_thread_read_reg_block(child->arch, child->handle, ®s); regs.dr7 = 0; - dmn_w32_thread_write_reg_block(child->arch, child->handle, ®s); + w32_dmn_thread_write_reg_block(child->arch, child->handle, ®s); }break; } } @@ -2710,7 +2690,7 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) // if(!dmn_handle_match(ctrls->single_step_thread, dmn_handle_zero())) ProfScope("unset single step bit") { - DMN_W32_Entity *thread = dmn_w32_entity_from_handle(ctrls->single_step_thread); + W32_DMN_Entity *thread = w32_dmn_entity_from_handle(ctrls->single_step_thread); Arch arch = thread->arch; switch(arch) { @@ -2746,34 +2726,34 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) //////////////////////////// //- rjf: produce debug events from queued up detached processes // - case DMN_W32_EventGenPath_DetachProcesses: + case W32_DMN_EventGenPath_DetachProcesses: { - for(DMN_HandleNode *n = dmn_w32_shared->detach_processes.first; n != 0; n = n->next) + for(DMN_HandleNode *n = w32_dmn_shared->detach_processes.first; n != 0; n = n->next) { - DMN_W32_Entity *process = dmn_w32_entity_from_handle(n->v); + W32_DMN_Entity *process = w32_dmn_entity_from_handle(n->v); // rjf: push exit thread events - for(DMN_W32_Entity *child = process->first; child != &dmn_w32_entity_nil; child = child->next) + for(W32_DMN_Entity *child = process->first; child != &w32_dmn_entity_nil; child = child->next) { - if(child->kind == DMN_W32_EntityKind_Thread) + if(child->kind == W32_DMN_EntityKind_Thread) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_ExitThread; - e->process = dmn_w32_handle_from_entity(process); - e->thread = dmn_w32_handle_from_entity(child); + e->process = w32_dmn_handle_from_entity(process); + e->thread = w32_dmn_handle_from_entity(child); } } // rjf: push unload module events - for(DMN_W32_Entity *child = process->first; child != &dmn_w32_entity_nil; child = child->next) + for(W32_DMN_Entity *child = process->first; child != &w32_dmn_entity_nil; child = child->next) { - if(child->kind == DMN_W32_EntityKind_Module) + if(child->kind == W32_DMN_EntityKind_Module) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_UnloadModule; - e->process = dmn_w32_handle_from_entity(process); - e->module = dmn_w32_handle_from_entity(child); - e->string = dmn_w32_full_path_from_module(arena, child); + e->process = w32_dmn_handle_from_entity(process); + e->module = w32_dmn_handle_from_entity(child); + e->string = w32_dmn_full_path_from_module(arena, child); } } @@ -2781,16 +2761,16 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) { DMN_Event *e = dmn_event_list_push(arena, &events); e->kind = DMN_EventKind_ExitProcess; - e->process = dmn_w32_handle_from_entity(process); + e->process = w32_dmn_handle_from_entity(process); } // rjf: free process - dmn_w32_entity_release(process); + w32_dmn_entity_release(process); } // rjf: reset queued up detached processes - MemoryZeroStruct(&dmn_w32_shared->detach_processes); - arena_clear(dmn_w32_shared->detach_arena); + MemoryZeroStruct(&w32_dmn_shared->detach_processes); + arena_clear(w32_dmn_shared->detach_arena); }break; } @@ -2804,26 +2784,26 @@ dmn_ctrl_run(Arena *arena, DMN_CtrlCtx *ctx, DMN_RunCtrls *ctrls) internal void dmn_halt(U64 code, U64 user_data) { - if(dmn_handle_match(dmn_handle_zero(), dmn_w32_shared->halter_process)) + if(dmn_handle_match(dmn_handle_zero(), w32_dmn_shared->halter_process)) { - DMN_W32_Entity *process = &dmn_w32_entity_nil; - for(DMN_W32_Entity *entity = dmn_w32_shared->entities_base->first; - entity != &dmn_w32_entity_nil; + W32_DMN_Entity *process = &w32_dmn_entity_nil; + for(W32_DMN_Entity *entity = w32_dmn_shared->entities_base->first; + entity != &w32_dmn_entity_nil; entity = entity->next) { - if(entity->kind == DMN_W32_EntityKind_Process) + if(entity->kind == W32_DMN_EntityKind_Process) { process = entity; break; } } - if(process != &dmn_w32_entity_nil) + if(process != &w32_dmn_entity_nil) { - dmn_w32_shared->halter_process = dmn_w32_handle_from_entity(process); - DMN_W32_InjectedBreak injection = {code, user_data}; - U64 data_injection_address = process->proc.injection_address + DMN_W32_INJECTED_CODE_SIZE; - dmn_w32_process_write_struct(process->handle, data_injection_address, &injection); - dmn_w32_shared->halter_tid = dmn_w32_inject_thread(process->handle, process->proc.injection_address); + w32_dmn_shared->halter_process = w32_dmn_handle_from_entity(process); + W32_DMN_InjectedBreak injection = {code, user_data}; + U64 data_injection_address = process->proc.injection_address + W32_DMN_INJECTED_CODE_SIZE; + w32_dmn_process_write_struct(process->handle, data_injection_address, &injection); + w32_dmn_shared->halter_tid = w32_dmn_inject_thread(process->handle, process->proc.injection_address); } } } @@ -2837,14 +2817,14 @@ internal B32 dmn_access_open(void) { B32 result = 0; - if(dmn_w32_ctrl_thread) + if(w32_dmn_ctrl_thread) { result = 1; } else { - mutex_take(dmn_w32_shared->access_mutex); - result = !dmn_w32_shared->access_run_state; + mutex_take(w32_dmn_shared->access_mutex); + result = !w32_dmn_shared->access_run_state; } return result; } @@ -2852,9 +2832,9 @@ dmn_access_open(void) internal void dmn_access_close(void) { - if(!dmn_w32_ctrl_thread) + if(!w32_dmn_ctrl_thread) { - mutex_drop(dmn_w32_shared->access_mutex); + mutex_drop(w32_dmn_shared->access_mutex); } } @@ -2866,7 +2846,7 @@ dmn_process_memory_reserve(DMN_Handle process, U64 vaddr, U64 size) U64 result = 0; DMN_AccessScope { - DMN_W32_Entity *process_entity = dmn_w32_entity_from_handle(process); + W32_DMN_Entity *process_entity = w32_dmn_entity_from_handle(process); result = (U64)VirtualAllocEx(process_entity->handle, (void *)vaddr, size, MEM_RESERVE, PAGE_READWRITE); if(result == 0) { @@ -2881,7 +2861,7 @@ dmn_process_memory_commit(DMN_Handle process, U64 vaddr, U64 size) { DMN_AccessScope { - DMN_W32_Entity *process_entity = dmn_w32_entity_from_handle(process); + W32_DMN_Entity *process_entity = w32_dmn_entity_from_handle(process); (U64)VirtualAllocEx(process_entity->handle, (void *)vaddr, size, MEM_COMMIT, PAGE_READWRITE); } } @@ -2891,7 +2871,7 @@ dmn_process_memory_decommit(DMN_Handle process, U64 vaddr, U64 size) { DMN_AccessScope { - DMN_W32_Entity *process_entity = dmn_w32_entity_from_handle(process); + W32_DMN_Entity *process_entity = w32_dmn_entity_from_handle(process); VirtualFreeEx(process_entity->handle, (void *)vaddr, size, MEM_DECOMMIT); } } @@ -2901,7 +2881,7 @@ dmn_process_memory_release(DMN_Handle process, U64 vaddr, U64 size) { DMN_AccessScope { - DMN_W32_Entity *process_entity = dmn_w32_entity_from_handle(process); + W32_DMN_Entity *process_entity = w32_dmn_entity_from_handle(process); VirtualFreeEx(process_entity->handle, (void *)vaddr, 0, MEM_RELEASE); } } @@ -2911,7 +2891,7 @@ dmn_process_memory_protect(DMN_Handle process, U64 vaddr, U64 size, AccessFlags { DMN_AccessScope { - DMN_W32_Entity *process_entity = dmn_w32_entity_from_handle(process); + W32_DMN_Entity *process_entity = w32_dmn_entity_from_handle(process); DWORD old_flags = 0; DWORD new_flags = PAGE_NOACCESS; switch(flags) @@ -2933,8 +2913,8 @@ dmn_process_read(DMN_Handle process, Rng1U64 range, void *dst) U64 result = 0; DMN_AccessScope { - DMN_W32_Entity *entity = dmn_w32_entity_from_handle(process); - result = dmn_w32_process_read(entity->handle, range, dst); + W32_DMN_Entity *entity = w32_dmn_entity_from_handle(process); + result = w32_dmn_process_read(entity->handle, range, dst); } return result; } @@ -2945,8 +2925,8 @@ dmn_process_write(DMN_Handle process, Rng1U64 range, void *src) B32 result = 0; DMN_AccessScope { - DMN_W32_Entity *entity = dmn_w32_entity_from_handle(process); - result = dmn_w32_process_write(entity->handle, range, src); + W32_DMN_Entity *entity = w32_dmn_entity_from_handle(process); + result = w32_dmn_process_write(entity->handle, range, src); } return result; } @@ -2959,7 +2939,7 @@ dmn_arch_from_thread(DMN_Handle handle) Arch arch = Arch_Null; DMN_AccessScope { - DMN_W32_Entity *entity = dmn_w32_entity_from_handle(handle); + W32_DMN_Entity *entity = w32_dmn_entity_from_handle(handle); arch = entity->arch; } return arch; @@ -2971,10 +2951,10 @@ dmn_stack_base_vaddr_from_thread(DMN_Handle handle) U64 result = 0; DMN_AccessScope { - DMN_W32_Entity *thread = dmn_w32_entity_from_handle(handle); - if(thread->kind == DMN_W32_EntityKind_Thread) + W32_DMN_Entity *thread = w32_dmn_entity_from_handle(handle); + if(thread->kind == W32_DMN_EntityKind_Thread) { - DMN_W32_Entity *process = thread->parent; + W32_DMN_Entity *process = thread->parent; U64 tlb = thread->thread.thread_local_base; switch(thread->arch) { @@ -2988,7 +2968,7 @@ dmn_stack_base_vaddr_from_thread(DMN_Handle handle) case Arch_x64: { U64 stack_base_addr = tlb + 0x8; - dmn_w32_process_read(process->handle, r1u64(stack_base_addr, stack_base_addr+8), &result); + w32_dmn_process_read(process->handle, r1u64(stack_base_addr, stack_base_addr+8), &result); }break; } } @@ -3002,8 +2982,8 @@ dmn_tls_root_vaddr_from_thread(DMN_Handle handle) U64 result = 0; DMN_AccessScope { - DMN_W32_Entity *entity = dmn_w32_entity_from_handle(handle); - if(entity->kind == DMN_W32_EntityKind_Thread) + W32_DMN_Entity *entity = w32_dmn_entity_from_handle(handle); + if(entity->kind == W32_DMN_EntityKind_Thread) { result = entity->thread.thread_local_base; switch(entity->arch) @@ -3031,8 +3011,8 @@ dmn_thread_read_reg_block(DMN_Handle handle, void *reg_block) B32 result = 0; DMN_AccessScope { - DMN_W32_Entity *thread = dmn_w32_entity_from_handle(handle); - result = dmn_w32_thread_read_reg_block(thread->arch, thread->handle, reg_block); + W32_DMN_Entity *thread = w32_dmn_entity_from_handle(handle); + result = w32_dmn_thread_read_reg_block(thread->arch, thread->handle, reg_block); } return result; } @@ -3043,8 +3023,8 @@ dmn_thread_write_reg_block(DMN_Handle handle, void *reg_block) B32 result = 0; DMN_AccessScope { - DMN_W32_Entity *thread = dmn_w32_entity_from_handle(handle); - result = dmn_w32_thread_write_reg_block(thread->arch, thread->handle, reg_block); + W32_DMN_Entity *thread = w32_dmn_entity_from_handle(handle); + result = w32_dmn_thread_write_reg_block(thread->arch, thread->handle, reg_block); } return result; } diff --git a/src/win32/demon/win32_demon.h b/src/win32/demon/win32_demon.h index 58e7dbc7..3bf51ff5 100644 --- a/src/win32/demon/win32_demon.h +++ b/src/win32/demon/win32_demon.h @@ -1,8 +1,8 @@ // Copyright (c) Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -#ifndef DEMON_CORE_WIN32_H -#define DEMON_CORE_WIN32_H +#ifndef WIN32_DEMON_H +#define WIN32_DEMON_H //////////////////////////////// //~ rjf: Windows Includes @@ -15,173 +15,173 @@ //////////////////////////////// //~ rjf: Win32 Exception Codes -#define DMN_W32_EXCEPTION_BREAKPOINT 0x80000003u -#define DMN_W32_EXCEPTION_SINGLE_STEP 0x80000004u -#define DMN_W32_EXCEPTION_LONG_JUMP 0x80000026u -#define DMN_W32_EXCEPTION_ACCESS_VIOLATION 0xC0000005u -#define DMN_W32_EXCEPTION_ARRAY_BOUNDS_EXCEEDED 0xC000008Cu -#define DMN_W32_EXCEPTION_DATA_TYPE_MISALIGNMENT 0x80000002u -#define DMN_W32_EXCEPTION_GUARD_PAGE_VIOLATION 0x80000001u -#define DMN_W32_EXCEPTION_FLT_DENORMAL_OPERAND 0xC000008Du -#define DMN_W32_EXCEPTION_FLT_DEVIDE_BY_ZERO 0xC000008Eu -#define DMN_W32_EXCEPTION_FLT_INEXACT_RESULT 0xC000008Fu -#define DMN_W32_EXCEPTION_FLT_INVALID_OPERATION 0xC0000090u -#define DMN_W32_EXCEPTION_FLT_OVERFLOW 0xC0000091u -#define DMN_W32_EXCEPTION_FLT_STACK_CHECK 0xC0000092u -#define DMN_W32_EXCEPTION_FLT_UNDERFLOW 0xC0000093u -#define DMN_W32_EXCEPTION_INT_DIVIDE_BY_ZERO 0xC0000094u -#define DMN_W32_EXCEPTION_INT_OVERFLOW 0xC0000095u -#define DMN_W32_EXCEPTION_PRIVILEGED_INSTRUCTION 0xC0000096u -#define DMN_W32_EXCEPTION_ILLEGAL_INSTRUCTION 0xC000001Du -#define DMN_W32_EXCEPTION_IN_PAGE_ERROR 0xC0000006u -#define DMN_W32_EXCEPTION_INVALID_DISPOSITION 0xC0000026u -#define DMN_W32_EXCEPTION_NONCONTINUABLE 0xC0000025u -#define DMN_W32_EXCEPTION_STACK_OVERFLOW 0xC00000FDu -#define DMN_W32_EXCEPTION_INVALID_HANDLE 0xC0000008u -#define DMN_W32_EXCEPTION_UNWIND_CONSOLIDATE 0x80000029u -#define DMN_W32_EXCEPTION_DLL_NOT_FOUND 0xC0000135u -#define DMN_W32_EXCEPTION_ORDINAL_NOT_FOUND 0xC0000138u -#define DMN_W32_EXCEPTION_ENTRY_POINT_NOT_FOUND 0xC0000139u -#define DMN_W32_EXCEPTION_DLL_INIT_FAILED 0xC0000142u -#define DMN_W32_EXCEPTION_CONTROL_C_EXIT 0xC000013Au -#define DMN_W32_EXCEPTION_FLT_MULTIPLE_FAULTS 0xC00002B4u -#define DMN_W32_EXCEPTION_FLT_MULTIPLE_TRAPS 0xC00002B5u -#define DMN_W32_EXCEPTION_NAT_CONSUMPTION 0xC00002C9u -#define DMN_W32_EXCEPTION_HEAP_CORRUPTION 0xC0000374u -#define DMN_W32_EXCEPTION_STACK_BUFFER_OVERRUN 0xC0000409u -#define DMN_W32_EXCEPTION_INVALID_CRUNTIME_PARAM 0xC0000417u -#define DMN_W32_EXCEPTION_ASSERT_FAILURE 0xC0000420u -#define DMN_W32_EXCEPTION_NO_MEMORY 0xC0000017u -#define DMN_W32_EXCEPTION_THROW 0xE06D7363u -#define DMN_W32_EXCEPTION_SET_THREAD_NAME 0x406d1388u +#define W32_DMN_EXCEPTION_BREAKPOINT 0x80000003u +#define W32_DMN_EXCEPTION_SINGLE_STEP 0x80000004u +#define W32_DMN_EXCEPTION_LONG_JUMP 0x80000026u +#define W32_DMN_EXCEPTION_ACCESS_VIOLATION 0xC0000005u +#define W32_DMN_EXCEPTION_ARRAY_BOUNDS_EXCEEDED 0xC000008Cu +#define W32_DMN_EXCEPTION_DATA_TYPE_MISALIGNMENT 0x80000002u +#define W32_DMN_EXCEPTION_GUARD_PAGE_VIOLATION 0x80000001u +#define W32_DMN_EXCEPTION_FLT_DENORMAL_OPERAND 0xC000008Du +#define W32_DMN_EXCEPTION_FLT_DEVIDE_BY_ZERO 0xC000008Eu +#define W32_DMN_EXCEPTION_FLT_INEXACT_RESULT 0xC000008Fu +#define W32_DMN_EXCEPTION_FLT_INVALID_OPERATION 0xC0000090u +#define W32_DMN_EXCEPTION_FLT_OVERFLOW 0xC0000091u +#define W32_DMN_EXCEPTION_FLT_STACK_CHECK 0xC0000092u +#define W32_DMN_EXCEPTION_FLT_UNDERFLOW 0xC0000093u +#define W32_DMN_EXCEPTION_INT_DIVIDE_BY_ZERO 0xC0000094u +#define W32_DMN_EXCEPTION_INT_OVERFLOW 0xC0000095u +#define W32_DMN_EXCEPTION_PRIVILEGED_INSTRUCTION 0xC0000096u +#define W32_DMN_EXCEPTION_ILLEGAL_INSTRUCTION 0xC000001Du +#define W32_DMN_EXCEPTION_IN_PAGE_ERROR 0xC0000006u +#define W32_DMN_EXCEPTION_INVALID_DISPOSITION 0xC0000026u +#define W32_DMN_EXCEPTION_NONCONTINUABLE 0xC0000025u +#define W32_DMN_EXCEPTION_STACK_OVERFLOW 0xC00000FDu +#define W32_DMN_EXCEPTION_INVALID_HANDLE 0xC0000008u +#define W32_DMN_EXCEPTION_UNWIND_CONSOLIDATE 0x80000029u +#define W32_DMN_EXCEPTION_DLL_NOT_FOUND 0xC0000135u +#define W32_DMN_EXCEPTION_ORDINAL_NOT_FOUND 0xC0000138u +#define W32_DMN_EXCEPTION_ENTRY_POINT_NOT_FOUND 0xC0000139u +#define W32_DMN_EXCEPTION_DLL_INIT_FAILED 0xC0000142u +#define W32_DMN_EXCEPTION_CONTROL_C_EXIT 0xC000013Au +#define W32_DMN_EXCEPTION_FLT_MULTIPLE_FAULTS 0xC00002B4u +#define W32_DMN_EXCEPTION_FLT_MULTIPLE_TRAPS 0xC00002B5u +#define W32_DMN_EXCEPTION_NAT_CONSUMPTION 0xC00002C9u +#define W32_DMN_EXCEPTION_HEAP_CORRUPTION 0xC0000374u +#define W32_DMN_EXCEPTION_STACK_BUFFER_OVERRUN 0xC0000409u +#define W32_DMN_EXCEPTION_INVALID_CRUNTIME_PARAM 0xC0000417u +#define W32_DMN_EXCEPTION_ASSERT_FAILURE 0xC0000420u +#define W32_DMN_EXCEPTION_NO_MEMORY 0xC0000017u +#define W32_DMN_EXCEPTION_THROW 0xE06D7363u +#define W32_DMN_EXCEPTION_SET_THREAD_NAME 0x406d1388u #define DMN_w32_EXCEPTION_CLRDBG_NOTIFICATION 0x04242420u #define DMN_w32_EXCEPTION_CLR 0xE0434352u -#define DMN_W32_EXCEPTION_RADDBG_SET_THREAD_COLOR 0x00524144u -#define DMN_W32_EXCEPTION_RADDBG_SET_BREAKPOINT 0x00524145u -#define DMN_W32_EXCEPTION_RADDBG_SET_VADDR_RANGE_NOTE 0x00524156u +#define W32_DMN_EXCEPTION_RADDBG_SET_THREAD_COLOR 0x00524144u +#define W32_DMN_EXCEPTION_RADDBG_SET_BREAKPOINT 0x00524145u +#define W32_DMN_EXCEPTION_RADDBG_SET_VADDR_RANGE_NOTE 0x00524156u //////////////////////////////// //~ rjf: Win32 Exception ExceptionInformation Codes // -// used as a subcode, apparently in all cases, for DMN_W32_EXCEPTION_STACK_BUFFER_OVERRUN. +// used as a subcode, apparently in all cases, for W32_DMN_EXCEPTION_STACK_BUFFER_OVERRUN. // need to somehow pipe this through & interpret it correctly in outer layers... @fastfail -#define DMN_W32_FAST_FAIL_LEGACY_GS_VIOLATION 0 -#define DMN_W32_FAST_FAIL_VTGUARD_CHECK_FAILURE 1 -#define DMN_W32_FAST_FAIL_STACK_COOKIE_CHECK_FAILURE 2 -#define DMN_W32_FAST_FAIL_CORRUPT_LIST_ENTRY 3 -#define DMN_W32_FAST_FAIL_INCORRECT_STACK 4 -#define DMN_W32_FAST_FAIL_INVALID_ARG 5 -#define DMN_W32_FAST_FAIL_GS_COOKIE_INIT 6 -#define DMN_W32_FAST_FAIL_FATAL_APP_EXIT 7 -#define DMN_W32_FAST_FAIL_RANGE_CHECK_FAILURE 8 -#define DMN_W32_FAST_FAIL_UNSAFE_REGISTRY_ACCESS 9 -#define DMN_W32_FAST_FAIL_GUARD_ICALL_CHECK_FAILURE 10 -#define DMN_W32_FAST_FAIL_GUARD_WRITE_CHECK_FAILURE 11 -#define DMN_W32_FAST_FAIL_INVALID_FIBER_SWITCH 12 -#define DMN_W32_FAST_FAIL_INVALID_SET_OF_CONTEXT 13 -#define DMN_W32_FAST_FAIL_INVALID_REFERENCE_COUNT 14 -#define DMN_W32_FAST_FAIL_INVALID_JUMP_BUFFER 18 -#define DMN_W32_FAST_FAIL_MRDATA_MODIFIED 19 -#define DMN_W32_FAST_FAIL_CERTIFICATION_FAILURE 20 -#define DMN_W32_FAST_FAIL_INVALID_EXCEPTION_CHAIN 21 -#define DMN_W32_FAST_FAIL_CRYPTO_LIBRARY 22 -#define DMN_W32_FAST_FAIL_INVALID_CALL_IN_DLL_CALLOUT 23 -#define DMN_W32_FAST_FAIL_INVALID_IMAGE_BASE 24 -#define DMN_W32_FAST_FAIL_DLOAD_PROTECTION_FAILURE 25 -#define DMN_W32_FAST_FAIL_UNSAFE_EXTENSION_CALL 26 -#define DMN_W32_FAST_FAIL_DEPRECATED_SERVICE_INVOKED 27 -#define DMN_W32_FAST_FAIL_INVALID_BUFFER_ACCESS 28 -#define DMN_W32_FAST_FAIL_INVALID_BALANCED_TREE 29 -#define DMN_W32_FAST_FAIL_INVALID_NEXT_THREAD 30 -#define DMN_W32_FAST_FAIL_GUARD_ICALL_CHECK_SUPPRESSED 31 // Telemetry, nonfatal -#define DMN_W32_FAST_FAIL_APCS_DISABLED 32 -#define DMN_W32_FAST_FAIL_INVALID_IDLE_STATE 33 -#define DMN_W32_FAST_FAIL_MRDATA_PROTECTION_FAILURE 34 -#define DMN_W32_FAST_FAIL_UNEXPECTED_HEAP_EXCEPTION 35 -#define DMN_W32_FAST_FAIL_INVALID_LOCK_STATE 36 -#define DMN_W32_FAST_FAIL_GUARD_JUMPTABLE 37 // Known to compiler, must retain value 37 -#define DMN_W32_FAST_FAIL_INVALID_LONGJUMP_TARGET 38 -#define DMN_W32_FAST_FAIL_INVALID_DISPATCH_CONTEXT 39 -#define DMN_W32_FAST_FAIL_INVALID_THREAD 40 -#define DMN_W32_FAST_FAIL_INVALID_SYSCALL_NUMBER 41 // Telemetry, nonfatal -#define DMN_W32_FAST_FAIL_INVALID_FILE_OPERATION 42 // Telemetry, nonfatal -#define DMN_W32_FAST_FAIL_LPAC_ACCESS_DENIED 43 // Telemetry, nonfatal -#define DMN_W32_FAST_FAIL_GUARD_SS_FAILURE 44 -#define DMN_W32_FAST_FAIL_LOADER_CONTINUITY_FAILURE 45 // Telemetry, nonfatal -#define DMN_W32_FAST_FAIL_GUARD_EXPORT_SUPPRESSION_FAILURE 46 -#define DMN_W32_FAST_FAIL_INVALID_CONTROL_STACK 47 -#define DMN_W32_FAST_FAIL_SET_CONTEXT_DENIED 48 -#define DMN_W32_FAST_FAIL_INVALID_IAT 49 -#define DMN_W32_FAST_FAIL_HEAP_METADATA_CORRUPTION 50 -#define DMN_W32_FAST_FAIL_PAYLOAD_RESTRICTION_VIOLATION 51 -#define DMN_W32_FAST_FAIL_LOW_LABEL_ACCESS_DENIED 52 // Telemetry, nonfatal -#define DMN_W32_FAST_FAIL_ENCLAVE_CALL_FAILURE 53 -#define DMN_W32_FAST_FAIL_UNHANDLED_LSS_EXCEPTON 54 -#define DMN_W32_FAST_FAIL_ADMINLESS_ACCESS_DENIED 55 // Telemetry, nonfatal -#define DMN_W32_FAST_FAIL_UNEXPECTED_CALL 56 -#define DMN_W32_FAST_FAIL_CONTROL_INVALID_RETURN_ADDRESS 57 -#define DMN_W32_FAST_FAIL_UNEXPECTED_HOST_BEHAVIOR 58 -#define DMN_W32_FAST_FAIL_FLAGS_CORRUPTION 59 -#define DMN_W32_FAST_FAIL_VEH_CORRUPTION 60 -#define DMN_W32_FAST_FAIL_ETW_CORRUPTION 61 -#define DMN_W32_FAST_FAIL_RIO_ABORT 62 -#define DMN_W32_FAST_FAIL_INVALID_PFN 63 -#define DMN_W32_FAST_FAIL_GUARD_ICALL_CHECK_FAILURE_XFG 64 -#define DMN_W32_FAST_FAIL_CAST_GUARD 65 // Known to compiler, must retain value 65 -#define DMN_W32_FAST_FAIL_HOST_VISIBILITY_CHANGE 66 -#define DMN_W32_FAST_FAIL_KERNEL_CET_SHADOW_STACK_ASSIST 67 -#define DMN_W32_FAST_FAIL_PATCH_CALLBACK_FAILED 68 -#define DMN_W32_FAST_FAIL_NTDLL_PATCH_FAILED 69 -#define DMN_W32_FAST_FAIL_INVALID_FLS_DATA 70 -#define DMN_W32_FAST_FAIL_INVALID_FAST_FAIL_CODE 0xFFFFFFFF +#define W32_DMN_FAST_FAIL_LEGACY_GS_VIOLATION 0 +#define W32_DMN_FAST_FAIL_VTGUARD_CHECK_FAILURE 1 +#define W32_DMN_FAST_FAIL_STACK_COOKIE_CHECK_FAILURE 2 +#define W32_DMN_FAST_FAIL_CORRUPT_LIST_ENTRY 3 +#define W32_DMN_FAST_FAIL_INCORRECT_STACK 4 +#define W32_DMN_FAST_FAIL_INVALID_ARG 5 +#define W32_DMN_FAST_FAIL_GS_COOKIE_INIT 6 +#define W32_DMN_FAST_FAIL_FATAL_APP_EXIT 7 +#define W32_DMN_FAST_FAIL_RANGE_CHECK_FAILURE 8 +#define W32_DMN_FAST_FAIL_UNSAFE_REGISTRY_ACCESS 9 +#define W32_DMN_FAST_FAIL_GUARD_ICALL_CHECK_FAILURE 10 +#define W32_DMN_FAST_FAIL_GUARD_WRITE_CHECK_FAILURE 11 +#define W32_DMN_FAST_FAIL_INVALID_FIBER_SWITCH 12 +#define W32_DMN_FAST_FAIL_INVALID_SET_OF_CONTEXT 13 +#define W32_DMN_FAST_FAIL_INVALID_REFERENCE_COUNT 14 +#define W32_DMN_FAST_FAIL_INVALID_JUMP_BUFFER 18 +#define W32_DMN_FAST_FAIL_MRDATA_MODIFIED 19 +#define W32_DMN_FAST_FAIL_CERTIFICATION_FAILURE 20 +#define W32_DMN_FAST_FAIL_INVALID_EXCEPTION_CHAIN 21 +#define W32_DMN_FAST_FAIL_CRYPTO_LIBRARY 22 +#define W32_DMN_FAST_FAIL_INVALID_CALL_IN_DLL_CALLOUT 23 +#define W32_DMN_FAST_FAIL_INVALID_IMAGE_BASE 24 +#define W32_DMN_FAST_FAIL_DLOAD_PROTECTION_FAILURE 25 +#define W32_DMN_FAST_FAIL_UNSAFE_EXTENSION_CALL 26 +#define W32_DMN_FAST_FAIL_DEPRECATED_SERVICE_INVOKED 27 +#define W32_DMN_FAST_FAIL_INVALID_BUFFER_ACCESS 28 +#define W32_DMN_FAST_FAIL_INVALID_BALANCED_TREE 29 +#define W32_DMN_FAST_FAIL_INVALID_NEXT_THREAD 30 +#define W32_DMN_FAST_FAIL_GUARD_ICALL_CHECK_SUPPRESSED 31 // Telemetry, nonfatal +#define W32_DMN_FAST_FAIL_APCS_DISABLED 32 +#define W32_DMN_FAST_FAIL_INVALID_IDLE_STATE 33 +#define W32_DMN_FAST_FAIL_MRDATA_PROTECTION_FAILURE 34 +#define W32_DMN_FAST_FAIL_UNEXPECTED_HEAP_EXCEPTION 35 +#define W32_DMN_FAST_FAIL_INVALID_LOCK_STATE 36 +#define W32_DMN_FAST_FAIL_GUARD_JUMPTABLE 37 // Known to compiler, must retain value 37 +#define W32_DMN_FAST_FAIL_INVALID_LONGJUMP_TARGET 38 +#define W32_DMN_FAST_FAIL_INVALID_DISPATCH_CONTEXT 39 +#define W32_DMN_FAST_FAIL_INVALID_THREAD 40 +#define W32_DMN_FAST_FAIL_INVALID_SYSCALL_NUMBER 41 // Telemetry, nonfatal +#define W32_DMN_FAST_FAIL_INVALID_FILE_OPERATION 42 // Telemetry, nonfatal +#define W32_DMN_FAST_FAIL_LPAC_ACCESS_DENIED 43 // Telemetry, nonfatal +#define W32_DMN_FAST_FAIL_GUARD_SS_FAILURE 44 +#define W32_DMN_FAST_FAIL_LOADER_CONTINUITY_FAILURE 45 // Telemetry, nonfatal +#define W32_DMN_FAST_FAIL_GUARD_EXPORT_SUPPRESSION_FAILURE 46 +#define W32_DMN_FAST_FAIL_INVALID_CONTROL_STACK 47 +#define W32_DMN_FAST_FAIL_SET_CONTEXT_DENIED 48 +#define W32_DMN_FAST_FAIL_INVALID_IAT 49 +#define W32_DMN_FAST_FAIL_HEAP_METADATA_CORRUPTION 50 +#define W32_DMN_FAST_FAIL_PAYLOAD_RESTRICTION_VIOLATION 51 +#define W32_DMN_FAST_FAIL_LOW_LABEL_ACCESS_DENIED 52 // Telemetry, nonfatal +#define W32_DMN_FAST_FAIL_ENCLAVE_CALL_FAILURE 53 +#define W32_DMN_FAST_FAIL_UNHANDLED_LSS_EXCEPTON 54 +#define W32_DMN_FAST_FAIL_ADMINLESS_ACCESS_DENIED 55 // Telemetry, nonfatal +#define W32_DMN_FAST_FAIL_UNEXPECTED_CALL 56 +#define W32_DMN_FAST_FAIL_CONTROL_INVALID_RETURN_ADDRESS 57 +#define W32_DMN_FAST_FAIL_UNEXPECTED_HOST_BEHAVIOR 58 +#define W32_DMN_FAST_FAIL_FLAGS_CORRUPTION 59 +#define W32_DMN_FAST_FAIL_VEH_CORRUPTION 60 +#define W32_DMN_FAST_FAIL_ETW_CORRUPTION 61 +#define W32_DMN_FAST_FAIL_RIO_ABORT 62 +#define W32_DMN_FAST_FAIL_INVALID_PFN 63 +#define W32_DMN_FAST_FAIL_GUARD_ICALL_CHECK_FAILURE_XFG 64 +#define W32_DMN_FAST_FAIL_CAST_GUARD 65 // Known to compiler, must retain value 65 +#define W32_DMN_FAST_FAIL_HOST_VISIBILITY_CHANGE 66 +#define W32_DMN_FAST_FAIL_KERNEL_CET_SHADOW_STACK_ASSIST 67 +#define W32_DMN_FAST_FAIL_PATCH_CALLBACK_FAILED 68 +#define W32_DMN_FAST_FAIL_NTDLL_PATCH_FAILED 69 +#define W32_DMN_FAST_FAIL_INVALID_FLS_DATA 70 +#define W32_DMN_FAST_FAIL_INVALID_FAST_FAIL_CODE 0xFFFFFFFF //////////////////////////////// //~ rjf: Win32 Register Codes -#define DMN_W32_CTX_X86 0x00010000 -#define DMN_W32_CTX_X64 0x00100000 +#define W32_DMN_CTX_X86 0x00010000 +#define W32_DMN_CTX_X64 0x00100000 -#define DMN_W32_CTX_INTEL_CONTROL 0x0001 // segss, rsp, segcs, rip, and rflags -#define DMN_W32_CTX_INTEL_INTEGER 0x0002 // rax, rcx, rdx, rbx, rbp, rsi, rdi, and r8-r15 -#define DMN_W32_CTX_INTEL_SEGMENTS 0x0004 // segds, seges, segfs, and seggs -#define DMN_W32_CTX_INTEL_FLOATS 0x0008 // xmm0-xmm15 -#define DMN_W32_CTX_INTEL_DEBUG 0x0010 // dr0-dr3 and dr6-dr7 -#define DMN_W32_CTX_INTEL_EXTENDED 0x0020 -#define DMN_W32_CTX_INTEL_XSTATE 0x0040 +#define W32_DMN_CTX_INTEL_CONTROL 0x0001 // segss, rsp, segcs, rip, and rflags +#define W32_DMN_CTX_INTEL_INTEGER 0x0002 // rax, rcx, rdx, rbx, rbp, rsi, rdi, and r8-r15 +#define W32_DMN_CTX_INTEL_SEGMENTS 0x0004 // segds, seges, segfs, and seggs +#define W32_DMN_CTX_INTEL_FLOATS 0x0008 // xmm0-xmm15 +#define W32_DMN_CTX_INTEL_DEBUG 0x0010 // dr0-dr3 and dr6-dr7 +#define W32_DMN_CTX_INTEL_EXTENDED 0x0020 +#define W32_DMN_CTX_INTEL_XSTATE 0x0040 -#define DMN_W32_CTX_X86_ALL (DMN_W32_CTX_X86 | \ -DMN_W32_CTX_INTEL_CONTROL | DMN_W32_CTX_INTEL_INTEGER | \ -DMN_W32_CTX_INTEL_SEGMENTS | DMN_W32_CTX_INTEL_DEBUG | \ -DMN_W32_CTX_INTEL_EXTENDED) -#define DMN_W32_CTX_X64_ALL (DMN_W32_CTX_X64 | \ -DMN_W32_CTX_INTEL_CONTROL | DMN_W32_CTX_INTEL_INTEGER | \ -DMN_W32_CTX_INTEL_SEGMENTS | DMN_W32_CTX_INTEL_FLOATS | \ -DMN_W32_CTX_INTEL_DEBUG) +#define W32_DMN_CTX_X86_ALL (W32_DMN_CTX_X86 | \ +W32_DMN_CTX_INTEL_CONTROL | W32_DMN_CTX_INTEL_INTEGER | \ +W32_DMN_CTX_INTEL_SEGMENTS | W32_DMN_CTX_INTEL_DEBUG | \ +W32_DMN_CTX_INTEL_EXTENDED) +#define W32_DMN_CTX_X64_ALL (W32_DMN_CTX_X64 | \ +W32_DMN_CTX_INTEL_CONTROL | W32_DMN_CTX_INTEL_INTEGER | \ +W32_DMN_CTX_INTEL_SEGMENTS | W32_DMN_CTX_INTEL_FLOATS | \ +W32_DMN_CTX_INTEL_DEBUG) //////////////////////////////// //~ rjf: Per-Entity State -typedef enum DMN_W32_EntityKind +typedef enum W32_DMN_EntityKind { - DMN_W32_EntityKind_Null, - DMN_W32_EntityKind_Root, - DMN_W32_EntityKind_Process, - DMN_W32_EntityKind_Thread, - DMN_W32_EntityKind_Module, - DMN_W32_EntityKind_COUNT + W32_DMN_EntityKind_Null, + W32_DMN_EntityKind_Root, + W32_DMN_EntityKind_Process, + W32_DMN_EntityKind_Thread, + W32_DMN_EntityKind_Module, + W32_DMN_EntityKind_COUNT } -DMN_W32_EntityKind; +W32_DMN_EntityKind; -typedef struct DMN_W32_Entity DMN_W32_Entity; -struct DMN_W32_Entity +typedef struct W32_DMN_Entity W32_DMN_Entity; +struct W32_DMN_Entity { - DMN_W32_Entity *first; - DMN_W32_Entity *last; - DMN_W32_Entity *next; - DMN_W32_Entity *prev; - DMN_W32_Entity *parent; - DMN_W32_EntityKind kind; + W32_DMN_Entity *first; + W32_DMN_Entity *last; + W32_DMN_Entity *next; + W32_DMN_Entity *prev; + W32_DMN_Entity *parent; + W32_DMN_EntityKind kind; U32 gen; U64 id; HANDLE handle; @@ -212,46 +212,46 @@ struct DMN_W32_Entity }; }; -typedef struct DMN_W32_EntityNode DMN_W32_EntityNode; -struct DMN_W32_EntityNode +typedef struct W32_DMN_EntityNode W32_DMN_EntityNode; +struct W32_DMN_EntityNode { - DMN_W32_EntityNode *next; - DMN_W32_Entity *v; + W32_DMN_EntityNode *next; + W32_DMN_Entity *v; }; -typedef struct DMN_W32_EntityIDHashNode DMN_W32_EntityIDHashNode; -struct DMN_W32_EntityIDHashNode +typedef struct W32_DMN_EntityIDHashNode W32_DMN_EntityIDHashNode; +struct W32_DMN_EntityIDHashNode { - DMN_W32_EntityIDHashNode *next; - DMN_W32_EntityIDHashNode *prev; + W32_DMN_EntityIDHashNode *next; + W32_DMN_EntityIDHashNode *prev; U64 id; - DMN_W32_Entity *entity; + W32_DMN_Entity *entity; }; -typedef struct DMN_W32_EntityIDHashSlot DMN_W32_EntityIDHashSlot; -struct DMN_W32_EntityIDHashSlot +typedef struct W32_DMN_EntityIDHashSlot W32_DMN_EntityIDHashSlot; +struct W32_DMN_EntityIDHashSlot { - DMN_W32_EntityIDHashNode *first; - DMN_W32_EntityIDHashNode *last; + W32_DMN_EntityIDHashNode *first; + W32_DMN_EntityIDHashNode *last; }; //////////////////////////////// //~ rjf: Injection Types -typedef struct DMN_W32_InjectedBreak DMN_W32_InjectedBreak; -struct DMN_W32_InjectedBreak +typedef struct W32_DMN_InjectedBreak W32_DMN_InjectedBreak; +struct W32_DMN_InjectedBreak { U64 code; U64 user_data; }; -#define DMN_W32_INJECTED_CODE_SIZE 32 +#define W32_DMN_INJECTED_CODE_SIZE 32 //////////////////////////////// //~ rjf: Image Info Types -typedef struct DMN_W32_ImageInfo DMN_W32_ImageInfo; -struct DMN_W32_ImageInfo +typedef struct W32_DMN_ImageInfo W32_DMN_ImageInfo; +struct W32_DMN_ImageInfo { Arch arch; U32 size; @@ -261,13 +261,13 @@ struct DMN_W32_ImageInfo //////////////////////////////// //~ rjf: Dynamically-Loaded Win32 Function Types -typedef HRESULT DMN_W32_GetThreadDescriptionFunctionType(HANDLE hThread, WCHAR **ppszThreadDescription); +typedef HRESULT W32_DMN_GetThreadDescriptionFunctionType(HANDLE hThread, WCHAR **ppszThreadDescription); //////////////////////////////// //~ rjf: Shared State Bundle -typedef struct DMN_W32_Shared DMN_W32_Shared; -struct DMN_W32_Shared +typedef struct W32_DMN_Shared W32_DMN_Shared; +struct W32_DMN_Shared { // rjf: top-level info Arena *arena; @@ -283,12 +283,12 @@ struct DMN_W32_Shared // rjf: entity state Arena *entities_arena; - DMN_W32_Entity *entities_base; - DMN_W32_Entity *entities_first_free; + W32_DMN_Entity *entities_base; + W32_DMN_Entity *entities_first_free; U64 entities_count; - DMN_W32_EntityIDHashSlot *entities_id_hash_slots; + W32_DMN_EntityIDHashSlot *entities_id_hash_slots; U64 entities_id_hash_slots_count; - DMN_W32_EntityIDHashNode *entities_id_hash_node_free; + W32_DMN_EntityIDHashNode *entities_id_hash_node_free; // rjf: launch state B32 new_process_pending; @@ -307,53 +307,47 @@ struct DMN_W32_Shared //////////////////////////////// //~ rjf: Globals -global DMN_W32_Shared *dmn_w32_shared = 0; -global DMN_W32_Entity dmn_w32_entity_nil = {&dmn_w32_entity_nil, &dmn_w32_entity_nil, &dmn_w32_entity_nil, &dmn_w32_entity_nil, &dmn_w32_entity_nil}; -global DMN_W32_GetThreadDescriptionFunctionType *dmn_w32_GetThreadDescription = 0; -thread_static B32 dmn_w32_ctrl_thread = 0; - -//////////////////////////////// -//~ rjf: Basic Helpers - -internal U64 dmn_w32_hash_from_string(String8 string); -internal U64 dmn_w32_hash_from_id(U64 id); +global W32_DMN_Shared *w32_dmn_shared = 0; +global W32_DMN_Entity w32_dmn_entity_nil = {&w32_dmn_entity_nil, &w32_dmn_entity_nil, &w32_dmn_entity_nil, &w32_dmn_entity_nil, &w32_dmn_entity_nil}; +global W32_DMN_GetThreadDescriptionFunctionType *w32_dmn_GetThreadDescription = 0; +thread_static B32 w32_dmn_ctrl_thread = 0; //////////////////////////////// //~ rjf: Entity Helpers //- rjf: entity <-> handle -internal DMN_Handle dmn_w32_handle_from_entity(DMN_W32_Entity *entity); -internal DMN_W32_Entity *dmn_w32_entity_from_handle(DMN_Handle handle); +internal DMN_Handle w32_dmn_handle_from_entity(W32_DMN_Entity *entity); +internal W32_DMN_Entity *w32_dmn_entity_from_handle(DMN_Handle handle); //- rjf: entity allocation/deallocation -internal DMN_W32_Entity *dmn_w32_entity_alloc(DMN_W32_Entity *parent, DMN_W32_EntityKind kind, U64 id); -internal void dmn_w32_entity_release(DMN_W32_Entity *entity); +internal W32_DMN_Entity *w32_dmn_entity_alloc(W32_DMN_Entity *parent, W32_DMN_EntityKind kind, U64 id); +internal void w32_dmn_entity_release(W32_DMN_Entity *entity); //- rjf: kind*id -> entity -internal DMN_W32_Entity *dmn_w32_entity_from_kind_id(DMN_W32_EntityKind kind, U64 id); +internal W32_DMN_Entity *w32_dmn_entity_from_kind_id(W32_DMN_EntityKind kind, U64 id); //////////////////////////////// //~ rjf: Module Info Extraction -internal String8 dmn_w32_full_path_from_module(Arena *arena, DMN_W32_Entity *module); +internal String8 w32_dmn_full_path_from_module(Arena *arena, W32_DMN_Entity *module); //////////////////////////////// //~ rjf: Win32-Level Process/Thread Reads/Writes //- rjf: processes -internal U64 dmn_w32_process_read(HANDLE process, Rng1U64 range, void *dst); -internal B32 dmn_w32_process_write(HANDLE process, Rng1U64 range, void *src); -internal String8 dmn_w32_read_memory_str(Arena *arena, HANDLE process_handle, U64 address); -internal String16 dmn_w32_read_memory_str16(Arena *arena, HANDLE process_handle, U64 address); -#define dmn_w32_process_read_struct(process, vaddr, ptr) dmn_w32_process_read((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr) -#define dmn_w32_process_write_struct(process, vaddr, ptr) dmn_w32_process_write((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr) -internal DMN_W32_ImageInfo dmn_w32_image_info_from_process_base_vaddr(HANDLE process, U64 base_vaddr); +internal U64 w32_dmn_process_read(HANDLE process, Rng1U64 range, void *dst); +internal B32 w32_dmn_process_write(HANDLE process, Rng1U64 range, void *src); +internal String8 w32_dmn_read_memory_str(Arena *arena, HANDLE process_handle, U64 address); +internal String16 w32_dmn_read_memory_str16(Arena *arena, HANDLE process_handle, U64 address); +#define w32_dmn_process_read_struct(process, vaddr, ptr) w32_dmn_process_read((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr) +#define w32_dmn_process_write_struct(process, vaddr, ptr) w32_dmn_process_write((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr) +internal W32_DMN_ImageInfo w32_dmn_image_info_from_process_base_vaddr(HANDLE process, U64 base_vaddr); //- rjf: threads -internal B32 dmn_w32_thread_read_reg_block(Arch arch, HANDLE thread, void *reg_block); -internal B32 dmn_w32_thread_write_reg_block(Arch arch, HANDLE thread, void *reg_block); +internal B32 w32_dmn_thread_read_reg_block(Arch arch, HANDLE thread, void *reg_block); +internal B32 w32_dmn_thread_write_reg_block(Arch arch, HANDLE thread, void *reg_block); //- rjf: remote thread injection -internal DWORD dmn_w32_inject_thread(HANDLE process, U64 start_address); +internal DWORD w32_dmn_inject_thread(HANDLE process, U64 start_address); #endif // DEMON_CORE_WIN32_H diff --git a/src/win32/window_manager/win32_window_manager.c b/src/win32/window_manager/win32_window_manager.c index c7e8708f..3baaa28c 100644 --- a/src/win32/window_manager/win32_window_manager.c +++ b/src/win32/window_manager/win32_window_manager.c @@ -19,7 +19,7 @@ global w32_GetSystemMetricsForDpi_Type *w32_GetSystemMetricsForDpi_func = 0; //~ rjf: Basic Helpers internal Rng2F32 -os_w32_rng2f32_from_rect(RECT rect) +w32_wm_rng2f32_from_rect(RECT rect) { Rng2F32 r = {0}; r.x0 = (F32)rect.left; @@ -32,25 +32,25 @@ os_w32_rng2f32_from_rect(RECT rect) //////////////////////////////// //~ rjf: Windows -internal OS_Window -os_w32_handle_from_window(OS_W32_Window *window) +internal WM_Window +w32_wm_handle_from_window(W32_WM_Window *window) { - OS_Window handle = {(U64)window}; + WM_Window handle = {(U64)window}; return handle; } -internal OS_W32_Window * -os_w32_window_from_handle(OS_Window handle) +internal W32_WM_Window * +w32_wm_window_from_handle(WM_Window handle) { - OS_W32_Window *window = (OS_W32_Window *)handle.u64[0]; + W32_WM_Window *window = (W32_WM_Window *)handle.u64[0]; return window; } -internal OS_W32_Window * -os_w32_window_from_hwnd(HWND hwnd) +internal W32_WM_Window * +w32_wm_window_from_hwnd(HWND hwnd) { - OS_W32_Window *result = 0; - for(OS_W32_Window *w = os_w32_gfx_state->first_window; w; w = w->next) + W32_WM_Window *result = 0; + for(W32_WM_Window *w = w32_wm_state->first_window; w; w = w->next) { if(w->hwnd == hwnd) { @@ -62,34 +62,34 @@ os_w32_window_from_hwnd(HWND hwnd) } internal HWND -os_w32_hwnd_from_window(OS_W32_Window *window) +w32_wm_hwnd_from_window(W32_WM_Window *window) { return window->hwnd; } -internal OS_W32_Window * -os_w32_window_alloc(void) +internal W32_WM_Window * +w32_wm_window_alloc(void) { - OS_W32_Window *result = os_w32_gfx_state->free_window; + W32_WM_Window *result = w32_wm_state->free_window; if(result) { - SLLStackPop(os_w32_gfx_state->free_window); + SLLStackPop(w32_wm_state->free_window); } else { - result = push_array_no_zero(os_w32_gfx_state->arena, OS_W32_Window, 1); + result = push_array_no_zero(w32_wm_state->arena, W32_WM_Window, 1); } MemoryZeroStruct(result); if(result) { - DLLPushBack(os_w32_gfx_state->first_window, os_w32_gfx_state->last_window, result); + DLLPushBack(w32_wm_state->first_window, w32_wm_state->last_window, result); } result->last_window_placement.length = sizeof(WINDOWPLACEMENT); return result; } internal void -os_w32_window_release(OS_W32_Window *window) +w32_wm_window_release(W32_WM_Window *window) { if(window->paint_arena != 0) { @@ -97,231 +97,231 @@ os_w32_window_release(OS_W32_Window *window) } ReleaseDC(window->hwnd, window->hdc); DestroyWindow(window->hwnd); - DLLRemove(os_w32_gfx_state->first_window, os_w32_gfx_state->last_window, window); - SLLStackPush(os_w32_gfx_state->free_window, window); + DLLRemove(w32_wm_state->first_window, w32_wm_state->last_window, window); + SLLStackPush(w32_wm_state->free_window, window); } -internal OS_Event * -os_w32_push_event(OS_EventKind kind, OS_W32_Window *window) +internal WM_Event * +w32_wm_push_event(WM_EventKind kind, W32_WM_Window *window) { - OS_Event *result = os_event_list_push_new(os_w32_event_arena, &os_w32_event_list, kind); - result->window = os_w32_handle_from_window(window); - result->modifiers = os_get_modifiers(); + WM_Event *result = wm_event_list_push_new(w32_wm_event_arena, &w32_wm_event_list, kind); + result->window = w32_wm_handle_from_window(window); + result->modifiers = wm_get_modifiers(); return result; } -internal OS_Key -os_w32_os_key_from_vkey(WPARAM vkey) +internal WM_Key +w32_wm_os_key_from_vkey(WPARAM vkey) { local_persist B32 first = 1; - local_persist OS_Key key_table[256]; + local_persist WM_Key key_table[256]; if (first){ first = 0; MemoryZeroArray(key_table); - key_table[(unsigned int)'A'] = OS_Key_A; - key_table[(unsigned int)'B'] = OS_Key_B; - key_table[(unsigned int)'C'] = OS_Key_C; - key_table[(unsigned int)'D'] = OS_Key_D; - key_table[(unsigned int)'E'] = OS_Key_E; - key_table[(unsigned int)'F'] = OS_Key_F; - key_table[(unsigned int)'G'] = OS_Key_G; - key_table[(unsigned int)'H'] = OS_Key_H; - key_table[(unsigned int)'I'] = OS_Key_I; - key_table[(unsigned int)'J'] = OS_Key_J; - key_table[(unsigned int)'K'] = OS_Key_K; - key_table[(unsigned int)'L'] = OS_Key_L; - key_table[(unsigned int)'M'] = OS_Key_M; - key_table[(unsigned int)'N'] = OS_Key_N; - key_table[(unsigned int)'O'] = OS_Key_O; - key_table[(unsigned int)'P'] = OS_Key_P; - key_table[(unsigned int)'Q'] = OS_Key_Q; - key_table[(unsigned int)'R'] = OS_Key_R; - key_table[(unsigned int)'S'] = OS_Key_S; - key_table[(unsigned int)'T'] = OS_Key_T; - key_table[(unsigned int)'U'] = OS_Key_U; - key_table[(unsigned int)'V'] = OS_Key_V; - key_table[(unsigned int)'W'] = OS_Key_W; - key_table[(unsigned int)'X'] = OS_Key_X; - key_table[(unsigned int)'Y'] = OS_Key_Y; - key_table[(unsigned int)'Z'] = OS_Key_Z; + key_table[(unsigned int)'A'] = WM_Key_A; + key_table[(unsigned int)'B'] = WM_Key_B; + key_table[(unsigned int)'C'] = WM_Key_C; + key_table[(unsigned int)'D'] = WM_Key_D; + key_table[(unsigned int)'E'] = WM_Key_E; + key_table[(unsigned int)'F'] = WM_Key_F; + key_table[(unsigned int)'G'] = WM_Key_G; + key_table[(unsigned int)'H'] = WM_Key_H; + key_table[(unsigned int)'I'] = WM_Key_I; + key_table[(unsigned int)'J'] = WM_Key_J; + key_table[(unsigned int)'K'] = WM_Key_K; + key_table[(unsigned int)'L'] = WM_Key_L; + key_table[(unsigned int)'M'] = WM_Key_M; + key_table[(unsigned int)'N'] = WM_Key_N; + key_table[(unsigned int)'O'] = WM_Key_O; + key_table[(unsigned int)'P'] = WM_Key_P; + key_table[(unsigned int)'Q'] = WM_Key_Q; + key_table[(unsigned int)'R'] = WM_Key_R; + key_table[(unsigned int)'S'] = WM_Key_S; + key_table[(unsigned int)'T'] = WM_Key_T; + key_table[(unsigned int)'U'] = WM_Key_U; + key_table[(unsigned int)'V'] = WM_Key_V; + key_table[(unsigned int)'W'] = WM_Key_W; + key_table[(unsigned int)'X'] = WM_Key_X; + key_table[(unsigned int)'Y'] = WM_Key_Y; + key_table[(unsigned int)'Z'] = WM_Key_Z; - for (U64 i = '0', j = OS_Key_0; i <= '9'; i += 1, j += 1){ - key_table[i] = (OS_Key)j; + for (U64 i = '0', j = WM_Key_0; i <= '9'; i += 1, j += 1){ + key_table[i] = (WM_Key)j; } - for (U64 i = VK_NUMPAD0, j = OS_Key_0; i <= VK_NUMPAD9; i += 1, j += 1){ - key_table[i] = (OS_Key)j; + for (U64 i = VK_NUMPAD0, j = WM_Key_0; i <= VK_NUMPAD9; i += 1, j += 1){ + key_table[i] = (WM_Key)j; } - for (U64 i = VK_F1, j = OS_Key_F1; i <= VK_F24; i += 1, j += 1){ - key_table[i] = (OS_Key)j; + for (U64 i = VK_F1, j = WM_Key_F1; i <= VK_F24; i += 1, j += 1){ + key_table[i] = (WM_Key)j; } - key_table[VK_SPACE] = OS_Key_Space; - key_table[VK_OEM_3] = OS_Key_Tick; - key_table[VK_OEM_MINUS] = OS_Key_Minus; - key_table[VK_OEM_PLUS] = OS_Key_Equal; - key_table[VK_OEM_4] = OS_Key_LeftBracket; - key_table[VK_OEM_6] = OS_Key_RightBracket; - key_table[VK_OEM_1] = OS_Key_Semicolon; - key_table[VK_OEM_7] = OS_Key_Quote; - key_table[VK_OEM_COMMA] = OS_Key_Comma; - key_table[VK_OEM_PERIOD]= OS_Key_Period; - key_table[VK_OEM_2] = OS_Key_Slash; - key_table[VK_OEM_5] = OS_Key_BackSlash; + key_table[VK_SPACE] = WM_Key_Space; + key_table[VK_OEM_3] = WM_Key_Tick; + key_table[VK_OEM_MINUS] = WM_Key_Minus; + key_table[VK_OEM_PLUS] = WM_Key_Equal; + key_table[VK_OEM_4] = WM_Key_LeftBracket; + key_table[VK_OEM_6] = WM_Key_RightBracket; + key_table[VK_OEM_1] = WM_Key_Semicolon; + key_table[VK_OEM_7] = WM_Key_Quote; + key_table[VK_OEM_COMMA] = WM_Key_Comma; + key_table[VK_OEM_PERIOD]= WM_Key_Period; + key_table[VK_OEM_2] = WM_Key_Slash; + key_table[VK_OEM_5] = WM_Key_BackSlash; - key_table[VK_TAB] = OS_Key_Tab; - key_table[VK_PAUSE] = OS_Key_Pause; - key_table[VK_ESCAPE] = OS_Key_Esc; + key_table[VK_TAB] = WM_Key_Tab; + key_table[VK_PAUSE] = WM_Key_Pause; + key_table[VK_ESCAPE] = WM_Key_Esc; - key_table[VK_UP] = OS_Key_Up; - key_table[VK_LEFT] = OS_Key_Left; - key_table[VK_DOWN] = OS_Key_Down; - key_table[VK_RIGHT] = OS_Key_Right; + key_table[VK_UP] = WM_Key_Up; + key_table[VK_LEFT] = WM_Key_Left; + key_table[VK_DOWN] = WM_Key_Down; + key_table[VK_RIGHT] = WM_Key_Right; - key_table[VK_BACK] = OS_Key_Backspace; - key_table[VK_RETURN] = OS_Key_Return; + key_table[VK_BACK] = WM_Key_Backspace; + key_table[VK_RETURN] = WM_Key_Return; - key_table[VK_DELETE] = OS_Key_Delete; - key_table[VK_INSERT] = OS_Key_Insert; - key_table[VK_PRIOR] = OS_Key_PageUp; - key_table[VK_NEXT] = OS_Key_PageDown; - key_table[VK_HOME] = OS_Key_Home; - key_table[VK_END] = OS_Key_End; + key_table[VK_DELETE] = WM_Key_Delete; + key_table[VK_INSERT] = WM_Key_Insert; + key_table[VK_PRIOR] = WM_Key_PageUp; + key_table[VK_NEXT] = WM_Key_PageDown; + key_table[VK_HOME] = WM_Key_Home; + key_table[VK_END] = WM_Key_End; - key_table[VK_CAPITAL] = OS_Key_CapsLock; - key_table[VK_NUMLOCK] = OS_Key_NumLock; - key_table[VK_SCROLL] = OS_Key_ScrollLock; - key_table[VK_APPS] = OS_Key_Menu; + key_table[VK_CAPITAL] = WM_Key_CapsLock; + key_table[VK_NUMLOCK] = WM_Key_NumLock; + key_table[VK_SCROLL] = WM_Key_ScrollLock; + key_table[VK_APPS] = WM_Key_Menu; - key_table[VK_CONTROL] = OS_Key_Ctrl; - key_table[VK_LCONTROL] = OS_Key_Ctrl; - key_table[VK_RCONTROL] = OS_Key_Ctrl; - key_table[VK_SHIFT] = OS_Key_Shift; - key_table[VK_LSHIFT] = OS_Key_Shift; - key_table[VK_RSHIFT] = OS_Key_Shift; - key_table[VK_MENU] = OS_Key_Alt; - key_table[VK_LMENU] = OS_Key_Alt; - key_table[VK_RMENU] = OS_Key_Alt; + key_table[VK_CONTROL] = WM_Key_Ctrl; + key_table[VK_LCONTROL] = WM_Key_Ctrl; + key_table[VK_RCONTROL] = WM_Key_Ctrl; + key_table[VK_SHIFT] = WM_Key_Shift; + key_table[VK_LSHIFT] = WM_Key_Shift; + key_table[VK_RSHIFT] = WM_Key_Shift; + key_table[VK_MENU] = WM_Key_Alt; + key_table[VK_LMENU] = WM_Key_Alt; + key_table[VK_RMENU] = WM_Key_Alt; - key_table[VK_DIVIDE] = OS_Key_NumSlash; - key_table[VK_MULTIPLY] = OS_Key_NumStar; - key_table[VK_SUBTRACT] = OS_Key_NumMinus; - key_table[VK_ADD] = OS_Key_NumPlus; - key_table[VK_DECIMAL] = OS_Key_NumPeriod; + key_table[VK_DIVIDE] = WM_Key_NumSlash; + key_table[VK_MULTIPLY] = WM_Key_NumStar; + key_table[VK_SUBTRACT] = WM_Key_NumMinus; + key_table[VK_ADD] = WM_Key_NumPlus; + key_table[VK_DECIMAL] = WM_Key_NumPeriod; for (U32 i = 0; i < 10; i += 1){ - key_table[VK_NUMPAD0 + i] = (OS_Key)((U64)OS_Key_Num0 + i); + key_table[VK_NUMPAD0 + i] = (WM_Key)((U64)WM_Key_Num0 + i); } for (U64 i = 0xDF, j = 0; i < 0xFF; i += 1, j += 1){ - key_table[i] = (OS_Key)((U64)OS_Key_Ex0 + j); + key_table[i] = (WM_Key)((U64)WM_Key_Ex0 + j); } } - OS_Key key = key_table[vkey&bitmask8]; + WM_Key key = key_table[vkey&bitmask8]; return key; } internal WPARAM -os_w32_vkey_from_os_key(OS_Key key) +w32_wm_vkey_from_os_key(WM_Key key) { WPARAM result = 0; { local_persist B32 initialized = 0; - local_persist WPARAM vkey_table[OS_Key_COUNT] = {0}; + local_persist WPARAM vkey_table[WM_Key_COUNT] = {0}; if(initialized == 0) { initialized = 1; - vkey_table[OS_Key_Esc] = VK_ESCAPE; - for(OS_Key key = OS_Key_F1; key <= OS_Key_F24; key = (OS_Key)(key+1)) + vkey_table[WM_Key_Esc] = VK_ESCAPE; + for(WM_Key key = WM_Key_F1; key <= WM_Key_F24; key = (WM_Key)(key+1)) { - vkey_table[key] = VK_F1+(key-OS_Key_F1); + vkey_table[key] = VK_F1+(key-WM_Key_F1); } - vkey_table[OS_Key_Tick] = VK_OEM_3; - for(OS_Key key = OS_Key_0; key <= OS_Key_9; key = (OS_Key)(key+1)) + vkey_table[WM_Key_Tick] = VK_OEM_3; + for(WM_Key key = WM_Key_0; key <= WM_Key_9; key = (WM_Key)(key+1)) { - vkey_table[key] = '0'+(key-OS_Key_0); + vkey_table[key] = '0'+(key-WM_Key_0); } - vkey_table[OS_Key_Minus] = VK_OEM_MINUS; - vkey_table[OS_Key_Equal] = VK_OEM_PLUS; - vkey_table[OS_Key_Backspace] = VK_BACK; - vkey_table[OS_Key_Tab] = VK_TAB; - vkey_table[OS_Key_Q] = 'Q'; - vkey_table[OS_Key_W] = 'W'; - vkey_table[OS_Key_E] = 'E'; - vkey_table[OS_Key_R] = 'R'; - vkey_table[OS_Key_T] = 'T'; - vkey_table[OS_Key_Y] = 'Y'; - vkey_table[OS_Key_U] = 'U'; - vkey_table[OS_Key_I] = 'I'; - vkey_table[OS_Key_O] = 'O'; - vkey_table[OS_Key_P] = 'P'; - vkey_table[OS_Key_LeftBracket] = VK_OEM_4; - vkey_table[OS_Key_RightBracket] = VK_OEM_6; - vkey_table[OS_Key_BackSlash] = VK_OEM_5; - vkey_table[OS_Key_CapsLock] = VK_CAPITAL; - vkey_table[OS_Key_A] = 'A'; - vkey_table[OS_Key_S] = 'S'; - vkey_table[OS_Key_D] = 'D'; - vkey_table[OS_Key_F] = 'F'; - vkey_table[OS_Key_G] = 'G'; - vkey_table[OS_Key_H] = 'H'; - vkey_table[OS_Key_J] = 'J'; - vkey_table[OS_Key_K] = 'K'; - vkey_table[OS_Key_L] = 'L'; - vkey_table[OS_Key_Semicolon] = VK_OEM_1; - vkey_table[OS_Key_Quote] = VK_OEM_7; - vkey_table[OS_Key_Return] = VK_RETURN; - vkey_table[OS_Key_Shift] = VK_SHIFT; - vkey_table[OS_Key_Z] = 'Z'; - vkey_table[OS_Key_X] = 'X'; - vkey_table[OS_Key_C] = 'C'; - vkey_table[OS_Key_V] = 'V'; - vkey_table[OS_Key_B] = 'B'; - vkey_table[OS_Key_N] = 'N'; - vkey_table[OS_Key_M] = 'M'; - vkey_table[OS_Key_Comma] = VK_OEM_COMMA; - vkey_table[OS_Key_Period] = VK_OEM_PERIOD; - vkey_table[OS_Key_Slash] = VK_OEM_2; - vkey_table[OS_Key_Ctrl] = VK_CONTROL; - vkey_table[OS_Key_Alt] = VK_MENU; - vkey_table[OS_Key_Space] = VK_SPACE; - vkey_table[OS_Key_Menu] = VK_APPS; - vkey_table[OS_Key_ScrollLock] = VK_SCROLL; - vkey_table[OS_Key_Pause] = VK_PAUSE; - vkey_table[OS_Key_Insert] = VK_INSERT; - vkey_table[OS_Key_Home] = VK_HOME; - vkey_table[OS_Key_PageUp] = VK_PRIOR; - vkey_table[OS_Key_Delete] = VK_DELETE; - vkey_table[OS_Key_End] = VK_END; - vkey_table[OS_Key_PageDown] = VK_NEXT; - vkey_table[OS_Key_Up] = VK_UP; - vkey_table[OS_Key_Left] = VK_LEFT; - vkey_table[OS_Key_Down] = VK_DOWN; - vkey_table[OS_Key_Right] = VK_RIGHT; - for(OS_Key key = OS_Key_Ex0; key <= OS_Key_Ex29; key = (OS_Key)(key+1)) + vkey_table[WM_Key_Minus] = VK_OEM_MINUS; + vkey_table[WM_Key_Equal] = VK_OEM_PLUS; + vkey_table[WM_Key_Backspace] = VK_BACK; + vkey_table[WM_Key_Tab] = VK_TAB; + vkey_table[WM_Key_Q] = 'Q'; + vkey_table[WM_Key_W] = 'W'; + vkey_table[WM_Key_E] = 'E'; + vkey_table[WM_Key_R] = 'R'; + vkey_table[WM_Key_T] = 'T'; + vkey_table[WM_Key_Y] = 'Y'; + vkey_table[WM_Key_U] = 'U'; + vkey_table[WM_Key_I] = 'I'; + vkey_table[WM_Key_O] = 'O'; + vkey_table[WM_Key_P] = 'P'; + vkey_table[WM_Key_LeftBracket] = VK_OEM_4; + vkey_table[WM_Key_RightBracket] = VK_OEM_6; + vkey_table[WM_Key_BackSlash] = VK_OEM_5; + vkey_table[WM_Key_CapsLock] = VK_CAPITAL; + vkey_table[WM_Key_A] = 'A'; + vkey_table[WM_Key_S] = 'S'; + vkey_table[WM_Key_D] = 'D'; + vkey_table[WM_Key_F] = 'F'; + vkey_table[WM_Key_G] = 'G'; + vkey_table[WM_Key_H] = 'H'; + vkey_table[WM_Key_J] = 'J'; + vkey_table[WM_Key_K] = 'K'; + vkey_table[WM_Key_L] = 'L'; + vkey_table[WM_Key_Semicolon] = VK_OEM_1; + vkey_table[WM_Key_Quote] = VK_OEM_7; + vkey_table[WM_Key_Return] = VK_RETURN; + vkey_table[WM_Key_Shift] = VK_SHIFT; + vkey_table[WM_Key_Z] = 'Z'; + vkey_table[WM_Key_X] = 'X'; + vkey_table[WM_Key_C] = 'C'; + vkey_table[WM_Key_V] = 'V'; + vkey_table[WM_Key_B] = 'B'; + vkey_table[WM_Key_N] = 'N'; + vkey_table[WM_Key_M] = 'M'; + vkey_table[WM_Key_Comma] = VK_OEM_COMMA; + vkey_table[WM_Key_Period] = VK_OEM_PERIOD; + vkey_table[WM_Key_Slash] = VK_OEM_2; + vkey_table[WM_Key_Ctrl] = VK_CONTROL; + vkey_table[WM_Key_Alt] = VK_MENU; + vkey_table[WM_Key_Space] = VK_SPACE; + vkey_table[WM_Key_Menu] = VK_APPS; + vkey_table[WM_Key_ScrollLock] = VK_SCROLL; + vkey_table[WM_Key_Pause] = VK_PAUSE; + vkey_table[WM_Key_Insert] = VK_INSERT; + vkey_table[WM_Key_Home] = VK_HOME; + vkey_table[WM_Key_PageUp] = VK_PRIOR; + vkey_table[WM_Key_Delete] = VK_DELETE; + vkey_table[WM_Key_End] = VK_END; + vkey_table[WM_Key_PageDown] = VK_NEXT; + vkey_table[WM_Key_Up] = VK_UP; + vkey_table[WM_Key_Left] = VK_LEFT; + vkey_table[WM_Key_Down] = VK_DOWN; + vkey_table[WM_Key_Right] = VK_RIGHT; + for(WM_Key key = WM_Key_Ex0; key <= WM_Key_Ex29; key = (WM_Key)(key+1)) { - vkey_table[key] = 0xDF + (key-OS_Key_Ex0); + vkey_table[key] = 0xDF + (key-WM_Key_Ex0); } - vkey_table[OS_Key_NumLock] = VK_NUMLOCK; - vkey_table[OS_Key_NumSlash] = VK_DIVIDE; - vkey_table[OS_Key_NumStar] = VK_MULTIPLY; - vkey_table[OS_Key_NumMinus] = VK_SUBTRACT; - vkey_table[OS_Key_NumPlus] = VK_ADD; - vkey_table[OS_Key_NumPeriod] = VK_DECIMAL; - vkey_table[OS_Key_Num0] = VK_NUMPAD0; - vkey_table[OS_Key_Num1] = VK_NUMPAD1; - vkey_table[OS_Key_Num2] = VK_NUMPAD2; - vkey_table[OS_Key_Num3] = VK_NUMPAD3; - vkey_table[OS_Key_Num4] = VK_NUMPAD4; - vkey_table[OS_Key_Num5] = VK_NUMPAD5; - vkey_table[OS_Key_Num6] = VK_NUMPAD6; - vkey_table[OS_Key_Num7] = VK_NUMPAD7; - vkey_table[OS_Key_Num8] = VK_NUMPAD8; - vkey_table[OS_Key_Num9] = VK_NUMPAD9; - vkey_table[OS_Key_LeftMouseButton] = VK_LBUTTON; - vkey_table[OS_Key_MiddleMouseButton] = VK_MBUTTON; - vkey_table[OS_Key_RightMouseButton] = VK_RBUTTON; + vkey_table[WM_Key_NumLock] = VK_NUMLOCK; + vkey_table[WM_Key_NumSlash] = VK_DIVIDE; + vkey_table[WM_Key_NumStar] = VK_MULTIPLY; + vkey_table[WM_Key_NumMinus] = VK_SUBTRACT; + vkey_table[WM_Key_NumPlus] = VK_ADD; + vkey_table[WM_Key_NumPeriod] = VK_DECIMAL; + vkey_table[WM_Key_Num0] = VK_NUMPAD0; + vkey_table[WM_Key_Num1] = VK_NUMPAD1; + vkey_table[WM_Key_Num2] = VK_NUMPAD2; + vkey_table[WM_Key_Num3] = VK_NUMPAD3; + vkey_table[WM_Key_Num4] = VK_NUMPAD4; + vkey_table[WM_Key_Num5] = VK_NUMPAD5; + vkey_table[WM_Key_Num6] = VK_NUMPAD6; + vkey_table[WM_Key_Num7] = VK_NUMPAD7; + vkey_table[WM_Key_Num8] = VK_NUMPAD8; + vkey_table[WM_Key_Num9] = VK_NUMPAD9; + vkey_table[WM_Key_LeftMouseButton] = VK_LBUTTON; + vkey_table[WM_Key_MiddleMouseButton] = VK_MBUTTON; + vkey_table[WM_Key_RightMouseButton] = VK_RBUTTON; } result = vkey_table[key]; } @@ -329,20 +329,20 @@ os_w32_vkey_from_os_key(OS_Key key) } internal LRESULT -os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +w32_wm_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { ProfBeginFunction(); LRESULT result = 0; B32 good = 1; - if(os_w32_event_arena == 0) + if(w32_wm_event_arena == 0) { result = DefWindowProcW(hwnd, uMsg, wParam, lParam); good = 0; } if(good) { - OS_W32_Window *window = os_w32_window_from_hwnd(hwnd); - OS_Window window_handle = os_w32_handle_from_window(window); + W32_WM_Window *window = w32_wm_window_from_hwnd(hwnd); + WM_Window window_handle = w32_wm_handle_from_window(window); B32 release = 0; switch(uMsg) @@ -354,12 +354,12 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_ENTERSIZEMOVE: { - os_w32_resizing = 1; + w32_wm_resizing = 1; }break; case WM_EXITSIZEMOVE: { - os_w32_resizing = 0; + w32_wm_resizing = 0; }break; case WM_SIZE: @@ -374,7 +374,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_CLOSE: { - os_w32_push_event(OS_EventKind_WindowClose, window); + w32_wm_push_event(WM_EventKind_WindowClose, window); }break; case WM_LBUTTONUP: @@ -387,20 +387,20 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: { - OS_Event *event = os_w32_push_event(release ? OS_EventKind_Release : OS_EventKind_Press, window); + WM_Event *event = w32_wm_push_event(release ? WM_EventKind_Release : WM_EventKind_Press, window); switch (uMsg) { case WM_LBUTTONUP: case WM_LBUTTONDOWN: { - event->key = OS_Key_LeftMouseButton; + event->key = WM_Key_LeftMouseButton; }break; case WM_MBUTTONUP: case WM_MBUTTONDOWN: { - event->key = OS_Key_MiddleMouseButton; + event->key = WM_Key_MiddleMouseButton; }break; case WM_RBUTTONUP: case WM_RBUTTONDOWN: { - event->key = OS_Key_RightMouseButton; + event->key = WM_Key_RightMouseButton; }break; } event->pos.x = (F32)(S16)LOWORD(lParam); @@ -417,7 +417,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MOUSEMOVE: { - OS_Event *event = os_w32_push_event(OS_EventKind_MouseMove, window); + WM_Event *event = w32_wm_push_event(WM_EventKind_MouseMove, window); event->pos.x = (F32)(S16)LOWORD(lParam); event->pos.y = (F32)(S16)HIWORD(lParam); }break; @@ -425,7 +425,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MOUSEWHEEL: { S16 wheel_delta = HIWORD(wParam); - OS_Event *event = os_w32_push_event(OS_EventKind_Scroll, window); + WM_Event *event = w32_wm_push_event(WM_EventKind_Scroll, window); POINT p; p.x = (S32)(S16)LOWORD(lParam); p.y = (S32)(S16)HIWORD(lParam); @@ -438,7 +438,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MOUSEHWHEEL: { S16 wheel_delta = HIWORD(wParam); - OS_Event *event = os_w32_push_event(OS_EventKind_Scroll, window); + WM_Event *event = w32_wm_push_event(WM_EventKind_Scroll, window); POINT p; p.x = (S32)(S16)LOWORD(lParam); p.y = (S32)(S16)HIWORD(lParam); @@ -479,14 +479,14 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) right_sided = 1; } - OS_Event *event = os_w32_push_event(release ? OS_EventKind_Release : OS_EventKind_Press, window); - event->key = os_w32_os_key_from_vkey(wParam); + WM_Event *event = w32_wm_push_event(release ? WM_EventKind_Release : WM_EventKind_Press, window); + event->key = w32_wm_os_key_from_vkey(wParam); event->repeat_count = lParam & bitmask16; event->is_repeat = is_repeat; event->right_sided = right_sided; - if(event->key == OS_Key_Alt && event->modifiers & OS_Modifier_Alt) { event->modifiers &= ~OS_Modifier_Alt; } - if(event->key == OS_Key_Ctrl && event->modifiers & OS_Modifier_Ctrl) { event->modifiers &= ~OS_Modifier_Ctrl; } - if(event->key == OS_Key_Shift && event->modifiers & OS_Modifier_Shift) { event->modifiers &= ~OS_Modifier_Shift; } + if(event->key == WM_Key_Alt && event->modifiers & WM_Modifier_Alt) { event->modifiers &= ~WM_Modifier_Alt; } + if(event->key == WM_Key_Ctrl && event->modifiers & WM_Modifier_Ctrl) { event->modifiers &= ~WM_Modifier_Ctrl; } + if(event->key == WM_Key_Shift && event->modifiers & WM_Modifier_Shift) { event->modifiers &= ~WM_Modifier_Shift; } }break; case WM_SYSCHAR: @@ -507,10 +507,10 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) U32 character = wParam; if(character >= 32 && character != 127) { - OS_Event *event = os_w32_push_event(OS_EventKind_Text, window); + WM_Event *event = w32_wm_push_event(WM_EventKind_Text, window); if(lParam & bit29) { - event->modifiers |= OS_Modifier_Alt; + event->modifiers |= WM_Modifier_Alt; } event->character = character; } @@ -518,14 +518,14 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_KILLFOCUS: { - os_w32_push_event(OS_EventKind_WindowLoseFocus, window); + w32_wm_push_event(WM_EventKind_WindowLoseFocus, window); ReleaseCapture(); }break; case WM_SETCURSOR: { - Rng2F32 window_rect = os_client_rect_from_window(window_handle); - Vec2F32 mouse = os_mouse_from_window(window_handle); + Rng2F32 window_rect = wm_client_rect_from_window(window_handle); + Vec2F32 mouse = wm_mouse_from_window(window_handle); B32 on_border = 0; DWORD window_style = window ? GetWindowLong(window->hwnd, GWL_STYLE) : 0; B32 is_fullscreen = !(window_style & WS_OVERLAPPEDWINDOW); @@ -535,9 +535,9 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) B32 on_border_y = (mouse.y <= window->custom_border_edge_thickness || window_rect.y1-window->custom_border_edge_thickness <= mouse.y); on_border = on_border_x || on_border_y; } - if(!os_w32_resizing && !on_border && contains_2f32(window_rect, mouse)) + if(!w32_wm_resizing && !on_border && contains_2f32(window_rect, mouse)) { - SetCursor(os_w32_gfx_state->hCursor); + SetCursor(w32_wm_state->hCursor); } else { @@ -565,16 +565,16 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) POINT drop_pt = {0}; DragQueryPoint(drop, &drop_pt); U64 num_files_dropped = DragQueryFile(drop, 0xffffffff, 0, 0); - OS_Event *event = os_w32_push_event(OS_EventKind_FileDrop, window); + WM_Event *event = w32_wm_push_event(WM_EventKind_FileDrop, window); event->pos = v2f32((F32)drop_pt.x, (F32)drop_pt.y); for(U64 idx = 0; idx < num_files_dropped; idx += 1) { U64 name_size = DragQueryFile(drop, idx, 0, 0) + 1; - U8 *name_ptr = push_array(os_w32_event_arena, U8, name_size); + U8 *name_ptr = push_array(w32_wm_event_arena, U8, name_size); DragQueryFile(drop, idx, (char *)name_ptr, name_size); String8 path_string = str8(name_ptr, name_size - 1); - String8 path_string__normalized = path_normalized_from_string(os_w32_event_arena, path_string); - str8_list_push(os_w32_event_arena, &event->strings, path_string__normalized); + String8 path_string__normalized = path_normalized_from_string(w32_wm_event_arena, path_string); + str8_list_push(w32_wm_event_arena, &event->strings, path_string__normalized); } DragFinish(drop); }break; @@ -582,7 +582,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) //- rjf: [custom border] case WM_NCPAINT: { - if(os_w32_new_window_custom_border || (window != 0 && window->custom_border && !window->custom_border_composition_enabled)) + if(w32_wm_new_window_custom_border || (window != 0 && window->custom_border && !window->custom_border_composition_enabled)) { result = 0; } @@ -619,7 +619,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_NCUAHDRAWFRAME: { // NOTE(rjf): undocumented messages for drawing themed window borders. - if(os_w32_new_window_custom_border || (window != 0 && window->custom_border)) + if(w32_wm_new_window_custom_border || (window != 0 && window->custom_border)) { result = 0; } @@ -631,7 +631,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_SETICON: case WM_SETTEXT: { - if(os_w32_new_window_custom_border || (window && window->custom_border && !window->custom_border_composition_enabled)) + if(w32_wm_new_window_custom_border || (window && window->custom_border && !window->custom_border_composition_enabled)) { // NOTE(rjf): // https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/ @@ -649,7 +649,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) //- rjf: [custom border] activation - without this `result`, stuff flickers. case WM_NCACTIVATE: { - if(!os_w32_new_window_custom_border && (window == 0 || window->custom_border == 0)) + if(!w32_wm_new_window_custom_border && (window == 0 || window->custom_border == 0)) { result = DefWindowProcW(hwnd, uMsg, wParam, lParam); } @@ -662,7 +662,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) //- rjf: [custom border] client/window size calculation case WM_NCCALCSIZE: { - if(os_w32_new_window_custom_border || (window && window->custom_border)) + if(w32_wm_new_window_custom_border || (window && window->custom_border)) { F32 dpi = w32_GetDpiForWindow_func ? (F32)w32_GetDpiForWindow_func(hwnd) : 96.f; S32 frame_x = w32_GetSystemMetricsForDpi_func ? w32_GetSystemMetricsForDpi_func(SM_CXFRAME, dpi) : GetSystemMetrics(SM_CXFRAME); @@ -742,7 +742,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) //- rjf: check against title bar client areas B32 is_over_title_bar_client_area = 0; - for(OS_W32_TitleBarClientArea *area = window->first_title_bar_client_area; + for(W32_WM_TitleBarClientArea *area = window->first_title_bar_client_area; area != 0; area = area->next) { @@ -803,11 +803,11 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) //~ rjf: Monitors internal BOOL -os_w32_monitor_gather_enum_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM bundle_ptr) +w32_wm_monitor_gather_enum_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM bundle_ptr) { - OS_W32_MonitorGatherBundle *bundle = (OS_W32_MonitorGatherBundle *)bundle_ptr; - OS_Monitor m = {(U64)monitor}; - OS_W32_MonitorGatherNode *n = push_array(bundle->arena, OS_W32_MonitorGatherNode, 1); + W32_WM_MonitorGatherBundle *bundle = (W32_WM_MonitorGatherBundle *)bundle_ptr; + WM_Monitor m = {(U64)monitor}; + W32_WM_MonitorGatherNode *n = push_array(bundle->arena, W32_WM_MonitorGatherNode, 1); n->v = m; SLLQueuePush(bundle->first_monitor, bundle->last_monitor, n); bundle->monitor_count += 1; @@ -818,14 +818,14 @@ os_w32_monitor_gather_enum_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM b //~ rjf: @os_hooks Main Initialization API (Implemented Per-OS) internal void -os_gfx_init(void) +wm_init(void) { //- rjf: set up base shared state Arena *arena = arena_alloc(); - os_w32_gfx_state = push_array(arena, OS_W32_GfxState, 1); - os_w32_gfx_state->arena = arena; - os_w32_gfx_state->gfx_thread_tid = (U32)GetCurrentThreadId(); - os_w32_gfx_state->hInstance = GetModuleHandle(0); + w32_wm_state = push_array(arena, W32_WM_State, 1); + w32_wm_state->arena = arena; + w32_wm_state->gfx_thread_tid = (U32)GetCurrentThreadId(); + w32_wm_state->hInstance = GetModuleHandle(0); //- rjf: set dpi awareness w32_SetProcessDpiAwarenessContext_Type *SetProcessDpiAwarenessContext_func = 0; @@ -863,11 +863,11 @@ os_gfx_init(void) //- rjf: register graphical-window class { WNDCLASSEXW wndclass = {sizeof(wndclass)}; - wndclass.lpfnWndProc = os_w32_wnd_proc; - wndclass.hInstance = os_w32_gfx_state->hInstance; + wndclass.lpfnWndProc = w32_wm_wnd_proc; + wndclass.hInstance = w32_wm_state->hInstance; wndclass.lpszClassName = L"graphical-window"; wndclass.hCursor = LoadCursorA(0, IDC_ARROW); - wndclass.hIcon = LoadIcon(os_w32_gfx_state->hInstance, MAKEINTRESOURCE(1)); + wndclass.hIcon = LoadIcon(w32_wm_state->hInstance, MAKEINTRESOURCE(1)); wndclass.style = CS_VREDRAW|CS_HREDRAW; ATOM wndatom = RegisterClassExW(&wndclass); (void)wndatom; @@ -875,121 +875,121 @@ os_gfx_init(void) //- rjf: grab graphics system info { - os_w32_gfx_state->gfx_info.double_click_time = GetDoubleClickTime()/1000.f; - os_w32_gfx_state->gfx_info.caret_blink_time = GetCaretBlinkTime()/1000.f; + w32_wm_state->gfx_info.double_click_time = GetDoubleClickTime()/1000.f; + w32_wm_state->gfx_info.caret_blink_time = GetCaretBlinkTime()/1000.f; DEVMODEW devmodew = {0}; if(EnumDisplaySettingsW(0, ENUM_CURRENT_SETTINGS, &devmodew)) { - os_w32_gfx_state->gfx_info.default_refresh_rate = (F32)devmodew.dmDisplayFrequency; + w32_wm_state->gfx_info.default_refresh_rate = (F32)devmodew.dmDisplayFrequency; } } //- rjf: set initial cursor - os_set_cursor(OS_Cursor_Pointer); + wm_set_cursor(WM_Cursor_Pointer); - //- rjf: fill vkey -> OS_Key table + //- rjf: fill vkey -> WM_Key table { - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'A'] = OS_Key_A; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'B'] = OS_Key_B; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'C'] = OS_Key_C; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'D'] = OS_Key_D; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'E'] = OS_Key_E; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'F'] = OS_Key_F; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'G'] = OS_Key_G; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'H'] = OS_Key_H; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'I'] = OS_Key_I; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'J'] = OS_Key_J; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'K'] = OS_Key_K; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'L'] = OS_Key_L; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'M'] = OS_Key_M; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'N'] = OS_Key_N; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'O'] = OS_Key_O; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'P'] = OS_Key_P; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'Q'] = OS_Key_Q; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'R'] = OS_Key_R; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'S'] = OS_Key_S; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'T'] = OS_Key_T; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'U'] = OS_Key_U; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'V'] = OS_Key_V; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'W'] = OS_Key_W; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'X'] = OS_Key_X; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'Y'] = OS_Key_Y; - os_w32_gfx_state->key_from_vkey_table[(unsigned int)'Z'] = OS_Key_Z; + w32_wm_state->key_from_vkey_table[(unsigned int)'A'] = WM_Key_A; + w32_wm_state->key_from_vkey_table[(unsigned int)'B'] = WM_Key_B; + w32_wm_state->key_from_vkey_table[(unsigned int)'C'] = WM_Key_C; + w32_wm_state->key_from_vkey_table[(unsigned int)'D'] = WM_Key_D; + w32_wm_state->key_from_vkey_table[(unsigned int)'E'] = WM_Key_E; + w32_wm_state->key_from_vkey_table[(unsigned int)'F'] = WM_Key_F; + w32_wm_state->key_from_vkey_table[(unsigned int)'G'] = WM_Key_G; + w32_wm_state->key_from_vkey_table[(unsigned int)'H'] = WM_Key_H; + w32_wm_state->key_from_vkey_table[(unsigned int)'I'] = WM_Key_I; + w32_wm_state->key_from_vkey_table[(unsigned int)'J'] = WM_Key_J; + w32_wm_state->key_from_vkey_table[(unsigned int)'K'] = WM_Key_K; + w32_wm_state->key_from_vkey_table[(unsigned int)'L'] = WM_Key_L; + w32_wm_state->key_from_vkey_table[(unsigned int)'M'] = WM_Key_M; + w32_wm_state->key_from_vkey_table[(unsigned int)'N'] = WM_Key_N; + w32_wm_state->key_from_vkey_table[(unsigned int)'O'] = WM_Key_O; + w32_wm_state->key_from_vkey_table[(unsigned int)'P'] = WM_Key_P; + w32_wm_state->key_from_vkey_table[(unsigned int)'Q'] = WM_Key_Q; + w32_wm_state->key_from_vkey_table[(unsigned int)'R'] = WM_Key_R; + w32_wm_state->key_from_vkey_table[(unsigned int)'S'] = WM_Key_S; + w32_wm_state->key_from_vkey_table[(unsigned int)'T'] = WM_Key_T; + w32_wm_state->key_from_vkey_table[(unsigned int)'U'] = WM_Key_U; + w32_wm_state->key_from_vkey_table[(unsigned int)'V'] = WM_Key_V; + w32_wm_state->key_from_vkey_table[(unsigned int)'W'] = WM_Key_W; + w32_wm_state->key_from_vkey_table[(unsigned int)'X'] = WM_Key_X; + w32_wm_state->key_from_vkey_table[(unsigned int)'Y'] = WM_Key_Y; + w32_wm_state->key_from_vkey_table[(unsigned int)'Z'] = WM_Key_Z; - for(U64 i = '0', j = OS_Key_0; i <= '9'; i += 1, j += 1) + for(U64 i = '0', j = WM_Key_0; i <= '9'; i += 1, j += 1) { - os_w32_gfx_state->key_from_vkey_table[i] = (OS_Key)j; + w32_wm_state->key_from_vkey_table[i] = (WM_Key)j; } - for(U64 i = VK_NUMPAD0, j = OS_Key_0; i <= VK_NUMPAD9; i += 1, j += 1) + for(U64 i = VK_NUMPAD0, j = WM_Key_0; i <= VK_NUMPAD9; i += 1, j += 1) { - os_w32_gfx_state->key_from_vkey_table[i] = (OS_Key)j; + w32_wm_state->key_from_vkey_table[i] = (WM_Key)j; } - for(U64 i = VK_F1, j = OS_Key_F1; i <= VK_F24; i += 1, j += 1) + for(U64 i = VK_F1, j = WM_Key_F1; i <= VK_F24; i += 1, j += 1) { - os_w32_gfx_state->key_from_vkey_table[i] = (OS_Key)j; + w32_wm_state->key_from_vkey_table[i] = (WM_Key)j; } - os_w32_gfx_state->key_from_vkey_table[VK_SPACE] = OS_Key_Space; - os_w32_gfx_state->key_from_vkey_table[VK_OEM_3] = OS_Key_Tick; - os_w32_gfx_state->key_from_vkey_table[VK_OEM_MINUS] = OS_Key_Minus; - os_w32_gfx_state->key_from_vkey_table[VK_OEM_PLUS] = OS_Key_Equal; - os_w32_gfx_state->key_from_vkey_table[VK_OEM_4] = OS_Key_LeftBracket; - os_w32_gfx_state->key_from_vkey_table[VK_OEM_6] = OS_Key_RightBracket; - os_w32_gfx_state->key_from_vkey_table[VK_OEM_1] = OS_Key_Semicolon; - os_w32_gfx_state->key_from_vkey_table[VK_OEM_7] = OS_Key_Quote; - os_w32_gfx_state->key_from_vkey_table[VK_OEM_COMMA] = OS_Key_Comma; - os_w32_gfx_state->key_from_vkey_table[VK_OEM_PERIOD]= OS_Key_Period; - os_w32_gfx_state->key_from_vkey_table[VK_OEM_2] = OS_Key_Slash; - os_w32_gfx_state->key_from_vkey_table[VK_OEM_5] = OS_Key_BackSlash; + w32_wm_state->key_from_vkey_table[VK_SPACE] = WM_Key_Space; + w32_wm_state->key_from_vkey_table[VK_OEM_3] = WM_Key_Tick; + w32_wm_state->key_from_vkey_table[VK_OEM_MINUS] = WM_Key_Minus; + w32_wm_state->key_from_vkey_table[VK_OEM_PLUS] = WM_Key_Equal; + w32_wm_state->key_from_vkey_table[VK_OEM_4] = WM_Key_LeftBracket; + w32_wm_state->key_from_vkey_table[VK_OEM_6] = WM_Key_RightBracket; + w32_wm_state->key_from_vkey_table[VK_OEM_1] = WM_Key_Semicolon; + w32_wm_state->key_from_vkey_table[VK_OEM_7] = WM_Key_Quote; + w32_wm_state->key_from_vkey_table[VK_OEM_COMMA] = WM_Key_Comma; + w32_wm_state->key_from_vkey_table[VK_OEM_PERIOD]= WM_Key_Period; + w32_wm_state->key_from_vkey_table[VK_OEM_2] = WM_Key_Slash; + w32_wm_state->key_from_vkey_table[VK_OEM_5] = WM_Key_BackSlash; - os_w32_gfx_state->key_from_vkey_table[VK_TAB] = OS_Key_Tab; - os_w32_gfx_state->key_from_vkey_table[VK_PAUSE] = OS_Key_Pause; - os_w32_gfx_state->key_from_vkey_table[VK_ESCAPE] = OS_Key_Esc; + w32_wm_state->key_from_vkey_table[VK_TAB] = WM_Key_Tab; + w32_wm_state->key_from_vkey_table[VK_PAUSE] = WM_Key_Pause; + w32_wm_state->key_from_vkey_table[VK_ESCAPE] = WM_Key_Esc; - os_w32_gfx_state->key_from_vkey_table[VK_UP] = OS_Key_Up; - os_w32_gfx_state->key_from_vkey_table[VK_LEFT] = OS_Key_Left; - os_w32_gfx_state->key_from_vkey_table[VK_DOWN] = OS_Key_Down; - os_w32_gfx_state->key_from_vkey_table[VK_RIGHT] = OS_Key_Right; + w32_wm_state->key_from_vkey_table[VK_UP] = WM_Key_Up; + w32_wm_state->key_from_vkey_table[VK_LEFT] = WM_Key_Left; + w32_wm_state->key_from_vkey_table[VK_DOWN] = WM_Key_Down; + w32_wm_state->key_from_vkey_table[VK_RIGHT] = WM_Key_Right; - os_w32_gfx_state->key_from_vkey_table[VK_BACK] = OS_Key_Backspace; - os_w32_gfx_state->key_from_vkey_table[VK_RETURN] = OS_Key_Return; + w32_wm_state->key_from_vkey_table[VK_BACK] = WM_Key_Backspace; + w32_wm_state->key_from_vkey_table[VK_RETURN] = WM_Key_Return; - os_w32_gfx_state->key_from_vkey_table[VK_DELETE] = OS_Key_Delete; - os_w32_gfx_state->key_from_vkey_table[VK_INSERT] = OS_Key_Insert; - os_w32_gfx_state->key_from_vkey_table[VK_PRIOR] = OS_Key_PageUp; - os_w32_gfx_state->key_from_vkey_table[VK_NEXT] = OS_Key_PageDown; - os_w32_gfx_state->key_from_vkey_table[VK_HOME] = OS_Key_Home; - os_w32_gfx_state->key_from_vkey_table[VK_END] = OS_Key_End; + w32_wm_state->key_from_vkey_table[VK_DELETE] = WM_Key_Delete; + w32_wm_state->key_from_vkey_table[VK_INSERT] = WM_Key_Insert; + w32_wm_state->key_from_vkey_table[VK_PRIOR] = WM_Key_PageUp; + w32_wm_state->key_from_vkey_table[VK_NEXT] = WM_Key_PageDown; + w32_wm_state->key_from_vkey_table[VK_HOME] = WM_Key_Home; + w32_wm_state->key_from_vkey_table[VK_END] = WM_Key_End; - os_w32_gfx_state->key_from_vkey_table[VK_CAPITAL] = OS_Key_CapsLock; - os_w32_gfx_state->key_from_vkey_table[VK_NUMLOCK] = OS_Key_NumLock; - os_w32_gfx_state->key_from_vkey_table[VK_SCROLL] = OS_Key_ScrollLock; - os_w32_gfx_state->key_from_vkey_table[VK_APPS] = OS_Key_Menu; + w32_wm_state->key_from_vkey_table[VK_CAPITAL] = WM_Key_CapsLock; + w32_wm_state->key_from_vkey_table[VK_NUMLOCK] = WM_Key_NumLock; + w32_wm_state->key_from_vkey_table[VK_SCROLL] = WM_Key_ScrollLock; + w32_wm_state->key_from_vkey_table[VK_APPS] = WM_Key_Menu; - os_w32_gfx_state->key_from_vkey_table[VK_CONTROL] = OS_Key_Ctrl; - os_w32_gfx_state->key_from_vkey_table[VK_LCONTROL] = OS_Key_Ctrl; - os_w32_gfx_state->key_from_vkey_table[VK_RCONTROL] = OS_Key_Ctrl; - os_w32_gfx_state->key_from_vkey_table[VK_SHIFT] = OS_Key_Shift; - os_w32_gfx_state->key_from_vkey_table[VK_LSHIFT] = OS_Key_Shift; - os_w32_gfx_state->key_from_vkey_table[VK_RSHIFT] = OS_Key_Shift; - os_w32_gfx_state->key_from_vkey_table[VK_MENU] = OS_Key_Alt; - os_w32_gfx_state->key_from_vkey_table[VK_LMENU] = OS_Key_Alt; - os_w32_gfx_state->key_from_vkey_table[VK_RMENU] = OS_Key_Alt; + w32_wm_state->key_from_vkey_table[VK_CONTROL] = WM_Key_Ctrl; + w32_wm_state->key_from_vkey_table[VK_LCONTROL] = WM_Key_Ctrl; + w32_wm_state->key_from_vkey_table[VK_RCONTROL] = WM_Key_Ctrl; + w32_wm_state->key_from_vkey_table[VK_SHIFT] = WM_Key_Shift; + w32_wm_state->key_from_vkey_table[VK_LSHIFT] = WM_Key_Shift; + w32_wm_state->key_from_vkey_table[VK_RSHIFT] = WM_Key_Shift; + w32_wm_state->key_from_vkey_table[VK_MENU] = WM_Key_Alt; + w32_wm_state->key_from_vkey_table[VK_LMENU] = WM_Key_Alt; + w32_wm_state->key_from_vkey_table[VK_RMENU] = WM_Key_Alt; - os_w32_gfx_state->key_from_vkey_table[VK_DIVIDE] = OS_Key_NumSlash; - os_w32_gfx_state->key_from_vkey_table[VK_MULTIPLY] = OS_Key_NumStar; - os_w32_gfx_state->key_from_vkey_table[VK_SUBTRACT] = OS_Key_NumMinus; - os_w32_gfx_state->key_from_vkey_table[VK_ADD] = OS_Key_NumPlus; - os_w32_gfx_state->key_from_vkey_table[VK_DECIMAL] = OS_Key_NumPeriod; + w32_wm_state->key_from_vkey_table[VK_DIVIDE] = WM_Key_NumSlash; + w32_wm_state->key_from_vkey_table[VK_MULTIPLY] = WM_Key_NumStar; + w32_wm_state->key_from_vkey_table[VK_SUBTRACT] = WM_Key_NumMinus; + w32_wm_state->key_from_vkey_table[VK_ADD] = WM_Key_NumPlus; + w32_wm_state->key_from_vkey_table[VK_DECIMAL] = WM_Key_NumPeriod; for(U32 i = 0; i < 10; i += 1) { - os_w32_gfx_state->key_from_vkey_table[VK_NUMPAD0 + i] = (OS_Key)((U64)OS_Key_Num0 + i); + w32_wm_state->key_from_vkey_table[VK_NUMPAD0 + i] = (WM_Key)((U64)WM_Key_Num0 + i); } for(U64 i = 0xDF, j = 0; i < 0xFF; i += 1, j += 1) { - os_w32_gfx_state->key_from_vkey_table[i] = (OS_Key)((U64)OS_Key_Ex0 + j); + w32_wm_state->key_from_vkey_table[i] = (WM_Key)((U64)WM_Key_Ex0 + j); } } } @@ -997,17 +997,17 @@ os_gfx_init(void) //////////////////////////////// //~ rjf: @os_hooks Graphics System Info (Implemented Per-OS) -internal OS_GfxInfo * -os_get_gfx_info(void) +internal WM_SystemInfo * +wm_get_system_info(void) { - return &os_w32_gfx_state->gfx_info; + return &w32_wm_state->gfx_info; } //////////////////////////////// //~ rjf: @os_hooks Clipboards (Implemented Per-OS) internal void -os_set_clipboard_text(String8 string) +wm_set_clipboard_text(String8 string) { Temp scratch = scratch_begin(0, 0); if(OpenClipboard(0)) @@ -1029,7 +1029,7 @@ os_set_clipboard_text(String8 string) } internal String8 -os_get_clipboard_text(Arena *arena) +wm_get_clipboard_text(Arena *arena) { String8 result = {0}; if(IsClipboardFormatAvailable(CF_UNICODETEXT) && @@ -1055,11 +1055,11 @@ os_get_clipboard_text(Arena *arena) //////////////////////////////// //~ rjf: @os_hooks Windows (Implemented Per-OS) -internal OS_Window -os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title) +internal WM_Window +wm_window_open(Rng2F32 rect, WM_WindowFlags flags, String8 title) { - B32 custom_border = !!(flags & OS_WindowFlag_CustomBorder); - B32 use_default_position = !!(flags & OS_WindowFlag_UseDefaultPosition); + B32 custom_border = !!(flags & WM_WindowFlag_CustomBorder); + B32 use_default_position = !!(flags & WM_WindowFlag_UseDefaultPosition); Vec2F32 pos = rect.p0; Vec2F32 dim = dim_2f32(rect); @@ -1068,7 +1068,7 @@ os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title) { Temp scratch = scratch_begin(0, 0); String16 title16 = str16_from_8(scratch.arena, title); - os_w32_new_window_custom_border = custom_border; + w32_wm_new_window_custom_border = custom_border; DWORD style_flags = WS_EX_APPWINDOW; #if defined(R_BACKEND) && R_BACKEND != R_BACKEND_OPENGL style_flags |= WS_EX_NOREDIRECTIONBITMAP; @@ -1082,15 +1082,15 @@ os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title) (S32)dim.x, (S32)dim.y, 0, 0, - os_w32_gfx_state->hInstance, + w32_wm_state->hInstance, 0); DragAcceptFiles(hwnd, 1); - os_w32_new_window_custom_border = 0; + w32_wm_new_window_custom_border = 0; scratch_end(scratch); } //- rjf- make/fill window - OS_W32_Window *window = os_w32_window_alloc(); + W32_WM_Window *window = w32_wm_window_alloc(); { window->hwnd = hwnd; window->hdc = GetDC(hwnd); @@ -1112,38 +1112,38 @@ os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title) } //- rjf: custom border - if(flags & OS_WindowFlag_CustomBorder) + if(flags & WM_WindowFlag_CustomBorder) { window->custom_border = 1; window->paint_arena = arena_alloc(); } //- rjf: convert to handle + return - OS_Window result = os_w32_handle_from_window(window); + WM_Window result = w32_wm_handle_from_window(window); return result; } internal void -os_window_close(OS_Window handle) +wm_window_close(WM_Window handle) { - OS_W32_Window *window = os_w32_window_from_handle(handle); - os_w32_window_release(window); + W32_WM_Window *window = w32_wm_window_from_handle(handle); + w32_wm_window_release(window); } internal void -os_window_set_title(OS_Window handle, String8 title) +wm_window_set_title(WM_Window handle, String8 title) { Temp scratch = scratch_begin(0, 0); - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); String16 title16 = str16_from_8(scratch.arena, title); SetWindowTextW(window->hwnd, (WCHAR *)title16.str); scratch_end(scratch); } internal void -os_window_first_paint(OS_Window window_handle) +wm_window_first_paint(WM_Window window_handle) { - OS_W32_Window *window = os_w32_window_from_handle(window_handle); + W32_WM_Window *window = w32_wm_window_from_handle(window_handle); window->first_paint_done = 1; ShowWindow(window->hwnd, SW_SHOW); if(window->maximized) @@ -1153,35 +1153,35 @@ os_window_first_paint(OS_Window window_handle) } internal void -os_window_focus(OS_Window handle) +wm_window_focus(WM_Window handle) { - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); SetForegroundWindow(window->hwnd); SetFocus(window->hwnd); } internal B32 -os_window_is_focused(OS_Window handle) +wm_window_is_focused(WM_Window handle) { - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); HWND active_hwnd = GetActiveWindow(); return active_hwnd == window->hwnd; } internal B32 -os_window_is_fullscreen(OS_Window handle) +wm_window_is_fullscreen(WM_Window handle) { - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); DWORD window_style = GetWindowLong(window->hwnd, GWL_STYLE); return !(window_style & WS_OVERLAPPEDWINDOW); } internal void -os_window_set_fullscreen(OS_Window handle, B32 fullscreen) +wm_window_set_fullscreen(WM_Window handle, B32 fullscreen) { - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); DWORD window_style = GetWindowLong(window->hwnd, GWL_STYLE); - B32 is_fullscreen_already = os_window_is_fullscreen(handle); + B32 is_fullscreen_already = wm_window_is_fullscreen(handle); if(fullscreen) { if(!is_fullscreen_already) @@ -1211,10 +1211,10 @@ os_window_set_fullscreen(OS_Window handle, B32 fullscreen) } internal B32 -os_window_is_maximized(OS_Window handle) +wm_window_is_maximized(WM_Window handle) { B32 result = 0; - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); if(window) { result = !!(IsZoomed(window->hwnd)); @@ -1223,9 +1223,9 @@ os_window_is_maximized(OS_Window handle) } internal void -os_window_set_maximized(OS_Window handle, B32 maximized) +wm_window_set_maximized(WM_Window handle, B32 maximized) { - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); if(window != 0) { if(window->first_paint_done) @@ -1245,10 +1245,10 @@ os_window_set_maximized(OS_Window handle, B32 maximized) } internal B32 -os_window_is_minimized(OS_Window handle) +wm_window_is_minimized(WM_Window handle) { B32 result = 0; - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); if(window) { result = !!(IsIconic(window->hwnd)); @@ -1257,10 +1257,10 @@ os_window_is_minimized(OS_Window handle) } internal void -os_window_set_minimized(OS_Window handle, B32 minimized) +wm_window_set_minimized(WM_Window handle, B32 minimized) { - OS_W32_Window *window = os_w32_window_from_handle(handle); - if(window != 0 && minimized != os_window_is_minimized(handle)) + W32_WM_Window *window = w32_wm_window_from_handle(handle); + if(window != 0 && minimized != wm_window_is_minimized(handle)) { switch(minimized) { @@ -1272,9 +1272,9 @@ os_window_set_minimized(OS_Window handle, B32 minimized) } internal void -os_window_bring_to_front(OS_Window handle) +wm_window_bring_to_front(WM_Window handle) { - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); if(window != 0) { BringWindowToTop(window->hwnd); @@ -1282,16 +1282,16 @@ os_window_bring_to_front(OS_Window handle) } internal void -os_window_set_monitor(OS_Window window_handle, OS_Monitor monitor) +wm_window_set_monitor(WM_Window window_handle, WM_Monitor monitor) { - OS_W32_Window *window = os_w32_window_from_handle(window_handle); + W32_WM_Window *window = w32_wm_window_from_handle(window_handle); HMONITOR hmonitor = (HMONITOR)monitor.u64[0]; { MONITORINFOEXW info; info.cbSize = sizeof(MONITORINFOEXW); if(GetMonitorInfoW(hmonitor, (MONITORINFO *)&info)) { - Rng2F32 existing_rect = os_rect_from_window(window_handle); + Rng2F32 existing_rect = wm_rect_from_window(window_handle); Vec2F32 window_size = dim_2f32(existing_rect); SetWindowPos(window->hwnd, HWND_TOP, (info.rcWork.left + info.rcWork.right)/2 - window_size.x/2, @@ -1303,9 +1303,9 @@ os_window_set_monitor(OS_Window window_handle, OS_Monitor monitor) } internal void -os_window_clear_custom_border_data(OS_Window handle) +wm_window_clear_custom_border_data(WM_Window handle) { - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); if(window->custom_border) { arena_clear(window->paint_arena); @@ -1316,26 +1316,26 @@ os_window_clear_custom_border_data(OS_Window handle) } internal void -os_window_push_custom_title_bar(OS_Window handle, F32 thickness) +wm_window_push_custom_title_bar(WM_Window handle, F32 thickness) { - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); window->custom_border_title_thickness = thickness; } internal void -os_window_push_custom_edges(OS_Window handle, F32 thickness) +wm_window_push_custom_edges(WM_Window handle, F32 thickness) { - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); window->custom_border_edge_thickness = thickness; } internal void -os_window_push_custom_title_bar_client_area(OS_Window handle, Rng2F32 rect) +wm_window_push_custom_title_bar_client_area(WM_Window handle, Rng2F32 rect) { - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); if(window->custom_border) { - OS_W32_TitleBarClientArea *area = push_array(window->paint_arena, OS_W32_TitleBarClientArea, 1); + W32_WM_TitleBarClientArea *area = push_array(window->paint_arena, W32_WM_TitleBarClientArea, 1); if(area != 0) { area->rect = rect; @@ -1345,38 +1345,38 @@ os_window_push_custom_title_bar_client_area(OS_Window handle, Rng2F32 rect) } internal Rng2F32 -os_rect_from_window(OS_Window handle) +wm_rect_from_window(WM_Window handle) { Rng2F32 r = {0}; - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); if(window) { RECT rect = {0}; - GetWindowRect(os_w32_hwnd_from_window(window), &rect); - r = os_w32_rng2f32_from_rect(rect); + GetWindowRect(w32_wm_hwnd_from_window(window), &rect); + r = w32_wm_rng2f32_from_rect(rect); } return r; } internal Rng2F32 -os_client_rect_from_window(OS_Window handle) +wm_client_rect_from_window(WM_Window handle) { Rng2F32 r = {0}; - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); if(window) { RECT rect = {0}; - GetClientRect(os_w32_hwnd_from_window(window), &rect); - r = os_w32_rng2f32_from_rect(rect); + GetClientRect(w32_wm_hwnd_from_window(window), &rect); + r = w32_wm_rng2f32_from_rect(rect); } return r; } internal F32 -os_dpi_from_window(OS_Window handle) +wm_dpi_from_window(WM_Window handle) { F32 result = 96.f; - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); if(window != 0) { result = window->dpi; @@ -1387,16 +1387,16 @@ os_dpi_from_window(OS_Window handle) //////////////////////////////// //~ rjf: @os_hooks External Windows (Implemented Per-OS) -internal OS_ExternalWindow -os_focused_external_window(void) +internal WM_ExtWindow +wm_focused_external_window(void) { HWND hwnd = GetForegroundWindow(); - OS_ExternalWindow result = {(U64)hwnd}; + WM_ExtWindow result = {(U64)hwnd}; return result; } internal void -os_focus_external_window(OS_ExternalWindow handle) +wm_focus_external_window(WM_ExtWindow handle) { HWND hwnd = (HWND)handle.u64[0]; if(hwnd != 0) @@ -1409,18 +1409,18 @@ os_focus_external_window(OS_ExternalWindow handle) //////////////////////////////// //~ rjf: @os_hooks Monitors (Implemented Per-OS) -internal OS_MonitorArray -os_push_monitors_array(Arena *arena) +internal WM_MonitorArray +wm_push_monitors_array(Arena *arena) { Temp scratch = scratch_begin(&arena, 1); - OS_W32_MonitorGatherBundle bundle = {arena}; - EnumDisplayMonitors(0, 0, os_w32_monitor_gather_enum_proc, (LPARAM)&bundle); - OS_MonitorArray array = {0}; + W32_WM_MonitorGatherBundle bundle = {arena}; + EnumDisplayMonitors(0, 0, w32_wm_monitor_gather_enum_proc, (LPARAM)&bundle); + WM_MonitorArray array = {0}; array.count = bundle.monitor_count; - array.v = push_array(arena, OS_Monitor, array.count); + array.v = push_array(arena, WM_Monitor, array.count); { U64 idx = 0; - for EachNode(n, OS_W32_MonitorGatherNode, bundle.first_monitor) + for EachNode(n, W32_WM_MonitorGatherNode, bundle.first_monitor) { array.v[idx] = n->v; idx += 1; @@ -1430,26 +1430,26 @@ os_push_monitors_array(Arena *arena) return array; } -internal OS_Monitor -os_primary_monitor(void) +internal WM_Monitor +wm_primary_monitor(void) { POINT zero_pt = {0, 0}; HMONITOR monitor = MonitorFromPoint(zero_pt, MONITOR_DEFAULTTOPRIMARY); - OS_Monitor result = {(U64)monitor}; + WM_Monitor result = {(U64)monitor}; return result; } -internal OS_Monitor -os_monitor_from_window(OS_Window window) +internal WM_Monitor +wm_monitor_from_window(WM_Window window) { - OS_W32_Window *w = os_w32_window_from_handle(window); + W32_WM_Window *w = w32_wm_window_from_handle(window); HMONITOR handle = MonitorFromWindow(w->hwnd, MONITOR_DEFAULTTOPRIMARY); - OS_Monitor result = {(U64)handle}; + WM_Monitor result = {(U64)handle}; return result; } internal String8 -os_name_from_monitor(Arena *arena, OS_Monitor monitor) +wm_name_from_monitor(Arena *arena, WM_Monitor monitor) { String8 result = {0}; HMONITOR monitor_handle = (HMONITOR)monitor.u64[0]; @@ -1464,7 +1464,7 @@ os_name_from_monitor(Arena *arena, OS_Monitor monitor) } internal Vec2F32 -os_dim_from_monitor(OS_Monitor monitor) +wm_dim_from_monitor(WM_Monitor monitor) { Vec2F32 result = {0}; HMONITOR monitor_handle = (HMONITOR)monitor.u64[0]; @@ -1479,7 +1479,7 @@ os_dim_from_monitor(OS_Monitor monitor) } internal F32 -os_dpi_from_monitor(OS_Monitor monitor) +wm_dpi_from_monitor(WM_Monitor monitor) { F32 result = 96.f; HMONITOR monitor_handle = (HMONITOR)monitor.u64[0]; @@ -1497,16 +1497,16 @@ os_dpi_from_monitor(OS_Monitor monitor) //~ rjf: @os_hooks Events (Implemented Per-OS) internal void -os_send_wakeup_event(void) +wm_send_wakeup_event(void) { - PostThreadMessageA(os_w32_gfx_state->gfx_thread_tid, 0x401, 0, 0); + PostThreadMessageA(w32_wm_state->gfx_thread_tid, 0x401, 0, 0); } -internal OS_EventList -os_get_events(Arena *arena, B32 wait) +internal WM_EventList +wm_get_events(Arena *arena, B32 wait) { - os_w32_event_arena = arena; - MemoryZeroStruct(&os_w32_event_list); + w32_wm_event_arena = arena; + MemoryZeroStruct(&w32_wm_event_list); MSG msg = {0}; if(!wait || GetMessage(&msg, 0, 0, 0)) { @@ -1517,37 +1517,37 @@ os_get_events(Arena *arena, B32 wait) TranslateMessage(&msg); if(msg.message == WM_QUIT) { - os_w32_push_event(OS_EventKind_WindowClose, 0); + w32_wm_push_event(WM_EventKind_WindowClose, 0); } } } - return os_w32_event_list; + return w32_wm_event_list; } -internal OS_Modifiers -os_get_modifiers(void) +internal WM_Modifiers +wm_get_modifiers(void) { - OS_Modifiers modifiers = 0; + WM_Modifiers modifiers = 0; if(GetKeyState(VK_CONTROL) & 0x8000) { - modifiers |= OS_Modifier_Ctrl; + modifiers |= WM_Modifier_Ctrl; } if(GetKeyState(VK_SHIFT) & 0x8000) { - modifiers |= OS_Modifier_Shift; + modifiers |= WM_Modifier_Shift; } if(GetKeyState(VK_MENU) & 0x8000) { - modifiers |= OS_Modifier_Alt; + modifiers |= WM_Modifier_Alt; } return modifiers; } internal B32 -os_key_is_down(OS_Key key) +wm_key_is_down(WM_Key key) { B32 down = 0; - WPARAM vkey = os_w32_vkey_from_os_key(key); + WPARAM vkey = w32_wm_vkey_from_os_key(key); if(GetKeyState(vkey) & 0x8000) { down = 1; @@ -1556,14 +1556,14 @@ os_key_is_down(OS_Key key) } internal Vec2F32 -os_mouse_from_window(OS_Window handle) +wm_mouse_from_window(WM_Window handle) { ProfBeginFunction(); Vec2F32 v = {0}; POINT p; if(GetCursorPos(&p)) { - OS_W32_Window *window = os_w32_window_from_handle(handle); + W32_WM_Window *window = w32_wm_window_from_handle(handle); ScreenToClient(window->hwnd, &p); v.x = (F32)p.x; v.y = (F32)p.y; @@ -1576,7 +1576,7 @@ os_mouse_from_window(OS_Window handle) //~ rjf: @os_hooks Cursors (Implemented Per-OS) internal void -os_set_cursor(OS_Cursor cursor) +wm_set_cursor(WM_Cursor cursor) { B32 valid_cursor = 1; HCURSOR hcursor = 0; @@ -1593,7 +1593,7 @@ X(UpRight, IDC_SIZENESW) \ X(UpDownLeftRight, IDC_SIZEALL) \ X(HandPoint, IDC_HAND)\ X(Disabled, IDC_NO) -#define CursorCase(E,R) case OS_Cursor_##E:{ \ +#define CursorCase(E,R) case WM_Cursor_##E:{ \ local_persist HCURSOR curs = 0; \ if (curs == 0){ curs = LoadCursor(NULL, R); } \ hcursor = curs; }break; @@ -1601,16 +1601,16 @@ hcursor = curs; }break; #undef CursorCase #undef Win32CursorXList } - if(valid_cursor && !os_w32_resizing) + if(valid_cursor && !w32_wm_resizing) { - if(hcursor != os_w32_gfx_state->hCursor) + if(hcursor != w32_wm_state->hCursor) { PostMessage(0, WM_SETCURSOR, 0, 0); POINT p = {0}; GetCursorPos(&p); SetCursorPos(p.x, p.y); } - os_w32_gfx_state->hCursor = hcursor; + w32_wm_state->hCursor = hcursor; } } @@ -1618,7 +1618,7 @@ hcursor = curs; }break; //~ rjf: @os_hooks Native User-Facing Graphical Messages (Implemented Per-OS) internal void -os_graphical_message(B32 error, String8 title, String8 message) +wm_graphical_message(B32 error, String8 title, String8 message) { Temp scratch = scratch_begin(0, 0); String16 title16 = str16_from_8(scratch.arena, title); @@ -1628,7 +1628,7 @@ os_graphical_message(B32 error, String8 title, String8 message) } internal String8 -os_graphical_pick_file(Arena *arena, String8 initial_path) +wm_graphical_pick_file(Arena *arena, String8 initial_path) { String8 result = {0}; { @@ -1654,7 +1654,7 @@ os_graphical_pick_file(Arena *arena, String8 initial_path) //~ rjf: @os_hooks Shell Operations internal void -os_show_in_filesystem_ui(String8 path) +wm_show_in_filesystem_ui(String8 path) { Temp scratch = scratch_begin(0, 0); String8 path_copy = push_str8_copy(scratch.arena, path); @@ -1678,7 +1678,7 @@ os_show_in_filesystem_ui(String8 path) } internal void -os_open_in_browser(String8 url) +wm_open_in_browser(String8 url) { Temp scratch = scratch_begin(0, 0); String16 url16 = str16_from_8(scratch.arena, url); diff --git a/src/win32/window_manager/win32_window_manager.h b/src/win32/window_manager/win32_window_manager.h index 90548121..6dd068c2 100644 --- a/src/win32/window_manager/win32_window_manager.h +++ b/src/win32/window_manager/win32_window_manager.h @@ -24,18 +24,18 @@ //////////////////////////////// //~ rjf: Windows -typedef struct OS_W32_TitleBarClientArea OS_W32_TitleBarClientArea; -struct OS_W32_TitleBarClientArea +typedef struct W32_WM_TitleBarClientArea W32_WM_TitleBarClientArea; +struct W32_WM_TitleBarClientArea { - OS_W32_TitleBarClientArea *next; + W32_WM_TitleBarClientArea *next; Rng2F32 rect; }; -typedef struct OS_W32_Window OS_W32_Window; -struct OS_W32_Window +typedef struct W32_WM_Window W32_WM_Window; +struct W32_WM_Window { - OS_W32_Window *next; - OS_W32_Window *prev; + W32_WM_Window *next; + W32_WM_Window *prev; HWND hwnd; HDC hdc; WINDOWPLACEMENT last_window_placement; @@ -47,77 +47,77 @@ struct OS_W32_Window F32 custom_border_edge_thickness; B32 custom_border_composition_enabled; Arena *paint_arena; - OS_W32_TitleBarClientArea *first_title_bar_client_area; - OS_W32_TitleBarClientArea *last_title_bar_client_area; + W32_WM_TitleBarClientArea *first_title_bar_client_area; + W32_WM_TitleBarClientArea *last_title_bar_client_area; }; //////////////////////////////// //~ rjf: Monitor Gathering Bundle -typedef struct OS_W32_MonitorGatherNode OS_W32_MonitorGatherNode; -struct OS_W32_MonitorGatherNode +typedef struct W32_WM_MonitorGatherNode W32_WM_MonitorGatherNode; +struct W32_WM_MonitorGatherNode { - OS_W32_MonitorGatherNode *next; - OS_Monitor v; + W32_WM_MonitorGatherNode *next; + WM_Monitor v; }; -typedef struct OS_W32_MonitorGatherBundle OS_W32_MonitorGatherBundle; -struct OS_W32_MonitorGatherBundle +typedef struct W32_WM_MonitorGatherBundle W32_WM_MonitorGatherBundle; +struct W32_WM_MonitorGatherBundle { Arena *arena; - OS_W32_MonitorGatherNode *first_monitor; - OS_W32_MonitorGatherNode *last_monitor; + W32_WM_MonitorGatherNode *first_monitor; + W32_WM_MonitorGatherNode *last_monitor; U64 monitor_count; }; //////////////////////////////// //~ rjf: Global State -typedef struct OS_W32_GfxState OS_W32_GfxState; -struct OS_W32_GfxState +typedef struct W32_WM_State W32_WM_State; +struct W32_WM_State { Arena *arena; U32 gfx_thread_tid; HINSTANCE hInstance; HCURSOR hCursor; - OS_GfxInfo gfx_info; - OS_W32_Window *first_window; - OS_W32_Window *last_window; - OS_W32_Window *free_window; - OS_Key key_from_vkey_table[256]; + WM_SystemInfo gfx_info; + W32_WM_Window *first_window; + W32_WM_Window *last_window; + W32_WM_Window *free_window; + WM_Key key_from_vkey_table[256]; }; //////////////////////////////// //~ rjf: Globals -global OS_W32_GfxState *os_w32_gfx_state = 0; -global OS_EventList os_w32_event_list = {0}; -global Arena *os_w32_event_arena = 0; -global B32 os_w32_resizing = 0; -global B32 os_w32_new_window_custom_border = 0; +global W32_WM_State *w32_wm_state = 0; +global WM_EventList w32_wm_event_list = {0}; +global Arena *w32_wm_event_arena = 0; +global B32 w32_wm_resizing = 0; +global B32 w32_wm_new_window_custom_border = 0; //////////////////////////////// //~ rjf: Basic Helpers -internal Rng2F32 os_w32_rng2f32_from_rect(RECT rect); +internal Rng2F32 w32_wm_rng2f32_from_rect(RECT rect); //////////////////////////////// //~ rjf: Windows -internal OS_Window os_w32_handle_from_window(OS_W32_Window *window); -internal OS_W32_Window * os_w32_window_from_handle(OS_Window window); -internal OS_W32_Window * os_w32_window_from_hwnd(HWND hwnd); -internal HWND os_w32_hwnd_from_window(OS_W32_Window *window); -internal OS_W32_Window * os_w32_window_alloc(void); -internal void os_w32_window_release(OS_W32_Window *window); -internal OS_Event * os_w32_push_event(OS_EventKind kind, OS_W32_Window *window); -internal OS_Key os_w32_os_key_from_vkey(WPARAM vkey); -internal WPARAM os_w32_vkey_from_os_key(OS_Key key); -internal LRESULT os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +internal WM_Window w32_wm_handle_from_window(W32_WM_Window *window); +internal W32_WM_Window * w32_wm_window_from_handle(WM_Window window); +internal W32_WM_Window * w32_wm_window_from_hwnd(HWND hwnd); +internal HWND w32_wm_hwnd_from_window(W32_WM_Window *window); +internal W32_WM_Window * w32_wm_window_alloc(void); +internal void w32_wm_window_release(W32_WM_Window *window); +internal WM_Event * w32_wm_push_event(WM_EventKind kind, W32_WM_Window *window); +internal WM_Key w32_wm_os_key_from_vkey(WPARAM vkey); +internal WPARAM w32_wm_vkey_from_os_key(WM_Key key); +internal LRESULT w32_wm_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); //////////////////////////////// //~ rjf: Monitors -internal BOOL os_w32_monitor_gather_enum_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM bundle_ptr); +internal BOOL w32_wm_monitor_gather_enum_proc(HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM bundle_ptr); #endif // WIN32_WINDOW_MANAGER_H diff --git a/src/window_manager/generated/window_manager.meta.c b/src/window_manager/generated/window_manager.meta.c index a3f50334..555a6239 100644 --- a/src/window_manager/generated/window_manager.meta.c +++ b/src/window_manager/generated/window_manager.meta.c @@ -4,7 +4,7 @@ //- GENERATED CODE C_LINKAGE_BEGIN -String8 os_g_key_display_string_table[143] = +String8 wm_key_display_name_table[143] = { str8_lit_comp("Invalid Key"), str8_lit_comp("Escape"), @@ -151,7 +151,7 @@ str8_lit_comp("Middle Mouse Button"), str8_lit_comp("Right Mouse Button"), }; -String8 os_g_key_cfg_string_table[143] = +String8 wm_key_cfg_name_table[143] = { str8_lit_comp("null"), str8_lit_comp("esc"), diff --git a/src/window_manager/generated/window_manager.meta.h b/src/window_manager/generated/window_manager.meta.h index b81d453f..f5772be4 100644 --- a/src/window_manager/generated/window_manager.meta.h +++ b/src/window_manager/generated/window_manager.meta.h @@ -6,157 +6,157 @@ #ifndef WINDOW_MANAGER_META_H #define WINDOW_MANAGER_META_H -typedef enum OS_Key +typedef enum WM_Key { -OS_Key_Null, -OS_Key_Esc, -OS_Key_F1, -OS_Key_F2, -OS_Key_F3, -OS_Key_F4, -OS_Key_F5, -OS_Key_F6, -OS_Key_F7, -OS_Key_F8, -OS_Key_F9, -OS_Key_F10, -OS_Key_F11, -OS_Key_F12, -OS_Key_F13, -OS_Key_F14, -OS_Key_F15, -OS_Key_F16, -OS_Key_F17, -OS_Key_F18, -OS_Key_F19, -OS_Key_F20, -OS_Key_F21, -OS_Key_F22, -OS_Key_F23, -OS_Key_F24, -OS_Key_Tick, -OS_Key_0, -OS_Key_1, -OS_Key_2, -OS_Key_3, -OS_Key_4, -OS_Key_5, -OS_Key_6, -OS_Key_7, -OS_Key_8, -OS_Key_9, -OS_Key_Minus, -OS_Key_Equal, -OS_Key_Backspace, -OS_Key_Tab, -OS_Key_Q, -OS_Key_W, -OS_Key_E, -OS_Key_R, -OS_Key_T, -OS_Key_Y, -OS_Key_U, -OS_Key_I, -OS_Key_O, -OS_Key_P, -OS_Key_LeftBracket, -OS_Key_RightBracket, -OS_Key_BackSlash, -OS_Key_CapsLock, -OS_Key_A, -OS_Key_S, -OS_Key_D, -OS_Key_F, -OS_Key_G, -OS_Key_H, -OS_Key_J, -OS_Key_K, -OS_Key_L, -OS_Key_Semicolon, -OS_Key_Quote, -OS_Key_Return, -OS_Key_Shift, -OS_Key_Z, -OS_Key_X, -OS_Key_C, -OS_Key_V, -OS_Key_B, -OS_Key_N, -OS_Key_M, -OS_Key_Comma, -OS_Key_Period, -OS_Key_Slash, -OS_Key_Ctrl, -OS_Key_Alt, -OS_Key_Space, -OS_Key_Menu, -OS_Key_ScrollLock, -OS_Key_Pause, -OS_Key_Insert, -OS_Key_Home, -OS_Key_PageUp, -OS_Key_Delete, -OS_Key_End, -OS_Key_PageDown, -OS_Key_Up, -OS_Key_Left, -OS_Key_Down, -OS_Key_Right, -OS_Key_Ex0, -OS_Key_Ex1, -OS_Key_Ex2, -OS_Key_Ex3, -OS_Key_Ex4, -OS_Key_Ex5, -OS_Key_Ex6, -OS_Key_Ex7, -OS_Key_Ex8, -OS_Key_Ex9, -OS_Key_Ex10, -OS_Key_Ex11, -OS_Key_Ex12, -OS_Key_Ex13, -OS_Key_Ex14, -OS_Key_Ex15, -OS_Key_Ex16, -OS_Key_Ex17, -OS_Key_Ex18, -OS_Key_Ex19, -OS_Key_Ex20, -OS_Key_Ex21, -OS_Key_Ex22, -OS_Key_Ex23, -OS_Key_Ex24, -OS_Key_Ex25, -OS_Key_Ex26, -OS_Key_Ex27, -OS_Key_Ex28, -OS_Key_Ex29, -OS_Key_NumLock, -OS_Key_NumSlash, -OS_Key_NumStar, -OS_Key_NumMinus, -OS_Key_NumPlus, -OS_Key_NumPeriod, -OS_Key_Num0, -OS_Key_Num1, -OS_Key_Num2, -OS_Key_Num3, -OS_Key_Num4, -OS_Key_Num5, -OS_Key_Num6, -OS_Key_Num7, -OS_Key_Num8, -OS_Key_Num9, -OS_Key_LeftMouseButton, -OS_Key_MiddleMouseButton, -OS_Key_RightMouseButton, -OS_Key_COUNT, -} OS_Key; +WM_Key_Null, +WM_Key_Esc, +WM_Key_F1, +WM_Key_F2, +WM_Key_F3, +WM_Key_F4, +WM_Key_F5, +WM_Key_F6, +WM_Key_F7, +WM_Key_F8, +WM_Key_F9, +WM_Key_F10, +WM_Key_F11, +WM_Key_F12, +WM_Key_F13, +WM_Key_F14, +WM_Key_F15, +WM_Key_F16, +WM_Key_F17, +WM_Key_F18, +WM_Key_F19, +WM_Key_F20, +WM_Key_F21, +WM_Key_F22, +WM_Key_F23, +WM_Key_F24, +WM_Key_Tick, +WM_Key_0, +WM_Key_1, +WM_Key_2, +WM_Key_3, +WM_Key_4, +WM_Key_5, +WM_Key_6, +WM_Key_7, +WM_Key_8, +WM_Key_9, +WM_Key_Minus, +WM_Key_Equal, +WM_Key_Backspace, +WM_Key_Tab, +WM_Key_Q, +WM_Key_W, +WM_Key_E, +WM_Key_R, +WM_Key_T, +WM_Key_Y, +WM_Key_U, +WM_Key_I, +WM_Key_O, +WM_Key_P, +WM_Key_LeftBracket, +WM_Key_RightBracket, +WM_Key_BackSlash, +WM_Key_CapsLock, +WM_Key_A, +WM_Key_S, +WM_Key_D, +WM_Key_F, +WM_Key_G, +WM_Key_H, +WM_Key_J, +WM_Key_K, +WM_Key_L, +WM_Key_Semicolon, +WM_Key_Quote, +WM_Key_Return, +WM_Key_Shift, +WM_Key_Z, +WM_Key_X, +WM_Key_C, +WM_Key_V, +WM_Key_B, +WM_Key_N, +WM_Key_M, +WM_Key_Comma, +WM_Key_Period, +WM_Key_Slash, +WM_Key_Ctrl, +WM_Key_Alt, +WM_Key_Space, +WM_Key_Menu, +WM_Key_ScrollLock, +WM_Key_Pause, +WM_Key_Insert, +WM_Key_Home, +WM_Key_PageUp, +WM_Key_Delete, +WM_Key_End, +WM_Key_PageDown, +WM_Key_Up, +WM_Key_Left, +WM_Key_Down, +WM_Key_Right, +WM_Key_Ex0, +WM_Key_Ex1, +WM_Key_Ex2, +WM_Key_Ex3, +WM_Key_Ex4, +WM_Key_Ex5, +WM_Key_Ex6, +WM_Key_Ex7, +WM_Key_Ex8, +WM_Key_Ex9, +WM_Key_Ex10, +WM_Key_Ex11, +WM_Key_Ex12, +WM_Key_Ex13, +WM_Key_Ex14, +WM_Key_Ex15, +WM_Key_Ex16, +WM_Key_Ex17, +WM_Key_Ex18, +WM_Key_Ex19, +WM_Key_Ex20, +WM_Key_Ex21, +WM_Key_Ex22, +WM_Key_Ex23, +WM_Key_Ex24, +WM_Key_Ex25, +WM_Key_Ex26, +WM_Key_Ex27, +WM_Key_Ex28, +WM_Key_Ex29, +WM_Key_NumLock, +WM_Key_NumSlash, +WM_Key_NumStar, +WM_Key_NumMinus, +WM_Key_NumPlus, +WM_Key_NumPeriod, +WM_Key_Num0, +WM_Key_Num1, +WM_Key_Num2, +WM_Key_Num3, +WM_Key_Num4, +WM_Key_Num5, +WM_Key_Num6, +WM_Key_Num7, +WM_Key_Num8, +WM_Key_Num9, +WM_Key_LeftMouseButton, +WM_Key_MiddleMouseButton, +WM_Key_RightMouseButton, +WM_Key_COUNT, +} WM_Key; C_LINKAGE_BEGIN -extern String8 os_g_key_display_string_table[143]; -extern String8 os_g_key_cfg_string_table[143]; +extern String8 wm_key_display_name_table[143]; +extern String8 wm_key_cfg_name_table[143]; C_LINKAGE_END diff --git a/src/window_manager/window_manager.c b/src/window_manager/window_manager.c index 1f59d2a5..c5dc11cb 100644 --- a/src/window_manager/window_manager.c +++ b/src/window_manager/window_manager.c @@ -9,22 +9,22 @@ //////////////////////////////// //~ rjf: Handle Type Helpers -internal OS_Window -os_window_zero(void) +internal WM_Window +wm_window_zero(void) { - OS_Window result = {0}; + WM_Window result = {0}; return result; } internal B32 -os_window_match(OS_Window a, OS_Window b) +wm_window_match(WM_Window a, WM_Window b) { B32 result = MemoryMatchStruct(&a, &b); return result; } internal B32 -os_monitor_match(OS_Monitor a, OS_Monitor b) +wm_monitor_match(WM_Monitor a, WM_Monitor b) { B32 result = MemoryMatchStruct(&a, &b); return result; @@ -34,46 +34,46 @@ os_monitor_match(OS_Monitor a, OS_Monitor b) //~ rjf: Event Functions (Helpers, Implemented Once) internal String8 -os_string_from_event_kind(OS_EventKind kind) +wm_string_from_event_kind(WM_EventKind kind) { String8 result = {0}; switch(kind) { - case OS_EventKind_Null: - case OS_EventKind_COUNT: + case WM_EventKind_Null: + case WM_EventKind_COUNT: {}break; - case OS_EventKind_Press: {result = str8_lit("Press");}break; - case OS_EventKind_Release: {result = str8_lit("Release");}break; - case OS_EventKind_MouseMove: {result = str8_lit("MouseMove");}break; - case OS_EventKind_Text: {result = str8_lit("Text");}break; - case OS_EventKind_Scroll: {result = str8_lit("Scroll");}break; - case OS_EventKind_WindowLoseFocus: {result = str8_lit("WindowLoseFocus");}break; - case OS_EventKind_WindowClose: {result = str8_lit("WindowClose");}break; - case OS_EventKind_FileDrop: {result = str8_lit("FileDrop");}break; - case OS_EventKind_Wakeup: {result = str8_lit("Wakeup");}break; + case WM_EventKind_Press: {result = str8_lit("Press");}break; + case WM_EventKind_Release: {result = str8_lit("Release");}break; + case WM_EventKind_MouseMove: {result = str8_lit("MouseMove");}break; + case WM_EventKind_Text: {result = str8_lit("Text");}break; + case WM_EventKind_Scroll: {result = str8_lit("Scroll");}break; + case WM_EventKind_WindowLoseFocus: {result = str8_lit("WindowLoseFocus");}break; + case WM_EventKind_WindowClose: {result = str8_lit("WindowClose");}break; + case WM_EventKind_FileDrop: {result = str8_lit("FileDrop");}break; + case WM_EventKind_Wakeup: {result = str8_lit("Wakeup");}break; } return result; } internal String8List -os_string_list_from_modifiers(Arena *arena, OS_Modifiers modifiers) +wm_string_list_from_modifiers(Arena *arena, WM_Modifiers modifiers) { String8List result = {0}; - if(modifiers & OS_Modifier_Ctrl) { str8_list_push(arena, &result, str8_lit("Ctrl")); } - if(modifiers & OS_Modifier_Shift) { str8_list_push(arena, &result, str8_lit("Shift")); } - if(modifiers & OS_Modifier_Alt) { str8_list_push(arena, &result, str8_lit("Alt")); } + if(modifiers & WM_Modifier_Ctrl) { str8_list_push(arena, &result, str8_lit("Ctrl")); } + if(modifiers & WM_Modifier_Shift) { str8_list_push(arena, &result, str8_lit("Shift")); } + if(modifiers & WM_Modifier_Alt) { str8_list_push(arena, &result, str8_lit("Alt")); } return result; } internal String8 -os_string_from_modifiers_key(Arena *arena, OS_Modifiers modifiers, OS_Key key) +wm_string_from_modifiers_key(Arena *arena, WM_Modifiers modifiers, WM_Key key) { String8 result = {0}; - if(key != OS_Key_Null) + if(key != WM_Key_Null) { Temp scratch = scratch_begin(&arena, 1); - String8List mods = os_string_list_from_modifiers(scratch.arena, modifiers); - String8 key_string = os_g_key_display_string_table[key]; + String8List mods = wm_string_list_from_modifiers(scratch.arena, modifiers); + String8 key_string = wm_key_display_name_table[key]; str8_list_push(scratch.arena, &mods, key_string); StringJoin join = {0}; join.sep = str8_lit(" + "); @@ -84,105 +84,105 @@ os_string_from_modifiers_key(Arena *arena, OS_Modifiers modifiers, OS_Key key) } internal U32 -os_codepoint_from_modifiers_and_key(OS_Modifiers modifiers, OS_Key key) +wm_codepoint_from_modifiers_and_key(WM_Modifiers modifiers, WM_Key key) { U32 result = 0; // rjf: special-case map - local_persist read_only struct {U32 character; OS_Key key; OS_Modifiers modifiers;} map[] = + local_persist read_only struct {U32 character; WM_Key key; WM_Modifiers modifiers;} map[] = { - {'!', OS_Key_1, OS_Modifier_Shift}, - {'@', OS_Key_2, OS_Modifier_Shift}, - {'#', OS_Key_3, OS_Modifier_Shift}, - {'$', OS_Key_4, OS_Modifier_Shift}, - {'%', OS_Key_5, OS_Modifier_Shift}, - {'^', OS_Key_6, OS_Modifier_Shift}, - {'&', OS_Key_7, OS_Modifier_Shift}, - {'*', OS_Key_8, OS_Modifier_Shift}, - {'(', OS_Key_9, OS_Modifier_Shift}, - {')', OS_Key_0, OS_Modifier_Shift}, - {'_', OS_Key_Minus, OS_Modifier_Shift}, - {'_', OS_Key_Minus, OS_Modifier_Shift}, - {'-', OS_Key_Minus, 0}, - {'=', OS_Key_Equal, 0}, - {'+', OS_Key_Equal, OS_Modifier_Shift}, - {'`', OS_Key_Tick, 0}, - {'~', OS_Key_Tick, OS_Modifier_Shift}, - {'[', OS_Key_LeftBracket, 0}, - {']', OS_Key_RightBracket, 0}, - {'{', OS_Key_LeftBracket, OS_Modifier_Shift}, - {'}', OS_Key_RightBracket, OS_Modifier_Shift}, - {'\\', OS_Key_BackSlash, 0}, - {'|', OS_Key_BackSlash, OS_Modifier_Shift}, - {';', OS_Key_Semicolon, 0}, - {':', OS_Key_Semicolon, OS_Modifier_Shift}, - {'\'', OS_Key_Quote, 0}, - {'"', OS_Key_Quote, OS_Modifier_Shift}, - {'.', OS_Key_Period, 0}, - {',', OS_Key_Comma, 0}, - {'<', OS_Key_Period, OS_Modifier_Shift}, - {'>', OS_Key_Comma, OS_Modifier_Shift}, - {'/', OS_Key_Slash, 0}, - {'?', OS_Key_Slash, OS_Modifier_Shift}, - {'a', OS_Key_A, 0}, - {'b', OS_Key_B, 0}, - {'c', OS_Key_C, 0}, - {'d', OS_Key_D, 0}, - {'e', OS_Key_E, 0}, - {'f', OS_Key_F, 0}, - {'g', OS_Key_G, 0}, - {'h', OS_Key_H, 0}, - {'i', OS_Key_I, 0}, - {'j', OS_Key_J, 0}, - {'k', OS_Key_K, 0}, - {'l', OS_Key_L, 0}, - {'m', OS_Key_M, 0}, - {'n', OS_Key_N, 0}, - {'o', OS_Key_O, 0}, - {'p', OS_Key_P, 0}, - {'q', OS_Key_Q, 0}, - {'r', OS_Key_R, 0}, - {'s', OS_Key_S, 0}, - {'t', OS_Key_T, 0}, - {'u', OS_Key_U, 0}, - {'v', OS_Key_V, 0}, - {'w', OS_Key_W, 0}, - {'x', OS_Key_X, 0}, - {'y', OS_Key_Y, 0}, - {'z', OS_Key_Z, 0}, - {'A', OS_Key_A, OS_Modifier_Shift}, - {'B', OS_Key_B, OS_Modifier_Shift}, - {'C', OS_Key_C, OS_Modifier_Shift}, - {'D', OS_Key_D, OS_Modifier_Shift}, - {'E', OS_Key_E, OS_Modifier_Shift}, - {'F', OS_Key_F, OS_Modifier_Shift}, - {'G', OS_Key_G, OS_Modifier_Shift}, - {'H', OS_Key_H, OS_Modifier_Shift}, - {'I', OS_Key_I, OS_Modifier_Shift}, - {'J', OS_Key_J, OS_Modifier_Shift}, - {'K', OS_Key_K, OS_Modifier_Shift}, - {'L', OS_Key_L, OS_Modifier_Shift}, - {'M', OS_Key_M, OS_Modifier_Shift}, - {'N', OS_Key_N, OS_Modifier_Shift}, - {'O', OS_Key_O, OS_Modifier_Shift}, - {'P', OS_Key_P, OS_Modifier_Shift}, - {'Q', OS_Key_Q, OS_Modifier_Shift}, - {'R', OS_Key_R, OS_Modifier_Shift}, - {'S', OS_Key_S, OS_Modifier_Shift}, - {'T', OS_Key_T, OS_Modifier_Shift}, - {'U', OS_Key_U, OS_Modifier_Shift}, - {'V', OS_Key_V, OS_Modifier_Shift}, - {'W', OS_Key_W, OS_Modifier_Shift}, - {'X', OS_Key_X, OS_Modifier_Shift}, - {'Y', OS_Key_Y, OS_Modifier_Shift}, - {'Z', OS_Key_Z, OS_Modifier_Shift}, - {' ', OS_Key_Space, 0}, + {'!', WM_Key_1, WM_Modifier_Shift}, + {'@', WM_Key_2, WM_Modifier_Shift}, + {'#', WM_Key_3, WM_Modifier_Shift}, + {'$', WM_Key_4, WM_Modifier_Shift}, + {'%', WM_Key_5, WM_Modifier_Shift}, + {'^', WM_Key_6, WM_Modifier_Shift}, + {'&', WM_Key_7, WM_Modifier_Shift}, + {'*', WM_Key_8, WM_Modifier_Shift}, + {'(', WM_Key_9, WM_Modifier_Shift}, + {')', WM_Key_0, WM_Modifier_Shift}, + {'_', WM_Key_Minus, WM_Modifier_Shift}, + {'_', WM_Key_Minus, WM_Modifier_Shift}, + {'-', WM_Key_Minus, 0}, + {'=', WM_Key_Equal, 0}, + {'+', WM_Key_Equal, WM_Modifier_Shift}, + {'`', WM_Key_Tick, 0}, + {'~', WM_Key_Tick, WM_Modifier_Shift}, + {'[', WM_Key_LeftBracket, 0}, + {']', WM_Key_RightBracket, 0}, + {'{', WM_Key_LeftBracket, WM_Modifier_Shift}, + {'}', WM_Key_RightBracket, WM_Modifier_Shift}, + {'\\', WM_Key_BackSlash, 0}, + {'|', WM_Key_BackSlash, WM_Modifier_Shift}, + {';', WM_Key_Semicolon, 0}, + {':', WM_Key_Semicolon, WM_Modifier_Shift}, + {'\'', WM_Key_Quote, 0}, + {'"', WM_Key_Quote, WM_Modifier_Shift}, + {'.', WM_Key_Period, 0}, + {',', WM_Key_Comma, 0}, + {'<', WM_Key_Period, WM_Modifier_Shift}, + {'>', WM_Key_Comma, WM_Modifier_Shift}, + {'/', WM_Key_Slash, 0}, + {'?', WM_Key_Slash, WM_Modifier_Shift}, + {'a', WM_Key_A, 0}, + {'b', WM_Key_B, 0}, + {'c', WM_Key_C, 0}, + {'d', WM_Key_D, 0}, + {'e', WM_Key_E, 0}, + {'f', WM_Key_F, 0}, + {'g', WM_Key_G, 0}, + {'h', WM_Key_H, 0}, + {'i', WM_Key_I, 0}, + {'j', WM_Key_J, 0}, + {'k', WM_Key_K, 0}, + {'l', WM_Key_L, 0}, + {'m', WM_Key_M, 0}, + {'n', WM_Key_N, 0}, + {'o', WM_Key_O, 0}, + {'p', WM_Key_P, 0}, + {'q', WM_Key_Q, 0}, + {'r', WM_Key_R, 0}, + {'s', WM_Key_S, 0}, + {'t', WM_Key_T, 0}, + {'u', WM_Key_U, 0}, + {'v', WM_Key_V, 0}, + {'w', WM_Key_W, 0}, + {'x', WM_Key_X, 0}, + {'y', WM_Key_Y, 0}, + {'z', WM_Key_Z, 0}, + {'A', WM_Key_A, WM_Modifier_Shift}, + {'B', WM_Key_B, WM_Modifier_Shift}, + {'C', WM_Key_C, WM_Modifier_Shift}, + {'D', WM_Key_D, WM_Modifier_Shift}, + {'E', WM_Key_E, WM_Modifier_Shift}, + {'F', WM_Key_F, WM_Modifier_Shift}, + {'G', WM_Key_G, WM_Modifier_Shift}, + {'H', WM_Key_H, WM_Modifier_Shift}, + {'I', WM_Key_I, WM_Modifier_Shift}, + {'J', WM_Key_J, WM_Modifier_Shift}, + {'K', WM_Key_K, WM_Modifier_Shift}, + {'L', WM_Key_L, WM_Modifier_Shift}, + {'M', WM_Key_M, WM_Modifier_Shift}, + {'N', WM_Key_N, WM_Modifier_Shift}, + {'O', WM_Key_O, WM_Modifier_Shift}, + {'P', WM_Key_P, WM_Modifier_Shift}, + {'Q', WM_Key_Q, WM_Modifier_Shift}, + {'R', WM_Key_R, WM_Modifier_Shift}, + {'S', WM_Key_S, WM_Modifier_Shift}, + {'T', WM_Key_T, WM_Modifier_Shift}, + {'U', WM_Key_U, WM_Modifier_Shift}, + {'V', WM_Key_V, WM_Modifier_Shift}, + {'W', WM_Key_W, WM_Modifier_Shift}, + {'X', WM_Key_X, WM_Modifier_Shift}, + {'Y', WM_Key_Y, WM_Modifier_Shift}, + {'Z', WM_Key_Z, WM_Modifier_Shift}, + {' ', WM_Key_Space, 0}, }; // rjf: check numeric - if(OS_Key_0 <= key && key <= OS_Key_9) + if(WM_Key_0 <= key && key <= WM_Key_9) { - result = '0' + (key - OS_Key_0); + result = '0' + (key - WM_Key_0); } // rjf: check special-case map @@ -199,23 +199,23 @@ os_codepoint_from_modifiers_and_key(OS_Modifiers modifiers, OS_Key key) } internal void -os_eat_event(OS_EventList *events, OS_Event *event) +wm_eat_event(WM_EventList *events, WM_Event *event) { DLLRemove(events->first, events->last, event); events->count -= 1; } internal B32 -os_key_press(OS_EventList *events, OS_Window window, OS_Modifiers modifiers, OS_Key key) +wm_key_press(WM_EventList *events, WM_Window window, WM_Modifiers modifiers, WM_Key key) { B32 result = 0; - for(OS_Event *event = events->first; event != 0; event = event->next) + for(WM_Event *event = events->first; event != 0; event = event->next) { - if((os_window_match(event->window, window) || os_window_match(window, os_window_zero())) && - event->kind == OS_EventKind_Press && event->key == key && event->modifiers == modifiers) + if((wm_window_match(event->window, window) || wm_window_match(window, wm_window_zero())) && + event->kind == WM_EventKind_Press && event->key == key && event->modifiers == modifiers) { result = 1; - os_eat_event(events, event); + wm_eat_event(events, event); break; } } @@ -223,16 +223,16 @@ os_key_press(OS_EventList *events, OS_Window window, OS_Modifiers modifiers, OS_ } internal B32 -os_key_release(OS_EventList *events, OS_Window window, OS_Modifiers modifiers, OS_Key key) +wm_key_release(WM_EventList *events, WM_Window window, WM_Modifiers modifiers, WM_Key key) { B32 result = 0; - for(OS_Event *event = events->first; event != 0; event = event->next) + for(WM_Event *event = events->first; event != 0; event = event->next) { - if((os_window_match(event->window, window) || os_window_match(window, os_window_zero())) && - event->kind == OS_EventKind_Release && event->key == key && event->modifiers == modifiers) + if((wm_window_match(event->window, window) || wm_window_match(window, wm_window_zero())) && + event->kind == WM_EventKind_Release && event->key == key && event->modifiers == modifiers) { result = 1; - os_eat_event(events, event); + wm_eat_event(events, event); break; } } @@ -240,29 +240,29 @@ os_key_release(OS_EventList *events, OS_Window window, OS_Modifiers modifiers, O } internal B32 -os_text(OS_EventList *events, OS_Window window, U32 character) +wm_text(WM_EventList *events, WM_Window window, U32 character) { B32 result = 0; - for(OS_Event *event = events->first; event != 0; event = event->next) + for(WM_Event *event = events->first; event != 0; event = event->next) { - if((os_window_match(event->window, window) || os_window_match(window, os_window_zero())) && - event->kind == OS_EventKind_Text && event->character == character) + if((wm_window_match(event->window, window) || wm_window_match(window, wm_window_zero())) && + event->kind == WM_EventKind_Text && event->character == character) { result = 1; - os_eat_event(events, event); + wm_eat_event(events, event); break; } } return result; } -internal OS_EventList -os_event_list_copy(Arena *arena, OS_EventList *src) +internal WM_EventList +wm_event_list_copy(Arena *arena, WM_EventList *src) { - OS_EventList dst = {0}; - for(OS_Event *s = src->first; s != 0; s = s->next) + WM_EventList dst = {0}; + for(WM_Event *s = src->first; s != 0; s = s->next) { - OS_Event *d = push_array(arena, OS_Event, 1); + WM_Event *d = push_array(arena, WM_Event, 1); MemoryCopyStruct(d, s); d->strings = str8_list_copy(arena, &s->strings); DLLPushBack(dst.first, dst.last, d); @@ -272,7 +272,7 @@ os_event_list_copy(Arena *arena, OS_EventList *src) } internal void -os_event_list_concat_in_place(OS_EventList *dst, OS_EventList *to_push) +wm_event_list_concat_in_place(WM_EventList *dst, WM_EventList *to_push) { if(dst->last && to_push->first) { @@ -288,10 +288,10 @@ os_event_list_concat_in_place(OS_EventList *dst, OS_EventList *to_push) MemoryZeroStruct(to_push); } -internal OS_Event * -os_event_list_push_new(Arena *arena, OS_EventList *evts, OS_EventKind kind) +internal WM_Event * +wm_event_list_push_new(Arena *arena, WM_EventList *evts, WM_EventKind kind) { - OS_Event *evt = push_array(arena, OS_Event, 1); + WM_Event *evt = push_array(arena, WM_Event, 1); DLLPushBack(evts->first, evts->last, evt); evts->count += 1; evt->timestamp_us = now_time_us(); diff --git a/src/window_manager/window_manager.h b/src/window_manager/window_manager.h index a64ca87f..c17f9c7c 100644 --- a/src/window_manager/window_manager.h +++ b/src/window_manager/window_manager.h @@ -1,14 +1,14 @@ // Copyright (c) Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -#ifndef OS_GFX_H -#define OS_GFX_H +#ifndef WINDOW_MANAGER_H +#define WINDOW_MANAGER_H //////////////////////////////// //~ rjf: Graphics System Info -typedef struct OS_GfxInfo OS_GfxInfo; -struct OS_GfxInfo +typedef struct WM_SystemInfo WM_SystemInfo; +struct WM_SystemInfo { F32 double_click_time; F32 caret_blink_time; @@ -18,15 +18,15 @@ struct OS_GfxInfo //////////////////////////////// //~ rjf: Window Types -typedef U32 OS_WindowFlags; +typedef U32 WM_WindowFlags; enum { - OS_WindowFlag_CustomBorder = (1<<0), - OS_WindowFlag_UseDefaultPosition = (1<<1), + WM_WindowFlag_CustomBorder = (1<<0), + WM_WindowFlag_UseDefaultPosition = (1<<1), }; -typedef struct OS_Window OS_Window; -struct OS_Window +typedef struct WM_Window WM_Window; +struct WM_Window { U64 u64[1]; }; @@ -34,8 +34,8 @@ struct OS_Window //////////////////////////////// //~ rjf: External Window Types -typedef struct OS_ExternalWindow OS_ExternalWindow; -struct OS_ExternalWindow +typedef struct WM_ExtWindow WM_ExtWindow; +struct WM_ExtWindow { U64 u64[1]; }; @@ -43,36 +43,36 @@ struct OS_ExternalWindow //////////////////////////////// //~ rjf: Monitor Types -typedef struct OS_Monitor OS_Monitor; -struct OS_Monitor +typedef struct WM_Monitor WM_Monitor; +struct WM_Monitor { U64 u64[1]; }; -typedef struct OS_MonitorArray OS_MonitorArray; -struct OS_MonitorArray +typedef struct WM_MonitorArray WM_MonitorArray; +struct WM_MonitorArray { - OS_Monitor *v; + WM_Monitor *v; U64 count; }; //////////////////////////////// //~ rjf: Cursor Types -typedef enum OS_Cursor +typedef enum WM_Cursor { - OS_Cursor_Pointer, - OS_Cursor_IBar, - OS_Cursor_LeftRight, - OS_Cursor_UpDown, - OS_Cursor_DownRight, - OS_Cursor_UpRight, - OS_Cursor_UpDownLeftRight, - OS_Cursor_HandPoint, - OS_Cursor_Disabled, - OS_Cursor_COUNT, + WM_Cursor_Pointer, + WM_Cursor_IBar, + WM_Cursor_LeftRight, + WM_Cursor_UpDown, + WM_Cursor_DownRight, + WM_Cursor_UpRight, + WM_Cursor_UpDownLeftRight, + WM_Cursor_HandPoint, + WM_Cursor_Disabled, + WM_Cursor_COUNT, } -OS_Cursor; +WM_Cursor; //////////////////////////////// //~ rjf: Generated Code @@ -82,40 +82,40 @@ OS_Cursor; //////////////////////////////// //~ rjf: Event Types -typedef enum OS_EventKind +typedef enum WM_EventKind { - OS_EventKind_Null, - OS_EventKind_Press, - OS_EventKind_Release, - OS_EventKind_MouseMove, - OS_EventKind_Text, - OS_EventKind_Scroll, - OS_EventKind_WindowLoseFocus, - OS_EventKind_WindowClose, - OS_EventKind_FileDrop, - OS_EventKind_Wakeup, - OS_EventKind_COUNT + WM_EventKind_Null, + WM_EventKind_Press, + WM_EventKind_Release, + WM_EventKind_MouseMove, + WM_EventKind_Text, + WM_EventKind_Scroll, + WM_EventKind_WindowLoseFocus, + WM_EventKind_WindowClose, + WM_EventKind_FileDrop, + WM_EventKind_Wakeup, + WM_EventKind_COUNT } -OS_EventKind; +WM_EventKind; -typedef U32 OS_Modifiers; +typedef U32 WM_Modifiers; enum { - OS_Modifier_Ctrl = (1<<0), - OS_Modifier_Shift = (1<<1), - OS_Modifier_Alt = (1<<2), + WM_Modifier_Ctrl = (1<<0), + WM_Modifier_Shift = (1<<1), + WM_Modifier_Alt = (1<<2), }; -typedef struct OS_Event OS_Event; -struct OS_Event +typedef struct WM_Event WM_Event; +struct WM_Event { - OS_Event *next; - OS_Event *prev; + WM_Event *next; + WM_Event *prev; U64 timestamp_us; - OS_Window window; - OS_EventKind kind; - OS_Modifiers modifiers; - OS_Key key; + WM_Window window; + WM_EventKind kind; + WM_Modifiers modifiers; + WM_Key key; B32 is_repeat; B32 right_sided; U32 character; @@ -125,12 +125,12 @@ struct OS_Event String8List strings; }; -typedef struct OS_EventList OS_EventList; -struct OS_EventList +typedef struct WM_EventList WM_EventList; +struct WM_EventList { U64 count; - OS_Event *first; - OS_Event *last; + WM_Event *first; + WM_Event *last; }; //////////////////////////////// @@ -141,106 +141,106 @@ internal B32 frame(void); //////////////////////////////// //~ rjf: Handle Type Helpers -internal OS_Window os_window_zero(void); -internal B32 os_window_match(OS_Window a, OS_Window b); -internal B32 os_monitor_match(OS_Monitor a, OS_Monitor b); +internal WM_Window wm_window_zero(void); +internal B32 wm_window_match(WM_Window a, WM_Window b); +internal B32 wm_monitor_match(WM_Monitor a, WM_Monitor b); //////////////////////////////// //~ rjf: Event Functions (Helpers, Implemented Once) -internal String8 os_string_from_event_kind(OS_EventKind kind); -internal String8List os_string_list_from_modifiers(Arena *arena, OS_Modifiers flags); -internal String8 os_string_from_modifiers_key(Arena *arena, OS_Modifiers modifiers, OS_Key key); -internal U32 os_codepoint_from_modifiers_and_key(OS_Modifiers flags, OS_Key key); -internal void os_eat_event(OS_EventList *events, OS_Event *event); -internal B32 os_key_press(OS_EventList *events, OS_Window window, OS_Modifiers modifiers, OS_Key key); -internal B32 os_key_release(OS_EventList *events, OS_Window window, OS_Modifiers modifiers, OS_Key key); -internal B32 os_text(OS_EventList *events, OS_Window window, U32 character); -internal OS_EventList os_event_list_copy(Arena *arena, OS_EventList *src); -internal void os_event_list_concat_in_place(OS_EventList *dst, OS_EventList *to_push); -internal OS_Event *os_event_list_push_new(Arena *arena, OS_EventList *evts, OS_EventKind kind); +internal String8 wm_string_from_event_kind(WM_EventKind kind); +internal String8List wm_string_list_from_modifiers(Arena *arena, WM_Modifiers flags); +internal String8 wm_string_from_modifiers_key(Arena *arena, WM_Modifiers modifiers, WM_Key key); +internal U32 wm_codepoint_from_modifiers_and_key(WM_Modifiers flags, WM_Key key); +internal void wm_eat_event(WM_EventList *events, WM_Event *event); +internal B32 wm_key_press(WM_EventList *events, WM_Window window, WM_Modifiers modifiers, WM_Key key); +internal B32 wm_key_release(WM_EventList *events, WM_Window window, WM_Modifiers modifiers, WM_Key key); +internal B32 wm_text(WM_EventList *events, WM_Window window, U32 character); +internal WM_EventList wm_event_list_copy(Arena *arena, WM_EventList *src); +internal void wm_event_list_concat_in_place(WM_EventList *dst, WM_EventList *to_push); +internal WM_Event *wm_event_list_push_new(Arena *arena, WM_EventList *evts, WM_EventKind kind); //////////////////////////////// //~ rjf: @os_hooks Main Initialization API (Implemented Per-OS) -internal void os_gfx_init(void); +internal void wm_init(void); //////////////////////////////// //~ rjf: @os_hooks Graphics System Info (Implemented Per-OS) -internal OS_GfxInfo *os_get_gfx_info(void); +internal WM_SystemInfo *wm_get_system_info(void); //////////////////////////////// //~ rjf: @os_hooks Clipboards (Implemented Per-OS) -internal void os_set_clipboard_text(String8 string); -internal String8 os_get_clipboard_text(Arena *arena); +internal void wm_set_clipboard_text(String8 string); +internal String8 wm_get_clipboard_text(Arena *arena); //////////////////////////////// //~ rjf: @os_hooks Windows (Implemented Per-OS) -internal OS_Window os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title); -internal void os_window_close(OS_Window window); -internal void os_window_set_title(OS_Window window, String8 title); -internal void os_window_first_paint(OS_Window window); -internal void os_window_focus(OS_Window window); -internal B32 os_window_is_focused(OS_Window window); -internal B32 os_window_is_fullscreen(OS_Window window); -internal void os_window_set_fullscreen(OS_Window window, B32 fullscreen); -internal B32 os_window_is_maximized(OS_Window window); -internal void os_window_set_maximized(OS_Window window, B32 maximized); -internal B32 os_window_is_minimized(OS_Window window); -internal void os_window_set_minimized(OS_Window window, B32 minimized); -internal void os_window_bring_to_front(OS_Window window); -internal void os_window_set_monitor(OS_Window window, OS_Monitor monitor); -internal void os_window_clear_custom_border_data(OS_Window handle); -internal void os_window_push_custom_title_bar(OS_Window handle, F32 thickness); -internal void os_window_push_custom_edges(OS_Window handle, F32 thickness); -internal void os_window_push_custom_title_bar_client_area(OS_Window handle, Rng2F32 rect); -internal Rng2F32 os_rect_from_window(OS_Window window); -internal Rng2F32 os_client_rect_from_window(OS_Window window); -internal F32 os_dpi_from_window(OS_Window window); +internal WM_Window wm_window_open(Rng2F32 rect, WM_WindowFlags flags, String8 title); +internal void wm_window_close(WM_Window window); +internal void wm_window_set_title(WM_Window window, String8 title); +internal void wm_window_first_paint(WM_Window window); +internal void wm_window_focus(WM_Window window); +internal B32 wm_window_is_focused(WM_Window window); +internal B32 wm_window_is_fullscreen(WM_Window window); +internal void wm_window_set_fullscreen(WM_Window window, B32 fullscreen); +internal B32 wm_window_is_maximized(WM_Window window); +internal void wm_window_set_maximized(WM_Window window, B32 maximized); +internal B32 wm_window_is_minimized(WM_Window window); +internal void wm_window_set_minimized(WM_Window window, B32 minimized); +internal void wm_window_bring_to_front(WM_Window window); +internal void wm_window_set_monitor(WM_Window window, WM_Monitor monitor); +internal void wm_window_clear_custom_border_data(WM_Window handle); +internal void wm_window_push_custom_title_bar(WM_Window handle, F32 thickness); +internal void wm_window_push_custom_edges(WM_Window handle, F32 thickness); +internal void wm_window_push_custom_title_bar_client_area(WM_Window handle, Rng2F32 rect); +internal Rng2F32 wm_rect_from_window(WM_Window window); +internal Rng2F32 wm_client_rect_from_window(WM_Window window); +internal F32 wm_dpi_from_window(WM_Window window); //////////////////////////////// //~ rjf: @os_hooks External Windows (Implemented Per-OS) -internal OS_ExternalWindow os_focused_external_window(void); -internal void os_focus_external_window(OS_ExternalWindow ext_window); +internal WM_ExtWindow wm_focused_external_window(void); +internal void wm_focus_external_window(WM_ExtWindow ext_window); //////////////////////////////// //~ rjf: @os_hooks Monitors (Implemented Per-OS) -internal OS_MonitorArray os_push_monitors_array(Arena *arena); -internal OS_Monitor os_primary_monitor(void); -internal OS_Monitor os_monitor_from_window(OS_Window window); -internal String8 os_name_from_monitor(Arena *arena, OS_Monitor monitor); -internal Vec2F32 os_dim_from_monitor(OS_Monitor monitor); -internal F32 os_dpi_from_monitor(OS_Monitor monitor); +internal WM_MonitorArray wm_push_monitors_array(Arena *arena); +internal WM_Monitor wm_primary_monitor(void); +internal WM_Monitor wm_monitor_from_window(WM_Window window); +internal String8 wm_name_from_monitor(Arena *arena, WM_Monitor monitor); +internal Vec2F32 wm_dim_from_monitor(WM_Monitor monitor); +internal F32 wm_dpi_from_monitor(WM_Monitor monitor); //////////////////////////////// //~ rjf: @os_hooks Events (Implemented Per-OS) -internal void os_send_wakeup_event(void); -internal OS_EventList os_get_events(Arena *arena, B32 wait); -internal OS_Modifiers os_get_modifiers(void); -internal B32 os_key_is_down(OS_Key key); -internal Vec2F32 os_mouse_from_window(OS_Window window); +internal void wm_send_wakeup_event(void); +internal WM_EventList wm_get_events(Arena *arena, B32 wait); +internal WM_Modifiers wm_get_modifiers(void); +internal B32 wm_key_is_down(WM_Key key); +internal Vec2F32 wm_mouse_from_window(WM_Window window); //////////////////////////////// //~ rjf: @os_hooks Cursors (Implemented Per-OS) -internal void os_set_cursor(OS_Cursor cursor); +internal void wm_set_cursor(WM_Cursor cursor); //////////////////////////////// //~ rjf: @os_hooks Native User-Facing Graphical Messages (Implemented Per-OS) -internal void os_graphical_message(B32 error, String8 title, String8 message); -internal String8 os_graphical_pick_file(Arena *arena, String8 initial_path); +internal void wm_graphical_message(B32 error, String8 title, String8 message); +internal String8 wm_graphical_pick_file(Arena *arena, String8 initial_path); //////////////////////////////// //~ rjf: @os_hooks Shell Operations -internal void os_show_in_filesystem_ui(String8 path); -internal void os_open_in_browser(String8 url); +internal void wm_show_in_filesystem_ui(String8 path); +internal void wm_open_in_browser(String8 url); -#endif // OS_GFX_H +#endif // WINDOW_MANAGER_H diff --git a/src/window_manager/window_manager.mdesk b/src/window_manager/window_manager.mdesk index 053c5119..ffa92dcb 100644 --- a/src/window_manager/window_manager.mdesk +++ b/src/window_manager/window_manager.mdesk @@ -5,7 +5,7 @@ //~ rjf: Tables @table(name, display_string, cfg_string) -OS_KeyTable: +WM_KeyTable: { {Null "Invalid Key" "null" } {Esc "Escape" "esc" } @@ -155,18 +155,18 @@ OS_KeyTable: //////////////////////////////// //~ rjf: Generators -@enum OS_Key: +@enum WM_Key: { - @expand(OS_KeyTable a) `$(a.name)`, + @expand(WM_KeyTable a) `$(a.name)`, COUNT, } -@data(String8) os_g_key_display_string_table: +@data(String8) wm_key_display_name_table: { - @expand(OS_KeyTable a) `str8_lit_comp("$(a.display_string)")`; + @expand(WM_KeyTable a) `str8_lit_comp("$(a.display_string)")`; } -@data(String8) os_g_key_cfg_string_table: +@data(String8) wm_key_cfg_name_table: { - @expand(OS_KeyTable a) `str8_lit_comp("$(a.cfg_string)")`; + @expand(WM_KeyTable a) `str8_lit_comp("$(a.cfg_string)")`; } diff --git a/src/window_manager/window_manager_stub.c b/src/window_manager/window_manager_stub.c index bf49a3d0..29ea886d 100644 --- a/src/window_manager/window_manager_stub.c +++ b/src/window_manager/window_manager_stub.c @@ -2,17 +2,17 @@ //~ rjf: @os_hooks Main Initialization API (Implemented Per-OS) internal void -os_gfx_init(void) +wm_init(void) { } //////////////////////////////// //~ rjf: @os_hooks Graphics System Info (Implemented Per-OS) -internal OS_GfxInfo * -os_get_gfx_info(void) +internal WM_SystemInfo * +wm_get_system_info(void) { - local_persist OS_GfxInfo g = {0}; + local_persist WM_SystemInfo g = {0}; return &g; } @@ -20,12 +20,12 @@ os_get_gfx_info(void) //~ rjf: @os_hooks Clipboards (Implemented Per-OS) internal void -os_set_clipboard_text(String8 string) +wm_set_clipboard_text(String8 string) { } internal String8 -os_get_clipboard_text(Arena *arena) +wm_get_clipboard_text(Arena *arena) { return str8_zero(); } @@ -33,118 +33,118 @@ os_get_clipboard_text(Arena *arena) //////////////////////////////// //~ rjf: @os_hooks Windows (Implemented Per-OS) -internal OS_Handle -os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title) +internal WM_Window +wm_window_open(Rng2F32 rect, WM_WindowFlags flags, String8 title) { - OS_Handle handle = {1}; + WM_Window handle = {1}; return handle; } internal void -os_window_close(OS_Handle window) +wm_window_close(WM_Window window) { } internal void -os_window_set_title(OS_Handle window, String8 title) +wm_window_set_title(WM_Window window, String8 title) { } internal void -os_window_first_paint(OS_Handle window) +wm_window_first_paint(WM_Window window) { } internal void -os_window_focus(OS_Handle window) +wm_window_focus(WM_Window window) { } internal B32 -os_window_is_focused(OS_Handle window) +wm_window_is_focused(WM_Window window) { return 0; } internal B32 -os_window_is_fullscreen(OS_Handle window) +wm_window_is_fullscreen(WM_Window window) { return 0; } internal void -os_window_set_fullscreen(OS_Handle window, B32 fullscreen) +wm_window_set_fullscreen(WM_Window window, B32 fullscreen) { } internal B32 -os_window_is_maximized(OS_Handle window) +wm_window_is_maximized(WM_Window window) { return 0; } internal void -os_window_set_maximized(OS_Handle window, B32 maximized) +wm_window_set_maximized(WM_Window window, B32 maximized) { } internal B32 -os_window_is_minimized(OS_Handle window) +wm_window_is_minimized(WM_Window window) { return 0; } internal void -os_window_set_minimized(OS_Handle window, B32 minimized) +wm_window_set_minimized(WM_Window window, B32 minimized) { } internal void -os_window_bring_to_front(OS_Handle window) +wm_window_bring_to_front(WM_Window window) { } internal void -os_window_set_monitor(OS_Handle window, OS_Handle monitor) +wm_window_set_monitor(WM_Window window, WM_Monitor monitor) { } internal void -os_window_clear_custom_border_data(OS_Handle handle) +wm_window_clear_custom_border_data(WM_Window handle) { } internal void -os_window_push_custom_title_bar(OS_Handle handle, F32 thickness) +wm_window_push_custom_title_bar(WM_Window handle, F32 thickness) { } internal void -os_window_push_custom_edges(OS_Handle handle, F32 thickness) +wm_window_push_custom_edges(WM_Window handle, F32 thickness) { } internal void -os_window_push_custom_title_bar_client_area(OS_Handle handle, Rng2F32 rect) +wm_window_push_custom_title_bar_client_area(WM_Window handle, Rng2F32 rect) { } internal Rng2F32 -os_rect_from_window(OS_Handle window) +wm_rect_from_window(WM_Window window) { Rng2F32 rect = r2f32(v2f32(0, 0), v2f32(500, 500)); return rect; } internal Rng2F32 -os_client_rect_from_window(OS_Handle window) +wm_client_rect_from_window(WM_Window window) { Rng2F32 rect = r2f32(v2f32(0, 0), v2f32(500, 500)); return rect; } internal F32 -os_dpi_from_window(OS_Handle window) +wm_dpi_from_window(WM_Window window) { return 96.f; } @@ -152,59 +152,57 @@ os_dpi_from_window(OS_Handle window) //////////////////////////////// //~ rjf: @os_hooks External Windows (Implemented Per-OS) -internal OS_Handle -os_focused_external_window(void) +internal WM_ExtWindow +wm_focused_external_window(void) { - OS_Handle result = {0}; - // TODO(rjf) + WM_ExtWindow result = {0}; return result; } internal void -os_focus_external_window(OS_Handle handle) +wm_focus_external_window(WM_ExtWindow handle) { - // TODO(rjf) } //////////////////////////////// //~ rjf: @os_hooks Monitors (Implemented Per-OS) -internal OS_HandleArray -os_push_monitors_array(Arena *arena) +internal WM_MonitorArray +wm_push_monitors_array(Arena *arena) { - OS_HandleArray arr = {0}; + WM_MonitorArray arr = {0}; return arr; } -internal OS_Handle -os_primary_monitor(void) +internal WM_Monitor +wm_primary_monitor(void) { - OS_Handle handle = {1}; + WM_Monitor handle = {1}; return handle; } -internal OS_Handle -os_monitor_from_window(OS_Handle window) +internal WM_Monitor +wm_monitor_from_window(WM_Window window) { - OS_Handle handle = {1}; + WM_Monitor handle = {1}; return handle; } internal String8 -os_name_from_monitor(Arena *arena, OS_Handle monitor) +wm_name_from_monitor(Arena *arena, WM_Monitor monitor) { return str8_zero(); } internal Vec2F32 -os_dim_from_monitor(OS_Handle monitor) +wm_dim_from_monitor(WM_Monitor monitor) { Vec2F32 v = v2f32(1000, 1000); return v; } internal F32 -os_dpi_from_monitor(OS_Handle monitor) +wm_dpi_from_monitor(WM_Monitor monitor) { return 96.f; } @@ -213,32 +211,32 @@ os_dpi_from_monitor(OS_Handle monitor) //~ rjf: @os_hooks Events (Implemented Per-OS) internal void -os_send_wakeup_event(void) +wm_send_wakeup_event(void) { } -internal OS_EventList -os_get_events(Arena *arena, B32 wait) +internal WM_EventList +wm_get_events(Arena *arena, B32 wait) { - OS_EventList evts = {0}; + WM_EventList evts = {0}; return evts; } -internal OS_Modifiers -os_get_modifiers(void) +internal WM_Modifiers +wm_get_modifiers(void) { - OS_Modifiers f = 0; + WM_Modifiers f = 0; return f; } internal B32 -os_key_is_down(OS_Key key) +wm_key_is_down(WM_Key key) { return 0; } internal Vec2F32 -os_mouse_from_window(OS_Handle window) +wm_mouse_from_window(WM_Window window) { return v2f32(0, 0); } @@ -247,7 +245,7 @@ os_mouse_from_window(OS_Handle window) //~ rjf: @os_hooks Cursors (Implemented Per-OS) internal void -os_set_cursor(OS_Cursor cursor) +wm_set_cursor(WM_Cursor cursor) { } @@ -255,12 +253,12 @@ os_set_cursor(OS_Cursor cursor) //~ rjf: @os_hooks Native User-Facing Graphical Messages (Implemented Per-OS) internal void -os_graphical_message(B32 error, String8 title, String8 message) +wm_graphical_message(B32 error, String8 title, String8 message) { } internal String8 -os_graphical_pick_file(Arena *arena, String8 initial_path) +wm_graphical_pick_file(Arena *arena, String8 initial_path) { return str8_zero(); } @@ -269,11 +267,11 @@ os_graphical_pick_file(Arena *arena, String8 initial_path) //~ rjf: @os_hooks Shell Operations internal void -os_show_in_filesystem_ui(String8 path) +wm_show_in_filesystem_ui(String8 path) { } internal void -os_open_in_browser(String8 url) +wm_open_in_browser(String8 url) { } diff --git a/src/window_manager/window_manager_stub.h b/src/window_manager/window_manager_stub.h index afdfce32..23495c09 100644 --- a/src/window_manager/window_manager_stub.h +++ b/src/window_manager/window_manager_stub.h @@ -1,7 +1,7 @@ // Copyright (c) Epic Games Tools // Licensed under the MIT license (https://opensource.org/license/mit/) -#ifndef OS_GFX_STUB_H -#define OS_GFX_STUB_H +#ifndef WINDOW_MANAGER_STUB_H +#define WINDOW_MANAGER_STUB_H -#endif // OS_GFX_STUB_H +#endif // WINDOW_MANAGER_STUB_H