PDRIVER_REINITIALIZE: Force stdcall for captive as it is callbacked
[reactos.git] / ntoskrnl / rtl / capture.c
1 /*
2  *  ReactOS kernel
3  *  Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 /* $Id$
20  *
21  * PROJECT:         ReactOS kernel
22  * FILE:            ntoskrnl/rtl/capture.c
23  * PURPOSE:         Helper routines for system calls.
24  * PROGRAMMER:      David Welch (welch@cwcom.net)
25  * UPDATE HISTORY:
26  *                02/09/01: Created
27  */
28
29 /* INCLUDES ******************************************************************/
30
31 #include <ddk/ntddk.h>
32 #include <internal/safe.h>
33
34 #define NDEBUG
35 #include <internal/debug.h>
36
37 /* FUNCTIONS *****************************************************************/
38
39 NTSTATUS
40 RtlCaptureUnicodeString(PUNICODE_STRING Dest,
41                         PUNICODE_STRING UnsafeSrc)
42 {
43   PUNICODE_STRING Src;
44   NTSTATUS Status;
45
46   /*
47    * Copy the source string structure to kernel space.
48    */
49   Status = MmCopyFromCaller(&Src, UnsafeSrc, sizeof(UNICODE_STRING));
50   if (!NT_SUCCESS(Status))
51     {
52       return(Status);
53     }
54
55   /*
56    * Initialize the destination string.
57    */
58   Dest->Length = Src->Length;
59   Dest->MaximumLength = Src->MaximumLength;
60   Dest->Buffer = ExAllocatePool(NonPagedPool, Dest->MaximumLength);
61   if (Dest->Buffer == NULL)
62     {
63       return(STATUS_NO_MEMORY);
64     }
65
66   /*
67    * Copy the source string to kernel space.
68    */
69   Status = MmCopyFromCaller(Dest->Buffer, Src->Buffer, Dest->Length);
70   if (!NT_SUCCESS(Status))
71     {
72       ExFreePool(Dest->Buffer);
73       return(Status);
74     }
75
76   return(STATUS_SUCCESS);
77 }
78
79 NTSTATUS
80 RtlCaptureAnsiString(PANSI_STRING Dest,
81                      PANSI_STRING UnsafeSrc)
82 {
83   PANSI_STRING Src; 
84   NTSTATUS Status;
85   
86   /*
87    * Copy the source string structure to kernel space.
88    */
89   Status = MmCopyFromCaller(&Src, UnsafeSrc, sizeof(ANSI_STRING));
90   if (!NT_SUCCESS(Status))
91     {
92       return(Status);
93     }
94
95   /*
96    * Initialize the destination string.
97    */
98   Dest->Length = Src->Length;
99   Dest->MaximumLength = Src->MaximumLength;
100   Dest->Buffer = ExAllocatePool(NonPagedPool, Dest->MaximumLength);
101   if (Dest->Buffer == NULL)
102     {
103       return(Status);
104     }
105
106   /*
107    * Copy the source string to kernel space.
108    */
109   Status = MmCopyFromCaller(Dest->Buffer, Src->Buffer, Dest->Length);
110   if (!NT_SUCCESS(Status))
111     {
112       ExFreePool(Dest->Buffer);
113       return(Status);
114     }
115
116   return(STATUS_SUCCESS);
117 }
118
119 /* EOF */
120