[erlang-questions] How to track down intermittent segfaults in a threaded NIF

Igor Clark igor.clark@REDACTED
Tue May 29 22:15:47 CEST 2018


OK. Thanks very much Scott. I've got all this working using both those 
extra options, and it does seem to make the NIF crash a lot sooner than 
previously, which is great. But I'm still only seeing "process_main" in 
the crashed thread, so I'm not much closer to knowing where the illegal 
access is. I wonder if it's in lots of places because of what I'm doing 
with the callback and the thread. I hope not.

I'll do some more digging, and tomorrow I'll try out a debug emulator 
build as well.

Thanks very much for helping me get this far!

On 29/05/2018 16:31, Scott Ribe wrote:
>> On May 29, 2018, at 9:16 AM, Igor Clark <igor.clark@REDACTED> wrote:
>>
>> So, do I have this right: the point of the Guard Malloc is to make the crash happen at the time of allocation, rather than delayed until something trying to access it triggers the segfault; so if I get a crash while running like this, I should be able to just check in the Console debug log, and the stack trace should show where the bug actually is?
> At the time of the illegal access, not the allocation. Yes, that's the point, you get a stack trace showing you illegal access.
>
> However, the BEAM allocator will reduce its effectiveness. When you malloc in your C code, you get a block set up such that accessing just past it (or potentially before it) will cause an immediate crash. When you free it, it's then set up such that accessing will cause an immediate crash. But if you use Erlang's allocation routines, Erlang may malloc a bigger block with those protections, then hand out multiple suballocations, and access beyond the end of one of those can simply corrupt the next one without crashing at that point.
>
> You should also be using MallocScribble & MallocPreScribble.
>
>
>




More information about the erlang-questions mailing list