Skip to content

Commit 25e012d

Browse files
committed
remap
1 parent c720e18 commit 25e012d

7 files changed

Lines changed: 697 additions & 2 deletions

File tree

Lib/test/test_external_inspection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3772,6 +3772,14 @@ def test_get_stats(self):
37723772
"batched_read_misses",
37733773
"batched_read_segments_requested",
37743774
"batched_read_segments_completed",
3775+
"alias_hits",
3776+
"alias_misses",
3777+
"alias_remap_failures",
3778+
"alias_validation_fails",
3779+
"alias_evictions",
3780+
"alias_identity_mismatches",
3781+
"alias_disabled_at_init",
3782+
"alias_disabled_at_runtime",
37753783
"batched_read_success_rate",
37763784
"batched_read_segment_completion_rate",
37773785
]

Modules/Setup.stdlib.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
@MODULE__PICKLE_TRUE@_pickle _pickle.c
4242
@MODULE__QUEUE_TRUE@_queue _queuemodule.c
4343
@MODULE__RANDOM_TRUE@_random _randommodule.c
44-
@MODULE__REMOTE_DEBUGGING_TRUE@_remote_debugging _remote_debugging/module.c _remote_debugging/gc_stats.c _remote_debugging/object_reading.c _remote_debugging/code_objects.c _remote_debugging/frames.c _remote_debugging/frame_cache.c _remote_debugging/threads.c _remote_debugging/asyncio.c _remote_debugging/binary_io_writer.c _remote_debugging/binary_io_reader.c _remote_debugging/subprocess.c _remote_debugging/interpreters.c
44+
@MODULE__REMOTE_DEBUGGING_TRUE@_remote_debugging _remote_debugging/module.c _remote_debugging/gc_stats.c _remote_debugging/object_reading.c _remote_debugging/code_objects.c _remote_debugging/frames.c _remote_debugging/frame_cache.c _remote_debugging/threads.c _remote_debugging/asyncio.c _remote_debugging/alias_read.c _remote_debugging/binary_io_writer.c _remote_debugging/binary_io_reader.c _remote_debugging/subprocess.c _remote_debugging/interpreters.c
4545
@MODULE__STRUCT_TRUE@_struct _struct.c
4646

4747
# build supports subinterpreters

Modules/_remote_debugging/_remote_debugging.h

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */
266304
typedef 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

677758
extern 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

Comments
 (0)