flat assembler
Message board for the users of flat assembler.
Index
> Main > Access Violation problem |
Author |
|
alexfru 03 Dec 2017, 04:04
Writing to memory through a code segment selector is not allowed. Why is there the CS segment prefix?
|
|||
03 Dec 2017, 04:04 |
|
DarkLordTed 03 Dec 2017, 11:16
Is this really true? In real mode this is not a problem. Also why can set section '.code' to writeable when is not possible to write into it? Is it possible to set ES = CS and then mov byte [es:.m1+00000001h], (.a1 - .m1) + 02h
|
|||
03 Dec 2017, 11:16 |
|
revolution 03 Dec 2017, 11:51
In Windows in terms of addressing ranges CS == DS == ES always. You won't need any segment override prefixes unless you are doing something unusual with the TEB/PEB that uses FS.
You can't simply use "mov ds,cs" though, because in protected mode the actual values of CS and DS are different, but the scope of what they select is the same. |
|||
03 Dec 2017, 11:51 |
|
Tomasz Grysztar 03 Dec 2017, 13:34
DarkLordTed wrote: Is this really true? In real mode this is not a problem. The original protected mode, as introduced by 80286, had no paging and all the protections were defined per segment. In protected mode the value you loaded into segment register was called selector and it defined an index in the descriptor table where the detailed information on the segment was set up. It included not only the base address of the segment, but also the limit (which defined how large the segment was, enabling protection against accessing any bytes outside of the defined area) and the permissions. The selector that was set up for CS would allow to execute the bytes as instructions, but would not allow to modify them. The data selector, intended to put into DS or ES, would allow writing but not execution. Then 80386 came, and next to 32-bit addressing it also allowed paging, and setting up access permissions per page. This quickly led to the abandonment of segmentation, as you could set up all selectors to encompass entire flat 4 GiB addressing space and instead use page attributes to manage permissions on various area of memory. When you declare section with attributes like "writeable" or "executable" you are setting up permissions on the pages that make up the section. But in addition to that you still have an old-school selector in CS that defines a segment that can be used to execute, but not to write. However, since both CS and DS are defined to encompass an entire flat addressing space starting from 0, you can safely use DS instead of CS on the same address to access exactly the same area of memory but through a different selector, the one that would allow you to write. |
|||
03 Dec 2017, 13:34 |
|
DarkLordTed 03 Dec 2017, 14:05
Thank you to all of you, again!
|
|||
03 Dec 2017, 14:05 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.