ia64/xen-unstable

view tools/libxc/xg_private.c @ 8964:8946b6dcd49e

Fix x86_64 Xen build.

event_callback_cs and failsafe_callback_cs are x86_32 only.

Signed-off-by: Ian Campbell <Ian.Campbell@XenSource.com>
author Ian.Campbell@xensource.com
date Wed Feb 22 17:26:39 2006 +0000 (2006-02-22)
parents c503c3887971
children 899532500ada
line source
1 /******************************************************************************
2 * xg_private.c
3 *
4 * Helper functions for the rest of the library.
5 */
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <zlib.h>
11 #include "xg_private.h"
13 char *xc_read_kernel_image(const char *filename, unsigned long *size)
14 {
15 int kernel_fd = -1;
16 gzFile kernel_gfd = NULL;
17 char *image = NULL;
18 unsigned int bytes;
20 if ( filename == NULL )
21 goto out;
23 if ( (kernel_fd = open(filename, O_RDONLY)) < 0 )
24 {
25 PERROR("Could not open kernel image");
26 goto out;
27 }
29 if ( (*size = xc_get_filesz(kernel_fd)) == 0 )
30 {
31 PERROR("Could not read kernel image");
32 goto out;
33 }
35 if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
36 {
37 PERROR("Could not allocate decompression state for state file");
38 goto out;
39 }
41 if ( (image = malloc(*size)) == NULL )
42 {
43 PERROR("Could not allocate memory for kernel image");
44 goto out;
45 }
47 if ( (bytes = gzread(kernel_gfd, image, *size)) != *size )
48 {
49 PERROR("Error reading kernel image, could not"
50 " read the whole image (%d != %ld).", bytes, *size);
51 free(image);
52 image = NULL;
53 }
55 out:
56 if ( kernel_gfd != NULL )
57 gzclose(kernel_gfd);
58 else if ( kernel_fd >= 0 )
59 close(kernel_fd);
60 return image;
61 }
63 /*******************/
65 int pin_table(
66 int xc_handle, unsigned int type, unsigned long mfn, domid_t dom)
67 {
68 struct mmuext_op op;
70 op.cmd = type;
71 op.arg1.mfn = mfn;
73 if ( xc_mmuext_op(xc_handle, &op, 1, dom) < 0 )
74 return 1;
76 return 0;
77 }
79 /* This is shared between save and restore, and may generally be useful. */
80 unsigned long csum_page (void * page)
81 {
82 int i;
83 unsigned long *p = page;
84 unsigned long long sum=0;
86 for ( i = 0; i < (PAGE_SIZE/sizeof(unsigned long)); i++ )
87 sum += p[i];
89 return sum ^ (sum>>32);
90 }