WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Make sure we save errno across error-path printfs and mu

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Make sure we save errno across error-path printfs and munlocks. Based
From: BitKeeper Bot <riel@xxxxxxxxxxx>
Date: Thu, 23 Jun 2005 08:40:39 +0000
Cc: james@xxxxxxxxxxxxx
Delivery-date: Thu, 23 Jun 2005 09:02:26 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: Xen Development List <xen-devel@xxxxxxxxxxxxxxxxxxx>
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
ChangeSet 1.1733, 2005/06/23 09:40:39+01:00, kaf24@xxxxxxxxxxxxxxxxxxxx

        Make sure we save errno across error-path printfs and munlocks. Based
        on a patch from Anthony Liguori.
        Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>



 xc_domain.c  |    8 ++------
 xc_evtchn.c  |    2 +-
 xc_gnttab.c  |    2 +-
 xc_misc.c    |    2 +-
 xc_private.c |   14 +++++++++-----
 xc_private.h |   44 +++++++++++++++++++++++++-------------------
 6 files changed, 39 insertions(+), 33 deletions(-)


diff -Nru a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c
--- a/tools/libxc/xc_domain.c   2005-06-23 05:03:36 -04:00
+++ b/tools/libxc/xc_domain.c   2005-06-23 05:03:36 -04:00
@@ -128,7 +128,7 @@
                                u32 vcpu,
                                vcpu_guest_context_t *ctxt)
 {
-    int rc, errno_saved;
+    int rc;
     dom0_op_t op;
 
     op.cmd = DOM0_GETVCPUCONTEXT;
@@ -143,11 +143,7 @@
     rc = do_dom0_op(xc_handle, &op);
 
     if ( ctxt != NULL )
-    {
-        errno_saved = errno;
-        (void)munlock(ctxt, sizeof(*ctxt));
-        errno = errno_saved;
-    }
+        safe_munlock(ctxt, sizeof(*ctxt));
 
     if ( rc > 0 )
         return -ESRCH;
diff -Nru a/tools/libxc/xc_evtchn.c b/tools/libxc/xc_evtchn.c
--- a/tools/libxc/xc_evtchn.c   2005-06-23 05:03:36 -04:00
+++ b/tools/libxc/xc_evtchn.c   2005-06-23 05:03:36 -04:00
@@ -26,7 +26,7 @@
     if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0)
         ERROR("do_evtchn_op: HYPERVISOR_event_channel_op failed: %d", ret);
 
-    (void)munlock(op, sizeof(*op));
+    safe_munlock(op, sizeof(*op));
  out:
     return ret;
 }
diff -Nru a/tools/libxc/xc_gnttab.c b/tools/libxc/xc_gnttab.c
--- a/tools/libxc/xc_gnttab.c   2005-06-23 05:03:36 -04:00
+++ b/tools/libxc/xc_gnttab.c   2005-06-23 05:03:36 -04:00
@@ -33,7 +33,7 @@
     if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
         ERROR("do_gnttab_op: HYPERVISOR_grant_table_op failed: %d", ret);
 
-    (void)munlock(op, sizeof(*op));
+    safe_munlock(op, sizeof(*op));
  out:
     return ret;
 }
diff -Nru a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
--- a/tools/libxc/xc_misc.c     2005-06-23 05:03:36 -04:00
+++ b/tools/libxc/xc_misc.c     2005-06-23 05:03:36 -04:00
@@ -43,7 +43,7 @@
         *pnr_chars = op.u.readconsole.count;
     }
 
-    (void)munlock(buffer, nr_chars);
+    safe_munlock(buffer, nr_chars);
 
     return ret;
 }    
diff -Nru a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c
--- a/tools/libxc/xc_private.c  2005-06-23 05:03:36 -04:00
+++ b/tools/libxc/xc_private.c  2005-06-23 05:03:36 -04:00
@@ -22,8 +22,10 @@
     ioctlx.arr=arr;
     if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAPBATCH, &ioctlx ) < 0 )
     {
+        int saved_errno = errno;
        perror("XXXXXXXX");
-       munmap(addr, num*PAGE_SIZE);
+       (void)munmap(addr, num*PAGE_SIZE);
+        errno = saved_errno;
        return NULL;
     }
     return addr;
