From 8f111b64fedae174e32560e797bff019048a89fa Mon Sep 17 00:00:00 2001 From: Jonathan Woodruff Date: Thu, 6 Feb 2020 11:01:36 +0000 Subject: [PATCH] Add SetAddrUnsafe function to the typeclass to support proper bounds checking for PCC. --- CHERICC_Fat.bsv | 9 +++++++++ CHERICap.bsv | 10 ++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHERICC_Fat.bsv b/CHERICC_Fat.bsv index f24acbb..26658e6 100644 --- a/CHERICC_Fat.bsv +++ b/CHERICC_Fat.bsv @@ -870,6 +870,7 @@ instance CHERICap #(CapMem, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); function setType = error("feature not implemented for this cap type"); function getAddr = error("feature not implemented for this cap type"); function setAddr = error("feature not implemented for this cap type"); + function setAddrUnsafe = error("feature not implemented for this cap type"); function getOffset = error("feature not implemented for this cap type"); function modifyOffset = error("feature not implemented for this cap type"); function getBase = error("feature not implemented for this cap type"); @@ -983,6 +984,7 @@ instance CHERICap #(CapReg, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); function getAddr (cap) = truncate(getAddress(cap)); function setAddr = error("feature not implemented for this cap type"); + function setAddrUnsafe = error("feature not implemented for this cap type"); function getOffset = error("feature not implemented for this cap type"); function modifyOffset = error("feature not implemented for this cap type"); @@ -1110,6 +1112,13 @@ instance CHERICap #(CapPipe, OTypeW, FlagsW, CapAddressW, CapW, TSub#(MW, 3)); cap.tempFields = getTempFields(cap.capFat); return Exact {exact: result.v, value: cap}; endfunction + + function CapPipe setAddrUnsafe (CapPipe cap, Bit#(CapAddressW) address); + let result = setCapPointer(cap.capFat, zeroExtend(address)); + cap.capFat = result; + cap.tempFields = getTempFields(cap.capFat); + return cap; + endfunction function getOffset (x) = getOffsetFat(x.capFat, x.tempFields); diff --git a/CHERICap.bsv b/CHERICap.bsv index e2ed483..5fcf36e 100644 --- a/CHERICap.bsv +++ b/CHERICap.bsv @@ -120,17 +120,19 @@ typeclass CHERICap#(type t, numeric type ot, numeric type flg, numeric type n, n // Get the address pointed to by the capability function Bit#(n) getAddr (t cap); - // Set the address of the capability. Result invalid if not exact + // Set the address of the capability. Result invalid if unrepresentable function Exact#(t) setAddr (t cap, Bit#(n) addr); + // Set the address of the capability. Result assumed to be representable + function t setAddrUnsafe (t cap, Bit#(n) addr); // Get the offset of the capability function Bit#(n) getOffset (t cap) = getAddr(cap) - getBase(cap); - // Modify the offset of the capability. Result invalid if not exact + // Modify the offset of the capability. Result invalid if unrepresentable function Exact#(t) modifyOffset (t cap, Bit#(n) offset, Bool doInc); - // Set the offset of the capability. Result invalid if not exact + // Set the offset of the capability. Result invalid if unrepresentable function Exact#(t) setOffset (t cap, Bit#(n) offset) = modifyOffset(cap, offset, False); - // Set the offset of the capability. Result invalid if not exact + // Set the offset of the capability. Result invalid if unrepresentable function Exact#(t) incOffset (t cap, Bit#(n) inc) = modifyOffset(cap, inc, True);