🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Shared memory question

#16424
From: Vladimir Afanasyev
Date: Thu, 15 May 2003 17:30
71 lines
4169 bytes
My sample is only sample to explain my point of view.
It is not suitable to write code for both processes here 
so may be my sample is not very succesful.

"Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> wrote:
>
>Well, of course.  But the whole point of sharing memory that is the other
>processes know about it, thus they will know the name of the mapping and can
>use Create/OpenFileMapping to get at it.  However, that is not the issue
>being discussed.  

Of course (not discussed) but main point of sharing memory is 
sharing memory. If processes cooperate in their work it is not 
very important how they will do it. It is not obligatery to 
know name if they really need in right handle to define virtual 
address.

>The original question was how to restrict access to
>read-only for other processes who do want to use the shared memory.  In that
>regard, the answer is as stated earlier - the process who initially creates
>the memory can't control that aspect of the memory, as each process
>obtaining a pointer to the memory can specify their own individual settings
>for how they want to access the memory.  Each process is only responsible
>for its own local pointers to the memory, to to other process's pointers.

It is just the question is it process that create mapping 
restricts access for another processes.


>
>> 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.
>
>That can only work if you are actually passing the duplicated handle to the
>other process directly, which I get the feeling is not the actual case in
>MWP's situation, but that the other processes are accessing his mapped
>memory directly.  


I told upper - it's only sample.
Really DuplicateHandle should be called from another process.
It only must know ProcessId of source process (that is create 
handle) and value of source handle:
"DuplicateHandle can be called by either the source process
or the target process."
"If the process that calls DuplicateHandle is not the 
target process, the duplicating process must use 
interprocess communication to pass the value of the 
duplicate handle to the target process."

>DuplicateHandle() does not copy the new handle to other
>processes, and certainly is not doing so in your examples.  

As I said before this operation should do another process.

>To do that, the
>other process would have to not be allowed to know the memory's mapped name
>(aka, make it random), and the other process would have to know the process
>handle of the memory's initial owner as well as the numeric value of the
>original read-only handle inside that process.  That last step is not one
>you have shown yet in your examples, as the other process has to make the
>call to DuplicateHandle() passing it the original process's information.

So for another process no need to call OpenFileMapping if 
it know ProcessId of source process and value of handle 
(the handle with RESTRICTION for writing).

Vladimir.
Technical Details
Message-ID: <3ec3ceac$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.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> <3ec37cee$1@newsgroups.borland.com> <3ec3c804$3@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 10:40:37 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> <3ec37cee$1@newsgroups.borland.com> <3ec3c804$3@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3ec3ceac$1@newsgroups.borland.com>
Date: 15 May 2003 10:30:20 -0700
X-Trace: newsgroups.borland.com 1053019820 207.105.83.65 (15 May 2003 10:30:20 -0700)
Lines: 71
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!newsfeed.news2me.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail