1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
/*
* Win32 virtual memory functions
*
* Copyright 1997 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <fcntl.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include "ntstatus.h"
#define WIN32_NO_STATUS
#define NONAMELESSUNION
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "winternl.h"
#include "winerror.h"
#include "psapi.h"
#include "wine/exception.h"
#include "wine/debug.h"
#include "kernel_private.h"
WINE_DECLARE_DEBUG_CHANNEL(seh);
WINE_DECLARE_DEBUG_CHANNEL(file);
/***********************************************************************
* VirtualAlloc (KERNEL32.@)
*
* Reserves or commits a region of pages in virtual address space.
*
* PARAMS
* addr [I] Address of region to reserve or commit.
* size [I] Size of region.
* type [I] Type of allocation.
* protect [I] Type of access protection.
*
* RETURNS
* Success: Base address of allocated region of pages.
* Failure: NULL.
*/
LPVOID WINAPI DECLSPEC_HOTPATCH VirtualAlloc( void *addr, SIZE_T size, DWORD type, DWORD protect )
{
return VirtualAllocEx( GetCurrentProcess(), addr, size, type, protect );
}
/***********************************************************************
* VirtualAllocEx (KERNEL32.@)
*
* Seems to be just as VirtualAlloc, but with process handle.
*
* PARAMS
* hProcess [I] Handle to process to do mem operation.
* addr [I] Address of region to reserve or commit.
* size [I] Size of region.
* type [I] Type of allocation.
* protect [I] Type of access protection.
*
*
* RETURNS
* Success: Base address of allocated region of pages.
* Failure: NULL.
*/
LPVOID WINAPI VirtualAllocEx( HANDLE hProcess, LPVOID addr, SIZE_T size,
DWORD type, DWORD protect )
{
LPVOID ret = addr;
NTSTATUS status;
if ((status = NtAllocateVirtualMemory( hProcess, &ret, 0, &size, type, protect )))
{
SetLastError( RtlNtStatusToDosError(status) );
ret = NULL;
}
return ret;
}
/***********************************************************************
* VirtualFree (KERNEL32.@)
*
* Releases or decommits a region of pages in virtual address space.
*
* PARAMS
* addr [I] Address of region of committed pages.
* size [I] Size of region.
* type [I] Type of operation.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*/
BOOL WINAPI VirtualFree( LPVOID addr, SIZE_T size, DWORD type )
{
return VirtualFreeEx( GetCurrentProcess(), addr, size, type );
}
/***********************************************************************
* VirtualFreeEx (KERNEL32.@)
*
* Releases or decommits a region of pages in virtual address space.
*
* PARAMS
* process [I] Handle to process.
* addr [I] Address of region to free.
* size [I] Size of region.
* type [I] Type of operation.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*/
BOOL WINAPI VirtualFreeEx( HANDLE process, LPVOID addr, SIZE_T size, DWORD type )
{
NTSTATUS status = NtFreeVirtualMemory( process, &addr, &size, type );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* VirtualLock (KERNEL32.@)
*
* Locks the specified region of virtual address space.
*
* PARAMS
* addr [I] Address of first byte of range to lock.
* size [I] Number of bytes in range to lock.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*
* NOTES
* Always returns TRUE.
*
*/
BOOL WINAPI VirtualLock( LPVOID addr, SIZE_T size )
{
NTSTATUS status = NtLockVirtualMemory( GetCurrentProcess(), &addr, &size, 1 );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* VirtualUnlock (KERNEL32.@)
*
* Unlocks a range of pages in the virtual address space.
*
* PARAMS
* addr [I] Address of first byte of range.
* size [I] Number of bytes in range.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*
* NOTES
* Always returns TRUE.
*
*/
BOOL WINAPI VirtualUnlock( LPVOID addr, SIZE_T size )
{
NTSTATUS status = NtUnlockVirtualMemory( GetCurrentProcess(), &addr, &size, 1 );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* VirtualProtect (KERNEL32.@)
*
* Changes the access protection on a region of committed pages.
*
* PARAMS
* addr [I] Address of region of committed pages.
* size [I] Size of region.
* new_prot [I] Desired access protection.
* old_prot [O] Address of variable to get old protection.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*/
BOOL WINAPI VirtualProtect( LPVOID addr, SIZE_T size, DWORD new_prot, LPDWORD old_prot)
{
return VirtualProtectEx( GetCurrentProcess(), addr, size, new_prot, old_prot );
}
/***********************************************************************
* VirtualProtectEx (KERNEL32.@)
*
* Changes the access protection on a region of committed pages in the
* virtual address space of a specified process.
*
* PARAMS
* process [I] Handle of process.
* addr [I] Address of region of committed pages.
* size [I] Size of region.
* new_prot [I] Desired access protection.
* old_prot [O] Address of variable to get old protection.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*/
BOOL WINAPI VirtualProtectEx( HANDLE process, LPVOID addr, SIZE_T size,
DWORD new_prot, LPDWORD old_prot )
{
NTSTATUS status;
DWORD prot;
/* Win9x allows passing NULL as old_prot while this fails on NT */
if (!old_prot && (GetVersion() & 0x80000000)) old_prot = &prot;
status = NtProtectVirtualMemory( process, &addr, &size, new_prot, old_prot );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* VirtualQuery (KERNEL32.@)
*
* Provides info about a range of pages in virtual address space.
*
* PARAMS
* addr [I] Address of region.
* info [O] Address of info buffer.
* len [I] Size of buffer.
*
* RETURNS
* Number of bytes returned in information buffer or 0 if
* addr >= 0xc0000000 (kernel space).
*/
SIZE_T WINAPI VirtualQuery( LPCVOID addr, PMEMORY_BASIC_INFORMATION info,
SIZE_T len )
{
return VirtualQueryEx( GetCurrentProcess(), addr, info, len );
}
/***********************************************************************
* VirtualQueryEx (KERNEL32.@)
*
* Provides info about a range of pages in virtual address space of a
* specified process.
*
* PARAMS
* process [I] Handle to process.
* addr [I] Address of region.
* info [O] Address of info buffer.
* len [I] Size of buffer.
*
* RETURNS
* Number of bytes returned in information buffer.
*/
SIZE_T WINAPI VirtualQueryEx( HANDLE process, LPCVOID addr,
PMEMORY_BASIC_INFORMATION info, SIZE_T len )
{
SIZE_T ret;
NTSTATUS status;
if ((status = NtQueryVirtualMemory( process, addr, MemoryBasicInformation, info, len, &ret )))
{
SetLastError( RtlNtStatusToDosError(status) );
ret = 0;
}
return ret;
}
/***********************************************************************
* CreateFileMappingA (KERNEL32.@)
*
* Creates a named or unnamed file-mapping object for the specified file.
*
* PARAMS
* hFile [I] Handle to the file to map.
* sa [I] Optional security attributes.
* protect [I] Protection for mapping object.
* size_high [I] High-order 32 bits of object size.
* size_low [I] Low-order 32 bits of object size.
* name [I] Name of file-mapping object.
*
* RETURNS
* Success: Handle.
* Failure: NULL. Mapping object does not exist.
*/
HANDLE WINAPI CreateFileMappingA( HANDLE hFile, SECURITY_ATTRIBUTES *sa,
DWORD protect, DWORD size_high, DWORD size_low, LPCSTR name )
{
WCHAR buffer[MAX_PATH];
if (!name) return CreateFileMappingW( hFile, sa, protect, size_high, size_low, NULL );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return CreateFileMappingW( hFile, sa, protect, size_high, size_low, buffer );
}
/***********************************************************************
* CreateFileMappingW (KERNEL32.@)
*
* See CreateFileMappingA.
*/
HANDLE WINAPI CreateFileMappingW( HANDLE hFile, LPSECURITY_ATTRIBUTES sa,
DWORD protect, DWORD size_high,
DWORD size_low, LPCWSTR name )
{
static const int sec_flags = SEC_FILE | SEC_IMAGE | SEC_RESERVE | SEC_COMMIT | SEC_NOCACHE;
HANDLE ret;
NTSTATUS status;
DWORD access, sec_type;
LARGE_INTEGER size;
sec_type = protect & sec_flags;
protect &= ~sec_flags;
if (!sec_type) sec_type = SEC_COMMIT;
/* Win9x compatibility */
if (!protect && (GetVersion() & 0x80000000)) protect = PAGE_READONLY;
switch(protect)
{
case PAGE_READONLY:
case PAGE_WRITECOPY:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ;
break;
case PAGE_READWRITE:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE;
break;
case PAGE_EXECUTE_READ:
case PAGE_EXECUTE_WRITECOPY:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_EXECUTE;
break;
case PAGE_EXECUTE_READWRITE:
access = STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_WRITE | SECTION_MAP_EXECUTE;
break;
default:
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
if (hFile == INVALID_HANDLE_VALUE)
{
hFile = 0;
if (!size_low && !size_high)
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
}
size.u.LowPart = size_low;
size.u.HighPart = size_high;
if (sa || name)
{
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW;
attr.Length = sizeof(attr);
attr.RootDirectory = 0;
attr.ObjectName = NULL;
attr.Attributes = OBJ_OPENIF | ((sa && sa->bInheritHandle) ? OBJ_INHERIT : 0);
attr.SecurityDescriptor = sa ? sa->lpSecurityDescriptor : NULL;
attr.SecurityQualityOfService = NULL;
if (name)
{
RtlInitUnicodeString( &nameW, name );
attr.ObjectName = &nameW;
attr.RootDirectory = get_BaseNamedObjects_handle();
}
status = NtCreateSection( &ret, access, &attr, &size, protect, sec_type, hFile );
}
else status = NtCreateSection( &ret, access, NULL, &size, protect, sec_type, hFile );
if (status == STATUS_OBJECT_NAME_EXISTS)
SetLastError( ERROR_ALREADY_EXISTS );
else
SetLastError( RtlNtStatusToDosError(status) );
return ret;
}
/***********************************************************************
* OpenFileMappingA (KERNEL32.@)
*
* Opens a named file-mapping object.
*
* PARAMS
* access [I] Access mode.
* inherit [I] Inherit flag.
* name [I] Name of file-mapping object.
*
* RETURNS
* Success: Handle.
* Failure: NULL.
*/
HANDLE WINAPI OpenFileMappingA( DWORD access, BOOL inherit, LPCSTR name )
{
WCHAR buffer[MAX_PATH];
if (!name) return OpenFileMappingW( access, inherit, NULL );
if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
{
SetLastError( ERROR_FILENAME_EXCED_RANGE );
return 0;
}
return OpenFileMappingW( access, inherit, buffer );
}
/***********************************************************************
* OpenFileMappingW (KERNEL32.@)
*
* See OpenFileMappingA.
*/
HANDLE WINAPI OpenFileMappingW( DWORD access, BOOL inherit, LPCWSTR name)
{
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW;
HANDLE ret;
NTSTATUS status;
if (!name)
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
attr.Length = sizeof(attr);
attr.RootDirectory = get_BaseNamedObjects_handle();
attr.ObjectName = &nameW;
attr.Attributes = inherit ? OBJ_INHERIT : 0;
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
RtlInitUnicodeString( &nameW, name );
if (access == FILE_MAP_COPY) access = SECTION_MAP_READ;
if (GetVersion() & 0x80000000)
{
/* win9x doesn't do access checks, so try with full access first */
if (!NtOpenSection( &ret, access | SECTION_MAP_READ | SECTION_MAP_WRITE, &attr )) return ret;
}
if ((status = NtOpenSection( &ret, access, &attr )))
{
SetLastError( RtlNtStatusToDosError(status) );
ret = 0;
}
return ret;
}
/***********************************************************************
* MapViewOfFile (KERNEL32.@)
*
* Maps a view of a file into the address space.
*
* PARAMS
* mapping [I] File-mapping object to map.
* access [I] Access mode.
* offset_high [I] High-order 32 bits of file offset.
* offset_low [I] Low-order 32 bits of file offset.
* count [I] Number of bytes to map.
*
* RETURNS
* Success: Starting address of mapped view.
* Failure: NULL.
*/
LPVOID WINAPI DECLSPEC_HOTPATCH MapViewOfFile( HANDLE mapping, DWORD access,
DWORD offset_high, DWORD offset_low, SIZE_T count )
{
return MapViewOfFileEx( mapping, access, offset_high,
offset_low, count, NULL );
}
/***********************************************************************
* MapViewOfFileEx (KERNEL32.@)
*
* Maps a view of a file into the address space.
*
* PARAMS
* handle [I] File-mapping object to map.
* access [I] Access mode.
* offset_high [I] High-order 32 bits of file offset.
* offset_low [I] Low-order 32 bits of file offset.
* count [I] Number of bytes to map.
* addr [I] Suggested starting address for mapped view.
*
* RETURNS
* Success: Starting address of mapped view.
* Failure: NULL.
*/
LPVOID WINAPI MapViewOfFileEx( HANDLE handle, DWORD access,
DWORD offset_high, DWORD offset_low, SIZE_T count, LPVOID addr )
{
NTSTATUS status;
LARGE_INTEGER offset;
ULONG protect;
BOOL exec;
offset.u.LowPart = offset_low;
offset.u.HighPart = offset_high;
exec = access & FILE_MAP_EXECUTE;
access &= ~FILE_MAP_EXECUTE;
if (access == FILE_MAP_COPY)
protect = exec ? PAGE_EXECUTE_WRITECOPY : PAGE_WRITECOPY;
else if (access & FILE_MAP_WRITE)
protect = exec ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE;
else if (access & FILE_MAP_READ)
protect = exec ? PAGE_EXECUTE_READ : PAGE_READONLY;
else protect = PAGE_NOACCESS;
if ((status = NtMapViewOfSection( handle, GetCurrentProcess(), &addr, 0, 0, &offset,
&count, ViewShare, 0, protect )) < 0)
{
SetLastError( RtlNtStatusToDosError(status) );
addr = NULL;
}
return addr;
}
/***********************************************************************
* UnmapViewOfFile (KERNEL32.@)
*
* Unmaps a mapped view of a file.
*
* PARAMS
* addr [I] Address where mapped view begins.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*
*/
BOOL WINAPI UnmapViewOfFile( LPCVOID addr )
{
NTSTATUS status;
if (GetVersion() & 0x80000000)
{
MEMORY_BASIC_INFORMATION info;
if (!VirtualQuery( addr, &info, sizeof(info) ) || info.AllocationBase != addr)
{
SetLastError( ERROR_INVALID_ADDRESS );
return FALSE;
}
}
status = NtUnmapViewOfSection( GetCurrentProcess(), (void *)addr );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* FlushViewOfFile (KERNEL32.@)
*
* Writes to the disk a byte range within a mapped view of a file.
*
* PARAMS
* base [I] Start address of byte range to flush.
* size [I] Number of bytes in range.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE.
*/
BOOL WINAPI FlushViewOfFile( LPCVOID base, SIZE_T size )
{
NTSTATUS status = NtFlushVirtualMemory( GetCurrentProcess(), &base, &size, 0 );
if (status)
{
if (status == STATUS_NOT_MAPPED_DATA) status = STATUS_SUCCESS;
else SetLastError( RtlNtStatusToDosError(status) );
}
return !status;
}
/***********************************************************************
* GetWriteWatch (KERNEL32.@)
*/
UINT WINAPI GetWriteWatch( DWORD flags, LPVOID base, SIZE_T size, LPVOID *addresses,
ULONG_PTR *count, ULONG *granularity )
{
NTSTATUS status;
status = NtGetWriteWatch( GetCurrentProcess(), flags, base, size, addresses, count, granularity );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return status ? ~0u : 0;
}
/***********************************************************************
* ResetWriteWatch (KERNEL32.@)
*/
UINT WINAPI ResetWriteWatch( LPVOID base, SIZE_T size )
{
NTSTATUS status;
status = NtResetWriteWatch( GetCurrentProcess(), base, size );
if (status) SetLastError( RtlNtStatusToDosError(status) );
return status ? ~0u : 0;
}
/***********************************************************************
* IsBadReadPtr (KERNEL32.@)
*
* Check for read access on a memory block.
*
* ptr [I] Address of memory block.
* size [I] Size of block.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE. Process has read access to entire block.
*/
BOOL WINAPI IsBadReadPtr( LPCVOID ptr, UINT_PTR size )
{
if (!size) return FALSE; /* handle 0 size case w/o reference */
if (!ptr) return TRUE;
__TRY
{
volatile const char *p = ptr;
char dummy __attribute__((unused));
UINT_PTR count = size;
while (count > system_info.PageSize)
{
dummy = *p;
p += system_info.PageSize;
count -= system_info.PageSize;
}
dummy = p[0];
dummy = p[count - 1];
}
__EXCEPT_PAGE_FAULT
{
TRACE_(seh)("%p caused page fault during read\n", ptr);
return TRUE;
}
__ENDTRY
return FALSE;
}
/***********************************************************************
* IsBadWritePtr (KERNEL32.@)
*
* Check for write access on a memory block.
*
* PARAMS
* ptr [I] Address of memory block.
* size [I] Size of block in bytes.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE. Process has write access to entire block.
*/
BOOL WINAPI IsBadWritePtr( LPVOID ptr, UINT_PTR size )
{
if (!size) return FALSE; /* handle 0 size case w/o reference */
if (!ptr) return TRUE;
__TRY
{
volatile char *p = ptr;
UINT_PTR count = size;
while (count > system_info.PageSize)
{
*p |= 0;
p += system_info.PageSize;
count -= system_info.PageSize;
}
p[0] |= 0;
p[count - 1] |= 0;
}
__EXCEPT_PAGE_FAULT
{
TRACE_(seh)("%p caused page fault during write\n", ptr);
return TRUE;
}
__ENDTRY
return FALSE;
}
/***********************************************************************
* IsBadHugeReadPtr (KERNEL32.@)
*
* Check for read access on a memory block.
*
* PARAMS
* ptr [I] Address of memory block.
* size [I] Size of block.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE. Process has read access to entire block.
*/
BOOL WINAPI IsBadHugeReadPtr( LPCVOID ptr, UINT_PTR size )
{
return IsBadReadPtr( ptr, size );
}
/***********************************************************************
* IsBadHugeWritePtr (KERNEL32.@)
*
* Check for write access on a memory block.
*
* PARAMS
* ptr [I] Address of memory block.
* size [I] Size of block.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE. Process has write access to entire block.
*/
BOOL WINAPI IsBadHugeWritePtr( LPVOID ptr, UINT_PTR size )
{
return IsBadWritePtr( ptr, size );
}
/***********************************************************************
* IsBadCodePtr (KERNEL32.@)
*
* Check for read access on a memory address.
*
* PARAMS
* ptr [I] Address of function.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE. Process has read access to specified memory.
*/
BOOL WINAPI IsBadCodePtr( FARPROC ptr )
{
return IsBadReadPtr( ptr, 1 );
}
/***********************************************************************
* IsBadStringPtrA (KERNEL32.@)
*
* Check for read access on a range of memory pointed to by a string pointer.
*
* PARAMS
* str [I] Address of string.
* max [I] Maximum size of string.
*
* RETURNS
* Success: TRUE.
* Failure: FALSE. Read access to all bytes in string.
*/
BOOL WINAPI IsBadStringPtrA( LPCSTR str, UINT_PTR max )
{
if (!str) return TRUE;
__TRY
{
volatile const char *p = str;
while (p != str + max) if (!*p++) break;
}
__EXCEPT_PAGE_FAULT
{
TRACE_(seh)("%p caused page fault during read\n", str);
return TRUE;
}
__ENDTRY
return FALSE;
}
/***********************************************************************
* IsBadStringPtrW (KERNEL32.@)
*
* See IsBadStringPtrA.
*/
BOOL WINAPI IsBadStringPtrW( LPCWSTR str, UINT_PTR max )
{
if (!str) return TRUE;
__TRY
{
volatile const WCHAR *p = str;
while (p != str + max) if (!*p++) break;
}
__EXCEPT_PAGE_FAULT
{
TRACE_(seh)("%p caused page fault during read\n", str);
return TRUE;
}
__ENDTRY
return FALSE;
}
/***********************************************************************
* K32GetMappedFileNameA (KERNEL32.@)
*/
DWORD WINAPI K32GetMappedFileNameA(HANDLE process, LPVOID lpv, LPSTR file_name, DWORD size)
{
FIXME_(file)("(%p, %p, %p, %d): stub\n", process, lpv, file_name, size);
if (file_name && size)
file_name[0] = '\0';
return 0;
}
/***********************************************************************
* K32GetMappedFileNameW (KERNEL32.@)
*/
DWORD WINAPI K32GetMappedFileNameW(HANDLE process, LPVOID lpv, LPWSTR file_name, DWORD size)
{
FIXME_(file)("(%p, %p, %p, %d): stub\n", process, lpv, file_name, size);
if (file_name && size)
file_name[0] = '\0';
return 0;
}
/***********************************************************************
* K32EnumPageFilesA (KERNEL32.@)
*/
BOOL WINAPI K32EnumPageFilesA( PENUM_PAGE_FILE_CALLBACKA callback, LPVOID context )
{
FIXME_(file)("(%p, %p) stub\n", callback, context );
return FALSE;
}
/***********************************************************************
* K32EnumPageFilesW (KERNEL32.@)
*/
BOOL WINAPI K32EnumPageFilesW( PENUM_PAGE_FILE_CALLBACKW callback, LPVOID context )
{
FIXME_(file)("(%p, %p) stub\n", callback, context );
return FALSE;
}
/***********************************************************************
* K32GetWsChanges (KERNEL32.@)
*/
BOOL WINAPI K32GetWsChanges(HANDLE process, PPSAPI_WS_WATCH_INFORMATION watchinfo, DWORD size)
{
NTSTATUS status;
TRACE_(seh)("(%p, %p, %d)\n", process, watchinfo, size);
status = NtQueryInformationProcess( process, ProcessWorkingSetWatch, watchinfo, size, NULL );
if (status)
{
SetLastError( RtlNtStatusToDosError( status ) );
return FALSE;
}
return TRUE;
}
/***********************************************************************
* K32InitializeProcessForWsWatch (KERNEL32.@)
*/
BOOL WINAPI K32InitializeProcessForWsWatch(HANDLE process)
{
FIXME_(seh)("(process=%p): stub\n", process);
return TRUE;
}