direct-io.hg

view tools/libxc/xc_ptrace_core.c @ 11774:5d2ce349f9f4

[SOLARIS] Don't build ptrace code on Solaris.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Tue Oct 17 17:59:32 2006 +0100 (2006-10-17)
parents f8af7041bf5b
children cfb1136ee8f7
line source
1 #include <sys/ptrace.h>
2 #include <sys/wait.h>
3 #include "xc_private.h"
4 #include "xg_private.h"
5 #include "xc_ptrace.h"
6 #include <time.h>
8 /* XXX application state */
10 static long nr_pages = 0;
11 static unsigned long *p2m_array = NULL;
12 static unsigned long *m2p_array = NULL;
13 static unsigned long pages_offset;
14 static unsigned long cr3[MAX_VIRT_CPUS];
16 /* --------------------- */
18 static unsigned long
19 map_mtop_offset(unsigned long ma)
20 {
21 return pages_offset + (m2p_array[ma >> PAGE_SHIFT] << PAGE_SHIFT);
22 return 0;
23 }
26 void *
27 map_domain_va_core(unsigned long domfd, int cpu, void * guest_va,
28 vcpu_guest_context_t *ctxt)
29 {
30 unsigned long pde, page;
31 unsigned long va = (unsigned long)guest_va;
32 void *v;
34 static unsigned long cr3_phys[MAX_VIRT_CPUS];
35 static unsigned long *cr3_virt[MAX_VIRT_CPUS];
36 static unsigned long pde_phys[MAX_VIRT_CPUS];
37 static unsigned long *pde_virt[MAX_VIRT_CPUS];
38 static unsigned long page_phys[MAX_VIRT_CPUS];
39 static unsigned long *page_virt[MAX_VIRT_CPUS];
41 if (cr3[cpu] != cr3_phys[cpu])
42 {
43 cr3_phys[cpu] = cr3[cpu];
44 if (cr3_virt[cpu])
45 munmap(cr3_virt[cpu], PAGE_SIZE);
46 v = mmap(
47 NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
48 map_mtop_offset(xen_cr3_to_pfn(cr3_phys[cpu])));
49 if (v == MAP_FAILED)
50 {
51 perror("mmap failed");
52 return NULL;
53 }
54 cr3_virt[cpu] = v;
55 }
56 if ((pde = cr3_virt[cpu][l2_table_offset_i386(va)]) == 0) /* logical address */
57 return NULL;
58 if (ctxt[cpu].flags & VGCF_HVM_GUEST)
59 pde = p2m_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
60 if (pde != pde_phys[cpu])
61 {
62 pde_phys[cpu] = pde;
63 if (pde_virt[cpu])
64 munmap(pde_virt[cpu], PAGE_SIZE);
65 v = mmap(
66 NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
67 map_mtop_offset(pde_phys[cpu]));
68 if (v == MAP_FAILED)
69 return NULL;
70 pde_virt[cpu] = v;
71 }
72 if ((page = pde_virt[cpu][l1_table_offset_i386(va)]) == 0) /* logical address */
73 return NULL;
74 if (ctxt[cpu].flags & VGCF_HVM_GUEST)
75 page = p2m_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
76 if (page != page_phys[cpu])
77 {
78 page_phys[cpu] = page;
79 if (page_virt[cpu])
80 munmap(page_virt[cpu], PAGE_SIZE);
81 v = mmap(
82 NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd,
83 map_mtop_offset(page_phys[cpu]));
84 if (v == MAP_FAILED)
85 {
86 IPRINTF("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, l1_table_offset_i386(va));
87 page_phys[cpu] = 0;
88 return NULL;
89 }
90 page_virt[cpu] = v;
91 }
92 return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK));
93 }
95 int
96 xc_waitdomain_core(
97 int xc_handle,
98 int domfd,
99 int *status,
100 int options,
101 vcpu_guest_context_t *ctxt)
102 {
103 int nr_vcpus;
104 int i;
105 xc_core_header_t header;
107 if (nr_pages == 0)
108 {
110 if (read(domfd, &header, sizeof(header)) != sizeof(header))
111 return -1;
113 if (header.xch_magic != XC_CORE_MAGIC) {
114 IPRINTF("Magic number missmatch: 0x%08x (file) != "
115 " 0x%08x (code)\n", header.xch_magic,
116 XC_CORE_MAGIC);
117 return -1;
118 }
120 nr_pages = header.xch_nr_pages;
121 nr_vcpus = header.xch_nr_vcpus;
122 pages_offset = header.xch_pages_offset;
124 if (read(domfd, ctxt, sizeof(vcpu_guest_context_t)*nr_vcpus) !=
125 sizeof(vcpu_guest_context_t)*nr_vcpus)
126 return -1;
128 for (i = 0; i < nr_vcpus; i++)
129 cr3[i] = ctxt[i].ctrlreg[3];
131 if ((p2m_array = malloc(nr_pages * sizeof(unsigned long))) == NULL)
132 {
133 IPRINTF("Could not allocate p2m_array\n");
134 return -1;
135 }
137 if (read(domfd, p2m_array, sizeof(unsigned long)*nr_pages) !=
138 sizeof(unsigned long)*nr_pages)
139 return -1;
141 if ((m2p_array = malloc((1<<20) * sizeof(unsigned long))) == NULL)
142 {
143 IPRINTF("Could not allocate m2p array\n");
144 return -1;
145 }
146 bzero(m2p_array, sizeof(unsigned long)* 1 << 20);
148 for (i = 0; i < nr_pages; i++)
149 m2p_array[p2m_array[i]] = i;
150 }
151 return 0;
152 }
154 /*
155 * Local variables:
156 * mode: C
157 * c-set-style: "BSD"
158 * c-basic-offset: 4
159 * tab-width: 4
160 * indent-tabs-mode: nil
161 * End:
162 */