This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Q] Accessing fs:0 on x86 Linux?


Hi Pierre,



>    On that target, its rather easy, as the debugger and debuggee share the same local descriptors.
>   It should also be possible to do this on cygwin target.
> We would need to use GetThreadSelectorEntry
> win32 API function to get
> the linear base  address of the %fs selector.
>    This function is not called in current xwin32-nat.c code and this only works
> because win32 kernel does give a zero linear base address to the 
> ordinary code and data selector (value of %cs for code , %ds, %es and %ss for data selector).


True, but I'm more concerned about how to do this on Linux, since it 
uses a flat memory model.


> 
>    Regarding wine on linux, this really depends on how wine does set the %fs selector 
> base and size, I have no idea how this is done...


Here's the code from Wine which gets some %fs data for an i386 platform.

#if defined(__i386__) && defined(__GNUC__)
extern inline struct _TEB WINAPI *NtCurrentTeb(void);
extern inline struct _TEB WINAPI *NtCurrentTeb(void)
{
     struct _TEB *teb;
     __asm__(".byte 0x64\n\tmovl (0x18),%0" : "=r" (teb));
     return teb;
}
#else
extern struct _TEB WINAPI *NtCurrentTeb(void);
#endif

This is the corresponding disassembly from gdb:

0x400911e2 <task_start+18>:     mov    %fs:0x18,%esi

So basically it uses inline assembly to manually get fs data.

--Rob


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]