Is it possible to catch a segfault - using try/catch loop?
Thank you
Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 11, 2021 catching segfault using try_ catch | ||||
---|---|---|---|---|
| ||||
July 11, 2021 Re: catching segfault using try_ catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to seany | On Sunday, 11 July 2021 at 20:18:18 UTC, seany wrote: >Is it possible to catch a segfault - using try/catch loop? I know it's possible on Linux using the [1] https://druntime.dpldocs.info/etc.linux.memoryerror.html |
July 11, 2021 Re: catching segfault using try_ catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Sunday, 11 July 2021 at 21:15:30 UTC, Paul Backus wrote: >I know it's possible on Linux using the With -m32, it just works. With -m32mscoff I'm not sure. With -m64, as far as I know, there is no way. |
July 11, 2021 Re: catching segfault using try_ catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D Ruppe | On Sunday, 11 July 2021 at 21:15:30 UTC, Paul Backus wrote: >I know it's possible on Linux using the Linux would be sufficient. |
July 12, 2021 Re: catching segfault using try_ catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to seany | On Sunday, 11 July 2021 at 23:34:38 UTC, seany wrote: >Is there an example i can use Thank you. You just call the registerMemoryHandler() function from that module at some point in your main function before doing other work. |
July 13, 2021 Re: catching segfault using try_ catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D Ruppe | On Monday, 12 July 2021 at 00:04:05 UTC, Adam D Ruppe wrote: >On Sunday, 11 July 2021 at 23:34:38 UTC, seany wrote: >Is there an example i can use Thank you. You just call the registerMemoryHandler() function from that module at some point in your main function before doing other work. OK Here, the source says that function is undocumented. What will it return to me? I want to catch the segfault and a segfault has occured, I want run a different code at that point. |
July 13, 2021 Re: catching segfault using try_ catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D Ruppe | On Monday, 12 July 2021 at 00:04:05 UTC, Adam D Ruppe wrote: >On Sunday, 11 July 2021 at 23:34:38 UTC, seany wrote: >Is there an example i can use Thank you. You just call the registerMemoryHandler() function from that module at some point in your main function before doing other work. PS will the function will work with LDC / LLVM based compiler? |
July 13, 2021 Re: catching segfault using try_ catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to seany | On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote: >What will it return to me? true if it succeeded. >I want to catch the segfault and a segfault has occured, I want run a different code at that point. You mean transparently rerun some code? That's better done with the lowlevel sigaction handler. But if you just want to standard try/catch then do something in the catch block, this is fine. import etc.linux.memoryerror; void main() { It can be used on ldc2 too but it isn't as reliable since ldc considers null access to be undefined behavior anyway and thus may optimize out your catch.... You also need to compile in the module with ldc so build it like $ ldc2 seg.d ~/d/ldc/import/etc/linux/memoryerror.d just including the memoryerror file o the command line lets it link. |
July 14, 2021 Re: catching segfault using try_ catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D Ruppe | On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote: >On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote: >[...] true if it succeeded. >[...] You mean transparently rerun some code? That's better done with the lowlevel sigaction handler. [...] Thank you. Is there a tutorial on the low level sigaction handlers you speak of? Thank oyu |
July 14, 2021 Re: catching segfault using try_ catch | ||||
---|---|---|---|---|
| ||||
Posted in reply to seany | On Wednesday, 14 July 2021 at 00:10:59 UTC, seany wrote: >On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote: >On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote: >[...] true if it succeeded. >[...] You mean transparently rerun some code? That's better done with the lowlevel sigaction handler. [...] Thank you. Is there a tutorial on the low level sigaction handlers you speak of? Thank oyu Try core.sys.posix.signal. kill provides a list of signals via kill -L. basically what you do, if I recall correctly (it's been a few years), is something like this:
|