Sharing Memory Between Processes

Hi everyone
I am trying to write (something like) a QNX4 device driver for an ATM
adapter.The NIC is installed on the PCI,and is memory mapped.For this
puprpose,I want to write to two different processes which are supposed
to cooperate as follows:the first (A) allocates a number of equal size
memory regions.Before this process terminates,it stores the pointers to
these allocated memory objects in a file,in shared memory (with
succesive calls to shm_open,mmap,ltrunc functions) so that the second
process (B) , can access them.A then terminates,with an exec call,but
the process which is afterwards loaded with this call is not B.When
later,process B is loaded it is supposed to retrieve the pointers to the
previously allocated buffers stored in the shared memory file as
mentioned before.My questions are:
a)Given that process A (responsible for allocating the memory objects
and storing the respective pointers in shared memory) will have
terminated when process B begins,will the memory remain allocated?
b)If the answer to the previous question is yes,will the stored pointers
be valid for process B to use?Will I accomplish that just by passing the
pointers returned by the calloc function?
c)Are the answers to the above two questions somehow related to the
memory model (small,large,flat etc) used by QNX4?
4)Since I am a rookie in develloping this kind of software,and I know
very few things about memory models I would aprreciate if you suggested
to me recomended web sites with tutorials on memory models and related
programming techniques
(I use Watcom C compiler,version 10.6)
Thank you very much!!!
I would really appreciate any kind of help

“Akis” <romeoita@yahoo.com> wrote in message
news:3ADE32E8.6BE8123A@yahoo.com

Hi everyone

I am trying to write (something like) a QNX4 device driver for an ATM
adapter.The NIC is installed on the PCI,and is memory mapped.For this
puprpose,I want to write to two different processes which are supposed
to cooperate as follows:the first (A) allocates a number of equal size
memory regions.Before this process terminates,it stores the pointers to
these allocated memory objects in a file,in shared memory (with
succesive calls to shm_open,mmap,ltrunc functions) so that the second
process (B) , can access them.A then terminates,with an exec call,but
the process which is afterwards loaded with this call is not B.When
later,process B is loaded it is supposed to retrieve the pointers to the
previously allocated buffers stored in the shared memory file as
mentioned before.My questions are:

I’m having a hard time following this :wink: Why would a process
need to run only to allocated some buffer and then die.

a)Given that process A (responsible for allocating the memory objects
and storing the respective pointers in shared memory) will have
terminated when process B begins,will the memory remain allocated?

No it won’t. Unless it’s a shared memory.

Each process runs in virtual address space. Pointers cannot be passed
from process to process.

b)If the answer to the previous question is yes,will the stored pointers
be valid for process B to use? Will I accomplish that just by passing the
pointers returned by the calloc function?

c)Are the answers to the above two questions somehow related to the
memory model (small,large,flat etc) used by QNX4?

Absolutely note. In a nut shell you can forget all about memory model.
QNX4 is a 32 bit OS. There is no need to bang your head against
the wall dealing with memory model.

4)Since I am a rookie in develloping this kind of software,and I know
very few things about memory models I would aprreciate if you suggested
to me recomended web sites with tutorials on memory models and related
programming techniques

I don’t know of such a site. Memory models specify out the memory
is segmented and such affect how pointer are represented and how they work.
In QNX4 when building a 32 bit applications there are three modes available
small, large and flat. Small means all pointers are 32 bits and each
segment
(DS, CS, SS ) are independendant, with flat, it means all segments are set
the same DS:0000 = CS:0000 = SS:0000. Large modem means pointer
are 48 bit (32 bit offset 16 big segment) I have never heard of anyone
using
this :wink:

Sharing of data between processes is done with shared memory and at
not point can pointers be share across process since they are only
meaningfull to the owner. All addresses are virtual.

You should read some of QNX4 documentation on share memory.
Check out /etc/readme/technotes/shmem.txt (not 100% sure of the path).

Still I don’t see why you need two processes?

Oh and by the way you posted the same message 7 times :wink:

(I use Watcom C compiler,version 10.6)
Thank you very much!!!
I would really appreciate any kind of help

Mario Charest <mcharest@deletezinformatic.com> wrote:


I don’t know of such a site. Memory models specify out the memory
is segmented and such affect how pointer are represented and how they work.
In QNX4 when building a 32 bit applications there are three modes available
small, large and flat. Small means all pointers are 32 bits and each
segment
(DS, CS, SS ) are independendant, with flat, it means all segments are set
the same DS:0000 = CS:0000 = SS:0000. Large modem means pointer
are 48 bit (32 bit offset 16 big segment) I have never heard of anyone
using
this > :wink:

While the compiler will allow you to compile 32-bit large objects,
there are no libraries available for that model, so you won’t be
able to ever link or run a program compiled in that model.

Sharing of data between processes is done with shared memory and at
not point can pointers be share across process since they are only
meaningfull to the owner. All addresses are virtual.

If you are using “pointers” in a shared memory area (i.e. for linked
lists) they should be “based” pointers, that is, they should be stored
as an offset from the base of the shared memory, rather than as a “true”
pointer, as the shared memory may get mapped in at different virtual
addresses in your different programs that are using it.

You should read some of QNX4 documentation on share memory.
Check out /etc/readme/technotes/shmem.txt (not 100% sure of the path).

Yup, that’s the right path.

-David

QNX Training Services
dagibbs@qnx.com

Would it be possible for you to simply mmap in the registers from your PCI
device and update them via pointers? That’s what I am doing for a user mode
driver that I have written for my companies PCI shared memory device…

Chris Fought

Akis <romeoita@yahoo.com> wrote in message
news:3ADE32E8.6BE8123A@yahoo.com

