Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ISA test #29

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions sdk/include/cheri.hh
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,95 @@ namespace CHERI
return this->contains(p) && this->contains(ps...);
}

/**
* Returns a new PermissionSet with the maximum permissions
* representable in the format that the hardware would use if asked to
* represent this PermissionSet. If `this` is representable it will
* return a superset but otherwise there is not necessarily any
* intersection!
*/
[[nodiscard]] constexpr PermissionSet get_max_format_perms() const
{
if (this->contains(Permission::Execute,
Permission::Load,
Permission::LoadStoreCapability))
{
// Executable format
return PermissionSet{Permission::Global,
Permission::Execute,
Permission::Load,
Permission::LoadStoreCapability,
Permission::LoadGlobal,
Permission::LoadMutable,
Permission::AccessSystemRegisters};
}
if (this->contains(Permission::Load,
Permission::Store,
Permission::LoadStoreCapability))
{
// cap-rw format
return PermissionSet{Permission::Global,
Permission::Load,
Permission::Store,
Permission::LoadStoreCapability,
Permission::LoadGlobal,
Permission::LoadMutable,
Permission::StoreLocal};
}
if (this->contains(Permission::Load,
Permission::LoadStoreCapability))
{
// cap-ro format
return PermissionSet{Permission::Global,
Permission::Load,
Permission::LoadStoreCapability,
Permission::LoadGlobal,
Permission::LoadMutable};
}
if (this->contains(Permission::Store,
Permission::LoadStoreCapability))
{
// cap-wo format
return PermissionSet{Permission::Global,
Permission::Store,
Permission::LoadStoreCapability};
}
if (this->contains(Permission::Store) ||
this->contains(Permission::Load))
{
// data-rw format
return PermissionSet{
Permission::Global, Permission::Load, Permission::Store};
}
// sealing format
return PermissionSet{Permission::Global,
Permission::Seal,
Permission::Unseal,
Permission::User0};
}

/**
* Returns a new PermissionSet that is the set of permissions that the
* hardware would return if asked to encode this PermissionSet by
* CAndPerms.
*
* The returned PermissionSet will always be a (possibly empty) subset
* of `this`.
*/
[[nodiscard]] constexpr PermissionSet to_representable() const
{
return this->get_max_format_perms() & (*this);
}

/**
* Returns whether this PermissionSet is exactly representable in the
* hardware encodings.
*/
[[nodiscard]] constexpr bool is_representable() const
{
return (*this) == this->to_representable();
}

/**
* Returns the raw permission mask as an integer containing a bitfield
* of permissions.
Expand Down Expand Up @@ -863,6 +952,14 @@ namespace CHERI
return false;
}

/**
* Clears the tag bit indicating whether this is a valid capability.
*/
void invalidate()
{
ptr = __builtin_cheri_tag_clear(ptr);
}

/**
* Return whether this is a sealed capability.
*/
Expand Down
6 changes: 2 additions & 4 deletions sdk/include/debug.hh
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ struct DebugFormatArgumentAdaptor<T>
{
__always_inline static DebugFormatArgument construct(T value)
{
return {reinterpret_cast<uintptr_t>(
static_cast<const volatile void *>(value)),
return {reinterpret_cast<uintptr_t>(value),
DebugFormatArgumentKind::DebugFormatArgumentPointer};
}
};
Expand All @@ -368,8 +367,7 @@ struct DebugFormatArgumentAdaptor<CHERI::Capability<T>>
__always_inline static DebugFormatArgument
construct(CHERI::Capability<T> value)
{
return {reinterpret_cast<uintptr_t>(
static_cast<const volatile void *>(value)),
return {reinterpret_cast<uintptr_t>(value.get()),
DebugFormatArgumentKind::DebugFormatArgumentPointer};
}
};
Expand Down
Loading
Loading