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

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

Implemented SEC_COMMIT flag for memory maps

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