update for HEAD-2003091401
[reactos.git] / lib / kernel32 / mem / virtual.c
1 /* $Id$
2  *
3  * COPYRIGHT:            See COPYING in the top level directory
4  * PROJECT:              ReactOS kernel
5  * FILE:                 lib/kernel32/mem/virtual.c
6  * PURPOSE:              Passing the Virtualxxx functions onto the kernel
7  * PROGRAMMER:           David Welch (welch@mcmail.com)
8  */
9
10 /* INCLUDES ******************************************************************/
11
12 #include <k32.h>
13
14 /* FUNCTIONS *****************************************************************/
15
16 /*
17  * @implemented
18  */
19 LPVOID STDCALL
20 VirtualAllocEx(HANDLE hProcess,
21                LPVOID lpAddress,
22                DWORD dwSize,
23                DWORD flAllocationType,
24                DWORD flProtect)
25 {
26   NTSTATUS Status;
27
28   Status = NtAllocateVirtualMemory(hProcess,
29                                    (PVOID *)&lpAddress,
30                                    0,
31                                    (PULONG)&dwSize,
32                                    flAllocationType,
33                                    flProtect);
34   if (!NT_SUCCESS(Status))
35     {
36       SetLastErrorByStatus(Status);
37       return(NULL);
38     }
39   return(lpAddress);
40 }
41
42
43 /*
44  * @implemented
45  */
46 LPVOID STDCALL
47 VirtualAlloc(LPVOID lpAddress,
48              DWORD dwSize,
49              DWORD flAllocationType,
50              DWORD flProtect)
51 {
52   return(VirtualAllocEx(GetCurrentProcess(),
53                         lpAddress,
54                         dwSize,
55                         flAllocationType,
56                         flProtect));
57 }
58
59
60 /*
61  * @implemented
62  */
63 WINBOOL STDCALL
64 VirtualFreeEx(HANDLE hProcess,
65               LPVOID lpAddress,
66               DWORD dwSize,
67               DWORD dwFreeType)
68 {
69   NTSTATUS Status;
70
71   Status = NtFreeVirtualMemory(hProcess,
72                                (PVOID *)&lpAddress,
73                                (PULONG)&dwSize,
74                                dwFreeType);
75   if (!NT_SUCCESS(Status))
76     {
77       SetLastErrorByStatus(Status);
78       return(FALSE);
79     }
80   return(TRUE);
81 }
82
83
84 /*
85  * @implemented
86  */
87 WINBOOL STDCALL
88 VirtualFree(LPVOID lpAddress,
89             DWORD dwSize,
90             DWORD dwFreeType)
91 {
92   return(VirtualFreeEx(GetCurrentProcess(),
93                        lpAddress,
94                        dwSize,
95                        dwFreeType));
96 }
97
98
99 /*
100  * @implemented
101  */
102 WINBOOL STDCALL
103 VirtualProtect(LPVOID lpAddress,
104                DWORD dwSize,
105                DWORD flNewProtect,
106                PDWORD lpflOldProtect)
107 {
108   return(VirtualProtectEx(GetCurrentProcess(),
109                           lpAddress,
110                           dwSize,
111                           flNewProtect,
112                           lpflOldProtect));
113 }
114
115
116 /*
117  * @implemented
118  */
119 WINBOOL STDCALL
120 VirtualProtectEx(HANDLE hProcess,
121                  LPVOID lpAddress,
122                  DWORD dwSize,
123                  DWORD flNewProtect,
124                  PDWORD lpflOldProtect)
125 {
126   NTSTATUS Status;
127
128   Status = NtProtectVirtualMemory(hProcess,
129                                   (PVOID)lpAddress,
130                                   dwSize,
131                                   flNewProtect,
132                                   (PULONG)lpflOldProtect);
133   if (!NT_SUCCESS(Status))
134     {
135       SetLastErrorByStatus(Status);
136       return(FALSE);
137     }
138   return(TRUE);
139 }
140
141
142 /*
143  * @implemented
144  */
145 WINBOOL STDCALL
146 VirtualLock(LPVOID lpAddress,
147             DWORD dwSize)
148 {
149   ULONG BytesLocked;
150   NTSTATUS Status;
151
152   Status = NtLockVirtualMemory(NtCurrentProcess(),
153                                lpAddress,
154                                dwSize,
155                                &BytesLocked);
156   if (!NT_SUCCESS(Status))
157     {
158       SetLastErrorByStatus(Status);
159       return(FALSE);
160     }
161   return(TRUE);
162 }
163
164
165 /*
166  * @implemented
167  */
168 DWORD STDCALL
169 VirtualQuery(LPCVOID lpAddress,
170              PMEMORY_BASIC_INFORMATION lpBuffer,
171              DWORD dwLength)
172 {
173   return(VirtualQueryEx(NtCurrentProcess(),
174                         lpAddress,
175                         lpBuffer,
176                         dwLength));
177 }
178
179
180 /*
181  * @implemented
182  */
183 DWORD STDCALL
184 VirtualQueryEx(HANDLE hProcess,
185                LPCVOID lpAddress,
186                PMEMORY_BASIC_INFORMATION lpBuffer,
187                DWORD dwLength)
188 {
189   NTSTATUS Status;
190   ULONG ResultLength;
191
192   Status = NtQueryVirtualMemory(hProcess,
193                                 (LPVOID)lpAddress,
194                                 MemoryBasicInformation,
195                                 lpBuffer,
196                                 sizeof(MEMORY_BASIC_INFORMATION),
197                                 &ResultLength );
198   if (!NT_SUCCESS(Status))
199     {
200       SetLastErrorByStatus(Status);
201       return(ResultLength);
202     }
203   return(ResultLength);
204 }
205
206
207 /*
208  * @implemented
209  */
210 WINBOOL STDCALL
211 VirtualUnlock(LPVOID lpAddress,
212               DWORD dwSize)
213 {
214   ULONG BytesLocked;
215   NTSTATUS Status;
216
217   Status = NtUnlockVirtualMemory(NtCurrentProcess(),
218                                  lpAddress,
219                                  dwSize,
220                                  &BytesLocked);
221   if (!NT_SUCCESS(Status))
222     {
223       SetLastErrorByStatus(Status);
224       return(FALSE);
225     }
226   return(TRUE);
227 }
228
229 /* EOF */