genericopenlibs/openenvcore/include/sys/shm.h
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /* $FreeBSD: src/sys/sys/shm.h,v 1.23 2005/04/02 12:33:36 das Exp $ */
       
     2 /*	$NetBSD: shm.h,v 1.15 1994/06/29 06:45:17 cgd Exp $	*/
       
     3 
       
     4 /*-
       
     5  * Copyright (c) 1994 Adam Glass
       
     6  * All rights reserved.
       
     7  *
       
     8  * Redistribution and use in source and binary forms, with or without
       
     9  * modification, are permitted provided that the following conditions
       
    10  * are met:
       
    11  * 1. Redistributions of source code must retain the above copyright
       
    12  *    notice, this list of conditions and the following disclaimer.
       
    13  * 2. Redistributions in binary form must reproduce the above copyright
       
    14  *    notice, this list of conditions and the following disclaimer in the
       
    15  *    documentation and/or other materials provided with the distribution.
       
    16  * 4. The name of the author may not be used to endorse or promote products
       
    17  *    derived from this software without specific prior written permission
       
    18  *
       
    19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
       
    20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
       
    21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
       
    22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
       
    23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
       
    24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    29  *
       
    30  *  Portions Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
    31  */
       
    32 
       
    33 /*
       
    34  * As defined+described in "X/Open System Interfaces and Headers"
       
    35  *                         Issue 4, p. XXX
       
    36  */
       
    37 
       
    38 #ifndef _SYS_SHM_H_
       
    39 #define _SYS_SHM_H_
       
    40 
       
    41 #include <sys/cdefs.h>
       
    42 #include <sys/ipc.h>
       
    43 #include <sys/_types.h>
       
    44 
       
    45 #define SHM_RDONLY  010000  /* Attach read-only (else read-write) */
       
    46 #define SHM_RND     020000  /* Round attach address to SHMLBA */
       
    47 #define SHMLBA      PAGE_SIZE /* Segment low boundary address multiple */
       
    48 
       
    49 /* "official" access mode definitions; somewhat braindead since you have
       
    50    to specify (SHM_* >> 3) for group and (SHM_* >> 6) for world permissions */
       
    51 #define SHM_R       (IPC_R)
       
    52 #define SHM_W       (IPC_W)
       
    53 
       
    54 /* predefine tbd *LOCK shmctl commands */
       
    55 #define	SHM_LOCK	11
       
    56 #define	SHM_UNLOCK	12
       
    57 
       
    58 /* ipcs shmctl commands */
       
    59 #define	SHM_STAT	13
       
    60 #define	SHM_INFO	14
       
    61 
       
    62 #ifndef _PID_T_DECLARED
       
    63 typedef	__pid_t		pid_t;
       
    64 #define	_PID_T_DECLARED
       
    65 #endif
       
    66 
       
    67 #ifndef _TIME_T_DECLARED
       
    68 typedef	__time_t	time_t;
       
    69 #define	_TIME_T_DECLARED
       
    70 #endif
       
    71 
       
    72 #ifndef _SIZE_T_DECLARED
       
    73 typedef	__size_t	size_t;
       
    74 #define	_SIZE_T_DECLARED
       
    75 #endif
       
    76 
       
    77 struct shmid_ds {
       
    78 	struct ipc_perm shm_perm;	/* operation permission structure */
       
    79 	int             shm_segsz;	/* size of segment in bytes */
       
    80 	pid_t           shm_lpid;   /* process ID of last shared memory op */
       
    81 	pid_t           shm_cpid;	/* process ID of creator */
       
    82 	short		shm_nattch;	/* number of current attaches */
       
    83 	time_t          shm_atime;	/* time of last shmat() */
       
    84 	time_t          shm_dtime;	/* time of last shmdt() */
       
    85 	time_t          shm_ctime;	/* time of last change by shmctl() */
       
    86 	void           *shm_internal;   /* sysv stupidity */
       
    87 };
       
    88 
       
    89 #ifdef _KERNEL
       
    90 
       
    91 /*
       
    92  * System 5 style catch-all structure for shared memory constants that
       
    93  * might be of interest to user programs.  Do we really want/need this?
       
    94  */
       
    95 struct shminfo {
       
    96 	int	shmmax,		/* max shared memory segment size (bytes) */
       
    97 		shmmin,		/* min shared memory segment size (bytes) */
       
    98 		shmmni,		/* max number of shared memory identifiers */
       
    99 		shmseg,		/* max shared memory segments per process */
       
   100 		shmall;		/* max amount of shared memory (pages) */
       
   101 };
       
   102 
       
   103 /* 
       
   104  * Add a kernel wrapper to the shmid_ds struct so that private info (like the
       
   105  * MAC label) can be added to it, without changing the user interface.
       
   106  */
       
   107 struct shmid_kernel {
       
   108 	struct shmid_ds u;
       
   109 	struct label *label;	/* MAC label */
       
   110 };
       
   111 
       
   112 extern struct shminfo	shminfo;
       
   113 
       
   114 struct shm_info {
       
   115 	int used_ids;
       
   116 	unsigned long shm_tot;
       
   117 	unsigned long shm_rss;
       
   118 	unsigned long shm_swp;
       
   119 	unsigned long swap_attempts;
       
   120 	unsigned long swap_successes;
       
   121 };
       
   122 
       
   123 struct thread;
       
   124 struct proc;
       
   125 struct vmspace;
       
   126 
       
   127 #else /* !_KERNEL */
       
   128 
       
   129 #include <sys/cdefs.h>
       
   130 
       
   131 #ifndef _SIZE_T_DECLARED
       
   132 typedef __size_t        size_t;
       
   133 #define _SIZE_T_DECLARED
       
   134 #endif
       
   135 
       
   136 // FUNCTION PROTOTYPES
       
   137 
       
   138 
       
   139 // FORWARD DECLARATIONS
       
   140 
       
   141 
       
   142 // CLASS/STRUCT/FUNCTION DECLARATION
       
   143 __BEGIN_DECLS
       
   144 /*
       
   145 * Get shared memory identifier using the IPC key generated by ftok.
       
   146 */
       
   147 
       
   148 IMPORT_C int shmget(key_t key, int size, int shmflg);
       
   149 
       
   150 
       
   151 /*
       
   152 * Attaches the shared memory segment associated with the shared memory identifier 
       
   153 * specified by shmid to the address space of the calling process.
       
   154 */
       
   155 
       
   156 IMPORT_C void* shmat(int shmid, const void *shmaddr, int shmflg);
       
   157 
       
   158 
       
   159 /*
       
   160 * Detaches the shared memory segment located at the address specified by shmaddr 
       
   161 * from the address space of the calling process.
       
   162 */
       
   163 
       
   164 IMPORT_C int shmdt(const void *shmaddr);
       
   165 
       
   166 
       
   167 /*
       
   168 * Provides a variety of shared memory control operations as specified by cmd.
       
   169 */
       
   170 
       
   171 IMPORT_C int shmctl(int shmid, int cmd, struct shmid_ds *buf);
       
   172 
       
   173 
       
   174 __END_DECLS
       
   175 
       
   176 #endif /* !_KERNEL */
       
   177 
       
   178 #endif // SHM_H
       
   179 
       
   180 //  End of File