1/*	$NetBSD: shm.h,v 1.6 2009/01/19 19:39:41 christos 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
43struct 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
55struct 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 */
73struct 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};
83struct shm_sysctl_info50 {
84	struct	shminfo shminfo;
85	struct	shmid_ds_sysctl50 shmids[1];
86};
87
88__BEGIN_DECLS
89static __inline void	__shmid_ds14_to_native(const struct shmid_ds14 *, struct shmid_ds *);
90static __inline void	__native_to_shmid_ds14(const struct shmid_ds *, struct shmid_ds14 *);
91static __inline void	__shmid_ds13_to_native(const struct shmid_ds13 *, struct shmid_ds *);
92static __inline void	__native_to_shmid_ds13(const struct shmid_ds *, struct shmid_ds13 *);
93static __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
110static __inline void
111__native_to_shmid_ds14(const struct shmid_ds *shmbuf, struct shmid_ds14 *oshmbuf)
112{
113
114	__native_to_ipc_perm14(&shmbuf->shm_perm, &oshmbuf->shm_perm);
115
116#define	CVT(x)	oshmbuf->x = shmbuf->x
117#define	CVTI(x)	oshmbuf->x = (int)shmbuf->x
118	CVTI(shm_segsz);
119	CVT(shm_lpid);
120	CVT(shm_cpid);
121	CVT(shm_nattch);
122	CVTI(shm_atime);
123	CVTI(shm_dtime);
124	CVTI(shm_ctime);
125#undef CVT
126#undef CVTI
127}
128
129static __inline void
130__shmid_ds13_to_native(const struct shmid_ds13 *oshmbuf, struct shmid_ds *shmbuf)
131{
132
133	shmbuf->shm_perm = oshmbuf->shm_perm;
134
135#define	CVT(x)	shmbuf->x = oshmbuf->x
136	CVT(shm_segsz);
137	CVT(shm_lpid);
138	CVT(shm_cpid);
139	CVT(shm_nattch);
140	CVT(shm_atime);
141	CVT(shm_dtime);
142	CVT(shm_ctime);
143#undef CVT
144}
145
146static __inline void
147__native_to_shmid_ds13(const struct shmid_ds *shmbuf, struct shmid_ds13 *oshmbuf)
148{
149
150	oshmbuf->shm_perm = shmbuf->shm_perm;
151
152#define	CVT(x)	oshmbuf->x = shmbuf->x
153#define	CVTI(x)	oshmbuf->x = (int)shmbuf->x
154	CVT(shm_segsz);
155	CVT(shm_lpid);
156	CVT(shm_cpid);
157	CVT(shm_nattch);
158	CVTI(shm_atime);
159	CVTI(shm_dtime);
160	CVTI(shm_ctime);
161#undef CVT
162#undef CVTI
163}
164
165int	__shmctl13(int, int, struct shmid_ds13 *);
166int	__shmctl14(int, int, struct shmid_ds14 *);
167int	__shmctl50(int, int, struct shmid_ds *);
168__END_DECLS
169
170#endif /* !_COMPAT_SYS_SHM_H_ */
171