-
Notifications
You must be signed in to change notification settings - Fork 20
fix dynamically built grate #1242
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
Open
qianxichen233
wants to merge
4
commits into
main
Choose a base branch
from
fix-grate-dylink
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
90da5f0
Enable grates to run under dynamic linking (shared build)
qianxichen233 40b8872
Reduce default grate worker stack to 1 MiB, make it env-configurable
qianxichen233 2443c15
memory tests: point invalid-access fault address above the grate stac…
qianxichen233 0d1e54f
grate tests: always build grates dynamically, drop --grate-build sele…
qianxichen233 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,14 +135,45 @@ pub const FPCAST_FUNC_SIGNATURE: &str = "$fpcast_emu$"; | |
| /// instance reserves the same number of worker stack slots in linear memory. | ||
| pub const MAX_GRATE_WORKERS: usize = 32; | ||
|
|
||
| /// Size in bytes of the usable stack region assigned to one grate worker. | ||
| /// Default size in bytes of the usable stack region assigned to one grate worker. | ||
| /// | ||
| /// Each worker executes in its own `Store + Instance` context, but workers may | ||
| /// still attach to the same underlying linear memory. Therefore, every worker | ||
| /// must be given a disjoint stack slot inside the shared stack arena. | ||
| /// | ||
| /// This constant specifies the usable portion of that per-worker slot. | ||
| pub const GRATE_STACK_SLOT_SIZE: u32 = 8 * 1024 * 1024; | ||
| /// must be given a disjoint stack slot inside the shared stack arena. This is the | ||
| /// usable portion of that per-worker slot. | ||
| /// | ||
| /// Grate workers only ever run grate *handler* code (syscall interposition), which | ||
| /// is shallow compared to arbitrary user programs, so the default is modest (1 MiB). | ||
| /// Override at runtime with the `LIND_GRATE_STACK_SIZE` environment variable; see | ||
| /// [`grate_stack_slot_size`]. | ||
| pub const DEFAULT_GRATE_STACK_SLOT_SIZE: u32 = 1024 * 1024; | ||
|
|
||
| /// Environment variable that overrides the per-worker grate stack slot size (bytes). | ||
| pub const GRATE_STACK_SIZE_ENV: &str = "LIND_GRATE_STACK_SIZE"; | ||
|
|
||
| static GRATE_STACK_SLOT_SIZE_CACHED: OnceLock<u32> = OnceLock::new(); | ||
|
|
||
| /// Per-worker grate stack slot size in bytes. | ||
| /// | ||
| /// Returns [`DEFAULT_GRATE_STACK_SLOT_SIZE`] (1 MiB) unless the `LIND_GRATE_STACK_SIZE` | ||
| /// environment variable is set to a positive integer number of bytes, in which case | ||
| /// that value (rounded up to a 4 KiB page) is used. | ||
| /// | ||
| /// The result is read from the environment once and cached for the process lifetime so | ||
| /// that every consumer agrees on the same arena geometry: the arena reservation in | ||
| /// `instance.rs` and the per-worker slot addressing in `lind-3i` must use the identical | ||
| /// value, otherwise worker stacks would not line up with the reserved region. | ||
| pub fn grate_stack_slot_size() -> u32 { | ||
| *GRATE_STACK_SLOT_SIZE_CACHED.get_or_init(|| { | ||
| std::env::var(GRATE_STACK_SIZE_ENV) | ||
| .ok() | ||
| .and_then(|v| v.trim().parse::<u32>().ok()) | ||
| .filter(|n| *n > 0) | ||
| // Keep slot boundaries page-aligned so the arena layout stays well-formed. | ||
| .map(|n| (n + 4095) & !4095) | ||
| .unwrap_or(DEFAULT_GRATE_STACK_SLOT_SIZE) | ||
| }) | ||
| } | ||
|
Comment on lines
+166
to
+176
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| /// Size in bytes of the guard region placed before each grate-worker stack slot. | ||
| /// | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if making this configurable through CLI makes more sense