[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Accessing guest kernel thread_info struct

From: Peter Maydell
Subject: Re: [Qemu-devel] Accessing guest kernel thread_info struct
Date: Mon, 20 Jul 2015 11:58:52 +0100

On 20 July 2015 at 11:43, Igor R <address@hidden> wrote:
> I need to access thread_info (linux kernel struct) of the guest from within
> qemu, when the guest is in kernel mode.
> To do this, I read the stack pointer and mask it with ~(stack_size - 1).
> This works with x86 and ARM, but doesn't seem to work with MIPS - the
> pointer points to something that doesn't look like thread_info.
> I get sp as follows: env->active_tc.gpr[29]

MIPS keeps the thread info pointer in a dedicated register.
To get this right for each architecture you need to look
at how the kernel implements current_thread_info().

For instance on ARM:

   return (struct thread_info *)
           (current_stack_pointer & ~(THREAD_SIZE - 1));

but on MIPS:
   return __current_thread_info;
   register struct thread_info *__current_thread_info __asm__("$28");

x86 doesn't use 'mask the stack pointer' either:
static inline struct thread_info *current_thread_info(void)
        return (struct thread_info *)(current_top_of_stack() - THREAD_SIZE);

where current_top_of_stack() is different for x86_64 and i386
but in both cases is reading a value from a per-CPU kernel variable.

If you're trying to do something the kernel does, it's usually
the case that the kernel has some kind of cross-platform
abstraction, and you can just search the kernel sources to find
out what the actual implementations for each architecture are.

-- PMM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]