From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 14-JUN-1992 22:04:50.85
To:	info-vax@kl.sri.com
CC:	
Subj:	Re: Help using Sections, $CRMPSC (sVr4-like shared memory)

In article <1992Jun14.220835.8295@ulowell.ulowell.edu>, jrichard@cs.ulowell.edu  writes:
>I am tying to use the $CRMPSC system service function to create some
>unix-like shared memory (not multiprocessor VMS shared memory).
>However, I can't get anything to work, not even the examples in the
>"Introduction to System Services" (they are all incomplete).  If anyone
>has a program that uses this function can you drop me some mail?  I'm
>working in C and Macro but anything will suffice!


Here is a code fragment that should give you the essentials needed to create
shared memory from a C program:

    int status, SYS$CRMPSC(), name_desc[2], flags, pages;
    char *retadr[2], *inadr[2];
    char name[32];

    /* Format name to use for global section and init other parameters. */

    strcpy(name,"SHMEM_EXAMPLE");
    name_desc[0] = strlen(name);
    name_desc[1] = (int) &name;		/* Global section name descriptor */
    pages = 6;				/* Size of section */
    inadr[0] = NULL;
    inadr[1] = inadr[0];   		/* create section in P0 */
    flags = 				/* Flags:
	    SEC$M_GBL | 		/*    Section is global (shared) */
	    SEC$M_WRT | 		/*    Section is writable */
	    SEC$M_PAGFIL | 		/*    Use pagefile as backing store */
	    SEC$M_EXPREG | 		/*    Expand region (map to new addr) */
	    SEC$M_DZRO;			/*    Create demand zero pages. */


    /* Make system service call and check status, protection argument (0xff00)
	specifies only system and owner access to the section. */

    status = SYS$CRMPSC
	(&inadr, &retadr, 0, flags, &name_desc, 0, 0, 0, pages, 0, 0x0ff00, 0);
    if ( (status&1) != 1 ) perror ( "could not map global section\n");

    else printf ( "Section create/mapped into address range %x - %x\n",
	retadr[0], retadr[1] );

Getting the flags argument correct it usually the key to getting the thing
to work right.  The flags I've shown will give results very close to the
bsd unix shmem routine, I don't know what SVR4 shared memory is like.


David L. Jones               |      Phone:    (614) 292-6929
Ohio State Unviversity       |      Internet:
1971 Neil Ave. Rm. 406       |               jonesd@kcgl1.eng.ohio-state.edu
Columbus, OH 43210           |               jones-d@eng.ohio-state.edu

Disclaimer: A repudiation of a claim.

