Skip to content

Instantly share code, notes, and snippets.

@toptensoftware
Created September 24, 2016 03:24
Show Gist options
  • Save toptensoftware/597a7513e75d21d862d01e4d9496ad44 to your computer and use it in GitHub Desktop.
Save toptensoftware/597a7513e75d21d862d01e4d9496ad44 to your computer and use it in GitHub Desktop.
Protected Mode Access Checks
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