home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Portable Patmos / usr / include / sys / mapmem.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-08  |  4.9 KB  |  118 lines  |  [TEXT/R*ch]

  1. /*
  2.  * Copyright (c) 1988 University of Utah.
  3.  * Copyright (c) 1990 The Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * This code is derived from software contributed to Berkeley by
  7.  * the Systems Programming Group of the University of Utah Computer
  8.  * Science Department.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  *
  38.  *    from: Utah Hdr: mmap.h 1.4 89/08/14
  39.  *    from: @(#)mapmem.h    7.2 (Berkeley) 6/6/90
  40.  *    $Id: mapmem.h,v 1.4 1993/08/01 19:26:29 mycroft Exp $
  41.  */
  42.  
  43. #ifndef _SYS_MAPMEM_H_
  44. #define _SYS_MAPMEM_H_
  45.  
  46. /*
  47.  * Mapped memory descriptors.
  48.  *
  49.  * A process has one of these for every "mapped" memory region.
  50.  * Mapped memory is characterized by:
  51.  *    - Corresponding physical memory is neither paged nor swapped.
  52.  *    - User PTEs have both pg_v and pg_fod set.
  53.  *    - Has no backing swap space unless mapped over existing data.
  54.  *    - If mapped over existing data, original data is lost when
  55.  *      segment is unmapped. (i.e. pages are reinitialized to ZFOD)
  56.  * Operations:
  57.  *    (*mm_fork)(mp, ischild) struct mapmem *mp; int ischild;
  58.  *        Called during fork in both parent and child.  Parent
  59.  *        call can be used for maintaining reference counts and
  60.  *        should NEVER destroy the region.  Child call should be
  61.  *        used for unmapping regions not inherited across forks.
  62.  *    (*mm_vfork)(mp, fup, tup) struct mapmem *mp; struct user *fup, *tup;
  63.  *        Called twice during vfork (always in parent context)
  64.  *        after exchanging resources (including u_mmap chains).
  65.  *        `fup' is the donor and `tup' the recipient of the
  66.  *        "parent" (full) context.  Needed for maintaining
  67.  *        reference counts or if the underlying object contains
  68.  *        references to owning process.  Routine should NEVER
  69.  *        destroy the region.
  70.  *    (*mm_exec)(mp) struct mapmem *mp;
  71.  *        Called during exec before releasing old address space.
  72.  *        Used for graceful cleanup of underlying object.  Resources
  73.  *        will be freed regardless of what this routine does.
  74.  *        Need to add a post-exec call to re-establish mappings
  75.  *        in the new address space for regions inherited across execs.
  76.  *    (*mm_exit)(mp) struct mapmem *mp;
  77.  *        Called during exit just before releasing address space.
  78.  *        Used for graceful cleanup of underlying object.  Resources
  79.  *        will be freed regardless of what this routine does.
  80.  * The default semantics for a region with routine addresses of zero are
  81.  * that it is inherited across forks, stays with the "active" process during
  82.  * vforks, and is destroyed by execs and exit.
  83.  */
  84.  
  85. struct mapmem {
  86.     struct    mapmem *mm_next;    /* next descriptor */
  87.     int    mm_id;            /* identifier (e.g. fd, shmid) */
  88.     caddr_t    mm_uva;            /* user VA at which region is mapped */
  89.     int    mm_size;        /* size of mapped region */
  90.     int    mm_prot;        /* attributes of region */
  91.     struct mapmemops {        /* operations */
  92.         int    (*mm_fork)();
  93.         int    (*mm_vfork)();
  94.         int    (*mm_exec)();
  95.         int    (*mm_exit)();
  96.     } *mm_ops;
  97. };
  98.  
  99. #define MMNIL    ((struct mapmem *)0)
  100.  
  101. /* attributes */
  102. #define MM_RW        0x00    /* region is read-write */
  103. #define    MM_RO        0x01    /* region is read-only */
  104. #define MM_CI        0x02    /* caching is inhibited on region */
  105. #define MM_NOCORE    0x04    /* cannot write region to core file;
  106.                    e.g. mapped framebuffer hardware */
  107.  
  108. #ifdef KERNEL
  109. #define MMALLOC(mp) \
  110.     (mp) = (struct mapmem *)malloc((u_long)sizeof(struct mapmem), \
  111.         M_MAPMEM, M_WAITOK)
  112.  
  113. #define MMFREE(mp) \
  114.     free((caddr_t)(mp), M_MAPMEM)
  115. #endif
  116.  
  117. #endif /* !_SYS_MAPMEM_H_ */
  118.