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 1, Linux 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 ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.