ia64/xen-unstable

changeset 13290:e98b092c2057

Add logic to generate headers reflecting the compatibility mode layout
of hypercall arguments. Provide infrastructure for accessing handles
passed from compatibility mode guests. Vector those hypercalls not
needing any translation to their native implementations.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Emmanuel Ackaouy <ack@xensource.com>
date Fri Jan 05 17:34:28 2007 +0000 (2007-01-05)
parents 5a690aa51fb5
children 4a164bf1edfc
files xen/Makefile xen/Rules.mk xen/arch/x86/x86_64/compat/entry.S xen/arch/x86/x86_64/compat/traps.c xen/common/Makefile xen/common/compat/Makefile xen/common/compat/kernel.c xen/common/kernel.c xen/include/Makefile xen/include/asm-x86/compat.h xen/include/asm-x86/x86_64/uaccess.h xen/include/xen/compat.h
line diff
     1.1 --- a/xen/Makefile	Fri Jan 05 17:34:27 2007 +0000
     1.2 +++ b/xen/Makefile	Fri Jan 05 17:34:28 2007 +0000
     1.3 @@ -48,6 +48,7 @@ build install debug clean distclean csco
     1.4  .PHONY: _clean
     1.5  _clean: delete-unfresh-files
     1.6  	$(MAKE) -C tools clean
     1.7 +	$(MAKE) -f $(BASEDIR)/Rules.mk -C include clean
     1.8  	$(MAKE) -f $(BASEDIR)/Rules.mk -C common clean
     1.9  	$(MAKE) -f $(BASEDIR)/Rules.mk -C drivers clean
    1.10  	$(MAKE) -f $(BASEDIR)/Rules.mk -C acm clean
    1.11 @@ -69,6 +70,7 @@ build install debug clean distclean csco
    1.12  	$(MAKE) -f $(BASEDIR)/Rules.mk include/xen/compile.h
    1.13  	$(MAKE) -f $(BASEDIR)/Rules.mk include/xen/acm_policy.h
    1.14  	[ -e include/asm ] || ln -sf asm-$(TARGET_ARCH) include/asm
    1.15 +	$(MAKE) -f $(BASEDIR)/Rules.mk -C include
    1.16  	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) asm-offsets.s
    1.17  	$(MAKE) -f $(BASEDIR)/Rules.mk include/asm-$(TARGET_ARCH)/asm-offsets.h
    1.18  	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) $(TARGET)
     2.1 --- a/xen/Rules.mk	Fri Jan 05 17:34:27 2007 +0000
     2.2 +++ b/xen/Rules.mk	Fri Jan 05 17:34:28 2007 +0000
     2.3 @@ -34,6 +34,7 @@ TARGET := $(BASEDIR)/xen
     2.4  
     2.5  HDRS := $(wildcard $(BASEDIR)/include/xen/*.h)
     2.6  HDRS += $(wildcard $(BASEDIR)/include/public/*.h)
     2.7 +HDRS += $(wildcard $(BASEDIR)/include/compat/*.h)
     2.8  HDRS += $(wildcard $(BASEDIR)/include/asm-$(TARGET_ARCH)/*.h)
     2.9  HDRS += $(wildcard $(BASEDIR)/include/asm-$(TARGET_ARCH)/$(TARGET_SUBARCH)/*.h)
    2.10  
     3.1 --- a/xen/arch/x86/x86_64/compat/entry.S	Fri Jan 05 17:34:27 2007 +0000
     3.2 +++ b/xen/arch/x86/x86_64/compat/entry.S	Fri Jan 05 17:34:28 2007 +0000
     3.3 @@ -281,28 +281,19 @@ CFIX14:
     3.4  #define compat_set_trap_table domain_crash_synchronous
     3.5  #define compat_mmu_update domain_crash_synchronous
     3.6  #define compat_set_gdt domain_crash_synchronous
     3.7 -#define compat_stack_switch domain_crash_synchronous
     3.8 -#define compat_fpu_taskswitch domain_crash_synchronous
     3.9 -#define compat_arch_sched_op_compat domain_crash_synchronous
    3.10  #define compat_platform_op domain_crash_synchronous
    3.11 -#define compat_set_debugreg domain_crash_synchronous
    3.12 -#define compat_get_debugreg domain_crash_synchronous
    3.13  #define compat_update_descriptor domain_crash_synchronous
    3.14  #define compat_memory_op domain_crash_synchronous
    3.15  #define compat_multicall domain_crash_synchronous
    3.16  #define compat_update_va_mapping domain_crash_synchronous
    3.17  #define compat_set_timer_op domain_crash_synchronous
    3.18  #define compat_event_channel_op_compat domain_crash_synchronous
    3.19 -#define compat_xen_version domain_crash_synchronous
    3.20 -#define compat_console_io domain_crash_synchronous
    3.21  #define compat_physdev_op_compat domain_crash_synchronous
    3.22  #define compat_grant_table_op domain_crash_synchronous
    3.23 -#define compat_vm_assist domain_crash_synchronous
    3.24  #define compat_update_va_mapping_otherdomain domain_crash_synchronous
    3.25  #define compat_vcpu_op domain_crash_synchronous
    3.26  #define compat_mmuext_op domain_crash_synchronous
    3.27  #define compat_acm_op domain_crash_synchronous
    3.28 -#define compat_nmi_op domain_crash_synchronous
    3.29  #define compat_arch_sched_op domain_crash_synchronous
    3.30  #define compat_xenoprof_op domain_crash_synchronous
    3.31  #define compat_event_channel_op domain_crash_synchronous
    3.32 @@ -314,29 +305,29 @@ ENTRY(compat_hypercall_table)
    3.33          .quad compat_set_trap_table     /*  0 */
    3.34          .quad compat_mmu_update
    3.35          .quad compat_set_gdt
    3.36 -        .quad compat_stack_switch
    3.37 +        .quad do_stack_switch
    3.38          .quad compat_set_callbacks
    3.39 -        .quad compat_fpu_taskswitch     /*  5 */
    3.40 -        .quad compat_arch_sched_op_compat
    3.41 +        .quad do_fpu_taskswitch         /*  5 */
    3.42 +        .quad do_sched_op_compat
    3.43          .quad compat_platform_op
    3.44 -        .quad compat_set_debugreg
    3.45 -        .quad compat_get_debugreg
    3.46 +        .quad do_set_debugreg
    3.47 +        .quad do_get_debugreg
    3.48          .quad compat_update_descriptor  /* 10 */
    3.49 -        .quad do_ni_hypercall
    3.50 +        .quad compat_ni_hypercall
    3.51          .quad compat_memory_op
    3.52          .quad compat_multicall
    3.53          .quad compat_update_va_mapping
    3.54          .quad compat_set_timer_op       /* 15 */
    3.55          .quad compat_event_channel_op_compat
    3.56          .quad compat_xen_version
    3.57 -        .quad compat_console_io
    3.58 +        .quad do_console_io
    3.59          .quad compat_physdev_op_compat
    3.60          .quad compat_grant_table_op     /* 20 */
    3.61          .quad compat_vm_assist
    3.62          .quad compat_update_va_mapping_otherdomain
    3.63          .quad compat_iret
    3.64          .quad compat_vcpu_op
    3.65 -        .quad do_ni_hypercall           /* 25 */
    3.66 +        .quad compat_ni_hypercall       /* 25 */
    3.67          .quad compat_mmuext_op
    3.68          .quad compat_acm_op
    3.69          .quad compat_nmi_op
    3.70 @@ -345,11 +336,11 @@ ENTRY(compat_hypercall_table)
    3.71          .quad compat_xenoprof_op
    3.72          .quad compat_event_channel_op
    3.73          .quad compat_physdev_op
    3.74 -        .quad do_ni_hypercall
    3.75 +        .quad compat_ni_hypercall
    3.76          .quad compat_sysctl             /* 35 */
    3.77          .quad compat_domctl
    3.78          .rept NR_hypercalls-((.-compat_hypercall_table)/8)
    3.79 -        .quad do_ni_hypercall
    3.80 +        .quad compat_ni_hypercall
    3.81          .endr
    3.82  
    3.83  ENTRY(compat_hypercall_args_table)
    3.84 @@ -359,12 +350,12 @@ ENTRY(compat_hypercall_args_table)
    3.85          .byte 2 /* compat_stack_switch      */
    3.86          .byte 4 /* compat_set_callbacks     */
    3.87          .byte 1 /* compat_fpu_taskswitch    */  /*  5 */
    3.88 -        .byte 2 /* compat_arch_sched_op_compat */
    3.89 +        .byte 2 /* compat_sched_op_compat   */
    3.90          .byte 1 /* compat_platform_op       */
    3.91          .byte 2 /* compat_set_debugreg      */
    3.92          .byte 1 /* compat_get_debugreg      */
    3.93          .byte 4 /* compat_update_descriptor */  /* 10 */
    3.94 -        .byte 0 /* do_ni_hypercall          */
    3.95 +        .byte 0 /* compat_ni_hypercall      */
    3.96          .byte 2 /* compat_memory_op         */
    3.97          .byte 2 /* compat_multicall         */
    3.98          .byte 4 /* compat_update_va_mapping */
    3.99 @@ -378,7 +369,7 @@ ENTRY(compat_hypercall_args_table)
   3.100          .byte 5 /* compat_update_va_mapping_otherdomain */
   3.101          .byte 0 /* compat_iret              */
   3.102          .byte 3 /* compat_vcpu_op           */
   3.103 -        .byte 0 /* do_ni_hypercall          */  /* 25 */
   3.104 +        .byte 0 /* compat_ni_hypercall      */  /* 25 */
   3.105          .byte 4 /* compat_mmuext_op         */
   3.106          .byte 1 /* compat_acm_op            */
   3.107          .byte 2 /* compat_nmi_op            */
   3.108 @@ -387,9 +378,9 @@ ENTRY(compat_hypercall_args_table)
   3.109          .byte 2 /* compat_xenoprof_op       */
   3.110          .byte 2 /* compat_event_channel_op  */
   3.111          .byte 2 /* compat_physdev_op        */
   3.112 -        .byte 0 /* do_ni_hypercall          */
   3.113 +        .byte 0 /* compat_ni_hypercall      */
   3.114          .byte 1 /* compat_sysctl            */  /* 35 */
   3.115          .byte 1 /* compat_domctl            */
   3.116          .rept NR_hypercalls-(.-compat_hypercall_args_table)
   3.117 -        .byte 0 /* do_ni_hypercall          */
   3.118 +        .byte 0 /* compat_ni_hypercall      */
   3.119          .endr
     4.1 --- a/xen/arch/x86/x86_64/compat/traps.c	Fri Jan 05 17:34:27 2007 +0000
     4.2 +++ b/xen/arch/x86/x86_64/compat/traps.c	Fri Jan 05 17:34:28 2007 +0000
     4.3 @@ -1,25 +1,6 @@
     4.4  #ifdef CONFIG_COMPAT
     4.5  
     4.6 -#if 0 /* XXX */
     4.7  #include <compat/callback.h>
     4.8 -#else
     4.9 -struct compat_xen_callback {
    4.10 -    unsigned int cs;
    4.11 -    unsigned int eip;
    4.12 -};
    4.13 -typedef struct compat_xen_callback xen_callback_compat_t;
    4.14 -
    4.15 -struct compat_callback_register {
    4.16 -    uint16_t type;
    4.17 -    uint16_t flags;
    4.18 -    xen_callback_compat_t address;
    4.19 -};
    4.20 -
    4.21 -struct compat_callback_unregister {
    4.22 -    uint16_t type;
    4.23 -    uint16_t _unused;
    4.24 -};
    4.25 -#endif
    4.26  
    4.27  void compat_show_guest_stack(struct cpu_user_regs *regs, int debug_stack_lines)
    4.28  {
     5.1 --- a/xen/common/Makefile	Fri Jan 05 17:34:27 2007 +0000
     5.2 +++ b/xen/common/Makefile	Fri Jan 05 17:34:28 2007 +0000
     5.3 @@ -35,5 +35,7 @@ obj-$(xenoprof)    += xenoprof.o
     5.4  
     5.5  obj-$(CONFIG_XENCOMM) += xencomm.o
     5.6  
     5.7 +subdir-$(CONFIG_COMPAT) += compat
     5.8 +
     5.9  # Object file contains changeset and compiler information.
    5.10  version.o: $(BASEDIR)/include/xen/compile.h
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/xen/common/compat/Makefile	Fri Jan 05 17:34:28 2007 +0000
     6.3 @@ -0,0 +1,4 @@
     6.4 +obj-y += kernel.o
     6.5 +
     6.6 +# extra dependencies
     6.7 +kernel.o:	../kernel.c
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/xen/common/compat/kernel.c	Fri Jan 05 17:34:28 2007 +0000
     7.3 @@ -0,0 +1,59 @@
     7.4 +/******************************************************************************
     7.5 + * kernel.c
     7.6 + */
     7.7 +
     7.8 +#include <xen/config.h>
     7.9 +#include <xen/init.h>
    7.10 +#include <xen/lib.h>
    7.11 +#include <xen/errno.h>
    7.12 +#include <xen/version.h>
    7.13 +#include <xen/sched.h>
    7.14 +#include <xen/shadow.h>
    7.15 +#include <xen/nmi.h>
    7.16 +#include <xen/guest_access.h>
    7.17 +#include <asm/current.h>
    7.18 +#include <compat/xen.h>
    7.19 +#include <compat/nmi.h>
    7.20 +#include <compat/version.h>
    7.21 +
    7.22 +#define xen_extraversion compat_extraversion
    7.23 +#define xen_extraversion_t compat_extraversion_t
    7.24 +
    7.25 +#define xen_compile_info compat_compile_info
    7.26 +#define xen_compile_info_t compat_compile_info_t
    7.27 +
    7.28 +CHECK_TYPE(capabilities_info);
    7.29 +
    7.30 +#define xen_platform_parameters compat_platform_parameters
    7.31 +#define xen_platform_parameters_t compat_platform_parameters_t
    7.32 +#undef HYPERVISOR_VIRT_START
    7.33 +#define HYPERVISOR_VIRT_START HYPERVISOR_COMPAT_VIRT_START
    7.34 +
    7.35 +#define xen_changeset_info compat_changeset_info
    7.36 +#define xen_changeset_info_t compat_changeset_info_t
    7.37 +
    7.38 +#define xen_feature_info compat_feature_info
    7.39 +#define xen_feature_info_t compat_feature_info_t
    7.40 +
    7.41 +CHECK_TYPE(domain_handle);
    7.42 +
    7.43 +#define xennmi_callback compat_nmi_callback
    7.44 +#define xennmi_callback_t compat_nmi_callback_t
    7.45 +
    7.46 +#define DO(fn) int compat_##fn
    7.47 +#define COMPAT
    7.48 +
    7.49 +#include "../kernel.c"
    7.50 +
    7.51 +int compat_disabled = 0;
    7.52 +boolean_param("no-pv-compat", compat_disabled);
    7.53 +
    7.54 +/*
    7.55 + * Local variables:
    7.56 + * mode: C
    7.57 + * c-set-style: "BSD"
    7.58 + * c-basic-offset: 4
    7.59 + * tab-width: 4
    7.60 + * indent-tabs-mode: nil
    7.61 + * End:
    7.62 + */
     8.1 --- a/xen/common/kernel.c	Fri Jan 05 17:34:27 2007 +0000
     8.2 +++ b/xen/common/kernel.c	Fri Jan 05 17:34:28 2007 +0000
     8.3 @@ -11,11 +11,14 @@
     8.4  #include <xen/version.h>
     8.5  #include <xen/sched.h>
     8.6  #include <xen/shadow.h>
     8.7 +#include <xen/nmi.h>
     8.8  #include <xen/guest_access.h>
     8.9  #include <asm/current.h>
    8.10  #include <public/nmi.h>
    8.11  #include <public/version.h>
    8.12  
    8.13 +#ifndef COMPAT
    8.14 +
    8.15  int tainted;
    8.16  
    8.17  void cmdline_parse(char *cmdline)
    8.18 @@ -116,11 +119,15 @@ void add_taint(unsigned flag)
    8.19      tainted |= flag;
    8.20  }
    8.21  
    8.22 +# define DO(fn) long do_##fn
    8.23 +
    8.24 +#endif
    8.25 +
    8.26  /*
    8.27   * Simple hypercalls.
    8.28   */
    8.29  
    8.30 -long do_xen_version(int cmd, XEN_GUEST_HANDLE(void) arg)
    8.31 +DO(xen_version)(int cmd, XEN_GUEST_HANDLE(void) arg)
    8.32  {
    8.33      switch ( cmd )
    8.34      {
    8.35 @@ -230,6 +237,8 @@ long do_xen_version(int cmd, XEN_GUEST_H
    8.36      return -ENOSYS;
    8.37  }
    8.38  
    8.39 +#ifndef COMPAT
    8.40 +
    8.41  long register_guest_nmi_callback(unsigned long address)
    8.42  {
    8.43      struct vcpu *v = current;
    8.44 @@ -260,7 +269,9 @@ long unregister_guest_nmi_callback(void)
    8.45      return 0;
    8.46  }
    8.47  
    8.48 -long do_nmi_op(unsigned int cmd, XEN_GUEST_HANDLE(void) arg)
    8.49 +#endif
    8.50 +
    8.51 +DO(nmi_op)(unsigned int cmd, XEN_GUEST_HANDLE(void) arg)
    8.52  {
    8.53      struct xennmi_callback cb;
    8.54      long rc = 0;
    8.55 @@ -284,12 +295,12 @@ long do_nmi_op(unsigned int cmd, XEN_GUE
    8.56      return rc;
    8.57  }
    8.58  
    8.59 -long do_vm_assist(unsigned int cmd, unsigned int type)
    8.60 +DO(vm_assist)(unsigned int cmd, unsigned int type)
    8.61  {
    8.62      return vm_assist(current->domain, cmd, type);
    8.63  }
    8.64  
    8.65 -long do_ni_hypercall(void)
    8.66 +DO(ni_hypercall)(void)
    8.67  {
    8.68      /* No-op hypercall. */
    8.69      return -ENOSYS;
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/xen/include/Makefile	Fri Jan 05 17:34:28 2007 +0000
     9.3 @@ -0,0 +1,57 @@
     9.4 +ifneq ($(CONFIG_COMPAT),)
     9.5 +
     9.6 +compat-arch-$(CONFIG_X86) := x86_32
     9.7 +
     9.8 +headers-y                 := $(shell echo public/*.h | sed -e 's,[^[:space:]]*-[^[:space:]]*,,g' -e 's,public/,compat/,g')
     9.9 +headers-y                 := $(filter-out %/dom0_ops.h,$(headers-y))
    9.10 +headers-y                 += compat/arch-$(compat-arch-y).h
    9.11 +
    9.12 +cppflags-y                := -include public/xen-compat.h
    9.13 +cppflags-$(CONFIG_X86)    += -m32
    9.14 +
    9.15 +# 8-byte types are 4-byte aligned on x86_32 ...
    9.16 +prefix-$(CONFIG_X86)      := \#pragma pack(push, 4)
    9.17 +suffix-$(CONFIG_X86)      := \#pragma pack(pop)
    9.18 +
    9.19 +endif
    9.20 +
    9.21 +.PHONY: all
    9.22 +all: $(headers-y)
    9.23 +
    9.24 +compat/%.h: compat/%.i Makefile
    9.25 +	id=_$$(echo $@ | sed 'y,abcdefghijklmnopqrstuvwxyz-/.,ABCDEFGHIJKLMNOPQRSTUVWXYZ___,'); \
    9.26 +	echo "#ifndef $$id" >$@.new; \
    9.27 +	echo "#define $$id" >>$@.new; \
    9.28 +	echo "#include <xen/compat.h>" >>$@.new; \
    9.29 +	$(if $(filter-out compat/arch-%.h,$@),echo "#include <$(patsubst compat/%,public/%,$@)>" >>$@.new;) \
    9.30 +	$(if $(prefix-y),echo "$(prefix-y)" >>$@.new;) \
    9.31 +	grep -v '^# [[:digit:]]' $< | \
    9.32 +	sed -e 's,__InClUdE__,#include,' \
    9.33 +	    -e 's,"xen-compat.h",<public/xen-compat.h>,' \
    9.34 +	    -e 's,\(struct\|union\|enum\)[[:space:]]\+\(xen_\?\)\?\([[:alpha:]_]\),\1 compat_\3,g' \
    9.35 +	    -e 's,_t\([^[:alnum:]_]\|$$\),_compat_t\1,g' \
    9.36 +	    -e 's,\(8\|16\|32\|64\)_compat_t\([^[:alnum:]_]\|$$\),\1_t\2,g' \
    9.37 +	    -e 's,\(^\|[^[:alnum:]_]\)xen_\?\([[:alnum:]_]*\)_compat_t\([^[:alnum:]_]\|$$\),\1compat_\2_t\3,g' \
    9.38 +	    -e 's,\(^\|[^[:alnum:]_]\)XEN_\?,\1COMPAT_,' \
    9.39 +	    -e 's,\(^\|[^[:alnum:]_]\)Xen_\?,\1Compat_,' \
    9.40 +	    -e 's,\(^\|[^[:alnum:]]\)long\([^[:alnum:]]\|$$\),\1int\2,g' | \
    9.41 +	uniq >>$@.new; \
    9.42 +	$(if $(suffix-y),echo "$(suffix-y)" >>$@.new;) \
    9.43 +	echo "#endif /* $$id */" >>$@.new
    9.44 +	mv -f $@.new $@
    9.45 +
    9.46 +compat/%.i: compat/%.c Makefile
    9.47 +	$(CPP) $(CFLAGS) $(cppflags-y) -o $@ $<
    9.48 +
    9.49 +compat/%.c: public/%.h Makefile
    9.50 +	mkdir -p $(@D)
    9.51 +	grep -v 'DEFINE_XEN_GUEST_HANDLE(long)' $< | \
    9.52 +	sed -e 's,^[[:space:]]*#[[:space:]]*include[[:space:]]\+,__InClUdE__ ,' \
    9.53 +	    -e 's,^[[:space:]]*#[[:space:]]*define[[:space:]]\+\([[:upper:]_]*_GUEST_HANDLE\),#define HIDE_\1,' \
    9.54 +	    -e 's,^[[:space:]]*#[[:space:]]*define[[:space:]]\+\([[:lower:]_]*_guest_handle\),#define hide_\1,' \
    9.55 +	    -e 's,XEN_GUEST_HANDLE\(_[[:xdigit:]]\+\)\?,COMPAT_HANDLE,g' \
    9.56 +	    >$@.new
    9.57 +	mv -f $@.new $@
    9.58 +
    9.59 +clean::
    9.60 +	rm -rf compat
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/xen/include/asm-x86/compat.h	Fri Jan 05 17:34:28 2007 +0000
    10.3 @@ -0,0 +1,6 @@
    10.4 +/******************************************************************************
    10.5 + * compat.h
    10.6 + */
    10.7 +
    10.8 +typedef uint32_t compat_ptr_t;
    10.9 +typedef unsigned long full_ptr_t;
    11.1 --- a/xen/include/asm-x86/x86_64/uaccess.h	Fri Jan 05 17:34:27 2007 +0000
    11.2 +++ b/xen/include/asm-x86/x86_64/uaccess.h	Fri Jan 05 17:34:28 2007 +0000
    11.3 @@ -15,6 +15,19 @@
    11.4  
    11.5  #define array_access_ok(addr, count, size) (__addr_ok(addr))
    11.6  
    11.7 +#ifdef CONFIG_COMPAT
    11.8 +
    11.9 +#define __compat_addr_ok(addr) \
   11.10 +    ((unsigned long)(addr) < HYPERVISOR_COMPAT_VIRT_START)
   11.11 +
   11.12 +#define compat_access_ok(addr, size) __compat_addr_ok((addr) + (size))
   11.13 +
   11.14 +#define compat_array_access_ok(addr,count,size) \
   11.15 +    (likely((count) < (~0U / (size))) && \
   11.16 +     compat_access_ok(addr, (count) * (size)))
   11.17 +
   11.18 +#endif
   11.19 +
   11.20  #define __put_user_size(x,ptr,size,retval,errret)			\
   11.21  do {									\
   11.22  	retval = 0;							\
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/xen/include/xen/compat.h	Fri Jan 05 17:34:28 2007 +0000
    12.3 @@ -0,0 +1,167 @@
    12.4 +/******************************************************************************
    12.5 + * compat.h
    12.6 + */
    12.7 +
    12.8 +#ifndef __XEN_COMPAT_H__
    12.9 +#define __XEN_COMPAT_H__
   12.10 +
   12.11 +#include <xen/config.h>
   12.12 +
   12.13 +#ifdef CONFIG_COMPAT
   12.14 +
   12.15 +#include <xen/types.h>
   12.16 +#include <asm/compat.h>
   12.17 +#include <compat/xlat.h>
   12.18 +
   12.19 +#define __DEFINE_COMPAT_HANDLE(name, type) \
   12.20 +    typedef struct { \
   12.21 +        compat_ptr_t c; \
   12.22 +        type *_[0] __attribute__((__packed__)); \
   12.23 +    } __compat_handle_ ## name
   12.24 +
   12.25 +#define DEFINE_COMPAT_HANDLE(name)   __DEFINE_COMPAT_HANDLE(name, name)
   12.26 +#define COMPAT_HANDLE(name)          __compat_handle_ ## name
   12.27 +
   12.28 +/* Is the compat handle a NULL reference? */
   12.29 +#define compat_handle_is_null(hnd)        ((hnd).c == 0)
   12.30 +
   12.31 +/* Offset the given compat handle into the array it refers to. */
   12.32 +#define compat_handle_add_offset(hnd, nr)                            \
   12.33 +    ((hnd).c += (nr) * sizeof(**(hnd)._))
   12.34 +
   12.35 +/* Cast a compat handle to the specified type of handle. */
   12.36 +#define compat_handle_cast(chnd, type) ({                            \
   12.37 +    type *_x = (__typeof__(**(chnd)._) *)(full_ptr_t)(chnd).c;       \
   12.38 +    (XEN_GUEST_HANDLE(type)) { _x };                                 \
   12.39 +})
   12.40 +
   12.41 +#define guest_from_compat_handle(ghnd, chnd)                         \
   12.42 +    set_xen_guest_handle(ghnd,                                       \
   12.43 +                         (__typeof__(**(chnd)._) *)(full_ptr_t)(chnd).c)
   12.44 +
   12.45 +/*
   12.46 + * Copy an array of objects to guest context via a compat handle,
   12.47 + * specifying an offset into the guest array.
   12.48 + */
   12.49 +#define copy_to_compat_offset(hnd, off, ptr, nr) ({                  \
   12.50 +    const typeof(ptr) _x = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
   12.51 +    const typeof(*(ptr)) *const _y = (ptr);                          \
   12.52 +    copy_to_user(_x + (off), _y, sizeof(*_x) * (nr));                \
   12.53 +})
   12.54 +
   12.55 +/*
   12.56 + * Copy an array of objects from guest context via a compat handle,
   12.57 + * specifying an offset into the guest array.
   12.58 + */
   12.59 +#define copy_from_compat_offset(ptr, hnd, off, nr) ({                \
   12.60 +    const typeof(ptr) _x = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
   12.61 +    const typeof(ptr) _y = (ptr);                                    \
   12.62 +    copy_from_user(_y, _x + (off), sizeof(*_x) * (nr));              \
   12.63 +})
   12.64 +
   12.65 +#define copy_to_compat(hnd, ptr, nr)                                 \
   12.66 +    copy_to_compat_offset(hnd, 0, ptr, nr)
   12.67 +
   12.68 +#define copy_from_compat(ptr, hnd, nr)                               \
   12.69 +    copy_from_compat_offset(ptr, hnd, 0, nr)
   12.70 +
   12.71 +/* Copy sub-field of a structure to guest context via a compat handle. */
   12.72 +#define copy_field_to_compat(hnd, ptr, field) ({                     \
   12.73 +    typeof((ptr)->field) *const _x = &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
   12.74 +    const typeof((ptr)->field) *const _y = &(ptr)->field;            \
   12.75 +    copy_to_user(_x, _y, sizeof(*_x));                               \
   12.76 +})
   12.77 +
   12.78 +/* Copy sub-field of a structure from guest context via a compat handle. */
   12.79 +#define copy_field_from_compat(ptr, hnd, field) ({                   \
   12.80 +    typeof((ptr)->field) *const _x = &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
   12.81 +    typeof((ptr)->field) *const _y = &(ptr)->field;                  \
   12.82 +    copy_from_user(_y, _x, sizeof(*_x));                             \
   12.83 +})
   12.84 +
   12.85 +/*
   12.86 + * Pre-validate a guest handle.
   12.87 + * Allows use of faster __copy_* functions.
   12.88 + */
   12.89 +#define compat_handle_okay(hnd, nr)                                  \
   12.90 +    compat_array_access_ok((void *)(full_ptr_t)(hnd).c, (nr), sizeof(**(hnd)._))
   12.91 +
   12.92 +#define __copy_to_compat_offset(hnd, off, ptr, nr) ({                \
   12.93 +    const typeof(ptr) _x = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
   12.94 +    const typeof(*(ptr)) *const _y = (ptr);                          \
   12.95 +    __copy_to_user(_x + (off), _y, sizeof(*_x) * (nr));              \
   12.96 +})
   12.97 +
   12.98 +#define __copy_from_compat_offset(ptr, hnd, off, nr) ({              \
   12.99 +    const typeof(ptr) _x = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
  12.100 +    const typeof(ptr) _y = (ptr);                                    \
  12.101 +    __copy_from_user(_y, _x + (off), sizeof(*_x) * (nr));            \
  12.102 +})
  12.103 +
  12.104 +#define __copy_to_compat(hnd, ptr, nr)                               \
  12.105 +    __copy_to_compat_offset(hnd, 0, ptr, nr)
  12.106 +
  12.107 +#define __copy_from_compat(ptr, hnd, nr)                             \
  12.108 +    __copy_from_compat_offset(ptr, hnd, 0, nr)
  12.109 +
  12.110 +#define __copy_field_to_compat(hnd, ptr, field) ({                   \
  12.111 +    typeof((ptr)->field) *const _x = &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
  12.112 +    const typeof((ptr)->field) *const _y = &(ptr)->field;            \
  12.113 +    __copy_to_user(_x, _y, sizeof(*_x));                             \
  12.114 +})
  12.115 +
  12.116 +#define __copy_field_from_compat(ptr, hnd, field) ({                 \
  12.117 +    typeof((ptr)->field) *const _x = &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
  12.118 +    typeof((ptr)->field) *const _y = &(ptr)->field;                  \
  12.119 +    __copy_from_user(_y, _x, sizeof(*_x));                           \
  12.120 +})
  12.121 +
  12.122 +
  12.123 +#define CHECK_TYPE(name) \
  12.124 +    typedef int __checkT ## name[1 - ((xen_ ## name ## _t *)0 != \
  12.125 +                                   (compat_ ## name ## _t *)0) * 2]
  12.126 +#define CHECK_TYPE_(k, n) \
  12.127 +    typedef int __checkT ## k ## _ ## n[1 - ((k xen_ ## n *)0 != \
  12.128 +                                          (k compat_ ## n *)0) * 2]
  12.129 +
  12.130 +#define CHECK_SIZE(name) \
  12.131 +    typedef int __checkS ## name[1 - (sizeof(xen_ ## name ## _t) != \
  12.132 +                                   sizeof(compat_ ## name ## _t)) * 2]
  12.133 +#define CHECK_SIZE_(k, n) \
  12.134 +    typedef int __checkS ## k ## _ ## n[1 - (sizeof(k xen_ ## n) != \
  12.135 +                                          sizeof(k compat_ ## n)) * 2]
  12.136 +
  12.137 +#define CHECK_FIELD(t, f) \
  12.138 +    typedef int __checkF ## t ## __ ## f[1 - (&((xen_ ## t ## _t *)0)->f != \
  12.139 +                                           &((compat_ ## t ## _t *)0)->f) * 2]
  12.140 +#define CHECK_FIELD_(k, n, f) \
  12.141 +    typedef int __checkF ## k ## _ ## n ## __ ## f[1 - (&((k xen_ ## n *)0)->f != \
  12.142 +                                                     &((k compat_ ## n *)0)->f) * 2]
  12.143 +
  12.144 +#define CHECK_SUBFIELD_1(t, f1, f2) \
  12.145 +    typedef int __checkF1 ## t ## __ ## f1 ## __ ## f2 \
  12.146 +                [1 - (&((xen_ ## t ## _t *)0)->f1.f2 != \
  12.147 +                   &((compat_ ## t ## _t *)0)->f1.f2) * 2]
  12.148 +#define CHECK_SUBFIELD_1_(k, n, f1, f2) \
  12.149 +    typedef int __checkF1 ## k ## _ ## n ## __ ## f1 ## __ ## f2 \
  12.150 +                [1 - (&((k xen_ ## n *)0)->f1.f2 != \
  12.151 +                   &((k compat_ ## n *)0)->f1.f2) * 2]
  12.152 +
  12.153 +#define CHECK_SUBFIELD_2(t, f1, f2, f3) \
  12.154 +    typedef int __checkF2 ## t ## __ ## f1 ## __ ## f2 ## __ ## f3 \
  12.155 +                [1 - (&((xen_ ## t ## _t *)0)->f1.f2.f3 != \
  12.156 +                   &((compat_ ## t ## _t *)0)->f1.f2.f3) * 2]
  12.157 +#define CHECK_SUBFIELD_2_(k, n, f1, f2, f3) \
  12.158 +    typedef int __checkF2 ## k ## _ ## n ## __ ## f1 ## __ ## f2 ## __ ## f3 \
  12.159 +                [1 - (&((k xen_ ## n *)0)->f1.f2.f3 != \
  12.160 +                   &((k compat_ ## n *)0)->f1.f2.f3) * 2]
  12.161 +
  12.162 +extern int compat_disabled;
  12.163 +
  12.164 +/* In-place translation functons: */
  12.165 +struct start_info;
  12.166 +void xlat_start_info(struct start_info *, enum XLAT_start_info_console);
  12.167 +
  12.168 +#endif
  12.169 +
  12.170 +#endif /* __XEN_COMPAT_H__ */