Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!cernvax!rdm From: rdm@cernapo (Alphonse Rademakers) Newsgroups: comp.sys.hp Subject: Problem using shared memory on a HP 9000/720... Message-ID: Date: 24 Apr 91 12:58:22 GMT Sender: news@cernvax.cern.ch Distribution: comp Organization: none Lines: 185 Hi, I have a problem using shared memory (shm calls) on the HP 9000/720. I've made a little program that creates a shared memory segment and accesses it via an offset from a base array (in Fortran). The offset from the base array was returned by the routine that created the shared memory segment (in C). The creation of the shared memory seems to be fine. Ipcs shows that it has been created with the right protections. I can write nicely into the shared memory segment, but as soon as I try to access it I get a 'memory fault'. Could somebody (HP?) maybe solve this problem? Attached is a small shar file containing the sample programs. Unpack and run make_server and execute server. Commenting out the line K = IAAP(IOFFST+I) in server.f makes the program run fine. This example runs fine on DecStations and Silicon Graphics machines. Thanks in advance, Fons Rademakers. ========= cut here ====== # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by Fons Rademakers on Wed Apr 17 20:09:11 1991 # # This archive contains: # hcreateg.f hcreates.c make_server server.f # LANG=""; export LANG PATH=/bin:/usr/bin:$PATH; export PATH echo x - hcreateg.f cat >hcreateg.f <<'@EOF' *CMZ : 26/03/91 16.21.48 by Fons Rademakers *-- Author : Fons Rademakers 20/03/91 INTEGER FUNCTION HCREATEG(MFILE, IBASE, ISIZE, ICOMAD, IOFFST) ************************************************************************ * * * HCREATEG * * * * Create a global section. This routine causes the pages at ICOMAD * * and continuing for at most ISIZE words (1 word = 4 bytes) to be * * mapped from file MFILE. MFILE will be created in the /tmp directory. * * IOFFST is the offset between the address of the common starting at * * IBASE and the address of ICOMAD. The space in ICOMAD can then be * * addressed like: IBASE(IOFFST+1,...). * * On successful completion this function returns 0. In case of an * * error -ERRNO is returned. * * HCREATEG is an interface routine that calls the C routine HCREATEI. * * * * After a global section has been created by this function, other * * processes can use the data in this global section via the functions * * HMAPG and HFREEG. * * * ************************************************************************ * CHARACTER*(*) MFILE INTEGER ICOMAD, ISIZE, IBASE, IOFFST, HCREATEI * CHARACTER*4 MKEY * MKEY = MFILE HCREATEG = HCREATEI(MKEY, IBASE, ISIZE, ICOMAD, IOFFST) * END @EOF chmod 644 hcreateg.f echo x - hcreates.c cat >hcreates.c <<'@EOF' /*CMZ : 03/04/91 17.29.25 by Fons Rademakers*/ /*-- Author : Fons Rademakers 20/03/91*/ #include #include #include #include #include int shm_pawc; long len; int hcreatei_(mkey, base_common, size, comaddr, offset) /* * mkey identifier for the shared segment * base_common address of base (PAW) common * size length of common in 32 bit words * comaddr starting address of the mapping (*) * offset offset of comaddr in respect to the base_common (*) * (*) = output variables */ long base_common, *comaddr, *offset; int *size; key_t *mkey; { int istat; int flag = IPC_CREAT | 0666; unsigned long off; char *paddr, *shmat(); len = *size * 4; /* create shared memory segment */ if ((shm_pawc = shmget(*mkey, len, flag)) < 0) { perror("shmget"); istat = -errno; return(istat); } /* attach shared memory segment */ if ((paddr = shmat(shm_pawc, 0, SHM_RND)) == (char *)-1) { perror("shmat"); istat = -errno; } else { istat = 0; *comaddr = (long) paddr; off = (*comaddr - base_common); *offset = off >> 2; } return(istat); } @EOF chmod 644 hcreates.c echo x - make_server cat >make_server <<'@EOF' #! /bin/sh cc -g -c hcreates.c f77 -g +ppu -o server *.f *.o @EOF chmod 755 make_server echo x - server.f cat >server.f <<'@EOF' PROGRAM PRODUCE PARAMETER (LCOM = 10) CHARACTER*4 GNAME INTEGER HCREATEG COMMON /AAP/ IAAP(LCOM) GNAME = 'pawg' IS = HCREATEG(GNAME, IAAP, LCOM, IGL, IOFFST) IF (IS .EQ. 0) THEN PRINT *, 'GLOBAL SECTION CREATED, begin address =',IGL, + ' offset from AAP =', ioffst ELSE PRINT *, 'GLOBAL SECTION ERROR = ',IS STOP ENDIF J = 0 5 DO 10 I = 1, LCOM IAAP(IOFFST+I) = J K = IAAP(IOFFST+I) 10 CONTINUE PRINT *, IAAP(IOFFST+1) J = J + 1 IF (J .LT. 5010000) GOTO 5 END @EOF chmod 644 server.f exit 0 -- Org: CERN, European Organization for Nuclear Research. Mail: 1123 Geneve, Switzerland Fax: +22 7677155 Phone: +22 7674886 or 7675049 UUCP: rdm@cernapo.cern.ch BITNET: rdm@cernvm.bitnet