ia64/xen-unstable

changeset 9138:2d87e2747973

Make guest_access implementation arch-specific.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Sat Mar 04 10:32:10 2006 +0100 (2006-03-04)
parents eb24eb6bc341
children 64f11b0e2e7d
files xen/include/asm-ia64/guest_access.h xen/include/asm-x86/guest_access.h xen/include/public/arch-ia64.h xen/include/public/arch-x86_32.h xen/include/public/arch-x86_64.h xen/include/public/xen.h xen/include/xen/guest_access.h
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xen/include/asm-ia64/guest_access.h	Sat Mar 04 10:32:10 2006 +0100
     1.3 @@ -0,0 +1,63 @@
     1.4 +/******************************************************************************
     1.5 + * guest_access.h
     1.6 + * 
     1.7 + * Copyright (c) 2006, K A Fraser
     1.8 + */
     1.9 +
    1.10 +#ifndef __ASM_IA64_GUEST_ACCESS_H__
    1.11 +#define __ASM_IA64_GUEST_ACCESS_H__
    1.12 +
    1.13 +#include <asm/uaccess.h>
    1.14 +
    1.15 +/* Is the guest handle a NULL reference? */
    1.16 +#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
    1.17 +
    1.18 +/* Offset the given guest handle into the array it refers to. */
    1.19 +#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
    1.20 +
    1.21 +/* Cast a guest handle to the specified type of handle. */
    1.22 +#define guest_handle_cast(hnd, type) ({         \
    1.23 +    type *_x = (hnd).p;                         \
    1.24 +    (GUEST_HANDLE(type)) { _x };                \
    1.25 +})
    1.26 +
    1.27 +/*
    1.28 + * Copy an array of objects to guest context via a guest handle,
    1.29 + * specifying an offset into the guest array.
    1.30 + */
    1.31 +#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
    1.32 +    const typeof(ptr) _x = (hnd).p;                     \
    1.33 +    const typeof(ptr) _y = (ptr);                       \
    1.34 +    copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));       \
    1.35 +})
    1.36 +
    1.37 +/*
    1.38 + * Copy an array of objects from guest context via a guest handle,
    1.39 + * specifying an offset into the guest array.
    1.40 + */
    1.41 +#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
    1.42 +    const typeof(ptr) _x = (hnd).p;                     \
    1.43 +    const typeof(ptr) _y = (ptr);                       \
    1.44 +    copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));     \
    1.45 +})
    1.46 +
    1.47 +/*
    1.48 + * Pre-validate a guest handle.
    1.49 + * Allows use of faster __copy_* functions.
    1.50 + */
    1.51 +#define guest_handle_okay(hnd, nr)                      \
    1.52 +    array_access_ok((hnd).p, (nr), sizeof(*(hnd).p))
    1.53 +
    1.54 +#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
    1.55 +    const typeof(ptr) _x = (hnd).p;                     \
    1.56 +    const typeof(ptr) _y = (ptr);                       \
    1.57 +    __copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));     \
    1.58 +})
    1.59 +
    1.60 +#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
    1.61 +    const typeof(ptr) _x = (hnd).p;                     \
    1.62 +    const typeof(ptr) _y = (ptr);                       \
    1.63 +    __copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));   \
    1.64 +})
    1.65 +
    1.66 +#endif /* __ASM_IA64_GUEST_ACCESS_H__ */
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/xen/include/asm-x86/guest_access.h	Sat Mar 04 10:32:10 2006 +0100
     2.3 @@ -0,0 +1,63 @@
     2.4 +/******************************************************************************
     2.5 + * guest_access.h
     2.6 + * 
     2.7 + * Copyright (c) 2006, K A Fraser
     2.8 + */
     2.9 +
    2.10 +#ifndef __ASM_X86_GUEST_ACCESS_H__
    2.11 +#define __ASM_X86_GUEST_ACCESS_H__
    2.12 +
    2.13 +#include <asm/uaccess.h>
    2.14 +
    2.15 +/* Is the guest handle a NULL reference? */
    2.16 +#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
    2.17 +
    2.18 +/* Offset the given guest handle into the array it refers to. */
    2.19 +#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
    2.20 +
    2.21 +/* Cast a guest handle to the specified type of handle. */
    2.22 +#define guest_handle_cast(hnd, type) ({         \
    2.23 +    type *_x = (hnd).p;                         \
    2.24 +    (GUEST_HANDLE(type)) { _x };                \
    2.25 +})
    2.26 +
    2.27 +/*
    2.28 + * Copy an array of objects to guest context via a guest handle,
    2.29 + * specifying an offset into the guest array.
    2.30 + */
    2.31 +#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
    2.32 +    const typeof(ptr) _x = (hnd).p;                     \
    2.33 +    const typeof(ptr) _y = (ptr);                       \
    2.34 +    copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));       \
    2.35 +})
    2.36 +
    2.37 +/*
    2.38 + * Copy an array of objects from guest context via a guest handle,
    2.39 + * specifying an offset into the guest array.
    2.40 + */
    2.41 +#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
    2.42 +    const typeof(ptr) _x = (hnd).p;                     \
    2.43 +    const typeof(ptr) _y = (ptr);                       \
    2.44 +    copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));     \
    2.45 +})
    2.46 +
    2.47 +/*
    2.48 + * Pre-validate a guest handle.
    2.49 + * Allows use of faster __copy_* functions.
    2.50 + */
    2.51 +#define guest_handle_okay(hnd, nr)                      \
    2.52 +    array_access_ok((hnd).p, (nr), sizeof(*(hnd).p))
    2.53 +
    2.54 +#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
    2.55 +    const typeof(ptr) _x = (hnd).p;                     \
    2.56 +    const typeof(ptr) _y = (ptr);                       \
    2.57 +    __copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));     \
    2.58 +})
    2.59 +
    2.60 +#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
    2.61 +    const typeof(ptr) _x = (hnd).p;                     \
    2.62 +    const typeof(ptr) _y = (ptr);                       \
    2.63 +    __copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));   \
    2.64 +})
    2.65 +
    2.66 +#endif /* __ASM_X86_GUEST_ACCESS_H__ */
     3.1 --- a/xen/include/public/arch-ia64.h	Sat Mar 04 10:25:05 2006 +0100
     3.2 +++ b/xen/include/public/arch-ia64.h	Sat Mar 04 10:32:10 2006 +0100
     3.3 @@ -7,6 +7,28 @@
     3.4  #ifndef __HYPERVISOR_IF_IA64_H__
     3.5  #define __HYPERVISOR_IF_IA64_H__
     3.6  
     3.7 +#ifdef __XEN__
     3.8 +#define __DEFINE_GUEST_HANDLE(name, type) \
     3.9 +    typedef struct { type *p; } __guest_handle_ ## name
    3.10 +#else
    3.11 +#define __DEFINE_GUEST_HANDLE(name, type) \
    3.12 +    typedef type * __guest_handle_ ## name
    3.13 +#endif
    3.14 +
    3.15 +#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
    3.16 +#define GUEST_HANDLE(name)        __guest_handle_ ## name
    3.17 +
    3.18 +#ifndef __ASSEMBLY__
    3.19 +/* Guest handles for primitive C types. */
    3.20 +__DEFINE_GUEST_HANDLE(uchar, unsigned char);
    3.21 +__DEFINE_GUEST_HANDLE(uint,  unsigned int);
    3.22 +__DEFINE_GUEST_HANDLE(ulong, unsigned long);
    3.23 +DEFINE_GUEST_HANDLE(char);
    3.24 +DEFINE_GUEST_HANDLE(int);
    3.25 +DEFINE_GUEST_HANDLE(long);
    3.26 +DEFINE_GUEST_HANDLE(void);
    3.27 +#endif
    3.28 +
    3.29  /* Maximum number of virtual CPUs in multi-processor guests. */
    3.30  /* WARNING: before changing this, check that shared_info fits on a page */
    3.31  #define MAX_VIRT_CPUS 4
     4.1 --- a/xen/include/public/arch-x86_32.h	Sat Mar 04 10:25:05 2006 +0100
     4.2 +++ b/xen/include/public/arch-x86_32.h	Sat Mar 04 10:32:10 2006 +0100
     4.3 @@ -9,6 +9,28 @@
     4.4  #ifndef __XEN_PUBLIC_ARCH_X86_32_H__
     4.5  #define __XEN_PUBLIC_ARCH_X86_32_H__
     4.6  
     4.7 +#ifdef __XEN__
     4.8 +#define __DEFINE_GUEST_HANDLE(name, type) \
     4.9 +    typedef struct { type *p; } __guest_handle_ ## name
    4.10 +#else
    4.11 +#define __DEFINE_GUEST_HANDLE(name, type) \
    4.12 +    typedef type * __guest_handle_ ## name
    4.13 +#endif
    4.14 +
    4.15 +#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
    4.16 +#define GUEST_HANDLE(name)        __guest_handle_ ## name
    4.17 +
    4.18 +#ifndef __ASSEMBLY__
    4.19 +/* Guest handles for primitive C types. */
    4.20 +__DEFINE_GUEST_HANDLE(uchar, unsigned char);
    4.21 +__DEFINE_GUEST_HANDLE(uint,  unsigned int);
    4.22 +__DEFINE_GUEST_HANDLE(ulong, unsigned long);
    4.23 +DEFINE_GUEST_HANDLE(char);
    4.24 +DEFINE_GUEST_HANDLE(int);
    4.25 +DEFINE_GUEST_HANDLE(long);
    4.26 +DEFINE_GUEST_HANDLE(void);
    4.27 +#endif
    4.28 +
    4.29  /*
    4.30   * SEGMENT DESCRIPTOR TABLES
    4.31   */
     5.1 --- a/xen/include/public/arch-x86_64.h	Sat Mar 04 10:25:05 2006 +0100
     5.2 +++ b/xen/include/public/arch-x86_64.h	Sat Mar 04 10:32:10 2006 +0100
     5.3 @@ -9,6 +9,28 @@
     5.4  #ifndef __XEN_PUBLIC_ARCH_X86_64_H__
     5.5  #define __XEN_PUBLIC_ARCH_X86_64_H__
     5.6  
     5.7 +#ifdef __XEN__
     5.8 +#define __DEFINE_GUEST_HANDLE(name, type) \
     5.9 +    typedef struct { type *p; } __guest_handle_ ## name
    5.10 +#else
    5.11 +#define __DEFINE_GUEST_HANDLE(name, type) \
    5.12 +    typedef type * __guest_handle_ ## name
    5.13 +#endif
    5.14 +
    5.15 +#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
    5.16 +#define GUEST_HANDLE(name)        __guest_handle_ ## name
    5.17 +
    5.18 +#ifndef __ASSEMBLY__
    5.19 +/* Guest handles for primitive C types. */
    5.20 +__DEFINE_GUEST_HANDLE(uchar, unsigned char);
    5.21 +__DEFINE_GUEST_HANDLE(uint,  unsigned int);
    5.22 +__DEFINE_GUEST_HANDLE(ulong, unsigned long);
    5.23 +DEFINE_GUEST_HANDLE(char);
    5.24 +DEFINE_GUEST_HANDLE(int);
    5.25 +DEFINE_GUEST_HANDLE(long);
    5.26 +DEFINE_GUEST_HANDLE(void);
    5.27 +#endif
    5.28 +
    5.29  /*
    5.30   * SEGMENT DESCRIPTOR TABLES
    5.31   */
     6.1 --- a/xen/include/public/xen.h	Sat Mar 04 10:25:05 2006 +0100
     6.2 +++ b/xen/include/public/xen.h	Sat Mar 04 10:32:10 2006 +0100
     6.3 @@ -9,28 +9,6 @@
     6.4  #ifndef __XEN_PUBLIC_XEN_H__
     6.5  #define __XEN_PUBLIC_XEN_H__
     6.6  
     6.7 -#ifdef __XEN__
     6.8 -#define __DEFINE_GUEST_HANDLE(name, type) \
     6.9 -    typedef struct { type *p; } __guest_handle_ ## name
    6.10 -#else
    6.11 -#define __DEFINE_GUEST_HANDLE(name, type) \
    6.12 -    typedef type * __guest_handle_ ## name
    6.13 -#endif
    6.14 -
    6.15 -#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
    6.16 -#define GUEST_HANDLE(name)        __guest_handle_ ## name
    6.17 -
    6.18 -#ifndef __ASSEMBLY__
    6.19 -/* Guest handles for primitive C types. */
    6.20 -__DEFINE_GUEST_HANDLE(uchar, unsigned char);
    6.21 -__DEFINE_GUEST_HANDLE(uint,  unsigned int);
    6.22 -__DEFINE_GUEST_HANDLE(ulong, unsigned long);
    6.23 -DEFINE_GUEST_HANDLE(char);
    6.24 -DEFINE_GUEST_HANDLE(int);
    6.25 -DEFINE_GUEST_HANDLE(long);
    6.26 -DEFINE_GUEST_HANDLE(void);
    6.27 -#endif
    6.28 -
    6.29  #if defined(__i386__)
    6.30  #include "arch-x86_32.h"
    6.31  #elif defined(__x86_64__)
     7.1 --- a/xen/include/xen/guest_access.h	Sat Mar 04 10:25:05 2006 +0100
     7.2 +++ b/xen/include/xen/guest_access.h	Sat Mar 04 10:32:10 2006 +0100
     7.3 @@ -7,64 +7,17 @@
     7.4  #ifndef __XEN_GUEST_ACCESS_H__
     7.5  #define __XEN_GUEST_ACCESS_H__
     7.6  
     7.7 -#include <asm/uaccess.h>
     7.8 -
     7.9 -/* Is the guest handle a NULL reference? */
    7.10 -#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
    7.11 -
    7.12 -/* Offset the given guest handle into the array it refers to. */
    7.13 -#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
    7.14 +#include <asm/guest_access.h>
    7.15  
    7.16 -/* Cast a guest handle to the specified type of handle. */
    7.17 -#define guest_handle_cast(hnd, type) ({         \
    7.18 -    type *_x = (hnd).p;                         \
    7.19 -    (GUEST_HANDLE(type)) { _x };                \
    7.20 -})
    7.21 -
    7.22 -/*
    7.23 - * Copy an array of objects to guest context via a guest handle.
    7.24 - * Optionally specify an offset into the guest array.
    7.25 - */
    7.26 -#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
    7.27 -    const typeof(ptr) _x = (hnd).p;                     \
    7.28 -    const typeof(ptr) _y = (ptr);                       \
    7.29 -    copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));       \
    7.30 -})
    7.31  #define copy_to_guest(hnd, ptr, nr)                     \
    7.32      copy_to_guest_offset(hnd, 0, ptr, nr)
    7.33  
    7.34 -/*
    7.35 - * Copy an array of objects from guest context via a guest handle.
    7.36 - * Optionally specify an offset into the guest array.
    7.37 - */
    7.38 -#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
    7.39 -    const typeof(ptr) _x = (hnd).p;                     \
    7.40 -    const typeof(ptr) _y = (ptr);                       \
    7.41 -    copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));     \
    7.42 -})
    7.43  #define copy_from_guest(ptr, hnd, nr)                   \
    7.44      copy_from_guest_offset(ptr, hnd, 0, nr)
    7.45  
    7.46 -/*
    7.47 - * Pre-validate a guest handle.
    7.48 - * Allows use of faster __copy_* functions.
    7.49 - */
    7.50 -#define guest_handle_okay(hnd, nr)                      \
    7.51 -    array_access_ok((hnd).p, (nr), sizeof(*(hnd).p))
    7.52 -
    7.53 -#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
    7.54 -    const typeof(ptr) _x = (hnd).p;                     \
    7.55 -    const typeof(ptr) _y = (ptr);                       \
    7.56 -    __copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));     \
    7.57 -})
    7.58  #define __copy_to_guest(hnd, ptr, nr)                   \
    7.59      __copy_to_guest_offset(hnd, 0, ptr, nr)
    7.60  
    7.61 -#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
    7.62 -    const typeof(ptr) _x = (hnd).p;                     \
    7.63 -    const typeof(ptr) _y = (ptr);                       \
    7.64 -    __copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));   \
    7.65 -})
    7.66  #define __copy_from_guest(ptr, hnd, nr)                 \
    7.67      __copy_from_guest_offset(ptr, hnd, 0, nr)
    7.68