Hi everyone
I am trying to write (something like) a QNX4 device driver for an ATM
adapter.The NIC is installed on the PCI,and is memory mapped.For this
puprpose,I want to write to two different processes which are supposed
to cooperate as follows:the first (A) allocates a number of equal size
memory regions.Before this process terminates,it stores the pointers to
these allocated memory objects in a file,in shared memory (with
succesive calls to shm_open,mmap,ltrunc functions) so that the second
process (B) , can access them.A then terminates,with an exec call,but
the process which is afterwards loaded with this call is not B.When
later,process B is loaded it is supposed to retrieve the pointers to the
previously allocated buffers stored in the shared memory file as
mentioned before.My questions are:
a)Given that process A (responsible for allocating the memory objects
and storing the respective pointers in shared memory) will have
terminated when process B begins,will the memory remain allocated?
b)If the answer to the previous question is yes,will the stored pointers
be valid for process B to use?Will I accomplish that just by passing the
pointers returned by the calloc function?
c)Are the answers to the above two questions somehow related to the
memory model (small,large,flat etc) used by QNX4?
4)Since I am a rookie in develloping this kind of software,and I know
very few things about memory models I would aprreciate if you suggested
to me recomended web sites with tutorials on memory models and related
programming techniques
(I use Watcom C compiler,version 10.6)
Thank you very much!!!
I would really appreciate any kind of help

Mario Charest wrote in message <9blfrh$svs$1@inn.qnx.com>…

“Akis” <> romeoita@yahoo.com> > wrote in message
news:> 3ADE32E8.6BE8123A@yahoo.com> …
Hi everyone

I am trying to write (something like) a QNX4 device driver for an ATM
adapter.The NIC is installed on the PCI,and is memory mapped.For this
puprpose,I want to write to two different processes which are supposed
to cooperate as follows:the first (A) allocates a number of equal size
memory regions.Before this process terminates,it stores the pointers to
these allocated memory objects in a file,in shared memory (with
succesive calls to shm_open,mmap,ltrunc functions) so that the second
process (B) , can access them.A then terminates,with an exec call,but
the process which is afterwards loaded with this call is not B.When
later,process B is loaded it is supposed to retrieve the pointers to the
previously allocated buffers stored in the shared memory file as
mentioned before.My questions are:

I’m having a hard time following this > :wink: > Why would a process
need to run only to allocated some buffer and then die.

a)Given that process A (responsible for allocating the memory objects
and storing the respective pointers in shared memory) will have
terminated when process B begins,will the memory remain allocated?

No it won’t. Unless it’s a shared memory.

Each process runs in virtual address space. Pointers cannot be passed
from process to process.

b)If the answer to the previous question is yes,will the stored pointers
be valid for process B to use? Will I accomplish that just by passing the
pointers returned by the calloc function?

c)Are the answers to the above two questions somehow related to the
memory model (small,large,flat etc) used by QNX4?

Absolutely note. In a nut shell you can forget all about memory model.
QNX4 is a 32 bit OS. There is no need to bang your head against
the wall dealing with memory model.

4)Since I am a rookie in develloping this kind of software,and I know
very few things about memory models I would aprreciate if you suggested
to me recomended web sites with tutorials on memory models and related
programming techniques

I don’t know of such a site. Memory models specify out the memory
is segmented and such affect how pointer are represented and how they work.
In QNX4 when building a 32 bit applications there are three modes available
small, large and flat. Small means all pointers are 32 bits and each
segment
(DS, CS, SS ) are independendant, with flat, it means all segments are set
the same DS:0000 = CS:0000 = SS:0000. Large modem means pointer
are 48 bit (32 bit offset 16 big segment) I have never heard of anyone
using
this > :wink:

Sharing of data between processes is done with shared memory and at
not point can pointers be share across process since they are only
meaningfull to the owner. All addresses are virtual.

The NIC I 'm writing the device driver for,needs equal sized memory

regions(buffers).The driver is intended to allocate these buffers and then
provide the NIC with their PHYSICAL adresses.Is the only way of dealing with
physical adresses to use the qnx_segment_alloc_flags() function with the
_PMF_DMA_SAFE flag set?Unless I am wrong,the adress (at this case) returned
in the respective structure ( I dont recall it’s name , I believe it’s
something like qnx_segment_info) is the physical adress of the allocated
region and not the virtual.
If that is the only way of dealing with physical adresses,what happens if I
want to allocate a memory region larger than 64K?Do I have to use the
qnx_segment_huge() function?And even if I do that,how can I make sure that
the region allocated will be physically contygious and not composed by
disjoint segments?
Are things getting a little complicated or is it just me??? :slight_smile:

You should read some of QNX4 documentation on share memory.
Check out /etc/readme/technotes/shmem.txt (not 100% sure of the path).

Still I don’t see why you need two processes?

Oh and by the way you posted the same message 7 times > :wink:
(Really sorry about that)

(I use Watcom C compiler,version 10.6)
Thank you very much!!!
I would really appreciate any kind of help

Akis <romeoita@yahoo.com> wrote:

The NIC I 'm writing the device driver for,needs equal sized memory
regions(buffers).The driver is intended to allocate these buffers and then
provide the NIC with their PHYSICAL adresses.Is the only way of dealing with
physical adresses to use the qnx_segment_alloc_flags() function with the
_PMF_DMA_SAFE flag set?

Also you want the _PMF_DMA_HIGH flag.

Unless I am wrong,the adress (at this case) returned
in the respective structure ( I dont recall it’s name , I believe it’s
something like qnx_segment_info) is the physical adress of the allocated
region and not the virtual.
If that is the only way of dealing with physical adresses,what happens if I
want to allocate a memory region larger than 64K?

Use the above function – remember you are working with 32-bit segments,
so any segment can (theoretically) be up to 4G in size.

-David

QNX Training Services
dagibbs@qnx.com