flags.c revision a8429c675016730a11cea73afad8801086df9905
1/*
2 * Copyright (c) 2006 "David Kirchner" <dpk@dpk.net>. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26#include <sys/cdefs.h>
27__FBSDID("$FreeBSD$");
28
29#define L2CAP_SOCKET_CHECKED
30
31#include <sys/types.h>
32#include <sys/acl.h>
33#include <sys/capsicum.h>
34#include <sys/extattr.h>
35#include <sys/linker.h>
36#include <sys/mman.h>
37#include <sys/mount.h>
38#include <sys/procctl.h>
39#include <sys/ptrace.h>
40#include <sys/reboot.h>
41#include <sys/resource.h>
42#include <sys/rtprio.h>
43#include <sys/sem.h>
44#include <sys/shm.h>
45#include <sys/socket.h>
46#include <sys/stat.h>
47#include <sys/thr.h>
48#include <sys/umtx.h>
49#include <netinet/in.h>
50#include <netinet/tcp.h>
51#include <netinet/udp.h>
52#include <nfsserver/nfs.h>
53#include <ufs/ufs/quota.h>
54#include <vm/vm.h>
55#include <vm/vm_param.h>
56#include <aio.h>
57#include <fcntl.h>
58#include <sched.h>
59#include <stdbool.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <strings.h>
63#include <sysdecode.h>
64#include <unistd.h>
65#include <sys/bitstring.h>
66#include <netgraph/bluetooth/include/ng_hci.h>
67#include <netgraph/bluetooth/include/ng_l2cap.h>
68#include <netgraph/bluetooth/include/ng_btsocket.h>
69
70/*
71 * This is taken from the xlat tables originally in truss which were
72 * in turn taken from strace.
73 */
74struct name_table {
75	uintmax_t val;
76	const char *str;
77};
78
79#define	X(a)	{ a, #a },
80#define	XEND	{ 0, NULL }
81
82#define	TABLE_START(n)	static struct name_table n[] = {
83#define	TABLE_ENTRY	X
84#define	TABLE_END	XEND };
85
86#include "tables.h"
87
88#undef TABLE_START
89#undef TABLE_ENTRY
90#undef TABLE_END
91
92/*
93 * These are simple support macros. print_or utilizes a variable
94 * defined in the calling function to track whether or not it should
95 * print a logical-OR character ('|') before a string. if_print_or
96 * simply handles the necessary "if" statement used in many lines
97 * of this file.
98 */
99#define print_or(fp,str,orflag) do {                     \
100	if (orflag) fputc(fp, '|'); else orflag = true;  \
101	fprintf(fp, str); }                              \
102	while (0)
103#define if_print_or(fp,i,flag,orflag) do {         \
104	if ((i & flag) == flag)                    \
105	print_or(fp,#flag,orflag); }               \
106	while (0)
107
108static const char *
109lookup_value(struct name_table *table, uintmax_t val)
110{
111
112	for (; table->str != NULL; table++)
113		if (table->val == val)
114			return (table->str);
115	return (NULL);
116}
117
118/*
119 * Used when the value maps to a bitmask of #definition values in the
120 * table.  This is a helper routine which outputs a symbolic mask of
121 * matched masks.  Multiple masks are separated by a pipe ('|').
122 * The value is modified on return to only hold unmatched bits.
123 */
124static void
125print_mask_part(FILE *fp, struct name_table *table, uintmax_t *valp,
126    bool *printed)
127{
128	uintmax_t rem;
129
130	rem = *valp;
131	for (; table->str != NULL; table++) {
132		if ((table->val & rem) == table->val) {
133			/*
134			 * Only print a zero mask if the raw value is
135			 * zero.
136			 */
137			if (table->val == 0 && *valp != 0)
138				continue;
139			fprintf(fp, "%s%s", *printed ? "|" : "", table->str);
140			*printed = true;
141			rem &= ~table->val;
142		}
143	}
144
145	*valp = rem;
146}
147
148/*
149 * Used when the value maps to a bitmask of #definition values in the
150 * table.  The return value is true if something was printed.  If
151 * rem is not NULL, *rem holds any bits not decoded if something was
152 * printed.  If nothing was printed and rem is not NULL, *rem holds
153 * the original value.
154 */
155static bool
156print_mask_int(FILE *fp, struct name_table *table, int ival, int *rem)
157{
158	uintmax_t val;
159	bool printed;
160
161	printed = false;
162	val = (unsigned)ival;
163	print_mask_part(fp, table, &val, &printed);
164	if (rem != NULL)
165		*rem = val;
166	return (printed);
167}
168
169/*
170 * Used for a mask of optional flags where a value of 0 is valid.
171 */
172static bool
173print_mask_0(FILE *fp, struct name_table *table, int val, int *rem)
174{
175
176	if (val == 0) {
177		fputs("0", fp);
178		if (rem != NULL)
179			*rem = 0;
180		return (true);
181	}
182	return (print_mask_int(fp, table, val, rem));
183}
184
185/*
186 * Like print_mask_0 but for a unsigned long instead of an int.
187 */
188static bool
189print_mask_0ul(FILE *fp, struct name_table *table, u_long lval, u_long *rem)
190{
191	uintmax_t val;
192	bool printed;
193
194	if (lval == 0) {
195		fputs("0", fp);
196		if (rem != NULL)
197			*rem = 0;
198		return (true);
199	}
200
201	printed = false;
202	val = lval;
203	print_mask_part(fp, table, &val, &printed);
204	if (rem != NULL)
205		*rem = val;
206	return (printed);
207}
208
209static void
210print_integer(FILE *fp, int val, int base)
211{
212
213	switch (base) {
214	case 8:
215		fprintf(fp, "0%o", val);
216		break;
217	case 10:
218		fprintf(fp, "%d", val);
219		break;
220	case 16:
221		fprintf(fp, "0x%x", val);
222		break;
223	default:
224		abort2("bad base", 0, NULL);
225		break;
226	}
227}
228
229static bool
230print_value(FILE *fp, struct name_table *table, uintmax_t val)
231{
232	const char *str;
233
234	str = lookup_value(table, val);
235	if (str != NULL) {
236		fputs(str, fp);
237		return (true);
238	}
239	return (false);
240}
241
242const char *
243sysdecode_atfd(int fd)
244{
245
246	if (fd == AT_FDCWD)
247		return ("AT_FDCWD");
248	return (NULL);
249}
250
251static struct name_table semctlops[] = {
252	X(GETNCNT) X(GETPID) X(GETVAL) X(GETALL) X(GETZCNT) X(SETVAL) X(SETALL)
253	X(IPC_RMID) X(IPC_SET) X(IPC_STAT) XEND
254};
255
256const char *
257sysdecode_semctl_cmd(int cmd)
258{
259
260	return (lookup_value(semctlops, cmd));
261}
262
263static struct name_table shmctlops[] = {
264	X(IPC_RMID) X(IPC_SET) X(IPC_STAT) XEND
265};
266
267const char *
268sysdecode_shmctl_cmd(int cmd)
269{
270
271	return (lookup_value(shmctlops, cmd));
272}
273
274const char *
275sysdecode_msgctl_cmd(int cmd)
276{
277
278	return (sysdecode_shmctl_cmd(cmd));
279}
280
281static struct name_table semgetflags[] = {
282	X(IPC_CREAT) X(IPC_EXCL) X(SEM_R) X(SEM_A) X((SEM_R>>3)) X((SEM_A>>3))
283	X((SEM_R>>6)) X((SEM_A>>6)) XEND
284};
285
286bool
287sysdecode_semget_flags(FILE *fp, int flag, int *rem)
288{
289
290	return (print_mask_int(fp, semgetflags, flag, rem));
291}
292
293static struct name_table idtypes[] = {
294	X(P_PID) X(P_PPID) X(P_PGID) X(P_SID) X(P_CID) X(P_UID) X(P_GID)
295	X(P_ALL) X(P_LWPID) X(P_TASKID) X(P_PROJID) X(P_POOLID) X(P_JAILID)
296	X(P_CTID) X(P_CPUID) X(P_PSETID) XEND
297};
298
299/* XXX: idtype is really an idtype_t */
300const char *
301sysdecode_idtype(int idtype)
302{
303
304	return (lookup_value(idtypes, idtype));
305}
306
307/*
308 * [g|s]etsockopt's level argument can either be SOL_SOCKET or a
309 * protocol-specific value.
310 */
311const char *
312sysdecode_sockopt_level(int level)
313{
314	const char *str;
315
316	if (level == SOL_SOCKET)
317		return ("SOL_SOCKET");
318
319	/* SOL_* constants for Bluetooth sockets. */
320	str = lookup_value(ngbtsolevel, level);
321	if (str != NULL)
322		return (str);
323
324	/*
325	 * IP and Infiniband sockets use IP protocols as levels.  Not all
326	 * protocols are valid but it is simpler to just allow all of them.
327	 *
328	 * XXX: IPPROTO_IP == 0, but UNIX domain sockets use a level of 0
329	 * for private options.
330	 */
331	str = sysdecode_ipproto(level);
332	if (str != NULL)
333		return (str);
334
335	return (NULL);
336}
337
338bool
339sysdecode_vmprot(FILE *fp, int type, int *rem)
340{
341
342	return (print_mask_int(fp, vmprot, type, rem));
343}
344
345static struct name_table sockflags[] = {
346	X(SOCK_CLOEXEC) X(SOCK_NONBLOCK) XEND
347};
348
349bool
350sysdecode_socket_type(FILE *fp, int type, int *rem)
351{
352	const char *str;
353	uintmax_t val;
354	bool printed;
355
356	str = lookup_value(socktype, type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK));
357	if (str != NULL) {
358		fputs(str, fp);
359		*rem = 0;
360		printed = true;
361	} else {
362		*rem = type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK);
363		printed = false;
364	}
365	val = type & (SOCK_CLOEXEC | SOCK_NONBLOCK);
366	print_mask_part(fp, sockflags, &val, &printed);
367	return (printed);
368}
369
370bool
371sysdecode_access_mode(FILE *fp, int mode, int *rem)
372{
373
374	return (print_mask_int(fp, accessmode, mode, rem));
375}
376
377/* XXX: 'type' is really an acl_type_t. */
378const char *
379sysdecode_acltype(int type)
380{
381
382	return (lookup_value(acltype, type));
383}
384
385bool
386sysdecode_cap_fcntlrights(FILE *fp, uint32_t rights, uint32_t *rem)
387{
388
389	return (print_mask_int(fp, capfcntl, rights, rem));
390}
391
392const char *
393sysdecode_extattrnamespace(int namespace)
394{
395
396	return (lookup_value(extattrns, namespace));
397}
398
399const char *
400sysdecode_fadvice(int advice)
401{
402
403	return (lookup_value(fadvisebehav, advice));
404}
405
406bool
407sysdecode_open_flags(FILE *fp, int flags, int *rem)
408{
409	bool printed;
410	int mode;
411	uintmax_t val;
412
413	mode = flags & O_ACCMODE;
414	flags &= ~O_ACCMODE;
415	switch (mode) {
416	case O_RDONLY:
417		if (flags & O_EXEC) {
418			flags &= ~O_EXEC;
419			fputs("O_EXEC", fp);
420		} else
421			fputs("O_RDONLY", fp);
422		printed = true;
423		mode = 0;
424		break;
425	case O_WRONLY:
426		fputs("O_WRONLY", fp);
427		printed = true;
428		mode = 0;
429		break;
430	case O_RDWR:
431		fputs("O_RDWR", fp);
432		printed = true;
433		mode = 0;
434		break;
435	default:
436		printed = false;
437	}
438	val = (unsigned)flags;
439	print_mask_part(fp, openflags, &val, &printed);
440	if (rem != NULL)
441		*rem = val | mode;
442	return (printed);
443}
444
445bool
446sysdecode_fcntl_fileflags(FILE *fp, int flags, int *rem)
447{
448	bool printed;
449	int oflags;
450
451	/*
452	 * The file flags used with F_GETFL/F_SETFL mostly match the
453	 * flags passed to open(2).  However, a few open-only flag
454	 * bits have been repurposed for fcntl-only flags.
455	 */
456	oflags = flags & ~(O_NOFOLLOW | FRDAHEAD);
457	printed = sysdecode_open_flags(fp, oflags, rem);
458	if (flags & O_NOFOLLOW) {
459		fprintf(fp, "%sFPOIXSHM", printed ? "|" : "");
460		printed = true;
461	}
462	if (flags & FRDAHEAD) {
463		fprintf(fp, "%sFRDAHEAD", printed ? "|" : "");
464		printed = true;
465	}
466	return (printed);
467}
468
469bool
470sysdecode_flock_operation(FILE *fp, int operation, int *rem)
471{
472
473	return (print_mask_int(fp, flockops, operation, rem));
474}
475
476static struct name_table getfsstatmode[] = {
477	X(MNT_WAIT) X(MNT_NOWAIT) XEND
478};
479
480const char *
481sysdecode_getfsstat_mode(int mode)
482{
483
484	return (lookup_value(getfsstatmode, mode));
485}
486
487const char *
488sysdecode_kldsym_cmd(int cmd)
489{
490
491	return (lookup_value(kldsymcmd, cmd));
492}
493
494const char *
495sysdecode_kldunload_flags(int flags)
496{
497
498	return (lookup_value(kldunloadfflags, flags));
499}
500
501const char *
502sysdecode_lio_listio_mode(int mode)
503{
504
505	return (lookup_value(lio_listiomodes, mode));
506}
507
508const char *
509sysdecode_madvice(int advice)
510{
511
512	return (lookup_value(madvisebehav, advice));
513}
514
515const char *
516sysdecode_minherit_inherit(int inherit)
517{
518
519	return (lookup_value(minheritflags, inherit));
520}
521
522bool
523sysdecode_mlockall_flags(FILE *fp, int flags, int *rem)
524{
525
526	return (print_mask_int(fp, mlockallflags, flags, rem));
527}
528
529bool
530sysdecode_mmap_prot(FILE *fp, int prot, int *rem)
531{
532
533	return (print_mask_int(fp, mmapprot, prot, rem));
534}
535
536bool
537sysdecode_fileflags(FILE *fp, fflags_t flags, fflags_t *rem)
538{
539
540	return (print_mask_0(fp, fileflags, flags, rem));
541}
542
543bool
544sysdecode_filemode(FILE *fp, int mode, int *rem)
545{
546
547	return (print_mask_0(fp, filemode, mode, rem));
548}
549
550bool
551sysdecode_mount_flags(FILE *fp, int flags, int *rem)
552{
553
554	return (print_mask_int(fp, mountflags, flags, rem));
555}
556
557bool
558sysdecode_msync_flags(FILE *fp, int flags, int *rem)
559{
560
561	return (print_mask_int(fp, msyncflags, flags, rem));
562}
563
564const char *
565sysdecode_nfssvc_flags(int flags)
566{
567
568	return (lookup_value(nfssvcflags, flags));
569}
570
571static struct name_table pipe2flags[] = {
572	X(O_CLOEXEC) X(O_NONBLOCK) XEND
573};
574
575bool
576sysdecode_pipe2_flags(FILE *fp, int flags, int *rem)
577{
578
579	return (print_mask_0(fp, pipe2flags, flags, rem));
580}
581
582const char *
583sysdecode_prio_which(int which)
584{
585
586	return (lookup_value(prio, which));
587}
588
589const char *
590sysdecode_procctl_cmd(int cmd)
591{
592
593	return (lookup_value(procctlcmd, cmd));
594}
595
596const char *
597sysdecode_ptrace_request(int request)
598{
599
600	return (lookup_value(ptraceop, request));
601}
602
603static struct name_table quotatypes[] = {
604	X(GRPQUOTA) X(USRQUOTA) XEND
605};
606
607bool
608sysdecode_quotactl_cmd(FILE *fp, int cmd)
609{
610	const char *primary, *type;
611
612	primary = lookup_value(quotactlcmds, cmd >> SUBCMDSHIFT);
613	if (primary == NULL)
614		return (false);
615	fprintf(fp, "QCMD(%s,", primary);
616	type = lookup_value(quotatypes, cmd & SUBCMDMASK);
617	if (type != NULL)
618		fprintf(fp, "%s", type);
619	else
620		fprintf(fp, "%#x", cmd & SUBCMDMASK);
621	fprintf(fp, ")");
622	return (true);
623}
624
625bool
626sysdecode_reboot_howto(FILE *fp, int howto, int *rem)
627{
628
629	return (print_mask_int(fp, rebootopt, howto, rem));
630}
631
632bool
633sysdecode_rfork_flags(FILE *fp, int flags, int *rem)
634{
635
636	return (print_mask_int(fp, rforkflags, flags, rem));
637}
638
639const char *
640sysdecode_rlimit(int resource)
641{
642
643	return (lookup_value(rlimit, resource));
644}
645
646const char *
647sysdecode_scheduler_policy(int policy)
648{
649
650	return (lookup_value(schedpolicy, policy));
651}
652
653bool
654sysdecode_sendfile_flags(FILE *fp, int flags, int *rem)
655{
656
657	return (print_mask_int(fp, sendfileflags, flags, rem));
658}
659
660bool
661sysdecode_shmat_flags(FILE *fp, int flags, int *rem)
662{
663
664	return (print_mask_int(fp, shmatflags, flags, rem));
665}
666
667const char *
668sysdecode_shutdown_how(int how)
669{
670
671	return (lookup_value(shutdownhow, how));
672}
673
674const char *
675sysdecode_sigbus_code(int si_code)
676{
677
678	return (lookup_value(sigbuscode, si_code));
679}
680
681const char *
682sysdecode_sigchld_code(int si_code)
683{
684
685	return (lookup_value(sigchldcode, si_code));
686}
687
688const char *
689sysdecode_sigfpe_code(int si_code)
690{
691
692	return (lookup_value(sigfpecode, si_code));
693}
694
695const char *
696sysdecode_sigill_code(int si_code)
697{
698
699	return (lookup_value(sigillcode, si_code));
700}
701
702const char *
703sysdecode_sigsegv_code(int si_code)
704{
705
706	return (lookup_value(sigsegvcode, si_code));
707}
708
709const char *
710sysdecode_sigtrap_code(int si_code)
711{
712
713	return (lookup_value(sigtrapcode, si_code));
714}
715
716const char *
717sysdecode_sigprocmask_how(int how)
718{
719
720	return (lookup_value(sigprocmaskhow, how));
721}
722
723const char *
724sysdecode_socketdomain(int domain)
725{
726
727	return (lookup_value(sockdomain, domain));
728}
729
730const char *
731sysdecode_sockaddr_family(int sa_family)
732{
733
734	return (lookup_value(sockfamily, sa_family));
735}
736
737const char *
738sysdecode_ipproto(int protocol)
739{
740
741	return (lookup_value(sockipproto, protocol));
742}
743
744const char *
745sysdecode_sockopt_name(int level, int optname)
746{
747
748	if (level == SOL_SOCKET)
749		return (lookup_value(sockopt, optname));
750	if (level == IPPROTO_IP)
751		/* XXX: UNIX domain socket options use a level of 0 also. */
752		return (lookup_value(sockoptip, optname));
753	if (level == IPPROTO_TCP)
754		return (lookup_value(sockopttcp, optname));
755	if (level == IPPROTO_UDP)
756		return (lookup_value(sockoptudp, optname));
757	return (NULL);
758}
759
760bool
761sysdecode_thr_create_flags(FILE *fp, int flags, int *rem)
762{
763
764	return (print_mask_int(fp, thrcreateflags, flags, rem));
765}
766
767const char *
768sysdecode_umtx_op(int op)
769{
770
771	return (lookup_value(umtxop, op));
772}
773
774const char *
775sysdecode_vmresult(int result)
776{
777
778	return (lookup_value(vmresult, result));
779}
780
781bool
782sysdecode_wait4_options(FILE *fp, int options, int *rem)
783{
784	bool printed;
785	int opt6;
786
787	/* A flags value of 0 is normal. */
788	if (options == 0) {
789		fputs("0", fp);
790		if (rem != NULL)
791			*rem = 0;
792		return (true);
793	}
794
795	/*
796	 * These flags are implicit and aren't valid flags for wait4()
797	 * directly (though they don't fail with EINVAL).
798	 */
799	opt6 = options & (WEXITED | WTRAPPED);
800	options &= ~opt6;
801	printed = print_mask_int(fp, wait6opt, options, rem);
802	if (rem != NULL)
803		*rem |= opt6;
804	return (printed);
805}
806
807bool
808sysdecode_wait6_options(FILE *fp, int options, int *rem)
809{
810
811	return (print_mask_int(fp, wait6opt, options, rem));
812}
813
814const char *
815sysdecode_whence(int whence)
816{
817
818	return (lookup_value(seekwhence, whence));
819}
820
821const char *
822sysdecode_fcntl_cmd(int cmd)
823{
824
825	return (lookup_value(fcntlcmd, cmd));
826}
827
828static struct name_table fcntl_fd_arg[] = {
829	X(FD_CLOEXEC) X(0) XEND
830};
831
832bool
833sysdecode_fcntl_arg_p(int cmd)
834{
835
836	switch (cmd) {
837	case F_GETFD:
838	case F_GETFL:
839	case F_GETOWN:
840		return (false);
841	default:
842		return (true);
843	}
844}
845
846void
847sysdecode_fcntl_arg(FILE *fp, int cmd, uintptr_t arg, int base)
848{
849	int rem;
850
851	switch (cmd) {
852	case F_SETFD:
853		if (!print_value(fp, fcntl_fd_arg, arg))
854		    print_integer(fp, arg, base);
855		break;
856	case F_SETFL:
857		if (!sysdecode_fcntl_fileflags(fp, arg, &rem))
858			fprintf(fp, "%#x", rem);
859		else if (rem != 0)
860			fprintf(fp, "|%#x", rem);
861		break;
862	case F_GETLK:
863	case F_SETLK:
864	case F_SETLKW:
865		fprintf(fp, "%p", (void *)arg);
866		break;
867	default:
868		print_integer(fp, arg, base);
869		break;
870	}
871}
872
873bool
874sysdecode_mmap_flags(FILE *fp, int flags, int *rem)
875{
876	uintmax_t val;
877	bool printed;
878	int align;
879
880	/*
881	 * MAP_ALIGNED can't be handled directly by print_mask_int().
882	 * MAP_32BIT is also problematic since it isn't defined for
883	 * all platforms.
884	 */
885	printed = false;
886	align = flags & MAP_ALIGNMENT_MASK;
887	val = (unsigned)flags & ~MAP_ALIGNMENT_MASK;
888	print_mask_part(fp, mmapflags, &val, &printed);
889#ifdef MAP_32BIT
890	if (val & MAP_32BIT) {
891		fprintf(fp, "%sMAP_32BIT", printed ? "|" : "");
892		printed = true;
893		val &= ~MAP_32BIT;
894	}
895#endif
896	if (align != 0) {
897		if (printed)
898			fputc('|', fp);
899		if (align == MAP_ALIGNED_SUPER)
900			fputs("MAP_ALIGNED_SUPER", fp);
901		else
902			fprintf(fp, "MAP_ALIGNED(%d)",
903			    align >> MAP_ALIGNMENT_SHIFT);
904		printed = true;
905	}
906	if (rem != NULL)
907		*rem = val;
908	return (printed);
909}
910
911const char *
912sysdecode_rtprio_function(int function)
913{
914
915	return (lookup_value(rtpriofuncs, function));
916}
917
918bool
919sysdecode_msg_flags(FILE *fp, int flags, int *rem)
920{
921
922	return (print_mask_0(fp, msgflags, flags, rem));
923}
924
925const char *
926sysdecode_sigcode(int sig, int si_code)
927{
928	const char *str;
929
930	str = lookup_value(sigcode, si_code);
931	if (str != NULL)
932		return (str);
933
934	switch (sig) {
935	case SIGILL:
936		return (sysdecode_sigill_code(si_code));
937	case SIGBUS:
938		return (sysdecode_sigbus_code(si_code));
939	case SIGSEGV:
940		return (sysdecode_sigsegv_code(si_code));
941	case SIGFPE:
942		return (sysdecode_sigfpe_code(si_code));
943	case SIGTRAP:
944		return (sysdecode_sigtrap_code(si_code));
945	case SIGCHLD:
946		return (sysdecode_sigchld_code(si_code));
947	default:
948		return (NULL);
949	}
950}
951
952bool
953sysdecode_umtx_cvwait_flags(FILE *fp, u_long flags, u_long *rem)
954{
955
956	return (print_mask_0ul(fp, umtxcvwaitflags, flags, rem));
957}
958
959bool
960sysdecode_umtx_rwlock_flags(FILE *fp, u_long flags, u_long *rem)
961{
962
963	return (print_mask_0ul(fp, umtxrwlockflags, flags, rem));
964}
965
966void
967sysdecode_cap_rights(FILE *fp, cap_rights_t *rightsp)
968{
969	struct name_table *t;
970	bool comma;
971
972	comma = false;
973	for (t = caprights; t->str != NULL; t++) {
974		if (cap_rights_is_set(rightsp, t->val)) {
975			fprintf(fp, "%s%s", comma ? "," : "", t->str);
976			comma = true;
977		}
978	}
979}
980