ia64/xen-unstable

view tools/libxc/xenctrl.h @ 9150:9de50910defd

libxc: Verify Magic number when reading dump

The xen core files record a magic number,
but when they are loaded it isn't checked.
This patch resolves this.

Signed-Off-By: Horms <horms@verge.net.au>
author kaf24@firebug.cl.cam.ac.uk
date Mon Mar 06 15:04:18 2006 +0100 (2006-03-06)
parents 8ed131452f27
children a1fcee3b2abe
line source
1 /******************************************************************************
2 * xenctrl.h
3 *
4 * A library for low-level access to the Xen control interfaces.
5 *
6 * Copyright (c) 2003-2004, K A Fraser.
7 */
9 #ifndef XENCTRL_H
10 #define XENCTRL_H
12 #include <stdint.h>
13 #include <sys/ptrace.h>
14 #include <xen/xen.h>
15 #include <xen/dom0_ops.h>
16 #include <xen/version.h>
17 #include <xen/event_channel.h>
18 #include <xen/sched.h>
19 #include <xen/sched_ctl.h>
20 #include <xen/memory.h>
21 #include <xen/acm.h>
23 #ifdef __ia64__
24 #define XC_PAGE_SHIFT 14
25 #else
26 #define XC_PAGE_SHIFT 12
27 #endif
28 #define XC_PAGE_SIZE (1UL << XC_PAGE_SHIFT)
29 #define XC_PAGE_MASK (~(XC_PAGE_SIZE-1))
31 /*
32 * DEFINITIONS FOR CPU BARRIERS
33 */
35 #if defined(__i386__)
36 #define mb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
37 #define rmb() __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
38 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
39 #elif defined(__x86_64__)
40 #define mb() __asm__ __volatile__ ( "mfence" : : : "memory")
41 #define rmb() __asm__ __volatile__ ( "lfence" : : : "memory")
42 #define wmb() __asm__ __volatile__ ( "" : : : "memory")
43 #elif defined(__ia64__)
44 /* FIXME */
45 #define mb()
46 #define rmb()
47 #define wmb()
48 #else
49 #error "Define barriers"
50 #endif
52 /*
53 * INITIALIZATION FUNCTIONS
54 */
56 /**
57 * This function opens a handle to the hypervisor interface. This function can
58 * be called multiple times within a single process. Multiple processes can
59 * have an open hypervisor interface at the same time.
60 *
61 * Each call to this function should have a corresponding call to
62 * xc_interface_close().
63 *
64 * This function can fail if the caller does not have superuser permission or
65 * if a Xen-enabled kernel is not currently running.
66 *
67 * @return a handle to the hypervisor interface or -1 on failure
68 */
69 int xc_interface_open(void);
71 /**
72 * This function closes an open hypervisor interface.
73 *
74 * This function can fail if the handle does not represent an open interface or
75 * if there were problems closing the interface.
76 *
77 * @parm xc_handle a handle to an open hypervisor interface
78 * @return 0 on success, -1 otherwise.
79 */
80 int xc_interface_close(int xc_handle);
82 /*
83 * DOMAIN DEBUGGING FUNCTIONS
84 */
86 typedef struct xc_core_header {
87 unsigned int xch_magic;
88 unsigned int xch_nr_vcpus;
89 unsigned int xch_nr_pages;
90 unsigned int xch_ctxt_offset;
91 unsigned int xch_index_offset;
92 unsigned int xch_pages_offset;
93 } xc_core_header_t;
95 #define XC_CORE_MAGIC 0xF00FEBED
97 long xc_ptrace_core(
98 int xc_handle,
99 enum __ptrace_request request,
100 uint32_t domid,
101 long addr,
102 long data,
103 vcpu_guest_context_t *ctxt);
104 void * map_domain_va_core(
105 unsigned long domfd,
106 int cpu,
107 void *guest_va,
108 vcpu_guest_context_t *ctxt);
109 int xc_waitdomain_core(
110 int xc_handle,
111 int domain,
112 int *status,
113 int options,
114 vcpu_guest_context_t *ctxt);
116 /*
117 * DOMAIN MANAGEMENT FUNCTIONS
118 */
120 typedef struct {
121 uint32_t domid;
122 uint32_t ssidref;
123 unsigned int dying:1, crashed:1, shutdown:1,
124 paused:1, blocked:1, running:1;
125 unsigned int shutdown_reason; /* only meaningful if shutdown==1 */
126 unsigned long nr_pages;
127 unsigned long shared_info_frame;
128 uint64_t cpu_time;
129 unsigned long max_memkb;
130 unsigned int nr_online_vcpus;
131 unsigned int max_vcpu_id;
132 xen_domain_handle_t handle;
133 } xc_dominfo_t;
135 typedef dom0_getdomaininfo_t xc_domaininfo_t;
136 int xc_domain_create(int xc_handle,
137 uint32_t ssidref,
138 xen_domain_handle_t handle,
139 uint32_t *pdomid);
142 int xc_domain_dumpcore(int xc_handle,
143 uint32_t domid,
144 const char *corename);
146 /*
147 * This function sets the maximum number of vcpus that a domain may create.
148 *
149 * @parm xc_handle a handle to an open hypervisor interface.
150 * @parm domid the domain id in which vcpus are to be created.
151 * @parm max the maximum number of vcpus that the domain may create.
152 * @return 0 on success, -1 on failure.
153 */
154 int xc_domain_max_vcpus(int xc_handle,
155 uint32_t domid,
156 unsigned int max);
158 /**
159 * This function pauses a domain. A paused domain still exists in memory
160 * however it does not receive any timeslices from the hypervisor.
161 *
162 * @parm xc_handle a handle to an open hypervisor interface
163 * @parm domid the domain id to pause
164 * @return 0 on success, -1 on failure.
165 */
166 int xc_domain_pause(int xc_handle,
167 uint32_t domid);
168 /**
169 * This function unpauses a domain. The domain should have been previously
170 * paused.
171 *
172 * @parm xc_handle a handle to an open hypervisor interface
173 * @parm domid the domain id to unpause
174 * return 0 on success, -1 on failure
175 */
176 int xc_domain_unpause(int xc_handle,
177 uint32_t domid);
179 /**
180 * This function will destroy a domain. Destroying a domain removes the domain
181 * completely from memory. This function should be called after sending the
182 * domain a SHUTDOWN control message to free up the domain resources.
183 *
184 * @parm xc_handle a handle to an open hypervisor interface
185 * @parm domid the domain id to destroy
186 * @return 0 on success, -1 on failure
187 */
188 int xc_domain_destroy(int xc_handle,
189 uint32_t domid);
191 int xc_vcpu_setaffinity(int xc_handle,
192 uint32_t domid,
193 int vcpu,
194 cpumap_t cpumap);
196 /**
197 * This function will return information about one or more domains. It is
198 * designed to iterate over the list of domains. If a single domain is
199 * requested, this function will return the next domain in the list - if
200 * one exists. It is, therefore, important in this case to make sure the
201 * domain requested was the one returned.
202 *
203 * @parm xc_handle a handle to an open hypervisor interface
204 * @parm first_domid the first domain to enumerate information from. Domains
205 * are currently enumerate in order of creation.
206 * @parm max_doms the number of elements in info
207 * @parm info an array of max_doms size that will contain the information for
208 * the enumerated domains.
209 * @return the number of domains enumerated or -1 on error
210 */
211 int xc_domain_getinfo(int xc_handle,
212 uint32_t first_domid,
213 unsigned int max_doms,
214 xc_dominfo_t *info);
217 /**
218 * This function will set the execution context for the specified vcpu.
219 *
220 * @parm xc_handle a handle to an open hypervisor interface
221 * @parm domid the domain to set the vcpu context for
222 * @parm vcpu the vcpu number for the context
223 * @parm ctxt pointer to the the cpu context with the values to set
224 * @return the number of domains enumerated or -1 on error
225 */
226 int xc_vcpu_setcontext(int xc_handle,
227 uint32_t domid,
228 uint32_t vcpu,
229 vcpu_guest_context_t *ctxt);
230 /**
231 * This function will return information about one or more domains, using a
232 * single hypercall. The domain information will be stored into the supplied
233 * array of xc_domaininfo_t structures.
234 *
235 * @parm xc_handle a handle to an open hypervisor interface
236 * @parm first_domain the first domain to enumerate information from.
237 * Domains are currently enumerate in order of creation.
238 * @parm max_domains the number of elements in info
239 * @parm info an array of max_doms size that will contain the information for
240 * the enumerated domains.
241 * @return the number of domains enumerated or -1 on error
242 */
243 int xc_domain_getinfolist(int xc_handle,
244 uint32_t first_domain,
245 unsigned int max_domains,
246 xc_domaininfo_t *info);
248 /**
249 * This function returns information about the execution context of a
250 * particular vcpu of a domain.
251 *
252 * @parm xc_handle a handle to an open hypervisor interface
253 * @parm domid the domain to get information from
254 * @parm vcpu the vcpu number
255 * @parm ctxt a pointer to a structure to store the execution context of the
256 * domain
257 * @return 0 on success, -1 on failure
258 */
259 int xc_vcpu_getcontext(int xc_handle,
260 uint32_t domid,
261 uint32_t vcpu,
262 vcpu_guest_context_t *ctxt);
264 typedef dom0_getvcpuinfo_t xc_vcpuinfo_t;
265 int xc_vcpu_getinfo(int xc_handle,
266 uint32_t domid,
267 uint32_t vcpu,
268 xc_vcpuinfo_t *info);
270 int xc_domain_setcpuweight(int xc_handle,
271 uint32_t domid,
272 float weight);
273 long long xc_domain_get_cpu_usage(int xc_handle,
274 domid_t domid,
275 int vcpu);
277 int xc_domain_sethandle(int xc_handle, uint32_t domid,
278 xen_domain_handle_t handle);
280 typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
281 int xc_shadow_control(int xc_handle,
282 uint32_t domid,
283 unsigned int sop,
284 unsigned long *dirty_bitmap,
285 unsigned long pages,
286 xc_shadow_control_stats_t *stats);
288 int xc_bvtsched_global_set(int xc_handle,
289 unsigned long ctx_allow);
291 int xc_bvtsched_domain_set(int xc_handle,
292 uint32_t domid,
293 uint32_t mcuadv,
294 int warpback,
295 int32_t warpvalue,
296 long long warpl,
297 long long warpu);
299 int xc_bvtsched_global_get(int xc_handle,
300 unsigned long *ctx_allow);
302 int xc_bvtsched_domain_get(int xc_handle,
303 uint32_t domid,
304 uint32_t *mcuadv,
305 int *warpback,
306 int32_t *warpvalue,
307 long long *warpl,
308 long long *warpu);
310 int xc_sedf_domain_set(int xc_handle,
311 uint32_t domid,
312 uint64_t period, uint64_t slice,
313 uint64_t latency, uint16_t extratime,
314 uint16_t weight);
316 int xc_sedf_domain_get(int xc_handle,
317 uint32_t domid,
318 uint64_t* period, uint64_t *slice,
319 uint64_t *latency, uint16_t *extratime,
320 uint16_t *weight);
322 typedef evtchn_status_t xc_evtchn_status_t;
324 /*
325 * EVENT CHANNEL FUNCTIONS
326 */
328 /**
329 * This function allocates an unbound port. Ports are named endpoints used for
330 * interdomain communication. This function is most useful in opening a
331 * well-known port within a domain to receive events on.
332 *
333 * @parm xc_handle a handle to an open hypervisor interface
334 * @parm dom the ID of the local domain (the 'allocatee')
335 * @parm remote_dom the ID of the domain who will later bind
336 * @return allocated port (in @dom) on success, -1 on failure
337 */
338 int xc_evtchn_alloc_unbound(int xc_handle,
339 uint32_t dom,
340 uint32_t remote_dom);
342 int xc_evtchn_status(int xc_handle,
343 uint32_t dom, /* may be DOMID_SELF */
344 evtchn_port_t port,
345 xc_evtchn_status_t *status);
347 int xc_physdev_pci_access_modify(int xc_handle,
348 uint32_t domid,
349 int bus,
350 int dev,
351 int func,
352 int enable);
354 int xc_readconsolering(int xc_handle,
355 char **pbuffer,
356 unsigned int *pnr_chars,
357 int clear);
359 typedef dom0_physinfo_t xc_physinfo_t;
360 int xc_physinfo(int xc_handle,
361 xc_physinfo_t *info);
363 int xc_sched_id(int xc_handle,
364 int *sched_id);
366 int xc_domain_setmaxmem(int xc_handle,
367 uint32_t domid,
368 unsigned int max_memkb);
370 int xc_domain_memory_increase_reservation(int xc_handle,
371 uint32_t domid,
372 unsigned long nr_extents,
373 unsigned int extent_order,
374 unsigned int address_bits,
375 unsigned long *extent_start);
377 int xc_domain_memory_decrease_reservation(int xc_handle,
378 uint32_t domid,
379 unsigned long nr_extents,
380 unsigned int extent_order,
381 unsigned long *extent_start);
383 int xc_domain_memory_populate_physmap(int xc_handle,
384 uint32_t domid,
385 unsigned long nr_extents,
386 unsigned int extent_order,
387 unsigned int address_bits,
388 unsigned long *extent_start);
390 int xc_domain_translate_gpfn_list(int xc_handle,
391 uint32_t domid,
392 unsigned long nr_gpfns,
393 unsigned long *gpfn_list,
394 unsigned long *mfn_list);
396 int xc_domain_ioport_permission(int xc_handle,
397 uint32_t domid,
398 uint32_t first_port,
399 uint32_t nr_ports,
400 uint32_t allow_access);
402 int xc_domain_irq_permission(int xc_handle,
403 uint32_t domid,
404 uint8_t pirq,
405 uint8_t allow_access);
407 int xc_domain_iomem_permission(int xc_handle,
408 uint32_t domid,
409 unsigned long first_mfn,
410 unsigned long nr_mfns,
411 uint8_t allow_access);
413 unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid,
414 unsigned long mfn);
416 typedef dom0_perfc_desc_t xc_perfc_desc_t;
417 /* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
418 int xc_perfc_control(int xc_handle,
419 uint32_t op,
420 xc_perfc_desc_t *desc);
422 /* read/write msr */
423 long long xc_msr_read(int xc_handle, int cpu_mask, int msr);
424 int xc_msr_write(int xc_handle, int cpu_mask, int msr, unsigned int low,
425 unsigned int high);
427 /**
428 * Memory maps a range within one domain to a local address range. Mappings
429 * should be unmapped with munmap and should follow the same rules as mmap
430 * regarding page alignment. Returns NULL on failure.
431 *
432 * In Linux, the ring queue for the control channel is accessible by mapping
433 * the shared_info_frame (from xc_domain_getinfo()) + 2048. The structure
434 * stored there is of type control_if_t.
435 *
436 * @parm xc_handle a handle on an open hypervisor interface
437 * @parm dom the domain to map memory from
438 * @parm size the amount of memory to map (in multiples of page size)
439 * @parm prot same flag as in mmap().
440 * @parm mfn the frame address to map.
441 */
442 void *xc_map_foreign_range(int xc_handle, uint32_t dom,
443 int size, int prot,
444 unsigned long mfn );
446 void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
447 unsigned long *arr, int num );
449 /**
450 * Translates a virtual address in the context of a given domain and
451 * vcpu returning the machine page frame number of the associated
452 * page.
453 *
454 * @parm xc_handle a handle on an open hypervisor interface
455 * @parm dom the domain to perform the translation in
456 * @parm vcpu the vcpu to perform the translation on
457 * @parm virt the virtual address to translate
458 */
459 unsigned long xc_translate_foreign_address(int xc_handle, uint32_t dom,
460 int vcpu, unsigned long long virt);
462 int xc_get_pfn_list(int xc_handle, uint32_t domid, unsigned long *pfn_buf,
463 unsigned long max_pfns);
465 int xc_ia64_get_pfn_list(int xc_handle, uint32_t domid,
466 unsigned long *pfn_buf,
467 unsigned int start_page, unsigned int nr_pages);
469 int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
470 unsigned long dst_pfn, void *src_page);
472 int xc_clear_domain_page(int xc_handle, uint32_t domid,
473 unsigned long dst_pfn);
475 int xc_ia64_copy_to_domain_pages(int xc_handle, uint32_t domid,
476 void* src_page, unsigned long dst_pfn, int nr_pages);
478 long xc_get_max_pages(int xc_handle, uint32_t domid);
480 int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
481 domid_t dom);
483 int xc_memory_op(int xc_handle, int cmd, void *arg);
485 int xc_get_pfn_type_batch(int xc_handle, uint32_t dom,
486 int num, unsigned long *arr);
489 /* Get current total pages allocated to a domain. */
490 long xc_get_tot_pages(int xc_handle, uint32_t domid);
493 /*
494 * Trace Buffer Operations
495 */
497 /**
498 * This function enables or disables tracing. Trace buffer memory must
499 * be already allocated by setting the size to a non-zero value, otherwise
500 * tracing cannot be enabled.
501 *
502 * @parm xc_handle a handle to an open hypervisor interface
503 * @parm enable the desired action, 1 for enable, 0 for disable
504 * @return 0 on success, -1 on failure.
505 */
506 int xc_tbuf_enable(int xc_handle, int enable);
508 /**
509 * This function sets the size of the trace buffers. Setting the size
510 * is currently a one-shot operation that may be performed either at boot
511 * time or via this interface, not both. The buffer size must be set before
512 * enabling tracing.
513 *
514 * @parm xc_handle a handle to an open hypervisor interface
515 * @parm size the size in pages per cpu for the trace buffers
516 * @return 0 on success, -1 on failure.
517 */
518 int xc_tbuf_set_size(int xc_handle, uint32_t size);
520 /**
521 * This function retrieves the current size of the trace buffers.
522 * Note that the size returned is in terms of bytes, not pages.
524 * @parm xc_handle a handle to an open hypervisor interface
525 * @parm size will contain the size in bytes for the trace buffers
526 * @return 0 on success, -1 on failure.
527 */
528 int xc_tbuf_get_size(int xc_handle, uint32_t *size);
531 /* Execute a privileged dom0 operation. */
532 int xc_dom0_op(int xc_handle, dom0_op_t *op);
534 int xc_version(int xc_handle, int cmd, void *arg);
536 /*
537 * MMU updates.
538 */
539 #define MAX_MMU_UPDATES 1024
540 struct xc_mmu {
541 mmu_update_t updates[MAX_MMU_UPDATES];
542 int idx;
543 domid_t subject;
544 };
545 typedef struct xc_mmu xc_mmu_t;
546 xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom);
547 int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu,
548 unsigned long long ptr, unsigned long long val);
549 int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
551 #endif