direct-io.hg

view tools/libxc/xg_private.h @ 12009:4a320d26fc24

[TOOLS] Uncompress and allocate memory for gzipped kernel and initrd images on
the fly. We cannot rely on the length contained in the gzip trailer to determine
the length of the decompressed data because images have been observed which have
trailing junk.

Signed-off-by: Ian Campbell <ian.campbell@xensource.com>
author Ian Campbell <ian.campbell@xensource.com>
date Thu Oct 26 16:56:16 2006 +0100 (2006-10-26)
parents 5d2ce349f9f4
children ac51e8f37108
line source
1 #ifndef XG_PRIVATE_H
2 #define XG_PRIVATE_H
4 #include <unistd.h>
5 #include <errno.h>
6 #include <fcntl.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <sys/mman.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
14 #include "xenctrl.h"
15 #include "xenguest.h"
16 #include "xc_private.h"
18 #include <xen/sys/privcmd.h>
19 #include <xen/memory.h>
20 #include <xen/elfnote.h>
22 #ifndef ELFSIZE
23 #include <limits.h>
24 #if UINT_MAX == ULONG_MAX
25 #define ELFSIZE 32
26 #else
27 #define ELFSIZE 64
28 #endif
29 #endif
31 char *xc_read_image(const char *filename, unsigned long *size);
32 char *xc_inflate_buffer(const char *in_buf,
33 unsigned long in_size,
34 unsigned long *out_size);
36 unsigned long csum_page (void * page);
38 #define _PAGE_PRESENT 0x001
39 #define _PAGE_RW 0x002
40 #define _PAGE_USER 0x004
41 #define _PAGE_PWT 0x008
42 #define _PAGE_PCD 0x010
43 #define _PAGE_ACCESSED 0x020
44 #define _PAGE_DIRTY 0x040
45 #define _PAGE_PAT 0x080
46 #define _PAGE_PSE 0x080
47 #define _PAGE_GLOBAL 0x100
49 #define L1_PAGETABLE_SHIFT_PAE 12
50 #define L2_PAGETABLE_SHIFT_PAE 21
51 #define L3_PAGETABLE_SHIFT_PAE 30
53 #define L2_PAGETABLE_SHIFT_I386 22
55 #if defined(__i386__)
56 #define L1_PAGETABLE_SHIFT 12
57 #define L2_PAGETABLE_SHIFT 22
58 #elif defined(__x86_64__)
59 #define L1_PAGETABLE_SHIFT 12
60 #define L2_PAGETABLE_SHIFT 21
61 #define L3_PAGETABLE_SHIFT 30
62 #define L4_PAGETABLE_SHIFT 39
63 #endif
65 #define L1_PAGETABLE_ENTRIES_PAE 512
66 #define L2_PAGETABLE_ENTRIES_PAE 512
67 #define L3_PAGETABLE_ENTRIES_PAE 4
69 #define L1_PAGETABLE_ENTRIES_I386 1024
70 #define L2_PAGETABLE_ENTRIES_I386 1024
72 #if defined(__i386__)
73 #define L1_PAGETABLE_ENTRIES 1024
74 #define L2_PAGETABLE_ENTRIES 1024
75 #elif defined(__x86_64__)
76 #define L1_PAGETABLE_ENTRIES 512
77 #define L2_PAGETABLE_ENTRIES 512
78 #define L3_PAGETABLE_ENTRIES 512
79 #define L4_PAGETABLE_ENTRIES 512
80 #endif
82 typedef uint32_t l1_pgentry_32_t;
83 typedef uint32_t l2_pgentry_32_t;
84 typedef uint64_t l1_pgentry_64_t;
85 typedef uint64_t l2_pgentry_64_t;
86 typedef uint64_t l3_pgentry_64_t;
87 typedef unsigned long l1_pgentry_t;
88 typedef unsigned long l2_pgentry_t;
89 #if defined(__x86_64__)
90 typedef unsigned long l3_pgentry_t;
91 typedef unsigned long l4_pgentry_t;
92 #endif
94 #define l1_table_offset_pae(_a) \
95 (((_a) >> L1_PAGETABLE_SHIFT_PAE) & (L1_PAGETABLE_ENTRIES_PAE - 1))
96 #define l2_table_offset_pae(_a) \
97 (((_a) >> L2_PAGETABLE_SHIFT_PAE) & (L2_PAGETABLE_ENTRIES_PAE - 1))
98 #define l3_table_offset_pae(_a) \
99 (((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1))
101 #define l1_table_offset_i386(_a) \
102 (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES_I386 - 1))
103 #define l2_table_offset_i386(_a) \
104 (((_a) >> L2_PAGETABLE_SHIFT_I386) & (L2_PAGETABLE_ENTRIES_I386 - 1))
106 #if defined(__i386__)
107 #define l1_table_offset(_a) \
108 (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
109 #define l2_table_offset(_a) \
110 ((_a) >> L2_PAGETABLE_SHIFT)
111 #elif defined(__x86_64__)
112 #define l1_table_offset(_a) \
113 (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
114 #define l2_table_offset(_a) \
115 (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
116 #define l3_table_offset(_a) \
117 (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
118 #define l4_table_offset(_a) \
119 (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
120 #endif
122 struct domain_setup_info
123 {
124 uint64_t v_start;
125 uint64_t v_end;
126 uint64_t v_kernstart;
127 uint64_t v_kernend;
128 uint64_t v_kernentry;
130 uint64_t elf_paddr_offset;
132 #define PAEKERN_no 0
133 #define PAEKERN_yes 1
134 #define PAEKERN_extended_cr3 2
135 unsigned int pae_kernel;
137 unsigned int load_symtab;
138 unsigned long symtab_addr;
139 unsigned long symtab_len;
141 /*
142 * Only one of __elfnote_* or __xen_guest_string will be
143 * non-NULL.
144 *
145 * You should use the xen_elfnote_* accessors below in order to
146 * pickup the correct one and retain backwards compatibility.
147 */
148 void *__elfnote_section, *__elfnote_section_end;
149 const char *__xen_guest_string;
150 };
152 typedef int (*parseimagefunc)(const char *image, unsigned long image_size,
153 struct domain_setup_info *dsi);
154 typedef int (*loadimagefunc)(const char *image, unsigned long image_size,
155 int xch,
156 uint32_t dom, xen_pfn_t *parray,
157 struct domain_setup_info *dsi);
159 /*
160 * If an ELF note of the given type is found then the value contained
161 * in the note is returned and *defined is set to non-zero. If no such
162 * note is found then *defined is set to 0 and 0 is returned.
163 */
164 extern unsigned long long xen_elfnote_numeric(struct domain_setup_info *dsi,
165 int type, int *defined);
167 /*
168 * If an ELF note of the given type is found then the string contained
169 * in the value is returned, otherwise NULL is returned.
170 */
171 extern const char * xen_elfnote_string(struct domain_setup_info *dsi,
172 int type);
174 struct load_funcs
175 {
176 parseimagefunc parseimage;
177 loadimagefunc loadimage;
178 };
180 #define mfn_mapper_queue_size 128
182 typedef struct mfn_mapper {
183 int xc_handle;
184 int size;
185 int prot;
186 int error;
187 int max_queue_size;
188 void * addr;
189 privcmd_mmap_t ioctl;
191 } mfn_mapper_t;
193 int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
194 unsigned long dst_pfn, const char *src_page);
196 void xc_map_memcpy(unsigned long dst, const char *src, unsigned long size,
197 int xch, uint32_t dom, xen_pfn_t *parray,
198 unsigned long vstart);
200 int pin_table(int xc_handle, unsigned int type, unsigned long mfn,
201 domid_t dom);
203 /* image loading */
204 int probe_elf(const char *image, unsigned long image_size,
205 struct load_funcs *funcs);
206 int probe_bin(const char *image, unsigned long image_size,
207 struct load_funcs *funcs);
209 #endif /* XG_PRIVATE_H */