moved Guid struct and related helpers to base

This commit is contained in:
Nikita Smith
2024-11-07 11:45:00 -08:00
parent f807dc4785
commit 214be8c433
21 changed files with 133 additions and 128 deletions
+13
View File
@@ -486,6 +486,19 @@ struct TxtRng
TxtPt max;
};
////////////////////////////////
//~ Globally Unique Ids
typedef struct Guid Guid;
struct Guid
{
U32 data1;
U16 data2;
U16 data3;
U8 data4[8];
};
StaticAssert(sizeof(Guid) == 16, g_guid_size_check);
////////////////////////////////
//~ NOTE(allen): Constants
+72
View File
@@ -1588,6 +1588,78 @@ string_from_elapsed_time(Arena *arena, DateTime dt){
return(result);
}
////////////////////////////////
//~ Globally UNique Ids
internal String8
string_from_guid(Arena *arena, Guid guid)
{
String8 result = push_str8f(arena, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
guid.data1,
guid.data2,
guid.data3,
guid.data4[0],
guid.data4[1],
guid.data4[2],
guid.data4[3],
guid.data4[4],
guid.data4[5],
guid.data4[6],
guid.data4[7]);
return result;
}
internal B32
try_guid_from_string(String8 string, Guid *guid_out)
{
Temp scratch = scratch_begin(0,0);
B32 is_parsed = 0;
String8List list = str8_split_by_string_chars(scratch.arena, string, str8_lit("-"), StringSplitFlag_KeepEmpties);
if(list.node_count == 5)
{
String8 data1_str = list.first->string;
String8 data2_str = list.first->next->string;
String8 data3_str = list.first->next->next->string;
String8 data4_hi_str = list.first->next->next->next->string;
String8 data4_lo_str = list.first->next->next->next->next->string;
if(str8_is_integer(data1_str, 16) &&
str8_is_integer(data2_str, 16) &&
str8_is_integer(data3_str, 16) &&
str8_is_integer(data4_hi_str, 16) &&
str8_is_integer(data4_lo_str, 16))
{
U64 data1 = u64_from_str8(data1_str, 16);
U64 data2 = u64_from_str8(data2_str, 16);
U64 data3 = u64_from_str8(data3_str, 16);
U64 data4_hi = u64_from_str8(data4_hi_str, 16);
U64 data4_lo = u64_from_str8(data4_lo_str, 16);
if(data1 <= max_U32 &&
data2 <= max_U16 &&
data3 <= max_U16 &&
data4_hi <= max_U16 &&
data4_lo <= 0xffffffffffff)
{
guid_out->data1 = (U32)data1;
guid_out->data2 = (U16)data2;
guid_out->data3 = (U16)data3;
U64 data4 = (data4_hi << 48) | data4_lo;
MemoryCopy(&guid_out->data4[0], &data4, sizeof(data4));
is_parsed = 1;
}
}
}
scratch_end(scratch);
return is_parsed;
}
internal Guid
guid_from_string(String8 string)
{
Guid guid = {0};
try_guid_from_string(string, &guid);
return guid;
}
////////////////////////////////
//~ rjf: Basic Text Indentation
+7
View File
@@ -328,6 +328,13 @@ internal String8 push_date_time_string(Arena *arena, DateTime *date_time);
internal String8 push_file_name_date_time_string(Arena *arena, DateTime *date_time);
internal String8 string_from_elapsed_time(Arena *arena, DateTime dt);
////////////////////////////////
//~ Globally Unique Ids
internal String8 string_from_guid(Arena *arena, Guid guid);
internal B32 try_guid_from_string(String8 string, Guid *guid_out);
internal Guid guid_from_string(String8 string);
////////////////////////////////
//~ rjf: Basic Text Indentation
+2 -2
View File
@@ -3440,10 +3440,10 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_
Rng1U64 tls_vaddr_range = {0};
U32 pdb_dbg_time = 0;
U32 pdb_dbg_age = 0;
OS_Guid pdb_dbg_guid = {0};
Guid pdb_dbg_guid = {0};
String8 pdb_dbg_path = str8_zero();
U32 rdi_dbg_time = 0;
OS_Guid rdi_dbg_guid = {0};
Guid rdi_dbg_guid = {0};
String8 rdi_dbg_path = str8_zero();
ProfScope("unpack relevant PE info")
{
+1 -1
View File
@@ -208,7 +208,7 @@ typedef struct CV_UDTInfo
typedef struct CV_TypeServerInfo
{
String8 name;
OS_Guid sig;
Guid sig;
U32 age;
} CV_TypeServerInfo;
+4 -4
View File
@@ -1402,7 +1402,7 @@ lnk_build_debug_pdb(LNK_SectionTable *st,
LNK_Section *sect,
LNK_Chunk *dir_array_chunk,
COFF_TimeStamp time_stamp,
OS_Guid guid,
Guid guid,
U32 age,
String8 pdb_path)
{
@@ -1429,7 +1429,7 @@ lnk_build_debug_rdi(LNK_SectionTable *st,
LNK_Section *debug_sect,
LNK_Chunk *debug_dir_array_chunk,
COFF_TimeStamp time_stamp,
OS_Guid guid,
Guid guid,
String8 rdi_path)
{
ProfBeginFunction();
@@ -4077,8 +4077,8 @@ l.count += 1; \
U128 hash = lnk_blake3_hash_parallel(tp, 128, image_data);
MemoryCopy(&config->guid, hash.u64, sizeof(hash.u64));
U64 guid_foff = lnk_file_off_from_symbol(sect_id_map, guid_symbol);
OS_Guid *guid_ptr = (OS_Guid *)(image_data.str + guid_foff);
U64 guid_foff = lnk_file_off_from_symbol(sect_id_map, guid_symbol);
Guid *guid_ptr = (Guid *)(image_data.str + guid_foff);
MemoryCopy(guid_ptr, hash.u64, sizeof(hash.u64));
ProfEnd();
+2 -2
View File
@@ -269,8 +269,8 @@ internal String8 lnk_make_linker_coff_obj(TP_Context *tp, Arena *arena, COFF_Tim
////////////////////////////////
// Win32 Image Helpers
internal void lnk_build_debug_pdb(LNK_SectionTable *st, LNK_SymbolTable *symtab, LNK_Section *debug_sect, LNK_Chunk *debug_dir_array_chunk, COFF_TimeStamp time_stamp, OS_Guid guid, U32 age, String8 pdb_path);
internal void lnk_build_debug_rdi(LNK_SectionTable *st, LNK_SymbolTable *symtab, LNK_Section *debug_sect, LNK_Chunk *debug_dir_array_chunk, COFF_TimeStamp time_stamp, OS_Guid guid, String8 rdi_path);
internal void lnk_build_debug_pdb(LNK_SectionTable *st, LNK_SymbolTable *symtab, LNK_Section *debug_sect, LNK_Chunk *debug_dir_array_chunk, COFF_TimeStamp time_stamp, Guid guid, U32 age, String8 pdb_path);
internal void lnk_build_debug_rdi(LNK_SectionTable *st, LNK_SymbolTable *symtab, LNK_Section *debug_sect, LNK_Chunk *debug_dir_array_chunk, COFF_TimeStamp time_stamp, Guid guid, String8 rdi_path);
internal void lnk_build_guard_tables(TP_Context *tp, LNK_SectionTable *st, LNK_SymbolTable *symtab, LNK_ExportTable *exptab, LNK_ObjList obj_list, COFF_MachineType machine, String8 entry_point_name, LNK_GuardFlags guard_flags, B32 emit_suppress_flag);
internal void lnk_build_base_relocs(TP_Context *tp, TP_Arena *tp_arena, LNK_SectionTable *st, LNK_SymbolTable *symtab, COFF_MachineType machine, U64 page_size, LNK_ObjList obj_list);
internal LNK_Chunk * lnk_build_dos_header(LNK_SymbolTable *symtab, LNK_Section *header_sect, LNK_Chunk *parent_chunk);
+2 -2
View File
@@ -1515,8 +1515,8 @@ lnk_config_from_cmd_line(Arena *arena, String8List raw_cmd_line)
} else if (str8_match(cmd->value_strings.first->string, str8_lit("random"), StringMatchFlag_CaseInsensitive)) {
config->guid = os_make_guid();
} else {
OS_Guid guid;
if (os_try_guid_from_string(cmd->value_strings.first->string, &guid)) {
Guid guid;
if (try_guid_from_string(cmd->value_strings.first->string, &guid)) {
config->guid = guid;
} else {
lnk_error_cmd_switch(LNK_Error_Cmdl, cmd_switch, "unable to parse \"%S\"", cmd->value_strings.first->string);
+1 -1
View File
@@ -244,7 +244,7 @@ typedef struct LNK_Config
U64 opt_iter_count;
LNK_GuardFlags guard_flags;
LNK_DebugInfoGuidType guid_type;
OS_Guid guid;
Guid guid;
COFF_TimeStamp time_stamp;
U32 age;
U64 section_virt_off;
+3 -3
View File
@@ -708,8 +708,8 @@ lnk_make_code_view_input(TP_Context *tp, TP_Arena *tp_arena, String8List lib_dir
pdb_info_parse_from_data(msf_parse->streams[PDB_FixedStream_Info], &info_parse);
if (!MemoryMatchStruct(&info_parse.guid, &ts_info_arr[ts_idx].sig)) {
Temp scratch = scratch_begin(0,0);
String8 expected_sig_str = os_string_from_guid(scratch.arena, ts_info_arr[ts_idx].sig);
String8 on_disk_sig_str = os_string_from_guid(scratch.arena, info_parse.guid);
String8 expected_sig_str = string_from_guid(scratch.arena, ts_info_arr[ts_idx].sig);
String8 on_disk_sig_str = string_from_guid(scratch.arena, info_parse.guid);
lnk_error(LNK_Warning_MismatchedTypeServerSignature, "%S: signature mismatch in type server read from disk, expected %S, got %S",
ts_info_arr[ts_idx].name, expected_sig_str, on_disk_sig_str);
scratch_end(scratch);
@@ -3121,7 +3121,7 @@ lnk_build_pdb_public_symbols(TP_Context *tp,
internal String8List
lnk_build_pdb(TP_Context *tp,
TP_Arena *tp_arena,
OS_Guid guid,
Guid guid,
COFF_MachineType machine,
COFF_TimeStamp time_stamp,
U32 age,
+1 -1
View File
@@ -581,7 +581,7 @@ internal void lnk_build_pdb_public_symbols(TP_Context *tp,
internal String8List lnk_build_pdb(TP_Context *tp,
TP_Arena *tp_arena,
OS_Guid guid,
Guid guid,
COFF_MachineType machine,
COFF_TimeStamp time_stamp,
U32 age,
-47
View File
@@ -139,50 +139,3 @@ operating_system_from_string(String8 string)
return OperatingSystem_Null;
}
internal B32
os_try_guid_from_string(String8 string, OS_Guid *guid_out)
{
Temp scratch = scratch_begin(0,0);
B32 is_parsed = 0;
String8List list = str8_split_by_string_chars(scratch.arena, string, str8_lit("-"), StringSplitFlag_KeepEmpties);
if (list.node_count == 5) {
String8 data1_str = list.first->string;
String8 data2_str = list.first->next->string;
String8 data3_str = list.first->next->next->string;
String8 data4_hi_str = list.first->next->next->next->string;
String8 data4_lo_str = list.first->next->next->next->next->string;
if (str8_is_integer(data1_str, 16) &&
str8_is_integer(data2_str, 16) &&
str8_is_integer(data3_str, 16) &&
str8_is_integer(data4_hi_str, 16) &&
str8_is_integer(data4_lo_str, 16)) {
U64 data1 = u64_from_str8(data1_str, 16);
U64 data2 = u64_from_str8(data2_str, 16);
U64 data3 = u64_from_str8(data3_str, 16);
U64 data4_hi = u64_from_str8(data4_hi_str, 16);
U64 data4_lo = u64_from_str8(data4_lo_str, 16);
if (data1 <= max_U32 &&
data2 <= max_U16 &&
data3 <= max_U16 &&
data4_hi <= max_U16 &&
data4_lo <= 0xffffffffffff) {
guid_out->data1 = (U32)data1;
guid_out->data2 = (U16)data2;
guid_out->data3 = (U16)data3;
U64 data4 = (data4_hi << 48) | data4_lo;
MemoryCopy(&guid_out->data4[0], &data4, sizeof(data4));
is_parsed = 1;
}
}
}
scratch_end(scratch);
return is_parsed;
}
internal OS_Guid
os_guid_from_string(String8 string)
{
OS_Guid guid = {0};
os_try_guid_from_string(string, &guid);
return guid;
}
-2
View File
@@ -35,5 +35,3 @@ internal B32 os_set_large_pages(B32 toggle);
internal U32 os_get_process_start_time_unix(void);
internal B32 os_try_guid_from_string(String8 string, OS_Guid *guid_out);
internal OS_Guid os_guid_from_string(String8 string);
+4 -4
View File
@@ -1648,7 +1648,7 @@ pdb_load_types_from_leaf_list(PDB_TypeServer **type_server_arr, CV_LeafList leaf
////////////////////////////////
internal PDB_InfoContext *
pdb_info_alloc(U32 age, COFF_TimeStamp time_stamp, OS_Guid guid)
pdb_info_alloc(U32 age, COFF_TimeStamp time_stamp, Guid guid)
{
ProfBeginFunction();
Arena *arena = arena_alloc();
@@ -3528,7 +3528,7 @@ pdb_alloc_msf(U64 page_size)
}
internal PDB_Context *
pdb_alloc(U64 page_size, COFF_MachineType machine, COFF_TimeStamp time_stamp, U32 age, OS_Guid guid)
pdb_alloc(U64 page_size, COFF_MachineType machine, COFF_TimeStamp time_stamp, U32 age, Guid guid)
{
ProfBeginFunction();
Arena *arena = arena_alloc();
@@ -3606,7 +3606,7 @@ pdb_set_machine(PDB_Context *pdb, COFF_MachineType machine)
}
internal void
pdb_set_guid(PDB_Context *pdb, OS_Guid guid)
pdb_set_guid(PDB_Context *pdb, Guid guid)
{
pdb->info->guid = guid;
}
@@ -3642,7 +3642,7 @@ pdb_get_age(PDB_Context *pdb)
return pdb->info->age;
}
internal OS_Guid
internal Guid
pdb_get_guid(PDB_Context *pdb)
{
return pdb->info->guid;
+6 -6
View File
@@ -154,7 +154,7 @@ typedef struct PDB_InfoParse
PDB_TpiVersion version;
COFF_TimeStamp time_stamp;
U32 age;
OS_Guid guid;
Guid guid;
String8 extra_info;
} PDB_InfoParse;
@@ -163,7 +163,7 @@ typedef struct PDB_InfoContext
Arena *arena;
COFF_TimeStamp time_stamp;
U32 age;
OS_Guid guid;
Guid guid;
PDB_FeatureFlags flags;
PDB_HashTable named_stream_ht;
PDB_HashTable src_header_block_ht;
@@ -347,23 +347,23 @@ typedef struct
////////////////////////////////
// PDB
internal PDB_Context * pdb_alloc(U64 page_size, COFF_MachineType machine, COFF_TimeStamp time_stamp, U32 age, OS_Guid guid);
internal PDB_Context * pdb_alloc(U64 page_size, COFF_MachineType machine, COFF_TimeStamp time_stamp, U32 age, Guid guid);
internal PDB_Context * pdb_open(String8 data);
internal void pdb_release(PDB_Context **pdb_ptr);
internal void pdb_build(TP_Context *tp, TP_Arena *pool_temp, PDB_Context *pdb, CV_StringHashTable string_ht);
internal void pdb_set_machine(PDB_Context *pdb, COFF_MachineType machine);
internal void pdb_set_guid(PDB_Context *pdb, OS_Guid guid);
internal void pdb_set_guid(PDB_Context *pdb, Guid guid);
internal void pdb_set_time_stamp(PDB_Context *pdb, COFF_TimeStamp time_stamp);
internal void pdb_set_age(PDB_Context *pdb, U32 age);
internal COFF_MachineType pdb_get_machine(PDB_Context *pdb);
internal COFF_TimeStamp pdb_get_time_stamp(PDB_Context *pdb);
internal U32 pdb_get_age(PDB_Context *pdb);
internal OS_Guid pdb_get_guid(PDB_Context *pdb);
internal Guid pdb_get_guid(PDB_Context *pdb);
////////////////////////////////
// Info
internal PDB_InfoContext * pdb_info_alloc(U32 age, COFF_TimeStamp time_stamp, OS_Guid guid);
internal PDB_InfoContext * pdb_info_alloc(U32 age, COFF_TimeStamp time_stamp, Guid guid);
internal void pdb_info_parse_from_data(String8 data, PDB_InfoParse *parse_out);
internal PDB_InfoContext * pdb_info_open(MSF_Context *msf, MSF_StreamNumber sn);
internal void pdb_info_build(PDB_InfoContext *info, MSF_Context *msf, MSF_StreamNumber sn);
-20
View File
@@ -238,23 +238,3 @@ os_cmd_line_launchf(char *fmt, ...)
return result;
}
////////////////////////////////
//~ rjf: GUID Helpers (Helpers, Implemented Once)
internal String8
os_string_from_guid(Arena *arena, OS_Guid guid)
{
String8 result = push_str8f(arena, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
guid.data1,
guid.data2,
guid.data3,
guid.data4[0],
guid.data4[1],
guid.data4[2],
guid.data4[3],
guid.data4[4],
guid.data4[5],
guid.data4[6],
guid.data4[7]);
return result;
}
+1 -19
View File
@@ -128,19 +128,6 @@ struct OS_ProcessLaunchParams
OS_Handle stdin_file;
};
////////////////////////////////
//~ rjf: Globally Unique IDs
typedef struct OS_Guid OS_Guid;
struct OS_Guid
{
U32 data1;
U16 data2;
U16 data3;
U8 data4[8];
};
StaticAssert(sizeof(OS_Guid) == 16, os_guid_check);
////////////////////////////////
//~ rjf: Thread Types
@@ -176,11 +163,6 @@ internal String8 os_string_from_file_range(Arena *arena, OS_Handle file,
internal OS_Handle os_cmd_line_launch(String8 string);
internal OS_Handle os_cmd_line_launchf(char *fmt, ...);
////////////////////////////////
//~ rjf: GUID Helpers (Helpers, Implemented Once)
internal String8 os_string_from_guid(Arena *arena, OS_Guid guid);
////////////////////////////////
//~ rjf: @os_hooks System/Process Info (Implemented Per-OS)
@@ -332,7 +314,7 @@ internal void os_safe_call(OS_ThreadFunctionType *func, OS_ThreadFunctionType *f
////////////////////////////////
//~ rjf: @os_hooks GUIDs (Implemented Per-OS)
internal OS_Guid os_make_guid(void);
internal Guid os_make_guid(void);
////////////////////////////////
//~ rjf: @os_hooks Entry Points (Implemented Per-OS)
+2 -2
View File
@@ -1294,10 +1294,10 @@ os_safe_call(OS_ThreadFunctionType *func, OS_ThreadFunctionType *fail_handler, v
////////////////////////////////
//~ rjf: @os_hooks GUIDs (Implemented Per-OS)
internal OS_Guid
internal Guid
os_make_guid(void)
{
OS_Guid result; MemoryZeroStruct(&result);
Guid result; MemoryZeroStruct(&result);
UUID uuid;
RPC_STATUS rpc_status = UuidCreate(&uuid);
if(rpc_status == RPC_S_OK)
+1 -1
View File
@@ -82,7 +82,7 @@ typedef struct PDB_InfoHeaderV70
PDB_InfoVersion version;
COFF_TimeStamp time_stamp;
U32 age;
OS_Guid guid;
Guid guid;
// PDB_HashTable named_stream_hash_table
// PDB_FeatureFlag features[*]
} PDB_InfoHeaderV70;
+3 -3
View File
@@ -195,7 +195,7 @@ pe_bin_info_from_data(Arena *arena, String8 data)
// rjf: read info about debug file
U32 dbg_time = 0;
U32 dbg_age = 0;
OS_Guid dbg_guid = {0};
Guid dbg_guid = {0};
U64 dbg_path_off = 0;
U64 dbg_path_size = 0;
if(valid && PE_DataDirectoryIndex_DEBUG < data_dir_count)
@@ -920,7 +920,7 @@ pe_make_manifest_resource(Arena *arena, U32 resource_id, String8 manifest_data)
//~ Debug Directory
internal String8
pe_make_debug_header_pdb70(Arena *arena, OS_Guid guid, U32 age, String8 pdb_path)
pe_make_debug_header_pdb70(Arena *arena, Guid guid, U32 age, String8 pdb_path)
{
Temp scratch = scratch_begin(&arena, 1);
@@ -941,7 +941,7 @@ pe_make_debug_header_pdb70(Arena *arena, OS_Guid guid, U32 age, String8 pdb_path
}
internal String8
pe_make_debug_header_rdi(Arena *arena, OS_Guid guid, String8 rdi_path)
pe_make_debug_header_rdi(Arena *arena, Guid guid, String8 rdi_path)
{
Temp scratch = scratch_begin(&arena,1);
+8 -8
View File
@@ -372,17 +372,17 @@ struct PE_CvHeaderPDB20
typedef struct PE_CvHeaderPDB70 PE_CvHeaderPDB70;
struct PE_CvHeaderPDB70
{
U32 magic;
OS_Guid guid;
U32 age;
U32 magic;
Guid guid;
U32 age;
// file name packed after struct
};
typedef struct PE_CvHeaderRDI PE_CvHeaderRDI;
struct PE_CvHeaderRDI
{
U32 magic;
OS_Guid guid;
U32 magic;
Guid guid;
// file name packed after struct
};
@@ -732,7 +732,7 @@ struct PE_BinInfo
U64 string_table_off;
U64 dbg_path_off;
U64 dbg_path_size;
OS_Guid dbg_guid;
Guid dbg_guid;
U32 dbg_age;
U32 dbg_time;
Arch arch;
@@ -784,8 +784,8 @@ internal String8 pe_make_manifest_resource(Arena *arena, U32 resource_id, String
////////////////////////////////
//~ Debug Directory
internal String8 pe_make_debug_header_pdb70(Arena *arena, OS_Guid guid, U32 age, String8 pdb_path);
internal String8 pe_make_debug_header_rdi(Arena *arena, OS_Guid guid, String8 rdi_path);
internal String8 pe_make_debug_header_pdb70(Arena *arena, Guid guid, U32 age, String8 pdb_path);
internal String8 pe_make_debug_header_rdi(Arena *arena, Guid guid, String8 rdi_path);
////////////////////////////////
//~ Image Checksum