Re: lea with fs override




JC wrote:
I'd like to know, from userland, what base linear address my OS
(Windows XP) has set the FS segment (or GS, for that matter) to point
to.

I thought I could be clever, and do something like this (intel
syntax):

lea eax, fs:[0]

To figure this out. Unfortunately, LEA ignores segment overrides, and
I get back 0. Not helpful.

Is there another way to figure this out?


In user mode, FS will always point to the current thread's TIB.
There's a pointer in there (at FS:0x18) that points to the linear
address of the TIB. It does something similar in the kernel.

While not particularly documented, the GDT itself isn't that hard to
find (although it's moved around in different versions of Windows), and
you can usually search from there. Try 0x80036000, it might still be
there (that was correct for at least some versions of 2GB Win2K).

Also, you could just search your address space for a block of memory
matching what's at FS:0. To make that simpler, TIBs are always page
aligned, and on a system with 2GB of user address space, are allocated
starting a little below the 2GB line and going down (there's something
like 128KB of other stuff first, then the PEB, then the TIBs). Or at
least those were the locations for Win2K.

A kernel debugger like SoftIce will also let you get to that stuff.

The first option (the FS:0x18 pointer) is the only thing approximating
a stable interface.

The question is what you're trying to accomplish.

.



Relevant Pages

  • Re: Does Linux hog fs and gs registers?
    ... > disappointing that Windows reserves fs and gs for itself. ... There really isn't much reason to use the other segment registers. ... segmentation to allow Windows code to use FS as the TEB pointer without ...
    (comp.lang.asm.x86)
  • Re: newbie questions
    ... Windows XP (at least in the 32 bit ... The good old int21 interface provides anything you need and is ... but about which "16 bit registers" are you speaking? ... And any applications uses segment registers. ...
    (alt.lang.asm)
  • Re: Role of the code segment register during "far" CALLs
    ... I read some of your article from which i understood that Windows ... does'nt use call gates to implement intersegment calls. ... privilege level as the code segment of my "main" program. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Role of the code segment register during "far" CALLs
    ... I read some of your article from which i understood that Windows ... reading it to understand how intersegment far calls are made across ... privilege level as the code segment of my "main" program. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Joining (physically) 2 seperate domains
    ... bits of equipment belong to which segment (ie the physical wired connections ... >I have a windows xp user workgroup which access an application on a windows ... > I also have a business network running xp users in a windows 2000 ... I want to connect the 2 networks and share resources. ...
    (microsoft.public.windows.server.networking)