From: Peter Dinda Date: Fri, 13 Apr 2012 23:27:24 +0000 (-0500) Subject: Add ability to write to gvas X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=8804b6f5dc0878407aa757d9596a96d774392582;p=palacios.git Add ability to write to gvas --- diff --git a/palacios/include/palacios/vm_guest_mem.h b/palacios/include/palacios/vm_guest_mem.h index db6a6a0..7c0dbcf 100644 --- a/palacios/include/palacios/vm_guest_mem.h +++ b/palacios/include/palacios/vm_guest_mem.h @@ -105,10 +105,10 @@ int v3_hva_to_gva(struct guest_info * guest_info, addr_t host_va, addr_t * gues -int v3_read_gva_memory(struct guest_info * guest_info, addr_t guest_va, int count, uchar_t * dest); -int v3_read_gpa_memory(struct guest_info * guest_info, addr_t guest_pa, int count, uchar_t * dest); -int v3_write_gpa_memory(struct guest_info * guest_info, addr_t guest_pa, int count, uchar_t * src); -// TODO int write_guest_va_memory(struct guest_info * guest_info, addr_t guest_va, int count, char * src); +int v3_read_gva_memory(struct guest_info * guest_info, addr_t guest_va, int count, uint8_t * dest); +int v3_read_gpa_memory(struct guest_info * guest_info, addr_t guest_pa, int count, uint8_t * dest); +int v3_write_gpa_memory(struct guest_info * guest_info, addr_t guest_pa, int count, uint8_t * src); +int v3_write_gva_memory(struct guest_info * guest_info, addr_t guest_va, int count, uint8_t * src); #endif // ! __V3VEE__ diff --git a/palacios/src/palacios/vm_guest_mem.c b/palacios/src/palacios/vm_guest_mem.c index 810be79..d05bd39 100644 --- a/palacios/src/palacios/vm_guest_mem.c +++ b/palacios/src/palacios/vm_guest_mem.c @@ -396,6 +396,41 @@ int v3_read_gpa_memory(struct guest_info * guest_info, addr_t gpa, int count, uc } +/* This clones v3_read_gva_memory + * We write only as far as page translations are available + */ +int v3_write_gva_memory(struct guest_info * guest_info, addr_t gva, int count, uchar_t * src) { + addr_t cursor = gva; + int bytes_written = 0; + + + + while (count > 0) { + int dist_to_pg_edge = (PAGE_ADDR(cursor) + PAGE_SIZE) - cursor; + int bytes_to_copy = (dist_to_pg_edge > count) ? count : dist_to_pg_edge; + addr_t host_addr = 0; + + + if (v3_gva_to_hva(guest_info, cursor, &host_addr) != 0) { + PrintDebug("Invalid GVA(%p)->HVA lookup\n", (void *)cursor); + return bytes_written; + } + + + + memcpy((void*)host_addr, + src + bytes_written, + bytes_to_copy); + + bytes_written += bytes_to_copy; + count -= bytes_to_copy; + cursor += bytes_to_copy; + } + + return bytes_written; +} + + /* This is a straight address conversion + copy,