qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Hooking memory access in TCG
@ 2011-02-26 16:25 felix.matenaar@rwth-aachen
  2011-02-26 22:28 ` James Greensky
  0 siblings, 1 reply; 2+ messages in thread
From: felix.matenaar@rwth-aachen @ 2011-02-26 16:25 UTC (permalink / raw)
  To: qemu-devel

Hi *,

i am currently trying to trace guest memory access (i386-softmmu). tcg
README says tcg_gen_(st|ld)X_Y functions are responsible for memory
access. Now I've got the following code snippets in tcg-op.h:

/* representing all tcg_gen_st and tcg_gen_ld functions in README*/
static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2,
tcg_target_long offset)
{
    tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
    int sizemask = 0;
    sizemask |= tcg_gen_sizemask(0, 0, 0);
    sizemask |= tcg_gen_sizemask(1, 0, 0);
    sizemask |= tcg_gen_sizemask(2, 0, 0);
    tcg_gen_helper3(tcg_flx_debug, sizemask, ret, ret, arg2,
tcg_const_i32(offset));
}

static inline void tcg_gen_helper3(void *func, int sizemask, TCGv_i32 ret,
                                    TCGv_i32 a, TCGv_i32 b, TCGv_i32 c)
{
    TCGv_ptr fn;
    TCGArg args[3];
    fn = tcg_const_ptr((tcg_target_long)func);
    args[0] = GET_TCGV_I32(a);
    args[1] = GET_TCGV_I32(b);
    args[2] = GET_TCGV_I32(c);
    tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE, sizemask,
                  GET_TCGV_I32(ret), 3, args);
    tcg_temp_free_ptr(fn);
}

static inline int32_t tcg_flx_debug(int32_t arg1, int32_t arg2, int32_t
arg3){
    printf("reading 0x%x from 0x%x\n",arg1,arg2+arg3);
    return arg1;
}


tcg_flx_debug produces output which does not seem to look like what I
want. What confuses me is that e.g.
tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,ldt.selector))
in translate.c ends up in one of the functions I am trying to hook but
the second and the third argument obviously are not directly valid
base+offset addresses in the guest memory.

So how is this part working? What I would like to build is that on each
read/write to guest memory, an analysis function is triggered with
address and value.

Regards,
    Felix Matenaar

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] Hooking memory access in TCG
  2011-02-26 16:25 [Qemu-devel] Hooking memory access in TCG felix.matenaar@rwth-aachen
@ 2011-02-26 22:28 ` James Greensky
  0 siblings, 0 replies; 2+ messages in thread
From: James Greensky @ 2011-02-26 22:28 UTC (permalink / raw)
  To: felix.matenaar@rwth-aachen; +Cc: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2123 bytes --]

You want to hook the tcg_gen_qemu_ functions such as tcg_gen_qemu_ld8s in
tcg-op.h

Jim

On Sat, Feb 26, 2011 at 8:25 AM, felix.matenaar@rwth-aachen <
felix.matenaar@rwth-aachen.de> wrote:

> Hi *,
>
> i am currently trying to trace guest memory access (i386-softmmu). tcg
> README says tcg_gen_(st|ld)X_Y functions are responsible for memory
> access. Now I've got the following code snippets in tcg-op.h:
>
> /* representing all tcg_gen_st and tcg_gen_ld functions in README*/
> static inline void tcg_gen_ld8s_i32(TCGv_i32 ret, TCGv_ptr arg2,
> tcg_target_long offset)
> {
>    tcg_gen_ldst_op_i32(INDEX_op_ld8s_i32, ret, arg2, offset);
>    int sizemask = 0;
>    sizemask |= tcg_gen_sizemask(0, 0, 0);
>    sizemask |= tcg_gen_sizemask(1, 0, 0);
>    sizemask |= tcg_gen_sizemask(2, 0, 0);
>    tcg_gen_helper3(tcg_flx_debug, sizemask, ret, ret, arg2,
> tcg_const_i32(offset));
> }
>
> static inline void tcg_gen_helper3(void *func, int sizemask, TCGv_i32 ret,
>                                    TCGv_i32 a, TCGv_i32 b, TCGv_i32 c)
> {
>    TCGv_ptr fn;
>    TCGArg args[3];
>    fn = tcg_const_ptr((tcg_target_long)func);
>    args[0] = GET_TCGV_I32(a);
>    args[1] = GET_TCGV_I32(b);
>    args[2] = GET_TCGV_I32(c);
>    tcg_gen_callN(&tcg_ctx, fn, TCG_CALL_CONST | TCG_CALL_PURE, sizemask,
>                  GET_TCGV_I32(ret), 3, args);
>    tcg_temp_free_ptr(fn);
> }
>
> static inline int32_t tcg_flx_debug(int32_t arg1, int32_t arg2, int32_t
> arg3){
>    printf("reading 0x%x from 0x%x\n",arg1,arg2+arg3);
>    return arg1;
> }
>
>
> tcg_flx_debug produces output which does not seem to look like what I
> want. What confuses me is that e.g.
> tcg_gen_ld32u_tl(cpu_T[0], cpu_env, offsetof(CPUX86State,ldt.selector))
> in translate.c ends up in one of the functions I am trying to hook but
> the second and the third argument obviously are not directly valid
> base+offset addresses in the guest memory.
>
> So how is this part working? What I would like to build is that on each
> read/write to guest memory, an analysis function is triggered with
> address and value.
>
> Regards,
>     Felix Matenaar
>
>

[-- Attachment #2: Type: text/html, Size: 3058 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-02-26 22:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-26 16:25 [Qemu-devel] Hooking memory access in TCG felix.matenaar@rwth-aachen
2011-02-26 22:28 ` James Greensky

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).