Author Topic: How do the segment registers work in Windows?  (Read 10835 times)

Offline ben321

  • Full Member
  • **
  • Posts: 185
How do the segment registers work in Windows?
« 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?
« Last Edit: April 03, 2016, 04:39:10 AM by ben321 »

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: How do the segment registers work in Windows?
« Reply #1 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).

About Bryant Keller
bkeller@about.me

Offline jackjps

  • Jr. Member
  • *
  • Posts: 60
Re: How do the segment registers work in Windows?
« Reply #2 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.

Offline Bryant Keller

  • Forum Moderator
  • Full Member
  • *****
  • Posts: 360
  • Country: us
    • About Bryant Keller
Re: How do the segment registers work in Windows?
« Reply #3 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
A Crash Course on the Depths of Win32™ Structured Exception Handling by Matt Pietrek
Thread Environment Block structure from Undocumented functions of NTDLL


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:
  • Use a different forum and
  • Use a different assembler?

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

About Bryant Keller
bkeller@about.me