[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Merged.



# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID 64f11b0e2e7d0c53320c4dc6e983fcb144258c43
# Parent  f43f094467f6f401ec9f54f1855cf142adcef92f
# Parent  2d87e274797318ab3d1abe04f6007ee7f4df7d70
Merged.

diff -r f43f094467f6 -r 64f11b0e2e7d 
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
--- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Sat Mar  4 
18:15:36 2006
+++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c    Sat Mar  4 
18:16:36 2006
@@ -948,9 +948,25 @@
 }
 
 
+static struct file_operations xsd_kva_fops;
 static struct proc_dir_entry *xsd_kva_intf;
 static struct proc_dir_entry *xsd_port_intf;
 
+static int xsd_kva_mmap(struct file *file, struct vm_area_struct *vma)
+{
+       size_t size = vma->vm_end - vma->vm_start;
+
+       if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
+               return -EINVAL;
+
+       vma->vm_pgoff = mfn_to_pfn(xen_start_info->store_mfn);
+
+       if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
+                           size, vma->vm_page_prot))
+               return -EAGAIN;
+
+       return 0;
+}
 
 static int xsd_kva_read(char *page, char **start, off_t off,
                         int count, int *eof, void *data)
@@ -1024,9 +1040,14 @@
                xen_start_info->store_evtchn = op.u.alloc_unbound.port;
 
                /* And finally publish the above info in /proc/xen */
-               if((xsd_kva_intf = create_xen_proc_entry("xsd_kva", 0400)))
+               if ((xsd_kva_intf = create_xen_proc_entry("xsd_kva", 0400))) {
+                       memcpy(&xsd_kva_fops, xsd_kva_intf->proc_fops,
+                              sizeof(xsd_kva_fops));
+                       xsd_kva_fops.mmap = xsd_kva_mmap;
+                       xsd_kva_intf->proc_fops = &xsd_kva_fops;
                        xsd_kva_intf->read_proc = xsd_kva_read;
-               if((xsd_port_intf = create_xen_proc_entry("xsd_port", 0400)))
+               }
+               if ((xsd_port_intf = create_xen_proc_entry("xsd_port", 0400)))
                        xsd_port_intf->read_proc = xsd_port_read;
        }
 
diff -r f43f094467f6 -r 64f11b0e2e7d tools/firmware/vmxassist/setup.c
--- a/tools/firmware/vmxassist/setup.c  Sat Mar  4 18:15:36 2006
+++ b/tools/firmware/vmxassist/setup.c  Sat Mar  4 18:16:36 2006
@@ -123,6 +123,8 @@
 void
 setup_gdt(void)
 {
+       unsigned long long addr = (unsigned long long) &tss;
+
        /* setup task state segment */
        memset(&tss, 0, sizeof(tss));
        tss.ss0 = DATA_SELECTOR;
@@ -130,8 +132,7 @@
        tss.iomap_base = offsetof(struct tss, iomap);
 
        /* initialize gdt's tss selector */
-       unsigned long long addr = (unsigned long long) &tss;
-        gdt[TSS_SELECTOR / sizeof(gdt[0])] |=
+       gdt[TSS_SELECTOR / sizeof(gdt[0])] |=
                ((addr & 0xFF000000) << (56-24)) |
                ((addr & 0x00FF0000) << (32-16)) |
                ((addr & 0x0000FFFF) << (16)) |
diff -r f43f094467f6 -r 64f11b0e2e7d tools/ioemu/audio/audio.c
--- a/tools/ioemu/audio/audio.c Sat Mar  4 18:15:36 2006
+++ b/tools/ioemu/audio/audio.c Sat Mar  4 18:16:36 2006
@@ -713,7 +713,7 @@
     delta = now - sw->old_ticks;
     bytes = (delta * sw->bytes_per_second) / ticks_per_sec;
     if (delta < 0) {
-        dolog ("whoops delta(<0)=%lld\n", delta);
+        dolog ("whoops delta(<0)=%"PRId64"\n", delta);
         return 0;
     }
 
diff -r f43f094467f6 -r 64f11b0e2e7d tools/ioemu/hw/i8254.c
--- a/tools/ioemu/hw/i8254.c    Sat Mar  4 18:15:36 2006
+++ b/tools/ioemu/hw/i8254.c    Sat Mar  4 18:16:36 2006
@@ -249,7 +249,7 @@
     req->u.data |= (irq << 16);
     req->u.data |= (hvm_channel << 24);
     req->u.data |= ((s->rw_mode) << 26);
-    fprintf(logfile, "HVM_PIT:pass info 0x%llx to HV!\n", req->u.data);
+    fprintf(logfile, "HVM_PIT:pass info 0x%"PRIx64" to HV!\n", req->u.data);
 }
 
 static inline void pit_load_count(PITChannelState *s, int val)
diff -r f43f094467f6 -r 64f11b0e2e7d tools/ioemu/monitor.c
--- a/tools/ioemu/monitor.c     Sat Mar  4 18:15:36 2006
+++ b/tools/ioemu/monitor.c     Sat Mar  4 18:16:36 2006
@@ -676,19 +676,19 @@
             break;
         case '-':
             {
-                int has_option;
+                long has_option;
                 /* option */
-                
+
                 c = *typestr++;
                 if (c == '\0')
                     goto bad_type;
-                while (isspace(*p)) 
+                while (isspace(*p))
                     p++;
                 has_option = 0;
                 if (*p == '-') {
                     p++;
                     if (*p != c) {
-                        term_printf("%s: unsupported option -%c\n", 
+                        term_printf("%s: unsupported option -%c\n",
                                     cmdname, *p);
                         goto fail;
                     }
diff -r f43f094467f6 -r 64f11b0e2e7d tools/ioemu/target-i386-dm/helper2.c
--- a/tools/ioemu/target-i386-dm/helper2.c      Sat Mar  4 18:15:36 2006
+++ b/tools/ioemu/target-i386-dm/helper2.c      Sat Mar  4 18:16:36 2006
@@ -138,11 +138,11 @@
         req = &(shared_page->vcpu_iodata[i].vp_ioreq);
         term_printf("vcpu %d: event port %d\n",
                     i, shared_page->vcpu_iodata[i].vp_eport);
-        term_printf("  req state: %x, pvalid: %x, addr: %llx, "
-                    "data: %llx, count: %llx, size: %llx\n",
+        term_printf("  req state: %x, pvalid: %x, addr: %"PRIx64", "
+                    "data: %"PRIx64", count: %"PRIx64", size: %"PRIx64"\n",
                     req->state, req->pdata_valid, req->addr,
                     req->u.data, req->count, req->size);
-        term_printf("  IO totally occurred on this vcpu: %llx\n",
+        term_printf("  IO totally occurred on this vcpu: %"PRIx64"\n",
                     req->io_count);
     }
 }
@@ -158,8 +158,8 @@
         return req;
 
     fprintf(logfile, "False I/O request ... in-service already: "
-                     "%x, pvalid: %x, port: %llx, "
-                     "data: %llx, count: %llx, size: %llx\n",
+                     "%x, pvalid: %x, port: %"PRIx64", "
+                     "data: %"PRIx64", count: %"PRIx64", size: %"PRIx64"\n",
                      req->state, req->pdata_valid, req->addr,
                      req->u.data, req->count, req->size);
     return NULL;
@@ -460,12 +460,6 @@
         FD_ZERO(&wakeup_rfds);
         FD_SET(evtchn_fd, &wakeup_rfds);
 
-#if __WORDSIZE == 32
-#define ULONGLONG_MAX   0xffffffffffffffffULL
-#else
-#define ULONGLONG_MAX   ULONG_MAX
-#endif
-
         tun_receive_handler(&rfds);
         if ( FD_ISSET(evtchn_fd, &rfds) ) {
             cpu_handle_ioreq(env);
diff -r f43f094467f6 -r 64f11b0e2e7d tools/ioemu/vl.c
--- a/tools/ioemu/vl.c  Sat Mar  4 18:15:36 2006
+++ b/tools/ioemu/vl.c  Sat Mar  4 18:16:36 2006
@@ -2672,6 +2672,7 @@
     char qemu_dm_logfilename[64];
     const char *loadvm = NULL;
     unsigned long nr_pages, extra_pages, ram_pages, *page_array;
+    xc_dominfo_t info;
     extern void *shared_page;
     extern void *shared_vram;
 
@@ -3132,7 +3133,7 @@
 
     ram_pages = ram_size/PAGE_SIZE;
 #if defined(__i386__) || defined(__x86_64__)
-    vgaram_pages =  (vga_ram_size -1)/PAGE_SIZE + 1;
+    vgaram_pages =  (vga_ram_size -1) / PAGE_SIZE + 1;
     free_pages = vgaram_pages / L1_PAGETABLE_ENTRIES;
     extra_pages = vgaram_pages + free_pages;
 #else
@@ -3142,7 +3143,6 @@
 
     xc_handle = xc_interface_open();
 
-    xc_dominfo_t info;
     xc_domain_getinfo(xc_handle, domid, 1, &info);
 
     nr_pages = info.nr_pages + extra_pages;
diff -r f43f094467f6 -r 64f11b0e2e7d tools/xenstore/hashtable.c
--- a/tools/xenstore/hashtable.c        Sat Mar  4 18:15:36 2006
+++ b/tools/xenstore/hashtable.c        Sat Mar  4 18:16:36 2006
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
+#include <stdint.h>
 
 /*
 Credit for primes table: Aaron Krowne
@@ -22,7 +23,7 @@
 805306457, 1610612741
 };
 const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
-const float max_load_factor = 0.65;
+const unsigned int max_load_factor = 65; /* percentage */
 
 /*****************************************************************************/
 struct hashtable *
@@ -48,7 +49,7 @@
     h->entrycount   = 0;
     h->hashfn       = hashf;
     h->eqfn         = eqf;
-    h->loadlimit    = (unsigned int) ceil(size * max_load_factor);
+    h->loadlimit    = (unsigned int)(((uint64_t)size * max_load_factor) / 100);
     return h;
 }
 
@@ -121,7 +122,8 @@
         }
     }
     h->tablelength = newsize;
-    h->loadlimit   = (unsigned int) ceil(newsize * max_load_factor);
+    h->loadlimit   = (unsigned int)
+        (((uint64_t)newsize * max_load_factor) / 100);
     return -1;
 }
 
