fix dbg_info loader treatment of nil keys, avoid bad usage of blank '.rdi' files; os_lnx_* -> lnx_*

This commit is contained in:
Ryan Fleury
2026-05-12 14:42:29 -07:00
parent 50a68b9d8c
commit dcc78314ab
10 changed files with 178 additions and 173 deletions
+1 -1
View File
@@ -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 = "build radbin debug telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
.f1 = { .win = "build raddbg asan", .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, },
+30 -26
View File
@@ -205,8 +205,11 @@ di_key_from_path_timestamp(String8 path, U64 min_timestamp)
if(!made_key)
{
made_key = 1;
U128 hash = u128_hash_from_seed_str8(min_timestamp, path);
MemoryCopy(&key, &hash, Min(sizeof(hash), sizeof(key)));
if(path.size != 0)
{
U128 hash = u128_hash_from_seed_str8(min_timestamp, path);
MemoryCopy(&key, &hash, Min(sizeof(hash), sizeof(key)));
}
}
//- rjf: made key -> store in (key -> path/timestamp) table
@@ -698,6 +701,7 @@ di_async_tick(void)
//- rjf: compute key's RDI path
String8 rdi_path = {0};
if(og_path.size != 0)
{
if(og_is_rdi)
{
@@ -1151,8 +1155,8 @@ di_search_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *
U64 element_count = 0;
void *table_base = rdi_section_raw_table_from_kind(rdi, section_kind, &element_count);
U64 element_size = rdi_section_element_size_table[section_kind];
// rjf: do search
// rjf: do search
Rng1U64 range = lane_range(element_count);
for EachInRange(idx, range)
{
@@ -1170,7 +1174,7 @@ di_search_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *
case RDI_SectionKind_UDTs:
{
RDI_UDT *udt = (RDI_UDT *)element;
RDI_TypeNode *type_node = rdi_element_from_name_idx(rdi, TypeNodes, udt->self_type_idx);
RDI_TypeNode *type_node = rdi_element_from_name_idx(rdi, TypeNodes, udt->self_type_idx);
name = fully_qualified_from_rdi_string_and_container(arena, rdi, type_node->user_defined.name_string_idx, udt->container_idx, udt->container_flags);
}break;
case RDI_SectionKind_SourceFiles:
@@ -1192,9 +1196,9 @@ di_search_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *
scratch_end(scratch);
}break;
default:
{
RDI_Symbol *symbol = (RDI_Symbol *)element;
name = fully_qualified_str8_from_rdi_symbol(arena, rdi, symbol);
{
RDI_Symbol *symbol = (RDI_Symbol *)element;
name = fully_qualified_str8_from_rdi_symbol(arena, rdi, symbol);
}break;
}
if(name.size == 0) { continue; }
@@ -1496,12 +1500,12 @@ di_match_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *g
Temp scratch = scratch_begin(0, 0);
//- rjf: unpack key
U64 index = 0;
U64 index = 0;
String8 name = {0};
DI_Key preferred_key = {0};
{
U64 key_read_off = 0;
key_read_off += str8_deserial_read_struct(key, key_read_off, &index);
key_read_off += str8_deserial_read_struct(key, key_read_off, &index);
key_read_off += str8_deserial_read_struct(key, key_read_off, &preferred_key);
key_read_off += str8_deserial_read_struct(key, key_read_off, &name.size);
name.str = push_array_no_zero(scratch.arena, U8, name.size);
@@ -1634,14 +1638,14 @@ di_match_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *g
RDI_NameMapNode *map_node = rdi_name_map_lookup(rdi, &parsed_name_map, leaf_part_of_name.str, leaf_part_of_name.size);
U32 matches_count = 0;
U32 *matches = rdi_matches_from_map_node(rdi, map_node, &matches_count);
// rjf: do we have a container? -> filter matches according to container string also
// rjf: do we have a container? -> filter matches according to container string also
U32 *filtered_matches = matches;
U32 filtered_matches_count = matches_count;
U32 filtered_matches_count = matches_count;
if(container_part_of_name.size != 0)
{
filtered_matches = push_array(scratch.arena, U32, matches_count);
filtered_matches_count = 0;
{
filtered_matches = push_array(scratch.arena, U32, matches_count);
filtered_matches_count = 0;
for EachIndex(match_idx, matches_count)
{
Temp scratch = scratch_begin(0, 0);
@@ -1678,16 +1682,16 @@ di_match_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *g
}
scratch_end(scratch);
}
}
// rjf: do we have a specific unit queried? -> filter matches according to containing unit
#if 0
if(target_unit_index != 0)
{
}
#endif
}
// rjf: do we have a specific unit queried? -> filter matches according to containing unit
#if 0
if(target_unit_index != 0)
{
}
#endif
// rjf: given matches, pick selected & return as result
if(filtered_matches_count != 0)
{
+67 -67
View File
@@ -5,7 +5,7 @@
//~ rjf: Helpers
internal DateTime
os_lnx_date_time_from_tm(tm in, U32 msec)
lnx_date_time_from_tm(tm in, U32 msec)
{
DateTime dt = {0};
dt.sec = in.tm_sec;
@@ -19,7 +19,7 @@ os_lnx_date_time_from_tm(tm in, U32 msec)
}
internal tm
os_lnx_tm_from_date_time(DateTime dt)
lnx_tm_from_date_time(DateTime dt)
{
tm result = {0};
result.tm_sec = dt.sec;
@@ -32,9 +32,9 @@ os_lnx_tm_from_date_time(DateTime dt)
}
internal timespec
os_lnx_timespec_from_date_time(DateTime dt)
lnx_timespec_from_date_time(DateTime dt)
{
tm tm_val = os_lnx_tm_from_date_time(dt);
tm tm_val = lnx_tm_from_date_time(dt);
time_t seconds = timegm(&tm_val);
timespec result = {0};
result.tv_sec = seconds;
@@ -42,25 +42,25 @@ os_lnx_timespec_from_date_time(DateTime dt)
}
internal DenseTime
os_lnx_dense_time_from_timespec(timespec in)
lnx_dense_time_from_timespec(timespec in)
{
DenseTime result = 0;
{
struct tm tm_time = {0};
gmtime_r(&in.tv_sec, &tm_time);
DateTime date_time = os_lnx_date_time_from_tm(tm_time, in.tv_nsec/Million(1));
DateTime date_time = lnx_date_time_from_tm(tm_time, in.tv_nsec/Million(1));
result = dense_time_from_date_time(date_time);
}
return result;
}
internal FileProperties
os_lnx_file_properties_from_stat(struct stat *s)
lnx_file_properties_from_stat(struct stat *s)
{
FileProperties props = {0};
props.size = s->st_size;
props.created = os_lnx_dense_time_from_timespec(s->st_ctim);
props.modified = os_lnx_dense_time_from_timespec(s->st_mtim);
props.created = lnx_dense_time_from_timespec(s->st_ctim);
props.modified = lnx_dense_time_from_timespec(s->st_mtim);
if(s->st_mode & S_IFDIR)
{
props.flags |= FilePropertyFlag_IsFolder;
@@ -69,9 +69,9 @@ os_lnx_file_properties_from_stat(struct stat *s)
}
internal void
os_lnx_safe_call_sig_handler(int x)
lnx_safe_call_sig_handler(int x)
{
LNX_SafeCallChain *chain = os_lnx_safe_call_chain;
LNX_SafeCallChain *chain = lnx_safe_call_chain;
if(chain != 0 && chain->fail_handler != 0)
{
chain->fail_handler(chain->ptr);
@@ -83,20 +83,20 @@ os_lnx_safe_call_sig_handler(int x)
//~ rjf: Entities
internal LNX_Entity *
os_lnx_entity_alloc(LNX_EntityKind kind)
lnx_entity_alloc(LNX_EntityKind kind)
{
LNX_Entity *entity = 0;
DeferLoop(pthread_mutex_lock(&os_lnx_state.entity_mutex),
pthread_mutex_unlock(&os_lnx_state.entity_mutex))
DeferLoop(pthread_mutex_lock(&lnx_state.entity_mutex),
pthread_mutex_unlock(&lnx_state.entity_mutex))
{
entity = os_lnx_state.entity_free;
entity = lnx_state.entity_free;
if(entity)
{
SLLStackPop(os_lnx_state.entity_free);
SLLStackPop(lnx_state.entity_free);
}
else
{
entity = push_array_no_zero(os_lnx_state.entity_arena, LNX_Entity, 1);
entity = push_array_no_zero(lnx_state.entity_arena, LNX_Entity, 1);
}
}
MemoryZeroStruct(entity);
@@ -105,12 +105,12 @@ os_lnx_entity_alloc(LNX_EntityKind kind)
}
internal void
os_lnx_entity_release(LNX_Entity *entity)
lnx_entity_release(LNX_Entity *entity)
{
DeferLoop(pthread_mutex_lock(&os_lnx_state.entity_mutex),
pthread_mutex_unlock(&os_lnx_state.entity_mutex))
DeferLoop(pthread_mutex_lock(&lnx_state.entity_mutex),
pthread_mutex_unlock(&lnx_state.entity_mutex))
{
SLLStackPush(os_lnx_state.entity_free, entity);
SLLStackPush(lnx_state.entity_free, entity);
}
}
@@ -118,7 +118,7 @@ os_lnx_entity_release(LNX_Entity *entity)
//~ rjf: Thread Entry Point
internal void *
os_lnx_thread_entry_point(void *ptr)
lnx_thread_entry_point(void *ptr)
{
LNX_Entity *entity = (LNX_Entity *)ptr;
ThreadEntryPointFunctionType *func = entity->thread.func;
@@ -153,7 +153,7 @@ now_time_universal(void)
time(&t);
struct tm universal_tm = {0};
gmtime_r(&t, &universal_tm);
DateTime result = os_lnx_date_time_from_tm(universal_tm, 0);
DateTime result = lnx_date_time_from_tm(universal_tm, 0);
return result;
}
@@ -161,14 +161,14 @@ internal DateTime
universal_from_local_time(DateTime *dt)
{
// rjf: local DateTime -> universal time_t
tm local_tm = os_lnx_tm_from_date_time(*dt);
tm local_tm = lnx_tm_from_date_time(*dt);
local_tm.tm_isdst = -1;
time_t universal_t = mktime(&local_tm);
// rjf: universal time_t -> DateTime
tm universal_tm = {0};
gmtime_r(&universal_t, &universal_tm);
DateTime result = os_lnx_date_time_from_tm(universal_tm, 0);
DateTime result = lnx_date_time_from_tm(universal_tm, 0);
return result;
}
@@ -176,14 +176,14 @@ internal DateTime
local_from_universal_time(DateTime *dt)
{
// rjf: universal DateTime -> local time_t
tm universal_tm = os_lnx_tm_from_date_time(*dt);
tm universal_tm = lnx_tm_from_date_time(*dt);
universal_tm.tm_isdst = -1;
time_t universal_t = timegm(&universal_tm);
tm local_tm = {0};
localtime_r(&universal_t, &local_tm);
// rjf: local tm -> DateTime
DateTime result = os_lnx_date_time_from_tm(local_tm, 0);
DateTime result = lnx_date_time_from_tm(local_tm, 0);
return result;
}
@@ -324,7 +324,7 @@ shared_memory_view_close(SharedMemory handle, void *ptr, Rng1U64 range)
internal SystemInfo *
get_system_info(void)
{
return &os_lnx_state.system_info;
return &lnx_state.system_info;
}
////////////////////////////////
@@ -353,14 +353,14 @@ set_platform_thread_name(String8 name)
internal Thread
thread_launch(ThreadEntryPointFunctionType *f, void *p)
{
LNX_Entity *entity = os_lnx_entity_alloc(LNX_EntityKind_Thread);
LNX_Entity *entity = lnx_entity_alloc(LNX_EntityKind_Thread);
entity->thread.func = f;
entity->thread.ptr = p;
{
int pthread_result = pthread_create(&entity->thread.handle, 0, os_lnx_thread_entry_point, entity);
int pthread_result = pthread_create(&entity->thread.handle, 0, lnx_thread_entry_point, entity);
if(pthread_result == -1)
{
os_lnx_entity_release(entity);
lnx_entity_release(entity);
entity = 0;
}
}
@@ -375,7 +375,7 @@ thread_join(Thread thread, U64 endt_us)
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);
lnx_entity_release(entity);
return result;
}
@@ -384,7 +384,7 @@ thread_detach(Thread thread)
{
if(MemoryIsZeroStruct(&thread)) { return; }
LNX_Entity *entity = (LNX_Entity *)thread.u64[0];
os_lnx_entity_release(entity);
lnx_entity_release(entity);
}
////////////////////////////////
@@ -395,11 +395,11 @@ thread_detach(Thread thread)
internal Mutex
mutex_alloc(void)
{
LNX_Entity *entity = os_lnx_entity_alloc(LNX_EntityKind_Mutex);
LNX_Entity *entity = lnx_entity_alloc(LNX_EntityKind_Mutex);
int init_result = pthread_mutex_init(&entity->mutex_handle, 0);
if(init_result == -1)
{
os_lnx_entity_release(entity);
lnx_entity_release(entity);
entity = 0;
}
Mutex handle = {(U64)entity};
@@ -412,7 +412,7 @@ mutex_release(Mutex mutex)
if(MemoryIsZeroStruct(&mutex)) { return; }
LNX_Entity *entity = (LNX_Entity *)mutex.u64[0];
pthread_mutex_destroy(&entity->mutex_handle);
os_lnx_entity_release(entity);
lnx_entity_release(entity);
}
internal void
@@ -436,11 +436,11 @@ mutex_drop(Mutex mutex)
internal RWMutex
rw_mutex_alloc(void)
{
LNX_Entity *entity = os_lnx_entity_alloc(LNX_EntityKind_RWMutex);
LNX_Entity *entity = lnx_entity_alloc(LNX_EntityKind_RWMutex);
int init_result = pthread_rwlock_init(&entity->rwmutex_handle, 0);
if(init_result == -1)
{
os_lnx_entity_release(entity);
lnx_entity_release(entity);
entity = 0;
}
RWMutex handle = {(U64)entity};
@@ -453,7 +453,7 @@ rw_mutex_release(RWMutex mutex)
if(MemoryIsZeroStruct(&mutex)) { return; }
LNX_Entity *entity = (LNX_Entity *)mutex.u64[0];
pthread_rwlock_destroy(&entity->rwmutex_handle);
os_lnx_entity_release(entity);
lnx_entity_release(entity);
}
internal void
@@ -484,11 +484,11 @@ rw_mutex_drop(RWMutex mutex, B32 write_mode)
internal CondVar
cond_var_alloc(void)
{
LNX_Entity *entity = os_lnx_entity_alloc(LNX_EntityKind_ConditionVariable);
LNX_Entity *entity = lnx_entity_alloc(LNX_EntityKind_ConditionVariable);
int init_result = pthread_cond_init(&entity->cv.cond_handle, 0);
if(init_result == -1)
{
os_lnx_entity_release(entity);
lnx_entity_release(entity);
entity = 0;
}
int init2_result = 0;
@@ -499,7 +499,7 @@ cond_var_alloc(void)
if(init2_result == -1)
{
pthread_cond_destroy(&entity->cv.cond_handle);
os_lnx_entity_release(entity);
lnx_entity_release(entity);
entity = 0;
}
CondVar handle = {(U64)entity};
@@ -513,7 +513,7 @@ cond_var_release(CondVar cv)
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);
lnx_entity_release(entity);
}
internal B32
@@ -713,7 +713,7 @@ semaphore_drop(Semaphore semaphore)
internal Barrier
barrier_alloc(U64 count)
{
LNX_Entity *entity = os_lnx_entity_alloc(LNX_EntityKind_Barrier);
LNX_Entity *entity = lnx_entity_alloc(LNX_EntityKind_Barrier);
if(entity != 0)
{
pthread_barrier_init(&entity->barrier, 0, count);
@@ -729,7 +729,7 @@ barrier_release(Barrier barrier)
if(entity != 0)
{
pthread_barrier_destroy(&entity->barrier);
os_lnx_entity_release(entity);
lnx_entity_release(entity);
}
}
@@ -751,13 +751,13 @@ safe_call(ThreadEntryPointFunctionType *func, ThreadEntryPointFunctionType *fail
{
// rjf: push handler to chain
LNX_SafeCallChain chain = {0};
SLLStackPush(os_lnx_safe_call_chain, &chain);
SLLStackPush(lnx_safe_call_chain, &chain);
chain.fail_handler = fail_handler;
chain.ptr = ptr;
// rjf: set up sig handler info
struct sigaction new_act = {0};
new_act.sa_handler = os_lnx_safe_call_sig_handler;
new_act.sa_handler = lnx_safe_call_sig_handler;
int signals_to_handle[] =
{
SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP,
@@ -883,7 +883,7 @@ file_set_times(File file, DateTime date_time)
{
if(file_match(file, file_zero())) { return 0; }
int fd = (int)file.u64[0];
timespec time = os_lnx_timespec_from_date_time(date_time);
timespec time = lnx_timespec_from_date_time(date_time);
timespec times[2] = {time, time};
int futimens_result = futimens(fd, times);
B32 good = (futimens_result != -1);
@@ -900,7 +900,7 @@ properties_from_file(File file)
FileProperties props = {0};
if(fstat_result != -1)
{
props = os_lnx_file_properties_from_stat(&fd_stat);
props = lnx_file_properties_from_stat(&fd_stat);
}
return props;
}
@@ -1036,7 +1036,7 @@ properties_from_file_path(String8 path)
FileProperties props = {0};
if(stat_result != -1)
{
props = os_lnx_file_properties_from_stat(&f_stat);
props = lnx_file_properties_from_stat(&f_stat);
}
scratch_end(scratch);
return props;
@@ -1135,7 +1135,7 @@ file_iter_next(Arena *arena, FileIter *iter, FileInfo *info_out)
info_out->name = push_str8_copy(arena, str8_cstring(lnx_iter->dp->d_name));
if(stat_result != -1)
{
info_out->props = os_lnx_file_properties_from_stat(&st);
info_out->props = lnx_file_properties_from_stat(&st);
}
break;
}
@@ -1187,7 +1187,7 @@ abort_self(S32 exit_code)
internal ProcessInfo *
get_process_info(void)
{
return &os_lnx_state.process_info;
return &lnx_state.process_info;
}
internal String8
@@ -1255,7 +1255,7 @@ process_launch(ProcessLaunchParams *params)
char **envp = 0;
if(params->inherit_env)
{
envp = os_lnx_state.default_env;
envp = lnx_state.default_env;
}
else
{
@@ -1453,14 +1453,14 @@ main(int argc, char **argv)
{
//- rjf: get statically-allocated system/process info
{
SystemInfo *info = &os_lnx_state.system_info;
SystemInfo *info = &lnx_state.system_info;
info->logical_processor_count = (U32)get_nprocs();
info->page_size = (U64)getpagesize();
info->large_page_size = MB(2);
info->allocation_granularity = info->page_size;
}
{
ProcessInfo *info = &os_lnx_state.process_info;
ProcessInfo *info = &lnx_state.process_info;
info->pid = (U32)getpid();
}
@@ -1469,28 +1469,28 @@ main(int argc, char **argv)
tctx_select(tctx);
//- rjf: set up dynamically allocated state
os_lnx_state.arena = arena_alloc();
os_lnx_state.entity_arena = arena_alloc();
pthread_mutex_init(&os_lnx_state.entity_mutex, 0);
lnx_state.arena = arena_alloc();
lnx_state.entity_arena = arena_alloc();
pthread_mutex_init(&lnx_state.entity_mutex, 0);
// cache default environment
{
U64 env_count = 0;
for(; __environ[env_count] != 0; env_count += 1) {}
char **default_env = push_array(os_lnx_state.arena, char *, env_count+1);
char **default_env = push_array(lnx_state.arena, char *, env_count+1);
for EachIndex(idx, env_count)
{
default_env[idx] = (char *)str8_copy(os_lnx_state.arena, str8_cstring(__environ[idx])).str;
default_env[idx] = (char *)str8_copy(lnx_state.arena, str8_cstring(__environ[idx])).str;
}
default_env[env_count] = 0;
os_lnx_state.default_env_count = env_count;
os_lnx_state.default_env = default_env;
lnx_state.default_env_count = env_count;
lnx_state.default_env = default_env;
}
//- rjf: grab dynamically allocated system info
{
Temp scratch = scratch_begin(0, 0);
SystemInfo *info = &os_lnx_state.system_info;
SystemInfo *info = &lnx_state.system_info;
// rjf: get machine name
B32 got_final_result = 0;
@@ -1513,7 +1513,7 @@ main(int argc, char **argv)
if(got_final_result && size > 0)
{
info->machine_name.size = size;
info->machine_name.str = push_array_no_zero(os_lnx_state.arena, U8, info->machine_name.size + 1);
info->machine_name.str = push_array_no_zero(lnx_state.arena, U8, info->machine_name.size + 1);
MemoryCopy(info->machine_name.str, buffer, info->machine_name.size);
info->machine_name.str[info->machine_name.size] = 0;
}
@@ -1524,7 +1524,7 @@ main(int argc, char **argv)
//- rjf: grab dynamically allocated process info
{
Temp scratch = scratch_begin(0, 0);
ProcessInfo *info = &os_lnx_state.process_info;
ProcessInfo *info = &lnx_state.process_info;
// rjf: grab binary path
{
@@ -1549,13 +1549,13 @@ main(int argc, char **argv)
{
String8 full_name = str8(buffer, size);
String8 name_chopped = str8_chop_last_slash(full_name);
info->binary_path = push_str8_copy(os_lnx_state.arena, name_chopped);
info->binary_path = push_str8_copy(lnx_state.arena, name_chopped);
}
}
// rjf: grab initial directory
{
info->initial_path = get_current_path(os_lnx_state.arena);
info->initial_path = get_current_path(lnx_state.arena);
}
// rjf: grab home directory
+12 -12
View File
@@ -61,7 +61,7 @@ struct LNX_FileIter
struct dirent *dp;
String8 path;
};
StaticAssert(sizeof(Member(FileIter, memory)) >= sizeof(LNX_FileIter), os_lnx_file_iter_size_check);
StaticAssert(sizeof(Member(FileIter, memory)) >= sizeof(LNX_FileIter), lnx_file_iter_size_check);
////////////////////////////////
//~ rjf: Safe Call Handler Chain
@@ -130,28 +130,28 @@ struct LNX_State
////////////////////////////////
//~ rjf: Globals
global LNX_State os_lnx_state = {0};
thread_static LNX_SafeCallChain *os_lnx_safe_call_chain = 0;
global LNX_State lnx_state = {0};
thread_static LNX_SafeCallChain *lnx_safe_call_chain = 0;
////////////////////////////////
//~ rjf: Helpers
internal DateTime os_lnx_date_time_from_tm(tm in, U32 msec);
internal tm os_lnx_tm_from_date_time(DateTime dt);
internal timespec os_lnx_timespec_from_date_time(DateTime dt);
internal DenseTime os_lnx_dense_time_from_timespec(timespec in);
internal FileProperties os_lnx_file_properties_from_stat(struct stat *s);
internal void os_lnx_safe_call_sig_handler(int x);
internal DateTime lnx_date_time_from_tm(tm in, U32 msec);
internal tm lnx_tm_from_date_time(DateTime dt);
internal timespec lnx_timespec_from_date_time(DateTime dt);
internal DenseTime lnx_dense_time_from_timespec(timespec in);
internal FileProperties lnx_file_properties_from_stat(struct stat *s);
internal void lnx_safe_call_sig_handler(int x);
////////////////////////////////
//~ rjf: Entities
internal LNX_Entity *os_lnx_entity_alloc(LNX_EntityKind kind);
internal void os_lnx_entity_release(LNX_Entity *entity);
internal LNX_Entity *lnx_entity_alloc(LNX_EntityKind kind);
internal void lnx_entity_release(LNX_Entity *entity);
////////////////////////////////
//~ rjf: Thread Entry Point
internal void *os_lnx_thread_entry_point(void *ptr);
internal void *lnx_thread_entry_point(void *ptr);
#endif // LINUX_BASE_H
+3 -3
View File
@@ -2280,14 +2280,14 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, ProcessLaunchParams *params)
}
// setup target environment
U64 envc = os_lnx_state.default_env_count + params->env.node_count + 1;
U64 envc = lnx_state.default_env_count + params->env.node_count + 1;
char **envp = push_array(scratch.arena, char *, envc);
{
// copy default environment
MemoryCopyTyped(envp, os_lnx_state.default_env, os_lnx_state.default_env_count);
MemoryCopyTyped(envp, lnx_state.default_env, lnx_state.default_env_count);
// copy user environment
U64 idx = os_lnx_state.default_env_count;
U64 idx = lnx_state.default_env_count;
for EachNode(n, String8Node, params->env.first)
{
envp[idx] = (char *)str8_copy(scratch.arena, n->string).str;
+51 -51
View File
@@ -5,10 +5,10 @@
//~ rjf: Helpers
internal LNX_WM_Window *
os_lnx_window_from_x11window(Window window)
lnx_window_from_x11window(Window window)
{
LNX_WM_Window *result = 0;
for(LNX_WM_Window *w = os_lnx_gfx_state->first_window; w != 0; w = w->next)
for(LNX_WM_Window *w = lnx_wm_state->first_window; w != 0; w = w->next)
{
if(w->window == window)
{
@@ -27,22 +27,22 @@ wm_init(void)
{
//- rjf: initialize basics
Arena *arena = arena_alloc();
os_lnx_gfx_state = push_array(arena, LNX_WM_GfxState, 1);
os_lnx_gfx_state->arena = arena;
os_lnx_gfx_state->display = XOpenDisplay(0);
lnx_wm_state = push_array(arena, LNX_WM_State, 1);
lnx_wm_state->arena = arena;
lnx_wm_state->display = XOpenDisplay(0);
//- rjf: calculate atoms
os_lnx_gfx_state->wm_delete_window_atom = XInternAtom(os_lnx_gfx_state->display, "WM_DELETE_WINDOW", 0);
os_lnx_gfx_state->wm_sync_request_atom = XInternAtom(os_lnx_gfx_state->display, "_NET_WM_SYNC_REQUEST", 0);
os_lnx_gfx_state->wm_sync_request_counter_atom = XInternAtom(os_lnx_gfx_state->display, "_NET_WM_SYNC_REQUEST_COUNTER", 0);
lnx_wm_state->wm_delete_window_atom = XInternAtom(lnx_wm_state->display, "WM_DELETE_WINDOW", 0);
lnx_wm_state->wm_sync_request_atom = XInternAtom(lnx_wm_state->display, "_NET_WM_SYNC_REQUEST", 0);
lnx_wm_state->wm_sync_request_counter_atom = XInternAtom(lnx_wm_state->display, "_NET_WM_SYNC_REQUEST_COUNTER", 0);
//- rjf: open im
os_lnx_gfx_state->xim = XOpenIM(os_lnx_gfx_state->display, 0, 0, 0);
lnx_wm_state->xim = XOpenIM(lnx_wm_state->display, 0, 0, 0);
//- rjf: fill out gfx info
os_lnx_gfx_state->gfx_info.double_click_time = 0.5f;
os_lnx_gfx_state->gfx_info.caret_blink_time = 0.5f;
os_lnx_gfx_state->gfx_info.default_refresh_rate = 60.f;
lnx_wm_state->gfx_info.double_click_time = 0.5f;
lnx_wm_state->gfx_info.caret_blink_time = 0.5f;
lnx_wm_state->gfx_info.default_refresh_rate = 60.f;
//- rjf: fill out cursors
{
@@ -65,7 +65,7 @@ wm_init(void)
};
for EachElement(idx, map)
{
os_lnx_gfx_state->cursors[map[idx].cursor] = XCreateFontCursor(os_lnx_gfx_state->display, map[idx].id);
lnx_wm_state->cursors[map[idx].cursor] = XCreateFontCursor(lnx_wm_state->display, map[idx].id);
}
}
}
@@ -76,7 +76,7 @@ wm_init(void)
internal WM_SystemInfo *
wm_get_system_info(void)
{
return &os_lnx_gfx_state->gfx_info;
return &lnx_wm_state->gfx_info;
}
////////////////////////////////
@@ -104,21 +104,21 @@ wm_window_open(Rng2F32 rect, WM_WindowFlags flags, String8 title)
Vec2F32 resolution = dim_2f32(rect);
//- rjf: allocate window
LNX_WM_Window *w = os_lnx_gfx_state->free_window;
LNX_WM_Window *w = lnx_wm_state->free_window;
if(w)
{
SLLStackPop(os_lnx_gfx_state->free_window);
SLLStackPop(lnx_wm_state->free_window);
}
else
{
w = push_array_no_zero(os_lnx_gfx_state->arena, LNX_WM_Window, 1);
w = push_array_no_zero(lnx_wm_state->arena, LNX_WM_Window, 1);
}
MemoryZeroStruct(w);
DLLPushBack(os_lnx_gfx_state->first_window, os_lnx_gfx_state->last_window, w);
DLLPushBack(lnx_wm_state->first_window, lnx_wm_state->last_window, w);
//- rjf: create window & equip with x11 info
w->window = XCreateWindow(os_lnx_gfx_state->display,
XDefaultRootWindow(os_lnx_gfx_state->display),
w->window = XCreateWindow(lnx_wm_state->display,
XDefaultRootWindow(lnx_wm_state->display),
0, 0, resolution.x, resolution.y,
0,
CopyFromParent,
@@ -126,7 +126,7 @@ wm_window_open(Rng2F32 rect, WM_WindowFlags flags, String8 title)
CopyFromParent,
0,
0);
XSelectInput(os_lnx_gfx_state->display, w->window,
XSelectInput(lnx_wm_state->display, w->window,
ExposureMask|
PointerMotionMask|
ButtonPressMask|
@@ -136,19 +136,19 @@ wm_window_open(Rng2F32 rect, WM_WindowFlags flags, String8 title)
FocusChangeMask);
Atom protocols[] =
{
os_lnx_gfx_state->wm_delete_window_atom,
os_lnx_gfx_state->wm_sync_request_atom,
lnx_wm_state->wm_delete_window_atom,
lnx_wm_state->wm_sync_request_atom,
};
XSetWMProtocols(os_lnx_gfx_state->display, w->window, protocols, ArrayCount(protocols));
XSetWMProtocols(lnx_wm_state->display, w->window, protocols, ArrayCount(protocols));
{
XSyncValue initial_value;
XSyncIntToValue(&initial_value, 0);
w->counter_xid = XSyncCreateCounter(os_lnx_gfx_state->display, initial_value);
w->counter_xid = XSyncCreateCounter(lnx_wm_state->display, initial_value);
}
XChangeProperty(os_lnx_gfx_state->display, w->window, os_lnx_gfx_state->wm_sync_request_counter_atom, XA_CARDINAL, 32, PropModeReplace, (U8 *)&w->counter_xid, 1);
XChangeProperty(lnx_wm_state->display, w->window, lnx_wm_state->wm_sync_request_counter_atom, XA_CARDINAL, 32, PropModeReplace, (U8 *)&w->counter_xid, 1);
//- rjf: create xic
w->xic = XCreateIC(os_lnx_gfx_state->xim,
w->xic = XCreateIC(lnx_wm_state->xim,
XNInputStyle, XIMPreeditNothing|XIMStatusNothing,
XNClientWindow, w->window,
XNFocusWindow, w->window,
@@ -157,7 +157,7 @@ wm_window_open(Rng2F32 rect, WM_WindowFlags flags, String8 title)
//- rjf: attach name
Temp scratch = scratch_begin(0, 0);
String8 title_copy = push_str8_copy(scratch.arena, title);
XStoreName(os_lnx_gfx_state->display, w->window, (char *)title_copy.str);
XStoreName(lnx_wm_state->display, w->window, (char *)title_copy.str);
scratch_end(scratch);
//- rjf: convert to handle & return
@@ -170,7 +170,7 @@ wm_window_close(WM_Window handle)
{
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);
XDestroyWindow(lnx_wm_state->display, w->window);
}
internal void
@@ -180,7 +180,7 @@ wm_window_set_title(WM_Window handle, String8 title)
Temp scratch = scratch_begin(0, 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);
XStoreName(lnx_wm_state->display, w->window, (char *)title_copy.str);
scratch_end(scratch);
}
@@ -189,7 +189,7 @@ wm_window_first_paint(WM_Window handle)
{
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);
XMapWindow(lnx_wm_state->display, w->window);
}
internal void
@@ -197,7 +197,7 @@ wm_window_focus(WM_Window handle)
{
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);
XSetInputFocus(lnx_wm_state->display, w->window, RevertToNone, CurrentTime);
}
internal B32
@@ -207,7 +207,7 @@ wm_window_is_focused(WM_Window handle)
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);
XGetInputFocus(lnx_wm_state->display, &focused_window, &revert_to);
B32 result = (w->window == focused_window);
return result;
}
@@ -305,7 +305,7 @@ wm_rect_from_window(WM_Window handle)
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);
Status s = XGetWindowAttributes(lnx_wm_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);
return result;
}
@@ -315,7 +315,7 @@ wm_client_rect_from_window(WM_Window handle)
{
LNX_WM_Window *w = (LNX_WM_Window *)handle.u64[0];
XWindowAttributes atts = {0};
Status s = XGetWindowAttributes(os_lnx_gfx_state->display, w->window, &atts);
Status s = XGetWindowAttributes(lnx_wm_state->display, w->window, &atts);
Rng2F32 result = r2f32p(0, 0, (F32)atts.width, (F32)atts.height);
return result;
}
@@ -405,10 +405,10 @@ internal WM_EventList
wm_get_events(Arena *arena, B32 wait)
{
WM_EventList evts = {0};
for(;XPending(os_lnx_gfx_state->display) > 0 || (wait && evts.count == 0);)
for(;XPending(lnx_wm_state->display) > 0 || (wait && evts.count == 0);)
{
XEvent evt = {0};
XNextEvent(os_lnx_gfx_state->display, &evt);
XNextEvent(lnx_wm_state->display, &evt);
B32 set_mouse_cursor = 0;
switch(evt.type)
{
@@ -425,7 +425,7 @@ wm_get_events(Arena *arena, B32 wait)
if(evt.xkey.state & Mod1Mask) { modifiers |= WM_Modifier_Alt; }
// rjf: map keycode -> keysym & codepoint
LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xkey.window);
LNX_WM_Window *window = 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);
@@ -552,7 +552,7 @@ wm_get_events(Arena *arena, B32 wait)
}
// rjf: push event
LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xbutton.window);
LNX_WM_Window *window = lnx_window_from_x11window(evt.xbutton.window);
if(key != WM_Key_Null)
{
WM_Event *e = wm_event_list_push_new(arena, &evts, evt.type == ButtonPress ? WM_EventKind_Press : WM_EventKind_Release);
@@ -575,7 +575,7 @@ wm_get_events(Arena *arena, B32 wait)
//- rjf: mouse motion
case MotionNotify:
{
LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xclient.window);
LNX_WM_Window *window = 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;
@@ -589,7 +589,7 @@ wm_get_events(Arena *arena, B32 wait)
}break;
case FocusOut:
{
LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xfocus.window);
LNX_WM_Window *window = 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;
@@ -597,15 +597,15 @@ wm_get_events(Arena *arena, B32 wait)
//- rjf: client messages
case ClientMessage:
{
if((Atom)evt.xclient.data.l[0] == os_lnx_gfx_state->wm_delete_window_atom)
if((Atom)evt.xclient.data.l[0] == lnx_wm_state->wm_delete_window_atom)
{
LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xclient.window);
LNX_WM_Window *window = 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)
else if((Atom)evt.xclient.data.l[0] == lnx_wm_state->wm_sync_request_atom)
{
LNX_WM_Window *window = os_lnx_window_from_x11window(evt.xclient.window);
LNX_WM_Window *window = lnx_window_from_x11window(evt.xclient.window);
if(window != 0)
{
window->counter_value = 0;
@@ -613,7 +613,7 @@ wm_get_events(Arena *arena, B32 wait)
window->counter_value |= (evt.xclient.data.l[3] << 32);
XSyncValue value;
XSyncIntToValue(&value, window->counter_value);
XSyncSetCounter(os_lnx_gfx_state->display, window->counter_xid, value);
XSyncSetCounter(lnx_wm_state->display, window->counter_xid, value);
}
}
}break;
@@ -627,10 +627,10 @@ wm_get_events(Arena *arena, B32 wait)
int child_rel_x = 0;
int child_rel_y = 0;
unsigned int mask = 0;
if(XQueryPointer(os_lnx_gfx_state->display, XDefaultRootWindow(os_lnx_gfx_state->display), &root_window, &child_window, &root_rel_x, &root_rel_y, &child_rel_x, &child_rel_y, &mask))
if(XQueryPointer(lnx_wm_state->display, XDefaultRootWindow(lnx_wm_state->display), &root_window, &child_window, &root_rel_x, &root_rel_y, &child_rel_x, &child_rel_y, &mask))
{
XDefineCursor(os_lnx_gfx_state->display, root_window, os_lnx_gfx_state->cursors[os_lnx_gfx_state->last_set_cursor]);
XFlush(os_lnx_gfx_state->display);
XDefineCursor(lnx_wm_state->display, root_window, lnx_wm_state->cursors[lnx_wm_state->last_set_cursor]);
XFlush(lnx_wm_state->display);
}
}
}
@@ -665,7 +665,7 @@ wm_mouse_from_window(WM_Window handle)
int child_rel_x = 0;
int child_rel_y = 0;
unsigned int mask = 0;
if(XQueryPointer(os_lnx_gfx_state->display, w->window, &root_window, &child_window, &root_rel_x, &root_rel_y, &child_rel_x, &child_rel_y, &mask))
if(XQueryPointer(lnx_wm_state->display, w->window, &root_window, &child_window, &root_rel_x, &root_rel_y, &child_rel_x, &child_rel_y, &mask))
{
result.x = child_rel_x;
result.y = child_rel_y;
@@ -680,7 +680,7 @@ wm_mouse_from_window(WM_Window handle)
internal void
wm_set_cursor(WM_Cursor cursor)
{
os_lnx_gfx_state->last_set_cursor = cursor;
lnx_wm_state->last_set_cursor = cursor;
}
////////////////////////////////
@@ -31,8 +31,8 @@ struct LNX_WM_Window
////////////////////////////////
//~ rjf: State Bundle
typedef struct LNX_WM_GfxState LNX_WM_GfxState;
struct LNX_WM_GfxState
typedef struct LNX_WM_State LNX_WM_State;
struct LNX_WM_State
{
Arena *arena;
Display *display;
@@ -51,11 +51,11 @@ struct LNX_WM_GfxState
////////////////////////////////
//~ rjf: Globals
global LNX_WM_GfxState *os_lnx_gfx_state = 0;
global LNX_WM_State *lnx_wm_state = 0;
////////////////////////////////
//~ rjf: Helpers
internal LNX_WM_Window *os_lnx_window_from_x11window(Window window);
internal LNX_WM_Window *lnx_window_from_x11window(Window window);
#endif // LINUX_WINDOW_MANAGER_H
+3 -2
View File
@@ -10,13 +10,14 @@
// [ ] value coloring view in watch window, so you can quickly scroll & see values outside of a threshold
// [x] step out of scopes / loops
//
// [ ] codebase-internal barrier impl (win7/linux support)
// [ ] asan pass
// [ ] external window focusing bugs
// [ ] PDB -> RDI conversion memory usage
// [x] codebase-internal barrier impl (win7/linux support)
// [x] policy for closing debug info which is no longer relevant?
// [x] killing/restarting thread performance (#780)
//
// [ ] PDB -> RDI conversion memory usage
//
// [ ] project/user file improvements
// [ ] "default" -> "untitled"
// [ ] should clear default project data every time the program starts
@@ -20,7 +20,7 @@ r_ogl_os_init(CmdLine *cmdln)
//- rjf: get EGL display
{
r_ogl_lnx_state->display = eglGetDisplay((EGLNativeDisplayType)os_lnx_gfx_state->display);
r_ogl_lnx_state->display = eglGetDisplay((EGLNativeDisplayType)lnx_wm_state->display);
if(r_ogl_lnx_state->display == EGL_NO_DISPLAY)
{
wm_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Failed to get EGL display."));
@@ -14,7 +14,7 @@ r_ogl_os_init(CmdLine *cmdln)
//- rjf: require GLX 1.3+
int glx_version_major = 0;
int glx_version_minor = 0;
if(!glXQueryVersion(os_lnx_gfx_state->display, &glx_version_major, &glx_version_minor) ||
if(!glXQueryVersion(lnx_wm_state->display, &glx_version_major, &glx_version_minor) ||
(glx_version_major == 1 && glx_version_minor < 3) ||
glx_version_major < 1)
{
@@ -42,7 +42,7 @@ r_ogl_os_init(CmdLine *cmdln)
None
};
int framebuffer_configs_count = 0;
GLXFBConfig *framebuffer_configs = glXChooseFBConfig(os_lnx_gfx_state->display, DefaultScreen(os_lnx_gfx_state->display), framebuffer_config_options, &framebuffer_configs_count);
GLXFBConfig *framebuffer_configs = glXChooseFBConfig(lnx_wm_state->display, DefaultScreen(lnx_wm_state->display), framebuffer_config_options, &framebuffer_configs_count);
if(framebuffer_configs == 0)
{
wm_graphical_message(1, str8_lit("Fatal Error"), str8_lit("Could not find a suitable framebuffer configuration."));
@@ -72,10 +72,10 @@ r_ogl_os_init(CmdLine *cmdln)
GLX_CONTEXT_FLAGS_ARB, !!debug_mode*GLX_CONTEXT_DEBUG_BIT_ARB,
None
};
r_ogl_lnx_ctx = glXCreateContextAttribsARB(os_lnx_gfx_state->display, framebuffer_config, 0, 1, context_options);
r_ogl_lnx_ctx = glXCreateContextAttribsARB(lnx_wm_state->display, framebuffer_config, 0, 1, context_options);
}
glXMakeCurrent(os_lnx_gfx_state->display, 0, r_ogl_lnx_ctx);
glXMakeCurrent(lnx_wm_state->display, 0, r_ogl_lnx_ctx);
}
internal R_Handle
@@ -95,12 +95,12 @@ internal void
r_ogl_os_select_window(WM_Window os, R_Handle r)
{
LNX_WM_Window *w = (LNX_WM_Window *)os.u64[0];
glXMakeCurrent(os_lnx_gfx_state->display, w->window, r_ogl_lnx_ctx);
glXMakeCurrent(lnx_wm_state->display, w->window, r_ogl_lnx_ctx);
}
internal void
r_ogl_os_window_swap(WM_Window os, R_Handle r)
{
LNX_WM_Window *w = (LNX_WM_Window *)os.u64[0];
glXSwapBuffers(os_lnx_gfx_state->display, w->window);
glXSwapBuffers(lnx_wm_state->display, w->window);
}