diff --git a/tools/libxc/xc_freebsd_osdep.c b/tools/libxc/xc_freebsd_osdep.c index 151d3bfc57..e6613ef00a 100644 --- a/tools/libxc/xc_freebsd_osdep.c +++ b/tools/libxc/xc_freebsd_osdep.c @@ -125,10 +125,13 @@ static void freebsd_privcmd_free_hypercall_buffer(xc_interface *xch, int npages) { + int saved_errno = errno; /* Unlock pages */ munlock(ptr, npages * XC_PAGE_SIZE); munmap(ptr, npages * XC_PAGE_SIZE); + /* We MUST propagate the hypercall errno, not unmap call's. */ + errno = saved_errno; } static int freebsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, diff --git a/tools/libxc/xc_hcall_buf.c b/tools/libxc/xc_hcall_buf.c index e762a93a67..932b47c2ef 100644 --- a/tools/libxc/xc_hcall_buf.c +++ b/tools/libxc/xc_hcall_buf.c @@ -33,16 +33,22 @@ pthread_mutex_t hypercall_buffer_cache_mutex = PTHREAD_MUTEX_INITIALIZER; static void hypercall_buffer_cache_lock(xc_interface *xch) { + int saved_errno = errno; if ( xch->flags & XC_OPENFLAG_NON_REENTRANT ) return; pthread_mutex_lock(&hypercall_buffer_cache_mutex); + /* Ignore pthread errors. */ + errno = saved_errno; } static void hypercall_buffer_cache_unlock(xc_interface *xch) { + int saved_errno = errno; if ( xch->flags & XC_OPENFLAG_NON_REENTRANT ) return; pthread_mutex_unlock(&hypercall_buffer_cache_mutex); + /* Ignore pthread errors. */ + errno = saved_errno; } static void *hypercall_buffer_cache_alloc(xc_interface *xch, int nr_pages) diff --git a/tools/libxc/xc_linux_osdep.c b/tools/libxc/xc_linux_osdep.c index 92f7cace97..2687424305 100644 --- a/tools/libxc/xc_linux_osdep.c +++ b/tools/libxc/xc_linux_osdep.c @@ -122,10 +122,13 @@ out: static void linux_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages) { + int saved_errno = errno; /* Recover the VMA flags. Maybe it's not necessary */ madvise(ptr, npages * XC_PAGE_SIZE, MADV_DOFORK); munmap(ptr, npages * XC_PAGE_SIZE); + /* We MUST propagate the hypercall errno, not unmap call's. */ + errno = saved_errno; } static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)