1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1988, 1993
5 *	The Regents of the University of California.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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. Neither the name of the University nor the names of its contributors
16 *    may be used to endorse or promote products derived from this software
17 *    without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#ifndef __KDUMP_H__
33#define __KDUMP_H__
34
35extern bool decimal, fancy, resolv;
36
37#define	_print_number64(first,i,n,c,d) do {				\
38	uint64_t __v;							\
39									\
40	if (quad_align && (((ptrdiff_t)((i) - (first))) & 1) == 1) {	\
41		(i)++;							\
42		(n)--;							\
43	}								\
44	if (quad_slots == 2)						\
45		__v = (uint64_t)(uint32_t)(i)[0] |			\
46		    ((uint64_t)(uint32_t)(i)[1]) << 32;			\
47	else								\
48		__v = (uint64_t)*(i);					\
49	if (d)								\
50		printf("%c%jd", (c), (intmax_t)__v);			\
51	else								\
52		printf("%c%#jx", (c), (uintmax_t)__v);			\
53	(i) += quad_slots;						\
54	(n) -= quad_slots;						\
55	(c) = ',';							\
56} while (0)
57
58#define _print_number(i,n,c,d) do {					\
59	if (d)								\
60		printf("%c%jd", c, (intmax_t)*i);			\
61	else								\
62		printf("%c%#jx", c, (uintmax_t)(u_register_t)*i);	\
63	i++;								\
64	n--;								\
65	c = ',';							\
66} while (0)
67
68#define	print_number(i,n,c)		_print_number(i,n,c,decimal)
69#define	print_decimal_number(i,n,c)	_print_number(i,n,c,true)
70#define	print_number64(first,i,n,c)	_print_number64(first,i,n,c,decimal)
71#define	print_decimal_number64(first,i,n,c) _print_number64(first,i,n,c,true)
72
73void	decode_filemode(int value);
74void	print_integer_arg(const char *(*decoder)(int), int value);
75void	print_integer_arg_valid(const char *(*decoder)(int), int value);
76void	print_mask_arg(bool (*decoder)(FILE *, int, int *), int value);
77void	print_mask_arg0(bool (*decoder)(FILE *, int, int *), int value);
78void	print_mask_arg32(bool (*decoder)(FILE *, uint32_t, uint32_t *),
79	    uint32_t value);
80void	print_mask_argul(bool (*decoder)(FILE *, u_long, u_long *),
81	    u_long value);
82bool	print_mask_arg_part(bool (*decoder)(FILE *, int, int *),
83	    int value, int *rem);
84
85#ifdef SYSDECODE_HAVE_LINUX
86bool ktrstruct_linux(const char *name, const char *data, size_t datalen);
87void ktrsyscall_linux(struct ktr_syscall *ktr, register_t **resip,
88    int *resnarg, char *resc);
89#ifdef __amd64__
90void ktrsyscall_linux32(struct ktr_syscall *ktr, register_t **resip,
91    int *resnarg, char *resc);
92#endif
93#endif /* SYSDECODE_HAVE_LINUX */
94
95#endif /* !__KDUMP_H__ */
96