diff -r f43f094467f6 -r 64f11b0e2e7d tools/xenstore/xenstored_domain.c
--- a/tools/xenstore/xenstored_domain.c Sat Mar  4 18:15:36 2006
+++ b/tools/xenstore/xenstored_domain.c Sat Mar  4 18:16:36 2006
@@ -27,7 +27,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <paths.h>
 
 //#define DEBUG
 #include "utils.h"
@@ -466,21 +465,8 @@
 { 
        int rc, fd;
        evtchn_port_t port; 
-       unsigned long kva; 
        char str[20]; 
        struct domain *dom0; 
-
-       fd = open(XENSTORED_PROC_KVA, O_RDONLY); 
-       if (fd == -1)
-               return -1;
-
-       rc = read(fd, str, sizeof(str)); 
-       if (rc == -1)
-               goto outfd;
-       str[rc] = '\0'; 
-       kva = strtoul(str, NULL, 0); 
-
-       close(fd); 
 
        fd = open(XENSTORED_PROC_PORT, O_RDONLY); 
        if (fd == -1)
@@ -496,12 +482,12 @@
 
        dom0 = new_domain(NULL, 0, port); 
 
-       fd = open(_PATH_KMEM, O_RDWR);
+       fd = open(XENSTORED_PROC_KVA, O_RDWR);
        if (fd == -1)
                return -1;
 
        dom0->interface = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,
-                              MAP_SHARED, fd, kva);
+                              MAP_SHARED, fd, 0);
        if (dom0->interface == MAP_FAILED)
                goto outfd;
 
diff -r f43f094467f6 -r 64f11b0e2e7d xen/arch/ia64/xen/dom0_ops.c
--- a/xen/arch/ia64/xen/dom0_ops.c      Sat Mar  4 18:15:36 2006
+++ b/xen/arch/ia64/xen/dom0_ops.c      Sat Mar  4 18:16:36 2006
@@ -16,10 +16,11 @@
 #include <asm/pdb.h>
 #include <xen/trace.h>
 #include <xen/console.h>
+#include <xen/guest_access.h>
 #include <public/sched_ctl.h>
 #include <asm/vmx.h>
 
-long arch_do_dom0_op(dom0_op_t *op, dom0_op_t *u_dom0_op)
+long arch_do_dom0_op(dom0_op_t *op, GUEST_HANDLE(dom0_op_t) u_dom0_op)
 {
     long ret = 0;
 
@@ -64,7 +65,7 @@
 
         put_domain(d);
 
-        copy_to_user(u_dom0_op, op, sizeof(*op));
+        copy_to_guest(u_dom0_op, op, 1);
     }
     break;
 
@@ -74,7 +75,6 @@
         int n,j;
         int num = op->u.getpageframeinfo2.num;
         domid_t dom = op->u.getpageframeinfo2.domain;
-        unsigned long *s_ptr = (unsigned long*) op->u.getpageframeinfo2.array;
         struct domain *d;
         unsigned long *l_arr;
         ret = -ESRCH;
@@ -95,7 +95,8 @@
         {
             int k = ((num-n)>GPF2_BATCH)?GPF2_BATCH:(num-n);
 
-            if ( copy_from_user(l_arr, &s_ptr[n], k*sizeof(unsigned long)) )
+            if ( copy_from_guest_offset(l_arr, op->u.getpageframeinfo2.array,
+                                        n, k) )
             {
                 ret = -EINVAL;
                 break;
@@ -135,7 +136,8 @@
 
             }
 
-            if ( copy_to_user(&s_ptr[n], l_arr, k*sizeof(unsigned long)) )
+            if ( copy_to_guest_offset(op->u.getpageframeinfo2.array,
+                                      n, l_arr, k) )
             {
                 ret = -EINVAL;
                 break;
@@ -160,7 +162,6 @@
         unsigned long start_page = op->u.getmemlist.max_pfns >> 32;
         unsigned long nr_pages = op->u.getmemlist.max_pfns & 0xffffffff;
         unsigned long mfn;
-        unsigned long *buffer = op->u.getmemlist.buffer;
 
         ret = -EINVAL;
         if ( d != NULL )
@@ -180,16 +181,16 @@
             {
                 mfn = gmfn_to_mfn_foreign(d, i);
 
-                if ( put_user(mfn, buffer) )
+                if ( copy_to_guest_offset(op->u.getmemlist.buffer,
+                                          i - start_page, &mfn, 1) )
                 {
                     ret = -EFAULT;
                     break;
                 }
-                buffer++;
             }
 
             op->u.getmemlist.num_pfns = i - start_page;
-            copy_to_user(u_dom0_op, op, sizeof(*op));
+            copy_to_guest(u_dom0_op, op, 1);
             
             put_domain(d);
         }
@@ -211,7 +212,7 @@
         memset(pi->hw_cap, 0, sizeof(pi->hw_cap));
         //memcpy(pi->hw_cap, boot_cpu_data.x86_capability, NCAPINTS*4);
         ret = 0;
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
     }
     break;
diff -r f43f094467f6 -r 64f11b0e2e7d xen/arch/x86/dom0_ops.c
--- a/xen/arch/x86/dom0_ops.c   Sat Mar  4 18:15:36 2006
+++ b/xen/arch/x86/dom0_ops.c   Sat Mar  4 18:16:36 2006
@@ -10,6 +10,7 @@
 #include <xen/types.h>
 #include <xen/lib.h>
 #include <xen/mm.h>
+#include <xen/guest_access.h>
 #include <public/dom0_ops.h>
 #include <xen/sched.h>
 #include <xen/event.h>
@@ -48,7 +49,7 @@
         (void)rdmsr_safe(msr_addr, msr_lo, msr_hi);
 }
 
-long arch_do_dom0_op(struct dom0_op *op, struct dom0_op *u_dom0_op)
+long arch_do_dom0_op(struct dom0_op *op, GUEST_HANDLE(dom0_op_t) u_dom0_op)
 {
     long ret = 0;
 
@@ -75,7 +76,7 @@
 
             op->u.msr.out1 = msr_lo;
             op->u.msr.out2 = msr_hi;
-            copy_to_user(u_dom0_op, op, sizeof(*op));
+            copy_to_guest(u_dom0_op, op, 1);
         }
         ret = 0;
     }
@@ -90,7 +91,7 @@
         {
             ret = shadow_mode_control(d, &op->u.shadow_control);
             put_domain(d);
-            copy_to_user(u_dom0_op, op, sizeof(*op));
+            copy_to_guest(u_dom0_op, op, 1);
         } 
     }
     break;
@@ -102,10 +103,11 @@
             op->u.add_memtype.nr_mfns,
             op->u.add_memtype.type,
             1);
-        if (ret > 0)
-        {
-            (void)__put_user(0, &u_dom0_op->u.add_memtype.handle);
-            (void)__put_user(ret, &u_dom0_op->u.add_memtype.reg);
+        if ( ret > 0 )
+        {
+            op->u.add_memtype.handle = 0;
+            op->u.add_memtype.reg    = ret;
+            (void)copy_to_guest(u_dom0_op, op, 1);
             ret = 0;
         }
     }
@@ -136,9 +138,10 @@
         if ( op->u.read_memtype.reg < num_var_ranges )
         {
             mtrr_if->get(op->u.read_memtype.reg, &mfn, &nr_mfns, &type);
-            (void)__put_user(mfn, &u_dom0_op->u.read_memtype.mfn);
-            (void)__put_user(nr_mfns, &u_dom0_op->u.read_memtype.nr_mfns);
-            (void)__put_user(type, &u_dom0_op->u.read_memtype.type);
+            op->u.read_memtype.mfn     = mfn;
+            op->u.read_memtype.nr_mfns = nr_mfns;
+            op->u.read_memtype.type    = type;
+            (void)copy_to_guest(u_dom0_op, op, 1);
             ret = 0;
         }
     }
@@ -147,7 +150,7 @@
     case DOM0_MICROCODE:
     {
         extern int microcode_update(void *buf, unsigned long len);
-        ret = microcode_update(op->u.microcode.data, op->u.microcode.length);
+        ret = microcode_update(op->u.microcode.data.p, op->u.microcode.length);
     }
     break;
 
@@ -195,7 +198,7 @@
         memset(pi->hw_cap, 0, sizeof(pi->hw_cap));
         memcpy(pi->hw_cap, boot_cpu_data.x86_capability, NCAPINTS*4);
         ret = 0;
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
     }
     break;
