ia64/xen-unstable

changeset 7985:602aefe7bd48

Make it possible to run valgrind on code linked with the libxc libraries.
Valgrind cannot see when a hypercall has initialised entries in a data
structure, so appropriate memsets have been placed before using dom0_op_t,
privcmd_hypercall_t, and a couple of miscellaneous blocks passed into this
layer. This initialises the block so that valgrind considers it to be valid,
but the data therein will be immediately overwritten by the hypercall, all
being well.

These changes are semantically neutral if -DVALGRIND is not set.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Tue Nov 22 16:31:16 2005 +0100 (2005-11-22)
parents c1c8da6f2afe
children bc1bfdb35f29
files tools/libxc/Makefile tools/libxc/xc_bvtsched.c tools/libxc/xc_domain.c tools/libxc/xc_evtchn.c tools/libxc/xc_gnttab.c tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_misc.c tools/libxc/xc_private.c tools/libxc/xc_private.h tools/libxc/xc_ptrace.c tools/libxc/xc_sedf.c tools/libxc/xc_tbuf.c tools/libxc/xg_private.h
line diff
     1.1 --- a/tools/libxc/Makefile	Mon Nov 21 19:08:44 2005 +0100
     1.2 +++ b/tools/libxc/Makefile	Tue Nov 22 16:31:16 2005 +0100
     1.3 @@ -49,6 +49,11 @@ CFLAGS   += -Werror
     1.4  CFLAGS   += -O3
     1.5  CFLAGS   += -fno-strict-aliasing
     1.6  CFLAGS   += $(INCLUDES) -I.
     1.7 +
     1.8 +# Define this to make it possible to run valgrind on code linked with these
     1.9 +# libraries.
    1.10 +#CFLAGS   += -DVALGRIND -O0 -ggdb3
    1.11 +
    1.12  # Get gcc to generate the dependencies for us.
    1.13  CFLAGS   += -Wp,-MD,.$(@F).d
    1.14  LDFLAGS  += -L.
     2.1 --- a/tools/libxc/xc_bvtsched.c	Mon Nov 21 19:08:44 2005 +0100
     2.2 +++ b/tools/libxc/xc_bvtsched.c	Tue Nov 22 16:31:16 2005 +0100
     2.3 @@ -11,7 +11,7 @@
     2.4  int xc_bvtsched_global_set(int xc_handle,
     2.5                             unsigned long ctx_allow)
     2.6  {
     2.7 -    dom0_op_t op;
     2.8 +    DECLARE_DOM0_OP;
     2.9  
    2.10      op.cmd = DOM0_SCHEDCTL;
    2.11      op.u.schedctl.sched_id = SCHED_BVT;
    2.12 @@ -24,7 +24,7 @@ int xc_bvtsched_global_set(int xc_handle
    2.13  int xc_bvtsched_global_get(int xc_handle,
    2.14                             unsigned long *ctx_allow)
    2.15  {
    2.16 -    dom0_op_t op;
    2.17 +    DECLARE_DOM0_OP;
    2.18      int ret;
    2.19      
    2.20      op.cmd = DOM0_SCHEDCTL;
    2.21 @@ -46,7 +46,7 @@ int xc_bvtsched_domain_set(int xc_handle
    2.22                             long long warpl,
    2.23                             long long warpu)
    2.24  {
    2.25 -    dom0_op_t op;
    2.26 +    DECLARE_DOM0_OP;
    2.27      struct bvt_adjdom *bvtadj = &op.u.adjustdom.u.bvt;
    2.28  
    2.29      op.cmd = DOM0_ADJUSTDOM;
    2.30 @@ -72,7 +72,7 @@ int xc_bvtsched_domain_get(int xc_handle
    2.31                             long long *warpu)
    2.32  {
    2.33      
    2.34 -    dom0_op_t op;
    2.35 +    DECLARE_DOM0_OP;
    2.36      int ret;
    2.37      struct bvt_adjdom *adjptr = &op.u.adjustdom.u.bvt;
    2.38  
     3.1 --- a/tools/libxc/xc_domain.c	Mon Nov 21 19:08:44 2005 +0100
     3.2 +++ b/tools/libxc/xc_domain.c	Tue Nov 22 16:31:16 2005 +0100
     3.3 @@ -15,7 +15,7 @@ int xc_domain_create(int xc_handle,
     3.4                       uint32_t *pdomid)
     3.5  {
     3.6      int err;
     3.7 -    dom0_op_t op;
     3.8 +    DECLARE_DOM0_OP;
     3.9  
    3.10      op.cmd = DOM0_CREATEDOMAIN;
    3.11      op.u.createdomain.domain = (domid_t)*pdomid;
    3.12 @@ -32,7 +32,7 @@ int xc_domain_create(int xc_handle,
    3.13  int xc_domain_pause(int xc_handle, 
    3.14                      uint32_t domid)
    3.15  {
    3.16 -    dom0_op_t op;
    3.17 +    DECLARE_DOM0_OP;
    3.18      op.cmd = DOM0_PAUSEDOMAIN;
    3.19      op.u.pausedomain.domain = (domid_t)domid;
    3.20      return do_dom0_op(xc_handle, &op);
    3.21 @@ -42,7 +42,7 @@ int xc_domain_pause(int xc_handle,
    3.22  int xc_domain_unpause(int xc_handle,
    3.23                        uint32_t domid)
    3.24  {
    3.25 -    dom0_op_t op;
    3.26 +    DECLARE_DOM0_OP;
    3.27      op.cmd = DOM0_UNPAUSEDOMAIN;
    3.28      op.u.unpausedomain.domain = (domid_t)domid;
    3.29      return do_dom0_op(xc_handle, &op);
    3.30 @@ -52,7 +52,7 @@ int xc_domain_unpause(int xc_handle,
    3.31  int xc_domain_destroy(int xc_handle,
    3.32                        uint32_t domid)
    3.33  {
    3.34 -    dom0_op_t op;
    3.35 +    DECLARE_DOM0_OP;
    3.36      op.cmd = DOM0_DESTROYDOMAIN;
    3.37      op.u.destroydomain.domain = (domid_t)domid;
    3.38      return do_dom0_op(xc_handle, &op);
    3.39 @@ -63,7 +63,7 @@ int xc_domain_pincpu(int xc_handle,
    3.40                       int vcpu,
    3.41                       cpumap_t cpumap)
    3.42  {
    3.43 -    dom0_op_t op;
    3.44 +    DECLARE_DOM0_OP;
    3.45      op.cmd = DOM0_PINCPUDOMAIN;
    3.46      op.u.pincpudomain.domain  = (domid_t)domid;
    3.47      op.u.pincpudomain.vcpu    = vcpu;
    3.48 @@ -79,7 +79,7 @@ int xc_domain_getinfo(int xc_handle,
    3.49  {
    3.50      unsigned int nr_doms;
    3.51      uint32_t next_domid = first_domid;
    3.52 -    dom0_op_t op;
    3.53 +    DECLARE_DOM0_OP;
    3.54      int rc = 0; 
    3.55  
    3.56      memset(info, 0, max_doms*sizeof(xc_dominfo_t));
    3.57 @@ -134,7 +134,7 @@ int xc_domain_getinfolist(int xc_handle,
    3.58                            xc_domaininfo_t *info)
    3.59  {
    3.60      int ret = 0;
    3.61 -    dom0_op_t op;
    3.62 +    DECLARE_DOM0_OP;
    3.63  
    3.64      if ( mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
    3.65          return -1;
    3.66 @@ -161,7 +161,7 @@ int xc_domain_get_vcpu_context(int xc_ha
    3.67                                 vcpu_guest_context_t *ctxt)
    3.68  {
    3.69      int rc;
    3.70 -    dom0_op_t op;
    3.71 +    DECLARE_DOM0_OP;
    3.72  
    3.73      op.cmd = DOM0_GETVCPUCONTEXT;
    3.74      op.u.getvcpucontext.domain = (domid_t)domid;
    3.75 @@ -187,7 +187,7 @@ int xc_shadow_control(int xc_handle,
    3.76                        xc_shadow_control_stats_t *stats )
    3.77  {
    3.78      int rc;
    3.79 -    dom0_op_t op;
    3.80 +    DECLARE_DOM0_OP;
    3.81      op.cmd = DOM0_SHADOW_CONTROL;
    3.82      op.u.shadow_control.domain = (domid_t)domid;
    3.83      op.u.shadow_control.op     = sop;
    3.84 @@ -250,7 +250,7 @@ int xc_domain_setmaxmem(int xc_handle,
    3.85                          uint32_t domid, 
    3.86                          unsigned int max_memkb)
    3.87  {
    3.88 -    dom0_op_t op;
    3.89 +    DECLARE_DOM0_OP;
    3.90      op.cmd = DOM0_SETDOMAINMAXMEM;
    3.91      op.u.setdomainmaxmem.domain = (domid_t)domid;
    3.92      op.u.setdomainmaxmem.max_memkb = max_memkb;
    3.93 @@ -328,7 +328,7 @@ int xc_domain_memory_decrease_reservatio
    3.94  
    3.95  int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max)
    3.96  {
    3.97 -    dom0_op_t op;
    3.98 +    DECLARE_DOM0_OP;
    3.99      op.cmd = DOM0_MAX_VCPUS;
   3.100      op.u.max_vcpus.domain = (domid_t)domid;
   3.101      op.u.max_vcpus.max    = max;
   3.102 @@ -338,7 +338,7 @@ int xc_domain_max_vcpus(int xc_handle, u
   3.103  int xc_domain_sethandle(int xc_handle, uint32_t domid, 
   3.104                          xen_domain_handle_t handle)
   3.105  {
   3.106 -    dom0_op_t op;
   3.107 +    DECLARE_DOM0_OP;
   3.108      op.cmd = DOM0_SETDOMAINHANDLE;
   3.109      op.u.setdomainhandle.domain = (domid_t)domid;
   3.110      memcpy(op.u.setdomainhandle.handle, handle, sizeof(xen_domain_handle_t));
   3.111 @@ -351,8 +351,7 @@ int xc_domain_get_vcpu_info(int xc_handl
   3.112                              xc_vcpuinfo_t *info)
   3.113  {
   3.114      int rc;
   3.115 -    dom0_op_t op;
   3.116 -
   3.117 +    DECLARE_DOM0_OP;
   3.118      op.cmd = DOM0_GETVCPUINFO;
   3.119      op.u.getvcpuinfo.domain = (domid_t)domid;
   3.120      op.u.getvcpuinfo.vcpu   = (uint16_t)vcpu;
   3.121 @@ -370,7 +369,7 @@ int xc_domain_ioport_permission(int xc_h
   3.122                                  uint16_t nr_ports,
   3.123                                  uint16_t allow_access)
   3.124  {
   3.125 -    dom0_op_t op;
   3.126 +    DECLARE_DOM0_OP;
   3.127  
   3.128      op.cmd = DOM0_IOPORT_PERMISSION;
   3.129      op.u.ioport_permission.domain = (domid_t)domid;
     4.1 --- a/tools/libxc/xc_evtchn.c	Mon Nov 21 19:08:44 2005 +0100
     4.2 +++ b/tools/libxc/xc_evtchn.c	Tue Nov 22 16:31:16 2005 +0100
     4.3 @@ -12,7 +12,7 @@
     4.4  static int do_evtchn_op(int xc_handle, evtchn_op_t *op)
     4.5  {
     4.6      int ret = -1;
     4.7 -    privcmd_hypercall_t hypercall;
     4.8 +    DECLARE_HYPERCALL;
     4.9  
    4.10      hypercall.op     = __HYPERVISOR_event_channel_op;
    4.11      hypercall.arg[0] = (unsigned long)op;
     5.1 --- a/tools/libxc/xc_gnttab.c	Mon Nov 21 19:08:44 2005 +0100
     5.2 +++ b/tools/libxc/xc_gnttab.c	Tue Nov 22 16:31:16 2005 +0100
     5.3 @@ -17,7 +17,7 @@ do_gnttab_op(int xc_handle,
     5.4               unsigned long count)
     5.5  {
     5.6      int ret = -1;
     5.7 -    privcmd_hypercall_t hypercall;
     5.8 +    DECLARE_HYPERCALL;
     5.9  
    5.10      hypercall.op     = __HYPERVISOR_grant_table_op;
    5.11      hypercall.arg[0] = cmd;
     6.1 --- a/tools/libxc/xc_linux_build.c	Mon Nov 21 19:08:44 2005 +0100
     6.2 +++ b/tools/libxc/xc_linux_build.c	Tue Nov 22 16:31:16 2005 +0100
     6.3 @@ -692,7 +692,8 @@ int xc_linux_build(int xc_handle,
     6.4                     unsigned int console_evtchn,
     6.5                     unsigned long *console_mfn)
     6.6  {
     6.7 -    dom0_op_t launch_op, op;
     6.8 +    dom0_op_t launch_op;
     6.9 +    DECLARE_DOM0_OP;
    6.10      int initrd_fd = -1;
    6.11      gzFile initrd_gfd = NULL;
    6.12      int rc, i;
    6.13 @@ -728,6 +729,10 @@ int xc_linux_build(int xc_handle,
    6.14          }
    6.15      }
    6.16  
    6.17 +#ifdef VALGRIND
    6.18 +    memset(&st_ctxt, 0, sizeof(st_ctxt));
    6.19 +#endif
    6.20 +
    6.21      if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
    6.22      {   
    6.23          PERROR("%s: ctxt mlock failed", __func__);
     7.1 --- a/tools/libxc/xc_linux_restore.c	Mon Nov 21 19:08:44 2005 +0100
     7.2 +++ b/tools/libxc/xc_linux_restore.c	Tue Nov 22 16:31:16 2005 +0100
     7.3 @@ -106,7 +106,7 @@ int xc_linux_restore(int xc_handle, int 
     7.4                       unsigned int store_evtchn, unsigned long *store_mfn,
     7.5                       unsigned int console_evtchn, unsigned long *console_mfn)
     7.6  {
     7.7 -    dom0_op_t op;
     7.8 +    DECLARE_DOM0_OP;
     7.9      int rc = 1, i, n;
    7.10      unsigned long mfn, pfn; 
    7.11      unsigned int prev_pc, this_pc;
     8.1 --- a/tools/libxc/xc_misc.c	Mon Nov 21 19:08:44 2005 +0100
     8.2 +++ b/tools/libxc/xc_misc.c	Tue Nov 22 16:31:16 2005 +0100
     8.3 @@ -25,7 +25,7 @@ int xc_readconsolering(int xc_handle,
     8.4                         int clear)
     8.5  {
     8.6      int ret;
     8.7 -    dom0_op_t op;
     8.8 +    DECLARE_DOM0_OP;
     8.9      char *buffer = *pbuffer;
    8.10      unsigned int nr_chars = *pnr_chars;
    8.11  
    8.12 @@ -52,7 +52,7 @@ int xc_physinfo(int xc_handle,
    8.13                  xc_physinfo_t *put_info)
    8.14  {
    8.15      int ret;
    8.16 -    dom0_op_t op;
    8.17 +    DECLARE_DOM0_OP;
    8.18      
    8.19      op.cmd = DOM0_PHYSINFO;
    8.20      op.interface_version = DOM0_INTERFACE_VERSION;
    8.21 @@ -69,7 +69,7 @@ int xc_sched_id(int xc_handle,
    8.22                  int *sched_id)
    8.23  {
    8.24      int ret;
    8.25 -    dom0_op_t op;
    8.26 +    DECLARE_DOM0_OP;
    8.27      
    8.28      op.cmd = DOM0_SCHED_ID;
    8.29      op.interface_version = DOM0_INTERFACE_VERSION;
    8.30 @@ -83,25 +83,25 @@ int xc_sched_id(int xc_handle,
    8.31  }
    8.32  
    8.33  int xc_perfc_control(int xc_handle,
    8.34 -                     uint32_t op,
    8.35 +                     uint32_t opcode,
    8.36                       xc_perfc_desc_t *desc)
    8.37  {
    8.38      int rc;
    8.39 -    dom0_op_t dop;
    8.40 +    DECLARE_DOM0_OP;
    8.41  
    8.42 -    dop.cmd = DOM0_PERFCCONTROL;
    8.43 -    dop.u.perfccontrol.op   = op;
    8.44 -    dop.u.perfccontrol.desc = desc;
    8.45 +    op.cmd = DOM0_PERFCCONTROL;
    8.46 +    op.u.perfccontrol.op   = opcode;
    8.47 +    op.u.perfccontrol.desc = desc;
    8.48  
    8.49 -    rc = do_dom0_op(xc_handle, &dop);
    8.50 +    rc = do_dom0_op(xc_handle, &op);
    8.51  
    8.52 -    return (rc == 0) ? dop.u.perfccontrol.nr_counters : rc;
    8.53 +    return (rc == 0) ? op.u.perfccontrol.nr_counters : rc;
    8.54  }
    8.55  
    8.56  long long xc_msr_read(int xc_handle, int cpu_mask, int msr)
    8.57  {
    8.58      int rc;    
    8.59 -    dom0_op_t op;
    8.60 +    DECLARE_DOM0_OP;
    8.61      
    8.62      op.cmd = DOM0_MSR;
    8.63      op.u.msr.write = 0;
    8.64 @@ -117,7 +117,7 @@ int xc_msr_write(int xc_handle, int cpu_
    8.65                    unsigned int high)
    8.66  {
    8.67      int rc;    
    8.68 -    dom0_op_t op;
    8.69 +    DECLARE_DOM0_OP;
    8.70      
    8.71      op.cmd = DOM0_MSR;
    8.72      op.u.msr.write = 1;
     9.1 --- a/tools/libxc/xc_private.c	Mon Nov 21 19:08:44 2005 +0100
     9.2 +++ b/tools/libxc/xc_private.c	Tue Nov 22 16:31:16 2005 +0100
     9.3 @@ -68,7 +68,7 @@ void *xc_map_foreign_range(int xc_handle
     9.4  int xc_get_pfn_type_batch(int xc_handle, 
     9.5                            uint32_t dom, int num, unsigned long *arr)
     9.6  {
     9.7 -    dom0_op_t op;
     9.8 +    DECLARE_DOM0_OP;
     9.9      op.cmd = DOM0_GETPAGEFRAMEINFO2;
    9.10      op.u.getpageframeinfo2.domain = (domid_t)dom;
    9.11      op.u.getpageframeinfo2.num    = num;
    9.12 @@ -81,7 +81,7 @@ unsigned int get_pfn_type(int xc_handle,
    9.13                            unsigned long mfn, 
    9.14                            uint32_t dom)
    9.15  {
    9.16 -    dom0_op_t op;
    9.17 +    DECLARE_DOM0_OP;
    9.18      op.cmd = DOM0_GETPAGEFRAMEINFO;
    9.19      op.u.getpageframeinfo.pfn    = mfn;
    9.20      op.u.getpageframeinfo.domain = (domid_t)dom;
    9.21 @@ -99,7 +99,7 @@ int xc_mmuext_op(
    9.22      unsigned int nr_ops,
    9.23      domid_t dom)
    9.24  {
    9.25 -    privcmd_hypercall_t hypercall;
    9.26 +    DECLARE_HYPERCALL;
    9.27      long ret = -EINVAL;
    9.28  
    9.29      hypercall.op     = __HYPERVISOR_mmuext_op;
    9.30 @@ -125,7 +125,7 @@ int xc_mmuext_op(
    9.31  static int flush_mmu_updates(int xc_handle, xc_mmu_t *mmu)
    9.32  {
    9.33      int err = 0;
    9.34 -    privcmd_hypercall_t hypercall;
    9.35 +    DECLARE_HYPERCALL;
    9.36  
    9.37      if ( mmu->idx == 0 )
    9.38          return 0;
    9.39 @@ -188,7 +188,7 @@ int xc_memory_op(int xc_handle,
    9.40                   int cmd,
    9.41                   void *arg)
    9.42  {
    9.43 -    privcmd_hypercall_t hypercall;
    9.44 +    DECLARE_HYPERCALL;
    9.45      struct xen_memory_reservation *reservation = arg;
    9.46      long ret = -EINVAL;
    9.47  
    9.48 @@ -236,7 +236,7 @@ int xc_memory_op(int xc_handle,
    9.49  
    9.50  long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid, int vcpu )
    9.51  {
    9.52 -    dom0_op_t op;
    9.53 +    DECLARE_DOM0_OP;
    9.54  
    9.55      op.cmd = DOM0_GETVCPUINFO;
    9.56      op.u.getvcpuinfo.domain = (domid_t)domid;
    9.57 @@ -255,13 +255,16 @@ int xc_get_pfn_list(int xc_handle,
    9.58                      unsigned long *pfn_buf, 
    9.59                      unsigned long max_pfns)
    9.60  {
    9.61 -    dom0_op_t op;
    9.62 +    DECLARE_DOM0_OP;
    9.63      int ret;
    9.64      op.cmd = DOM0_GETMEMLIST;
    9.65      op.u.getmemlist.domain   = (domid_t)domid;
    9.66      op.u.getmemlist.max_pfns = max_pfns;
    9.67      op.u.getmemlist.buffer   = pfn_buf;
    9.68  
    9.69 +#ifdef VALGRIND
    9.70 +    memset(pfn_buf, 0, max_pfns * sizeof(unsigned long));
    9.71 +#endif
    9.72  
    9.73      if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 )
    9.74      {
    9.75 @@ -293,7 +296,7 @@ int xc_get_pfn_list(int xc_handle,
    9.76  
    9.77  long xc_get_tot_pages(int xc_handle, uint32_t domid)
    9.78  {
    9.79 -    dom0_op_t op;
    9.80 +    DECLARE_DOM0_OP;
    9.81      op.cmd = DOM0_GETDOMAININFO;
    9.82      op.u.getdomaininfo.domain = (domid_t)domid;
    9.83      return (do_dom0_op(xc_handle, &op) < 0) ? 
    9.84 @@ -403,6 +406,11 @@ int xc_version(int xc_handle, int cmd, v
    9.85          return -ENOMEM;
    9.86      }
    9.87  
    9.88 +#ifdef VALGRIND
    9.89 +    if (argsize != 0)
    9.90 +        memset(arg, 0, argsize);
    9.91 +#endif
    9.92 +
    9.93      rc = do_xen_version(xc_handle, cmd, arg);
    9.94  
    9.95      if ( argsize != 0 )
    10.1 --- a/tools/libxc/xc_private.h	Mon Nov 21 19:08:44 2005 +0100
    10.2 +++ b/tools/libxc/xc_private.h	Tue Nov 22 16:31:16 2005 +0100
    10.3 @@ -17,6 +17,19 @@
    10.4  
    10.5  #include <xen/linux/privcmd.h>
    10.6  
    10.7 +/* valgrind cannot see when a hypercall has filled in some values.  For this
    10.8 +   reason, we must zero the privcmd_hypercall_t or dom0_op_t instance before a
    10.9 +   call, if using valgrind.  */
   10.10 +#ifdef VALGRIND
   10.11 +#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall; \
   10.12 +  memset(&hypercall, 0, sizeof(hypercall))
   10.13 +#define DECLARE_DOM0_OP dom0_op_t op; memset(&op, 0, sizeof(op))
   10.14 +#else
   10.15 +#define DECLARE_HYPERCALL privcmd_hypercall_t hypercall
   10.16 +#define DECLARE_DOM0_OP dom0_op_t op
   10.17 +#endif
   10.18 +
   10.19 +
   10.20  #define PAGE_SHIFT              XC_PAGE_SHIFT
   10.21  #define PAGE_SIZE               (1UL << PAGE_SHIFT)
   10.22  #define PAGE_MASK               (~(PAGE_SIZE-1))
   10.23 @@ -61,7 +74,7 @@ static inline int do_xen_hypercall(int x
   10.24  
   10.25  static inline int do_xen_version(int xc_handle, int cmd, void *dest)
   10.26  {
   10.27 -    privcmd_hypercall_t hypercall;
   10.28 +    DECLARE_HYPERCALL;
   10.29  
   10.30      hypercall.op     = __HYPERVISOR_xen_version;
   10.31      hypercall.arg[0] = (unsigned long) cmd;
   10.32 @@ -73,7 +86,7 @@ static inline int do_xen_version(int xc_
   10.33  static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
   10.34  {
   10.35      int ret = -1;
   10.36 -    privcmd_hypercall_t hypercall;
   10.37 +    DECLARE_HYPERCALL;
   10.38  
   10.39      op->interface_version = DOM0_INTERFACE_VERSION;
   10.40  
    11.1 --- a/tools/libxc/xc_ptrace.c	Mon Nov 21 19:08:44 2005 +0100
    11.2 +++ b/tools/libxc/xc_ptrace.c	Tue Nov 22 16:31:16 2005 +0100
    11.3 @@ -283,7 +283,7 @@ xc_waitdomain(
    11.4      int *status,
    11.5      int options)
    11.6  {
    11.7 -    dom0_op_t op;
    11.8 +    DECLARE_DOM0_OP;
    11.9      int retval;
   11.10      struct timespec ts;
   11.11      ts.tv_sec = 0;
   11.12 @@ -323,7 +323,7 @@ xc_ptrace(
   11.13      long eaddr,
   11.14      long edata)
   11.15  {
   11.16 -    dom0_op_t       op;
   11.17 +    DECLARE_DOM0_OP;
   11.18      int             status = 0;
   11.19      struct gdb_regs pt;
   11.20      long            retval = 0;
    12.1 --- a/tools/libxc/xc_sedf.c	Mon Nov 21 19:08:44 2005 +0100
    12.2 +++ b/tools/libxc/xc_sedf.c	Tue Nov 22 16:31:16 2005 +0100
    12.3 @@ -13,7 +13,7 @@
    12.4  int xc_sedf_domain_set(int xc_handle,
    12.5                            uint32_t domid, uint64_t period, uint64_t slice,uint64_t latency, uint16_t extratime,uint16_t weight)
    12.6  {
    12.7 -    dom0_op_t op;
    12.8 +    DECLARE_DOM0_OP;
    12.9      struct sedf_adjdom *p = &op.u.adjustdom.u.sedf;
   12.10  
   12.11      op.cmd = DOM0_ADJUSTDOM;
   12.12 @@ -31,7 +31,7 @@ int xc_sedf_domain_set(int xc_handle,
   12.13  
   12.14  int xc_sedf_domain_get(int xc_handle, uint32_t domid, uint64_t *period, uint64_t *slice, uint64_t* latency, uint16_t* extratime, uint16_t* weight)
   12.15  {
   12.16 -    dom0_op_t op;
   12.17 +    DECLARE_DOM0_OP;
   12.18      int ret;
   12.19      struct sedf_adjdom *p = &op.u.adjustdom.u.sedf;
   12.20  
    13.1 --- a/tools/libxc/xc_tbuf.c	Mon Nov 21 19:08:44 2005 +0100
    13.2 +++ b/tools/libxc/xc_tbuf.c	Tue Nov 22 16:31:16 2005 +0100
    13.3 @@ -10,7 +10,7 @@
    13.4  
    13.5  int xc_tbuf_enable(int xc_handle, int enable)
    13.6  {
    13.7 -  dom0_op_t op;
    13.8 +  DECLARE_DOM0_OP;
    13.9  
   13.10    op.cmd = DOM0_TBUFCONTROL;
   13.11    op.interface_version = DOM0_INTERFACE_VERSION;
   13.12 @@ -24,7 +24,7 @@ int xc_tbuf_enable(int xc_handle, int en
   13.13  
   13.14  int xc_tbuf_set_size(int xc_handle, uint32_t size)
   13.15  {
   13.16 -  dom0_op_t op;
   13.17 +  DECLARE_DOM0_OP;
   13.18  
   13.19    op.cmd = DOM0_TBUFCONTROL;
   13.20    op.interface_version = DOM0_INTERFACE_VERSION;
   13.21 @@ -37,7 +37,7 @@ int xc_tbuf_set_size(int xc_handle, uint
   13.22  int xc_tbuf_get_size(int xc_handle, uint32_t *size)
   13.23  {
   13.24    int rc;
   13.25 -  dom0_op_t op;
   13.26 +  DECLARE_DOM0_OP;
   13.27  
   13.28    op.cmd = DOM0_TBUFCONTROL;
   13.29    op.interface_version = DOM0_INTERFACE_VERSION;
    14.1 --- a/tools/libxc/xg_private.h	Mon Nov 21 19:08:44 2005 +0100
    14.2 +++ b/tools/libxc/xg_private.h	Tue Nov 22 16:31:16 2005 +0100
    14.3 @@ -16,6 +16,16 @@
    14.4  #include <xen/linux/privcmd.h>
    14.5  #include <xen/memory.h>
    14.6  
    14.7 +/* valgrind cannot see when a hypercall has filled in some values.  For this
    14.8 +   reason, we must zero the dom0_op_t instance before a call, if using
    14.9 +   valgrind.  */
   14.10 +#ifdef VALGRIND
   14.11 +#define DECLARE_DOM0_OP dom0_op_t op; memset(&op, 0, sizeof(op))
   14.12 +#else
   14.13 +#define DECLARE_DOM0_OP dom0_op_t op
   14.14 +#endif
   14.15 +
   14.16 +
   14.17  char *xc_read_kernel_image(const char *filename, unsigned long *size);
   14.18  unsigned long csum_page (void * page);
   14.19