Article 135062 of comp.os.vms:
Path: nntpd.lkg.dec.com!lead.zk3.dec.com!crl.dec.com!crl.dec.com!caen!spool.mu.edu!howland.reston.ans.net!gatech2!news.sprintlink.net!hookup!lll-winken.llnl.gov!enews.sgi.com!decwrl!waikato!comp.vuw.ac.nz!usenet
From: mdlcpgs@lhn.gns.cri.nz
Newsgroups: comp.os.vms
Subject: $CRMPSC on Alpha? How to share a global sect on AXP
Date: Wed, 29 Nov 95 20:42:33 +1200
Organization: Institute of Geological and Nuclear Sciences
Lines: 168
Message-ID: <49h32t$dlh@st-james.comp.vuw.ac.nz>
NNTP-Posting-Host: lhn.gns.cri.nz

I am really hitting my head on a brick wall porting a vax/vms system
to Alpha vms when it comes to sharing memory between processes by
$crmpsc. this works fine on the vax but I get
"Invalid argument" in the call on the Alpha. I would love to RTFM but
as usual I am stuck in remote site with borrowed Alpha and no manuals or
CD. 
The alternative is obviously a installed common block and after many hoops
have that working (PSECT_ATTR=command,SHR and SYMBOL_VECTOR=(common=PSECT)
but really want to avoid the need for privileged install.

Here is the routine(s) that i currently use. In the link, I am setting
PSECT_ATTR=common,SHR as well. All in vain though. Something to do with
the page size on Alpha??

C#   MODULE OS_SHARE
C#
C#   Title	   :  
C#   Version       :1-001
C#   Facilty       : (_)
C#   Date Written  : Dec 1994
C#   Abstract      :  This module contains routines to support sharing
C#		      a common block between processes using a VMS shared
C#		      global section. A specified section of memory is
C#		      mapped via a file to a global section.
C#			OS_MAPCMN (map common) does the mapping of the
C#			common block. Two internal routines are called
C#			are called by the file open mechanism to either
C#			create or open a file for the shared memory.
C#   Reference:    : VMS System Services, $CRMPSM
C#   Environment   : Compile assumptions: system include files used. Calls
C#			Vax/VMS system service routines.
C#		     Linking assumptions: 
C#		     RunTime assumptions:
C#		Module is non-reentrant
C#   Author        : Phil Scadden
C#   Location      : Wellington NZ
C#   Amendment date: Original, Dec 1994
C#   Work performed: 
C#   Name          : Phil Scadden
C#
C#	PROCEDURE OS_MAPCMN
C#   Functional description: Maps an address range (a common block usually)
C#		to a shared global section of memory. Two processes that
C#		map memory to the same named global section can share variables
C#		in this section. A file is used to hold the hold the mapped
C#		variables.
C#                   
C#   Reference    : VMS System Services, $CRMPSC
C#                   
C#   Calling sequence:  CALL OS_MAPCMN(FIRST,LAST,LASTLEN,FNAME,NAME)
C#                   
C#   Formal Arguments: FIRST - Readonly, reference toany variable type. 
C#				The first variable in the common block to map.
C#                     LAST  - Readonly, reference any variable type. 
C#				The last variable in the common block to map. 
C#		       LASTLEN - readonly, longword integer, reference
C# 			length in bytes of the last variable in the common
C#			block
C#		       FNAME - readonly, character descriptor.
C#			Full filespec of file to hold mapped variables
C#		       NAME - readonly, character descriptor.
C#			Name for the global section. To share variables,
C#			the global sections must have same name.
C#   Dependencies:  
C#
C#   Implicit inputs : None
C#
C#   Implicit output : SEC_CHAN , the IO channel to the file
C#
C#   Files referenced: FNAME is file created or opened by the mapping
C#
C#   Completion Status: Errors are signalled.
C#
C#
	SUBROUTINE OS_MAPCMN(FIRST,LAST,LASTLEN,FNAME,NAME)
        IMPLICIT NONE
        INTEGER FIRST,LAST,LASTLEN
        CHARACTER*(*) FNAME, NAME
C
        INTEGER SEC_CHAN
        COMMON /OS_MAP/ SEC_CHAN
C
        INCLUDE '($SECDEF)'
        INTEGER MLUN
        LOGICAL NOTNEW
        INTEGER SECLEN, SEC_MASK
        INTEGER PASS_ADDR(2), RET_ADDR(2)
        INTEGER STATUS
        INTEGER  SEC_OPEN, SEC_CREATE, SYS$CRMPSC, SYS$MGBLSC
        EXTERNAL SEC_OPEN, SEC_CREATE, SYS$CRMPSC, SYS$MGBLSC
C
	IF (MLUN.EQ.0) CALL OS_GETLUN(MLUN)
        SECLEN = (%LOC(LAST) - %LOC(FIRST) + LASTLEN + 511)/512
C	  Try open existing file
        SEC_MASK = SEC$M_WRT .OR. SEC$M_GBL
        PASS_ADDR(1) = %LOC(FIRST)
        PASS_ADDR(2) = %LOC(LAST)
        OPEN(UNIT=MLUN,FILE=FNAME,STATUS='OLD',INITIALSIZE=SECLEN,
     *     USEROPEN=SEC_OPEN, IOSTAT = STATUS)
C		Create a file
        IF (STATUS.EQ.30) THEN !file locked so section must exist.
          SEC_MASK = SEC$M_WRT 
C		map to the existing global section
          STATUS = SYS$MGBLSC(PASS_ADDR,RET_ADDR,,%VAL(SEC_MASK),NAME,,)
          IF (.NOT. STATUS) CALL LIB$SIGNAL(%VAL(STATUS))
          RETURN
        ELSE IF (STATUS.NE.0) THEN !File cant exist to create it and zero it
          SEC_MASK = SEC$M_WRT .OR. SEC$M_DZRO .OR. SEC$M_GBL
          OPEN(UNIT=MLUN,FILE=FNAME,STATUS='NEW',INITIALSIZE=SECLEN,
     *     USEROPEN=SEC_CREATE)
        ENDIF
        CLOSE(MLUN)
C	  Create (if necessary) and map the section.
        STATUS = SYS$CRMPSC(PASS_ADDR,RET_ADDR,,%VAL(SEC_MASK),NAME,,,
     *  %VAL(SEC_CHAN),0,,,)
        IF (.NOT. STATUS) CALL LIB$SIGNAL(%VAL(STATUS))
        RETURN
        END
C**********************************************************************
      INTEGER FUNCTION SEC_CREATE(FAB,RAB,LUN)
      IMPLICIT NONE
      INCLUDE '($FABDEF)'
      INCLUDE '($RABDEF)'
C
      RECORD /FABDEF/ FAB
      RECORD /RABDEF/ RAB
      INTEGER LUN
C
      INTEGER STATUS
      INTEGER SEC_CHAN
      COMMON /OS_MAP/ SEC_CHAN
C
      INTEGER SYS$CREATE
C
      FAB.FAB$L_FOP = FAB.FAB$L_FOP .OR. FAB$M_UFO
      STATUS = SYS$CREATE(FAB)
      SEC_CHAN = FAB.FAB$L_STV
      SEC_CREATE = STATUS
      RETURN
      END
C**********************************************************************
      INTEGER FUNCTION SEC_OPEN(FAB,RAB,LUN)
      IMPLICIT NONE
      INCLUDE '($FABDEF)'
      INCLUDE '($RABDEF)'
C
      RECORD /FABDEF/ FAB
      RECORD /RABDEF/ RAB
      INTEGER LUN
C
      INTEGER STATUS
      INTEGER SEC_CHAN
      COMMON /OS_MAP/ SEC_CHAN
C
      INTEGER SYS$OPEN
C
      FAB.FAB$L_FOP = FAB.FAB$L_FOP .OR. FAB$M_UFO
      STATUS = SYS$OPEN(FAB)
      SEC_CHAN = FAB.FAB$L_STV
      SEC_OPEN = STATUS
      RETURN
      END

----------------------------------------------------------------------------
Phil Scadden, Scadden Research
55 Buick St, Petone, Lower Hutt
New Zealand
ph (04) 568-7190, fax (04) 569 5016


