sharing contiguous memory

Hello,

I’m using mmap with MAP_PHYS | MAP_ANON flags and NOFD as file
descriptor to allocate a contiguous block of memory for PCI DMA.

addr = mmap(0, size, PROT_READ|PROT_WRITE|PROT_NOCACHE,
MAP_PHYS|MAP_ANON, NOFD, 0);

Is there a way to share this block of memory with another process ?
The doc. seems to say that if I used the MAP_SHARED flag instead of
MAP_ANON the memory would not be contiguous.

Or is there another way to allocate a contiguous block of memory that
can be share with other processes ?

Thanks


Frederic

Use open a shared memory region with shm_open() and then use
shm_ctl(SHMCTL_PHYS) to map it over your physical memory.

Look at the example under shm_ctl() in the docs - it is very similar to
what you want except in your case you would use mem_offset(NO_FD) to get the
physical address of the region you created with mmap(), rather than knowing
it up front.

Rob Rutherford


“Frederic Villeneuve” <fred@nospam.ueidaq.com> wrote in message
news:atu3rd$3l8$1@inn.qnx.com

Hello,

I’m using mmap with MAP_PHYS | MAP_ANON flags and NOFD as file
descriptor to allocate a contiguous block of memory for PCI DMA.

addr = mmap(0, size, PROT_READ|PROT_WRITE|PROT_NOCACHE,
MAP_PHYS|MAP_ANON, NOFD, 0);

Is there a way to share this block of memory with another process ?
The doc. seems to say that if I used the MAP_SHARED flag instead of
MAP_ANON the memory would not be contiguous.

Or is there another way to allocate a contiguous block of memory that
can be share with other processes ?

Thanks


Frederic

Robert Rutherford <ruzz@nospamplease.ruzz.com> wrote:

Use open a shared memory region with shm_open() and then use
shm_ctl(SHMCTL_PHYS) to map it over your physical memory.

Look at the example under shm_ctl() in the docs - it is very similar to
what you want except in your case you would use mem_offset(NO_FD) to get the
physical address of the region you created with mmap(), rather than knowing
it up front.

That works.

Or… get the physical address, then pass the physical address and
offset to another process and the other process can then mmap()
to get access to it, as if it were mapping any other physical address.

-David

QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.