mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 10:40:03 +01:00
Also update the tools accordingly. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
87 lines
1.9 KiB
C
87 lines
1.9 KiB
C
/******************************************************************************
|
|
* xg_private.c
|
|
*
|
|
* Helper functions for the rest of the library.
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <zlib.h>
|
|
|
|
#include "xg_private.h"
|
|
|
|
char *xc_read_kernel_image(const char *filename, unsigned long *size)
|
|
{
|
|
int kernel_fd = -1;
|
|
gzFile kernel_gfd = NULL;
|
|
char *image = NULL;
|
|
unsigned int bytes;
|
|
|
|
if ( (kernel_fd = open(filename, O_RDONLY)) < 0 )
|
|
{
|
|
PERROR("Could not open kernel image");
|
|
goto out;
|
|
}
|
|
|
|
if ( (*size = xc_get_filesz(kernel_fd)) == 0 )
|
|
{
|
|
PERROR("Could not read kernel image");
|
|
goto out;
|
|
}
|
|
|
|
if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
|
|
{
|
|
PERROR("Could not allocate decompression state for state file");
|
|
goto out;
|
|
}
|
|
|
|
if ( (image = malloc(*size)) == NULL )
|
|
{
|
|
PERROR("Could not allocate memory for kernel image");
|
|
goto out;
|
|
}
|
|
|
|
if ( (bytes = gzread(kernel_gfd, image, *size)) != *size )
|
|
{
|
|
PERROR("Error reading kernel image, could not"
|
|
" read the whole image (%d != %ld).", bytes, *size);
|
|
free(image);
|
|
image = NULL;
|
|
}
|
|
|
|
out:
|
|
if ( kernel_gfd != NULL )
|
|
gzclose(kernel_gfd);
|
|
else if ( kernel_fd >= 0 )
|
|
close(kernel_fd);
|
|
return image;
|
|
}
|
|
|
|
/*******************/
|
|
|
|
int pin_table(
|
|
int xc_handle, unsigned int type, unsigned long mfn, domid_t dom)
|
|
{
|
|
struct mmuext_op op;
|
|
|
|
op.cmd = type;
|
|
op.mfn = mfn;
|
|
|
|
if ( xc_mmuext_op(xc_handle, &op, 1, dom) < 0 )
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* This is shared between save and restore, and may generally be useful. */
|
|
unsigned long csum_page (void * page)
|
|
{
|
|
int i;
|
|
unsigned long *p = page;
|
|
unsigned long long sum=0;
|
|
|
|
for ( i = 0; i < (PAGE_SIZE/sizeof(unsigned long)); i++ )
|
|
sum += p[i];
|
|
|
|
return sum ^ (sum>>32);
|
|
}
|