[PATCH 1/5] ntdll: Factor out capture_stack_back_trace() function.
Paul Gofman
pgofman at codeweavers.com
Thu Oct 21 11:03:36 CDT 2021
Signed-off-by: Paul Gofman <pgofman at codeweavers.com>
---
dlls/ntdll/signal_i386.c | 22 ++++++++++++++++------
dlls/ntdll/signal_x86_64.c | 35 +++++++++++++++++++++++------------
2 files changed, 39 insertions(+), 18 deletions(-)
diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c
index 14971032ce6..0245aa602a1 100644
--- a/dlls/ntdll/signal_i386.c
+++ b/dlls/ntdll/signal_i386.c
@@ -481,17 +481,15 @@ __ASM_STDCALL_FUNC( RtlRaiseException, 4,
/*************************************************************************
- * RtlCaptureStackBackTrace (NTDLL.@)
+ * capture_stack_back_trace
*/
-USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash )
+static USHORT capture_stack_back_trace( CONTEXT *context, ULONG skip, ULONG count, PVOID *buffer, ULONG *hash )
{
- CONTEXT context;
- ULONG i;
ULONG *frame;
+ ULONG i;
- RtlCaptureContext( &context );
if (hash) *hash = 0;
- frame = (ULONG *)context.Ebp;
+ frame = (ULONG *)context->Ebp;
while (skip--)
{
@@ -510,6 +508,18 @@ USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer,
}
+/*************************************************************************
+ * RtlCaptureStackBackTrace (NTDLL.@)
+ */
+USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash )
+{
+ CONTEXT context;
+
+ RtlCaptureContext( &context );
+ return capture_stack_back_trace( &context, skip, count, buffer, hash );
+}
+
+
/***********************************************************************
* signal_start_thread
*/
diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c
index ef32eba68b7..dbf622392b7 100644
--- a/dlls/ntdll/signal_x86_64.c
+++ b/dlls/ntdll/signal_x86_64.c
@@ -1490,27 +1490,23 @@ static inline ULONG hash_pointers( void **ptrs, ULONG count )
/*************************************************************************
- * RtlCaptureStackBackTrace (NTDLL.@)
+ * capture_stack_back_trace
*/
-USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash )
+static USHORT capture_stack_back_trace( CONTEXT *context, ULONG skip, ULONG count, PVOID *buffer, ULONG *hash )
{
- UNWIND_HISTORY_TABLE table;
DISPATCHER_CONTEXT dispatch;
- CONTEXT context;
+ UNWIND_HISTORY_TABLE table;
+ USHORT num_entries = 0;
NTSTATUS status;
ULONG i;
- USHORT num_entries = 0;
- TRACE( "(%u, %u, %p, %p)\n", skip, count, buffer, hash );
-
- RtlCaptureContext( &context );
dispatch.TargetIp = 0;
- dispatch.ContextRecord = &context;
+ dispatch.ContextRecord = context;
dispatch.HistoryTable = &table;
if (hash) *hash = 0;
for (i = 0; i < skip + count; i++)
{
- status = virtual_unwind( UNW_FLAG_NHANDLER, &dispatch, &context );
+ status = virtual_unwind( UNW_FLAG_NHANDLER, &dispatch, context );
if (status != STATUS_SUCCESS) return i;
if (!dispatch.EstablisherFrame) break;
@@ -1524,9 +1520,9 @@ USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer,
break;
}
- if (context.Rsp == (ULONG64)NtCurrentTeb()->Tib.StackBase) break;
+ if (context->Rsp == (ULONG64)NtCurrentTeb()->Tib.StackBase) break;
- if (i >= skip) buffer[num_entries++] = (void *)context.Rip;
+ if (i >= skip) buffer[num_entries++] = (void *)context->Rip;
}
if (hash && num_entries > 0) *hash = hash_pointers( buffer, num_entries );
TRACE( "captured %hu frames\n", num_entries );
@@ -1534,6 +1530,21 @@ USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer,
}
+/*************************************************************************
+ * RtlCaptureStackBackTrace (NTDLL.@)
+ */
+USHORT WINAPI RtlCaptureStackBackTrace( ULONG skip, ULONG count, PVOID *buffer, ULONG *hash )
+{
+ CONTEXT context;
+
+ TRACE( "(%u, %u, %p, %p)\n", skip, count, buffer, hash );
+
+ RtlCaptureContext( &context );
+
+ return capture_stack_back_trace( &context, skip, count, buffer, hash );
+}
+
+
/***********************************************************************
* signal_start_thread
*/
--
2.31.1
More information about the wine-devel
mailing list