@@ -245,7 +248,7 @@
 
         put_domain(d);
 
-        copy_to_user(u_dom0_op, op, sizeof(*op));
+        copy_to_guest(u_dom0_op, op, 1);
     }
     break;
 
@@ -255,7 +258,6 @@
         int n,j;
         int num = op->u.getpageframeinfo2.num;
         domid_t dom = op->u.getpageframeinfo2.domain;
-        unsigned long *s_ptr = (unsigned long*) op->u.getpageframeinfo2.array;
         struct domain *d;
         unsigned long *l_arr;
         ret = -ESRCH;
@@ -277,7 +279,8 @@
         {
             int k = ((num-n)>GPF2_BATCH)?GPF2_BATCH:(num-n);
 
-            if ( copy_from_user(l_arr, &s_ptr[n], k*sizeof(unsigned long)) )
+            if ( copy_from_guest_offset(l_arr, op->u.getpageframeinfo2.array,
+                                        n, k) )
             {
                 ret = -EINVAL;
                 break;
@@ -320,7 +323,8 @@
 
             }
 
-            if ( copy_to_user(&s_ptr[n], l_arr, k*sizeof(unsigned long)) )
+            if ( copy_to_guest_offset(op->u.getpageframeinfo2.array,
+                                      n, l_arr, k) )
             {
                 ret = -EINVAL;
                 break;
@@ -341,7 +345,6 @@
         struct domain *d = find_domain_by_id(op->u.getmemlist.domain);
         unsigned long max_pfns = op->u.getmemlist.max_pfns;
         unsigned long mfn;
-        unsigned long *buffer = op->u.getmemlist.buffer;
         struct list_head *list_ent;
 
         ret = -EINVAL;
@@ -353,19 +356,20 @@
             list_ent = d->page_list.next;
             for ( i = 0; (i < max_pfns) && (list_ent != &d->page_list); i++ )
             {
-                mfn = page_to_mfn(list_entry(list_ent, struct page_info, 
list));
-                if ( put_user(mfn, buffer) )
+                mfn = page_to_mfn(list_entry(
+                    list_ent, struct page_info, list));
+                if ( copy_to_guest_offset(op->u.getmemlist.buffer,
+                                          i, &mfn, 1) )
                 {
                     ret = -EFAULT;
                     break;
                 }
-                buffer++;
                 list_ent = mfn_to_page(mfn)->list.next;
             }
             spin_unlock(&d->page_alloc_lock);
 
             op->u.getmemlist.num_pfns = i;
-            copy_to_user(u_dom0_op, op, sizeof(*op));
+            copy_to_guest(u_dom0_op, op, 1);
             
             put_domain(d);
         }
@@ -401,13 +405,12 @@
             entry.start  = e820.map[i].addr;
             entry.end    = e820.map[i].addr + e820.map[i].size;
             entry.is_ram = (e820.map[i].type == E820_RAM);
-            (void)copy_to_user(
-                &op->u.physical_memory_map.memory_map[i],
-                &entry, sizeof(entry));
+            (void)copy_to_guest_offset(
+                op->u.physical_memory_map.memory_map, i, &entry, 1);
         }
 
         op->u.physical_memory_map.nr_map_entries = i;
-        (void)copy_to_user(u_dom0_op, op, sizeof(*op));
+        (void)copy_to_guest(u_dom0_op, op, 1);
     }
     break;
 
diff -r f43f094467f6 -r 64f11b0e2e7d xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c Sat Mar  4 18:15:36 2006
+++ b/xen/arch/x86/mm.c Sat Mar  4 18:16:36 2006
@@ -2788,7 +2788,7 @@
 }
 
 
-long arch_memory_op(int op, guest_handle(void) arg)
+long arch_memory_op(int op, GUEST_HANDLE(void) arg)
 {
     struct xen_reserved_phys_area xrpa;
     unsigned long pfn;
diff -r f43f094467f6 -r 64f11b0e2e7d xen/arch/x86/shadow32.c
--- a/xen/arch/x86/shadow32.c   Sat Mar  4 18:15:36 2006
+++ b/xen/arch/x86/shadow32.c   Sat Mar  4 18:16:36 2006
@@ -29,6 +29,7 @@
 #include <xen/event.h>
 #include <xen/sched.h>
 #include <xen/trace.h>
+#include <xen/guest_access.h>
 
 #define MFN_PINNED(_x) (mfn_to_page(_x)->u.inuse.type_info & PGT_pinned)
 #define va_to_l1mfn(_ed, _va) \
@@ -1508,14 +1509,14 @@
         d->arch.shadow_fault_count       = 0;
         d->arch.shadow_dirty_count       = 0;
  
-        if ( (sc->dirty_bitmap == NULL) || 
+        if ( guest_handle_is_null(sc->dirty_bitmap) ||
              (d->arch.shadow_dirty_bitmap == NULL) )
         {
             rc = -EINVAL;
             break;
         }
 
-        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
+        if ( sc->pages > d->arch.shadow_dirty_bitmap_size )
             sc->pages = d->arch.shadow_dirty_bitmap_size; 
 
 #define chunk (8*1024) /* Transfer and clear in 1kB chunks for L1 cache. */
@@ -1524,10 +1525,10 @@
             int bytes = ((((sc->pages - i) > chunk) ?
                           chunk : (sc->pages - i)) + 7) / 8;
      
-            if (copy_to_user(
-                    sc->dirty_bitmap + (i/(8*sizeof(unsigned long))),
-                    d->arch.shadow_dirty_bitmap +(i/(8*sizeof(unsigned long))),
-                    bytes))
+            if ( copy_to_guest_offset(
+                sc->dirty_bitmap, i/(8*sizeof(unsigned long)),
+                d->arch.shadow_dirty_bitmap +(i/(8*sizeof(unsigned long))),
+                (bytes+sizeof(unsigned long)-1) / sizeof(unsigned long)) )
             {
                 rc = -EINVAL;
                 break;
@@ -1544,18 +1545,20 @@
         sc->stats.fault_count       = d->arch.shadow_fault_count;
         sc->stats.dirty_count       = d->arch.shadow_dirty_count;
 
-        if ( (sc->dirty_bitmap == NULL) || 
+        if ( guest_handle_is_null(sc->dirty_bitmap) ||
              (d->arch.shadow_dirty_bitmap == NULL) )
         {
             rc = -EINVAL;
             break;
         }
  
-        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
+        if ( sc->pages > d->arch.shadow_dirty_bitmap_size )
             sc->pages = d->arch.shadow_dirty_bitmap_size; 
 
-        if (copy_to_user(sc->dirty_bitmap, 
-                         d->arch.shadow_dirty_bitmap, (sc->pages+7)/8))
+        if ( copy_to_guest(sc->dirty_bitmap, 
+                           d->arch.shadow_dirty_bitmap,
+                           (((sc->pages+7)/8)+sizeof(unsigned long)-1) /
+                           sizeof(unsigned long)) )
         {
             rc = -EINVAL;
             break;
diff -r f43f094467f6 -r 64f11b0e2e7d xen/arch/x86/shadow_public.c
--- a/xen/arch/x86/shadow_public.c      Sat Mar  4 18:15:36 2006
+++ b/xen/arch/x86/shadow_public.c      Sat Mar  4 18:16:36 2006
@@ -29,6 +29,7 @@
 #include <xen/event.h>
 #include <xen/sched.h>
 #include <xen/trace.h>
+#include <xen/guest_access.h>
 #include <asm/shadow_64.h>
 
 static int alloc_p2m_table(struct domain *d);
@@ -1267,14 +1268,14 @@
         d->arch.shadow_fault_count       = 0;
         d->arch.shadow_dirty_count       = 0;
  
-        if ( (sc->dirty_bitmap == NULL) || 
+        if ( guest_handle_is_null(sc->dirty_bitmap) ||
              (d->arch.shadow_dirty_bitmap == NULL) )
         {
             rc = -EINVAL;
             break;
         }
 
-        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
+        if ( sc->pages > d->arch.shadow_dirty_bitmap_size )
             sc->pages = d->arch.shadow_dirty_bitmap_size; 
 
 #define chunk (8*1024) /* Transfer and clear in 1kB chunks for L1 cache. */
@@ -1283,10 +1284,10 @@
             int bytes = ((((sc->pages - i) > chunk) ?
                           chunk : (sc->pages - i)) + 7) / 8;
 
-            if (copy_to_user(
-                sc->dirty_bitmap + (i/(8*sizeof(unsigned long))),
+            if ( copy_to_guest_offset(
+                sc->dirty_bitmap, i/(8*sizeof(unsigned long)),
                 d->arch.shadow_dirty_bitmap +(i/(8*sizeof(unsigned long))),
-                bytes))
+                (bytes+sizeof(unsigned long)-1) / sizeof(unsigned long)) )
             {
                 rc = -EINVAL;
                 break;
@@ -1302,18 +1303,20 @@
         sc->stats.fault_count       = d->arch.shadow_fault_count;
         sc->stats.dirty_count       = d->arch.shadow_dirty_count;
  
-        if ( (sc->dirty_bitmap == NULL) || 
+        if ( guest_handle_is_null(sc->dirty_bitmap) ||
              (d->arch.shadow_dirty_bitmap == NULL) )
         {
             rc = -EINVAL;
             break;
         }
  
-        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
+        if ( sc->pages > d->arch.shadow_dirty_bitmap_size )
             sc->pages = d->arch.shadow_dirty_bitmap_size; 
 
-        if (copy_to_user(sc->dirty_bitmap, 
-                         d->arch.shadow_dirty_bitmap, (sc->pages+7)/8))
+        if ( copy_to_guest(sc->dirty_bitmap, 
+                           d->arch.shadow_dirty_bitmap,
+                           (((sc->pages+7)/8)+sizeof(unsigned long)-1) /
+                           sizeof(unsigned long)) )
         {
             rc = -EINVAL;
             break;
diff -r f43f094467f6 -r 64f11b0e2e7d xen/arch/x86/x86_32/mm.c
--- a/xen/arch/x86/x86_32/mm.c  Sat Mar  4 18:15:36 2006
+++ b/xen/arch/x86/x86_32/mm.c  Sat Mar  4 18:16:36 2006
@@ -192,7 +192,7 @@
     }
 }
 
-long subarch_memory_op(int op, guest_handle(void) arg)
+long subarch_memory_op(int op, GUEST_HANDLE(void) arg)
 {
     struct xen_machphys_mfn_list xmml;
     unsigned long mfn;
diff -r f43f094467f6 -r 64f11b0e2e7d xen/arch/x86/x86_64/mm.c
--- a/xen/arch/x86/x86_64/mm.c  Sat Mar  4 18:15:36 2006
+++ b/xen/arch/x86/x86_64/mm.c  Sat Mar  4 18:16:36 2006
@@ -183,7 +183,7 @@
     }
 }
 
-long subarch_memory_op(int op, guest_handle(void) arg)
+long subarch_memory_op(int op, GUEST_HANDLE(void) arg)
 {
     struct xen_machphys_mfn_list xmml;
     l3_pgentry_t l3e;
diff -r f43f094467f6 -r 64f11b0e2e7d xen/common/dom0_ops.c
--- a/xen/common/dom0_ops.c     Sat Mar  4 18:15:36 2006
+++ b/xen/common/dom0_ops.c     Sat Mar  4 18:16:36 2006
@@ -17,13 +17,14 @@
 #include <xen/trace.h>
 #include <xen/console.h>
 #include <xen/iocap.h>
+#include <xen/guest_access.h>
 #include <asm/current.h>
 #include <public/dom0_ops.h>
 #include <public/sched_ctl.h>
 #include <acm/acm_hooks.h>
 
 extern long arch_do_dom0_op(
-    struct dom0_op *op, struct dom0_op *u_dom0_op);
+    struct dom0_op *op, GUEST_HANDLE(dom0_op_t) u_dom0_op);
 extern void arch_getdomaininfo_ctxt(
     struct vcpu *, struct vcpu_guest_context *);
 
@@ -89,7 +90,7 @@
     memcpy(info->handle, d->handle, sizeof(xen_domain_handle_t));
 }
 
-long do_dom0_op(struct dom0_op *u_dom0_op)
+long do_dom0_op(GUEST_HANDLE(dom0_op_t) u_dom0_op)
 {
     long ret = 0;
     struct dom0_op curop, *op = &curop;
@@ -99,7 +100,7 @@
     if ( !IS_PRIV(current->domain) )
         return -EPERM;
 
-    if ( copy_from_user(op, u_dom0_op, sizeof(*op)) )
+    if ( copy_from_guest(op, u_dom0_op, 1) )
         return -EFAULT;
 
     if ( op->interface_version != DOM0_INTERFACE_VERSION )
@@ -239,7 +240,7 @@
         ret = 0;
 
         op->u.createdomain.domain = d->domain_id;
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
     }
     break;
@@ -357,7 +358,7 @@
     case DOM0_SCHEDCTL:
     {
         ret = sched_ctl(&op->u.schedctl);
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
     }
     break;
@@ -365,7 +366,7 @@
     case DOM0_ADJUSTDOM:
     {
         ret = sched_adjdom(&op->u.adjustdom);
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
     }
     break;
@@ -398,20 +399,17 @@
 
         getdomaininfo(d, &op->u.getdomaininfo);
 
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )     
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
 
         put_domain(d);
     }
     break;
-
-
 
     case DOM0_GETDOMAININFOLIST:
     { 
         struct domain *d;
         dom0_getdomaininfo_t info;
-        dom0_getdomaininfo_t *buffer = op->u.getdomaininfolist.buffer;
         u32 num_domains = 0;
 
         read_lock(&domlist_lock);
@@ -432,13 +430,13 @@
 
             put_domain(d);
 
-            if ( copy_to_user(buffer, &info, sizeof(dom0_getdomaininfo_t)) )
+            if ( copy_to_guest_offset(op->u.getdomaininfolist.buffer,
+                                      num_domains, &info, 1) )
             {
                 ret = -EFAULT;
                 break;
             }
             
-            buffer++;
             num_domains++;
         }
         
@@ -449,7 +447,7 @@
         
         op->u.getdomaininfolist.num_domains = num_domains;
 
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
     }
     break;
@@ -489,12 +487,12 @@
         if ( v != current )
             vcpu_unpause(v);
 
-        if ( copy_to_user(op->u.getvcpucontext.ctxt, c, sizeof(*c)) )
+        if ( copy_to_guest(op->u.getvcpucontext.ctxt, c, 1) )
             ret = -EFAULT;
 
         xfree(c);
 
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )     
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
 
     getvcpucontext_out:
@@ -534,7 +532,7 @@
                    (int)sizeof(op->u.getvcpuinfo.cpumap)));
         ret = 0;
 
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )     
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
 
     getvcpuinfo_out:
@@ -554,7 +552,7 @@
     case DOM0_TBUFCONTROL:
     {
         ret = tb_control(&op->u.tbufcontrol);
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
     }
     break;
@@ -562,10 +560,10 @@
     case DOM0_READCONSOLE:
     {
         ret = read_console_ring(
-            &op->u.readconsole.buffer, 
+            op->u.readconsole.buffer, 
             &op->u.readconsole.count,
             op->u.readconsole.clear); 
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
     }
     break;
@@ -573,7 +571,7 @@
     case DOM0_SCHED_ID:
     {
         op->u.sched_id.sched_id = sched_id();
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
         else
             ret = 0;
@@ -678,15 +676,15 @@
     {
         extern int perfc_control(dom0_perfccontrol_t *);
         ret = perfc_control(&op->u.perfccontrol);
-        if ( copy_to_user(u_dom0_op, op, sizeof(*op)) )
+        if ( copy_to_guest(u_dom0_op, op, 1) )
             ret = -EFAULT;
     }
     break;
 #endif
 
     default:
-        ret = arch_do_dom0_op(op,u_dom0_op);
-
+        ret = arch_do_dom0_op(op, u_dom0_op);
+        break;
     }
 
     spin_unlock(&dom0_lock);
diff -r f43f094467f6 -r 64f11b0e2e7d xen/common/domain.c
--- a/xen/common/domain.c       Sat Mar  4 18:15:36 2006
+++ b/xen/common/domain.c       Sat Mar  4 18:16:36 2006
@@ -17,6 +17,7 @@
 #include <xen/softirq.h>
 #include <xen/domain_page.h>
 #include <xen/rangeset.h>
+#include <xen/guest_access.h>
 #include <asm/debugger.h>
 #include <public/dom0_ops.h>
 #include <public/sched.h>
@@ -380,7 +381,7 @@
     domain_pause(d);
 
     rc = -EFAULT;
-    if ( copy_from_user(c, setvcpucontext->ctxt, sizeof(*c)) == 0 )
+    if ( copy_from_guest(c, setvcpucontext->ctxt, 1) == 0 )
         rc = arch_set_info_guest(v, c);
 
     domain_unpause(d);
