shmat problem
Quoted 7 lines
Doug, thanks for the reply. I've set
SHM_RNDin the call and used "__attribute__((aligned(4096)))" during the the declaration of variableglobal01_
(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-16mdkWe 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));
elseadd SHM_REMAP.
-alex
Quoted 1 line · Alex Riesen
You have to add
SHM_REMAPto shmat flags (see definitions ofSHM_flags).
Hmm, the manpage (on RH7.3 at least) doesn't mention SHM_REMAP. Nice to know about it.
-Doug
Doug McNaught, Mon, Jan 06, 2003 17:36:39 +0100:
Quoted 3 lines
Quoted 1 line
You have to add
SHM_REMAPto shmat flags (see definitions ofSHM_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
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_REMAPto shmat flags (see definitions ofSHM_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_REMAPflag 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
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_REMAPflag 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];
intmy_unshared_var;void *foo = shmat(id, &my_shared_area, SHM_REMAP);Would
my_unshared_varend 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