• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <sys/msg.h>
2 #include <endian.h>
3 #include <unsupported_api.h>
4 
5 #include "syscall.h"
6 #include "ipc.h"
7 
8 #if __BYTE_ORDER != __BIG_ENDIAN
9 #undef SYSCALL_IPC_BROKEN_MODE
10 #endif
11 
msgctl(int q,int cmd,struct msqid_ds * buf)12 int msgctl(int q, int cmd, struct msqid_ds *buf)
13 {
14 #if IPC_TIME64
15 	struct msqid_ds out, *orig;
16 	if (cmd&IPC_TIME64) {
17 		out = (struct msqid_ds){0};
18 		orig = buf;
19 		buf = &out;
20 	}
21 #endif
22 	unsupported_api(__FUNCTION__);
23 #ifdef SYSCALL_IPC_BROKEN_MODE
24 	struct msqid_ds tmp;
25 	if (cmd == IPC_SET) {
26 		tmp = *buf;
27 		tmp.msg_perm.mode *= 0x10000U;
28 		buf = &tmp;
29 	}
30 #endif
31 #ifndef SYS_ipc
32 	int r = __syscall(SYS_msgctl, q, IPC_CMD(cmd), buf);
33 #else
34 	int r = __syscall(SYS_ipc, IPCOP_msgctl, q, IPC_CMD(cmd), 0, buf, 0);
35 #endif
36 #ifdef SYSCALL_IPC_BROKEN_MODE
37 	if (r >= 0) switch (cmd | IPC_TIME64) {
38 	case IPC_STAT:
39 	case MSG_STAT:
40 	case MSG_STAT_ANY:
41 		buf->msg_perm.mode >>= 16;
42 	}
43 #endif
44 #if IPC_TIME64
45 	if (r >= 0 && (cmd&IPC_TIME64)) {
46 		buf = orig;
47 		*buf = out;
48 		IPC_HILO(buf, msg_stime);
49 		IPC_HILO(buf, msg_rtime);
50 		IPC_HILO(buf, msg_ctime);
51 	}
52 #endif
53 	return __syscall_ret(r);
54 }
55