diff -r f43f094467f6 -r 64f11b0e2e7d xen/common/memory.c
--- a/xen/common/memory.c       Sat Mar  4 18:15:36 2006
+++ b/xen/common/memory.c       Sat Mar  4 18:16:36 2006
@@ -31,7 +31,7 @@
 static long
 increase_reservation(
     struct domain *d, 
-    guest_handle(ulong) extent_list,
+    GUEST_HANDLE(ulong) extent_list,
     unsigned int   nr_extents,
     unsigned int   extent_order,
     unsigned int   flags,
@@ -80,7 +80,7 @@
 static long
 populate_physmap(
     struct domain *d, 
-    guest_handle(ulong) extent_list,
+    GUEST_HANDLE(ulong) extent_list,
     unsigned int  nr_extents,
     unsigned int  extent_order,
     unsigned int  flags,
@@ -141,7 +141,7 @@
 static long
 decrease_reservation(
     struct domain *d,
-    guest_handle(ulong) extent_list,
+    GUEST_HANDLE(ulong) extent_list,
     unsigned int   nr_extents,
     unsigned int   extent_order,
     unsigned int   flags,
@@ -198,7 +198,7 @@
 
 static long
 translate_gpfn_list(
-    guest_handle(xen_translate_gpfn_list_t) uop, unsigned long *progress)
+    GUEST_HANDLE(xen_translate_gpfn_list_t) uop, unsigned long *progress)
 {
     struct xen_translate_gpfn_list op;
     unsigned long i, gpfn, mfn;
@@ -257,7 +257,7 @@
     return 0;
 }
 
-long do_memory_op(unsigned long cmd, guest_handle(void) arg)
+long do_memory_op(unsigned long cmd, GUEST_HANDLE(void) arg)
 {
     struct domain *d;
     int rc, op, flags = 0, preempted = 0;
diff -r f43f094467f6 -r 64f11b0e2e7d xen/common/perfc.c
--- a/xen/common/perfc.c        Sat Mar  4 18:15:36 2006
+++ b/xen/common/perfc.c        Sat Mar  4 18:16:36 2006
@@ -5,9 +5,10 @@
 #include <xen/perfc.h>
 #include <xen/keyhandler.h> 
 #include <xen/spinlock.h>
+#include <xen/mm.h>
+#include <xen/guest_access.h>
 #include <public/dom0_ops.h>
 #include <asm/uaccess.h>
-#include <xen/mm.h>
 
 #undef  PERFCOUNTER
 #undef  PERFCOUNTER_CPU
@@ -131,12 +132,12 @@
 
 static dom0_perfc_desc_t perfc_d[NR_PERFCTRS];
 static int               perfc_init = 0;
-static int perfc_copy_info(dom0_perfc_desc_t *desc)
+static int perfc_copy_info(GUEST_HANDLE(dom0_perfc_desc_t) desc)
 {
     unsigned int i, j;
     atomic_t *counters = (atomic_t *)&perfcounters;
 
-    if ( desc == NULL )
+    if ( guest_handle_is_null(desc) )
         return 0;
 
     /* We only copy the name and array-size information once. */
@@ -196,7 +197,7 @@
         }
     }
 
-    return (copy_to_user(desc, perfc_d, NR_PERFCTRS * sizeof(*desc)) ?
+    return (copy_to_guest(desc, (dom0_perfc_desc_t *)perfc_d, NR_PERFCTRS) ?
             -EFAULT : 0);
 }
 
diff -r f43f094467f6 -r 64f11b0e2e7d xen/drivers/char/console.c
--- a/xen/drivers/char/console.c        Sat Mar  4 18:15:36 2006
+++ b/xen/drivers/char/console.c        Sat Mar  4 18:16:36 2006
@@ -20,6 +20,7 @@
 #include <xen/keyhandler.h>
 #include <xen/mm.h>
 #include <xen/delay.h>
+#include <xen/guest_access.h>
 #include <asm/current.h>
 #include <asm/uaccess.h>
 #include <asm/debugger.h>
@@ -221,9 +222,8 @@
         conringc = conringp - CONRING_SIZE;
 }
 
-long read_console_ring(char **pstr, u32 *pcount, int clear)
-{
-    char *str = *pstr;
+long read_console_ring(GUEST_HANDLE(char) str, u32 *pcount, int clear)
+{
     unsigned int idx, len, max, sofar, c;
     unsigned long flags;
 
@@ -239,7 +239,7 @@
             len = CONRING_SIZE - idx;
         if ( (sofar + len) > max )
             len = max - sofar;
-        if ( copy_to_user(str + sofar, &conring[idx], len) )
+        if ( copy_to_guest_offset(str, sofar, &conring[idx], len) )
             return -EFAULT;
         sofar += len;
         c += len;
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/asm-x86/mm.h
--- a/xen/include/asm-x86/mm.h  Sat Mar  4 18:15:36 2006
+++ b/xen/include/asm-x86/mm.h  Sat Mar  4 18:16:36 2006
@@ -380,7 +380,7 @@
 int __sync_lazy_execstate(void);
 
 /* Arch-specific portion of memory_op hypercall. */
-long arch_memory_op(int op, guest_handle(void) arg);
-long subarch_memory_op(int op, guest_handle(void) arg);
+long arch_memory_op(int op, GUEST_HANDLE(void) arg);
+long subarch_memory_op(int op, GUEST_HANDLE(void) arg);
 
 #endif /* __ASM_X86_MM_H__ */
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/public/arch-ia64.h
--- a/xen/include/public/arch-ia64.h    Sat Mar  4 18:15:36 2006
+++ b/xen/include/public/arch-ia64.h    Sat Mar  4 18:16:36 2006
@@ -6,6 +6,28 @@
 
 #ifndef __HYPERVISOR_IF_IA64_H__
 #define __HYPERVISOR_IF_IA64_H__
+
+#ifdef __XEN__
+#define __DEFINE_GUEST_HANDLE(name, type) \
+    typedef struct { type *p; } __guest_handle_ ## name
+#else
+#define __DEFINE_GUEST_HANDLE(name, type) \
+    typedef type * __guest_handle_ ## name
+#endif
+
+#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
+#define GUEST_HANDLE(name)        __guest_handle_ ## name
+
+#ifndef __ASSEMBLY__
+/* Guest handles for primitive C types. */
+__DEFINE_GUEST_HANDLE(uchar, unsigned char);
+__DEFINE_GUEST_HANDLE(uint,  unsigned int);
+__DEFINE_GUEST_HANDLE(ulong, unsigned long);
+DEFINE_GUEST_HANDLE(char);
+DEFINE_GUEST_HANDLE(int);
+DEFINE_GUEST_HANDLE(long);
+DEFINE_GUEST_HANDLE(void);
+#endif
 
 /* Maximum number of virtual CPUs in multi-processor guests. */
 /* WARNING: before changing this, check that shared_info fits on a page */
@@ -298,6 +320,7 @@
     arch_initrd_info_t initrd;
     char cmdline[IA64_COMMAND_LINE_SIZE];
 } vcpu_guest_context_t;
+DEFINE_GUEST_HANDLE(vcpu_guest_context_t);
 
 #endif /* !__ASSEMBLY__ */
 
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/public/arch-x86_32.h
--- a/xen/include/public/arch-x86_32.h  Sat Mar  4 18:15:36 2006
+++ b/xen/include/public/arch-x86_32.h  Sat Mar  4 18:16:36 2006
@@ -8,6 +8,28 @@
 
 #ifndef __XEN_PUBLIC_ARCH_X86_32_H__
 #define __XEN_PUBLIC_ARCH_X86_32_H__
+
+#ifdef __XEN__
+#define __DEFINE_GUEST_HANDLE(name, type) \
+    typedef struct { type *p; } __guest_handle_ ## name
+#else
+#define __DEFINE_GUEST_HANDLE(name, type) \
+    typedef type * __guest_handle_ ## name
+#endif
+
+#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
+#define GUEST_HANDLE(name)        __guest_handle_ ## name
+
+#ifndef __ASSEMBLY__
+/* Guest handles for primitive C types. */
+__DEFINE_GUEST_HANDLE(uchar, unsigned char);
+__DEFINE_GUEST_HANDLE(uint,  unsigned int);
+__DEFINE_GUEST_HANDLE(ulong, unsigned long);
+DEFINE_GUEST_HANDLE(char);
+DEFINE_GUEST_HANDLE(int);
+DEFINE_GUEST_HANDLE(long);
+DEFINE_GUEST_HANDLE(void);
+#endif
 
 /*
  * SEGMENT DESCRIPTOR TABLES
@@ -130,6 +152,7 @@
     unsigned long failsafe_callback_eip;
     unsigned long vm_assist;                /* VMASST_TYPE_* bitmap */
 } vcpu_guest_context_t;
+DEFINE_GUEST_HANDLE(vcpu_guest_context_t);
 
 typedef struct arch_shared_info {
     unsigned long max_pfn;                  /* max pfn that appears in table */
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/public/arch-x86_64.h
--- a/xen/include/public/arch-x86_64.h  Sat Mar  4 18:15:36 2006
+++ b/xen/include/public/arch-x86_64.h  Sat Mar  4 18:16:36 2006
@@ -8,6 +8,28 @@
 
 #ifndef __XEN_PUBLIC_ARCH_X86_64_H__
 #define __XEN_PUBLIC_ARCH_X86_64_H__
+
+#ifdef __XEN__
+#define __DEFINE_GUEST_HANDLE(name, type) \
+    typedef struct { type *p; } __guest_handle_ ## name
+#else
+#define __DEFINE_GUEST_HANDLE(name, type) \
+    typedef type * __guest_handle_ ## name
+#endif
+
+#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name)
+#define GUEST_HANDLE(name)        __guest_handle_ ## name
+
+#ifndef __ASSEMBLY__
+/* Guest handles for primitive C types. */
+__DEFINE_GUEST_HANDLE(uchar, unsigned char);
+__DEFINE_GUEST_HANDLE(uint,  unsigned int);
+__DEFINE_GUEST_HANDLE(ulong, unsigned long);
+DEFINE_GUEST_HANDLE(char);
+DEFINE_GUEST_HANDLE(int);
+DEFINE_GUEST_HANDLE(long);
+DEFINE_GUEST_HANDLE(void);
+#endif
 
 /*
  * SEGMENT DESCRIPTOR TABLES
@@ -215,6 +237,7 @@
     uint64_t      gs_base_kernel;
     uint64_t      gs_base_user;
 } vcpu_guest_context_t;
+DEFINE_GUEST_HANDLE(vcpu_guest_context_t);
 
 typedef struct arch_shared_info {
     unsigned long max_pfn;                  /* max pfn that appears in table */
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/public/dom0_ops.h
--- a/xen/include/public/dom0_ops.h     Sat Mar  4 18:15:36 2006
+++ b/xen/include/public/dom0_ops.h     Sat Mar  4 18:16:36 2006
@@ -28,18 +28,21 @@
     /* IN variables. */
     domid_t       domain;
     unsigned long max_pfns;
-    void         *buffer;
+    GUEST_HANDLE(ulong) buffer;
     /* OUT variables. */
     unsigned long num_pfns;
 } dom0_getmemlist_t;
+DEFINE_GUEST_HANDLE(dom0_getmemlist_t);
 
 #define DOM0_SCHEDCTL          6
  /* struct sched_ctl_cmd is from sched-ctl.h   */
 typedef struct sched_ctl_cmd dom0_schedctl_t;
+DEFINE_GUEST_HANDLE(dom0_schedctl_t);
 
 #define DOM0_ADJUSTDOM         7
 /* struct sched_adjdom_cmd is from sched-ctl.h */
 typedef struct sched_adjdom_cmd dom0_adjustdom_t;
+DEFINE_GUEST_HANDLE(dom0_adjustdom_t);
 
 #define DOM0_CREATEDOMAIN      8
 typedef struct dom0_createdomain {
@@ -50,24 +53,28 @@
     /* Identifier for new domain (auto-allocate if zero is specified). */
     domid_t domain;
 } dom0_createdomain_t;
+DEFINE_GUEST_HANDLE(dom0_createdomain_t);
 
 #define DOM0_DESTROYDOMAIN     9
 typedef struct dom0_destroydomain {
     /* IN variables. */
     domid_t domain;
 } dom0_destroydomain_t;
+DEFINE_GUEST_HANDLE(dom0_destroydomain_t);
 
 #define DOM0_PAUSEDOMAIN      10
 typedef struct dom0_pausedomain {
     /* IN parameters. */
     domid_t domain;
 } dom0_pausedomain_t;
+DEFINE_GUEST_HANDLE(dom0_pausedomain_t);
 
 #define DOM0_UNPAUSEDOMAIN    11
 typedef struct dom0_unpausedomain {
     /* IN parameters. */
     domid_t domain;
 } dom0_unpausedomain_t;
+DEFINE_GUEST_HANDLE(dom0_unpausedomain_t);
 
 #define DOM0_GETDOMAININFO    12
 typedef struct dom0_getdomaininfo {
@@ -93,6 +100,7 @@
     uint32_t ssidref;
     xen_domain_handle_t handle;
 } dom0_getdomaininfo_t;
+DEFINE_GUEST_HANDLE(dom0_getdomaininfo_t);
 
 #define DOM0_SETVCPUCONTEXT   13
 typedef struct dom0_setvcpucontext {
@@ -100,8 +108,9 @@
     domid_t               domain;
     uint32_t              vcpu;
     /* IN/OUT parameters */
-    vcpu_guest_context_t *ctxt;
+    GUEST_HANDLE(vcpu_guest_context_t) ctxt;
 } dom0_setvcpucontext_t;
+DEFINE_GUEST_HANDLE(dom0_setvcpucontext_t);
 
 #define DOM0_MSR              15
 typedef struct dom0_msr {
@@ -115,6 +124,7 @@
     uint32_t out1;
     uint32_t out2;
 } dom0_msr_t;
+DEFINE_GUEST_HANDLE(dom0_msr_t);
 
 /*
  * Set clock such that it would read <secs,nsecs> after 00:00:00 UTC,
@@ -127,6 +137,7 @@
     uint32_t nsecs;
     uint64_t system_time;
 } dom0_settime_t;
+DEFINE_GUEST_HANDLE(dom0_settime_t);
 
 #define DOM0_GETPAGEFRAMEINFO 18
 #define NOTAB 0         /* normal page */
@@ -147,6 +158,7 @@
     /* Is the page PINNED to a type? */
     uint32_t type;         /* see above type defs */
 } dom0_getpageframeinfo_t;
