In which segments is the compiled C program used?

I read on the OSDev wiki that x86 architecture protected mode allows you to create separate segments for code and data, while you cannot write to a section of code. That Windows (yes, this is the platform) loads the new code into the code segment, and the data is created in the data segment. But, if so, as the program knows, should it switch segments into a data segment? If you understand this correctly, note that all instructions for the address point to the segment from which you run the code, unless you switch the descriptor. But I also read that such a compact model with flat memory allows you to run code and data in one segment. But I read it only in connection with the assembler. So please, what happens to the C compiled code on Windows? Thank.

+3
source share
2 answers

There are two values ​​for the segment in the explanation:

  • 8086 memory address segment
  • module section of the module program section

The first relates to what is loaded into the segment register 80386+; it contains the starting address of the physical memory, the length of the memory allocation, read / write / execute access is allowed, and whether it grows from low to high or vice versa (plus a few more obscure flags, for example, copy by link).

The second value is part of the language of the object module. Basically, there is a segment with a name code, a segment with a name data(which contains initialized data) and a segment for uninitialized data with a namebss ( - 1960- , Block Starting with Symbol). , , bss. , CPU ( ) , . CPU, . , , . . ( , , .)

x86 . , . CS, SS, , ESP EBP, DS. ES, FS GS , , movs cmps. , CS .

, , CPU ( ) , . (, CS), .

+2

, , . Windows 1993 32- . CS DS . - , . , flNewProtect API VirtualProtectEx().

API , .

+3

Source: https://habr.com/ru/post/1743723/


All Articles