-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Dynamically allocate the alternate signal stack #10266
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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
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.
This can now return ENOMEM under two circumstances -- either the malloc failing or the sigaltstack call failing (and the latter should never happen since SIGSTKSZ should never be < MINSIGSTKSZ). That seems right.
Do we need to adjust the invocation of caml_setup_stack_overflow_detection() in otherlibs/systhreads/st_stubs.c:caml_thread_start to do something in the event of it returning -1?
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.
Perhaps... but I'm not sure what to do!
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.
How about doing this?
It prints a message and aborts the thread, but more importantly it does the same thing as any other out-of-memory error happening on that thread.
(If you're feeling particularly keen, you could also allocate the alt stack in the parent thread during
caml_thread_new
wherecaml_raise_out_of_memory()
is a reasonable thing to do and pass it down via thecaml_thread_t
. I'm not sure it's worth it, though)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.
If it was just the main thread, I'd advocate for 1. since a malloc failing so early in the runtime initialisation would either indicate a critical lack of resources (many other future mallocs will fail), or some external thing trying to manipulate a specific condition into occurring (e.g. some malware that might be chaining an attack that wants to turn off stack overflow detection). But this is now for all threads begun with caml_thread_start, so aborting the whole program seems extreme.
The problem with 2. is that it's quite non-deterministic -- I'd hope that I could determine at program startup time if stack overflow detection is available or not (if I understand your suggestion correctly that we turn off overflow detection for the particular thread where malloc fails).
Is there an option 3. where we could simply terminate a thread that attempts to turn on stack overflow detection but fails to do so? This would be extremely rare, but at least the failure to start the thread would be observable by the mutator and so could potentially be handled by the application as with any other reason why a system thread might fail to spawn.
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.
My comment was sent in parallel with @stedolan. Raising Out_of_memory seems ideal to me!
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.
These are nice suggestions, thanks @stedolan! However,
caml_exn_Out_of_memory
exists only in native code and is not exported... So, this would need some refactoring.I'm going to table this issue for later work. There are other, more urgent changes in this department, such as freeing the alternate stack when the thread terminates. I'll address these issues later in a separate PR.
Right now, the code does exactly what it did before, i.e. ignore failures when setting up the alternate signal stack in a new thread. So there is no regression, and improvements will come later.