NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: ben321 on April 03, 2016, 04:34:20 AM

Title: How do the segment registers work in Windows?
Post by: ben321 on April 03, 2016, 04:34:20 AM
I know they don't actually point to segments like they do in DOS. Instead they represent indices to entries in a table somewhere, but where exactly in memory is this table? What address is it at?
Title: Re: How do the segment registers work in Windows?
Post by: Bryant Keller on April 03, 2016, 06:47:28 AM
I haven't used Windows in a long time, but IIRC it uses a flat memory model and segment registers all point at the start of the processes memory. This memory is virtually paged in and out as needed. I do remember that FS is used for exception handling. I hope that helps. If you need more information, you could try registering for MSDN and request a copy of the Windows Research Kernel source code. If you search around hard enough, you might actually find a copy laying around somewhere (although I think it's expressly against Microsoft's WRK use license to publish a copy of it, so do that at your own risk).
Title: Re: How do the segment registers work in Windows?
Post by: jackjps on April 03, 2016, 03:04:04 PM
My 2 cents worth.
Try the masm32 forum. Lots if good info there.
These days you should be using the flat assembler
and not messing with segments.
Title: Re: How do the segment registers work in Windows?
Post by: Bryant Keller on April 06, 2016, 03:09:29 AM
ben321,

I tend to avoid giving direct answers relating to windows because I've not used it since Win2kProSP2. That said, I'm going to make some assumptions here; I assume what you really are wanting to know about is the TEB and SEH. I make this assumption because (AFAIK) windows sets all other segment registers to 0 while operating in the flat memory model. That said, here is some information:

Win32 Exception handling for assembler programmers by Jeremy Gordon (http://www.godevtool.com/ExceptFrame.htm)
 A Crash Course on the Depths of Win32™ Structured Exception Handling by Matt Pietrek (https://www.microsoft.com/msj/0197/exception/exception.aspx)
Thread Environment Block structure from Undocumented functions of NTDLL (http://undocumented.ntinternals.net/index.html?page=UserMode%2FUndocumented%20Functions%2FNT%20Objects%2FThread%2FTEB.html)


My 2 cents worth.
Try the masm32 forum. Lots if good info there.
These days you should be using the flat assembler
and not messing with segments.

So your 2 cents sums up to:

If that's truly how you feel, then why are you here?