public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
370cfa16d1e4c296c6a658241e74793981eae31e blob 3914 bytes (raw)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
 
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright Red Hat
 * Author: David Gibson <david@gibson.dropbear.id.au>
 *
 * Definitions used by both passt/pasta and other tools
 */

#ifndef COMMON_H
#define COMMON_H

#include <string.h>

#define VERSION_BLOB							       \
	VERSION "\n"							       \
	"Copyright Red Hat\n"						       \
	"GNU General Public License, version 2 or later\n"		       \
	"  <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>\n"	       \
	"This is free software: you are free to change and redistribute it.\n" \
	"There is NO WARRANTY, to the extent permitted by law.\n\n"

#ifndef MIN
#define MIN(x, y)		(((x) < (y)) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x, y)		(((x) > (y)) ? (x) : (y))
#endif

#define MAX_FROM_BITS(n)	(((1U << (n)) - 1))

/* FPRINTF() intentionally silences cert-err33-c clang-tidy warnings */
#define FPRINTF(f, ...)	(void)fprintf(f, __VA_ARGS__)

#define ARRAY_SIZE(a)		((int)(sizeof(a) / sizeof((a)[0])))

#define DIV_ROUND_UP(n, d)	(((n) + (d) - 1) / (d))
#define DIV_ROUND_CLOSEST(n, d)	(((n) + (d) / 2) / (d))
#define ROUND_DOWN(x, y)	((x) & ~((y) - 1))
#define ROUND_UP(x, y)		(((x) + (y) - 1) & ~((y) - 1))

#define UINT16_STRLEN		(sizeof("65535"))

/*
 * Starting from glibc 2.40.9000 and commit 25a5eb4010df ("string: strerror,
 * strsignal cannot use buffer after dlmopen (bug 32026)"), strerror() needs
 * getrandom(2) and brk(2) as it allocates memory for the locale-translated
 * error description, but our seccomp profiles forbid both.
 *
 * Use the strerror_() wrapper instead, calling into strerrordesc_np() to get
 * a static untranslated string. It's a GNU implementation, but also defined by
 * bionic.
 *
 * If strerrordesc_np() is not defined (e.g. musl), call strerror(). C libraries
 * not defining strerrordesc_np() are expected to provide strerror()
 * implementations that are simple enough for us to call.
 */
__attribute__ ((weak)) const char *strerrordesc_np(int errnum);

/**
 * strerror_() - strerror() wrapper calling strerrordesc_np() if available
 * @errnum:	Error code
 *
 * Return: error description string
 */
static inline const char *strerror_(int errnum)
{
	if (strerrordesc_np)
		return strerrordesc_np(errnum);

	return strerror(errnum);
}

#define strerror(x) @ "Don't call strerror() directly, use strerror_() instead"

#ifndef __bswap_constant_16
#define __bswap_constant_16(x)						\
	((uint16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)))
#endif

