tools: use xen-tools/libs.h for common definitions
v2 cover tools: use xen-tools/libs.h for common definitions
There are some macros defined multiple times in tools. Use only a single header file for defining those macros and drop the copies.
V2:
- add patch 1 (Andrew Cooper)
Juergen Gross (4):
tools: rename xen-tools/libs.h file to common-macros.h
tools: add container_of() macro to xen-tools/common-macros.h
tools: get rid of additional min() and max() definitions
tools: add offsetof() to xen-tools/common-macros.h
tools/console/daemon/io.c | 2 +-
tools/firmware/hvmloader/util.h | 11 ++--------
tools/firmware/include/stddef.h | 4 ++--
tools/fuzz/cpu-policy/afl-policy-fuzzer.c | 2 +-
.../xen-tools/{libs.h => common-macros.h} | 22 ++++++++++++++++---
tools/libfsimage/Rules.mk | 2 ++
tools/libfsimage/xfs/fsys_xfs.c | 4 +---
tools/libs/call/buffer.c | 2 +-
tools/libs/ctrl/xc_pm.c | 2 +-
tools/libs/ctrl/xc_private.h | 2 +-
tools/libs/foreignmemory/linux.c | 2 +-
tools/libs/gnttab/freebsd.c | 2 +-
tools/libs/gnttab/linux.c | 2 +-
tools/libs/guest/xg_core_arm.c | 2 +-
tools/libs/guest/xg_cpuid_x86.c | 2 +-
tools/libs/guest/xg_dom_arm.c | 2 +-
tools/libs/guest/xg_dom_bzimageloader.c | 2 +-
tools/libs/guest/xg_dom_x86.c | 2 +-
tools/libs/guest/xg_sr_common.c | 2 +-
tools/libs/light/libxl_internal.h | 2 +-
tools/libs/light/libxl_psr.c | 2 +-
tools/libs/stat/xenstat_linux.c | 2 +-
tools/libs/vchan/init.c | 7 +-----
tools/misc/xen-access.c | 2 +-
tools/misc/xen-cpuid.c | 2 +-
tools/misc/xen-diag.c | 2 +-
tools/misc/xen-hptool.c | 2 +-
tools/misc/xen-livepatch.c | 2 +-
tools/misc/xen-mfndump.c | 2 +-
tools/misc/xenpm.c | 2 +-
tools/ocaml/libs/mmap/xenmmap_stubs.c | 2 +-
tools/ocaml/libs/xc/xenctrl_stubs.c | 2 +-
tools/python/xen/lowlevel/xc/xc.c | 2 +-
tools/tests/cpu-policy/test-cpu-policy.c | 2 +-
.../paging-mempool/test-paging-mempool.c | 2 +-
tools/tests/resource/test-resource.c | 2 +-
tools/tests/tsx/test-tsx.c | 2 +-
tools/tests/vhpet/emul.h | 16 +-------------
tools/tests/vpci/emul.h | 22 +------------------
tools/tests/x86_emulator/x86-emulate.h | 7 +-----
tools/tests/xenstore/test-xenstore.c | 2 +-
tools/xenstore/list.h | 6 ++---
tools/xenstore/utils.h | 2 +-
tools/xentrace/analyze.h | 2 +-
tools/xl/xl_cmdtable.c | 2 +-
xen/lib/x86/private.h | 2 +-
46 files changed, 68 insertions(+), 105 deletions(-)
rename tools/include/xen-tools/{libs.h => common-macros.h} (74%)Signature · 1 line
2.35.3
PATCH v2 1/4 tools: rename xen-tools/libs.h file to common-macros.h
In order to better reflect the contents of the header and to make it more appropriate to use it for different runtime environments like programs, libraries, and firmware, rename the libs.h include file to common-macros.h. Additionally ad a comment pointing out the need to be self-contained.
---
V2:
- new patch
---
tools/console/daemon/io.c | 2 +-
tools/fuzz/cpu-policy/afl-policy-fuzzer.c | 2 +-
.../include/xen-tools/{libs.h => common-macros.h} | 14 +++++++++++---
tools/libs/call/buffer.c | 2 +-
tools/libs/ctrl/xc_pm.c | 2 +-
tools/libs/ctrl/xc_private.h | 2 +-
tools/libs/foreignmemory/linux.c | 2 +-
tools/libs/gnttab/freebsd.c | 2 +-
tools/libs/gnttab/linux.c | 2 +-
tools/libs/guest/xg_core_arm.c | 2 +-
tools/libs/guest/xg_cpuid_x86.c | 2 +-
tools/libs/guest/xg_dom_arm.c | 2 +-
tools/libs/guest/xg_dom_bzimageloader.c | 2 +-
tools/libs/guest/xg_dom_x86.c | 2 +-
tools/libs/guest/xg_sr_common.c | 2 +-
tools/libs/light/libxl_internal.h | 2 +-
tools/libs/light/libxl_psr.c | 2 +-
tools/libs/stat/xenstat_linux.c | 2 +-
tools/misc/xen-access.c | 2 +-
tools/misc/xen-cpuid.c | 2 +-
tools/misc/xen-diag.c | 2 +-
tools/misc/xen-hptool.c | 2 +-
tools/misc/xen-livepatch.c | 2 +-
tools/misc/xen-mfndump.c | 2 +-
tools/misc/xenpm.c | 2 +-
tools/ocaml/libs/mmap/xenmmap_stubs.c | 2 +-
tools/ocaml/libs/xc/xenctrl_stubs.c | 2 +-
tools/python/xen/lowlevel/xc/xc.c | 2 +-
tools/tests/cpu-policy/test-cpu-policy.c | 2 +-
tools/tests/paging-mempool/test-paging-mempool.c | 2 +-
tools/tests/resource/test-resource.c | 2 +-
tools/tests/tsx/test-tsx.c | 2 +-
tools/tests/vhpet/emul.h | 2 +-
tools/tests/x86_emulator/x86-emulate.h | 2 +-
tools/tests/xenstore/test-xenstore.c | 2 +-
tools/xenstore/utils.h | 2 +-
tools/xentrace/analyze.h | 2 +-
tools/xl/xl_cmdtable.c | 2 +-
xen/lib/x86/private.h | 2 +-
39 files changed, 49 insertions(+), 41 deletions(-)
rename tools/include/xen-tools/{libs.h => common-macros.h} (83%)tools/console/daemon/io.c +1 -1
@@ -50,7 +50,7 @@#include <sys/ioctl.h> #include <libutil.h> #endif -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> /* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */ #define MAX_STRLEN (x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2)
tools/fuzz/cpu-policy/afl-policy-fuzzer.c +1 -1
@@ -8,7 +8,7 @@#include <getopt.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include <xen/lib/x86/cpuid.h> #include <xen/lib/x86/msr.h> #include <xen/domctl.h>
tools/include/xen-tools/common-macros.h renamed from tools/include/xen-tools/libs.h +11 -3
@@ -1,5 +1,13 @@ -#ifndef __XEN_TOOLS_LIBS__ -#define __XEN_TOOLS_LIBS__ +#ifndef __XEN_TOOLS_COMMON_MACROS__ +#define __XEN_TOOLS_COMMON_MACROS__ + +/* +* Caution: +* +* This header must be completely self-contained. There are no external +* references to variables or functions allowed, as the file might be included +* for different runtime environments, such as firmware or normal programs. +*/ #ifndef BUILD_BUG_ON #if __GNUC__ >4 || (__GNUC__ ==4 && __GNUC_MINOR__ >=6 )
@@ -67,4 +75,4 @@#define __must_check __attribute__((__warn_unused_result__))#endif -#endif /* __XEN_TOOLS_LIBS__ */ +#endif /* __XEN_TOOLS_COMMON_MACROS__ */
tools/libs/call/buffer.c +1 -1
@@ -16,7 +16,7 @@#include <errno.h> #include <string.h> #include <pthread.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "private.h"
tools/libs/ctrl/xc_pm.c +1 -1
@@ -21,7 +21,7 @@#include <stdbool.h> #include "xc_private.h" -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> /* * Get PM statistic info
tools/libs/ctrl/xc_private.h +1 -1
@@ -39,7 +39,7 @@#include <xen/sys/privcmd.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #if defined(HAVE_VALGRIND_MEMCHECK_H ) && !defined(NDEBUG ) && !defined(__MINIOS__)/* Compile in Valgrind client requests? */
tools/libs/foreignmemory/linux.c +1 -1
@@ -25,7 +25,7 @@#include <sys/mman.h> #include <sys/ioctl.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "private.h"
tools/libs/gnttab/freebsd.c +1 -1
@@ -31,7 +31,7 @@#include <xen/sys/gntdev.h> #include <xenctrl.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "private.h"
tools/libs/gnttab/linux.c +1 -1
@@ -33,7 +33,7 @@#include <xen/sys/gntalloc.h> #include <xenctrl.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "private.h"
tools/libs/guest/xg_core_arm.c +1 -1
@@ -19,7 +19,7 @@#include "xc_private.h" #include "xg_core.h" -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> int xc_core_arch_gpfn_may_present(struct xc_core_arch_context *arch_ctxt,
tools/libs/guest/xg_cpuid_x86.c +1 -1
@@ -24,7 +24,7 @@#include <limits.h> #include "xg_private.h" #include <xen/hvm/params.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> enum {#define XEN_CPUFEATURE(name, value) X86_FEATURE_##name = value,
tools/libs/guest/xg_dom_arm.c +1 -1
@@ -21,7 +21,7 @@#include <xen/xen.h> #include <xen/io/protocols.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "xg_private.h"
tools/libs/guest/xg_dom_bzimageloader.c +1 -1
@@ -34,7 +34,7 @@#include "xg_private.h" #include "xg_dom_decompress.h" -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #ifndef __MINIOS__
tools/libs/guest/xg_dom_x86.c +1 -1
@@ -35,7 +35,7 @@#include <xen/arch-x86/hvm/start_info.h> #include <xen/io/protocols.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "xg_private.h" #include "xenctrl.h"
tools/libs/guest/xg_sr_common.c +1 -1
@@ -2,7 +2,7 @@#include "xg_sr_common.h" -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> static const char *const dhdr_types[] = {
tools/libs/light/libxl_internal.h +1 -1
@@ -58,7 +58,7 @@#include <xenguest.h> #include <xenhypfs.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "xentoollog.h"
tools/libs/light/libxl_psr.c +1 -1
@@ -16,7 +16,7 @@#include "libxl_osdeps.h" /* must come before any other headers */ #include "libxl_internal.h" -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #define IA32_QM_CTR_ERROR_MASK (0x3ul << 62)
tools/libs/stat/xenstat_linux.c +1 -1
@@ -30,7 +30,7 @@#include <string.h> #include <unistd.h> #include <regex.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "xenstat_priv.h"
tools/misc/xen-access.c +1 -1
@@ -43,7 +43,7 @@#include <xenevtchn.h> #include <xen/vm_event.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #if defined(__arm__) || defined(__aarch64__)#include <xen/arch-arm.h>
tools/misc/xen-cpuid.c +1 -1
@@ -10,7 +10,7 @@#include <xenctrl.h> #include <xenguest.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> static uint32_t nr_features;
tools/misc/xen-diag.c +1 -1
@@ -11,7 +11,7 @@#include <xenctrl.h> #include <xen/errno.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> static xc_interface *xch;
tools/misc/xen-hptool.c +1 -1
@@ -5,7 +5,7 @@#include <xenctrl.h> #include <xenguest.h> #include <xenstore.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> static xc_interface *xch;
tools/misc/xen-livepatch.c +1 -1
@@ -15,7 +15,7 @@#include <xenstore.h> #include <xen/errno.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> static xc_interface *xch;
tools/misc/xen-mfndump.c +1 -1
@@ -8,7 +8,7 @@#include <xenctrl.h> #include <xenguest.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #define M2P_SIZE (_m) ROUNDUP(((_m) * sizeof(xen_pfn_t)), 21)#define is_mapped (pfn_type) (!((pfn_type) & 0x80000000UL))
tools/misc/xenpm.c +1 -1
@@ -28,7 +28,7 @@#include <inttypes.h> #include <sys/time.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #define MAX_PKG_RESIDENCIES 12#define MAX_CORE_RESIDENCIES 8
tools/ocaml/libs/mmap/xenmmap_stubs.c +1 -1
@@ -21,7 +21,7 @@#include <errno.h> #include "mmap_stubs.h" -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include <caml/mlvalues.h> #include <caml/memory.h>
tools/ocaml/libs/xc/xenctrl_stubs.c +1 -1
@@ -33,7 +33,7 @@#define XC_WANT_COMPAT_MAP_FOREIGN_API #include <xenctrl.h> #include <xenguest.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "mmap_stubs.h"
tools/python/xen/lowlevel/xc/xc.c +1 -1
@@ -22,7 +22,7 @@#include <xen/hvm/hvm_info_table.h> #include <xen/hvm/params.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> /* Needed for Python versions earlier than 2.3. */ #ifndef PyMODINIT_FUNC
tools/tests/cpu-policy/test-cpu-policy.c +1 -1
@@ -7,7 +7,7 @@#include <string.h> #include <err.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include <xen/asm/x86-vendors.h> #include <xen/lib/x86/cpu-policy.h> #include <xen/domctl.h>
tools/tests/paging-mempool/test-paging-mempool.c +1 -1
@@ -8,7 +8,7 @@#include <xenctrl.h> #include <xenforeignmemory.h> #include <xengnttab.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> static unsigned int nr_failures;#define fail (fmt, ...) \
tools/tests/resource/test-resource.c +1 -1
@@ -7,7 +7,7 @@#include <xenctrl.h> #include <xenforeignmemory.h> #include <xengnttab.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> static unsigned int nr_failures;#define fail (fmt, ...) \
tools/tests/tsx/test-tsx.c +1 -1
@@ -28,7 +28,7 @@#include <xenctrl.h> #include <xenguest.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "xg_private.h"
tools/tests/vhpet/emul.h +1 -1
@@ -24,7 +24,7 @@#include "hpet.h" -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #define NR_CPUS 8
tools/tests/x86_emulator/x86-emulate.h +1 -1
@@ -39,7 +39,7 @@#include <xen/asm/x86-defns.h> #include <xen/asm/x86-vendors.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #define BUG () abort()#define ASSERT assert
tools/tests/xenstore/test-xenstore.c +1 -1
@@ -31,7 +31,7 @@#include <time.h> #include <xenstore.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #define TEST_PATH "xenstore-test"#define WRITE_BUFFERS_N 10
tools/xenstore/utils.h +1 -1
@@ -5,7 +5,7 @@#include <stdint.h> #include <stdio.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "xenstore_lib.h"
tools/xentrace/analyze.h +1 -1
@@ -3,7 +3,7 @@#include <stdint.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #define TRC_GEN_MAIN 0#define TRC_SCHED_MAIN 1
tools/xl/xl_cmdtable.c +1 -1
@@ -15,7 +15,7 @@#include <string.h> #include <libxl.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> #include "xl.h"
xen/lib/x86/private.h +1 -1
@@ -26,7 +26,7 @@#include <xen/asm/msr-index.h> #include <xen/asm/x86-vendors.h> -#include <xen-tools/libs.h> +#include <xen-tools/common-macros.h> static inline bool test_bit (unsigned int bit,const void *vaddr) {
Signature · 1 line
2.35.3
Re: [PATCH v2 1/4] tools: rename xen-tools/libs.h file to common-macros.h
Quoted 5 lines · Juergen Gross
tools/include/xen-tools/common-macros.h renamed from tools/include/xen-tools/libs.h +0
-2@@ -1,5 +1,13 @@ -#ifndef __XEN_TOOLS_LIBS__ -#define __XEN_TOOLS_LIBS__
tools/include/xen-tools/common-macros.h line 10
Quoted 10 lines
tools/include/xen-tools/common-macros.h renamed from tools/include/xen-tools/libs.h +10
-0+#ifndef __XEN_TOOLS_COMMON_MACROS__ +#define __XEN_TOOLS_COMMON_MACROS__ + +/* +* Caution: +* +* This header must be completely self-contained. There are no external +* references to variables or functions allowed, as the file might be included +* for different runtime environments, such as firmware or normal programs. +*/
May I ask to go a tiny step further: s/normal/target and build host/ or something alike?
Jan
Re: [PATCH v2 1/4] tools: rename xen-tools/libs.h file to common-macros.h
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Juergen Gross
tools/include/xen-tools/common-macros.h renamed from tools/include/xen-tools/libs.h +5
-2@@ -1,5 +1,13 @@ -#ifndef __XEN_TOOLS_LIBS__ -#define __XEN_TOOLS_LIBS__ +#ifndef __XEN_TOOLS_COMMON_MACROS__ +#define __XEN_TOOLS_COMMON_MACROS__ + +/* +* Caution:
Quoted 8 lines
tools/include/xen-tools/common-macros.h line 10
Quoted 5 lines
tools/include/xen-tools/common-macros.h renamed from tools/include/xen-tools/libs.h +5
-0+* +* This header must be completely self-contained. There are no external +* references to variables or functions allowed, as the file might be included +* for different runtime environments, such as firmware or normal programs. +*/ May I ask to go a tiny step further: s/normal/target and build host/ or something alike?
Fine with me.
Juergen
Re: [PATCH v2 1/4] tools: rename xen-tools/libs.h file to common-macros.h
In reply to Juergen GrossQuoted 6 lines · Juergen Gross
In order to better reflect the contents of the header and to make it more appropriate to use it for different runtime environments like programs, libraries, and firmware, rename the
libs.hinclude file tocommon-macros.h. Additionally ad a comment pointing out the need to be self-contained.
Quoted 6 lines
Suggested-by Andrew Cooper <[email protected]>Signed-off-by Juergen Gross <[email protected]>---
V2:
- new patch
---
For this (assuming header rename itself will be acked):
Quoted 1 line
tools/python/xen/lowlevel/xc/xc.c | 2 +-
Signature · 3 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab
PATCH v2 2/4 tools: add container_of() macro to xen-tools/common-macros.h
In reply to Juergen GrossInstead of having 4 identical copies of the definition of a container_of() macro in different tools header files, add that macro to xen-tools/common-macros.h and use that instead.
Delete the other copies of that macro.
---
There is a similar macro CONTAINER_OF() defined in tools/include/xentoolcore_internal.h, which allows to not only use a type for the 2nd parameter, but a variable, too.
I'd like to get rid of that macro as well, but there are lots of use cases especially in libxl. Any thoughts regarding that macro? I could either:
- don't touch it at all
- enhance container_of() like CONTAINER_OF() and replace all use cases of CONTAINER_OF() with container_of()
- replace the few CONTAINER_OF() users outside libxl with container_of() and define CONTAINER_OF() in e.g. libxl_internal.h
- replace all CONTAINER_OF() use cases with container_of(), including the change from (.., var, ..) to (.., type, ...).
--- tools/include/xen-tools/common-macros.h | 4 ++++ tools/tests/vhpet/emul.h | 3 --- tools/tests/vpci/emul.h | 6 +----- tools/tests/x86_emulator/x86-emulate.h | 5 ----- tools/xenstore/list.h | 6 ++---- 5 files changed, 7 insertions(+), 17 deletions(-)
tools/include/xen-tools/common-macros.h +4 -0
@@ -75,4 +75,8 @@#define __must_check __attribute__((__warn_unused_result__))#endif +#define container_of (ptr, type, member) ({ \ + typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) +#endif /* __XEN_TOOLS_COMMON_MACROS__ */
tools/tests/vhpet/emul.h +0 -3
@@ -125,9 +125,6 @@ enum#define max_t (type, x, y) \ ({ type __x = (x); type __y = (y); __x > __y ? __x : __y; })#define offsetof (t, m) ((unsigned long )&((t *)0)->m) -#define container_of (ptr, type, member) ({ \ - typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) ); })struct domain ;
tools/tests/vpci/emul.h +1 -5
@@ -27,11 +27,7 @@#include <stdio.h> #include <stdlib.h> -#define container_of (ptr, type, member) ({ \ - typeof(((type *)0)->member) *mptr = (ptr); \ - \ - (type *)((char *)mptr - offsetof(type, member)); \ -}) +#include <xen-tools/common-macros.h> #define smp_wmb ()#define prefetch (x) __builtin_prefetch(x)
tools/tests/x86_emulator/x86-emulate.h +0 -5
@@ -56,11 +56,6 @@#define cf_check/* No Control Flow Integriy checking */ -#define container_of (ptr, type, member) ({ \ - typeof(((type *)0)->member) *mptr__ = (ptr); \ - (type *)((char *)mptr__ - offsetof(type, member)); \ -}) -#define AC_ (n,t) (n##t)#define _AC (n,t) AC_(n,t)
tools/xenstore/list.h +2 -4
@@ -3,6 +3,8 @@/* Taken from Linux kernel code, but de-kernelized for userspace. */ #include <stddef.h> +#include <xen-tools/common-macros.h> +#undef LIST_HEAD_INIT#undef LIST_HEAD#undef INIT_LIST_HEAD
@@ -15,10 +17,6 @@#define LIST_POISON1 ((void *) 0x00100100)#define LIST_POISON2 ((void *) 0x00200200) -#define container_of (ptr, type, member) ({ \ - typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) -/* * Simple doubly linked list implementation. *
Signature · 1 line
2.35.3
PATCH v2 3/4 tools: get rid of additional min() and max() definitions
In reply to Juergen GrossDefining min(), min_t(), max() and max_t() at other places than xen-tools/common-macros.h isn't needed, as the definitions in said header can be used instead.
Same applies to BUILD_BUG_ON() in hvmloader.
--- tools/firmware/hvmloader/util.h | 8 ++------ tools/libs/vchan/init.c | 3 +-- tools/tests/vhpet/emul.h | 11 +---------- tools/tests/vpci/emul.h | 16 ---------------- 4 files changed, 4 insertions(+), 34 deletions(-)
tools/firmware/hvmloader/util.h +2 -6
@@ -9,6 +9,8 @@#include <xen/hvm/hvm_info_table.h> #include "e820.h" +#include <xen-tools/common-macros.h> +/* Request un-prefixed values from errno.h. */ #define XEN_ERRNO (name, value) name = value,enum {
@@ -41,12 +43,6 @@ void __assert_failed(const char *assertion, const char *file, int line)void __bug (const char *file,int line) __attribute__((noreturn));#define BUG () __bug(__FILE__, __LINE__)#define BUG_ON (p) do { if (p) BUG(); } while (0) -#define BUILD_BUG_ON (p) ((void)sizeof(char[1 - 2 * !!(p)])) - -#define min_t (type,x,y) \ - ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) -#define max_t (type,x,y) \ - ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })#define MB (mb) (mb##ULL << 20)#define GB (gb) (gb##ULL << 30)
tools/libs/vchan/init.c +1 -2
@@ -45,6 +45,7 @@#include <xen/sys/gntalloc.h> #include <xen/sys/gntdev.h> #include <libxenvchan.h> +#include <xen-tools/common-macros.h> #include "vchan.h"
@@ -72,8 +73,6 @@#define offsetof (TYPE ,MEMBER ) ((size_t) &((TYPE *)0)->MEMBER)#endif -#define max (a,b) ((a > b) ? a : b) -static int init_gnt_srv (struct libxenvchan *ctrl,int domain) {int pages_left = ctrl->read.order >=PAGE_SHIFT ?1 << (ctrl->read.order -PAGE_SHIFT ) :0 ;
tools/tests/vhpet/emul.h +1 -10
@@ -114,16 +114,7 @@ enumTASKLET_SOFTIRQ , NR_COMMON_SOFTIRQS }; -/* -* ..and if you can't take the strict -* types, you can specify one yourself. -* -* Or not use min/max at all, of course. -*/ -#define min_t (type, x, y) \ - ({ type __x = (x); type __y = (y); __x < __y ? __x : __y; }) -#define max_t (type, x, y) \ - ({ type __x = (x); type __y = (y); __x > __y ? __x : __y; }) +#define offsetof (t, m) ((unsigned long )&((t *)0)->m)struct domain ;
tools/tests/vpci/emul.h +0 -16
@@ -106,22 +106,6 @@ typedef union {#define BUG () assert(0)#define ASSERT_UNREACHABLE () assert(0) -#define min (x, y) ({ \ - const typeof(x) tx = (x); \ - const typeof(y) ty = (y); \ - \ - (void) (&tx == &ty); \ - tx < ty ? tx : ty; \ -}) - -#define max (x, y) ({ \ - const typeof(x) tx = (x); \ - const typeof(y) ty = (y); \ - \ - (void) (&tx == &ty); \ - tx > ty ? tx : ty; \ -}) -#endif /*
Signature · 1 line
2.35.3
PATCH v2 4/4 tools: add offsetof() to xen-tools/common-macros.h
In reply to Juergen GrossInstead of having multiple files defining offsetof(), add the definition to tools/include/xen-tools/common-macros.h.
--- tools/firmware/hvmloader/util.h | 3 --- tools/firmware/include/stddef.h | 4 ++-- tools/include/xen-tools/common-macros.h | 4 ++++ tools/libfsimage/Rules.mk | 2 ++ tools/libfsimage/xfs/fsys_xfs.c | 4 +--- tools/libs/vchan/init.c | 4 ---- tools/tests/vhpet/emul.h | 2 -- 7 files changed, 9 insertions(+), 14 deletions(-)
tools/firmware/hvmloader/util.h +0 -3
@@ -30,9 +30,6 @@ enum {#define SEL_DATA32 0x0020#define SEL_CODE64 0x0028 -#undef offsetof -#define offsetof (t, m) ((unsigned long)&((t *)0)->m) -#undef NULL#define NULL ((void*)0)
tools/firmware/include/stddef.h +2 -2
@@ -1,10 +1,10 @@#ifndef _STDDEF_H_#define _STDDEF_H_ +#include <xen-tools/common-macros.h> +typedef __SIZE_TYPE__ size_t ;#define NULL ((void*)0) -#define offsetof (t, m) __builtin_offsetof(t, m) -#endif
tools/include/xen-tools/common-macros.h +4 -0
@@ -79,4 +79,8 @@typeof ( ((type *)0 )->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) +#ifndef offsetof +#define offsetof (a, b) __builtin_offsetof(a, b) +#endif +#endif /* __XEN_TOOLS_COMMON_MACROS__ */
tools/libfsimage/Rules.mk +2 -0
@@ -3,6 +3,8 @@ include $(XEN_ROOT)/tools/libfsimage/common.mk FSLIB = fsimage.so TARGETS += $(FSLIB) +CFLAGS += $(CFLAGS_xeninclude) + .PHONY: all all: $(TARGETS)
tools/libfsimage/xfs/fsys_xfs.c +1 -3
@@ -19,6 +19,7 @@#include <xenfsimage_grub.h> #include "xfs.h" +#include <xen-tools/common-macros.h> #define MAX_LINK_COUNT 8
@@ -182,9 +183,6 @@ fsb2daddr (xfs_fsblock_t fsbno) (xfs_agblock_t)(fsbno & mask32lo(xfs.agblklog))); } -#undef offsetof -#define offsetof (t,m) ((size_t)&(((t *)0)->m)) -static inline int btroot_maxrecs (fsi_file_t *ffi) {
tools/libs/vchan/init.c +0 -4
@@ -69,10 +69,6 @@#define MAX_RING_SHIFT 20#define MAX_RING_SIZE (1 << MAX_RING_SHIFT) -#ifndef offsetof -#define offsetof (TYPE ,MEMBER ) ((size_t) &((TYPE *)0)->MEMBER) -#endif -static int init_gnt_srv (struct libxenvchan *ctrl,int domain) {int pages_left = ctrl->read.order >=PAGE_SHIFT ?1 << (ctrl->read.order -PAGE_SHIFT ) :0 ;
tools/tests/vhpet/emul.h +0 -2
@@ -115,8 +115,6 @@ enum NR_COMMON_SOFTIRQS }; -#define offsetof (t, m) ((unsigned long )&((t *)0)->m) -struct domain ;struct vcpu
Signature · 1 line
2.35.3
Re: [PATCH v2 4/4] tools: add offsetof() to xen-tools/common-macros.h
Quoted 5 lines · Juergen Gross
tools/firmware/include/stddef.h +0
-0@@ -1,10 +1,10 @@#ifndef _STDDEF_H_#define _STDDEF_H_
tools/firmware/include/stddef.h line 10
Quoted 10 lines
tools/firmware/include/stddef.h +2
-2+#include <xen-tools/common-macros.h> +typedef __SIZE_TYPE__ size_t ;#define NULL ((void*)0) -#define offsetof (t, m) __builtin_offsetof(t, m) -#endif
The C standard is pretty specific about what a header of this name may or (in particular here) may not define. You add much more to the name space than just the replacement offsetof(). If this was a header used by an individual component, this might be fine. But this header is meant to serve all components under firmware/ which care to include it. At present that's hvmloader (which we control, so we can arrange for it to be free of collisions) and rombios (which we do not really control, and which people also may not build routinely anymore).
Jan
Re: [PATCH v2 4/4] tools: add offsetof() to xen-tools/common-macros.h
Quoted 13 lines · Jan Beulich
Quoted 12 lines · Juergen Gross
tools/firmware/include/stddef.h +2
-0@@ -1,10 +1,10 @@#ifndef _STDDEF_H_#define _STDDEF_H_ +#include <xen-tools/common-macros.h> +typedef __SIZE_TYPE__ size_t ;#define NULL ((void*)0)
Quoted 13 lines
tools/firmware/include/stddef.h line 10
Quoted 3 lines
tools/firmware/include/stddef.h +0
-2-#define offsetof (t, m) __builtin_offsetof(t, m) -#endif The C standard is pretty specific about what a header of this name may or (in particular here) may not define. You add much more to the name space than just the replacement
offsetof(). If this was a header used by an individual component, this might be fine. But this header is meant to serve all components underfirmware/which care to include it. At present that's hvmloader (which we control, so we can arrange for it to be free of collisions) and rombios (which we do not really control, and which people also may not build routinely anymore).
Good point.
I have verified that the build is still succeeding without the modification of tools/firmware/include/stddef.h, so I'll drop this hunk.
Juergen
Quoted 63 lines · Juergen Gross
There are some macros defined multiple times in tools. Use only a single header file for defining those macros and drop the copies.
V2:
- add patch 1 (Andrew Cooper)Juergen Gross (4):
tools: renamexen-tools/libs.hfile tocommon-macros.h
tools: addcontainer_of()macro toxen-tools/common-macros.h
tools: get rid of additionalmin()andmax()definitions
tools: addoffsetof()toxen-tools/common-macros.htools/console/daemon/io.c | 2 +- tools/firmware/hvmloader/util.h | 11 ++-------- tools/firmware/include/stddef.h | 4 ++-- tools/fuzz/cpu-policy/afl-policy-fuzzer.c | 2 +- .../xen-tools/{libs.h => common-macros.h} | 22 ++++++++++++++++--- tools/libfsimage/Rules.mk | 2 ++ tools/libfsimage/xfs/fsys_xfs.c | 4 +--- tools/libs/call/buffer.c | 2 +- tools/libs/ctrl/xc_pm.c | 2 +- tools/libs/ctrl/xc_private.h | 2 +- tools/libs/foreignmemory/linux.c | 2 +- tools/libs/gnttab/freebsd.c | 2 +- tools/libs/gnttab/linux.c | 2 +- tools/libs/guest/xg_core_arm.c | 2 +- tools/libs/guest/xg_cpuid_x86.c | 2 +- tools/libs/guest/xg_dom_arm.c | 2 +- tools/libs/guest/xg_dom_bzimageloader.c | 2 +- tools/libs/guest/xg_dom_x86.c | 2 +- tools/libs/guest/xg_sr_common.c | 2 +- tools/libs/light/libxl_internal.h | 2 +- tools/libs/light/libxl_psr.c | 2 +- tools/libs/stat/xenstat_linux.c | 2 +- tools/libs/vchan/init.c | 7 +----- tools/misc/xen-access.c | 2 +- tools/misc/xen-cpuid.c | 2 +- tools/misc/xen-diag.c | 2 +- tools/misc/xen-hptool.c | 2 +- tools/misc/xen-livepatch.c | 2 +- tools/misc/xen-mfndump.c | 2 +- tools/misc/xenpm.c | 2 +- tools/ocaml/libs/mmap/xenmmap_stubs.c | 2 +- tools/ocaml/libs/xc/xenctrl_stubs.c | 2 +- tools/python/xen/lowlevel/xc/xc.c | 2 +- tools/tests/cpu-policy/test-cpu-policy.c | 2 +- .../paging-mempool/test-paging-mempool.c | 2 +- tools/tests/resource/test-resource.c | 2 +- tools/tests/tsx/test-tsx.c | 2 +- tools/tests/vhpet/emul.h | 16 +------------- tools/tests/vpci/emul.h | 22 +------------------ tools/tests/x86_emulator/x86-emulate.h | 7 +----- tools/tests/xenstore/test-xenstore.c | 2 +- tools/xenstore/list.h | 6 ++--- tools/xenstore/utils.h | 2 +- tools/xentrace/analyze.h | 2 +- tools/xl/xl_cmdtable.c | 2 +- xen/lib/x86/private.h | 2 +- 46 files changed, 68 insertions(+), 105 deletions(-)
Quoted 5 lines
rename
tools/include/xen-tools/{libs.h=>common-macros.h} (74%)Signature · 1 line
2.35.3