The OpenD Programming Language

1 /**
2 * D header file for POSIX.
3 *
4 * Authors: Neven Miculinić
5 */
6 
7 module core.sys.posix.sys.msg;
8 
9 import core.sys.posix.config;
10 import core.sys.posix.sys.ipc;
11 import core.sys.posix.sys.types;
12 import core.stdc.config;
13 
14 version (CRuntime_Glibc):
15 // Some of these may be from linux kernel headers.
16 extern (C):
17 
18 version (ARM)     version = ARM_Any;
19 version (AArch64) version = ARM_Any;
20 version (HPPA)    version = HPPA_Any;
21 version (HPPA64)  version = HPPA_Any;
22 version (MIPS32)  version = MIPS_Any;
23 version (MIPS64)  version = MIPS_Any;
24 version (PPC)     version = PPC_Any;
25 version (PPC64)   version = PPC_Any;
26 version (RISCV32) version = RISCV_Any;
27 version (RISCV64) version = RISCV_Any;
28 version (S390)    version = IBMZ_Any;
29 version (SPARC)   version = SPARC_Any;
30 version (SPARC64) version = SPARC_Any;
31 version (SystemZ) version = IBMZ_Any;
32 
33 version (linux)
34 {
35     enum MSG_STAT = 11;
36     enum MSG_INFO = 12;
37 
38     enum MSG_NOERROR = 1 << 12; // octal!10000
39     enum  MSG_EXCEPT = 2 << 12; // octal!20000
40     enum    MSG_COPY = 4 << 12; // octal!40000
41 
42     struct msginfo
43     {
44         int msgpool;
45         int msgmap;
46         int msgmax;
47         int msgmnb;
48         int msgmni;
49         int msgssz;
50         int msgtql;
51         ushort msgseg;
52     }
53 
54     version (Alpha)     version = GENERICMSQ;
55     version (ARM_Any)   version = GENERICMSQ;
56     version (IA64)      version = GENERICMSQ;
57     version (IBMZ_Any)  version = GENERICMSQ;
58     version (RISCV_Any) version = GENERICMSQ;
59     version (LoongArch64) version = GENERICMSQ;
60 
61     version (GENERICMSQ)
62     {
63         // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/bits/msq-pad.h
64         private enum MSQ_PAD_AFTER_TIME = (__WORDSIZE == 32);
65         private enum MSQ_PAD_BEFORE_TIME = false;
66     }
67     else version (HPPA_Any)
68     {
69         // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/hppa/bits/msq-pad.h
70         private enum MSQ_PAD_AFTER_TIME = false;
71         private enum MSQ_PAD_BEFORE_TIME = (__WORDSIZE == 32);
72     }
73     else version (MIPS_Any)
74     {
75         // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/mips/bits/msq-pad.h
76         version (LittleEndian)
77         {
78             private enum MSQ_PAD_AFTER_TIME = (__WORDSIZE == 32);
79             private enum MSQ_PAD_BEFORE_TIME = false;
80         }
81         else
82         {
83             private enum MSQ_PAD_AFTER_TIME = false;
84             private enum MSQ_PAD_BEFORE_TIME = (__WORDSIZE == 32);
85         }
86     }
87     else version (PPC_Any)
88     {
89         //  https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/powerpc/bits/msq-pad.h
90         private enum MSQ_PAD_AFTER_TIME = false;
91         private enum MSQ_PAD_BEFORE_TIME = (__WORDSIZE == 32);
92     }
93     else version (SPARC_Any)
94     {
95         // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sparc/bits/msq-pad.h
96         private enum MSQ_PAD_AFTER_TIME = false;
97         private enum MSQ_PAD_BEFORE_TIME = (__WORDSIZE == 32);
98     }
99     else version (X86)
100     {
101         // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/x86/bits/msq-pad.h
102         private enum MSQ_PAD_AFTER_TIME = true;
103         private enum MSQ_PAD_BEFORE_TIME = false;
104     }
105     else version (X86_64)
106     {
107         // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/x86/bits/msq-pad.h
108         private enum MSQ_PAD_AFTER_TIME = false;
109         private enum MSQ_PAD_BEFORE_TIME = false;
110     }
111     else
112         static assert(0, "unimplemented");
113 
114     // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/bits/msq.h
115     alias msgqnum_t = ulong_t;
116     alias msglen_t = ulong_t;
117 
118     static if (MSQ_PAD_BEFORE_TIME)
119     {
120         struct msqid_ds
121         {
122             ipc_perm        msg_perm;
123             c_ulong __glibc_reserved1;
124             time_t          msg_stime;
125             c_ulong __glibc_reserved2;
126             time_t          msg_rtime;
127             c_ulong __glibc_reserved3;
128             time_t          msg_ctime;
129             ulong_t         __msg_cbytes;
130             msgqnum_t       msg_qnum;
131             msglen_t        msg_qbytes;
132             pid_t           msg_lspid;
133             pid_t           msg_lrpid;
134             ulong_t __glibc_reserved4;
135             ulong_t __glibc_reserved5;
136         }
137     }
138     else static if (MSQ_PAD_AFTER_TIME)
139     {
140         struct msqid_ds
141         {
142             ipc_perm        msg_perm;
143             time_t          msg_stime;
144             c_ulong __glibc_reserved1;
145             time_t          msg_rtime;
146             c_ulong __glibc_reserved2;
147             time_t          msg_ctime;
148             c_ulong __glibc_reserved3;
149             ulong_t         __msg_cbytes;
150             msgqnum_t       msg_qnum;
151             msglen_t        msg_qbytes;
152             pid_t           msg_lspid;
153             pid_t           msg_lrpid;
154             ulong_t __glibc_reserved4;
155             ulong_t __glibc_reserved5;
156         }
157     }
158     else
159     {
160         struct msqid_ds
161         {
162             ipc_perm        msg_perm;
163             time_t          msg_stime;
164             time_t          msg_rtime;
165             time_t          msg_ctime;
166             ulong_t         __msg_cbytes;
167             msgqnum_t       msg_qnum;
168             msglen_t        msg_qbytes;
169             pid_t           msg_lspid;
170             pid_t           msg_lrpid;
171             ulong_t __glibc_reserved4;
172             ulong_t __glibc_reserved5;
173         }
174     }
175 }
176 else
177 {
178     // https://sourceware.org/git/?p=glibc.git;a=blob;f=bits/msq.h
179     enum MSG_NOERROR = 1 << 12; // octal!10000
180 
181     alias msgqnum_t = ushort;
182     alias msglen_t = ushort;
183 
184     struct msqid_ds
185     {
186         ipc_perm msg_perm;
187         time_t          msg_stime;
188         time_t          msg_rtime;
189         time_t          msg_ctime;
190         msgqnum_t       msg_qnum;
191         msglen_t        msg_qbytes;
192         pid_t           msg_lspid;
193         pid_t           msg_lrpid;
194     }
195 }
196 
197 struct msgbuf
198 {
199     c_long mtype;
200     char[1] mtext = 0;
201 }
202 
203 int msgctl(int msqid, int cmd, msqid_ds* __buf);
204 int msgget(key_t key, int msgflg);
205 ssize_t msgrcv(int msqid, void* msgp, size_t msgsz, c_long msgtyp, int msgflg);
206 int msgsnd(int msqid, msgbuf* msgp, int msgsz, int msgflg);