3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/rtl/capture.c
6 * PURPOSE: Helper routines for system calls.
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
11 /* INCLUDES ******************************************************************/
15 #include <internal/debug.h>
17 /* FUNCTIONS *****************************************************************/
20 RtlCaptureUnicodeString(OUT PUNICODE_STRING Dest
,
21 IN KPROCESSOR_MODE CurrentMode
,
22 IN POOL_TYPE PoolType
,
23 IN BOOLEAN CaptureIfKernel
,
24 IN PUNICODE_STRING UnsafeSrc
)
27 NTSTATUS Status
= STATUS_SUCCESS
;
32 * Copy the source string structure to kernel space.
35 if(CurrentMode
== UserMode
)
37 RtlZeroMemory(&Src
, sizeof(Src
));
41 ProbeForRead(UnsafeSrc
,
42 sizeof(UNICODE_STRING
),
47 ProbeForRead(Src
.Buffer
,
54 Status
= _SEH_GetExceptionCode();
58 if(!NT_SUCCESS(Status
))
63 else if(!CaptureIfKernel
)
65 /* just copy the UNICODE_STRING structure, the pointers are considered valid */
67 return STATUS_SUCCESS
;
71 /* capture the string even though it is considered to be valid */
76 * Initialize the destination string.
78 Dest
->Length
= Src
.Length
;
81 Dest
->MaximumLength
= Src
.Length
+ sizeof(WCHAR
);
82 Dest
->Buffer
= ExAllocatePool(PoolType
, Dest
->MaximumLength
);
83 if (Dest
->Buffer
== NULL
)
85 Dest
->Length
= Dest
->MaximumLength
= 0;
87 return STATUS_INSUFFICIENT_RESOURCES
;
90 * Copy the source string to kernel space.
94 RtlCopyMemory(Dest
->Buffer
, Src
.Buffer
, Src
.Length
);
95 Dest
->Buffer
[Src
.Length
/ sizeof(WCHAR
)] = L
'\0';
99 Status
= _SEH_GetExceptionCode();
103 if(!NT_SUCCESS(Status
))
105 ExFreePool(Dest
->Buffer
);
107 Dest
->Length
= Dest
->MaximumLength
= 0;
112 Dest
->MaximumLength
= 0;
120 RtlReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString
,
121 IN KPROCESSOR_MODE CurrentMode
,
122 IN BOOLEAN CaptureIfKernel
)
124 if(CurrentMode
!= KernelMode
|| CaptureIfKernel
)
126 RtlFreeUnicodeString(CapturedString
);
136 OUT PCONTEXT ContextRecord
147 RtlCaptureStackBackTrace (
148 IN ULONG FramesToSkip
,
149 IN ULONG FramesToCapture
,
150 OUT PVOID
*BackTrace
,
151 OUT PULONG BackTraceHash OPTIONAL