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
)
39 ProbeForRead(UnsafeSrc
,
40 sizeof(UNICODE_STRING
),
45 ProbeForRead(Src
.Buffer
,
52 Status
= _SEH_GetExceptionCode();
56 if(!NT_SUCCESS(Status
))
61 else if(!CaptureIfKernel
)
63 /* just copy the UNICODE_STRING structure, the pointers are considered valid */
65 return STATUS_SUCCESS
;
69 /* capture the string even though it is considered to be valid */
74 * Initialize the destination string.
76 Dest
->Length
= Src
.Length
;
79 Dest
->MaximumLength
= Src
.Length
+ sizeof(WCHAR
);
80 Dest
->Buffer
= ExAllocatePool(PoolType
, Dest
->MaximumLength
);
81 if (Dest
->Buffer
== NULL
)
83 Dest
->Length
= Dest
->MaximumLength
= 0;
85 return STATUS_INSUFFICIENT_RESOURCES
;
88 * Copy the source string to kernel space.
92 RtlCopyMemory(Dest
->Buffer
, Src
.Buffer
, Src
.Length
);
93 Dest
->Buffer
[Src
.Length
/ sizeof(WCHAR
)] = L
'\0';
97 Status
= _SEH_GetExceptionCode();
101 if(!NT_SUCCESS(Status
))
103 ExFreePool(Dest
->Buffer
);
105 Dest
->Length
= Dest
->MaximumLength
= 0;
110 Dest
->MaximumLength
= 0;
118 RtlReleaseCapturedUnicodeString(IN PUNICODE_STRING CapturedString
,
119 IN KPROCESSOR_MODE CurrentMode
,
120 IN BOOLEAN CaptureIfKernel
)
122 if(CurrentMode
!= KernelMode
|| CaptureIfKernel
)
124 RtlFreeUnicodeString(CapturedString
);
134 OUT PCONTEXT ContextRecord
145 RtlCaptureStackBackTrace (
146 IN ULONG FramesToSkip
,
147 IN ULONG FramesToCapture
,
148 OUT PVOID
*BackTrace
,
149 OUT PULONG BackTraceHash OPTIONAL