Created
September 24, 2016 03:24
-
-
Save toptensoftware/597a7513e75d21d862d01e4d9496ad44 to your computer and use it in GitHub Desktop.
Protected Mode Access Checks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Selector | |
{ | |
public byte[] memory; | |
bool writable; | |
} | |
Selector[] _selectorTable; | |
public void WriteByte(ushort seg, ushort offset, byte value) | |
{ | |
try | |
{ | |
var sel = _selectorTable[seg >> 3]; | |
if (!sel.writable) | |
throw new Sharp86.GeneralProtectionFaultException(); | |
sel.memory[offset] = value; | |
} | |
catch (NullReferenceException) | |
{ | |
throw new Sharp86.SegmentNotPresentException(); | |
} | |
catch (IndexOutOfRangeException) | |
{ | |
throw new Sharp86.GeneralProtectionFaultException(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment