ia64/xen-unstable
changeset 9147:26eff2448966
libxc: xc_ptrace cleanups
General Cleanups
* Use { after if consistently in xc_ptrace.c and xc_ptrace_core.c
(But not in xc_ptrace_core() which should be removed shortly)
* Remove duplicate code and centralise around xc_ptrace.h
* Avoid ifing values covered by case in xc_ptrace()
- PTRACE_GETREGS, PTRACE_GETFPREGS and PTRACE_GETFPXREGS are grouped into
a single case, and then with the exception of a call to FETCH_REGS(),
different code is executed based on ifing the values covered by the
case. The PTRACE_GETFPREGS and PTRACE_GETFPXREGS code is actually a
duplicate. This patch breaks the code out to two different cases.
Error Handling
* Eliminate FETCH_REGS macro as it forces several functions
to have an otherwise uneeded error_out label, mittigating
any code savins.
* Rework error handling in xc_ptrace().
- Remove FETCH_REGS as above
- Make sure that all dom0 errors are caught
- Make sure errno is always set on error
* Eliminate gotos in xc_ptrace_core.c that do nothing but return
Signed-Off-By: Horms <horms@verge.net.au>
General Cleanups
* Use { after if consistently in xc_ptrace.c and xc_ptrace_core.c
(But not in xc_ptrace_core() which should be removed shortly)
* Remove duplicate code and centralise around xc_ptrace.h
* Avoid ifing values covered by case in xc_ptrace()
- PTRACE_GETREGS, PTRACE_GETFPREGS and PTRACE_GETFPXREGS are grouped into
a single case, and then with the exception of a call to FETCH_REGS(),
different code is executed based on ifing the values covered by the
case. The PTRACE_GETFPREGS and PTRACE_GETFPXREGS code is actually a
duplicate. This patch breaks the code out to two different cases.
Error Handling
* Eliminate FETCH_REGS macro as it forces several functions
to have an otherwise uneeded error_out label, mittigating
any code savins.
* Rework error handling in xc_ptrace().
- Remove FETCH_REGS as above
- Make sure that all dom0 errors are caught
- Make sure errno is always set on error
* Eliminate gotos in xc_ptrace_core.c that do nothing but return
Signed-Off-By: Horms <horms@verge.net.au>
author | kaf24@firebug.cl.cam.ac.uk |
---|---|
date | Mon Mar 06 12:05:44 2006 +0100 (2006-03-06) |
parents | f614ea56143c |
children | 8ed131452f27 |
files | tools/libxc/xc_ptrace.c tools/libxc/xc_ptrace.h tools/libxc/xc_ptrace_core.c |
line diff
1.1 --- a/tools/libxc/xc_ptrace.c Mon Mar 06 11:04:37 2006 +0100 1.2 +++ b/tools/libxc/xc_ptrace.c Mon Mar 06 12:05:44 2006 +0100 1.3 @@ -7,9 +7,35 @@ 1.4 1.5 #include "xc_private.h" 1.6 #include "xg_private.h" 1.7 -#include <thread_db.h> 1.8 #include "xc_ptrace.h" 1.9 1.10 +const char const * ptrace_names[] = { 1.11 + "PTRACE_TRACEME", 1.12 + "PTRACE_PEEKTEXT", 1.13 + "PTRACE_PEEKDATA", 1.14 + "PTRACE_PEEKUSER", 1.15 + "PTRACE_POKETEXT", 1.16 + "PTRACE_POKEDATA", 1.17 + "PTRACE_POKEUSER", 1.18 + "PTRACE_CONT", 1.19 + "PTRACE_KILL", 1.20 + "PTRACE_SINGLESTEP", 1.21 + "PTRACE_INVALID", 1.22 + "PTRACE_INVALID", 1.23 + "PTRACE_GETREGS", 1.24 + "PTRACE_SETREGS", 1.25 + "PTRACE_GETFPREGS", 1.26 + "PTRACE_SETFPREGS", 1.27 + "PTRACE_ATTACH", 1.28 + "PTRACE_DETACH", 1.29 + "PTRACE_GETFPXREGS", 1.30 + "PTRACE_SETFPXREGS", 1.31 + "PTRACE_INVALID", 1.32 + "PTRACE_INVALID", 1.33 + "PTRACE_INVALID", 1.34 + "PTRACE_INVALID", 1.35 + "PTRACE_SYSCALL", 1.36 +}; 1.37 1.38 /* XXX application state */ 1.39 static long nr_pages = 0; 1.40 @@ -32,7 +58,8 @@ fetch_regs(int xc_handle, int cpu, int * 1.41 1.42 if (online) 1.43 *online = 0; 1.44 - if ( !(regs_valid & (1 << cpu)) ) { 1.45 + if ( !(regs_valid & (1 << cpu)) ) 1.46 + { 1.47 retval = xc_vcpu_getcontext(xc_handle, current_domid, 1.48 cpu, &ctxt[cpu]); 1.49 if ( retval ) 1.50 @@ -50,9 +77,6 @@ fetch_regs(int xc_handle, int cpu, int * 1.51 return retval; 1.52 } 1.53 1.54 -#define FETCH_REGS(cpu) if (fetch_regs(xc_handle, cpu, NULL)) goto error_out; 1.55 - 1.56 - 1.57 static struct thr_ev_handlers { 1.58 thr_ev_handler_t td_create; 1.59 thr_ev_handler_t td_death; 1.60 @@ -95,14 +119,12 @@ get_online_cpumap(int xc_handle, dom0_ge 1.61 *cpumap = 0; 1.62 for (i = 0; i <= d->max_vcpu_id; i++) { 1.63 if ((retval = fetch_regs(xc_handle, i, &online))) 1.64 - goto error_out; 1.65 + return retval; 1.66 if (online) 1.67 *cpumap |= (1 << i); 1.68 } 1.69 1.70 return 0; 1.71 - error_out: 1.72 - return retval; 1.73 } 1.74 1.75 /* 1.76 @@ -118,7 +140,8 @@ online_vcpus_changed(cpumap_t cpumap) 1.77 int index; 1.78 1.79 while ( (index = ffsll(changed_cpumap)) ) { 1.80 - if ( cpumap & (1 << (index - 1)) ) { 1.81 + if ( cpumap & (1 << (index - 1)) ) 1.82 + { 1.83 if (handlers.td_create) handlers.td_create(index - 1); 1.84 } else { 1.85 printf("thread death: %d\n", index - 1); 1.86 @@ -143,34 +166,32 @@ map_domain_va_pae( 1.87 uint64_t *l3, *l2, *l1; 1.88 static void *v; 1.89 1.90 - FETCH_REGS(cpu); 1.91 + if (fetch_regs(xc_handle, cpu, NULL)) 1.92 + return NULL; 1.93 1.94 l3 = xc_map_foreign_range( 1.95 xc_handle, current_domid, PAGE_SIZE, PROT_READ, ctxt[cpu].ctrlreg[3] >> PAGE_SHIFT); 1.96 if ( l3 == NULL ) 1.97 - goto error_out; 1.98 + return NULL; 1.99 1.100 l2p = l3[l3_table_offset_pae(va)] >> PAGE_SHIFT; 1.101 l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p); 1.102 if ( l2 == NULL ) 1.103 - goto error_out; 1.104 + return NULL; 1.105 1.106 l1p = l2[l2_table_offset_pae(va)] >> PAGE_SHIFT; 1.107 l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p); 1.108 if ( l1 == NULL ) 1.109 - goto error_out; 1.110 + return NULL; 1.111 1.112 p = l1[l1_table_offset_pae(va)] >> PAGE_SHIFT; 1.113 if ( v != NULL ) 1.114 munmap(v, PAGE_SIZE); 1.115 v = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p); 1.116 if ( v == NULL ) 1.117 - goto error_out; 1.118 + return NULL; 1.119 1.120 return (void *)((unsigned long)v | (va & (PAGE_SIZE - 1))); 1.121 - 1.122 - error_out: 1.123 - return NULL; 1.124 } 1.125 1.126 static void * 1.127 @@ -215,17 +236,18 @@ map_domain_va( 1.128 if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL ) 1.129 { 1.130 printf("Could not allocate memory\n"); 1.131 - goto error_out; 1.132 + return NULL; 1.133 } 1.134 if ( xc_get_pfn_list(xc_handle, current_domid, 1.135 page_array, nr_pages) != nr_pages ) 1.136 { 1.137 printf("Could not get the page frame list\n"); 1.138 - goto error_out; 1.139 + return NULL; 1.140 } 1.141 } 1.142 1.143 - FETCH_REGS(cpu); 1.144 + if (fetch_regs(xc_handle, cpu, NULL)) 1.145 + return NULL; 1.146 1.147 if ( ctxt[cpu].ctrlreg[3] != cr3_phys[cpu] ) 1.148 { 1.149 @@ -236,10 +258,10 @@ map_domain_va( 1.150 xc_handle, current_domid, PAGE_SIZE, PROT_READ, 1.151 cr3_phys[cpu] >> PAGE_SHIFT); 1.152 if ( cr3_virt[cpu] == NULL ) 1.153 - goto error_out; 1.154 + return NULL; 1.155 } 1.156 if ( (pde = cr3_virt[cpu][vtopdi(va)]) == 0 ) 1.157 - goto error_out; 1.158 + return NULL; 1.159 if ( (ctxt[cpu].flags & VGCF_HVM_GUEST) && paging_enabled(&ctxt[cpu]) ) 1.160 pde = page_array[pde >> PAGE_SHIFT] << PAGE_SHIFT; 1.161 if ( pde != pde_phys[cpu] ) 1.162 @@ -251,10 +273,10 @@ map_domain_va( 1.163 xc_handle, current_domid, PAGE_SIZE, PROT_READ, 1.164 pde_phys[cpu] >> PAGE_SHIFT); 1.165 if ( pde_virt[cpu] == NULL ) 1.166 - goto error_out; 1.167 + return NULL; 1.168 } 1.169 if ( (page = pde_virt[cpu][vtopti(va)]) == 0 ) 1.170 - goto error_out; 1.171 + return NULL; 1.172 if ( (ctxt[cpu].flags & VGCF_HVM_GUEST) && paging_enabled(&ctxt[cpu]) ) 1.173 page = page_array[page >> PAGE_SHIFT] << PAGE_SHIFT; 1.174 if ( (page != page_phys[cpu]) || (perm != prev_perm[cpu]) ) 1.175 @@ -268,15 +290,12 @@ map_domain_va( 1.176 if ( page_virt[cpu] == NULL ) 1.177 { 1.178 page_phys[cpu] = 0; 1.179 - goto error_out; 1.180 + return NULL; 1.181 } 1.182 prev_perm[cpu] = perm; 1.183 } 1.184 1.185 return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK)); 1.186 - 1.187 - error_out: 1.188 - return NULL; 1.189 } 1.190 1.191 int 1.192 @@ -335,7 +354,6 @@ xc_ptrace( 1.193 long edata) 1.194 { 1.195 DECLARE_DOM0_OP; 1.196 - int status = 0; 1.197 struct gdb_regs pt; 1.198 long retval = 0; 1.199 unsigned long *guest_va; 1.200 @@ -353,10 +371,7 @@ xc_ptrace( 1.201 guest_va = (unsigned long *)map_domain_va( 1.202 xc_handle, cpu, addr, PROT_READ); 1.203 if ( guest_va == NULL ) 1.204 - { 1.205 - status = EFAULT; 1.206 - goto error_out; 1.207 - } 1.208 + goto out_error; 1.209 retval = *guest_va; 1.210 break; 1.211 1.212 @@ -365,38 +380,30 @@ xc_ptrace( 1.213 /* XXX assume that all CPUs have the same address space */ 1.214 guest_va = (unsigned long *)map_domain_va( 1.215 xc_handle, cpu, addr, PROT_READ|PROT_WRITE); 1.216 - if ( guest_va == NULL ) { 1.217 - status = EFAULT; 1.218 - goto error_out; 1.219 - } 1.220 + if ( guest_va == NULL ) 1.221 + goto out_error; 1.222 *guest_va = (unsigned long)data; 1.223 break; 1.224 1.225 case PTRACE_GETREGS: 1.226 + if (fetch_regs(xc_handle, cpu, NULL)) 1.227 + goto out_error; 1.228 + SET_PT_REGS(pt, ctxt[cpu].user_regs); 1.229 + memcpy(data, &pt, sizeof(struct gdb_regs)); 1.230 + break; 1.231 + 1.232 case PTRACE_GETFPREGS: 1.233 case PTRACE_GETFPXREGS: 1.234 - 1.235 - FETCH_REGS(cpu); 1.236 - if ( request == PTRACE_GETREGS ) 1.237 - { 1.238 - SET_PT_REGS(pt, ctxt[cpu].user_regs); 1.239 - memcpy(data, &pt, sizeof(struct gdb_regs)); 1.240 - } 1.241 - else if (request == PTRACE_GETFPREGS) 1.242 - { 1.243 - memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt)); 1.244 - } 1.245 - else /*if (request == PTRACE_GETFPXREGS)*/ 1.246 - { 1.247 - memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt)); 1.248 - } 1.249 + if (fetch_regs(xc_handle, cpu, NULL)) 1.250 + goto out_error; 1.251 + memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt)); 1.252 break; 1.253 1.254 case PTRACE_SETREGS: 1.255 SET_XC_REGS(((struct gdb_regs *)data), ctxt[cpu].user_regs); 1.256 - retval = xc_vcpu_setcontext(xc_handle, current_domid, cpu, &ctxt[cpu]); 1.257 - if (retval) 1.258 - goto error_out; 1.259 + if ((retval = xc_vcpu_setcontext(xc_handle, current_domid, cpu, 1.260 + &ctxt[cpu]))) 1.261 + goto out_error_dom0; 1.262 break; 1.263 1.264 case PTRACE_SINGLESTEP: 1.265 @@ -404,12 +411,9 @@ xc_ptrace( 1.266 * during single-stepping - but that just seems retarded 1.267 */ 1.268 ctxt[cpu].user_regs.eflags |= PSL_T; 1.269 - retval = xc_vcpu_setcontext(xc_handle, current_domid, cpu, &ctxt[cpu]); 1.270 - if ( retval ) 1.271 - { 1.272 - perror("dom0 op failed"); 1.273 - goto error_out; 1.274 - } 1.275 + if ((retval = xc_vcpu_setcontext(xc_handle, current_domid, cpu, 1.276 + &ctxt[cpu]))) 1.277 + goto out_error_dom0; 1.278 /* FALLTHROUGH */ 1.279 1.280 case PTRACE_CONT: 1.281 @@ -418,16 +422,15 @@ xc_ptrace( 1.282 { 1.283 FOREACH_CPU(cpumap, index) { 1.284 cpu = index - 1; 1.285 - FETCH_REGS(cpu); 1.286 + if (fetch_regs(xc_handle, cpu, NULL)) 1.287 + goto out_error; 1.288 /* Clear trace flag */ 1.289 - if ( ctxt[cpu].user_regs.eflags & PSL_T ) { 1.290 + if ( ctxt[cpu].user_regs.eflags & PSL_T ) 1.291 + { 1.292 ctxt[cpu].user_regs.eflags &= ~PSL_T; 1.293 - retval = xc_vcpu_setcontext(xc_handle, current_domid, 1.294 - cpu, &ctxt[cpu]); 1.295 - if ( retval ) { 1.296 - perror("dom0 op failed"); 1.297 - goto error_out; 1.298 - } 1.299 + if ((retval = xc_vcpu_setcontext(xc_handle, current_domid, 1.300 + cpu, &ctxt[cpu]))) 1.301 + goto out_error_dom0; 1.302 } 1.303 } 1.304 } 1.305 @@ -436,10 +439,13 @@ xc_ptrace( 1.306 op.cmd = DOM0_SETDEBUGGING; 1.307 op.u.setdebugging.domain = current_domid; 1.308 op.u.setdebugging.enable = 0; 1.309 - retval = do_dom0_op(xc_handle, &op); 1.310 + if ((retval = do_dom0_op(xc_handle, &op))) 1.311 + goto out_error_dom0; 1.312 } 1.313 regs_valid = 0; 1.314 - xc_domain_unpause(xc_handle, current_domid > 0 ? current_domid : -current_domid); 1.315 + if ((retval = xc_domain_unpause(xc_handle, current_domid > 0 ? 1.316 + current_domid : -current_domid))) 1.317 + goto out_error_dom0; 1.318 break; 1.319 1.320 case PTRACE_ATTACH: 1.321 @@ -448,19 +454,16 @@ xc_ptrace( 1.322 op.u.getdomaininfo.domain = current_domid; 1.323 retval = do_dom0_op(xc_handle, &op); 1.324 if ( retval || (op.u.getdomaininfo.domain != current_domid) ) 1.325 - { 1.326 - perror("dom0 op failed"); 1.327 - goto error_out; 1.328 - } 1.329 + goto out_error_dom0; 1.330 if ( op.u.getdomaininfo.flags & DOMFLAGS_PAUSED ) 1.331 - { 1.332 printf("domain currently paused\n"); 1.333 - } else 1.334 - retval = xc_domain_pause(xc_handle, current_domid); 1.335 + else if ((retval = xc_domain_pause(xc_handle, current_domid))) 1.336 + goto out_error_dom0; 1.337 op.cmd = DOM0_SETDEBUGGING; 1.338 op.u.setdebugging.domain = current_domid; 1.339 op.u.setdebugging.enable = 1; 1.340 - retval = do_dom0_op(xc_handle, &op); 1.341 + if ((retval = do_dom0_op(xc_handle, &op))) 1.342 + goto out_error_dom0; 1.343 1.344 if (get_online_cpumap(xc_handle, &op.u.getdomaininfo, &cpumap)) 1.345 printf("get_online_cpumap failed\n"); 1.346 @@ -478,21 +481,20 @@ xc_ptrace( 1.347 printf("unsupported xc_ptrace request %s\n", ptrace_names[request]); 1.348 #endif 1.349 /* XXX not yet supported */ 1.350 - status = ENOSYS; 1.351 - break; 1.352 + errno = ENOSYS; 1.353 + return -1; 1.354 1.355 case PTRACE_TRACEME: 1.356 printf("PTRACE_TRACEME is an invalid request under Xen\n"); 1.357 - status = EINVAL; 1.358 - } 1.359 - 1.360 - if ( status ) 1.361 - { 1.362 - errno = status; 1.363 - retval = -1; 1.364 + goto out_error; 1.365 } 1.366 1.367 - error_out: 1.368 + return retval; 1.369 + 1.370 + out_error_dom0: 1.371 + perror("dom0 op failed"); 1.372 + out_error: 1.373 + errno = EINVAL; 1.374 return retval; 1.375 } 1.376
2.1 --- a/tools/libxc/xc_ptrace.h Mon Mar 06 11:04:37 2006 +0100 2.2 +++ b/tools/libxc/xc_ptrace.h Mon Mar 06 12:05:44 2006 +0100 2.3 @@ -1,6 +1,8 @@ 2.4 #ifndef XC_PTRACE_ 2.5 #define XC_PTRACE_ 2.6 2.7 +#include <thread_db.h> 2.8 + 2.9 #ifdef XC_PTRACE_PRIVATE 2.10 #define X86_CR0_PE 0x00000001 /* Enable Protected Mode (RW) */ 2.11 #define X86_CR0_PG 0x80000000 /* Paging (RW) */ 2.12 @@ -8,33 +10,7 @@ 2.13 #define PDRSHIFT 22 2.14 #define PSL_T 0x00000100 /* trace enable bit */ 2.15 2.16 -char * ptrace_names[] = { 2.17 - "PTRACE_TRACEME", 2.18 - "PTRACE_PEEKTEXT", 2.19 - "PTRACE_PEEKDATA", 2.20 - "PTRACE_PEEKUSER", 2.21 - "PTRACE_POKETEXT", 2.22 - "PTRACE_POKEDATA", 2.23 - "PTRACE_POKEUSER", 2.24 - "PTRACE_CONT", 2.25 - "PTRACE_KILL", 2.26 - "PTRACE_SINGLESTEP", 2.27 - "PTRACE_INVALID", 2.28 - "PTRACE_INVALID", 2.29 - "PTRACE_GETREGS", 2.30 - "PTRACE_SETREGS", 2.31 - "PTRACE_GETFPREGS", 2.32 - "PTRACE_SETFPREGS", 2.33 - "PTRACE_ATTACH", 2.34 - "PTRACE_DETACH", 2.35 - "PTRACE_GETFPXREGS", 2.36 - "PTRACE_SETFPXREGS", 2.37 - "PTRACE_INVALID", 2.38 - "PTRACE_INVALID", 2.39 - "PTRACE_INVALID", 2.40 - "PTRACE_INVALID", 2.41 - "PTRACE_SYSCALL", 2.42 -}; 2.43 +extern const char const * ptrace_names[]; 2.44 2.45 struct gdb_regs { 2.46 long ebx; /* 0 */
3.1 --- a/tools/libxc/xc_ptrace_core.c Mon Mar 06 11:04:37 2006 +0100 3.2 +++ b/tools/libxc/xc_ptrace_core.c Mon Mar 06 12:05:44 2006 +0100 3.3 @@ -1,82 +1,13 @@ 3.4 +#define XC_PTRACE_PRIVATE 3.5 + 3.6 #include <sys/ptrace.h> 3.7 #include <sys/wait.h> 3.8 #include "xc_private.h" 3.9 +#include "xc_ptrace.h" 3.10 #include <time.h> 3.11 3.12 -#define BSD_PAGE_MASK (PAGE_SIZE-1) 3.13 -#define PDRSHIFT 22 3.14 #define VCPU 0 /* XXX */ 3.15 3.16 -/* 3.17 - * long 3.18 - * ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data); 3.19 - */ 3.20 - 3.21 -struct gdb_regs { 3.22 - long ebx; /* 0 */ 3.23 - long ecx; /* 4 */ 3.24 - long edx; /* 8 */ 3.25 - long esi; /* 12 */ 3.26 - long edi; /* 16 */ 3.27 - long ebp; /* 20 */ 3.28 - long eax; /* 24 */ 3.29 - int xds; /* 28 */ 3.30 - int xes; /* 32 */ 3.31 - int xfs; /* 36 */ 3.32 - int xgs; /* 40 */ 3.33 - long orig_eax; /* 44 */ 3.34 - long eip; /* 48 */ 3.35 - int xcs; /* 52 */ 3.36 - long eflags; /* 56 */ 3.37 - long esp; /* 60 */ 3.38 - int xss; /* 64 */ 3.39 -}; 3.40 - 3.41 -#define printval(x) printf("%s = %lx\n", #x, (long)x); 3.42 -#define SET_PT_REGS(pt, xc) \ 3.43 -{ \ 3.44 - pt.ebx = xc.ebx; \ 3.45 - pt.ecx = xc.ecx; \ 3.46 - pt.edx = xc.edx; \ 3.47 - pt.esi = xc.esi; \ 3.48 - pt.edi = xc.edi; \ 3.49 - pt.ebp = xc.ebp; \ 3.50 - pt.eax = xc.eax; \ 3.51 - pt.eip = xc.eip; \ 3.52 - pt.xcs = xc.cs; \ 3.53 - pt.eflags = xc.eflags; \ 3.54 - pt.esp = xc.esp; \ 3.55 - pt.xss = xc.ss; \ 3.56 - pt.xes = xc.es; \ 3.57 - pt.xds = xc.ds; \ 3.58 - pt.xfs = xc.fs; \ 3.59 - pt.xgs = xc.gs; \ 3.60 -} 3.61 - 3.62 -#define SET_XC_REGS(pt, xc) \ 3.63 -{ \ 3.64 - xc.ebx = pt->ebx; \ 3.65 - xc.ecx = pt->ecx; \ 3.66 - xc.edx = pt->edx; \ 3.67 - xc.esi = pt->esi; \ 3.68 - xc.edi = pt->edi; \ 3.69 - xc.ebp = pt->ebp; \ 3.70 - xc.eax = pt->eax; \ 3.71 - xc.eip = pt->eip; \ 3.72 - xc.cs = pt->xcs; \ 3.73 - xc.eflags = pt->eflags; \ 3.74 - xc.esp = pt->esp; \ 3.75 - xc.ss = pt->xss; \ 3.76 - xc.es = pt->xes; \ 3.77 - xc.ds = pt->xds; \ 3.78 - xc.fs = pt->xfs; \ 3.79 - xc.gs = pt->xgs; \ 3.80 -} 3.81 - 3.82 - 3.83 -#define vtopdi(va) ((va) >> PDRSHIFT) 3.84 -#define vtopti(va) (((va) >> PAGE_SHIFT) & 0x3ff) 3.85 - 3.86 /* XXX application state */ 3.87 3.88 static long nr_pages = 0; 3.89 @@ -120,12 +51,12 @@ map_domain_va(unsigned long domfd, int c 3.90 if (v == MAP_FAILED) 3.91 { 3.92 perror("mmap failed"); 3.93 - goto error_out; 3.94 + return NULL; 3.95 } 3.96 cr3_virt[cpu] = v; 3.97 } 3.98 if ((pde = cr3_virt[cpu][vtopdi(va)]) == 0) /* logical address */ 3.99 - goto error_out; 3.100 + return NULL; 3.101 if (ctxt[cpu].flags & VGCF_HVM_GUEST) 3.102 pde = p2m_array[pde >> PAGE_SHIFT] << PAGE_SHIFT; 3.103 if (pde != pde_phys[cpu]) 3.104 @@ -137,11 +68,11 @@ map_domain_va(unsigned long domfd, int c 3.105 NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd, 3.106 map_mtop_offset(pde_phys[cpu])); 3.107 if (v == MAP_FAILED) 3.108 - goto error_out; 3.109 + return NULL; 3.110 pde_virt[cpu] = v; 3.111 } 3.112 if ((page = pde_virt[cpu][vtopti(va)]) == 0) /* logical address */ 3.113 - goto error_out; 3.114 + return NULL; 3.115 if (ctxt[cpu].flags & VGCF_HVM_GUEST) 3.116 page = p2m_array[page >> PAGE_SHIFT] << PAGE_SHIFT; 3.117 if (page != page_phys[cpu]) 3.118 @@ -152,17 +83,15 @@ map_domain_va(unsigned long domfd, int c 3.119 v = mmap( 3.120 NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE, domfd, 3.121 map_mtop_offset(page_phys[cpu])); 3.122 - if (v == MAP_FAILED) { 3.123 + if (v == MAP_FAILED) 3.124 + { 3.125 printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va)); 3.126 page_phys[cpu] = 0; 3.127 - goto error_out; 3.128 + return NULL; 3.129 } 3.130 page_virt[cpu] = v; 3.131 } 3.132 return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK)); 3.133 - 3.134 - error_out: 3.135 - return 0; 3.136 } 3.137 3.138 int 3.139 @@ -172,12 +101,12 @@ xc_waitdomain_core( 3.140 int *status, 3.141 int options) 3.142 { 3.143 - int retval = -1; 3.144 int nr_vcpus; 3.145 int i; 3.146 xc_core_header_t header; 3.147 3.148 - if (nr_pages == 0) { 3.149 + if (nr_pages == 0) 3.150 + { 3.151 3.152 if (read(domfd, &header, sizeof(header)) != sizeof(header)) 3.153 return -1; 3.154 @@ -193,17 +122,19 @@ xc_waitdomain_core( 3.155 for (i = 0; i < nr_vcpus; i++) { 3.156 cr3[i] = ctxt[i].ctrlreg[3]; 3.157 } 3.158 - if ((p2m_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) { 3.159 + if ((p2m_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) 3.160 + { 3.161 printf("Could not allocate p2m_array\n"); 3.162 - goto error_out; 3.163 + return -1; 3.164 } 3.165 if (read(domfd, p2m_array, sizeof(unsigned long)*nr_pages) != 3.166 sizeof(unsigned long)*nr_pages) 3.167 return -1; 3.168 3.169 - if ((m2p_array = malloc((1<<20) * sizeof(unsigned long))) == NULL) { 3.170 + if ((m2p_array = malloc((1<<20) * sizeof(unsigned long))) == NULL) 3.171 + { 3.172 printf("Could not allocate m2p array\n"); 3.173 - goto error_out; 3.174 + return -1; 3.175 } 3.176 bzero(m2p_array, sizeof(unsigned long)* 1 << 20); 3.177 3.178 @@ -212,10 +143,7 @@ xc_waitdomain_core( 3.179 } 3.180 3.181 } 3.182 - retval = 0; 3.183 - error_out: 3.184 - return retval; 3.185 - 3.186 + return 0; 3.187 } 3.188 3.189 long