1 /* 2 * Helper routines to provide target memory access for semihosting 3 * syscalls in system emulation mode. 4 * 5 * Copyright (c) 2007 CodeSourcery. 6 * 7 * This code is licensed under the GPL 8 */ 9 10 #include "qemu/osdep.h" 11 #include "semihosting/softmmu-uaccess.h" 12 13 void *softmmu_lock_user(CPUArchState *env, target_ulong addr, 14 target_ulong len, bool copy) 15 { 16 void *p = malloc(len); 17 if (p && copy) { 18 if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { 19 free(p); 20 p = NULL; 21 } 22 } 23 return p; 24 } 25 26 char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) 27 { 28 /* TODO: Make this something that isn't fixed size. */ 29 char *s = malloc(1024); 30 size_t len = 0; 31 32 if (!s) { 33 return NULL; 34 } 35 do { 36 if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { 37 free(s); 38 return NULL; 39 } 40 } while (s[len++]); 41 return s; 42 } 43 44 void softmmu_unlock_user(CPUArchState *env, void *p, 45 target_ulong addr, target_ulong len) 46 { 47 if (len) { 48 cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1); 49 } 50 free(p); 51 } 52