From 1d030aa41fde126560189bccb7ffef85c57e3687 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Wed, 30 Mar 2022 12:56:56 -0500 Subject: [PATCH] Implement RtlCaptureStackBackTrace --- src/core/kernel/exports/EmuKrnlRtl.cpp | 44 ++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/core/kernel/exports/EmuKrnlRtl.cpp b/src/core/kernel/exports/EmuKrnlRtl.cpp index 3c09b2bd2..356eb20d1 100644 --- a/src/core/kernel/exports/EmuKrnlRtl.cpp +++ b/src/core/kernel/exports/EmuKrnlRtl.cpp @@ -294,6 +294,7 @@ XBSYSAPI EXPORTNUM(265) xbox::void_xt NTAPI xbox::RtlCaptureContext // ****************************************************************** // * 0x010A - RtlCaptureStackBackTrace() // ****************************************************************** +// Source: ReactOS XBSYSAPI EXPORTNUM(266) xbox::ushort_xt NTAPI xbox::RtlCaptureStackBackTrace ( IN ulong_xt FramesToSkip, @@ -309,9 +310,48 @@ XBSYSAPI EXPORTNUM(266) xbox::ushort_xt NTAPI xbox::RtlCaptureStackBackTrace LOG_FUNC_ARG_OUT(BackTraceHash) LOG_FUNC_END; - LOG_UNIMPLEMENTED(); + PVOID Frames[2 * 64]; + ulong_xt FrameCount; + ulong_xt Hash = 0; + ushort_xt i; - RETURN(NULL); + /* Skip a frame for the caller */ + FramesToSkip++; + + /* Don't go past the limit */ + if ((FramesToCapture + FramesToSkip) >= 128) { + return 0; + } + + /* Do the back trace */ + FrameCount = RtlWalkFrameChain(Frames, FramesToCapture + FramesToSkip, 0); + + /* Make sure we're not skipping all of them */ + if (FrameCount <= FramesToSkip) { + return 0; + } + + /* Loop all the frames */ + for (i = 0; i < FramesToCapture; i++) { + /* Don't go past the limit */ + if ((FramesToSkip + i) >= FrameCount) { + break; + } + + /* Save this entry and hash it */ + BackTrace[i] = Frames[FramesToSkip + i]; + Hash += reinterpret_cast(BackTrace[i]); + } + + /* Write the hash */ + if (BackTraceHash) { + *BackTraceHash = Hash; + } + + /* Clear the other entries and return count */ + RtlFillMemoryUlong(Frames, 128, 0); + + RETURN(i); } // ******************************************************************