-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Refactor process.cpp to eliminate vector dependency and shutdown race conditions #123074
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
Conversation
Co-authored-by: jkotas <[email protected]>
Co-authored-by: jkotas <[email protected]>
Co-authored-by: jkotas <[email protected]>
…additions Co-authored-by: jkotas <[email protected]>
Changed runtime bounds checks to _ASSERTE calls since MAX_ARGV_ENTRIES (32) is large enough that these conditions should never be true in practice. This matches the pattern used in NativeAOT's PalCreateDump.cpp. Co-authored-by: jkotas <[email protected]>
Moved the `argv[argc] = nullptr;` assignment outside the if/else block to eliminate duplication, as suggested by @jkotas. Co-authored-by: jkotas <[email protected]>
|
Tagging subscribers to this area: @steveisok, @dotnet/dotnet-diag |
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.
Pull request overview
This PR refactors the crash dump generation code in process.cpp to eliminate the dependency on std::vector and prevent race conditions during process shutdown. The vector's destructor can cause issues when invoked during shutdown, potentially leading to crashes or hangs.
Changes:
- Replaced
std::vector<const char*> g_argvCreateDumpwith fixed-size arrayconst char* g_argvCreateDump[MAX_ARGV_ENTRIES](32 entries) - Updated all related functions to use array indexing instead of vector operations
- Removed
#include <vector>dependency - Added compile-time assertions for bounds checking following the NativeAOT pattern
…NativeAOT with assert pattern - Added bounds check `&& argc < MAX_ARGV_ENTRIES` before processing siginfo in process.cpp - Changed NativeAOT PalCreateDump.cpp to use assert instead of runtime check, consistent with the pattern established in earlier review feedback Co-authored-by: jkotas <[email protected]>
Co-authored-by: Copilot <[email protected]>
Fixes potential crashes or hangs during process shutdown due to race conditions in vector destructor execution.
Noticed while reviewing #122989
Description
Replaced
std::vector<const char*> g_argvCreateDumpstatic variable with a fixed-size arrayconst char* g_argvCreateDump[MAX_ARGV_ENTRIES](32 entries) in both CoreCLR and NativeAOT implementations. The vector's destructor can cause race conditions during process shutdown, potentially leading to crashes or hangs.Changes:
const char* g_argvCreateDump[MAX_ARGV_ENTRIES]insrc/coreclr/pal/src/thread/process.cppPROCBuildCreateDumpCommandLineto use array indexing instead ofpush_back()PROCCreateCrashDumpIfEnabledto copy array elements manually and added bounds check for siginfo processingPAL_GenerateCoreDumpto use local fixed-size array#include <vector>dependency from process.cppsrc/coreclr/nativeaot/Runtime/unix/PalCreateDump.cppto use assert instead of runtime check for consistency_ASSERTEfor bounds checking instead of runtime checks, matching the established patternCustomer Impact
Prevents potential crashes or hangs during process shutdown due to race conditions in vector destructor execution, particularly in crash dump generation scenarios.
Regression
No. This addresses a pre-existing race condition.
Testing
CoreCLR and NativeAOT components build successfully with no errors or warnings. Asserts verify that array bounds are respected during development and testing.
Risk
Low. Changes are isolated to crash dump generation code path. Pattern is consistent between CoreCLR and NativeAOT implementations. Asserts will catch any programming errors during development while not adding runtime overhead in release builds.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.