1 /* $NetBSD: msg.h,v 1.7 2023/02/12 16:28:32 andvar Exp $ */
2
3 /*
4 * SVID compatible msg.h file
5 *
6 * Author: Daniel Boulet
7 *
8 * Copyright 1993 Daniel Boulet and RTMX Inc.
9 *
10 * This system call was implemented by Daniel Boulet under contract from RTMX.
11 *
12 * Redistribution and use in source forms, with and without modification,
13 * are permitted provided that this entire comment appears intact.
14 *
15 * Redistribution in binary form may occur without any restrictions.
16 * Obviously, it would be nice if you gave credit where credit is due
17 * but requiring it would be too onerous.
18 *
19 * This software is provided ``AS IS'' without any warranties of any kind.
20 */
21
22 #ifndef _COMPAT_SYS_MSG_H_
23 #define _COMPAT_SYS_MSG_H_
24
25 #include <compat/sys/ipc.h>
26 /*
27 * Old message queue data structure used before NetBSD 1.5.
28 */
29 struct msqid_ds14 {
30 struct ipc_perm14 msg_perm; /* msg queue permission bits */
31 struct __msg *msg_first; /* first message in the queue */
32 struct __msg *msg_last; /* last message in the queue */
33 u_long msg_cbytes; /* number of bytes in use on the queue */
34 u_long msg_qnum; /* number of msgs in the queue */
35 u_long msg_qbytes; /* max # of bytes on the queue */
36 pid_t msg_lspid; /* pid of last msgsnd() */
37 pid_t msg_lrpid; /* pid of last msgrcv() */
38 int32_t msg_stime; /* time of last msgsnd() */
39 long msg_pad1;
40 int32_t msg_rtime; /* time of last msgrcv() */
41 long msg_pad2;
42 int32_t msg_ctime; /* time of last msgctl() */
43 long msg_pad3;
44 long msg_pad4[4];
45 };
46
47 struct msqid_ds13 {
48 struct ipc_perm msg_perm; /* operation permission structure */
49 msgqnum_t msg_qnum; /* number of messages in the queue */
50 msglen_t msg_qbytes; /* max # of bytes in the queue */
51 pid_t msg_lspid; /* process ID of last msgsend() */
52 pid_t msg_lrpid; /* process ID of last msgrcv() */
53 int32_t msg_stime; /* time of last msgsend() */
54 int32_t msg_rtime; /* time of last msgrcv() */
55 int32_t msg_ctime; /* time of last change */
56
57 /*
58 * These members are private and used only in the internal
59 * implementation of this interface.
60 */
61 struct __msg *_msg_first; /* first message in the queue */
62 struct __msg *_msg_last; /* last message in the queue */
63 msglen_t _msg_cbytes; /* # of bytes currently in queue */
64 };
65
66 /* Warning: 64-bit structure padding is needed here */
67 struct msgid_ds_sysctl50 {
68 struct ipc_perm_sysctl msg_perm;
69 uint64_t msg_qnum;
70 uint64_t msg_qbytes;
71 uint64_t _msg_cbytes;
72 pid_t msg_lspid;
73 pid_t msg_lrpid;
74 int32_t msg_stime;
75 int32_t msg_rtime;
76 int32_t msg_ctime;
77 int32_t pad;
78 };
79 struct msg_sysctl_info50 {
80 struct msginfo msginfo;
81 struct msgid_ds_sysctl50 msgids[1];
82 };
83
84 __BEGIN_DECLS
85 static __inline void __msqid_ds14_to_native(const struct msqid_ds14 *, struct msqid_ds *);
86 static __inline void __native_to_msqid_ds14(const struct msqid_ds *, struct msqid_ds14 *);
87 static __inline void __msqid_ds13_to_native(const struct msqid_ds13 *, struct msqid_ds *);
88 static __inline void __native_to_msqid_ds13(const struct msqid_ds *, struct msqid_ds13 *);
89
90 static __inline void
__msqid_ds13_to_native(const struct msqid_ds13 * omsqbuf,struct msqid_ds * msqbuf)91 __msqid_ds13_to_native(const struct msqid_ds13 *omsqbuf, struct msqid_ds *msqbuf)
92 {
93
94 memset(msqbuf, 0, sizeof *msqbuf);
95 msqbuf->msg_perm = omsqbuf->msg_perm;
96
97 #define CVT(x) msqbuf->x = omsqbuf->x
98 CVT(msg_qnum);
99 CVT(msg_qbytes);
100 CVT(msg_lspid);
101 CVT(msg_lrpid);
102 CVT(msg_stime);
103 CVT(msg_rtime);
104 CVT(msg_ctime);
105 #undef CVT
106 }
107
108 static __inline void
__native_to_msqid_ds13(const struct msqid_ds * msqbuf,struct msqid_ds13 * omsqbuf)109 __native_to_msqid_ds13(const struct msqid_ds *msqbuf, struct msqid_ds13 *omsqbuf)
110 {
111
112 memset(omsqbuf, 0, sizeof(*omsqbuf));
113 omsqbuf->msg_perm = msqbuf->msg_perm;
114
115 #define CVT(x) omsqbuf->x = msqbuf->x
116 #define CVTI(x) omsqbuf->x = (int)msqbuf->x
117 CVT(msg_qnum);
118 CVT(msg_qbytes);
119 CVT(msg_lspid);
120 CVT(msg_lrpid);
121 CVTI(msg_stime);
122 CVTI(msg_rtime);
123 CVTI(msg_ctime);
124 #undef CVT
125 #undef CVTI
126
127 /*
128 * Not part of the API, but some programs might look at it.
129 */
130 omsqbuf->_msg_cbytes = msqbuf->_msg_cbytes;
131 }
132
133 static __inline void
__msqid_ds14_to_native(const struct msqid_ds14 * omsqbuf,struct msqid_ds * msqbuf)134 __msqid_ds14_to_native(const struct msqid_ds14 *omsqbuf, struct msqid_ds *msqbuf)
135 {
136
137 memset(msqbuf, 0, sizeof *msqbuf);
138 __ipc_perm14_to_native(&omsqbuf->msg_perm, &msqbuf->msg_perm);
139
140 #define CVT(x) msqbuf->x = omsqbuf->x
141 CVT(msg_qnum);
142 CVT(msg_qbytes);
143 CVT(msg_lspid);
144 CVT(msg_lrpid);
145 CVT(msg_stime);
146 CVT(msg_rtime);
147 CVT(msg_ctime);
148 #undef CVT
149 }
150
151 static __inline void
__native_to_msqid_ds14(const struct msqid_ds * msqbuf,struct msqid_ds14 * omsqbuf)152 __native_to_msqid_ds14(const struct msqid_ds *msqbuf, struct msqid_ds14 *omsqbuf)
153 {
154
155 memset(omsqbuf, 0, sizeof *omsqbuf);
156 __native_to_ipc_perm14(&msqbuf->msg_perm, &omsqbuf->msg_perm);
157
158 #define CVT(x) omsqbuf->x = msqbuf->x
159 #define CVTI(x) omsqbuf->x = (int)msqbuf->x
160 CVT(msg_qnum);
161 CVT(msg_qbytes);
162 CVT(msg_lspid);
163 CVT(msg_lrpid);
164 CVTI(msg_stime);
165 CVTI(msg_rtime);
166 CVTI(msg_ctime);
167 #undef CVT
168 #undef CVTI
169 }
170
171 int __msgctl13(int, int, struct msqid_ds13 *);
172 int __msgctl14(int, int, struct msqid_ds14 *);
173 int __msgctl50(int, int, struct msqid_ds *);
174 __END_DECLS
175
176 #endif /* !_COMPAT_SYS_MSG_H_ */
177