X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fgeekos%2Fvm_guest_mem.c;h=364dde4fc89b78a56aefa67cb82ed2d8b9153f56;hb=c7e3f043b6458083162e23e1a8adb7703fd06559;hp=2978ae7a4e3a90be78b41332855da2be7d7881f5;hpb=8cb3daaded0d8c80be801aa74493006b5a06999f;p=palacios-OLD.git diff --git a/palacios/src/geekos/vm_guest_mem.c b/palacios/src/geekos/vm_guest_mem.c index 2978ae7..364dde4 100644 --- a/palacios/src/geekos/vm_guest_mem.c +++ b/palacios/src/geekos/vm_guest_mem.c @@ -280,6 +280,7 @@ int host_va_to_guest_va(struct guest_info * guest_info, addr_t host_va, addr_t * */ int read_guest_va_memory(struct guest_info * guest_info, addr_t guest_va, int count, char * dest) { addr_t cursor = guest_va; + int bytes_read = 0; while (count > 0) { int dist_to_pg_edge = (PAGE_OFFSET(cursor) + PAGE_SIZE) - cursor; @@ -287,16 +288,17 @@ int read_guest_va_memory(struct guest_info * guest_info, addr_t guest_va, int co addr_t host_addr; if (guest_va_to_host_va(guest_info, cursor, &host_addr) != 0) { - return -1; + return bytes_read; } - memcpy(dest, (void*)cursor, bytes_to_copy); - + memcpy(dest + bytes_read, (void*)host_addr, bytes_to_copy); + + bytes_read += bytes_to_copy; count -= bytes_to_copy; cursor += bytes_to_copy; } - return 0; + return bytes_read; } @@ -309,6 +311,7 @@ int read_guest_va_memory(struct guest_info * guest_info, addr_t guest_va, int co */ int read_guest_pa_memory(struct guest_info * guest_info, addr_t guest_pa, int count, char * dest) { addr_t cursor = guest_pa; + int bytes_read = 0; while (count > 0) { int dist_to_pg_edge = (PAGE_OFFSET(cursor) + PAGE_SIZE) - cursor; @@ -316,15 +319,45 @@ int read_guest_pa_memory(struct guest_info * guest_info, addr_t guest_pa, int co addr_t host_addr; if (guest_pa_to_host_va(guest_info, cursor, &host_addr) != 0) { - return -1; + return bytes_read; } - memcpy(dest, (void*)cursor, bytes_to_copy); + memcpy(dest + bytes_read, (void*)host_addr, bytes_to_copy); + bytes_read += bytes_to_copy; count -= bytes_to_copy; cursor += bytes_to_copy; } - return 0; + return bytes_read; +} + + + + +/* This is a straight address conversion + copy, + * except for the tiny little issue of crossing page boundries..... + */ +int write_guest_pa_memory(struct guest_info * guest_info, addr_t guest_pa, int count, char * src) { + addr_t cursor = guest_pa; + int bytes_written = 0; + + while (count > 0) { + int dist_to_pg_edge = (PAGE_OFFSET(cursor) + PAGE_SIZE) - cursor; + int bytes_to_copy = (dist_to_pg_edge > count) ? count : dist_to_pg_edge; + addr_t host_addr; + + if (guest_pa_to_host_va(guest_info, cursor, &host_addr) != 0) { + 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; }