Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VirtualProtect() in Memory Mapped Files

308 views
Skip to first unread message

Cesar Fraile

unread,
Feb 1, 2000, 3:00:00 AM2/1/00
to
hello all:

I´m trying to develop a persistence system for C++. I´m using my own heap
based on memory mapped files. I have discover great differences here betwen
WindowsNT and 95, and as I currently use 95 I´m focusing on it.
For managing transactions I protect the view of the file with readonly
access. When the program tries to access a protected area an access
violation exception ocurs. This exception is cached by a little debugger
attached to the process, that acts as a transaction server. The debugger
copies the protected data to a backup file, and changes the protection
attributes of the area. Then it lets the application to continue execution.
If an error ocurs before the transaction has finished the data is restored
from the backup file ensuring consistency of data in case of system
failure.
The unit of protection I´m currently using is the allocation granularity
(64k). This is the granularity used by MapViewOfFile(), wich I use to
change the protection of blocks. I have discover that Win95 allows to use
this function for this purpose. I can map first the entire file with
FILE_MAP_READ access and later change the protection of a 64k block on it
using MapViewOfFile() with the new protection over this block leaving the
rest of the file the same.

The problem with this schema is that 64k is a poor granularity and imposes
a great overhead for small transactions. Then I ask me if it would be
possible to change the protection of individual pages of memory mapped
files with VirtualProtect(). I tried it and I found that when I changes the
protection of a read-write area of the file to PAGE_READONLY the this
works, but later when I try to get it PAGE_READWRITE the function fails
giving error code 87 (ERROR_INVALID_PARAMETER).

are there a way to solve this?
does it works in WindowsNT?
are there any other way to use page protection in MMFs in 95 or NT?

thanks in advance,
and sorry for bad english (and bad and large explanation of the question)

César Fraile
ce...@NOSPAMusuarios.retecal.es


Cesar Fraile

unread,
Feb 3, 2000, 3:00:00 AM2/3/00
to
I haven´t think yet about multithreading, but the problem is if there is a
simpler way of protect memory areas and handle access violation exceptions,
allowing exception continuation. The unique posible way in Win32 seems to
be using a proccess as a debugger, are there any other way?
Then, if using memory mapped files or VirtualAlloc and MemCopy, can be a
question of taste. The problem with the later is that the allocate and copy
scheme leads to duplication of data ( better triplication ): one copy in
the store file, another in swap file (virtual memory) and a third in backup
file for secure transactions in the store. By using MMFs one can avoid the
copy in the swap file.

César

Andy Lutomirski <Lu...@mailandnews.nospam.com> escribió en artículo
<6n7m4.29009$eC2.2...@news1.alsv1.occa.home.com>...
> This sounds very excessive and not thread- (let alone process-) safe.
>
> Andy
>
> "Cesar Fraile" <ce...@NOSPAM.usuarios.retecal.es> wrote in message
> news:01bf6cb3$42b3f920$9d3216d4@k6-2-350...

0 new messages