1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) 2020 Linaro Limited. All rights reserved. 4 * Author: Viresh Kumar <viresh.kumar@linaro.org> 5 */ 6 7#ifndef LAPI_SHMBUF_H__ 8#define LAPI_SHMBUF_H__ 9 10#include "lapi/posix_types.h" 11#include <sys/sem.h> 12#include "tst_timer.h" 13#include "ipcbuf.h" 14 15#ifndef HAVE_SHMID64_DS 16 17#if defined(__mips__) 18#define HAVE_SHMID64_DS 19/* 20 * The shmid64_ds structure for the MIPS architecture. 21 * Note extra padding because this structure is passed back and forth 22 * between kernel and user space. 23 * 24 * As MIPS was lacking proper padding after shm_?time, we use 48 bits 25 * of the padding at the end to store a few additional bits of the time. 26 * libc implementations need to take care to convert this into a proper 27 * data structure when moving to 64-bit time_t. 28 */ 29 30#if __BITS_PER_LONG == 64 31struct shmid64_ds { 32 struct ipc64_perm shm_perm; /* operation perms */ 33 size_t shm_segsz; /* size of segment (bytes) */ 34 long shm_atime; /* last attach time */ 35 long shm_dtime; /* last detach time */ 36 long shm_ctime; /* last change time */ 37 __kernel_pid_t shm_cpid; /* pid of creator */ 38 __kernel_pid_t shm_lpid; /* pid of last operator */ 39 unsigned long shm_nattch; /* no. of current attaches */ 40 unsigned long __unused1; 41 unsigned long __unused2; 42}; 43#else 44#define HAVE_SHMID64_DS_TIME_HIGH 45struct shmid64_ds { 46 struct ipc64_perm shm_perm; /* operation perms */ 47 size_t shm_segsz; /* size of segment (bytes) */ 48 unsigned long shm_atime; /* last attach time */ 49 unsigned long shm_dtime; /* last detach time */ 50 unsigned long shm_ctime; /* last change time */ 51 __kernel_pid_t shm_cpid; /* pid of creator */ 52 __kernel_pid_t shm_lpid; /* pid of last operator */ 53 unsigned long shm_nattch; /* no. of current attaches */ 54 unsigned short shm_atime_high; 55 unsigned short shm_dtime_high; 56 unsigned short shm_ctime_high; 57 unsigned short __unused1; 58}; 59#endif 60 61#endif /* __mips__ */ 62 63#if defined(__hppa__) 64#define HAVE_SHMID64_DS 65/* 66 * The shmid64_ds structure for parisc architecture. 67 * Note extra padding because this structure is passed back and forth 68 * between kernel and user space. 69 * 70 * Pad space is left for: 71 * - 2 miscellaneous 32-bit values 72 */ 73 74struct shmid64_ds { 75 struct ipc64_perm shm_perm; /* operation perms */ 76#if __BITS_PER_LONG == 64 77 long shm_atime; /* last attach time */ 78 long shm_dtime; /* last detach time */ 79 long shm_ctime; /* last change time */ 80#else 81#define HAVE_SHMID64_DS_TIME_HIGH 82 unsigned long shm_atime_high; 83 unsigned long shm_atime; /* last attach time */ 84 unsigned long shm_dtime_high; 85 unsigned long shm_dtime; /* last detach time */ 86 unsigned long shm_ctime_high; 87 unsigned long shm_ctime; /* last change time */ 88 unsigned int __pad4; 89#endif 90 __kernel_size_t shm_segsz; /* size of segment (bytes) */ 91 __kernel_pid_t shm_cpid; /* pid of creator */ 92 __kernel_pid_t shm_lpid; /* pid of last operator */ 93 unsigned long shm_nattch; /* no. of current attaches */ 94 unsigned long __unused1; 95 unsigned long __unused2; 96}; 97#endif /* __hppa__ */ 98 99#if defined(__powerpc__) || defined(__powerpc64__) 100#define HAVE_SHMID64_DS 101/* 102 * The shmid64_ds structure for PPC architecture. 103 * 104 * Note extra padding because this structure is passed back and forth 105 * between kernel and user space. 106 * 107 * Pad space is left for: 108 * - 2 miscellaneous 32-bit values 109 */ 110 111struct shmid64_ds { 112 struct ipc64_perm shm_perm; /* operation perms */ 113#ifdef __powerpc64__ 114 long shm_atime; /* last attach time */ 115 long shm_dtime; /* last detach time */ 116 long shm_ctime; /* last change time */ 117#else 118#define HAVE_SHMID64_DS_TIME_HIGH 119 unsigned long shm_atime_high; 120 unsigned long shm_atime; /* last attach time */ 121 unsigned long shm_dtime_high; 122 unsigned long shm_dtime; /* last detach time */ 123 unsigned long shm_ctime_high; 124 unsigned long shm_ctime; /* last change time */ 125 unsigned long __unused4; 126#endif 127 size_t shm_segsz; /* size of segment (bytes) */ 128 __kernel_pid_t shm_cpid; /* pid of creator */ 129 __kernel_pid_t shm_lpid; /* pid of last operator */ 130 unsigned long shm_nattch; /* no. of current attaches */ 131 unsigned long __unused5; 132 unsigned long __unused6; 133}; 134 135#endif /* defined(__powerpc__) || defined(__powerpc64__) */ 136 137#if defined(__sparc__) 138#define HAVE_SHMID64_DS 139/* 140 * The shmid64_ds structure for sparc architecture. 141 * Note extra padding because this structure is passed back and forth 142 * between kernel and user space. 143 * 144 * Pad space is left for: 145 * - 2 miscellaneous 32-bit values 146 */ 147 148struct shmid64_ds { 149 struct ipc64_perm shm_perm; /* operation perms */ 150#if defined(__arch64__) 151 long shm_atime; /* last attach time */ 152 long shm_dtime; /* last detach time */ 153 long shm_ctime; /* last change time */ 154#else 155#define HAVE_SHMID64_DS_TIME_HIGH 156 unsigned long shm_atime_high; 157 unsigned long shm_atime; /* last attach time */ 158 unsigned long shm_dtime_high; 159 unsigned long shm_dtime; /* last detach time */ 160 unsigned long shm_ctime_high; 161 unsigned long shm_ctime; /* last change time */ 162#endif 163 size_t shm_segsz; /* size of segment (bytes) */ 164 __kernel_pid_t shm_cpid; /* pid of creator */ 165 __kernel_pid_t shm_lpid; /* pid of last operator */ 166 unsigned long shm_nattch; /* no. of current attaches */ 167 unsigned long __unused1; 168 unsigned long __unused2; 169}; 170 171#endif /* __sparc__ */ 172 173#if defined(__x86_64__) && defined(__ILP32__) 174#define HAVE_SHMID64_DS 175/* 176 * The shmid64_ds structure for x86 architecture with x32 ABI. 177 * 178 * On x86-32 and x86-64 we can just use the generic definition, but 179 * x32 uses the same binary layout as x86_64, which is differnet 180 * from other 32-bit architectures. 181 */ 182 183struct shmid64_ds { 184 struct ipc64_perm shm_perm; /* operation perms */ 185 size_t shm_segsz; /* size of segment (bytes) */ 186 __kernel_long_t shm_atime; /* last attach time */ 187 __kernel_long_t shm_dtime; /* last detach time */ 188 __kernel_long_t shm_ctime; /* last change time */ 189 __kernel_pid_t shm_cpid; /* pid of creator */ 190 __kernel_pid_t shm_lpid; /* pid of last operator */ 191 __kernel_ulong_t shm_nattch; /* no. of current attaches */ 192 __kernel_ulong_t __unused4; 193 __kernel_ulong_t __unused5; 194}; 195#endif /* defined(__x86_64__) && defined(__ILP32__) */ 196 197#if defined(__xtensa__) 198#define HAVE_SHMID64_DS 199#define HAVE_SHMID64_DS_TIME_HIGH 200/* 201 * The shmid64_ds structure for Xtensa architecture. 202 * Note extra padding because this structure is passed back and forth 203 * between kernel and user space, but the padding is on the wrong 204 * side for big-endian xtensa, for historic reasons. 205 * 206 * Pad space is left for: 207 * - 2 miscellaneous 32-bit values 208 */ 209 210struct shmid64_ds { 211 struct ipc64_perm shm_perm; /* operation perms */ 212 size_t shm_segsz; /* size of segment (bytes) */ 213 unsigned long shm_atime; /* last attach time */ 214 unsigned long shm_atime_high; 215 unsigned long shm_dtime; /* last detach time */ 216 unsigned long shm_dtime_high; 217 unsigned long shm_ctime; /* last change time */ 218 unsigned long shm_ctime_high; 219 __kernel_pid_t shm_cpid; /* pid of creator */ 220 __kernel_pid_t shm_lpid; /* pid of last operator */ 221 unsigned long shm_nattch; /* no. of current attaches */ 222 unsigned long __unused4; 223 unsigned long __unused5; 224}; 225 226#endif /* __xtensa__ */ 227 228#ifndef HAVE_SHMID64_DS 229/* 230 * The shmid64_ds structure for most architectures (though it came 231 * from x86_32 originally). Note extra padding because this structure 232 * is passed back and forth between kernel and user space. 233 * 234 * shmid64_ds was originally meant to be architecture specific, but 235 * everyone just ended up making identical copies without specific 236 * optimizations, so we may just as well all use the same one. 237 * 238 * 64 bit architectures use a 64-bit long time field here, while 239 * 32 bit architectures have a pair of unsigned long values. 240 * On big-endian systems, the lower half is in the wrong place. 241 * 242 * 243 * Pad space is left for: 244 * - 2 miscellaneous 32-bit values 245 */ 246 247struct shmid64_ds { 248 struct ipc64_perm shm_perm; /* operation perms */ 249 size_t shm_segsz; /* size of segment (bytes) */ 250#if __BITS_PER_LONG == 64 251 long shm_atime; /* last attach time */ 252 long shm_dtime; /* last detach time */ 253 long shm_ctime; /* last change time */ 254#else 255#define HAVE_SHMID64_DS_TIME_HIGH 256 unsigned long shm_atime; /* last attach time */ 257 unsigned long shm_atime_high; 258 unsigned long shm_dtime; /* last detach time */ 259 unsigned long shm_dtime_high; 260 unsigned long shm_ctime; /* last change time */ 261 unsigned long shm_ctime_high; 262#endif 263 __kernel_pid_t shm_cpid; /* pid of creator */ 264 __kernel_pid_t shm_lpid; /* pid of last operator */ 265 unsigned long shm_nattch; /* no. of current attaches */ 266 unsigned long __unused4; 267 unsigned long __unused5; 268}; 269#endif /* shmid64_ds */ 270 271#endif /* HAVE_SHMID64_DS */ 272 273#endif /* LAPI_SHMBUF_H__ */ 274