Text segment

Text is code: the actual opcodes and operands that make up the machine instructions that are fed to the CPU to consume. Readers may recall the objdump --source ./hello_dbg we did in Chapter 1Linux System Architecture, showing C code translated into assembly and machine language. This machine code resides within the process VAS in a segment called text. For example, let's say a program has 32 KB of text; when we run it, it becomes a process and the text segment takes 32 KB of virtual memory; that's 32K/4K = 8 (virtual) pages.

For optimization and protection, the OS marks, that is, protects, all these eight pages of text as read-execute (r-x). This makes sense: code will be read from memory and executed by the CPU, not written to it.

The text segment on Linux is always toward the low end of the process VAS. Note that it will never start at the 0x0 address.

As a typical example, on the IA-32, the text segment usually starts at 0x0804 8000. This is very arch-specific though  and changes in the presence of Linux security mechanisms like Address Space Layout Randomization (ASLR).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset