From: "felix.matenaar@rwth-aachen" <felix.matenaar@rwth-aachen.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] Memory Access Hooking Howto
Date: Mon, 04 Apr 2011 00:12:35 +0200 [thread overview]
Message-ID: <4D98F0D3.9040705@rwth-aachen.de> (raw)
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
reply other threads:[~2011-04-03 22:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D98F0D3.9040705@rwth-aachen.de \
--to=felix.matenaar@rwth-aachen.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).