[prev in list] [next in list] [prev in thread] [next in thread]
List: wine-devel
Subject: Re: init memory in VirtualAlloc
From: gerard patel <g.patel () wanadoo ! fr>
Date: 1999-09-26 10:27:05
[Download RAW message or body]
At 11:40 AM 9/25/99 +0200, you wrote:
>No, it's the normal way. The first time the memory is allocated we use
>an anonymous map so the memory is cleared; this already works
>today. Now if we need to clear it again once it has been committed, it
>should be done by unmapping the range and mapping anonymous pages
>again, exactly in the same way as for the initial allocation.
>
Thanks for the explanation, I understand now
what was the real problem.
ChangeLog:
* memory/virtual.c
initialize memory in VirtualAlloc
["virt4.dif" (text/plain)]
Index: memory/virtual.c
===================================================================
RCS file: /home/wine/wine/memory/virtual.c,v
retrieving revision 1.26
diff -u -r1.26 virtual.c
--- memory/virtual.c 1999/07/10 13:16:30 1.26
+++ memory/virtual.c 1999/09/26 09:16:41
@@ -522,6 +522,80 @@
/***********************************************************************
+ * VIRTUAL_DoSetProtCommitted
+ */
+BOOL VIRTUAL_DoSetProtCommitted(
+ FILE_VIEW *view,
+ UINT begin,
+ UINT count,
+ BYTE vprot,
+ BYTE oldprot)
+{
+ UINT ptr, newptr;
+ DWORD size = count << page_shift;
+ ptr = (view->base + (begin << page_shift));
+ if (!oldprot)
+ { /* area just committed, clear it again */
+ if (FILE_munmap( (void *)(ptr), 0, size )==-1)
+ {
+ ERR("can't unmap=%d\n", errno);
+ SetLastError( ERROR_INVALID_ADDRESS );
+ return FALSE;
+ }
+ newptr = (UINT)FILE_dommap( -1, (LPVOID)ptr, 0, size, 0, 0,
+ VIRTUAL_GetUnixProt( vprot ), MAP_PRIVATE );
+ if (newptr == (UINT)-1)
+ {
+ SetLastError( ERROR_OUTOFMEMORY );
+ return FALSE;
+ }
+ if (ptr != newptr)
+ {
+ ERR("can't get back same address\n");
+ FILE_munmap( (void *)ptr, 0, size );
+ SetLastError( ERROR_INVALID_ADDRESS );
+ return FALSE;
+ }
+ }
+ if (!VIRTUAL_SetProt( view, ptr, size, vprot)) return FALSE;
+ return TRUE;
+}
+
+/***********************************************************************
+ * VIRTUAL_SetProtCommitted
+ * protect committed memory, initializing if necessary
+ */
+LPVOID VIRTUAL_SetProtCommitted(
+ FILE_VIEW *view,
+ UINT base,
+ DWORD size,
+ BYTE vprot)
+{
+ BYTE oldprot;
+ UINT i, count, deb, begin;
+
+ deb = (base - view->base) >> page_shift;
+ oldprot = view->prot[deb] & VPROT_COMMITTED;
+ begin = deb;
+ /* for all pages */
+ for (count = 0, i = deb; i < deb + (size >> page_shift); i++, count++)
+ {
+ if ((view->prot[i] & VPROT_COMMITTED) != oldprot)
+ {
+ if (!VIRTUAL_DoSetProtCommitted(view, begin, count, vprot, oldprot))
+ return NULL;
+ count = 0;
+ oldprot = view->prot[i];
+ begin = i;
+ }
+
+ }
+ if (!VIRTUAL_DoSetProtCommitted(view, begin, count, vprot, oldprot))
+ return NULL;
+ return (LPVOID) base;
+}
+
+/***********************************************************************
* VirtualAlloc (KERNEL32.548)
* Reserves or commits a region of pages in virtual address space
*
@@ -639,9 +713,12 @@
SetLastError( ERROR_INVALID_PARAMETER );
return NULL;
}
-
- if (!VIRTUAL_SetProt( view, base, size, vprot )) return NULL;
- return (LPVOID)base;
+ if (!(vprot & VPROT_COMMITTED) || (protect & MEM_RESET))
+ {
+ if (!VIRTUAL_SetProt( view, base, size, vprot )) return NULL;
+ else return (void *) base;
+ }
+ else return VIRTUAL_SetProtCommitted(view, base, size, vprot);
}
=========================================================================
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic