@@ -60,6 +60,20 @@ ctrl_exception_kind_from_dmn(DMN_ExceptionKind kind)
6060 return result ;
6161}
6262
63+ internal CTRL_TlsModel
64+ ctrl_dynamic_linker_type_from_dmn (DMN_TlsModel type )
65+ {
66+ CTRL_TlsModel result = CTRL_TlsModel_Null ;
67+ switch (type )
68+ {
69+ default :{}break ;
70+ case DMN_TlsModel_Null : {result = CTRL_TlsModel_Null ;}break ;
71+ case DMN_TlsModel_WinodwsNt : {result = CTRL_TlsModel_WinodwsNt ;}break ;
72+ case DMN_TlsModel_Gnu : {result = CTRL_TlsModel_Gnu ;}break ;
73+ }
74+ return result ;
75+ }
76+
6377internal String8
6478ctrl_string_from_event_kind (CTRL_EventKind kind )
6579{
@@ -616,6 +630,9 @@ ctrl_serialized_string_from_event(Arena *arena, CTRL_Event *event, U64 max)
616630 str8_serial_push_struct (scratch .arena , & srl , & event -> exception_code );
617631 str8_serial_push_struct (scratch .arena , & srl , & event -> rgba );
618632 str8_serial_push_struct (scratch .arena , & srl , & event -> bp_flags );
633+ str8_serial_push_struct (scratch .arena , & srl , & event -> tls_model );
634+ str8_serial_push_struct (scratch .arena , & srl , & event -> tls_index );
635+ str8_serial_push_struct (scratch .arena , & srl , & event -> tls_offset );
619636 String8 string = event -> string ;
620637 string .size = Min (string .size , max - srl .total_size );
621638 str8_serial_push_struct (scratch .arena , & srl , & string .size );
@@ -649,6 +666,9 @@ ctrl_event_from_serialized_string(Arena *arena, String8 string)
649666 read_off += str8_deserial_read_struct (string , read_off , & event .exception_code );
650667 read_off += str8_deserial_read_struct (string , read_off , & event .rgba );
651668 read_off += str8_deserial_read_struct (string , read_off , & event .bp_flags );
669+ read_off += str8_deserial_read_struct (string , read_off , & event .tls_model );
670+ read_off += str8_deserial_read_struct (string , read_off , & event .tls_index );
671+ read_off += str8_deserial_read_struct (string , read_off , & event .tls_offset );
652672 read_off += str8_deserial_read_struct (string , read_off , & event .string .size );
653673 event .string .str = push_array_no_zero (arena , U8 , event .string .size );
654674 read_off += str8_deserial_read (string , read_off , event .string .str , event .string .size , 1 );
@@ -1249,6 +1269,7 @@ ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *lis
12491269 {
12501270 CTRL_Entity * machine = ctrl_entity_from_handle (& store -> ctx , ctrl_handle_make (event -> entity .machine_id , dmn_handle_zero ()));
12511271 CTRL_Entity * process = ctrl_entity_alloc (store , machine , CTRL_EntityKind_Process , event -> arch , event -> entity , (U64 )event -> entity_id );
1272+ process -> tls_model = event -> tls_model ;
12521273 }break ;
12531274 case CTRL_EventKind_EndProc :
12541275 {
@@ -1370,6 +1391,8 @@ ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *lis
13701391 ctrl_entity_equip_string (store , module , event -> string );
13711392 module -> timestamp = event -> timestamp ;
13721393 module -> vaddr_range = event -> vaddr_rng ;
1394+ module -> tls_index = event -> tls_index ;
1395+ module -> tls_offset = event -> tls_offset ;
13731396 CTRL_Entity * first_module = ctrl_entity_child_from_kind (process , CTRL_EntityKind_Module );
13741397 if (first_module == module )
13751398 {
@@ -1723,26 +1746,6 @@ ctrl_entry_point_voff_from_module(CTRL_Handle module_handle)
17231746 return result ;
17241747}
17251748
1726- internal Rng1U64
1727- ctrl_tls_vaddr_range_from_module (CTRL_Handle module_handle )
1728- {
1729- Rng1U64 result = {0 };
1730- U64 hash = ctrl_hash_from_handle (module_handle );
1731- U64 slot_idx = hash %ctrl_state -> module_image_info_cache .slots_count ;
1732- U64 stripe_idx = slot_idx %ctrl_state -> module_image_info_cache .stripes_count ;
1733- CTRL_ModuleImageInfoCacheSlot * slot = & ctrl_state -> module_image_info_cache .slots [slot_idx ];
1734- CTRL_ModuleImageInfoCacheStripe * stripe = & ctrl_state -> module_image_info_cache .stripes [stripe_idx ];
1735- MutexScopeR (stripe -> rw_mutex ) for (CTRL_ModuleImageInfoCacheNode * n = slot -> first ; n != 0 ; n = n -> next )
1736- {
1737- if (ctrl_handle_match (n -> module , module_handle ))
1738- {
1739- result = n -> tls_vaddr_range ;
1740- break ;
1741- }
1742- }
1743- return result ;
1744- }
1745-
17461749internal String8
17471750ctrl_initial_debug_info_path_from_module (Arena * arena , CTRL_Handle module_handle )
17481751{
@@ -3734,7 +3737,6 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_
37343737
37353738 Arena * arena = arena_alloc ();
37363739 U64 entry_point_voff = 0 ;
3737- Rng1U64 tls_vaddr_range = {0 };
37383740 U32 rdi_dbg_time = 0 ;
37393741 Guid rdi_dbg_guid = {0 };
37403742 String8 exe_dbg_path = {0 };
@@ -3855,34 +3857,6 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_
38553857 dmn_process_read (process .dmn_handle , r1u64 (vaddr_range .min + pdatas_voff_range .min , vaddr_range .min + pdatas_voff_range .max ), pdatas );
38563858 }
38573859
3858- // rjf: extract tls header
3859- PE_TLSHeader64 tls_header = {0 };
3860- if (data_dir_count > PE_DataDirectoryIndex_TLS )
3861- {
3862- PE_DataDirectory dir = {0 };
3863- dmn_process_read_struct (process .dmn_handle , vaddr_range .min + opt_ext_off_range .min + reported_data_dir_offset + sizeof (PE_DataDirectory )* PE_DataDirectoryIndex_TLS , & dir );
3864- Rng1U64 tls_voff_range = r1u64 ((U64 )dir .virt_off , (U64 )dir .virt_off + (U64 )dir .virt_size );
3865- switch (file_header .machine )
3866- {
3867- default :{}break ;
3868- case COFF_MachineType_X86 :
3869- {
3870- PE_TLSHeader32 tls_header32 = {0 };
3871- dmn_process_read_struct (process .dmn_handle , vaddr_range .min + tls_voff_range .min , & tls_header32 );
3872- tls_header .raw_data_start = (U64 )tls_header32 .raw_data_start ;
3873- tls_header .raw_data_end = (U64 )tls_header32 .raw_data_end ;
3874- tls_header .index_address = (U64 )tls_header32 .index_address ;
3875- tls_header .callbacks_address = (U64 )tls_header32 .callbacks_address ;
3876- tls_header .zero_fill_size = (U64 )tls_header32 .zero_fill_size ;
3877- tls_header .characteristics = (U64 )tls_header32 .characteristics ;
3878- }break ;
3879- case COFF_MachineType_X64 :
3880- {
3881- dmn_process_read_struct (process .dmn_handle , vaddr_range .min + tls_voff_range .min , & tls_header );
3882- }break ;
3883- }
3884- }
3885-
38863860 // rjf: extract sections
38873861 U64 sec_array_off = opt_ext_off_range .max ;
38883862 U64 sec_count = file_header .section_count ;
@@ -3892,9 +3866,6 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_
38923866 // rjf: grab entry point vaddr
38933867 entry_point_voff = entry_point ;
38943868
3895- // rjf: calculate TLS vaddr range
3896- tls_vaddr_range = r1u64 (tls_header .index_address , tls_header .index_address + sizeof (U32 ));
3897-
38983869 // rjf: grab data about debug info
38993870 if (data_dir_count > PE_DataDirectoryIndex_DEBUG )
39003871 {
@@ -4469,11 +4440,12 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
44694440 case DMN_EventKind_CreateProcess :
44704441 {
44714442 CTRL_Event * out_evt = ctrl_event_list_push (scratch .arena , & evts );
4472- out_evt -> kind = CTRL_EventKind_NewProc ;
4473- out_evt -> msg_id = msg -> msg_id ;
4474- out_evt -> entity = ctrl_handle_make (CTRL_MachineID_Local , event -> process );
4475- out_evt -> arch = event -> arch ;
4476- out_evt -> entity_id = event -> code ;
4443+ out_evt -> kind = CTRL_EventKind_NewProc ;
4444+ out_evt -> msg_id = msg -> msg_id ;
4445+ out_evt -> entity = ctrl_handle_make (CTRL_MachineID_Local , event -> process );
4446+ out_evt -> arch = event -> arch ;
4447+ out_evt -> entity_id = event -> code ;
4448+ out_evt -> tls_model = ctrl_dynamic_linker_type_from_dmn (event -> tls_model );
44774449 ctrl_state -> process_counter += 1 ;
44784450 }break ;
44794451 case DMN_EventKind_CreateThread :
@@ -4508,6 +4480,8 @@ ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg,
45084480 out_evt1 -> rip_vaddr = event -> address ;
45094481 out_evt1 -> timestamp = exe_timestamp ;
45104482 out_evt1 -> string = module_path ;
4483+ out_evt1 -> tls_index = event -> tls_index ;
4484+ out_evt1 -> tls_offset = event -> tls_offset ;
45114485 CTRL_Event * out_evt2 = ctrl_event_list_push (scratch .arena , & evts );
45124486 String8 initial_debug_info_path = ctrl_initial_debug_info_path_from_module (scratch .arena , module_handle );
45134487 U64 debug_info_timestamp = os_properties_from_file_path (initial_debug_info_path ).modified ;
0 commit comments