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>
This commit is contained in:
kaf24@firebug.cl.cam.ac.uk committed 2005-06-23 08:40:39 +00:00
1 parent 40c6180f82
commit 8a6c33ded1
6 files changed
+39 -33

No files matched your search

+2 -6
View File
@@ -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;
+1 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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;
}
+9 -5
View File
@@ -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
+25 -19
View File
@@ -101,12 +101,28 @@ struct load_funcs
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...) \
fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
errno, strerror(errno))
#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;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.