xref: /linux/tools/perf/trace/beauty/msg_flags.c (revision 537609924c43715e39a41762d3e3d3c7c534bb71)
1 // SPDX-License-Identifier: LGPL-2.1
2 #include "trace/beauty/beauty.h"
3 
4 #include <sys/types.h>
5 #include <sys/socket.h>
6 
7 #ifndef MSG_PROBE
8 #define MSG_PROBE		     0x10
9 #endif
10 #ifndef MSG_WAITFORONE
11 #define MSG_WAITFORONE		   0x10000
12 #endif
13 #ifndef MSG_BATCH
14 #define MSG_BATCH		   0x40000
15 #endif
16 #ifndef MSG_SOCK_DEVMEM
17 #define MSG_SOCK_DEVMEM		 0x2000000
18 #endif
19 #ifndef MSG_ZEROCOPY
20 #define MSG_ZEROCOPY		 0x4000000
21 #endif
22 #ifndef MSG_SPLICE_PAGES
23 #define MSG_SPLICE_PAGES	0x8000000
24 #endif
25 #ifndef MSG_FASTOPEN
26 #define MSG_FASTOPEN		0x20000000
27 #endif
28 #ifndef MSG_CMSG_CLOEXEC
29 # define MSG_CMSG_CLOEXEC	0x40000000
30 #endif
31 
32 size_t syscall_arg__scnprintf_msg_flags(char *bf, size_t size,
33 					struct syscall_arg *arg)
34 {
35 	bool show_prefix = arg->show_string_prefix;
36 	const char *prefix = "MSG_";
37 	int printed = 0, flags = arg->val;
38 
39 	if (flags == 0)
40 		return scnprintf(bf, size, "NONE");
41 #define	P_MSG_FLAG(n) \
42 	if (flags & MSG_##n) { \
43 		printed += scnprintf(bf + printed, size - printed, "%s%s%s", printed ? "|" : "", show_prefix ? prefix : "", #n); \
44 		flags &= ~MSG_##n; \
45 	}
46 
47 	P_MSG_FLAG(OOB);
48 	P_MSG_FLAG(PEEK);
49 	P_MSG_FLAG(DONTROUTE);
50 	P_MSG_FLAG(CTRUNC);
51 	P_MSG_FLAG(PROBE);
52 	P_MSG_FLAG(TRUNC);
53 	P_MSG_FLAG(DONTWAIT);
54 	P_MSG_FLAG(EOR);
55 	P_MSG_FLAG(WAITALL);
56 	P_MSG_FLAG(FIN);
57 	P_MSG_FLAG(SYN);
58 	P_MSG_FLAG(CONFIRM);
59 	P_MSG_FLAG(RST);
60 	P_MSG_FLAG(ERRQUEUE);
61 	P_MSG_FLAG(NOSIGNAL);
62 	P_MSG_FLAG(MORE);
63 	P_MSG_FLAG(WAITFORONE);
64 	P_MSG_FLAG(BATCH);
65 	P_MSG_FLAG(SOCK_DEVMEM);
66 	P_MSG_FLAG(ZEROCOPY);
67 	P_MSG_FLAG(SPLICE_PAGES);
68 	P_MSG_FLAG(FASTOPEN);
69 	P_MSG_FLAG(CMSG_CLOEXEC);
70 #undef P_MSG_FLAG
71 
72 	if (flags)
73 		printed += scnprintf(bf + printed, size - printed, "%s%#x", printed ? "|" : "", flags);
74 
75 	return printed;
76 }
77