@@ -262,6 +262,44 @@ typedef struct {
262262 uintptr_t frame_addr ;
263263} RemoteReadPrefetch ;
264264
265+ #if defined(__APPLE__ ) && TARGET_OS_OSX
266+ typedef enum {
267+ ALIAS_STABLE_RUNTIME ,
268+ ALIAS_TSTATE ,
269+ ALIAS_FRAME_PAGE
270+ } AliasReadKind ;
271+
272+ #define MAX_ALIAS_PAGES 256
273+ #define ALIAS_PROBE_MASK 0x3ff
274+ #define ALIAS_FAILURE_WINDOW 100
275+ #define ALIAS_FAILURE_THRESHOLD 10
276+
277+ typedef struct {
278+ uintptr_t remote_page_base ;
279+ mach_vm_address_t local_page_base ;
280+ mach_vm_size_t size ;
281+ mach_port_t task_port ;
282+ uint64_t target_start_tvsec ;
283+ uint64_t target_start_tvusec ;
284+ uint64_t access_seq ;
285+ int valid ;
286+ } AliasPageEntry ;
287+
288+ typedef struct {
289+ AliasPageEntry pages [MAX_ALIAS_PAGES ];
290+ uint64_t access_seq ;
291+ uint64_t target_start_tvsec ;
292+ uint64_t target_start_tvusec ;
293+ uint32_t probe_counter ;
294+ uint32_t remap_failure_index ;
295+ uint32_t remap_failure_samples ;
296+ uint32_t remap_failure_count ;
297+ unsigned char remap_failure_window [ALIAS_FAILURE_WINDOW ];
298+ int disabled_at_init ;
299+ int disabled_at_runtime ;
300+ } AliasReadCache ;
301+ #endif
302+
265303/* Statistics for profiling performance analysis */
266304typedef struct {
267305 uint64_t total_samples ; // Total number of get_stack_trace calls
@@ -280,6 +318,14 @@ typedef struct {
280318 uint64_t batched_read_misses ; // Attempts that fell back or partially read
281319 uint64_t batched_read_segments_requested ; // Segments requested by batched reads
282320 uint64_t batched_read_segments_completed ; // Segments completed by batched reads
321+ uint64_t alias_hits ; // macOS alias-cache hits
322+ uint64_t alias_misses ; // macOS alias-cache misses
323+ uint64_t alias_remap_failures ; // macOS remap/protect failures
324+ uint64_t alias_validation_fails ; // macOS alias snapshot validation failures
325+ uint64_t alias_evictions ; // macOS alias-cache LRU evictions
326+ uint64_t alias_identity_mismatches ; // macOS target identity mismatches
327+ uint64_t alias_disabled_at_init ; // macOS aliasing disabled during init (0/1)
328+ uint64_t alias_disabled_at_runtime ; // macOS aliasing disabled at runtime (0/1)
283329} UnwinderStats ;
284330
285331#if defined(__GNUC__ ) || defined(__clang__ )
@@ -382,6 +428,9 @@ typedef struct {
382428#ifdef __APPLE__
383429 uint64_t thread_id_offset ;
384430 int thread_id_offset_initialized ;
431+ # if TARGET_OS_OSX
432+ AliasReadCache alias_cache ;
433+ # endif
385434#endif
386435#ifdef MS_WINDOWS
387436 PVOID win_process_buffer ;
@@ -648,6 +697,38 @@ extern int collect_frames_with_cache(
648697 FrameWalkContext * ctx ,
649698 uint64_t thread_id );
650699
700+ #if defined(__APPLE__ ) && TARGET_OS_OSX
701+ extern int parse_frame_object_aliased (
702+ RemoteUnwinderObject * unwinder ,
703+ uintptr_t expected_parent ,
704+ PyObject * * result ,
705+ uintptr_t address ,
706+ uintptr_t * address_of_code_object ,
707+ uintptr_t * previous_frame
708+ );
709+
710+ extern int _Py_RemoteDebug_ValidateInterpreterSnapshot (
711+ RemoteUnwinderObject * unwinder ,
712+ const char * interp_state_buffer
713+ );
714+ extern int _Py_RemoteDebug_ValidateThreadStateSnapshot (
715+ RemoteUnwinderObject * unwinder ,
716+ const char * tstate_buffer ,
717+ uintptr_t tstate_addr ,
718+ uintptr_t current_interpreter
719+ );
720+ extern int _Py_RemoteDebug_AliasedRead (
721+ RemoteUnwinderObject * unwinder ,
722+ AliasReadKind kind ,
723+ uintptr_t remote_addr ,
724+ size_t len ,
725+ void * dst );
726+ extern void _Py_RemoteDebug_AliasCacheInit (RemoteUnwinderObject * unwinder );
727+ extern void _Py_RemoteDebug_AliasCacheClear (RemoteUnwinderObject * unwinder );
728+ extern void _Py_RemoteDebug_AliasCacheInvalidatePage (RemoteUnwinderObject * unwinder , uintptr_t remote_addr );
729+ extern int _Py_RemoteDebug_AliasProbe (RemoteUnwinderObject * unwinder , uintptr_t probe_addr );
730+ #endif
731+
651732/* ============================================================================
652733 * THREAD FUNCTION DECLARATIONS
653734 * ============================================================================ */
@@ -676,6 +757,7 @@ extern int get_thread_status(RemoteUnwinderObject *unwinder, uint64_t tid, uint6
676757
677758extern PyObject * unwind_stack_for_thread (
678759 RemoteUnwinderObject * unwinder ,
760+ uintptr_t current_interpreter ,
679761 uintptr_t * current_tstate ,
680762 uintptr_t gil_holder_tstate ,
681763 uintptr_t gc_frame ,
0 commit comments