This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: [Q] Accessing fs:0 on x86 Linux?
- From: Robert Baruch <autophile at starband dot net>
- To: Pierre Muller <muller at cerbere dot u-strasbg dot fr>
- Cc: gdb at sources dot redhat dot com, Eli Zaretskii <eliz at is dot elta dot co dot il>,Christopher Faylor <cgf at redhat dot com>
- Date: Fri, 14 Dec 2001 10:49:38 -0500
- Subject: Re: [Q] Accessing fs:0 on x86 Linux?
- References: <4.2.0.58.20011214092106.00aca8d8@ics.u-strasbg.fr>
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