shmat() ... is it a bug?

From: Umut Aymakoglu <umuta_at_us.ibm.com>
Date: 2003-08-29 10:04:10
Hi -
 Below ,I have 2 small programs which shows a problem in shmat() when the
executable linked with the curses library(libncurses). Has anybody seen
something like this?

a.c --> allocates a shared memory segment and attaches.
b.c --> attaching the allocated shared memory segment using the address
from a.c

thanks,
Umut


a.c:
-----
#include <stdio.h>
#include <sys/types.h>
#include <sys/shm.h>

main()
{

unsigned int segsize = 512*1024;
int                     shmid;
key_t               shmkey = 123456789;
void * adr;

shmid = shmget(shmkey, segsize,IPC_CREAT|0660);
adr = shmat(shmid, 0,0);

printf("shmid = %d  adr = %p\n",shmid, adr);
}


b.c:
-----
#include <stdio.h>
#include <stdlib.h>
#include<sys/types.h>
#include <sys/shm.h>

main(int argc, char **argv)
{
 void * addr1, * addr2;
key_t  shmkey = 123456789;
int shmid;

addr1 = (void*) strtoul(argv[1],NULL,0);
shmid = shmget(shmkey, 0, 0660);

addr2 = shmat(shmid, addr1, 0);
printf("addr2 = %p\n",addr2);
}

%gcc3 -o a a.c
%gcc3 -o b b.c
%gcc3 -o c b.c -lncurses

% ./a
shmid = 313556996 adr = 0x2000000000300000

%./b 0x2000000000300000
addr2 = 0x2000000000300000

%./c 0x2000000000300000
addr2 = 0xffffffffffffffff


-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Thu Aug 28 20:27:34 2003

This archive was generated by hypermail 2.1.8 : 2005-08-02 09:20:17 EST