Are pointers in a shared memory segment valid for a different process?

Todd Kelley kelley at qucis.queensu.CA
Thu Aug 23 06:17:00 AEST 1990


This question is closely related to my previous question about IPC
using shared memory (comp.unix.questions).

Suppose that process A and process B both have one particular shared
memory segment attached to their respective address spaces with shmat().

Now suppose that process A puts an array of strings into the shared memory
segment, such that each string resides in the shared memory segment, but
they do not occupy a contiguous piece of memory.  That array will be
meaningless to process B, because the (char *) pointers in the array
point into A's address space, and not B's address space.  If the base of
the shared memory segment is at AAA0 in A's address space, and at
BBB0 in B's address space (for example), in order for
B to access the strings in the array, B would need to add (AAA0-BBB0) to
each of the pointers in the array to make them point at the strings in
B's address space.

Is this wrong?   If not, is there an accepted way to map addresses back
and forth between address spaces?  For instance, should each string's
offset from the base of the segment be stored in the array, rather
than the actual pointer?

If this *is* wrong, please let me know.

Respond by email, and if there seems to be enough interest in this
question, I'll post a summary.
-- 

Todd Kelley  (kelley at qucis.queensu.ca)



More information about the Comp.unix.wizards mailing list