Received: from [140.186.70.92] (port=58439 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6VXC-0002O1-Ib for qemu-devel@nongnu.org; Sun, 03 Apr 2011 18:12:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q6VXB-0004mP-Cp for qemu-devel@nongnu.org; Sun, 03 Apr 2011 18:12:38 -0400 Received: from mta-2.ms.rz.rwth-aachen.de ([134.130.7.73]:56330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q6VXB-0004m1-69 for qemu-devel@nongnu.org; Sun, 03 Apr 2011 18:12:37 -0400 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; charset=ISO-8859-1 Received: from ironport-out-1.rz.rwth-aachen.de ([134.130.5.40]) by mta-2.ms.rz.RWTH-Aachen.de (Sun Java(tm) System Messaging Server 6.3-7.04 (built Sep 26 2008)) with ESMTP id <0LJ300DCEKCY9UH0@mta-2.ms.rz.RWTH-Aachen.de> for qemu-devel@nongnu.org; Mon, 04 Apr 2011 00:12:34 +0200 (CEST) Received: from [172.23.23.190] ([unknown] [87.79.236.180]) by relay-auth-1.ms.rz.rwth-aachen.de (Sun Java(tm) System Messaging Server 7.0-3.01 64bit (built Dec 9 2008)) with ESMTPA id <0LJ3002EYKCYD870@relay-auth-1.ms.rz.rwth-aachen.de> for qemu-devel@nongnu.org; Mon, 04 Apr 2011 00:12:34 +0200 (CEST) Message-id: <4D98F0D3.9040705@rwth-aachen.de> Date: Mon, 04 Apr 2011 00:12:35 +0200 From: "felix.matenaar@rwth-aachen" Subject: [Qemu-devel] Memory Access Hooking Howto List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Hi, since some people independently asked me if I got memory access tracing working, here is how one can do it for the archive: I did this on a 64bit Host with a 32bit x86 Guest Patch tcg/tcg-op.h: tcg_gen_qemu_ld* functions are responsible to read from memory tcg_gen_qemu_st* functions are responsible to write to memory Arguments: Memory access functions have the arguments (ret/arg, addr, mem_index) , you can ignore mem_index in this use case and use ret/arg as the value to be read/written and addr as the address which will be accessed. Patch target-i386/translate.c Write your own memtrace_read/memtrace_write function in target-i386/translate.c and use gen_helper there to translate your hook. Call these functions from tcg/tcg-op.h Example: in tcg/tcg-op.h: static inline void tcg_gen_qemu_st8(TCGv arg, TCGv addr, int mem_index) { #if TARGET_LONG_BITS == 32 tcg_gen_op3i_i32(INDEX_op_qemu_st8, arg, addr, mem_index); #else tcg_gen_op4i_i32(INDEX_op_qemu_st8, TCGV_LOW(arg), TCGV_LOW(addr), TCGV_HIGH(addr), mem_index); #endif flx_memtrace_write(arg, addr, 8); // Custom function where the hook will be translated } in target-i386/translate.c: void flx_memtrace_write(TCGv arg, TCGv addr, uint8_t size){ gen_helper_flx_memtrace_write(arg, addr, tcg_const_i32(size)); } in target-i386/helper.h: DEF_HELPER_3(flx_memtrace_write, void, i64, i64, i32) in target-i386/op_helper.c: void helper_flx_memtrace_write(uint64_t value, uint64_t address, uint32_t size){ // so sth. with the write event... } I hope this will help everyone which wants to do that in the future. Regards, Felix