+DEFINE_GUEST_HANDLE(dom0_getpageframeinfo_t);
 
 /*
  * Read console content from Xen buffer ring.
@@ -154,11 +166,12 @@
 #define DOM0_READCONSOLE      19
 typedef struct dom0_readconsole {
     /* IN variables. */
-    uint32_t clear;        /* Non-zero -> clear after reading. */
+    uint32_t clear;            /* Non-zero -> clear after reading. */
     /* IN/OUT variables. */
-    char    *buffer;       /* In: Buffer start; Out: Used buffer start */
-    uint32_t count;        /* In: Buffer size;  Out: Used buffer size  */
+    GUEST_HANDLE(char) buffer; /* In: Buffer start; Out: Used buffer start */
+    uint32_t count;            /* In: Buffer size;  Out: Used buffer size  */
 } dom0_readconsole_t;
+DEFINE_GUEST_HANDLE(dom0_readconsole_t);
 
 /* 
  * Set which physical cpus a vcpu can execute on.
@@ -170,6 +183,7 @@
     uint32_t  vcpu;
     cpumap_t  cpumap;
 } dom0_setvcpuaffinity_t;
+DEFINE_GUEST_HANDLE(dom0_setvcpuaffinity_t);
 
 /* Get trace buffers machine base address */
 #define DOM0_TBUFCONTROL       21
@@ -189,6 +203,7 @@
     unsigned long buffer_mfn;
     uint32_t size;
 } dom0_tbufcontrol_t;
+DEFINE_GUEST_HANDLE(dom0_tbufcontrol_t);
 
 /*
  * Get physical information about the host machine
@@ -204,6 +219,7 @@
     unsigned long free_pages;
     uint32_t hw_cap[8];
 } dom0_physinfo_t;
+DEFINE_GUEST_HANDLE(dom0_physinfo_t);
 
 /*
  * Get the ID of the current scheduler.
@@ -213,6 +229,7 @@
     /* OUT variable */
     uint32_t sched_id;
 } dom0_sched_id_t;
+DEFINE_GUEST_HANDLE(dom0_sched_id_t);
 
 /* 
  * Control shadow pagetables operation
@@ -234,17 +251,19 @@
     uint32_t dirty_net_count;     
     uint32_t dirty_block_count;     
 } dom0_shadow_control_stats_t;
+DEFINE_GUEST_HANDLE(dom0_shadow_control_stats_t);
 
 typedef struct dom0_shadow_control {
     /* IN variables. */
     domid_t        domain;
     uint32_t       op;
-    unsigned long *dirty_bitmap; /* pointer to locked buffer */
+    GUEST_HANDLE(ulong) dirty_bitmap;
     /* IN/OUT variables. */
     unsigned long  pages;        /* size of buffer, updated with actual size */
     /* OUT variables. */
     dom0_shadow_control_stats_t stats;
 } dom0_shadow_control_t;
+DEFINE_GUEST_HANDLE(dom0_shadow_control_t);
 
 #define DOM0_SETDOMAINMAXMEM   28
 typedef struct dom0_setdomainmaxmem {
@@ -252,6 +271,7 @@
     domid_t       domain;
     unsigned long max_memkb;
 } dom0_setdomainmaxmem_t;
+DEFINE_GUEST_HANDLE(dom0_setdomainmaxmem_t);
 
 #define DOM0_GETPAGEFRAMEINFO2 29   /* batched interface */
 typedef struct dom0_getpageframeinfo2 {
@@ -259,8 +279,9 @@
     domid_t        domain;
     unsigned long  num;
     /* IN/OUT variables. */
-    unsigned long *array;
+    GUEST_HANDLE(ulong) array;
 } dom0_getpageframeinfo2_t;
+DEFINE_GUEST_HANDLE(dom0_getpageframeinfo2_t);
 
 /*
  * Request memory range (@mfn, @mfn+@nr_mfns-1) to have type @type.
@@ -279,6 +300,7 @@
     uint32_t      handle;
     uint32_t      reg;
 } dom0_add_memtype_t;
+DEFINE_GUEST_HANDLE(dom0_add_memtype_t);
 
 /*
  * Tear down an existing memory-range type. If @handle is remembered then it
@@ -293,6 +315,7 @@
     uint32_t handle;
     uint32_t reg;
 } dom0_del_memtype_t;
+DEFINE_GUEST_HANDLE(dom0_del_memtype_t);
 
 /* Read current type of an MTRR (x86-specific). */
 #define DOM0_READ_MEMTYPE        33
@@ -304,6 +327,7 @@
     unsigned long nr_mfns;
     uint32_t type;
 } dom0_read_memtype_t;
+DEFINE_GUEST_HANDLE(dom0_read_memtype_t);
 
 /* Interface for controlling Xen software performance counters. */
 #define DOM0_PERFCCONTROL        34
@@ -315,20 +339,23 @@
     uint32_t     nr_vals;              /* number of values for this counter */
     uint32_t     vals[64];             /* array of values */
 } dom0_perfc_desc_t;
+DEFINE_GUEST_HANDLE(dom0_perfc_desc_t);
 typedef struct dom0_perfccontrol {
     /* IN variables. */
     uint32_t       op;                /*  DOM0_PERFCCONTROL_OP_??? */
     /* OUT variables. */
     uint32_t       nr_counters;       /*  number of counters */
-    dom0_perfc_desc_t *desc;          /*  counter information (or NULL) */
+    GUEST_HANDLE(dom0_perfc_desc_t) desc; /*  counter information (or NULL) */
 } dom0_perfccontrol_t;
