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

[cheriintrin.h] Avoid unnecessary truncate in cheri_perms_get() #674

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

arichardson
Copy link
Member

The intrinsic returns an i64 for 64-bit so we should use ptraddr_t
as the underlying type for cheri_perms_t.

In RV32 the return type of __builtin_cheri_type_get() is int since that is
what ptrdiff_t is by default. Use __PTRDIFF_TYPE__ instead of long an
re-generate the test checks.
The intrinsic returns an i64 for 64-bit so we should use `ptraddr_t`
as the underlying type for `cheri_perms_t`.
@arichardson arichardson requested a review from jrtc27 January 12, 2023 17:00
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wfixed-enum-extension"
/* Use __PTRADDR_TYPE__ as the underlying type to avoid unnecessary truncates */
typedef enum __attribute__((flag_enum, enum_extensibility(open))) : __PTRADDR_TYPE__ {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of this enum? Are we not better off with a list of #define CHERI_PERM_FOO (__CHERI_CAP_PERMISSION_FOO__)? We can make sure the preprocessor gives the latter the right type (or cast each one here, but that seems worse).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I can't remember why I originally made this an enum. Maybe to avoid redefinition warnings in CheriBSD?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That only works so long as cheriintrin.h is included before cherireg.h, which is the opposite of what style(9) says

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could also be that the reason was for nicer visualization in debuggers, but I'm not sure if that actually works.

@arichardson
Copy link
Member Author

Ping? I would prefer to keep the enum to reduce the amount of changes here. If you feel strongly that it should be a series of #defines instead that should IMO be a follow-up change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants