Skip to content
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
  • Loading branch information
pablogsal and gpshead committed Apr 12, 2026
commit 215390a0efeffad298a09dc40b171d139b601e21
35 changes: 21 additions & 14 deletions Modules/_remote_debugging/debug_offsets_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,24 +206,27 @@ validate_fixed_field(
} while (0)

/*
* Each list below must include every offset that is later dereferenced against
* a local buffer or local object view. The validator checks that each field
* stays within both the remote table's reported section size and the local
* buffer size we use when reading that section. If a new dereferenced field is
* added to the offset tables, add it to the matching list here.
* Each list below must include every offset that is later dereferenced against
* a local buffer or local object view. The validator checks that each field
* stays within both the remote table's reported section size and the local
* buffer size we use when reading that section. If a new dereferenced field is
* added to the offset tables, add it to the matching list here.
*
* Sections not listed here are present in the offset tables but not used by
* the unwinder, so no validation is needed for them.
*/
#define PY_REMOTE_DEBUG_RUNTIME_STATE_FIELDS(APPLY, buffer_size) \
APPLY(runtime_state, interpreters_head, sizeof(uintptr_t), buffer_size)

#define PY_REMOTE_DEBUG_THREAD_STATE_FIELDS(APPLY, buffer_size) \
APPLY(thread_state, native_thread_id, sizeof(long), buffer_size); \
APPLY(thread_state, interp, sizeof(uintptr_t), buffer_size); \
APPLY(thread_state, datastack_chunk, sizeof(uintptr_t), buffer_size); \
APPLY(thread_state, status, FIELD_SIZE(PyThreadState, _status), buffer_size); \
APPLY(thread_state, holds_gil, sizeof(int), buffer_size); \
APPLY(thread_state, gil_requested, sizeof(int), buffer_size); \
APPLY(thread_state, current_exception, sizeof(uintptr_t), buffer_size); \
APPLY(thread_state, thread_id, sizeof(long), buffer_size); \
APPLY(thread_state, native_thread_id, sizeof(unsigned long), buffer_size); \
APPLY(thread_state, interp, sizeof(uintptr_t), buffer_size); \
APPLY(thread_state, datastack_chunk, sizeof(uintptr_t), buffer_size); \
APPLY(thread_state, status, FIELD_SIZE(PyThreadState, _status), buffer_size); \
APPLY(thread_state, holds_gil, sizeof(int), buffer_size); \
APPLY(thread_state, gil_requested, sizeof(int), buffer_size); \
APPLY(thread_state, current_exception, sizeof(uintptr_t), buffer_size); \
APPLY(thread_state, thread_id, sizeof(unsigned long), buffer_size); \
APPLY(thread_state, next, sizeof(uintptr_t), buffer_size); \
APPLY(thread_state, current_frame, sizeof(uintptr_t), buffer_size); \
APPLY(thread_state, base_frame, sizeof(uintptr_t), buffer_size); \
Expand Down Expand Up @@ -296,7 +299,11 @@ validate_fixed_field(
static inline int
_PyRemoteDebug_ValidateDebugOffsetsLayout(struct _Py_DebugOffsets *debug_offsets)
{
PY_REMOTE_DEBUG_VALIDATE_SECTION(runtime_state);
/* Validate every field the unwinder dereferences against a local buffer
* or local object view. Fields used only for remote address arithmetic
* (e.g. runtime_state.interpreters_head) are also checked as a sanity
* bound on the offset value. */
PY_REMOTE_DEBUG_VALIDATE_SECTION(runtime_state);
PY_REMOTE_DEBUG_RUNTIME_STATE_FIELDS(
PY_REMOTE_DEBUG_VALIDATE_FIELD,
sizeof(_PyRuntimeState));
Expand Down
Loading