On 20 July 2015 at 11:43, Igor R <boost.li...@gmail.com> 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: http://lxr.free-electrons.com/source/arch/arm/include/asm/thread_info.h#L95 return (struct thread_info *) (current_stack_pointer & ~(THREAD_SIZE - 1)); but on MIPS: http://lxr.free-electrons.com/source/arch/mips/include/asm/thread_info.h#L55 return __current_thread_info; where 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. thanks -- PMM