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