mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-09 15:28:08 +00:00
add cstr union field to String8 and remove char* casts from the Linux code
This commit is contained in:
@@ -10,7 +10,11 @@
|
||||
typedef struct String8 String8;
|
||||
struct String8
|
||||
{
|
||||
U8 *str;
|
||||
union
|
||||
{
|
||||
U8 *str;
|
||||
char *cstr;
|
||||
};
|
||||
U64 size;
|
||||
};
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ dmn_lnx_exe_path_from_pid(Arena *arena, pid_t pid)
|
||||
for(S64 r = 0, cap = PATH_MAX; r < 4; cap *= 2, r += 1)
|
||||
{
|
||||
U8 *buffer = push_array(arena, U8, cap);
|
||||
readlink_result = readlink((char *)exe_link_path.str, (char *)buffer, cap);
|
||||
readlink_result = readlink(exe_link_path.cstr, (char *)buffer, cap);
|
||||
|
||||
if(readlink_result < 0)
|
||||
{
|
||||
@@ -139,7 +139,7 @@ dmn_lnx_dl_path_from_pid(Arena *arena, pid_t pid, U64 auxv_base)
|
||||
|
||||
String8 dl_path = {0};
|
||||
|
||||
int maps_fd = open((char *)str8f(scratch.arena, "/proc/%d/maps", pid).str, O_RDONLY);
|
||||
int maps_fd = open(str8f(scratch.arena, "/proc/%d/maps", pid).cstr, O_RDONLY);
|
||||
if(maps_fd != -1)
|
||||
{
|
||||
// read entire /proc/pid/maps
|
||||
@@ -212,7 +212,7 @@ dmn_lnx_ehdr_from_pid(pid_t pid)
|
||||
ELF_Hdr64 exe = {0};
|
||||
B32 is_read = 0;
|
||||
|
||||
char *exe_path = (char *)push_str8f(scratch.arena, "/proc/%d/exe", pid).str;
|
||||
char *exe_path = push_str8f(scratch.arena, "/proc/%d/exe", pid).cstr;
|
||||
int exe_fd = OS_LNX_RETRY_ON_EINTR(open(exe_path, O_RDONLY));
|
||||
|
||||
if(exe_fd >= 0)
|
||||
@@ -234,7 +234,7 @@ dmn_lnx_auxv_from_pid(pid_t pid, ELF_Class elf_class)
|
||||
|
||||
// rjf: open aux data
|
||||
String8 auxv_path = push_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 = OS_LNX_RETRY_ON_EINTR(open(auxv_path.cstr, O_RDONLY));
|
||||
|
||||
// rjf: scan aux data
|
||||
if(auxv_fd >= 0)
|
||||
@@ -630,7 +630,7 @@ dmn_lnx_process_alloc(pid_t pid, DMN_LNX_ProcessState state, DMN_LNX_Process *pa
|
||||
|
||||
DMN_LNX_Process *process = &dmn_lnx_entity_alloc(DMN_LNX_EntityKind_Process)->process;
|
||||
process->pid = pid;
|
||||
process->fd = open((char*)str8f(scratch.arena, "/proc/%d/mem", pid).str, O_RDWR);
|
||||
process->fd = open(str8f(scratch.arena, "/proc/%d/mem", pid).cstr, O_RDWR);
|
||||
process->state = state;
|
||||
process->debug_subprocesses = debug_subprocesses;
|
||||
process->is_cow = is_cow;
|
||||
@@ -698,7 +698,7 @@ dmn_lnx_process_ctx_alloc(DMN_LNX_Process *process, B32 is_rebased)
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
|
||||
String8 dl_path = dmn_lnx_dl_path_from_pid(scratch.arena, process->pid, auxv.base);
|
||||
int dl_fd = open((char *)dl_path.str, O_RDONLY);
|
||||
int dl_fd = open(dl_path.cstr, O_RDONLY);
|
||||
|
||||
DMN_LNX_ProbeList probes = {0};
|
||||
if(dl_fd >= 0)
|
||||
@@ -2157,7 +2157,7 @@ dmn_lnx_event_attach(Arena *arena, DMN_EventList *events, pid_t pid)
|
||||
// extract threads from /proc/pid/task
|
||||
{
|
||||
String8 task_path = push_str8f(scratch.arena, "/proc/%d/task", pid);
|
||||
DIR *task_dirp = opendir((char *)task_path.str);
|
||||
DIR *task_dirp = opendir(task_path.cstr);
|
||||
if(task_dirp)
|
||||
{
|
||||
for(;;)
|
||||
@@ -2279,7 +2279,7 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_ProcessLaunchParams *params)
|
||||
U64 idx = 0;
|
||||
for EachNode(n, String8Node, params->cmd_line.first)
|
||||
{
|
||||
argv[idx++] = (char *)push_str8_copy(scratch.arena, n->string).str;
|
||||
argv[idx++] = push_str8_copy(scratch.arena, n->string).cstr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2294,12 +2294,12 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_ProcessLaunchParams *params)
|
||||
U64 idx = os_lnx_state.default_env_count;
|
||||
for EachNode(n, String8Node, params->env.first)
|
||||
{
|
||||
envp[idx++] = (char *)push_str8_copy(scratch.arena, n->string).str;
|
||||
envp[idx++] = push_str8_copy(scratch.arena, n->string).cstr;
|
||||
}
|
||||
}
|
||||
|
||||
// create zero-terminated work directory path
|
||||
char *work_dir_path = (char *)push_str8_copy(scratch.arena, params->path).str;
|
||||
char *work_dir_path = push_str8_copy(scratch.arena, params->path).cstr;
|
||||
|
||||
// fork process
|
||||
pid_t pid = fork();
|
||||
|
||||
@@ -159,7 +159,7 @@ os_get_process_start_time_unix(void)
|
||||
pid_t pid = getpid();
|
||||
String8 path = push_str8f(scratch.arena, "/proc/%u", pid);
|
||||
struct stat st;
|
||||
int err = stat((char*)path.str, &st);
|
||||
int err = stat(path.cstr, &st);
|
||||
if(err == 0)
|
||||
{
|
||||
start_time = st.st_mtime;
|
||||
@@ -240,7 +240,7 @@ os_set_thread_name(String8 name)
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 name_copy = push_str8_copy(scratch.arena, name);
|
||||
pthread_t current_thread = pthread_self();
|
||||
pthread_setname_np(current_thread, (char *)name_copy.str);
|
||||
pthread_setname_np(current_thread, name_copy.cstr);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ os_file_open(OS_AccessFlags flags, String8 path)
|
||||
lnx_flags |= O_CREAT;
|
||||
}
|
||||
lnx_flags |= O_CLOEXEC;
|
||||
int fd = open((char *)path_copy.str, lnx_flags, 0755);
|
||||
int fd = open(path_copy.cstr, lnx_flags, 0755);
|
||||
OS_Handle handle = {0};
|
||||
if(fd != -1)
|
||||
{
|
||||
@@ -400,7 +400,7 @@ os_delete_file_at_path(String8 path)
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
B32 result = 0;
|
||||
String8 path_copy = push_str8_copy(scratch.arena, path);
|
||||
if(remove((char*)path_copy.str) != -1)
|
||||
if(remove(path_copy.cstr) != -1)
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
@@ -447,8 +447,8 @@ os_move_file_path(String8 dst, String8 src)
|
||||
B32 good = 0;
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
{
|
||||
char *src_cstr = (char *)push_str8_copy(scratch.arena, src).str;
|
||||
char *dst_cstr = (char *)push_str8_copy(scratch.arena, dst).str;
|
||||
char *src_cstr = push_str8_copy(scratch.arena, src).cstr;
|
||||
char *dst_cstr = push_str8_copy(scratch.arena, dst).cstr;
|
||||
int rename_result = rename(src_cstr, dst_cstr);
|
||||
good = (rename_result != -1);
|
||||
}
|
||||
@@ -462,7 +462,7 @@ os_full_path_from_path(Arena *arena, String8 path)
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8 path_copy = push_str8_copy(scratch.arena, path);
|
||||
char buffer[PATH_MAX] = {0};
|
||||
realpath((char *)path_copy.str, buffer);
|
||||
realpath(path_copy.cstr, buffer);
|
||||
String8 result = push_str8_copy(arena, str8_cstring(buffer));
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
@@ -473,7 +473,7 @@ os_file_path_exists(String8 path)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 path_copy = push_str8_copy(scratch.arena, path);
|
||||
int access_result = access((char *)path_copy.str, F_OK);
|
||||
int access_result = access(path_copy.cstr, F_OK);
|
||||
B32 result = 0;
|
||||
if(access_result == 0)
|
||||
{
|
||||
@@ -489,7 +489,7 @@ os_folder_path_exists(String8 path)
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
B32 exists = 0;
|
||||
String8 path_copy = push_str8_copy(scratch.arena, path);
|
||||
DIR *handle = opendir((char*)path_copy.str);
|
||||
DIR *handle = opendir(path_copy.cstr);
|
||||
if(handle)
|
||||
{
|
||||
closedir(handle);
|
||||
@@ -505,7 +505,7 @@ os_properties_from_file_path(String8 path)
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 path_copy = push_str8_copy(scratch.arena, path);
|
||||
struct stat f_stat = {0};
|
||||
int stat_result = stat((char *)path_copy.str, &f_stat);
|
||||
int stat_result = stat(path_copy.cstr, &f_stat);
|
||||
FileProperties props = {0};
|
||||
if(stat_result != -1)
|
||||
{
|
||||
@@ -564,7 +564,7 @@ os_file_iter_begin(Arena *arena, String8 path, OS_FileIterFlags flags)
|
||||
OS_LNX_FileIter *iter = (OS_LNX_FileIter *)base_iter->memory;
|
||||
{
|
||||
String8 path_copy = push_str8_copy(arena, path);
|
||||
iter->dir = opendir((char *)path_copy.str);
|
||||
iter->dir = opendir(path_copy.cstr);
|
||||
iter->path = path_copy;
|
||||
}
|
||||
return base_iter;
|
||||
@@ -588,7 +588,7 @@ os_file_iter_next(Arena *arena, OS_FileIter *iter, OS_FileInfo *info_out)
|
||||
{
|
||||
Temp scratch = scratch_begin(&arena, 1);
|
||||
String8 full_path = push_str8f(scratch.arena, "%S/%s", lnx_iter->path, lnx_iter->dp->d_name);
|
||||
stat_result = stat((char *)full_path.str, &st);
|
||||
stat_result = stat(full_path.cstr, &st);
|
||||
scratch_end(scratch);
|
||||
}
|
||||
|
||||
@@ -637,7 +637,7 @@ os_make_directory(String8 path)
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
B32 result = 0;
|
||||
String8 path_copy = push_str8_copy(scratch.arena, path);
|
||||
if(mkdir((char*)path_copy.str, 0755) != -1)
|
||||
if(mkdir(path_copy.cstr, 0755) != -1)
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
@@ -653,7 +653,7 @@ os_shared_memory_alloc(U64 size, String8 name)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 name_copy = push_str8_copy(scratch.arena, name);
|
||||
int id = shm_open((char *)name_copy.str, O_RDWR|O_CREAT, 0666);
|
||||
int id = shm_open(name_copy.cstr, O_RDWR|O_CREAT, 0666);
|
||||
ftruncate(id, size);
|
||||
OS_Handle result = {(U64)id};
|
||||
scratch_end(scratch);
|
||||
@@ -665,7 +665,7 @@ os_shared_memory_open(String8 name)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
String8 name_copy = push_str8_copy(scratch.arena, name);
|
||||
int id = shm_open((char *)name_copy.str, O_RDWR, 0);
|
||||
int id = shm_open(name_copy.cstr, O_RDWR, 0);
|
||||
OS_Handle result = {(U64)id};
|
||||
scratch_end(scratch);
|
||||
return result;
|
||||
@@ -802,9 +802,9 @@ os_process_launch(OS_ProcessLaunchParams *params)
|
||||
str8_list_push(scratch.arena, &l, params->cmd_line.first->string);
|
||||
String8 path_to_exe = str8_path_list_join_by_style(scratch.arena, &l, PathStyle_SystemAbsolute);
|
||||
|
||||
argv[0] = (char *)path_to_exe.str;
|
||||
argv[0] = path_to_exe.cstr;
|
||||
U64 arg_idx = 1;
|
||||
for EachNode(n, String8Node, params->cmd_line.first->next) { argv[arg_idx++] = (char *)n->string.str; }
|
||||
for EachNode(n, String8Node, params->cmd_line.first->next) { argv[arg_idx++] = n->string.cstr; }
|
||||
}
|
||||
|
||||
// package envp
|
||||
@@ -819,7 +819,7 @@ os_process_launch(OS_ProcessLaunchParams *params)
|
||||
U64 env_idx = 0;
|
||||
for EachNode(n, String8Node, params->cmd_line.first)
|
||||
{
|
||||
envp[env_idx] = (char *)n->string.str;
|
||||
envp[env_idx] = n->string.cstr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1175,10 +1175,10 @@ os_semaphore_alloc(U32 initial_count, U32 max_count, String8 name)
|
||||
{
|
||||
for EachIndex(attempt_idx, 64)
|
||||
{
|
||||
sem_t *s = sem_open((char *)name.str, O_CREAT | O_EXCL, 0666, initial_count);
|
||||
sem_t *s = sem_open(name.cstr, O_CREAT | O_EXCL, 0666, initial_count);
|
||||
if(s == SEM_FAILED)
|
||||
{
|
||||
s = sem_open((char *)name.str, 0);
|
||||
s = sem_open(name.cstr, 0);
|
||||
}
|
||||
if(s != SEM_FAILED)
|
||||
{
|
||||
@@ -1211,7 +1211,7 @@ internal Semaphore
|
||||
os_semaphore_open(String8 name)
|
||||
{
|
||||
Semaphore result = {0};
|
||||
sem_t *s = sem_open((char *)name.str, 0);
|
||||
sem_t *s = sem_open(name.cstr, 0);
|
||||
if(s != SEM_FAILED)
|
||||
{
|
||||
result.u64[0] = (U64)s;
|
||||
@@ -1310,7 +1310,7 @@ internal OS_Handle
|
||||
os_library_open(String8 path)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
char *path_cstr = (char *)push_str8_copy(scratch.arena, path).str;
|
||||
char *path_cstr = push_str8_copy(scratch.arena, path).cstr;
|
||||
void *so = dlopen(path_cstr, RTLD_LAZY|RTLD_LOCAL);
|
||||
OS_Handle lib = { (U64)so };
|
||||
scratch_end(scratch);
|
||||
@@ -1322,7 +1322,7 @@ os_library_load_proc(OS_Handle lib, String8 name)
|
||||
{
|
||||
Temp scratch = scratch_begin(0, 0);
|
||||
void *so = (void *)lib.u64;
|
||||
char *name_cstr = (char *)push_str8_copy(scratch.arena, name).str;
|
||||
char *name_cstr = push_str8_copy(scratch.arena, name).cstr;
|
||||
VoidProc *proc = (VoidProc *)dlsym(so, name_cstr);
|
||||
scratch_end(scratch);
|
||||
return proc;
|
||||
@@ -1493,7 +1493,7 @@ main(int argc, char **argv)
|
||||
char **default_env = push_array(os_lnx_state.arena, char *, env_count+1);
|
||||
for EachIndex(i, env_count)
|
||||
{
|
||||
default_env[i] = (char *)str8_copy(os_lnx_state.arena, str8_cstring(__environ[i])).str;
|
||||
default_env[i] = str8_copy(os_lnx_state.arena, str8_cstring(__environ[i])).cstr;
|
||||
}
|
||||
default_env[env_count] = 0;
|
||||
os_lnx_state.default_env_count = env_count;
|
||||
|
||||
Reference in New Issue
Block a user