diff options
author | kaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk> | 2005-06-23 08:40:39 +0000 |
---|---|---|
committer | kaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk> | 2005-06-23 08:40:39 +0000 |
commit | 8a6c33ded164e72467aed3d2c4d4f41cc4665f33 (patch) | |
tree | 9cdae7c10f90bf0b753cc55578fb35d7c53ed67b /tools/libxc | |
parent | 40c6180f8265775557dff71a39f272898907f849 (diff) | |
download | xen-8a6c33ded164e72467aed3d2c4d4f41cc4665f33.tar.gz xen-8a6c33ded164e72467aed3d2c4d4f41cc4665f33.tar.bz2 xen-8a6c33ded164e72467aed3d2c4d4f41cc4665f33.zip |
bitkeeper revision 1.1726.2.3 (42ba7587nwhnhQJ_hDkHTk8kTKtAFw)
Make sure we save errno across error-path printfs and munlocks. Based
on a patch from Anthony Liguori.
Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'tools/libxc')
-rw-r--r-- | tools/libxc/xc_domain.c | 8 | ||||
-rw-r--r-- | tools/libxc/xc_evtchn.c | 2 | ||||
-rw-r--r-- | tools/libxc/xc_gnttab.c | 2 | ||||
-rw-r--r-- | tools/libxc/xc_misc.c | 2 | ||||
-rw-r--r-- | tools/libxc/xc_private.c | 14 | ||||
-rw-r--r-- | tools/libxc/xc_private.h | 46 |
6 files changed, 40 insertions, 34 deletions
diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 2edf11c39d..5ea0a33903 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -128,7 +128,7 @@ int xc_domain_get_vcpu_context(int xc_handle, 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 @@ int xc_domain_get_vcpu_context(int xc_handle, 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 --git a/tools/libxc/xc_evtchn.c b/tools/libxc/xc_evtchn.c index 1c0294d83b..74e8468dd5 100644 --- a/tools/libxc/xc_evtchn.c +++ b/tools/libxc/xc_evtchn.c @@ -26,7 +26,7 @@ static int do_evtchn_op(int xc_handle, evtchn_op_t *op) 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 --git a/tools/libxc/xc_gnttab.c b/tools/libxc/xc_gnttab.c index ad23e68013..409539cb14 100644 --- a/tools/libxc/xc_gnttab.c +++ b/tools/libxc/xc_gnttab.c @@ -33,7 +33,7 @@ do_gnttab_op( int xc_handle, 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 --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c index 40291bc3ef..ac306b1585 100644 --- a/tools/libxc/xc_misc.c +++ b/tools/libxc/xc_misc.c @@ -43,7 +43,7 @@ int xc_readconsolering(int xc_handle, *pnr_chars = op.u.readconsole.count; } - (void)munlock(buffer, nr_chars); + safe_munlock(buffer, nr_chars); return ret; } diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c index 87e5ecd1f3..fe8f42c1c8 100644 --- a/tools/libxc/xc_private.c +++ b/tools/libxc/xc_private.c @@ -22,8 +22,10 @@ void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot, 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 @@ void *xc_map_foreign_range(int xc_handle, u32 dom, 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 @@ static int flush_mmu_updates(int xc_handle, mmu_t *mmu) } mmu->idx = 0; - - (void)munlock(mmu->updates, sizeof(mmu->updates)); + + safe_munlock(mmu->updates, sizeof(mmu->updates)); out: return err; @@ -232,7 +236,7 @@ int xc_get_pfn_list(int xc_handle, 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 --git a/tools/libxc/xc_private.h b/tools/libxc/xc_private.h index baf1e5f26d..c50813ee3c 100644 --- a/tools/libxc/xc_private.h +++ b/tools/libxc/xc_private.h @@ -101,12 +101,28 @@ struct load_funcs loadimagefunc loadimage; }; -#define ERROR(_m, _a...) \ - fprintf(stderr, "ERROR: " _m "\n" , ## _a ) - -#define PERROR(_m, _a...) \ - fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ - errno, strerror(errno)) +#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) + +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_xen_hypercall(int xc_handle, 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 @@ static inline int do_dom0_op(int xc_handle, dom0_op_t *op) " 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 @@ static inline int do_dom_mem_op(int xc_handle, { 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 @@ static inline int do_dom_mem_op(int xc_handle, } 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 @@ static inline int do_mmuext_op( { 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 @@ static inline int do_mmuext_op( " 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; |