ntdll/tests: Added more registry symlink tests.
[wine.git] / dlls / kernel32 / virtual.c
blob5733a42bbf565d7d93f31e8ecaf337c94f67b031
1 /*
2 * Win32 virtual memory functions
4 * Copyright 1997 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <fcntl.h>
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sys/types.h>
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
33 #include "ntstatus.h"
34 #define WIN32_NO_STATUS
35 #define NONAMELESSUNION
36 #include "windef.h"
37 #include "winbase.h"
38 #include "winnls.h"
39 #include "winternl.h"
40 #include "winerror.h"
41 #include "psapi.h"
42 #include "wine/exception.h"
43 #include "wine/debug.h"
45 #include "kernel_private.h"
47 WINE_DECLARE_DEBUG_CHANNEL(seh);
48 WINE_DECLARE_DEBUG_CHANNEL(file);
51 /***********************************************************************
52 * VirtualAlloc (KERNEL32.@)
54 * Reserves or commits a region of pages in virtual address space.
56 * PARAMS
57 * addr [I] Address of region to reserve or commit.
58 * size [I] Size of region.
59 * type [I] Type of allocation.
60 * protect [I] Type of access protection.
62 * RETURNS
63 * Success: Base address of allocated region of pages.
64 * Failure: NULL.
66 LPVOID WINAPI DECLSPEC_HOTPATCH VirtualAlloc( void *addr, SIZE_T size, DWORD type, DWORD protect )
68 return VirtualAllocEx( GetCurrentProcess(), addr, size, type, protect );
72 /***********************************************************************
73 * VirtualAllocEx (KERNEL32.@)
75 * Seems to be just as VirtualAlloc, but with process handle.
77 * PARAMS
78 * hProcess [I] Handle to process to do mem operation.
79 * addr [I] Address of region to reserve or commit.
80 * size [I] Size of region.
81 * type [I] Type of allocation.
82 * protect [I] Type of access protection.
85 * RETURNS
86 * Success: Base address of allocated region of pages.
87 * Failure: NULL.
89 LPVOID WINAPI VirtualAllocEx( HANDLE hProcess, LPVOID addr, SIZE_T size,
90 DWORD type, DWORD protect )
92 LPVOID ret = addr;
93 NTSTATUS status;
95 if ((status = NtAllocateVirtualMemory( hProcess, &ret, 0, &size, type, protect )))
97 SetLastError( RtlNtStatusToDosError(status) );
98 ret = NULL;
100 return ret;
104 /***********************************************************************
105 * VirtualFree (KERNEL32.@)
107 * Releases or decommits a region of pages in virtual address space.
109 * PARAMS
110 * addr [I] Address of region of committed pages.
111 * size [I] Size of region.
112 * type [I] Type of operation.
114 * RETURNS
115 * Success: TRUE.
116 * Failure: FALSE.
118 BOOL WINAPI VirtualFree( LPVOID addr, SIZE_T size, DWORD type )
120 return VirtualFreeEx( GetCurrentProcess(), addr, size, type );
124 /***********************************************************************
125 * VirtualFreeEx (KERNEL32.@)
127 * Releases or decommits a region of pages in virtual address space.
129 * PARAMS
130 * process [I] Handle to process.
131 * addr [I] Address of region to free.
132 * size [I] Size of region.
133 * type [I] Type of operation.
135 * RETURNS
136 * Success: TRUE.
137 * Failure: FALSE.
139 BOOL WINAPI VirtualFreeEx( HANDLE process, LPVOID addr, SIZE_T size, DWORD type )
141 NTSTATUS status = NtFreeVirtualMemory( process, &addr, &size, type );
142 if (status) SetLastError( RtlNtStatusToDosError(status) );
143 return !status;
147 /***********************************************************************
148 * VirtualLock (KERNEL32.@)
150 * Locks the specified region of virtual address space.
152 * PARAMS
153 * addr [I] Address of first byte of range to lock.
154 * size [I] Number of bytes in range to lock.
156 * RETURNS
157 * Success: TRUE.
158 * Failure: FALSE.
160 * NOTES
161 * Always returns TRUE.
164 BOOL WINAPI VirtualLock( LPVOID addr, SIZE_T size )
166 NTSTATUS status = NtLockVirtualMemory( GetCurrentProcess(), &addr, &size, 1 );
167 if (status) SetLastError( RtlNtStatusToDosError(status) );
168 return !status;
172 /***********************************************************************
173 * VirtualUnlock (KERNEL32.@)
175 * Unlocks a range of pages in the virtual address space.
177 * PARAMS
178 * addr [I] Address of first byte of range.
179 * size [I] Number of bytes in range.
181 * RETURNS
182 * Success: TRUE.
183 * Failure: FALSE.
185 * NOTES
186 * Always returns TRUE.
189 BOOL WINAPI VirtualUnlock( LPVOID addr, SIZE_T size )
191 NTSTATUS status = NtUnlockVirtualMemory( GetCurrentProcess(), &addr, &size, 1 );
192 if (status) SetLastError( RtlNtStatusToDosError(status) );
193 return !status;
197 /***********************************************************************
198 * VirtualProtect (KERNEL32.@)
200 * Changes the access protection on a region of committed pages.
202 * PARAMS
203 * addr [I] Address of region of committed pages.
204 * size [I] Size of region.
205 * new_prot [I] Desired access protection.
206 * old_prot [O] Address of variable to get old protection.
208 * RETURNS
209 * Success: TRUE.
210 * Failure: FALSE.
212 BOOL WINAPI VirtualProtect( LPVOID addr, SIZE_T size, DWORD new_prot, LPDWORD old_prot)
214 return VirtualProtectEx( GetCurrentProcess(), addr, size, new_prot, old_prot );
218 /***********************************************************************
219 * VirtualProtectEx (KERNEL32.@)
221 * Changes the access protection on a region of committed pages in the
222 * virtual address space of a specified process.
224 * PARAMS
225 * process [I] Handle of process.
226 * addr [I] Address of region of committed pages.
227 * size [I] Size of region.
228 * new_prot [I] Desired access protection.
229 * old_prot [O] Address of variable to get old protection.
231 * RETURNS
232 * Success: TRUE.
233 * Failure: FALSE.
235 BOOL WINAPI VirtualProtectEx( HANDLE process, LPVOID addr, SIZE_T size,
236 DWORD new_prot, LPDWORD old_prot )
238 NTSTATUS status;
239 DWORD prot;
241 /* Win9x allows passing NULL as old_prot while this fails on NT */
242 if (!old_prot && (GetVersion() & 0x80000000)) old_prot = &prot;
244 status = NtProtectVirtualMemory( process, &addr, &size, new_prot, old_prot );
245 if (status) SetLastError( RtlNtStatusToDosError(status) );
246 return !status;
250 /***********************************************************************
251 * VirtualQuery (KERNEL32.@)
253 * Provides info about a range of pages in virtual address space.
255 * PARAMS
256 * addr [I] Address of region.
257 * info [O] Address of info buffer.
258 * len [I] Size of buffer.
260 * RETURNS
261 * Number of bytes returned in information buffer or 0 if
262 * addr >= 0xc0000000 (kernel space).
264 SIZE_T WINAPI VirtualQuery( LPCVOID addr, PMEMORY_BASIC_INFORMATION info,
265 SIZE_T len )
267 return VirtualQueryEx( GetCurrentProcess(), addr, info, len );
271 /***********************************************************************
272 * VirtualQueryEx (KERNEL32.@)
274 * Provides info about a range of pages in virtual address space of a
275 * specified process.
277 * PARAMS
278 * process [I] Handle to process.
279 * addr [I] Address of region.
280 * info [O] Address of info buffer.
281 * len [I] Size of buffer.
283 * RETURNS
284 * Number of bytes returned in information buffer.
286 SIZE_T WINAPI VirtualQueryEx( HANDLE process, LPCVOID addr,
287 PMEMORY_BASIC_INFORMATION info, SIZE_T len )
289 SIZE_T ret;
290 NTSTATUS status;
292 if ((status = NtQueryVirtualMemory( process, addr, MemoryBasicInformation, info, len, &ret )))
294 SetLastError( RtlNtStatusToDosError(status) );
295 ret = 0;
297 return ret;
301 /***********************************************************************
302 * CreateFileMappingA (KERNEL32.@)
304 * Creates a named or unnamed file-mapping object for the specified file.
306 * PARAMS
307 * hFile [I] Handle to the file to map.
308 * sa [I] Optional security attributes.
309 * protect [I] Protection for mapping object.
310 * size_high [I] High-order 32 bits of object size.
311 * size_low [I] Low-order 32 bits of object size.
312 * name [I] Name of file-mapping object.
314 * RETURNS
315 * Success: Handle.
316 * Failure: NULL. Mapping object does not exist.
318 HANDLE WINAPI CreateFileMappingA( HANDLE hFile, SECURITY_ATTRIBUTES *sa,
319 DWORD protect, DWORD size_high, DWORD size_low, LPCSTR name )
321 WCHAR buffer[MAX_PATH];
323 if (!name) return CreateFileMappingW( hFile, sa, protect, size_high, size_low, NULL );
325 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
327 SetLastError( ERROR_FILENAME_EXCED_RANGE );
328 return 0;
330 return CreateFileMappingW( hFile, sa, protect, size_high, size_low, buffer );
334 /***********************************************************************
335 * CreateFileMappingW (KERNEL32.@)
337 * See CreateFileMappingA.
339 HANDLE WINAPI CreateFileMappingW( HANDLE hFile, LPSECURITY_ATTRIBUTES sa,
340 DWORD protect, DWORD size_high,
341 DWORD size_low, LPCWSTR name )
343 static const int sec_flags = SEC_FILE | SEC_IMAGE | SEC_RESERVE | SEC_COMMIT | SEC_NOCACHE;
345 HANDLE ret;
346 NTSTATUS status;
347 DWORD access, sec_type;
348 LARGE_INTEGER size;
350 sec_type = protect & sec_flags;
351 protect &= ~sec_flags;
352 if (!sec_type) sec_type = SEC_COMMIT;
354 /* Win9x compatibility */
355 if (!protect && (GetVersion() & 0x80000000)) protect = PAGE_READONLY;
357 switch(protect)
359 case PAGE_READONLY:
360 case PAGE_WRITECOPY:
361 access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ;
362 break;
363 case PAGE_READWRITE:
364 access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE;
365 break;
366 case PAGE_EXECUTE_READ:
367 case PAGE_EXECUTE_WRITECOPY:
368 access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_EXECUTE;
369 break;
370 case PAGE_EXECUTE_READWRITE:
371 access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE | SECTION_MAP_EXECUTE;
372 break;
373 default:
374 SetLastError( ERROR_INVALID_PARAMETER );
375 return 0;
378 if (hFile == INVALID_HANDLE_VALUE)
380 hFile = 0;
381 if (!size_low && !size_high)
383 SetLastError( ERROR_INVALID_PARAMETER );
384 return 0;
388 size.u.LowPart = size_low;
389 size.u.HighPart = size_high;
391 if (sa || name)
393 OBJECT_ATTRIBUTES attr;
394 UNICODE_STRING nameW;
396 attr.Length = sizeof(attr);
397 attr.RootDirectory = 0;
398 attr.ObjectName = NULL;
399 attr.Attributes = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
400 attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
401 attr.SecurityQualityOfService = NULL;
402 if (name)
404 RtlInitUnicodeString( &nameW, name );
405 attr.ObjectName = &nameW;
406 attr.RootDirectory = get_BaseNamedObjects_handle();
408 status = NtCreateSection( &ret, access, &attr, &size, protect, sec_type, hFile );
410 else status = NtCreateSection( &ret, access, NULL, &size, protect, sec_type, hFile );
412 if (status == STATUS_OBJECT_NAME_EXISTS)
413 SetLastError( ERROR_ALREADY_EXISTS );
414 else
415 SetLastError( RtlNtStatusToDosError(status) );
416 return ret;
420 /***********************************************************************
421 * OpenFileMappingA (KERNEL32.@)
423 * Opens a named file-mapping object.
425 * PARAMS
426 * access [I] Access mode.
427 * inherit [I] Inherit flag.
428 * name [I] Name of file-mapping object.
430 * RETURNS
431 * Success: Handle.
432 * Failure: NULL.
434 HANDLE WINAPI OpenFileMappingA( DWORD access, BOOL inherit, LPCSTR name )
436 WCHAR buffer[MAX_PATH];
438 if (!name) return OpenFileMappingW( access, inherit, NULL );
440 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
442 SetLastError( ERROR_FILENAME_EXCED_RANGE );
443 return 0;
445 return OpenFileMappingW( access, inherit, buffer );
449 /***********************************************************************
450 * OpenFileMappingW (KERNEL32.@)
452 * See OpenFileMappingA.
454 HANDLE WINAPI OpenFileMappingW( DWORD access, BOOL inherit, LPCWSTR name)
456 OBJECT_ATTRIBUTES attr;
457 UNICODE_STRING nameW;
458 HANDLE ret;
459 NTSTATUS status;
461 if (!name)
463 SetLastError( ERROR_INVALID_PARAMETER );
464 return 0;
466 attr.Length = sizeof(attr);
467 attr.RootDirectory = get_BaseNamedObjects_handle();
468 attr.ObjectName = &nameW;
469 attr.Attributes = inherit ? OBJ_INHERIT : 0;
470 attr.SecurityDescriptor = NULL;
471 attr.SecurityQualityOfService = NULL;
472 RtlInitUnicodeString( &nameW, name );
474 if (access == FILE_MAP_COPY) access = SECTION_MAP_READ;
476 if (GetVersion() & 0x80000000)
478 /* win9x doesn't do access checks, so try with full access first */
479 if (!NtOpenSection( &ret, access | SECTION_MAP_READ | SECTION_MAP_WRITE, &attr )) return ret;
482 if ((status = NtOpenSection( &ret, access, &attr )))
484 SetLastError( RtlNtStatusToDosError(status) );
485 ret = 0;
487 return ret;
491 /***********************************************************************
492 * MapViewOfFile (KERNEL32.@)
494 * Maps a view of a file into the address space.
496 * PARAMS
497 * mapping [I] File-mapping object to map.
498 * access [I] Access mode.
499 * offset_high [I] High-order 32 bits of file offset.
500 * offset_low [I] Low-order 32 bits of file offset.
501 * count [I] Number of bytes to map.
503 * RETURNS
504 * Success: Starting address of mapped view.
505 * Failure: NULL.
507 LPVOID WINAPI DECLSPEC_HOTPATCH MapViewOfFile( HANDLE mapping, DWORD access,
508 DWORD offset_high, DWORD offset_low, SIZE_T count )
510 return MapViewOfFileEx( mapping, access, offset_high,
511 offset_low, count, NULL );
515 /***********************************************************************
516 * MapViewOfFileEx (KERNEL32.@)
518 * Maps a view of a file into the address space.
520 * PARAMS
521 * handle [I] File-mapping object to map.
522 * access [I] Access mode.
523 * offset_high [I] High-order 32 bits of file offset.
524 * offset_low [I] Low-order 32 bits of file offset.
525 * count [I] Number of bytes to map.
526 * addr [I] Suggested starting address for mapped view.
528 * RETURNS
529 * Success: Starting address of mapped view.
530 * Failure: NULL.
532 LPVOID WINAPI MapViewOfFileEx( HANDLE handle, DWORD access,
533 DWORD offset_high, DWORD offset_low, SIZE_T count, LPVOID addr )
535 NTSTATUS status;
536 LARGE_INTEGER offset;
537 ULONG protect;
538 BOOL exec;
540 offset.u.LowPart = offset_low;
541 offset.u.HighPart = offset_high;
543 exec = access & FILE_MAP_EXECUTE;
544 access &= ~FILE_MAP_EXECUTE;
546 if (access == FILE_MAP_COPY)
547 protect = exec ? PAGE_EXECUTE_WRITECOPY : PAGE_WRITECOPY;
548 else if (access & FILE_MAP_WRITE)
549 protect = exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
550 else if (access & FILE_MAP_READ)
551 protect = exec ? PAGE_EXECUTE_READ : PAGE_READONLY;
552 else protect = PAGE_NOACCESS;
554 if ((status = NtMapViewOfSection( handle, GetCurrentProcess(), &addr, 0, 0, &offset,
555 &count, ViewShare, 0, protect )) < 0)
557 SetLastError( RtlNtStatusToDosError(status) );
558 addr = NULL;
560 return addr;
564 /***********************************************************************
565 * UnmapViewOfFile (KERNEL32.@)
567 * Unmaps a mapped view of a file.
569 * PARAMS
570 * addr [I] Address where mapped view begins.
572 * RETURNS
573 * Success: TRUE.
574 * Failure: FALSE.
577 BOOL WINAPI UnmapViewOfFile( LPCVOID addr )
579 NTSTATUS status;
581 if (GetVersion() & 0x80000000)
583 MEMORY_BASIC_INFORMATION info;
584 if (!VirtualQuery( addr, &info, sizeof(info) ) || info.AllocationBase != addr)
586 SetLastError( ERROR_INVALID_ADDRESS );
587 return FALSE;
591 status = NtUnmapViewOfSection( GetCurrentProcess(), (void *)addr );
592 if (status) SetLastError( RtlNtStatusToDosError(status) );
593 return !status;
597 /***********************************************************************
598 * FlushViewOfFile (KERNEL32.@)
600 * Writes to the disk a byte range within a mapped view of a file.
602 * PARAMS
603 * base [I] Start address of byte range to flush.
604 * size [I] Number of bytes in range.
606 * RETURNS
607 * Success: TRUE.
608 * Failure: FALSE.
610 BOOL WINAPI FlushViewOfFile( LPCVOID base, SIZE_T size )
612 NTSTATUS status = NtFlushVirtualMemory( GetCurrentProcess(), &base, &size, 0 );
613 if (status)
615 if (status == STATUS_NOT_MAPPED_DATA) status = STATUS_SUCCESS;
616 else SetLastError( RtlNtStatusToDosError(status) );
618 return !status;
622 /***********************************************************************
623 * GetWriteWatch (KERNEL32.@)
625 UINT WINAPI GetWriteWatch( DWORD flags, LPVOID base, SIZE_T size, LPVOID *addresses,
626 ULONG_PTR *count, ULONG *granularity )
628 NTSTATUS status;
630 status = NtGetWriteWatch( GetCurrentProcess(), flags, base, size, addresses, count, granularity );
631 if (status) SetLastError( RtlNtStatusToDosError(status) );
632 return status ? ~0u : 0;
636 /***********************************************************************
637 * ResetWriteWatch (KERNEL32.@)
639 UINT WINAPI ResetWriteWatch( LPVOID base, SIZE_T size )
641 NTSTATUS status;
643 status = NtResetWriteWatch( GetCurrentProcess(), base, size );
644 if (status) SetLastError( RtlNtStatusToDosError(status) );
645 return status ? ~0u : 0;
649 /***********************************************************************
650 * IsBadReadPtr (KERNEL32.@)
652 * Check for read access on a memory block.
654 * ptr [I] Address of memory block.
655 * size [I] Size of block.
657 * RETURNS
658 * Success: TRUE.
659 * Failure: FALSE. Process has read access to entire block.
661 BOOL WINAPI IsBadReadPtr( LPCVOID ptr, UINT_PTR size )
663 if (!size) return FALSE; /* handle 0 size case w/o reference */
664 if (!ptr) return TRUE;
665 __TRY
667 volatile const char *p = ptr;
668 char dummy __attribute__((unused));
669 UINT_PTR count = size;
671 while (count > system_info.PageSize)
673 dummy = *p;
674 p += system_info.PageSize;
675 count -= system_info.PageSize;
677 dummy = p[0];
678 dummy = p[count - 1];
680 __EXCEPT_PAGE_FAULT
682 TRACE_(seh)("%p caused page fault during read\n", ptr);
683 return TRUE;
685 __ENDTRY
686 return FALSE;
690 /***********************************************************************
691 * IsBadWritePtr (KERNEL32.@)
693 * Check for write access on a memory block.
695 * PARAMS
696 * ptr [I] Address of memory block.
697 * size [I] Size of block in bytes.
699 * RETURNS
700 * Success: TRUE.
701 * Failure: FALSE. Process has write access to entire block.
703 BOOL WINAPI IsBadWritePtr( LPVOID ptr, UINT_PTR size )
705 if (!size) return FALSE; /* handle 0 size case w/o reference */
706 if (!ptr) return TRUE;
707 __TRY
709 volatile char *p = ptr;
710 UINT_PTR count = size;
712 while (count > system_info.PageSize)
714 *p |= 0;
715 p += system_info.PageSize;
716 count -= system_info.PageSize;
718 p[0] |= 0;
719 p[count - 1] |= 0;
721 __EXCEPT_PAGE_FAULT
723 TRACE_(seh)("%p caused page fault during write\n", ptr);
724 return TRUE;
726 __ENDTRY
727 return FALSE;
731 /***********************************************************************
732 * IsBadHugeReadPtr (KERNEL32.@)
734 * Check for read access on a memory block.
736 * PARAMS
737 * ptr [I] Address of memory block.
738 * size [I] Size of block.
740 * RETURNS
741 * Success: TRUE.
742 * Failure: FALSE. Process has read access to entire block.
744 BOOL WINAPI IsBadHugeReadPtr( LPCVOID ptr, UINT_PTR size )
746 return IsBadReadPtr( ptr, size );
750 /***********************************************************************
751 * IsBadHugeWritePtr (KERNEL32.@)
753 * Check for write access on a memory block.
755 * PARAMS
756 * ptr [I] Address of memory block.
757 * size [I] Size of block.
759 * RETURNS
760 * Success: TRUE.
761 * Failure: FALSE. Process has write access to entire block.
763 BOOL WINAPI IsBadHugeWritePtr( LPVOID ptr, UINT_PTR size )
765 return IsBadWritePtr( ptr, size );
769 /***********************************************************************
770 * IsBadCodePtr (KERNEL32.@)
772 * Check for read access on a memory address.
774 * PARAMS
775 * ptr [I] Address of function.
777 * RETURNS
778 * Success: TRUE.
779 * Failure: FALSE. Process has read access to specified memory.
781 BOOL WINAPI IsBadCodePtr( FARPROC ptr )
783 return IsBadReadPtr( ptr, 1 );
787 /***********************************************************************
788 * IsBadStringPtrA (KERNEL32.@)
790 * Check for read access on a range of memory pointed to by a string pointer.
792 * PARAMS
793 * str [I] Address of string.
794 * max [I] Maximum size of string.
796 * RETURNS
797 * Success: TRUE.
798 * Failure: FALSE. Read access to all bytes in string.
800 BOOL WINAPI IsBadStringPtrA( LPCSTR str, UINT_PTR max )
802 if (!str) return TRUE;
804 __TRY
806 volatile const char *p = str;
807 while (p != str + max) if (!*p++) break;
809 __EXCEPT_PAGE_FAULT
811 TRACE_(seh)("%p caused page fault during read\n", str);
812 return TRUE;
814 __ENDTRY
815 return FALSE;
819 /***********************************************************************
820 * IsBadStringPtrW (KERNEL32.@)
822 * See IsBadStringPtrA.
824 BOOL WINAPI IsBadStringPtrW( LPCWSTR str, UINT_PTR max )
826 if (!str) return TRUE;
828 __TRY
830 volatile const WCHAR *p = str;
831 while (p != str + max) if (!*p++) break;
833 __EXCEPT_PAGE_FAULT
835 TRACE_(seh)("%p caused page fault during read\n", str);
836 return TRUE;
838 __ENDTRY
839 return FALSE;
842 /***********************************************************************
843 * K32GetMappedFileNameA (KERNEL32.@)
845 DWORD WINAPI K32GetMappedFileNameA(HANDLE process, LPVOID lpv, LPSTR file_name, DWORD size)
847 FIXME_(file)("(%p, %p, %p, %d): stub\n", process, lpv, file_name, size);
849 if (file_name && size)
850 file_name[0] = '\0';
852 return 0;
855 /***********************************************************************
856 * K32GetMappedFileNameW (KERNEL32.@)
858 DWORD WINAPI K32GetMappedFileNameW(HANDLE process, LPVOID lpv, LPWSTR file_name, DWORD size)
860 FIXME_(file)("(%p, %p, %p, %d): stub\n", process, lpv, file_name, size);
862 if (file_name && size)
863 file_name[0] = '\0';
865 return 0;
868 /***********************************************************************
869 * K32EnumPageFilesA (KERNEL32.@)
871 BOOL WINAPI K32EnumPageFilesA( PENUM_PAGE_FILE_CALLBACKA callback, LPVOID context )
873 FIXME_(file)("(%p, %p) stub\n", callback, context );
874 return FALSE;
877 /***********************************************************************
878 * K32EnumPageFilesW (KERNEL32.@)
880 BOOL WINAPI K32EnumPageFilesW( PENUM_PAGE_FILE_CALLBACKW callback, LPVOID context )
882 FIXME_(file)("(%p, %p) stub\n", callback, context );
883 return FALSE;
886 /***********************************************************************
887 * K32GetWsChanges (KERNEL32.@)
889 BOOL WINAPI K32GetWsChanges(HANDLE process, PPSAPI_WS_WATCH_INFORMATION watchinfo, DWORD size)
891 NTSTATUS status;
893 TRACE_(seh)("(%p, %p, %d)\n", process, watchinfo, size);
895 status = NtQueryInformationProcess( process, ProcessWorkingSetWatch, watchinfo, size, NULL );
897 if (status)
899 SetLastError( RtlNtStatusToDosError( status ) );
900 return FALSE;
902 return TRUE;
905 /***********************************************************************
906 * K32InitializeProcessForWsWatch (KERNEL32.@)
908 BOOL WINAPI K32InitializeProcessForWsWatch(HANDLE process)
910 FIXME_(seh)("(process=%p): stub\n", process);
912 return TRUE;