+DEFINE_GUEST_HANDLE(dom0_perfccontrol_t);
 
 #define DOM0_MICROCODE           35
 typedef struct dom0_microcode {
     /* IN variables. */
-    void    *data;                    /* Pointer to microcode data */
+    GUEST_HANDLE(void) data;          /* Pointer to microcode data */
     uint32_t length;                  /* Length of microcode data. */
 } dom0_microcode_t;
+DEFINE_GUEST_HANDLE(dom0_microcode_t);
 
 #define DOM0_IOPORT_PERMISSION   36
 typedef struct dom0_ioport_permission {
@@ -337,6 +364,7 @@
     uint32_t nr_ports;                /* size of port range */
     uint8_t  allow_access;            /* allow or deny access to range? */
 } dom0_ioport_permission_t;
+DEFINE_GUEST_HANDLE(dom0_ioport_permission_t);
 
 #define DOM0_GETVCPUCONTEXT      37
 typedef struct dom0_getvcpucontext {
@@ -344,8 +372,9 @@
     domid_t  domain;                  /* domain to be affected */
     uint32_t vcpu;                    /* vcpu # */
     /* OUT variables. */
-    vcpu_guest_context_t *ctxt;
+    GUEST_HANDLE(vcpu_guest_context_t) ctxt;
 } dom0_getvcpucontext_t;
+DEFINE_GUEST_HANDLE(dom0_getvcpucontext_t);
 
 #define DOM0_GETVCPUINFO         43
 typedef struct dom0_getvcpuinfo {
@@ -360,16 +389,18 @@
     uint32_t cpu;                     /* current mapping   */
     cpumap_t cpumap;                  /* allowable mapping */
 } dom0_getvcpuinfo_t;
+DEFINE_GUEST_HANDLE(dom0_getvcpuinfo_t);
 
 #define DOM0_GETDOMAININFOLIST   38
 typedef struct dom0_getdomaininfolist {
     /* IN variables. */
     domid_t               first_domain;
     uint32_t              max_domains;
-    dom0_getdomaininfo_t *buffer;
+    GUEST_HANDLE(dom0_getdomaininfo_t) buffer;
     /* OUT variables. */
     uint32_t              num_domains;
 } dom0_getdomaininfolist_t;
+DEFINE_GUEST_HANDLE(dom0_getdomaininfolist_t);
 
 #define DOM0_PLATFORM_QUIRK      39  
 #define QUIRK_NOIRQBALANCING  1
@@ -377,37 +408,44 @@
     /* IN variables. */
     uint32_t quirk_id;
 } dom0_platform_quirk_t;
+DEFINE_GUEST_HANDLE(dom0_platform_quirk_t);
 
 #define DOM0_PHYSICAL_MEMORY_MAP 40
+typedef struct dom0_memory_map_entry {
+    uint64_t start, end;
+    uint32_t flags; /* reserved */
+    uint8_t  is_ram;
+} dom0_memory_map_entry_t;
+DEFINE_GUEST_HANDLE(dom0_memory_map_entry_t);
 typedef struct dom0_physical_memory_map {
     /* IN variables. */
     uint32_t max_map_entries;
     /* OUT variables. */
     uint32_t nr_map_entries;
-    struct dom0_memory_map_entry {
-        uint64_t start, end;
-        uint32_t flags; /* reserved */
-        uint8_t  is_ram;
-    } *memory_map;
+    GUEST_HANDLE(dom0_memory_map_entry_t) memory_map;
 } dom0_physical_memory_map_t;
+DEFINE_GUEST_HANDLE(dom0_physical_memory_map_t);
 
 #define DOM0_MAX_VCPUS 41
 typedef struct dom0_max_vcpus {
     domid_t  domain;        /* domain to be affected */
     uint32_t max;           /* maximum number of vcpus */
 } dom0_max_vcpus_t;
+DEFINE_GUEST_HANDLE(dom0_max_vcpus_t);
 
 #define DOM0_SETDOMAINHANDLE 44
 typedef struct dom0_setdomainhandle {
     domid_t domain;
     xen_domain_handle_t handle;
 } dom0_setdomainhandle_t;
+DEFINE_GUEST_HANDLE(dom0_setdomainhandle_t);
 
 #define DOM0_SETDEBUGGING 45
 typedef struct dom0_setdebugging {
     domid_t domain;
     uint8_t enable;
 } dom0_setdebugging_t;
+DEFINE_GUEST_HANDLE(dom0_setdebugging_t);
 
 #define DOM0_IRQ_PERMISSION 46
 typedef struct dom0_irq_permission {
@@ -415,6 +453,7 @@
     uint8_t pirq;
     uint8_t allow_access;    /* flag to specify enable/disable of IRQ access */
 } dom0_irq_permission_t;
+DEFINE_GUEST_HANDLE(dom0_irq_permission_t);
 
 #define DOM0_IOMEM_PERMISSION 47
 typedef struct dom0_iomem_permission {
@@ -423,12 +462,14 @@
     unsigned long nr_mfns;    /* number of pages in range (>0) */
     uint8_t allow_access;     /* allow (!0) or deny (0) access to range? */
 } dom0_iomem_permission_t;
+DEFINE_GUEST_HANDLE(dom0_iomem_permission_t);
  
 #define DOM0_HYPERCALL_INIT   48
 typedef struct dom0_hypercall_init {
     domid_t  domain;          /* domain to be affected */
     unsigned long mfn;        /* machine frame to be initialised */
 } dom0_hypercall_init_t;
+DEFINE_GUEST_HANDLE(dom0_hypercall_init_t);
  
 typedef struct dom0_op {
     uint32_t cmd;
@@ -471,9 +512,10 @@
         struct dom0_irq_permission    irq_permission;
         struct dom0_iomem_permission  iomem_permission;
         struct dom0_hypercall_init    hypercall_init;
-        uint8_t                  pad[128];
+        uint8_t                       pad[128];
     } u;
 } dom0_op_t;
+DEFINE_GUEST_HANDLE(dom0_op_t);
 
 #endif /* __XEN_PUBLIC_DOM0_OPS_H__ */
 
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/public/hvm/ioreq.h
--- a/xen/include/public/hvm/ioreq.h    Sat Mar  4 18:15:36 2006
+++ b/xen/include/public/hvm/ioreq.h    Sat Mar  4 18:16:36 2006
@@ -71,8 +71,8 @@
 typedef struct {
     ioreq_t         vp_ioreq;
     /* Event channel port */
-    unsigned long   vp_eport;   /* VMX vcpu uses this to notify DM */
-    unsigned long   dm_eport;   /* DM uses this to notify VMX vcpu */
+    unsigned int    vp_eport;   /* VMX vcpu uses this to notify DM */
+    unsigned int    dm_eport;   /* DM uses this to notify VMX vcpu */
 } vcpu_iodata_t;
 
 typedef struct {
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/public/memory.h
--- a/xen/include/public/memory.h       Sat Mar  4 18:15:36 2006
+++ b/xen/include/public/memory.h       Sat Mar  4 18:16:36 2006
@@ -29,7 +29,7 @@
      *   OUT: GMFN bases of extents that were allocated
      *   (NB. This command also updates the mach_to_phys translation table)
      */
-    guest_handle(ulong) extent_start;
+    GUEST_HANDLE(ulong) extent_start;
 
     /* Number of extents, and size/alignment of each (2^extent_order pages). */
     unsigned long  nr_extents;
@@ -50,7 +50,7 @@
     domid_t        domid;
 
 } xen_memory_reservation_t;
-define_guest_handle(xen_memory_reservation_t);
+DEFINE_GUEST_HANDLE(xen_memory_reservation_t);
 
 /*
  * Returns the maximum machine frame number of mapped RAM in this system.
@@ -86,7 +86,7 @@
      * any large discontiguities in the machine address space, 2MB gaps in
      * the machphys table will be represented by an MFN base of zero.
      */
-    guest_handle(ulong) extent_start;
+    GUEST_HANDLE(ulong) extent_start;
 
     /*
      * Number of extents written to the above array. This will be smaller
@@ -94,7 +94,7 @@
      */
     unsigned int nr_extents;
 } xen_machphys_mfn_list_t;
-define_guest_handle(xen_machphys_mfn_list_t);
+DEFINE_GUEST_HANDLE(xen_machphys_mfn_list_t);
 
 /*
  * Returns the base and size of the specified reserved 'RAM hole' in the
@@ -115,7 +115,7 @@
     /* Base and size of the specified reserved area. */
     unsigned long first_gpfn, nr_gpfns;
 } xen_reserved_phys_area_t;
-define_guest_handle(xen_reserved_phys_area_t);
+DEFINE_GUEST_HANDLE(xen_reserved_phys_area_t);
 
 /*
  * Translates a list of domain-specific GPFNs into MFNs. Returns a -ve error
@@ -130,15 +130,15 @@
     unsigned long nr_gpfns;
 
     /* List of GPFNs to translate. */
-    guest_handle(ulong) gpfn_list;
+    GUEST_HANDLE(ulong) gpfn_list;
 
     /*
      * Output list to contain MFN translations. May be the same as the input
      * list (in which case each input GPFN is overwritten with the output MFN).
      */
-    guest_handle(ulong) mfn_list;
+    GUEST_HANDLE(ulong) mfn_list;
 } xen_translate_gpfn_list_t;
