-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Stack declarations for memory protection #3623
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
Comments
by Andrew Boie: Andy Gross Vincenzo Frascino Kumar Gala I have an API proposal more or less as follows, which will deprecate the existing __stack decorator:
The only caveat that users will need to be aware of is that they should not take sizeof() the symbol they define and expect it to match the size passed in. They should pass the defined stack symbol to k_thread_create() but otherwise not do anything to it. Now on x86 with MMU we have 4k pages. We can pursue some different strategies:
For #1, the definitions could look like this, we just increase the size of the stacks by 4K:
And then in x86's _new_thread, skip ahead the supplied stack buffer by 4096. For #2, we'd have a new RAM section "stacks" at either the very beginning of RAM, or immediately after a different section which is always read-only. The stacks would all get put in that section. There would be no guards, but on context switch, only the incoming thread's stack will be read-write, the rest read-only. The question is, is the above API definition workable for your needs? |
by Andrew Boie: Pull request with proposed implementation: |
Reported by Andrew Boie:
We need a good method for defining stack memory regions. Right now the typical way to do it is with __stack __noinit. We may need something more generic so that we can have fine, architecture-specific control on how the stacks are declared.
For example, on x86 all the stacks are going to need to be aligned to 4096 byte boundaries, AND any given stack area should be immediately preceded by some memory which cannot be written to by the current thread. So I think we will need to position all the stacks in between rodata (which can't be written to) and the data section.
Other arches have much less in the way of constraints on the alignment/size of stacks, but the general requirement is that if the thread attempts to write RAM immediately before the stack (i.e. it overflows) we get an exception.
(Imported from Jira ZEP-2185)
The text was updated successfully, but these errors were encountered: