| Here's a C code fragment that does what you want. It performs the
task using CRMPSC, but it creates a pagefile global section... you
don't need a file or a channel to do this - the backing store is
the pagefile. After the section is created, the other processes
just map to it using MGBLSC calls.
-Rick
/*
* First, the code that creates the section.
* this stuff was ported from ULTRIX [It used shared memory].
* the "KEY" is used to fabricate the name of the section.
*/
tshmid = create_section (TKEY, &torps,
sizeof(struct torp) * MAXPLAYER * MAXTORP);
if ((tshmid&1) != 1 ) {
printf("Can't create torp section");
exit (tshmid);
}
/*
* lots of other stuff elided..
*/
create_section(key, ptr, size)
/*
* Create a global section. KEY is used to identify the section name.
* PTR is the address of a pointer to the section.
* SIZE is the size of the section in bytes.
*/
int key;
int *ptr;
int size;
{
int descr[2];
int inadr[2];
int retadr[2];
int status;
int page_size;
char str[64];
/*
* The section is normally a System, Writable, Pagefile section.
*/
static sec_flags = SEC$M_GBL|SEC$M_EXPREG|SEC$M_WRT|
SEC$M_SYSGBL|SEC$M_PAGFIL;
/*
* build the section name from the key.
* then build a string descriptor to point to it.
*/
sprintf(str, "XTREK_%d",key);
descr[0] = strlen(str);
descr[1] = &str;
/*
* calculate size in pages given the size on bytes.
*/
if (size && 0x1FF)
page_size = size/0x200 + 1;
else
page_size = size/0x200;
inadr[0] = 0;
inadr[1] = 0;
status = sys$crmpsc (
inadr ,
retadr ,
0 ,
sec_flags ,
descr ,
0 ,
0 ,
0 ,
page_size ,
0 ,
0 ,
0 );
/*
* If nopriv, we're not able to create the system section;
* fall back to group.
*/
if (status == SS$_NOPRIV) {
sec_flags = SEC$M_GBL|SEC$M_EXPREG|SEC$M_WRT|SEC$M_PAGFIL;
status = sys$crmpsc (
inadr ,
retadr ,
0 ,
sec_flags ,
descr ,
0 ,
0 ,
0 ,
page_size ,
0 ,
0 ,
0 );
}
*ptr = retadr[0];
return(status);
}
|