@@ -51,7 +53,9 @@
     entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
     if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx ) < 0 )
     {
-       munmap(addr, size);
+        int saved_errno = errno;
+       (void)munmap(addr, size);
+        errno = saved_errno;
        return NULL;
     }
     return addr;
@@ -134,8 +138,8 @@
     }
 
     mmu->idx = 0;
-    
-    (void)munlock(mmu->updates, sizeof(mmu->updates));
+
+    safe_munlock(mmu->updates, sizeof(mmu->updates));
 
  out:
     return err;
@@ -232,7 +236,7 @@
 
     ret = do_dom0_op(xc_handle, &op);
 
-    (void)munlock(pfn_buf, max_pfns * sizeof(unsigned long));
+    safe_munlock(pfn_buf, max_pfns * sizeof(unsigned long));
 
 #if 0
 #ifdef DEBUG
diff -Nru a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h
--- a/tools/libxc/xc_private.h  2005-06-23 05:03:36 -04:00
+++ b/tools/libxc/xc_private.h  2005-06-23 05:03:36 -04:00
@@ -101,12 +101,28 @@
     loadimagefunc loadimage;
 };
 
-#define ERROR(_m, _a...)  \
-    fprintf(stderr, "ERROR: " _m "\n" , ## _a )
+#define ERROR(_m, _a...)                                \
+do {                                                    \
+    int __saved_errno = errno;                          \
+    fprintf(stderr, "ERROR: " _m "\n" , ## _a );        \
+    errno = __saved_errno;                              \
+} while (0)
+
+
+#define PERROR(_m, _a...)                                       \
+do {                                                            \
+    int __saved_errno = errno;                                  \
+    fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a ,       \
+            __saved_errno, strerror(__saved_errno));            \
+    errno = __saved_errno;                                      \
+} while (0)
 
-#define PERROR(_m, _a...) \
-    fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
-            errno, strerror(errno))
+static inline void safe_munlock(const void *addr, size_t len)
+{
+    int saved_errno = errno;
+    (void)munlock(addr, len);
+    errno = saved_errno;
+}
 
 static inline int do_privcmd(int xc_handle,
                              unsigned int cmd, 
@@ -125,7 +141,7 @@
 
 static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
 {
-    int ret = -1, errno_saved;
+    int ret = -1;
     privcmd_hypercall_t hypercall;
 
     op->interface_version = DOM0_INTERFACE_VERSION;
@@ -146,9 +162,7 @@
                     " rebuild the user-space tool set?\n");
     }
 
-    errno_saved = errno;
-    (void)munlock(op, sizeof(*op));
-    errno = errno_saved;
+    safe_munlock(op, sizeof(*op));
 
  out1:
     return ret;
@@ -163,7 +177,6 @@
 {
     privcmd_hypercall_t hypercall;
     long ret = -EINVAL;
-    int errno_saved;
 
     hypercall.op     = __HYPERVISOR_dom_mem_op;
     hypercall.arg[0] = (unsigned long)memop;
@@ -186,11 +199,7 @@
     }
 
     if ( extent_list != NULL )
-    {
-        errno_saved = errno;
-        (void)munlock(extent_list, nr_extents*sizeof(unsigned long));
-        errno = errno_saved;
-    }
+        safe_munlock(extent_list, nr_extents*sizeof(unsigned long));
 
  out1:
     return ret;
@@ -204,7 +213,6 @@
 {
     privcmd_hypercall_t hypercall;
     long ret = -EINVAL;
-    int errno_saved;
 
     hypercall.op     = __HYPERVISOR_mmuext_op;
     hypercall.arg[0] = (unsigned long)op;
@@ -224,9 +232,7 @@
                     " rebuild the user-space tool set?\n",ret,errno);
     }
 
-    errno_saved = errno;
-    (void)munlock(op, nr_ops*sizeof(*op));
-    errno = errno_saved;
+    safe_munlock(op, nr_ops*sizeof(*op));
 
  out1:
     return ret;

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Make sure we save errno across error-path printfs and munlocks. Based, BitKeeper Bot <=