Skip to contentSkip to conversation

shmat problem

DISCUSSION Alex Riesen 2 participants 5 messages Jan 6, 2003

lore
Share & tools
lore
#0 lore raw
Quoted 7 lines

Doug, thanks for the reply. I've set SHM_RND in the call and used "__attribute__ ((aligned(4096)))" during the the declaration of variable global01_
(as shown below) such that it is aligned on a page boundary. I'm porting code that was
written for a Unix system to Linux and the example shown below is how the code is implemented on Unix.

on which exactly?

Quoted 9 lines

The example included executed correctly on:
mandrake - ? (Can't remember, but it was an old version)

but fails to work on:
redhat - 2.2.14-5.0
debian - 2.2.9
mandrake - 2.4.19-16mdk

We are currently working on mandrake - kernel 2.4.19-16mdk.

You have to add SHM_REMAP to shmat flags (see definitions of SHM_ flags).

Quoted 4 lines
	if ( (shmptr = shmat(shmid, &global01_, SHM_RND)) == (void *) -1)
		printf("shmat error: %d %s\n",errno, strerror(errno));
	else

add SHM_REMAP.

-alex

#1 lore raw
Quoted 1 line · Alex Riesen

You have to add SHM_REMAP to shmat flags (see definitions of SHM_ flags).

Hmm, the manpage (on RH7.3 at least) doesn't mention SHM_REMAP. Nice to know about it.

-Doug

#2 lore raw

Doug McNaught, Mon, Jan 06, 2003 17:36:39 +0100:

Quoted 3 lines
Quoted 1 line

You have to add SHM_REMAP to shmat flags (see definitions of SHM_ flags).

Hmm, the manpage (on RH7.3 at least) doesn't mention SHM_REMAP. Nice to know about it.

RH7.3 manpage is quiet old, btw.

Linux manpages-1.54 (Dec 30 2002):

The (Linux-specific) SHM_REMAP flag may be asserted in shmflg to indi- cate that the mapping of the segment should replace any existing map- ping in the range starting at shmaddr and continuing for the size of the segment. (Normally an EINVAL error would result if a mapping already exists in this address range.) In this case, shmaddr must not be NULL.

-alex

#3 lore raw
Quoted 6 lines · Alex Riesen

Doug McNaught, Mon, Jan 06, 2003 17:36:39 +0100:

Quoted 3 lines
Quoted 1 line

You have to add SHM_REMAP to shmat flags (see definitions of SHM_ flags).

Hmm, the manpage (on RH7.3 at least) doesn't mention SHM_REMAP. Nice to know about it.

RH7.3 manpage is quiet old, btw.

Apparently so.

Quoted 8 lines

Linux manpages-1.54 (Dec 30 2002):

The (Linux-specific) SHM_REMAP flag may be asserted in shmflg to indi- cate that the mapping of the segment should replace any existing map- ping in the range starting at shmaddr and continuing for the size of the segment. (Normally an EINVAL error would result if a mapping already exists in this address range.) In this case, shmaddr must not be NULL.

Wouldn't the OP's code still (potentially) have problems? What if you had:

char my_shared_area[2048];
int my_unshared_var;

...

   void *foo = shmat(id, &my_shared_area, SHM_REMAP);

Would my_unshared_var end up shared, since memory mappings have page granularity?

-Doug

#4 lore raw

Doug McNaught, Mon, Jan 06, 2003 17:50:24 +0100:

Quoted 12 lines
Quoted 8 lines

Linux manpages-1.54 (Dec 30 2002):

The (Linux-specific) SHM_REMAP flag may be asserted in shmflg to indi- cate that the mapping of the segment should replace any existing map- ping in the range starting at shmaddr and continuing for the size of the segment. (Normally an EINVAL error would result if a mapping already exists in this address range.) In this case, shmaddr must not be NULL.

Wouldn't the OP's code still (potentially) have problems? What if you had:

Quoted 8 lines

char my_shared_area[2048];
int my_unshared_var;

   void *foo = shmat(id, &my_shared_area, SHM_REMAP);

Would my_unshared_var end up shared, since memory mappings have page granularity?

yes, i suppose so.
Maybe that was the reason making SHM_REMAP non-default behaviour for shmat.

-alex