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

Make cheriot_minimum_stack attribute parameter available within the function? #58

Open
nwf opened this issue Dec 11, 2024 · 5 comments
Open
Labels
good first issue Good for newcomers

Comments

@nwf
Copy link
Member

nwf commented Dec 11, 2024

If a function is decorated with __attribute__((cheri_minimum_stack(x))) (probably spelled __cheriot_minimum_stack(x)), it'd be nice if the value of x were available within the function body, so that we could feed it to the RAII-driven StackUsageCheck objects (probably via convenience macros) so that we didn't have to repeat it all over the place as we do now (see
here, for example, together with all the other uses of STACK_CHECK).

@resistor
Copy link
Collaborator

I think the easiest way to support this might be to add __builtin_cheri_get_minimum_stack(), which StackUsageCheck could then use instead of having to take an argument.

@resistor resistor added the good first issue Good for newcomers label Dec 12, 2024
@resistor
Copy link
Collaborator

I think the easiest way to support this might be to add __builtin_cheri_get_minimum_stack(), which StackUsageCheck could then use instead of having to take an argument.

Clarifying for myself: StackUsageCheck would need to capture it as a default argument value, so that it can capture the value from the calling function.

@v01dXYZ
Copy link

v01dXYZ commented Dec 18, 2024

I've got a hard time to find a builtin that is similar to the one you describe (return a const expr which is the value of an attribute of the current function). I think the biggest problem is to have a builtin that depends on the current function. Unfortunately, there is no way in C to have an identifier of the current function. One way to deal with that is preprocessor dirty hacks (override a MIN_STACK macro whom default value is a #error). Probably I didn't look hard enough...

@resistor
Copy link
Collaborator

@v01dXYZ The way I could do this is to add a builtin that codegen's to a constant zero (or maybe ~0) in any function that doesn't have the cheri_minimum_stack annotation, and codegen's to the specified size in a function that does have the attribute. By doing it entirely in codegen, you don't have to worry about introducing an identifier or anything.

@davidchisnall
Copy link

The __LINE__ macro and friends have this property.

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

No branches or pull requests

4 participants