problem about memory operation

Hello everyone,

There are some problem about memory I want to ask.In my process, I defined a
queue in shared memory, and it’s read/write mode is poll. My questions is
that if read/write address of this queue is outside of the shared memory
address, what would happened?

PS:there have not other process access the memory outside.

Thank you!
Maa
2004-11-25

Maa <maa_vip@sina.com> wrote:

Hello everyone,

There are some problem about memory I want to ask.In my process, I defined a
queue in shared memory, and it’s read/write mode is poll. My questions is
that if read/write address of this queue is outside of the shared memory
address, what would happened?

I don’t think QNX supplied a memory based queueing library, so I’ll assume
you have set up the queue yourself.

If the address is outside the shared memory region, it will attempt to
write to that address within your process’s virtual addresss space. If
you’re lucky, there’ll be nothing there, and your process will crash
(SIGSEGV) immediately. If you’re unlucky, there’ll be something there,
you’ll modify (corrupt) somebody else’s data structures, and later on
when you try to use them, strange things will happen.

-David

David Gibbs
QNX Training Services
dagibbs@qnx.com

Dear David,
That’s right what your said, the queue is created by myself. I create a
shared memory object, and then mmap() it, then let my queue object pointer
equal to the return value of mmap(). And base on it, I try to use semaphore
to control it’s read and write.

Maybe I am lucky, it’s seem no problem on it, but our machine sometimes
would crash suddenly, and the run time of our machine is not certain, could
the problem lead it?

In PII cpu board or PIII cpu board,is the phenomenon of this problem
different?

Best regards!
Maa
2004-11-26

Maa <maa@vip.sina.com> wrote:

Dear David,
That’s right what your said, the queue is created by myself. I create a
shared memory object, and then mmap() it, then let my queue object pointer
equal to the return value of mmap(). And base on it, I try to use semaphore
to control it’s read and write.

Maybe I am lucky, it’s seem no problem on it, but our machine sometimes
would crash suddenly, and the run time of our machine is not certain, could
the problem lead it?

In PII cpu board or PIII cpu board,is the phenomenon of this problem
different?

I would not expect PII vs PIII to make a difference for such a problem.

-David

David Gibbs
QNX Training Services
dagibbs@qnx.com

Dear David£¬

Thank you very much, and I’ll clean this bug.

Best Regards!
Maa
2004-11-27

Maa <maa@vip.sina.com> wrote:
M > Dear David,
M > That’s right what your said, the queue is created by myself. I create a
M > shared memory object, and then mmap() it, then let my queue object pointer
M > equal to the return value of mmap(). And base on it, I try to use semaphore
M > to control it’s read and write.

M > Maybe I am lucky, it’s seem no problem on it, but our machine sometimes
M > would crash suddenly, and the run time of our machine is not certain, could
M > the problem lead it?

M > In PII cpu board or PIII cpu board,is the phenomenon of this problem
M > different?

M > Best regards!
M > Maa
M > 2004-11-26

Hi Maa

A queue usually involves things like a head and tail pointers. You aer
aware that if two seperate proceses try to map the same shared memory
into their own address space, the address that that shared memory gets
mapped into will probibly be different.

I.E.

Process A
shared memory mapped at address 0x78000

Process B
same shared memory mapped at 0xc1000

But these two addresses both refer to the same memory.
I know from experience.

The way arounf this is to not store addresses in the shared memory. Instead
you can store an OFFSET to data within the shared memory.

What I like to do is define the contents of shared memory as a typedef
struct. Then, cast the shared memory pointer as a pointer to an object of
this type, and from then on refer to memory using the cast pointer.

“Bill Caroselli” <qtps@earthlink.net> wrote in message
news:coklhm$982$2@inn.qnx.com

Maa <> maa@vip.sina.com> > wrote:
M > Dear David,
M > That’s right what your said, the queue is created by myself. I
create a
M > shared memory object, and then mmap() it, then let my queue object
pointer
M > equal to the return value of mmap(). And base on it, I try to use
semaphore
M > to control it’s read and write.

M > Maybe I am lucky, it’s seem no problem on it, but our machine
sometimes
M > would crash suddenly, and the run time of our machine is not certain,
could
M > the problem lead it?

M > In PII cpu board or PIII cpu board,is the phenomenon of this problem
M > different?

M > Best regards!
M > Maa
M > 2004-11-26

Hi Maa

A queue usually involves things like a head and tail pointers. You aer
aware that if two seperate proceses try to map the same shared memory
into their own address space, the address that that shared memory gets
mapped into will probibly be different.

I.E.

Process A
shared memory mapped at address 0x78000

Process B
same shared memory mapped at 0xc1000

But these two addresses both refer to the same memory.
I know from experience.

The way arounf this is to not store addresses in the shared memory.
Instead
you can store an OFFSET to data within the shared memory.

This works great. But what does it have to do with a queue?

Kevin Miller <kevin.miller@transcore.com> wrote:
KM > What I like to do is define the contents of shared memory as a typedef
KM > struct. Then, cast the shared memory pointer as a pointer to an object of
KM > this type, and from then on refer to memory using the cast pointer.

KM > “Bill Caroselli” <qtps@earthlink.net> wrote in message
KM > news:coklhm$982$2@inn.qnx.com

Maa <> maa@vip.sina.com> > wrote:
M > Dear David,
M > That’s right what your said, the queue is created by myself. I
create a
M > shared memory object, and then mmap() it, then let my queue object
pointer
M > equal to the return value of mmap(). And base on it, I try to use
semaphore
M > to control it’s read and write.

M > Maybe I am lucky, it’s seem no problem on it, but our machine
sometimes
M > would crash suddenly, and the run time of our machine is not certain,
could
M > the problem lead it?

M > In PII cpu board or PIII cpu board,is the phenomenon of this problem
M > different?

M > Best regards!
M > Maa
M > 2004-11-26

Hi Maa

A queue usually involves things like a head and tail pointers. You aer
aware that if two seperate proceses try to map the same shared memory
into their own address space, the address that that shared memory gets
mapped into will probibly be different.

I.E.

Process A
shared memory mapped at address 0x78000

Process B
same shared memory mapped at 0xc1000

But these two addresses both refer to the same memory.
I know from experience.

The way arounf this is to not store addresses in the shared memory.
Instead
you can store an OFFSET to data within the shared memory.


Bill Caroselli – Q-TPS Consulting
qtps@earthlink.net