Home | History | Annotate | Line # | Download | only in sys
      1 /*	$NetBSD: shm.h,v 1.8 2019/02/21 03:37:19 mrg Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 Adam Glass
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Adam Glass.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * As defined+described in "X/Open System Interfaces and Headers"
     35  *                         Issue 4, p. XXX
     36  */
     37 
     38 #ifndef _COMPAT_SYS_SHM_H_
     39 #define _COMPAT_SYS_SHM_H_
     40 
     41 #include <compat/sys/ipc.h>
     42 
     43 struct shmid_ds14 {
     44 	struct ipc_perm14 shm_perm;	/* operation permission structure */
     45 	int		shm_segsz;	/* size of segment in bytes */
     46 	pid_t		shm_lpid;	/* process ID of last shm op */
     47 	pid_t		shm_cpid;	/* process ID of creator */
     48 	short		shm_nattch;	/* number of current attaches */
     49 	int32_t		shm_atime;	/* time of last shmat() */
     50 	int32_t		shm_dtime;	/* time of last shmdt() */
     51 	int32_t		shm_ctime;	/* time of last change by shmctl() */
     52 	void		*shm_internal;	/* sysv stupidity */
     53 };
     54 
     55 struct shmid_ds13 {
     56 	struct ipc_perm	shm_perm;	/* operation permission structure */
     57 	size_t		shm_segsz;	/* size of segment in bytes */
     58 	pid_t		shm_lpid;	/* process ID of last shm operation */
     59 	pid_t		shm_cpid;	/* process ID of creator */
     60 	shmatt_t	shm_nattch;	/* number of current attaches */
     61 	int32_t		shm_atime;	/* time of last shmat() */
     62 	int32_t		shm_dtime;	/* time of last shmdt() */
     63 	int32_t		shm_ctime;	/* time of last change by shmctl() */
     64 
     65 	/*
     66 	 * These members are private and used only in the internal
     67 	 * implementation of this interface.
     68 	 */
     69 	void		*_shm_internal;
     70 };
     71 
     72 /* Warning: 64-bit structure padding is needed here */
     73 struct shmid_ds_sysctl50 {
     74 	struct		ipc_perm_sysctl shm_perm;
     75 	uint64_t	shm_segsz;
     76 	pid_t		shm_lpid;
     77 	pid_t		shm_cpid;
     78 	int32_t		shm_atime;
     79 	int32_t		shm_dtime;
     80 	int32_t		shm_ctime;
     81 	uint32_t	shm_nattch;
     82 };
     83 struct shm_sysctl_info50 {
     84 	struct	shminfo shminfo;
     85 	struct	shmid_ds_sysctl50 shmids[1];
     86 };
     87 
     88 __BEGIN_DECLS
     89 static __inline void	__shmid_ds14_to_native(const struct shmid_ds14 *, struct shmid_ds *);
     90 static __inline void	__native_to_shmid_ds14(const struct shmid_ds *, struct shmid_ds14 *);
     91 static __inline void	__shmid_ds13_to_native(const struct shmid_ds13 *, struct shmid_ds *);
     92 static __inline void	__native_to_shmid_ds13(const struct shmid_ds *, struct shmid_ds13 *);
     93 static __inline void
     94 __shmid_ds14_to_native(const struct shmid_ds14 *oshmbuf, struct shmid_ds *shmbuf)
     95 {
     96 
     97 	__ipc_perm14_to_native(&oshmbuf->shm_perm, &shmbuf->shm_perm);
     98 
     99 #define	CVT(x)	shmbuf->x = oshmbuf->x
    100 	CVT(shm_segsz);
    101 	CVT(shm_lpid);
    102 	CVT(shm_cpid);
    103 	CVT(shm_nattch);
    104 	CVT(shm_atime);
    105 	CVT(shm_dtime);
    106 	CVT(shm_ctime);
    107 #undef CVT
    108 }
    109 
    110 static __inline void
    111 __native_to_shmid_ds14(const struct shmid_ds *shmbuf, struct shmid_ds14 *oshmbuf)
    112 {
    113 
    114 	memset(oshmbuf, 0, sizeof *oshmbuf);
    115 	__native_to_ipc_perm14(&shmbuf->shm_perm, &oshmbuf->shm_perm);
    116 
    117 #define	CVT(x)	oshmbuf->x = shmbuf->x
    118 #define	CVTI(x)	oshmbuf->x = (int)shmbuf->x
    119 	CVTI(shm_segsz);
    120 	CVT(shm_lpid);
    121 	CVT(shm_cpid);
    122 	CVT(shm_nattch);
    123 	CVTI(shm_atime);
    124 	CVTI(shm_dtime);
    125 	CVTI(shm_ctime);
    126 #undef CVT
    127 #undef CVTI
    128 }
    129 
    130 static __inline void
    131 __shmid_ds13_to_native(const struct shmid_ds13 *oshmbuf, struct shmid_ds *shmbuf)
    132 {
    133 
    134 	shmbuf->shm_perm = oshmbuf->shm_perm;
    135 
    136 #define	CVT(x)	shmbuf->x = oshmbuf->x
    137 	CVT(shm_segsz);
    138 	CVT(shm_lpid);
    139 	CVT(shm_cpid);
    140 	CVT(shm_nattch);
    141 	CVT(shm_atime);
    142 	CVT(shm_dtime);
    143 	CVT(shm_ctime);
    144 #undef CVT
    145 }
    146 
    147 static __inline void
    148 __native_to_shmid_ds13(const struct shmid_ds *shmbuf, struct shmid_ds13 *oshmbuf)
    149 {
    150 
    151 	memset(oshmbuf, 0, sizeof *oshmbuf);
    152 	oshmbuf->shm_perm = shmbuf->shm_perm;
    153 
    154 #define	CVT(x)	oshmbuf->x = shmbuf->x
    155 #define	CVTI(x)	oshmbuf->x = (int)shmbuf->x
    156 	CVT(shm_segsz);
    157 	CVT(shm_lpid);
    158 	CVT(shm_cpid);
    159 	CVT(shm_nattch);
    160 	CVTI(shm_atime);
    161 	CVTI(shm_dtime);
    162 	CVTI(shm_ctime);
    163 #undef CVT
    164 #undef CVTI
    165 }
    166 
    167 int	__shmctl13(int, int, struct shmid_ds13 *);
    168 int	__shmctl14(int, int, struct shmid_ds14 *);
    169 int	__shmctl50(int, int, struct shmid_ds *);
    170 __END_DECLS
    171 
    172 #endif /* !_COMPAT_SYS_SHM_H_ */
    173