linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* shared mapping of /dev/zero
@ 2002-11-08 12:24 Denis Zaitsev
  2002-11-08 17:54 ` Glynn Clements
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Zaitsev @ 2002-11-08 12:24 UTC (permalink / raw)
  To: linux-c-programming

I'm trying to do something like the anonymous mapping of the same
memory region thru a different virtual addresses.  I.e.:

    char *a, *b;
    int z= open("/dev/zero", O_RDWR);
    a= mmap(NULL, 0x2000, PROT_READ|PROT_WRITE, MAP_SHARED, z,0);
    b= mmap(a+0x1000, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, z,0);

And what I have as the result, are two mapping as if they was created
with MAP_ANONYMOUS flag, so they do not share the same space (of file
desc z, at offset 0), as required.  So, mapping of /dev/zero is just
the synonum for the anonymous mapping...  Is this the correct
behaviour, and if so, what is the way to do the trick?

Thanks in advance...

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: shared mapping of /dev/zero
  2002-11-08 12:24 shared mapping of /dev/zero Denis Zaitsev
@ 2002-11-08 17:54 ` Glynn Clements
  0 siblings, 0 replies; 2+ messages in thread
From: Glynn Clements @ 2002-11-08 17:54 UTC (permalink / raw)
  To: Denis Zaitsev; +Cc: linux-c-programming


Denis Zaitsev wrote:

> I'm trying to do something like the anonymous mapping of the same
> memory region thru a different virtual addresses.  I.e.:
> 
>     char *a, *b;
>     int z= open("/dev/zero", O_RDWR);
>     a= mmap(NULL, 0x2000, PROT_READ|PROT_WRITE, MAP_SHARED, z,0);
>     b= mmap(a+0x1000, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, z,0);
> 
> And what I have as the result, are two mapping as if they was created
> with MAP_ANONYMOUS flag, so they do not share the same space (of file
> desc z, at offset 0), as required.  So, mapping of /dev/zero is just
> the synonum for the anonymous mapping...  Is this the correct
> behaviour, and if so, what is the way to do the trick?

AFAICT, this trick is a BSD-ism; it doesn't work on Linux. If you want
shared memory, you have to use the SysV IPC approach, i.e. shmget(),
shmat() etc.

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-11-08 17:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-08 12:24 shared mapping of /dev/zero Denis Zaitsev
2002-11-08 17:54 ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).