Hi
I am reading an article about protected mode.
http://www.summitsoftconsulting.com/NtSystemCalls.htm
It says:
Since each code segment that exists in the system is described by a segment descriptor and since there are potentially many, many code segments in a system (each program may have many) the segment descriptors must be stored somewhere so that the CPU can read them in order to accept or deny access to a program that wishes to execute code in a segment.

I know that In PE file format there is only one Code Section entry. (about its, VA and Size)

So how can be more than one Code segment when a program execute?
Posted on 2007-10-22 12:00:29 by sawer
Quoting:

Since each code segment that exists in the system....

Note the term "system" which in here means the resources managed by the Operating System. When the Operating System is running, it normally has one Code Segment created for its own uses in the Global Descriptor Table (GDT). When the Operating System creates a process, it usually creates two Segment Descriptors for that process. Those are the Code and the Data Segment Descriptors although there could be other descriptors created per process and given to the process through DS, ES, GS and FS Segment Registers.

The Operating System could have lots of Code Segment Descriptors for its own uses and then simply switch the code segments which is really rare. What happens is that the Operating System creates some Segment Descriptors for its own use and then never modify them again. But whenever a process is created, it is given a separate User-Space Stack, Code Segment and Data Segment. To be able to change the Code Segment, you have to make a Long Jump. Since a sane operating system only creates one Code Segment per process, you will not be able to switch from segment to segment.
Posted on 2007-10-22 15:02:09 by XCHG
And well, there can be multiple .code sections in a PE file, if you so desire. The "size of code","base of code" fields in the PE header aren't really used for anything.

But only one set of code,data,stack segments are used for all running processes, since NT has a flat protected mode layout where protection is handled with paging.
Posted on 2007-10-23 03:50:48 by f0dder
OK.
Thanks for answers
Posted on 2007-10-23 04:20:10 by sawer