This repository was archived by the owner on Oct 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 411
Handle page protection errors as D errors on Linux with --DRT-memoryError=1 #2249
Closed
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| Page protection error handling can now be registered via `--DRT-memoryError=1` | ||
|
|
||
| In environments where attaching a debugger or retrieving a core dump isn't possible or hard, | ||
| on Linux x86_64 one has always been able to attach druntime's memory handler: | ||
|
|
||
| --- | ||
| shared static this() | ||
| { | ||
| import etc.linux.memoryerror : registerMemoryErrorHandler; | ||
| registerMemoryErrorHandler; | ||
| } | ||
|
|
||
| void main() { | ||
| int* ptr = null; | ||
| (*ptr)++; | ||
| } | ||
| --- | ||
|
|
||
| And thus retrieved the full segfault as D `Error` on the command-line: | ||
|
|
||
| $(CONSOLE dmd -g -run test.d | ||
| etc.linux.memoryerror.NullPointerError@src/etc/linux/memoryerror.d(325) | ||
| $(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH) | ||
| ??:? void etc.linux.memoryerror.sigsegvUserspaceProcess(void*) [0x8353df09] | ||
| ??:? void etc.linux.memoryerror.sigsegvDataHandler() [0x8353de4a] | ||
| test.d:9 _Dmain [0x8353c2b5] | ||
| ) | ||
|
|
||
| With this release, instead of recompiling the binary and adding the `registerMemoryError`, | ||
| one can use the runtime flag `--DRT-memoryError=1` to activate druntime's memory error handling. | ||
|
|
||
| $(CONSOLE dmd -g test.d && ./test --DRT-memoryError=1 | ||
| etc.linux.memoryerror.NullPointerError@src/etc/linux/memoryerror.d(325) | ||
| $(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH)$(NDASH) | ||
| ??:? void etc.linux.memoryerror.sigsegvUserspaceProcess(void*) [0x8353df09] | ||
| ??:? void etc.linux.memoryerror.sigsegvDataHandler() [0x8353de4a] | ||
| test.d:2 _Dmain [0x8353c2b5] | ||
| ) | ||
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| void main() { | ||
| int* ptr = null; | ||
| (*ptr)++; | ||
| } |
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.
The code in the
etc.linux.memoryerrormodule is defined for both 32 bit and 64 bit.