From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 30-JUN-1989 19:24
To:	MRGATE::"ARISIA::EVERHART"
Subj:	RE: Use C to call SYS$CRMPSC?

Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Fri, 30 JUN 89 14:35:15 PDT
Received: from LBL.Gov by KL.SRI.COM with TCP; Fri, 30 Jun 89 14:30:18 PDT
Received: from warner.hepnet by LBL.Gov with VMSmail ;
	Fri, 30 Jun 89 14:27:27 PDT
Date:    Fri, 30 Jun 89 14:27:27 PDT
From: nagy%warner.hepnet@LBL.Gov (Frank J. Nagy/VAX Guru&Wizard)
Message-Id: <890630142727.2b600dc9@LBL.Gov>
Subject: RE: Use C to call SYS$CRMPSC?
To: Info-VAX@kl.sri.com
X-St-Vmsmail-To: info_vax

>   I have a question for all of the C gurus out there.  What I would
>like to do is map a file to virtual memory with a private section using the
>SYS$CRMPSC system service.  What I would like to know, is how do I find a range
>of virtual address that I can use, and set it aside such that the malloc
>function still works correctly.

What I do is to have $CRMPSC expand the P0 region with new virtual addresses.
How this is done:

	1. Specify the inadr argument as a pair of longwords, put 512 into
	   each longword (512 is just convienent, all they do is tell $CRMPSC
	   to work in P0 space).

	2. Specify the retadr argument as a pair of longwords to be written
	   into.  When $CRMPSC returns (successfully), then retadr[0] is the
	   address of the base of the section you have created.  This can be
	   typecast into a C pointer of the appropriate type.  Usually, I
	   just need generic pointers (char *), so I define retadr as:

		char *retadr[2];

	   and then do sys$crmpsc( inadr, retadr, ...);

	3. Make sure the SEC$M_EXPREG flag is set in the flags argument to
	   $CRMPSC to tell the service to expand the P0 address space, 
	   placing the new section in the newly created addresses.

malloc (which is based ultimately on $CRETVA) will continue to work, its
just that the memory pool malloc has to work with will be discontinuous
around your section.

= Dr. Frank J. Nagy   "VAX Guru & Wizard"
= Fermilab Research Division/Electrical and Electronics Dept/Controls Group
= HEPNET: WARNER::NAGY (43198::NAGY) or FNAL::NAGY (43009::NAGY)
= BitNet: NAGY@FNAL
= USnail: Fermilab POB 500 MS/220 Batavia, IL 60510


