Coder's Guild Mailing List

Re: Write permission in x86 PMode

Posted by Jes Rahbek Klinke on 1999-03-23

>Date:  Mon, 22 Mar 1999 10:47:43 +01d0
>From:  "Sigrist Bernhard Gossau" <null@xxxx.xx>
>Subject:   Re: Write permission in x86 PMode
>
>>>Write to it, if your program crashes, you don't!
>Heheh, that's the current state. But (as you might have suspected) =
thats not very user-friendly 8-)
>>>[...]
>>>What exactly is the situtation.
>
>I have a Win32 app where I get a pointer to a data buffer (=3Dlogical =
address). The problem is, at runtime I don't know how large that buffer =
is (it can even be 0). What I want to do is check if I may write a byte, =
then write it, check the next one and so on. AFAIK there's am ASM =
instruction for that type of checking, but I don't remember it. Help =
would be greatly appreciated. ASM would be just fine, API calls are =
okay.

I do not think there could be an instruction for this kind of job, =
because the CPU cannot tell the difference between a page to which you =
have no rights and a page which is temporarily swapped to the disk. Both =
of them will be marked as inaccessible in some way. If you try to read =
or write to any of them, the CPU will trap to the OS, which either =
terminates the application with a protection fault, or swaps the =
required page back in memory and re-executes the offending instruction.
In my point of view, only the OS can tell you, whether or not you have =
rights to a given address.
Also I do not think the other suggestions about LDT and GDT will work in =
Win32. As far as I know this belongs to Windows 3.x, DPMI or other =
16-bit protected mode environments. In Win32 I think it all goes on in =
one big segment, which covers the entire 32-bit addressing space.
Enough reasons why it cannot be done. I am using Delphi and I have =
noticed that whenever I violate the memory protection Delphi comes up =
with a dialog saying that my application has raised some exception. My =
point is that it is possible for my application to catch this exception =
if I add a try ... except block. Even if you do not use Delphi, I think =
this proves that it is possible to trap memory access violations =