[ 前のページ ] [ 次のページ ] [ 目次 ] [ 索引 ] [ DOC Home ]

D VLMプログラム例

このサンプル・プログラムは,第4章 で説明したメモリ管理VLM機能を紹介します。

/*
*****************************************************************************
*
* Copyright (c) Digital Equipment Corporation, 1996 All Rights Reserved.
* Unpublished rights reserved under the copyright laws of the United States.
*
* The software contained on this media is proprietary to and embodies the
* confidential technology of Digital Equipment Corporation.  Possession, use,
* duplication or dissemination of the software and media is authorized only
* pursuant to a valid written license from Digital Equipment Corporation.
*
* RESTRICTED RIGHTS LEGEND   Use, duplication, or disclosure by the U.S.
* Government is subject to restrictions as set forth in Subparagraph
* (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable.
*
*****************************************************************************
/*
   This program creates and maps to a memory resident global section using
   shared page tables.  The program requires a reserved memory entry
   (named In_Memory_Database) in the Reserved Memory Registry.

   The entry in the registry is created using SYSMAN as follows:

   $ MCR SYSMAN
   SYSMAN> RESERVED_MEMORY ADD "In_Memory_Database"/ALLOCATE/PAGE_TABLES -
       /ZERO/SIZE=64/GROUP=100

   The above command creates an entry named In_Memory_Database that is
   64 Mbytes in size and requests that the physical memory be allocated
   during system initialization.  This enables the physcial memory to
   be mapped with granularity hints by the SYS$CRMPSC_GDZRO_64 system
   service.  It also requests that physical memory be allocated for
   page tables for the named entry, requests the allocated memory be
   zeroed, and requests that UIC group number 100 be associated with
   the entry.

   Once the entry has been created with SYSMAN, the system must be
   re-tuned with AUTOGEN.  Doing so allows AUTOGEN to re-calculate
   values for SYSGEN parameters that are sensitive to changes in
   physical memory sizes.  (Recall that the Reserved Memory Registry
   takes physical pages away from the system.)  Once AUTOGEN has
   been run, the system must be rebooted.

   Using the following commands to compile and link this program:

   $ CC/POINTER_SIZE=32 shared_page_tables_example
   $ LINK shared_page_tables_example

   Since 64-bit virtual addresses are used by this program, a Version
   5.2 DEC C compiler or later is required to compile it.

*/
#define     __NEW_STARLET   1

#include    <DESCRIP>
#include    <FAR_POINTERS>
#include    <GEN64DEF>
#include    <INTS>
#include    <PSLDEF>
#include    <SECDEF>
#include    <SSDEF>
#include    <STARLET>
#include    <STDIO>
#include    <STDLIB>
#include    <STRING>
#include    <VADEF>

#define     bad_status(status) (((status) & 1) != 1)
#define     ONE_MEGABYTE    0x100000


main ()
{
    int
        status;
 
    $DESCRIPTOR (section_name, "In_Memory_Database");

    uint32
        region_flags = VA$M_SHARED_PTS,   /* Shared PT region. */
        section_flags = SEC$M_EXPREG;

    uint64
         mapped_length,
         requested_size = 64*ONE_MEGABYTE,
         section_length = 64*ONE_MEGABYTE,
         region_length;

    GENERIC_64
         region_id;

    VOID_PQ
        mapped_va,
        region_start_va;

    printf ("Shared Page Table Region Creation Attempt:  Size = %0Ld\n",
        requested_size);

/*  Create a shared page table region. */

    status = sys$create_region_64 (
        requested_size,                 /* Size in bytes of region */
        VA$C_REGION_UCREATE_UOWN,       /* Region VA creation and owner mode */
        region_flags,                   /* Region Flags:  shared page tables */
        ®ion_id,                     /* Region ID */
        ®ion_start_va,               /* Starting VA for region */
        ®ion_length);                /* Size of created region */

    if (bad_status (status))
    {
        printf ("ERROR:  Unable to create region of size %16Ld\n\n",
            requested_size);
        return;
    }

    printf ("Shared Page Table Region Created:  VA = %016LX, Size = %0Ld\n\n",
        region_start_va,
        region_length);

/* Create and map a memory resident section with shared page tables
       into the shared page table region. */

    printf ("Create and map to section %s\n", section_name.dsc$a_pointer);
    status = sys$crmpsc_gdzro_64 (
            §ion_name,              /* Section name */
            0,                          /* Section Ident */
            0,                          /* Section protection */
            section_length,             /* Length of Section */
            ®ion_id,                 /* RDE */
            0,                          /* Section Offset; map entire section */
            PSL$C_USER,                 /* Access Mode */
            section_flags,              /* Section Creation Flags */
            &mapped_va,                 /* Return VA */
            &mapped_length);            /* Return Mapped Length */

    if (bad_status (status))
        printf ("ERROR:  Unable to Create and Map Section %s, status = %08x\n\n",
                section_name.dsc$a_pointer,
                status);
    else
    {
        printf ("Section %s created, Section Length = %0Ld\n",
                section_name.dsc$a_pointer,
                section_length);
        printf ("    Mapped VA = %016LX, Mapped Length = %0Ld\n\n",
                mapped_va,
                mapped_length);
    }

    /* Delete the shared page table.  This will cause the mapping to the
       section and the section itself to be deleted. */

        printf ("Delete the mapping to the memory resident global section");
        printf (" and the shared\n    page table region.\n");
        status = sys$delete_region_64 (
                ®ion_id,
                PSL$C_USER,
                ®ion_start_va,
                ®ion_length);

        if (bad_status (status))
            printf ("ERROR:  Unable to delete shared page table region, status = %08x\n\n", status);
        else
            printf ("Region Deleted, Start VA = %016LX, Length = %016LX\n\n",
                    region_start_va,
                    region_length);
        printf ("\n");
}

This example program displays the following output:

Shared Page Table Region Creation Attempt:  Size = 67108864
Shared Page Table Region Created:  VA = FFFFFFFBFC000000, Size = 67108864

Create and map to section In_Memory_Database
Section In_Memory_Database created, Section Length = 67108864
    Mapped VA = FFFFFFFBFC000000, Mapped Length = 67108864

Delete the mapping to the memory resident global section and the shared
    page table region.
Region Deleted, Start VA = FFFFFFFBFC000000, Length = 0000000004000000


[ 前のページ ] [ 次のページ ] [ 目次 ] [ 索引 ] [ DOC Home ]