🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #16407

Re: Shared memory question

#16407
From: Vladimir Afanasyev
Date: Thu, 15 May 2003 11:41
47 lines
2848 bytes
"Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> wrote:
>
>"MWP" <mwp@overclockers.com.au> wrote in message
>news:3ec201ad$1@newsgroups.borland.com...
>
>> Is there a way to share the memory, but to make
>> it read-only to other processes?
>
>The other processes would have to explitically specify PAGE_READONLY and
>FILE_MAP_READ instead of PAGE_READWRITE and FILE_MAP_ALL_ACCESS.  Although
>the underlying memory block is being shared, each process creates its own
>unique acces to it.  You have no control over the other processes (unless
>you're writting them yourself).  You can only control your own process.

No.
It can be so if name of the file-mapping object is known for 
all processes that want to use it.
But process can create file mapping with name that is 
defines via random generator. In this case another process 
can't connect to file mapping via OpenFileMapping 
because name is unknown.


HANDLE newHandle;
HANDLE SharedAll = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 1000, "$Monitor-Data$");
//open the same mapping with another access
HANDLE SharedMemRead=OpenFileMapping(FILE_MAP_READ,TRUE,"$Monitor-Data$");

DWORD Shared2 = (DWORD)MapViewOfFile(SharedAll, FILE_MAP_ALL_ACCESS, 0, 0, 1000);


//key point READ-ONLY handle can be pass to this or another 
//process
bool abc=DuplicateHandle(GetCurrentProcess(),(HANDLE)SharedMemRead,GetCurrentProcess(),&newHandle, 0,FALSE,DUPLICATE_SAME_ACCESS);

//possible
DWORD SharedRead = (DWORD)MapViewOfFile(newHandle, FILE_MAP_READ, 0, 0, 1000);
//impossible:
DWORD SharedALL = (DWORD)MapViewOfFile(newHandle, FILE_MAP_ALL_ACCESS, 0, 0, 1000);

If to return to question:
>> Is there a way to share the memory, but to make
>> it read-only to other processes?
The answer is yes and DuplicateHandle just for it.

Vladimir.
Technical Details
Message-ID: <3ec37cee$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3ec201ad$1@newsgroups.borland.com> <3ec2709a@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,e0ac8188bda6f9e
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-05-15 04:47:38 PST
From: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Sender: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Reply-To: "Vladimir Afanasyev" <avv@systema.kiev.ua>
Subject: Re: Shared memory question
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 62.244.14.114 62.244.14.114    
X-Forwarded-For: 192.168.0.147
References: <3ec201ad$1@newsgroups.borland.com> <3ec2709a@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3ec37cee$1@newsgroups.borland.com>
Date: 15 May 2003 04:41:34 -0700
X-Trace: newsgroups.borland.com 1052998894 207.105.83.65 (15 May 2003 04:41:34 -0700)
Lines: 47
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail