Skip to content

Commit

Permalink
implement w^x
Browse files Browse the repository at this point in the history
  • Loading branch information
noahw2021 committed Dec 26, 2023
1 parent 1ae45b3 commit 3f5dcba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Binary file not shown.
4 changes: 2 additions & 2 deletions plasm2_emu/cpu/mmu/mmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ typedef struct _MMU_CTX {
union {
WORD64 Permissions;
struct {
WORD64 Execute : 1;
WORD64 Secure : 1;
WORD64 Selector : 1; // 0 = W, 1 = X
WORD64 Read : 1;
WORD64 Write : 1;
WORD64 Active : 1;
};
};
Expand Down
14 changes: 10 additions & 4 deletions plasm2_emu/cpu/mmu/mmu_virt.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ WORD64 MmuTranslate(WORD64 VirtualAddress, BYTE Reason, WORD64 MaxSize) {
if (!(EmuCtx->Flags & EMUFLAG_NOSECURE)) {
if ((Reason & REASON_READ) && !MmuCtx->Pages[p].Read)
return 0;
if ((Reason & REASON_WRTE) && !MmuCtx->Pages[p].Write)
return 0;
if ((Reason & REASON_EXEC) && !MmuCtx->Pages[p].Execute)
return 0;
if ((Reason & (REASON_WRTE | REASON_EXEC))) {
if (!MmuCtx->Pages[p].Secure)
return 0;

if (MmuCtx->Pages[p].Selector && (Reason & REASON_WRTE))
return 0;
if (!MmuCtx->Pages[p].Selector && (Reason & REASON_EXEC))
return 0;
}

if (MaxSize != SIZE_WATCHDOG) {
if (VirtualAddress + MaxSize >= (MmuCtx->Pages[p].Virtual + MmuCtx->Pages[p].Size))
return 0;
Expand Down

0 comments on commit 3f5dcba

Please sign in to comment.