2 * Copyright (c) 2015 Elvira Khabirova <lineprinter0@gmail.com>
3 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
4 * Copyright (c) 2015-2017 The strace developers.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <asm/unistd.h>
39 #define text_string "STRACE_STRING"
40 #define msgsz sizeof(text_string)
42 static int msqid = -1;
45 # define str_ipc_creat "0x200"
46 # define str_ipc_private "0"
47 # define str_ipc_rmid "0"
48 # define str_ipc_64 "0x100"
50 # define str_ipc_creat "0x200 /\\* IPC_CREAT \\*/"
51 # define str_ipc_private "0 /\\* IPC_PRIVATE \\*/"
52 # define str_ipc_rmid "0 /\\* IPC_RMID \\*/"
53 # define str_ipc_64 "0x100 /\\* IPC_64 \\*/"
55 # define str_ipc_creat "IPC_CREAT"
56 # define str_ipc_private "IPC_PRIVATE"
57 # define str_ipc_rmid "IPC_RMID"
58 # define str_ipc_64 "IPC_64"
65 int rc = msgctl(msqid, IPC_RMID, 0);
66 printf("msgctl\\(%d, (%s\\|)?%s, NULL\\) = 0\n",
67 msqid, str_ipc_64, str_ipc_rmid);
71 puts("\\+\\+\\+ exited with 0 \\+\\+\\+");
77 sys_msgrcv(int msqid, void *msgp, size_t sz, kernel_long_t msgtyp,
80 #if defined __x86_64__ && defined __ILP32__
81 return syscall(__NR_msgrcv, msqid, msgp, sz, msgtyp, msgflg);
83 return msgrcv(msqid, msgp, sz, msgtyp, msgflg);
90 /* mtype has to be positive */
91 const kernel_long_t mtype = (kernel_long_t) 0x7facefed5adc0dedULL;
99 msqid = msgget(IPC_PRIVATE, IPC_CREAT | S_IRWXU);
101 perror_msg_and_skip("msgget");
102 printf("msgget\\(%s, %s\\|0700\\) = %d\n",
103 str_ipc_private, str_ipc_creat, msqid);
105 typedef void (*atexit_func)(void);
106 atexit((atexit_func) cleanup);
108 printf("msgsnd\\(%d, \\{%lld, \"" text_string "\\\\0\"\\}, 14, 0\\)"
110 msqid, (long long) mtype);
111 if (msgsnd(msqid, &msg, msgsz, 0) == -1)
112 perror_msg_and_skip("msgsnd");
114 if (sys_msgrcv(msqid, &msg, msgsz, -mtype, 0) != msgsz)
115 perror_msg_and_skip("msgrcv");
116 printf("msgrcv\\(%d, \\{%lld, \"" text_string "\\\\0\"\\}, 14, %lld"
118 msqid, (long long) mtype, -(long long) mtype);