aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc/xg_private.c
diff options
context:
space:
mode:
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>2005-08-25 00:51:20 +0000
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>2005-08-25 00:51:20 +0000
commitacc63faffa3cdefd9bd5f6e099971b4fcdae436b (patch)
tree826e7457f143456e94b597a2cdd175d1df4d726c /tools/libxc/xg_private.c
parent60eb66351321ad80bf3356e2e35aeced44522a7a (diff)
downloadxen-acc63faffa3cdefd9bd5f6e099971b4fcdae436b.tar.gz
xen-acc63faffa3cdefd9bd5f6e099971b4fcdae436b.tar.bz2
xen-acc63faffa3cdefd9bd5f6e099971b4fcdae436b.zip
Break the building/save/restore code out into a separate library libxenguest.
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>
Diffstat (limited to 'tools/libxc/xg_private.c')
-rw-r--r--tools/libxc/xg_private.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/tools/libxc/xg_private.c b/tools/libxc/xg_private.c
new file mode 100644
index 0000000000..a5b81fdd35
--- /dev/null
+++ b/tools/libxc/xg_private.c
@@ -0,0 +1,86 @@
+/******************************************************************************
+ * 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);
+}