From: Peter Dinda Date: Thu, 18 Jun 2015 21:59:05 +0000 (-0500) Subject: Guest mem gpa/gva memset functions X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=31281ec866f7244baf965402aebc8e26046b43e0;p=palacios.git Guest mem gpa/gva memset functions --- diff --git a/palacios/include/palacios/vm_guest_mem.h b/palacios/include/palacios/vm_guest_mem.h index 7c0dbcf..fb98f69 100644 --- a/palacios/include/palacios/vm_guest_mem.h +++ b/palacios/include/palacios/vm_guest_mem.h @@ -109,6 +109,8 @@ int v3_read_gva_memory(struct guest_info * guest_info, addr_t guest_va, int coun 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); +int v3_set_gpa_memory(struct guest_info * guest_info, addr_t guest_pa, int count, uint8_t src); +int v3_set_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 e2729b9..9c7703e 100644 --- a/palacios/src/palacios/vm_guest_mem.c +++ b/palacios/src/palacios/vm_guest_mem.c @@ -430,6 +430,37 @@ int v3_write_gva_memory(struct guest_info * guest_info, addr_t gva, int count, u return bytes_written; } +int v3_set_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(guest_info->vm_info, guest_info, "Invalid GVA(%p)->HVA lookup\n", (void *)cursor); + return bytes_written; + } + + + + memset((void*)host_addr, + src, + bytes_to_copy); + + bytes_written += bytes_to_copy; + count -= bytes_to_copy; + cursor += bytes_to_copy; + } + + return bytes_written; +} + @@ -460,3 +491,28 @@ int v3_write_gpa_memory(struct guest_info * guest_info, addr_t gpa, int count, u return bytes_written; } + +int v3_set_gpa_memory(struct guest_info * guest_info, addr_t gpa, int count, uchar_t src) { + addr_t cursor = gpa; + 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; + + if (v3_gpa_to_hva(guest_info, cursor, &host_addr) != 0) { + return bytes_written; + } + + + memset((void*)host_addr, src, bytes_to_copy); + + bytes_written += bytes_to_copy; + count -= bytes_to_copy; + cursor += bytes_to_copy; + } + + return bytes_written; +} +