source: trunk/src/kernel32/mmap.cpp@ 2658

Last change on this file since 2658 was 2658, checked in by sandervl, 26 years ago

memory map fixes

File size: 21.0 KB
Line 
1/* $Id: mmap.cpp,v 1.32 2000-02-05 14:09:31 sandervl Exp $ */
2
3/*
4 * Win32 Memory mapped file & view classes
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 * NOTE: Memory mapping DOES NOT work when kernel-mode code causes
9 * a pagefault in the memory mapped object. (exceptions aren't
10 * dispatched to our exception handler until after the kernel mode
11 * call returns (too late))
12 *
13 * NOTE: Are apps allowed to change the protection flags of memory mapped pages?
14 * I'm assuming they aren't for now.
15 *
16 * TODO: Handles returned should be usable by all apis that accept file handles
17 * TODO: Sharing memory mapped files between multiple processes
18 * TODO: Memory mapped files with views that extend the file (not 100% correct now)
19 *
20 * Project Odin Software License can be found in LICENSE.TXT
21 *
22 */
23#include <os2win.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <win\virtual.h>
28#include <vmutex.h>
29#include <handlemanager.h>
30#include "mmap.h"
31#include "oslibdos.h"
32#include <winimagepeldr.h>
33
34//Global DLL Data
35#pragma data_seg(_GLOBALDATA)
36Win32MemMap *Win32MemMap::memmaps = NULL;
37VMutex globalmapMutex(VMUTEX_SHARED);
38#pragma data_seg()
39VMutex globalviewMutex;
40Win32MemMapView *Win32MemMapView::mapviews = NULL;
41
42//******************************************************************************
43//TODO: sharing between processes
44//******************************************************************************
45Win32MemMap::Win32MemMap(HFILE hfile, ULONG size, ULONG fdwProtect, LPSTR lpszName)
46 : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0), image(0)
47{
48 globalmapMutex.enter();
49 next = memmaps;
50 memmaps = this;
51 globalmapMutex.leave();
52
53 hMemFile = hfile;
54
55 mSize = size;
56 mProtFlags = fdwProtect;
57 mProcessId = GetCurrentProcess();
58
59 if(lpszName) {
60 lpszMapName = (char *)_smalloc(strlen(lpszName)+1);
61 strcpy(lpszMapName, lpszName);
62 }
63 else lpszMapName = NULL;
64}
65//******************************************************************************
66//Map constructor used for executable image maps (only used internally)
67//******************************************************************************
68Win32MemMap::Win32MemMap(Win32PeLdrImage *pImage, ULONG baseAddress, ULONG size)
69 : nrMappings(0), pMapping(NULL), mMapAccess(0), referenced(0)
70{
71 globalmapMutex.enter();
72 next = memmaps;
73 memmaps = this;
74 globalmapMutex.leave();
75
76 hMemFile = -1;
77
78 mSize = size;
79 mProtFlags = PAGE_READWRITE;
80 mProcessId = GetCurrentProcess();
81
82 pMapping = (LPVOID)baseAddress;
83
84 image = pImage;
85 lpszMapName= NULL;
86}
87//******************************************************************************
88//******************************************************************************
89BOOL Win32MemMap::Init(HANDLE hMemMap)
90{
91 mapMutex.enter();
92 if(hMemFile != -1)
93 {
94 if(DuplicateHandle(mProcessId, hMemFile, GetCurrentProcess(),
95 &hMemFile, 0, FALSE, DUPLICATE_SAME_ACCESS) == FALSE)
96 {
97 dprintf(("Win32MemMap::Init: DuplicateHandle failed!"));
98 goto fail;
99 }
100 mSize = SetFilePointer(hMemFile, 0, NULL, FILE_END);
101 if(mSize == -1) {
102 dprintf(("Win32MemMap::init: SetFilePointer failed to set pos end"));
103 goto fail;
104 }
105 //SvL: Temporary limitation of size (Warp Server Advanced doesn't allow
106 // one to reserve more than 450 MB (unless you override the virtual
107 // memory max limit) of continuous memory; (Warp 4 much less))
108 if(mSize > 64*1024*1024) {
109 mSize = 64*1024*1024;
110 }
111 }
112
113 dprintf(("CreateFileMappingA for file %x, prot %x size %d, name %s", hMemFile, mProtFlags, mSize, lpszMapName));
114 this->hMemMap = hMemMap;
115 mapMutex.leave();
116 return TRUE;
117fail:
118 mapMutex.leave();
119 return FALSE;
120}
121//******************************************************************************
122//******************************************************************************
123Win32MemMap::~Win32MemMap()
124{
125 Win32MemMapView::deleteViews(this); //delete all views of our memory mapped file
126
127 dprintf(("Win32MemMap dtor: deleting view %x %x", pMapping, mSize));
128
129 mapMutex.enter();
130 if(lpszMapName) {
131 free(lpszMapName);
132 }
133 if(pMapping && !image) {
134 if(lpszMapName) {
135 OSLibDosFreeMem(pMapping);
136 }
137 else VirtualFree(pMapping, mSize, MEM_RELEASE);
138
139 pMapping = NULL;
140 }
141 if(hMemFile != -1) {
142 CloseHandle(hMemFile);
143 hMemFile = -1;
144 }
145 mapMutex.leave();
146
147 globalmapMutex.enter();
148 Win32MemMap *map = memmaps;
149
150 if(map == this) {
151 memmaps = next;
152 }
153 else {
154 while(map->next) {
155 if(map->next == this)
156 break;
157 map = map->next;
158 }
159 if(map->next) {
160 map->next = next;
161 }
162 else dprintf(("Win32MemMap::~Win32MemMap: map not found!! (%x)", this));
163 }
164 globalmapMutex.leave();
165}
166//******************************************************************************
167//We determine whether a page has been modified by checking it's protection flags
168//If the write flag is set, this means commitPage had to enable this due to a pagefault
169//(all pages are readonly until the app tries to write to it)
170//******************************************************************************
171BOOL Win32MemMap::commitPage(ULONG offset, BOOL fWriteAccess, int nrpages)
172{
173 MEMORY_BASIC_INFORMATION memInfo;
174 LPVOID lpPageFaultAddr = (LPVOID)((ULONG)pMapping + offset);
175 DWORD pageAddr = (DWORD)lpPageFaultAddr & ~0xFFF;
176 DWORD oldProt, newProt, nrBytesRead, size;
177 int i;
178
179// mapMutex.enter();
180
181 if(image) {
182 return image->commitPage(pageAddr, fWriteAccess);
183 }
184 newProt = mProtFlags & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY);
185
186 dprintf(("Win32MemMap::commitPage %x (faultaddr %x)", pageAddr, lpPageFaultAddr));
187 if(hMemFile != -1) {
188// for(i=0;i<nrpages;i++) {
189 if(VirtualQuery((LPSTR)pageAddr, &memInfo, nrpages*PAGE_SIZE) == 0) {
190 dprintf(("Win32MemMap::commitPage: VirtualQuery (%x,%x) failed for %x", pageAddr, nrpages*PAGE_SIZE));
191 goto fail;
192 }
193 //Only changes the state of the pages with the same attribute flags
194 //(returned in memInfo.RegionSize)
195 //If it's smaller than the mNrPages, it simply means one or more of the
196 //other pages have already been committed
197 if(memInfo.State & MEM_COMMIT)
198 {//if it's already committed, then the app tried to write to it
199 if(!fWriteAccess) {
200 dprintf(("Win32MemMap::commitPage: Huh? Already committed and not trying to write (%x,%x) failed for %x", pageAddr, memInfo.RegionSize));
201 goto fail;
202 }
203 if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, newProt, &oldProt) == FALSE) {
204 dprintf(("Win32MemMap::commitPage: Failed to set write flag on page (%x,%x) failed for %x", pageAddr, memInfo.RegionSize));
205 goto fail;
206 }
207 }
208 else {
209 if(VirtualAlloc((LPVOID)pageAddr, memInfo.RegionSize, MEM_COMMIT, PAGE_READWRITE) == FALSE) {
210 goto fail;
211 }
212 if(!fWriteAccess) {
213 offset = pageAddr - (ULONG)pMapping;
214 size = memInfo.RegionSize;
215 if(offset + size > mSize) {
216 dprintf(("Adjusting size from %d to %d", size, mSize - offset));
217 size = mSize - offset;
218 }
219 if(SetFilePointer(hMemFile, offset, NULL, FILE_BEGIN) != offset) {
220 dprintf(("Win32MemMap::commitPage: SetFilePointer failed to set pos to %x", offset));
221 goto fail;
222 }
223 if(ReadFile(hMemFile, (LPSTR)pageAddr, size, &nrBytesRead, NULL) == FALSE) {
224 dprintf(("Win32MemMap::commitPage: ReadFile failed for %x", pageAddr));
225 goto fail;
226 }
227 if(nrBytesRead != size) {
228 dprintf(("Win32MemMap::commitPage: ReadFile didn't read all bytes for %x", pageAddr));
229 goto fail;
230 }
231 }
232 if(mProtFlags != PAGE_READWRITE) {
233 if(VirtualProtect((LPVOID)pageAddr, memInfo.RegionSize, newProt, &oldProt) == FALSE) {
234 goto fail;
235 }
236 }
237 }
238// pageAddr += PAGE_SIZE;
239// }
240 }
241 else {
242 ULONG sizeleft = nrpages*PAGE_SIZE;
243 while(sizeleft) {
244 if(VirtualQuery((LPSTR)pageAddr, &memInfo, sizeleft) == 0) {
245 dprintf(("Win32MemMap::commitPage: VirtualQuery (%x,%x) failed", pageAddr, sizeleft));
246 goto fail;
247 }
248 if(!(memInfo.State & MEM_COMMIT))
249 {//if it's already committed, then the app tried to write to it
250 if(VirtualAlloc((LPVOID)pageAddr, memInfo.RegionSize, MEM_COMMIT, newProt) == FALSE)
251 goto fail;
252 }
253 memInfo.RegionSize = (memInfo.RegionSize+PAGE_SIZE-1) & ~0xfff;
254 pageAddr += memInfo.RegionSize;
255 sizeleft -= memInfo.RegionSize;
256 }
257 }
258
259// mapMutex.leave();
260 return TRUE;
261fail:
262// mapMutex.leave();
263 return FALSE;
264}
265//******************************************************************************
266//******************************************************************************
267BOOL Win32MemMap::unmapViewOfFile(Win32MemMapView *view)
268{
269 mapMutex.enter();
270
271 if(nrMappings == 0)
272 goto fail;
273
274 delete view;
275
276 if(--nrMappings) {
277 VirtualFree(pMapping, mSize, MEM_RELEASE);
278 pMapping = NULL;
279 }
280 mapMutex.leave();
281 return TRUE;
282fail:
283 mapMutex.leave();
284 return FALSE;
285}
286//******************************************************************************
287//******************************************************************************
288LPVOID Win32MemMap::mapViewOfFile(ULONG size, ULONG offset, ULONG fdwAccess)
289{
290 DWORD processId = GetCurrentProcess();
291
292 mapMutex.enter();
293 ULONG memFlags = (mProtFlags & (PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY));
294 ULONG fAlloc = 0;
295 Win32MemMapView *mapview;
296
297 //@@@PH: if(fdwAccess & ~(FILE_MAP_WRITE|FILE_MAP_READ|FILE_MAP_COPY))
298 // Docs say FILE_MAP_ALL_ACCESS is same as FILE_MAP_WRITE. Doesn't match reality though.
299 if(fdwAccess & ~FILE_MAP_ALL_ACCESS)
300 goto parmfail;
301 if((fdwAccess & FILE_MAP_WRITE) && !(mProtFlags & PAGE_READWRITE))
302 goto parmfail;
303 if((fdwAccess & FILE_MAP_READ) && !(mProtFlags & (PAGE_READWRITE|PAGE_READONLY)))
304 goto parmfail;
305
306 //@@@PH
307 if (fdwAccess != FILE_MAP_ALL_ACCESS)
308 if((fdwAccess & FILE_MAP_COPY) && !(mProtFlags & PAGE_WRITECOPY))
309 goto parmfail;
310
311 if(offset+size > mSize && (!(fdwAccess & FILE_MAP_WRITE) || !hMemFile))
312 goto parmfail;
313
314 //SvL: TODO: Doesn't work for multiple views
315 if(offset+size > mSize) {
316 mSize = offset+size;
317 }
318
319//TODO: If committed, read file into memory
320#if 0
321 if(mProtFlags & SEC_COMMIT)
322 fAlloc |= MEM_COMMIT;
323 else
324 if(mProtFlags & SEC_RESERVE)
325 fAlloc |= MEM_RESERVE;
326#else
327 fAlloc = MEM_RESERVE;
328#endif
329
330 //Memory has already been allocated for executable image maps (only used internally)
331 if(!pMapping && nrMappings == 0) {//if not mapped, reserve/commit entire view
332 //SvL: Always read/write access or else ReadFile will crash once we
333 // start committing pages.
334 // This is most likely an OS/2 bug and doesn't happen in Aurora
335 // when allocating memory with the PAG_ANY bit set. (without this
336 // flag it will also crash)
337 if(!hMemFile && lpszMapName) {
338 pMapping = VirtualAllocShared(mSize, fAlloc, PAGE_READWRITE, lpszMapName);
339 }
340 else {
341 pMapping = VirtualAlloc(0, mSize, fAlloc, PAGE_READWRITE);
342 }
343 if(pMapping == NULL) {
344 dprintf(("Win32MemMap::mapFileView: VirtualAlloc %x %x %x failed!", mSize, fAlloc, memFlags));
345 goto fail;
346 }
347 //Windows NT seems to commit memory for memory maps, regardsless of the SEC_COMMIT flag
348 if((hMemFile == -1 && !image)) {//commit memory
349 VirtualAlloc(pMapping, mSize, MEM_COMMIT, PAGE_READWRITE);
350 }
351 if(hMemFile && (mProtFlags & SEC_COMMIT)) {
352 DWORD nrPages = mSize >> PAGE_SHIFT;
353 if(mSize & 0xFFF)
354 nrPages++;
355
356 commitPage(0, FALSE, nrPages);
357 }
358 }
359 mapview = new Win32MemMapView(this, offset, (size == 0) ? mSize : size, fdwAccess);
360 if(mapview == NULL) {
361 goto fail;
362 }
363 if(mapview->everythingOk() == FALSE) {
364 dprintf(("Win32MemMap::mapFileView: !mapview->everythingOk"));
365 delete mapview;
366 goto fail;
367 }
368 nrMappings++;
369 mapMutex.leave();
370 return mapview->getViewAddr();
371
372parmfail:
373 dprintf(("Win32MemMap::mapFileView: ERROR_INVALID_PARAMETER"));
374 SetLastError(ERROR_INVALID_PARAMETER);
375fail:
376 mapMutex.leave();
377 return 0;
378}
379//******************************************************************************
380//We determine whether a page has been modified by checking it's protection flags
381//If the write flag is set, this means commitPage had to enable this due to a pagefault
382//(all pages are readonly until the app tries to modify the contents of the page)
383//
384//TODO: Are apps allowed to change the protection flags of memory mapped pages?
385// I'm assuming they aren't for now.
386//******************************************************************************
387BOOL Win32MemMap::flushView(ULONG offset, ULONG cbFlush)
388{
389 LPVOID lpvBase = (LPVOID)((ULONG)pMapping+offset);
390 MEMORY_BASIC_INFORMATION memInfo;
391 ULONG nrBytesWritten, size;
392 int i;
393
394 if(image) //no flushing for image maps
395 return TRUE;
396
397 dprintf(("Win32MemMap::flushView: %x %x", lpvBase, cbFlush));
398 if(nrMappings == 0)
399 goto parmfail;
400
401 if(cbFlush == 0)
402 cbFlush = mSize;
403
404 if(lpvBase < pMapping || (ULONG)lpvBase+cbFlush > (ULONG)pMapping+mSize)
405 goto parmfail;
406
407 if(mProtFlags & PAGE_READONLY)
408 goto parmfail;
409
410 if(hMemFile == -1)
411 goto success; //TODO: Return an error here?
412
413 while(cbFlush) {
414 if(VirtualQuery((LPSTR)lpvBase, &memInfo, cbFlush) == 0) {
415 dprintf(("Win32MemMap::flushView: VirtualQuery (%x,%x) failed for %x", lpvBase, cbFlush, (ULONG)lpvBase+i*PAGE_SIZE));
416 goto fail;
417 }
418 //If a page (or range of pages) is reserved or write protected, we
419 //won't bother flushing it to disk
420 if(memInfo.State & MEM_COMMIT &&
421 memInfo.AllocationProtect & (PAGE_READWRITE|PAGE_WRITECOPY|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY))
422 {//committed and allowed for writing?
423 offset = (ULONG)lpvBase - (ULONG)pMapping;
424 size = memInfo.RegionSize;
425 if(size > cbFlush) {
426 size = cbFlush;
427 }
428 dprintf(("Win32MemMap::flushView for offset %x, size %d", offset, size));
429
430 if(SetFilePointer(hMemFile, offset, NULL, FILE_BEGIN) != offset) {
431 dprintf(("Win32MemMap::flushView: SetFilePointer failed to set pos to %x", offset));
432 goto fail;
433 }
434 if(WriteFile(hMemFile, (LPSTR)lpvBase, size, &nrBytesWritten, NULL) == FALSE) {
435 dprintf(("Win32MemMap::flushView: WriteFile failed for %x", (ULONG)lpvBase));
436 goto fail;
437 }
438 if(nrBytesWritten != size) {
439 dprintf(("Win32MemMap::flushView: WriteFile didn't write all bytes for %x", (ULONG)lpvBase));
440 goto fail;
441 }
442 }
443 lpvBase = (LPVOID)((ULONG)lpvBase + memInfo.RegionSize);
444
445 if(cbFlush < memInfo.RegionSize)
446 break;
447
448 cbFlush -= memInfo.RegionSize;
449 }
450success:
451 return TRUE;
452parmfail:
453 SetLastError(ERROR_INVALID_PARAMETER);
454 return FALSE;
455fail:
456 return FALSE;
457}
458//******************************************************************************
459//******************************************************************************
460Win32MemMap *Win32MemMap::findMap(LPSTR lpszName)
461{
462 if(lpszName == NULL)
463 return NULL;
464
465 globalmapMutex.enter();
466 Win32MemMap *map = memmaps;
467
468 if(map != NULL) {
469 while(map) {
470 if(map->lpszMapName && !strcmp(map->lpszMapName, lpszName))
471 break;
472 map = map->next;
473 }
474 }
475 globalmapMutex.leave();
476 if(!map) dprintf(("Win32MemMap::findMap: couldn't find map %s", lpszName));
477 return map;
478}
479//******************************************************************************
480//******************************************************************************
481Win32MemMap *Win32MemMap::findMap(ULONG address)
482{
483 globalmapMutex.enter();
484 Win32MemMap *map = memmaps;
485
486 if(map != NULL) {
487 while(map) {
488 if(map->pMapping && (ULONG)map->pMapping <= address &&
489 (ULONG)map->pMapping + map->mSize > address)
490 {
491 break;
492 }
493 map = map->next;
494 }
495 }
496 globalmapMutex.leave();
497 return map;
498}
499//******************************************************************************
500//Assumes mutex has been acquired
501//******************************************************************************
502void Win32MemMap::deleteAll()
503{
504 Win32MemMap *map = memmaps, *nextmap;
505 DWORD processId = GetCurrentProcess();
506
507 //delete all maps created by this process
508 while(map) {
509 nextmap = map->next;
510 if(map->getProcessId() == processId) {
511 //Delete map directly for executable images (only used internally)
512 if(map->getImage()) {
513 delete map;
514 }
515 else CloseHandle(memmaps->hMemMap);
516 }
517 else {
518 //delete all views created by this process for this map
519 Win32MemMapView::deleteViews(map);
520 }
521 map = nextmap;
522 }
523}
524//******************************************************************************
525//******************************************************************************
526Win32MemMapView::Win32MemMapView(Win32MemMap *map, ULONG offset, ULONG size,
527 ULONG fdwAccess)
528{
529 LPVOID viewaddr = (LPVOID)((ULONG)map->getMappingAddr()+offset);
530 ULONG accessAttr = 0;
531 Win32MemMapView *tmpview = mapviews;
532
533 errorState = 0;
534 mParentMap = map;
535 mSize = size;
536 mOffset = offset;
537 mProcessId = GetCurrentProcess();
538
539 switch(fdwAccess) {
540 case FILE_MAP_READ:
541 accessAttr = PAG_READ;
542 mfAccess = MEMMAP_ACCESS_READ;
543 break;
544 case FILE_MAP_ALL_ACCESS:
545 case FILE_MAP_WRITE:
546 case FILE_MAP_WRITE|FILE_MAP_READ:
547 case FILE_MAP_COPY:
548 accessAttr = (PAG_READ|PAG_WRITE);
549 mfAccess = MEMMAP_ACCESS_READ | MEMMAP_ACCESS_WRITE;
550 break;
551 }
552 if(map->getMemName() != NULL && !map->getFileHandle()) {
553 //shared memory map, so map it into our address space
554 if(OSLibDosGetNamedSharedMem((LPVOID *)&viewaddr, map->getMemName()) != OSLIB_NOERROR) {
555 dprintf(("new OSLibDosGetNamedSharedMem FAILED"));
556 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
557 errorState = 1;
558 return;
559 }
560 }
561
562 //view == memory mapping for executable images (only used internally)
563 if(map->getImage()) {
564 pMapView = map->getMappingAddr();
565 }
566 else {
567 if(OSLibDosAliasMem(viewaddr, size, &pMapView, accessAttr) != OSLIB_NOERROR) {
568 dprintf(("new OSLibDosAliasMem FAILED"));
569 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
570 errorState = 1;
571 return;
572 }
573 }
574
575 dprintf(("Win32MemMapView::Win32MemMapView: created %x (alias for %x), size %d", pMapView, viewaddr, size));
576
577 globalviewMutex.enter();
578 if(tmpview == NULL || tmpview->getViewAddr() > pMapView) {
579 next = mapviews;
580 mapviews = this;
581 }
582 else {
583 while(tmpview->next) {
584 if(tmpview->next->getViewAddr() > pMapView) {
585 break;
586 }
587 tmpview = tmpview->next;
588 }
589 next = tmpview->next;
590 tmpview->next = this;
591 }
592 globalviewMutex.leave();
593}
594//******************************************************************************
595//******************************************************************************
596Win32MemMapView::~Win32MemMapView()
597{
598 if(errorState != 0)
599 return;
600
601 dprintf(("Win32MemMapView dtor: deleting view %x %x", mOffset, mSize));
602
603 if(mfAccess & MEMMAP_ACCESS_WRITE)
604 mParentMap->flushView(mOffset, mSize);
605
606 //Don't free memory for executable image map views (only used internally)
607 if(!mParentMap->getImage())
608 OSLibDosFreeMem(pMapView);
609
610 globalviewMutex.enter();
611 Win32MemMapView *view = mapviews;
612
613 if(view == this) {
614 mapviews = next;
615 }
616 else {
617 while(view->next) {
618 if(view->next == this)
619 break;
620 view = view->next;
621 }
622 if(view->next) {
623 view->next = next;
624 }
625 else dprintf(("Win32MemMapView::~Win32MemMapView: map not found!! (%x)", this));
626 }
627 globalviewMutex.leave();
628}
629//******************************************************************************
630//******************************************************************************
631void Win32MemMapView::deleteViews(Win32MemMap *map)
632{
633 globalviewMutex.enter();
634 Win32MemMapView *view = mapviews, *nextview;
635
636 if(view != NULL) {
637 while(view) {
638 nextview = view->next;
639 if(view->getParentMap() == map)
640 {
641 globalviewMutex.leave();
642 delete view;
643 globalviewMutex.enter();
644 }
645 view = nextview;
646 }
647 }
648 globalviewMutex.leave();
649}
650//******************************************************************************
651//******************************************************************************
652Win32MemMap *Win32MemMapView::findMapByView(ULONG address, ULONG *offset,
653 ULONG accessType,
654 Win32MemMapView **pView)
655{
656 globalviewMutex.enter();
657 Win32MemMapView *view = mapviews;
658
659 *offset = 0;
660
661 if(view != NULL) {
662 while(view && (ULONG)view->getViewAddr() <= address) {
663 if((ULONG)view->getViewAddr() <= address &&
664 (ULONG)view->getViewAddr() + view->getSize() > address &&
665 view->getAccessFlags() >= accessType)
666 {
667 *offset = view->getOffset() + (address - (ULONG)view->getViewAddr());
668 goto success;
669 }
670 view = view->next;
671 }
672 //failure if we get here
673 view = NULL;
674 }
675success:
676 if(view && !view->getParentMap()->isImageMap())
677 dprintf(("findMapByView %x %x -> %x off %x", address, accessType, view->getViewAddr(), *offset));
678
679 globalviewMutex.leave();
680 if(pView) *pView = view;
681 return (view) ? view->getParentMap() : NULL;
682}
683//******************************************************************************
684//******************************************************************************
685Win32MemMapView *Win32MemMapView::findView(LPVOID address)
686{
687 Win32MemMapView *view = mapviews;
688
689 if(view != NULL) {
690 while(view) {
691 if(view->getViewAddr() == address)
692 {
693 break;
694 }
695 view = view->next;
696 }
697 }
698 return view;
699}
700//******************************************************************************
701//******************************************************************************
702
Note: See TracBrowser for help on using the repository browser.