2 * Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
3 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
4 * Copyright (c) 2015-2019 The strace developers.
7 * SPDX-License-Identifier: GPL-2.0-or-later
19 #define text_string "STRACE_STRING"
20 #define msgsz sizeof(text_string)
22 static int msqid = -1;
25 # define str_ipc_creat "0x200"
26 # define str_ipc_private "0"
27 # define str_ipc_rmid "0"
28 # define str_ipc_64 "0x100"
30 # define str_ipc_creat "0x200 /\\* IPC_CREAT \\*/"
31 # define str_ipc_private "0 /\\* IPC_PRIVATE \\*/"
32 # define str_ipc_rmid "0 /\\* IPC_RMID \\*/"
33 # define str_ipc_64 "0x100 /\\* IPC_64 \\*/"
35 # define str_ipc_creat "IPC_CREAT"
36 # define str_ipc_private "IPC_PRIVATE"
37 # define str_ipc_rmid "IPC_RMID"
38 # define str_ipc_64 "IPC_64"
45 int rc = msgctl(msqid, IPC_RMID, 0);
46 printf("msgctl\\(%d, (%s\\|)?%s, NULL\\) = 0\n",
47 msqid, str_ipc_64, str_ipc_rmid);
51 puts("\\+\\+\\+ exited with 0 \\+\\+\\+");
57 sys_msgrcv(int msqid, void *msgp, size_t sz, kernel_long_t msgtyp,
60 #if defined __x86_64__ && defined __ILP32__
61 return syscall(__NR_msgrcv, msqid, msgp, sz, msgtyp, msgflg);
63 return msgrcv(msqid, msgp, sz, msgtyp, msgflg);
70 /* mtype has to be positive */
71 const kernel_long_t mtype = (kernel_long_t) 0x7facefed5adc0dedULL;
79 msqid = msgget(IPC_PRIVATE, IPC_CREAT | S_IRWXU);
81 perror_msg_and_skip("msgget");
82 printf("msgget\\(%s, %s\\|0700\\) = %d\n",
83 str_ipc_private, str_ipc_creat, msqid);
85 typedef void (*atexit_func)(void);
86 atexit((atexit_func) cleanup);
88 printf("msgsnd\\(%d, \\{%lld, \"" text_string "\\\\0\"\\}, 14, 0\\)"
90 msqid, (long long) mtype);
91 if (msgsnd(msqid, &msg, msgsz, 0) == -1)
92 perror_msg_and_skip("msgsnd");
94 if (sys_msgrcv(msqid, &msg, msgsz, -mtype, 0) != msgsz)
95 perror_msg_and_skip("msgrcv");
96 printf("msgrcv\\(%d, \\{%lld, \"" text_string "\\\\0\"\\}, 14, %lld"
98 msqid, (long long) mtype, -(long long) mtype);