#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
+#include <assert.h>
#include "xc_private.h"
#include "xc_bitops.h"
struct outbuf* ob, void* buf, size_t len)
{
if ( len > ob->size - ob->pos ) {
+ errno = ERANGE;
DBGPRINTF("outbuf_write: %zu > %zu@%zu\n", len, ob->size - ob->pos, ob->pos);
return -1;
}
xc_dominfo_t info;
DECLARE_DOMCTL;
- int rc = 1, frc, i, j, last_iter = 0, iter = 0;
+ int rc, frc, i, j, last_iter = 0, iter = 0;
int live = (flags & XCFLAGS_LIVE);
int debug = (flags & XCFLAGS_DEBUG);
int superpages = !!hvm;
{
ERROR("No switch_qemu_logdirty callback provided.");
errno = EINVAL;
- return 1;
+ goto exit;
}
outbuf_init(xch, &ob_pagebuf, OUTBUF_SIZE);
&ctx->max_mfn, &ctx->hvirt_start, &ctx->pt_levels, &dinfo->guest_width) )
{
ERROR("Unable to get platform info.");
- return 1;
+ goto exit;
}
if ( xc_domain_getinfo(xch, dom, 1, &info) != 1 )
{
PERROR("Could not get domain info");
- return 1;
+ goto exit;
}
shared_info_frame = info.shared_info_frame;
if ( dinfo->p2m_size > ~XEN_DOMCTL_PFINFO_LTAB_MASK )
{
+ errno = E2BIG;
ERROR("Cannot save this big a guest");
goto out;
}
if ( !to_send || !to_fix || !to_skip )
{
+ errno = ENOMEM;
ERROR("Couldn't allocate to_send array");
goto out;
}
hvm_buf = malloc(hvm_buf_size);
if ( !hvm_buf )
{
+ errno = ENOMEM;
ERROR("Couldn't allocate memory");
goto out;
}
if ( info.max_vcpu_id >= XC_SR_MAX_VCPUS )
{
+ errno = E2BIG;
ERROR("Too many VCPUS in guest!");
goto out;
}
}
/* HVM guests are done now */
- rc = 0;
+ errno = 0;
goto out;
}
mfn = GET_FIELD(&ctxt, user_regs.edx);
if ( !MFN_IS_IN_PSEUDOPHYS_MAP(mfn) )
{
+ errno = ERANGE;
ERROR("Suspend record is not in range of pseudophys map");
goto out;
}
mfn = GET_FIELD(&ctxt, gdt_frames[j]);
if ( !MFN_IS_IN_PSEUDOPHYS_MAP(mfn) )
{
+ errno = ERANGE;
ERROR("GDT frame is not in range of pseudophys map");
goto out;
}
if ( !MFN_IS_IN_PSEUDOPHYS_MAP(UNFOLD_CR3(
GET_FIELD(&ctxt, ctrlreg[3]))) )
{
+ errno = ERANGE;
ERROR("PT base is not in range of pseudophys map");
goto out;
}
{
if ( !MFN_IS_IN_PSEUDOPHYS_MAP(UNFOLD_CR3(ctxt.x64.ctrlreg[1])) )
{
+ errno = ERANGE;
ERROR("PT base is not in range of pseudophys map");
goto out;
}
}
/* Success! */
- rc = 0;
+ rc = errno = 0;
+ goto out_rc;
out:
+ rc = errno;
+ assert(rc);
+ out_rc:
completed = 1;
if ( !rc && callbacks->postcopy )
if (wrcompressed(io_fd) < 0)
{
ERROR("Error when writing compressed data, after postcopy\n");
- rc = 1;
goto out;
}
/* Append the tailbuf data to the main outbuf */
if ( wrexact(io_fd, ob_tailbuf.buf, ob_tailbuf.pos) )
{
- rc = 1;
PERROR("Error when copying tailbuf into outbuf");
goto out;
}
/* Flush last write and discard cache for file. */
if ( ob && outbuf_flush(xch, ob, io_fd) < 0 ) {
PERROR("Error when flushing output buffer");
- rc = 1;
+ if (!rc)
+ rc = errno;
}
discard_file_cache(xch, io_fd, 1 /* flush */);
/* reset stats timer */
print_stats(xch, dom, 0, &time_stats, &shadow_stats, 0);
- rc = 1;
/* last_iter = 1; */
if ( suspend_and_state(callbacks->suspend, callbacks->data, xch,
io_fd, dom, &info) )
free(hvm_buf);
outbuf_free(&ob_pagebuf);
- DPRINTF("Save exit of domid %u with rc=%d\n", dom, rc);
+ errno = rc;
+exit:
+ DPRINTF("Save exit of domid %u with errno=%d\n", dom, errno);
- return !!rc;
+ return !!errno;
}
/*