#ifndef __bswap_constant_32
#define __bswap_constant_32(x)						\
	((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) |	\
	 (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
#endif

#ifndef __bswap_constant_32
#define __bswap_constant_32(x)						\
	((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) |	\
	 (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
#endif

#ifndef __bswap_constant_64
#define __bswap_constant_64(x) \
	((((x) & 0xff00000000000000ULL) >> 56) |			\
	 (((x) & 0x00ff000000000000ULL) >> 40) |			\
	 (((x) & 0x0000ff0000000000ULL) >> 24) |			\
	 (((x) & 0x000000ff00000000ULL) >> 8)  |			\
	 (((x) & 0x00000000ff000000ULL) << 8)  |			\
	 (((x) & 0x0000000000ff0000ULL) << 24) |			\
	 (((x) & 0x000000000000ff00ULL) << 40) |			\
	 (((x) & 0x00000000000000ffULL) << 56))
#endif

#if __BYTE_ORDER == __BIG_ENDIAN
#define	htons_constant(x)	(x)
#define	htonl_constant(x)	(x)
#define htonll_constant(x)	(x)
#define	ntohs_constant(x)	(x)
#define	ntohl_constant(x)	(x)
#define ntohll_constant(x)	(x)
#else
#define	htons_constant(x)	(__bswap_constant_16(x))
#define	htonl_constant(x)	(__bswap_constant_32(x))
#define	htonll_constant(x)	(__bswap_constant_64(x))
#define	ntohs_constant(x)	(__bswap_constant_16(x))
#define	ntohl_constant(x)	(__bswap_constant_32(x))
#define	ntohll_constant(x)	(__bswap_constant_64(x))
#endif

#define ntohll(x)		(be64toh((x)))
#define htonll(x)		(htobe64((x)))

#endif /* _COMMON_H */
debug log:

solving 370cfa16 ...
found 370cfa16 in https://archives.passt.top/passt-dev/20260421062516.2601204-15-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421044217.2500314-14-david@gibson.dropbear.id.au/
found 4a167ae0 in https://archives.passt.top/passt-dev/20260421062516.2601204-14-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421044217.2500314-13-david@gibson.dropbear.id.au/
found 45f66ea6 in https://archives.passt.top/passt-dev/20260421044217.2500314-12-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421062516.2601204-13-david@gibson.dropbear.id.au/
found 2f2e6f1e in https://archives.passt.top/passt-dev/20260421062516.2601204-11-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421044217.2500314-10-david@gibson.dropbear.id.au/
found a9c115a5 in https://archives.passt.top/passt-dev/20260421062516.2601204-10-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20260421044217.2500314-9-david@gibson.dropbear.id.au/

applying [1/10] https://archives.passt.top/passt-dev/20260421062516.2601204-10-david@gibson.dropbear.id.au/
diff --git a/common.h b/common.h
new file mode 100644
index 00000000..a9c115a5

Checking patch common.h...
Applied patch common.h cleanly.

skipping https://archives.passt.top/passt-dev/20260421044217.2500314-9-david@gibson.dropbear.id.au/ for a9c115a5
index at:
100644 a9c115a5efa11ad103c2db76b21382ceac8e8f6d	common.h

applying [2/10] https://archives.passt.top/passt-dev/20260421062516.2601204-11-david@gibson.dropbear.id.au/
diff --git a/common.h b/common.h
index a9c115a5..2f2e6f1e 100644

Checking patch common.h...
Applied patch common.h cleanly.

skipping https://archives.passt.top/passt-dev/20260421044217.2500314-10-david@gibson.dropbear.id.au/ for 2f2e6f1e
index at:
100644 2f2e6f1e826a85721e4885b05d58dae59f987419	common.h

applying [3/10] https://archives.passt.top/passt-dev/20260421044217.2500314-12-david@gibson.dropbear.id.au/
diff --git a/common.h b/common.h
index 2f2e6f1e..45f66ea6 100644

Checking patch common.h...
Applied patch common.h cleanly.

skipping https://archives.passt.top/passt-dev/20260421062516.2601204-13-david@gibson.dropbear.id.au/ for 45f66ea6
index at:
100644 45f66ea6072ecd4ac662f242e83c3323588ad671	common.h

applying [4/10] https://archives.passt.top/passt-dev/20260421062516.2601204-14-david@gibson.dropbear.id.au/
diff --git a/common.h b/common.h
index 45f66ea6..4a167ae0 100644

Checking patch common.h...
Applied patch common.h cleanly.

skipping https://archives.passt.top/passt-dev/20260421044217.2500314-13-david@gibson.dropbear.id.au/ for 4a167ae0
index at:
100644 4a167ae0b5c1a4bed3dc93415610651d746bf0dd	common.h

applying [5/10] https://archives.passt.top/passt-dev/20260421062516.2601204-15-david@gibson.dropbear.id.au/
diff --git a/common.h b/common.h
index 4a167ae0..370cfa16 100644

Checking patch common.h...
Applied patch common.h cleanly.

skipping https://archives.passt.top/passt-dev/20260421044217.2500314-14-david@gibson.dropbear.id.au/ for 370cfa16
index at:
100644 370cfa16d1e4c296c6a658241e74793981eae31e	common.h

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).