-define_guest_handle(xen_translate_gpfn_list_t);
+DEFINE_GUEST_HANDLE(xen_translate_gpfn_list_t);
 
 #endif /* __XEN_PUBLIC_MEMORY_H__ */
 
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/public/xen.h
--- a/xen/include/public/xen.h  Sat Mar  4 18:15:36 2006
+++ b/xen/include/public/xen.h  Sat Mar  4 18:16:36 2006
@@ -8,28 +8,6 @@
 
 #ifndef __XEN_PUBLIC_XEN_H__
 #define __XEN_PUBLIC_XEN_H__
-
-#ifdef __XEN__
-#define __define_guest_handle(name, type) \
-    typedef struct { type *p; } __guest_handle_ ## name
-#else
-#define __define_guest_handle(name, type) \
-    typedef type * __guest_handle_ ## name
-#endif
-
-#define define_guest_handle(name) __define_guest_handle(name, name)
-#define guest_handle(name)        __guest_handle_ ## name
-
-#ifndef __ASSEMBLY__
-/* Guest handles for primitive C types. */
-__define_guest_handle(uchar, unsigned char);
-__define_guest_handle(uint,  unsigned int);
-__define_guest_handle(ulong, unsigned long);
-define_guest_handle(char);
-define_guest_handle(int);
-define_guest_handle(long);
-define_guest_handle(void);
-#endif
 
 #if defined(__i386__)
 #include "arch-x86_32.h"
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/xen/console.h
--- a/xen/include/xen/console.h Sat Mar  4 18:15:36 2006
+++ b/xen/include/xen/console.h Sat Mar  4 18:16:36 2006
@@ -13,7 +13,7 @@
 
 void set_printk_prefix(const char *prefix);
 
-long read_console_ring(char **, u32 *, int);
+long read_console_ring(GUEST_HANDLE(char), u32 *, int);
 
 void init_console(void);
 void console_endboot(int disable_vga);
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/xen/guest_access.h
--- a/xen/include/xen/guest_access.h    Sat Mar  4 18:15:36 2006
+++ b/xen/include/xen/guest_access.h    Sat Mar  4 18:16:36 2006
@@ -7,64 +7,17 @@
 #ifndef __XEN_GUEST_ACCESS_H__
 #define __XEN_GUEST_ACCESS_H__
 
-#include <asm/uaccess.h>
+#include <asm/guest_access.h>
 
-/* Is the guest handle a NULL reference? */
-#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
-
-/* Offset the given guest handle into the array it refers to. */
-#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
-
-/* Cast a guest handle to the specified type of handle. */
-#define guest_handle_cast(hnd, type) ({         \
-    type *_x = (hnd).p;                         \
-    (guest_handle(type)) { _x };                \
-})
-
-/*
- * Copy an array of objects to guest context via a guest handle.
- * Optionally specify an offset into the guest array.
- */
-#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
-    const typeof(ptr) _x = (hnd).p;                     \
-    const typeof(ptr) _y = (ptr);                       \
-    copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));       \
-})
 #define copy_to_guest(hnd, ptr, nr)                     \
     copy_to_guest_offset(hnd, 0, ptr, nr)
 
-/*
- * Copy an array of objects from guest context via a guest handle.
- * Optionally specify an offset into the guest array.
- */
-#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
-    const typeof(ptr) _x = (hnd).p;                     \
-    const typeof(ptr) _y = (ptr);                       \
-    copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));     \
-})
 #define copy_from_guest(ptr, hnd, nr)                   \
     copy_from_guest_offset(ptr, hnd, 0, nr)
 
-/*
- * Pre-validate a guest handle.
- * Allows use of faster __copy_* functions.
- */
-#define guest_handle_okay(hnd, nr)                      \
-    array_access_ok((hnd).p, (nr), sizeof(*(hnd).p))
-
-#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
-    const typeof(ptr) _x = (hnd).p;                     \
-    const typeof(ptr) _y = (ptr);                       \
-    __copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));     \
-})
 #define __copy_to_guest(hnd, ptr, nr)                   \
     __copy_to_guest_offset(hnd, 0, ptr, nr)
 
-#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
-    const typeof(ptr) _x = (hnd).p;                     \
-    const typeof(ptr) _y = (ptr);                       \
-    __copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));   \
-})
 #define __copy_from_guest(ptr, hnd, nr)                 \
     __copy_from_guest_offset(ptr, hnd, 0, nr)
 
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/xen/sched.h
--- a/xen/include/xen/sched.h   Sat Mar  4 18:15:36 2006
+++ b/xen/include/xen/sched.h   Sat Mar  4 18:16:36 2006
@@ -311,7 +311,7 @@
  *  'i' [unsigned] {char, int}
  *  'l' [unsigned] long
  *  'p' pointer (foo *)
- *  'h' guest handle (guest_handle(foo))
+ *  'h' guest handle (GUEST_HANDLE(foo))
  */
 unsigned long hypercall_create_continuation(
     unsigned int op, const char *format, ...);
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/asm-ia64/guest_access.h
--- /dev/null   Sat Mar  4 18:15:36 2006
+++ b/xen/include/asm-ia64/guest_access.h       Sat Mar  4 18:16:36 2006
@@ -0,0 +1,63 @@
+/******************************************************************************
+ * guest_access.h
+ * 
+ * Copyright (c) 2006, K A Fraser
+ */
+
+#ifndef __ASM_IA64_GUEST_ACCESS_H__
+#define __ASM_IA64_GUEST_ACCESS_H__
+
+#include <asm/uaccess.h>
+
+/* Is the guest handle a NULL reference? */
+#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
+
+/* Offset the given guest handle into the array it refers to. */
+#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
+
+/* Cast a guest handle to the specified type of handle. */
+#define guest_handle_cast(hnd, type) ({         \
+    type *_x = (hnd).p;                         \
+    (GUEST_HANDLE(type)) { _x };                \
+})
+
+/*
+ * Copy an array of objects to guest context via a guest handle,
+ * specifying an offset into the guest array.
+ */
+#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
+    const typeof(ptr) _x = (hnd).p;                     \
+    const typeof(ptr) _y = (ptr);                       \
+    copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));       \
+})
+
+/*
+ * Copy an array of objects from guest context via a guest handle,
+ * specifying an offset into the guest array.
+ */
+#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
+    const typeof(ptr) _x = (hnd).p;                     \
+    const typeof(ptr) _y = (ptr);                       \
+    copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));     \
+})
+
+/*
+ * Pre-validate a guest handle.
+ * Allows use of faster __copy_* functions.
+ */
+#define guest_handle_okay(hnd, nr)                      \
+    array_access_ok((hnd).p, (nr), sizeof(*(hnd).p))
+
+#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
+    const typeof(ptr) _x = (hnd).p;                     \
+    const typeof(ptr) _y = (ptr);                       \
+    __copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));     \
+})
+
+#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
+    const typeof(ptr) _x = (hnd).p;                     \
+    const typeof(ptr) _y = (ptr);                       \
+    __copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));   \
+})
+
+#endif /* __ASM_IA64_GUEST_ACCESS_H__ */
diff -r f43f094467f6 -r 64f11b0e2e7d xen/include/asm-x86/guest_access.h
--- /dev/null   Sat Mar  4 18:15:36 2006
+++ b/xen/include/asm-x86/guest_access.h        Sat Mar  4 18:16:36 2006
@@ -0,0 +1,63 @@
+/******************************************************************************
+ * guest_access.h
+ * 
+ * Copyright (c) 2006, K A Fraser
+ */
+
+#ifndef __ASM_X86_GUEST_ACCESS_H__
+#define __ASM_X86_GUEST_ACCESS_H__
+
+#include <asm/uaccess.h>
+
+/* Is the guest handle a NULL reference? */
+#define guest_handle_is_null(hnd)        ((hnd).p == NULL)
+
+/* Offset the given guest handle into the array it refers to. */
+#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
+
+/* Cast a guest handle to the specified type of handle. */
+#define guest_handle_cast(hnd, type) ({         \
+    type *_x = (hnd).p;                         \
+    (GUEST_HANDLE(type)) { _x };                \
+})
+
+/*
+ * Copy an array of objects to guest context via a guest handle,
+ * specifying an offset into the guest array.
+ */
+#define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
+    const typeof(ptr) _x = (hnd).p;                     \
+    const typeof(ptr) _y = (ptr);                       \
+    copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));       \
+})
+
+/*
+ * Copy an array of objects from guest context via a guest handle,
+ * specifying an offset into the guest array.
+ */
+#define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
+    const typeof(ptr) _x = (hnd).p;                     \
+    const typeof(ptr) _y = (ptr);                       \
+    copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));     \
+})
+
+/*
+ * Pre-validate a guest handle.
+ * Allows use of faster __copy_* functions.
+ */
+#define guest_handle_okay(hnd, nr)                      \
+    array_access_ok((hnd).p, (nr), sizeof(*(hnd).p))
+
+#define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
+    const typeof(ptr) _x = (hnd).p;                     \
+    const typeof(ptr) _y = (ptr);                       \
+    __copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));     \
+})
+
+#define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
+    const typeof(ptr) _x = (hnd).p;                     \
+    const typeof(ptr) _y = (ptr);                       \
+    __copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));   \
+})
+
+#endif /* __ASM_X86_GUEST_ACCESS_H__ */

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.