1/* $NetBSD: msg.h,v 1.4 2009/01/19 19:39:41 christos 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 */
29struct 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
47struct msqid_ds13 {
48 struct ipc_perm msg_perm; /* operation permission strucure */
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 */
67struct 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};
79struct msg_sysctl_info50 {
80 struct msginfo msginfo;
81 struct msgid_ds_sysctl50 msgids[1];
82};
83
84__BEGIN_DECLS
85static __inline void __msqid_ds14_to_native(const struct msqid_ds14 *, struct msqid_ds *);
86static __inline void __native_to_msqid_ds14(const struct msqid_ds *, struct msqid_ds14 *);
87static __inline void __msqid_ds13_to_native(const struct msqid_ds13 *, struct msqid_ds *);
88static __inline void __native_to_msqid_ds13(const struct msqid_ds *, struct msqid_ds13 *);
89
90static __inline void
91__msqid_ds13_to_native(const struct msqid_ds13 *omsqbuf, struct msqid_ds *msqbuf)
92{
93
94 msqbuf->msg_perm = omsqbuf->msg_perm;
95
96#define CVT(x) msqbuf->x = omsqbuf->x
97 CVT(msg_qnum);
98 CVT(msg_qbytes);
99 CVT(msg_lspid);
100 CVT(msg_lrpid);
101 CVT(msg_stime);
102 CVT(msg_rtime);
103 CVT(msg_ctime);
104#undef CVT
105}
106
107static __inline void
108__native_to_msqid_ds13(const struct msqid_ds *msqbuf, struct msqid_ds13 *omsqbuf)
109{
110
111 omsqbuf->msg_perm = msqbuf->msg_perm;
112
113#define CVT(x) omsqbuf->x = msqbuf->x
114#define CVTI(x) omsqbuf->x = (int)msqbuf->x
115 CVT(msg_qnum);
116 CVT(msg_qbytes);
117 CVT(msg_lspid);
118 CVT(msg_lrpid);
119 CVTI(msg_stime);
120 CVTI(msg_rtime);
121 CVTI(msg_ctime);
122#undef CVT
123#undef CVTI
124
125 /*
126 * Not part of the API, but some programs might look at it.
127 */
128 omsqbuf->_msg_cbytes = msqbuf->_msg_cbytes;
129}
130
131static __inline void
132__msqid_ds14_to_native(const struct msqid_ds14 *omsqbuf, struct msqid_ds *msqbuf)
133{
134
135 __ipc_perm14_to_native(&omsqbuf->msg_perm, &msqbuf->msg_perm);
136
137#define CVT(x) msqbuf->x = omsqbuf->x
138 CVT(msg_qnum);
139 CVT(msg_qbytes);
140 CVT(msg_lspid);
141 CVT(msg_lrpid);
142 CVT(msg_stime);
143 CVT(msg_rtime);
144 CVT(msg_ctime);
145#undef CVT
146}
147
148static __inline void
149__native_to_msqid_ds14(const struct msqid_ds *msqbuf, struct msqid_ds14 *omsqbuf)
150{
151
152 __native_to_ipc_perm14(&msqbuf->msg_perm, &omsqbuf->msg_perm);
153
154#define CVT(x) omsqbuf->x = msqbuf->x
155#define CVTI(x) omsqbuf->x = (int)msqbuf->x
156 CVT(msg_qnum);
157 CVT(msg_qbytes);
158 CVT(msg_lspid);
159 CVT(msg_lrpid);
160 CVTI(msg_stime);
161 CVTI(msg_rtime);
162 CVTI(msg_ctime);
163#undef CVT
164#undef CVTI
165}
166
167int __msgctl13(int, int, struct msqid_ds13 *);
168int __msgctl14(int, int, struct msqid_ds14 *);
169int __msgctl50(int, int, struct msqid_ds *);
170__END_DECLS
171
172#endif /* !_COMPAT_SYS_MSG_H_ */
173