[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] x86emul/test: add a private header
This is to avoid having to duplicate auxiliary definitions in both source files. Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx> --- a/tools/tests/x86_emulator/test_x86_emulator.c +++ b/tools/tests/x86_emulator/test_x86_emulator.c @@ -1,15 +1,9 @@ -#include <assert.h> #include <errno.h> #include <limits.h> -#include <stdbool.h> #include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdint.h> -#include <xen/xen.h> #include <sys/mman.h> -#include "x86_emulate/x86_emulate.h" +#include "x86_emulate.h" #include "blowfish.h" #define verbose false /* Switch to true for far more logging. */ @@ -1373,7 +1367,7 @@ int main(int argc, char **argv) else printf("skipped\n"); - for ( j = 0; j < sizeof(blobs) / sizeof(*blobs); j++ ) + for ( j = 0; j < ARRAY_SIZE(blobs); j++ ) { memcpy(res, blobs[j].code, blobs[j].size); ctxt.addr_size = ctxt.sp_size = blobs[j].bitness; --- a/tools/tests/x86_emulator/x86_emulate.c +++ b/tools/tests/x86_emulator/x86_emulate.c @@ -1,34 +1,8 @@ -#include <assert.h> -#include <stdbool.h> -#include <stddef.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <xen/xen.h> - -#include "x86_emulate/x86_emulate.h" - -#define is_canonical_address(x) (((int64_t)(x) >> 47) == ((int64_t)(x) >> 63)) +#include "x86_emulate.h" #define EFER_SCE (1 << 0) #define EFER_LMA (1 << 10) -#define BUG() abort() -#define ASSERT_UNREACHABLE() assert(!__LINE__) - -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -/* Force a compilation error if condition is true */ -#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); }) -#define BUILD_BUG_ON_ZERO(cond) \ - sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); }) -#else -#define BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); }) -#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond)) -#endif - -#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m)) - #define cpu_has_amd_erratum(nr) 0 #define mark_regs_dirty(r) ((void)(r)) @@ -44,10 +18,4 @@ #define get_stub(stb) ((void *)((stb).addr = (uintptr_t)(stb).buf)) #define put_stub(stb) -#define __init -#define __maybe_unused __attribute__((__unused__)) - -#define likely(x) __builtin_expect(!!(x), true) -#define unlikely(x) __builtin_expect(!!(x), false) - #include "x86_emulate/x86_emulate.c" --- /dev/null +++ b/tools/tests/x86_emulator/x86_emulate.h @@ -0,0 +1,36 @@ +#include <assert.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <xen/xen.h> + +#define BUG() abort() +#define ASSERT assert +#define ASSERT_UNREACHABLE() assert(!__LINE__) + +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) + +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +/* Force a compilation error if condition is true */ +#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); }) +#define BUILD_BUG_ON_ZERO(cond) \ + sizeof(struct { _Static_assert(!(cond), "!(" #cond ")"); }) +#else +#define BUILD_BUG_ON_ZERO(cond) sizeof(struct { int:-!!(cond); }) +#define BUILD_BUG_ON(cond) ((void)BUILD_BUG_ON_ZERO(cond)) +#endif + +#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m))) +#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m)) + +#define __init +#define __maybe_unused __attribute__((__unused__)) + +#define likely(x) __builtin_expect(!!(x), true) +#define unlikely(x) __builtin_expect(!!(x), false) + +#define is_canonical_address(x) (((int64_t)(x) >> 47) == ((int64_t)(x) >> 63)) + +#include "x86_emulate/x86_emulate.h" --- a/xen/arch/x86/x86_emulate/x86_emulate.h +++ b/xen/arch/x86/x86_emulate/x86_emulate.h @@ -23,10 +23,6 @@ #ifndef __X86_EMULATE_H__ #define __X86_EMULATE_H__ -#if !defined(__XEN__) && !defined(ASSERT) -#define ASSERT assert -#endif - #define MAX_INST_LEN 15 struct x86_emulate_ctxt; Attachment:
x86emul-test-header.patch _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |