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