Talk:Code segment

Unnamed section
"As a memory region, a code segment may be placed below the heap or stack in order to prevent heap and stack overflows from overwriting it."

Not too sure about the 'below' part. The stack is commonly implemented as 'upside-down' (pushing onto the stack reduces stack pointer register) so it would make more sense to have it in memory that is 'higher' than the stack. — Preceding unsigned comment added by 176.249.187.76 (talk) 13:35, 16 January 2014 (UTC)

The technique would be ineffective for the heap when memory addresses are decremented. Sam Tomato (talk) 21:59, 12 October 2016 (UTC)

In the reference paper it is described as follows. Because the stack is writable and executable (which is the main cause that stack based overflows are working at all) they are moving the stack section to a place higher than the code segment. See the original text below. (anyway the appropriate sentence should be changed to clarify this)

A fundamental reason for the stack buffer overflow is that the stack is executable, so the malicious code injected into the stack can be executed just like the valid code. To make the victim program's stack region non-executable, we relocate the stack region and modify the effective limit in code segment descriptor to exclude the stack region from valid code region. Supposed that U is the highest address of the user-mode applications' code region, the stack is relocated to the location higher than U, then the effective limit of code segment descriptor is set as U. Therefore, once the malicious code residing in the stack seizes the control of the process, a general-protection exception is generated due to exceeding the segment limit, the hijacking attempt will be terminated. — Preceding unsigned comment added by 2A02:8070:46CB:5700:1D70:6DB6:1319:FB1B (talk) 18:04, 25 October 2016 (UTC)

terminology
Why is the code segment also called the text segment? 118.208.38.118 (talk) 09:33, 12 March 2014 (UTC)

This article is very confusing. It mixes object files with processor memory and does not make it clear which is which.

To answer the question about code segments and text segments, a code segment is a type of text segment. In object files, the term "text segment" is very misleading; don't try to understand what text segments are based on that name. It would be more accurate to think of a text segment as a general-purpose type of data, of which executable code is one type. For the purpose of link-editing (the program that creates object files) executable code is just data that it does nothing to except copy from input to output. The linker might update addresses within the executable code but that is more commonly done by the operating system during execution. Sam Tomato (talk) 22:08, 12 October 2016 (UTC)