[erlang-questions] Nif and driver callbacks

Sverker Eriksson sverker@REDACTED
Thu May 23 20:42:37 CEST 2019

On tor, 2019-05-23 at 15:54 +0200, Mikael Karlsson wrote:
> Hi,
> I just started to write some nif code to interface towards a Linux driver API.
> I can install a callback function in my nif module that gets called from the
> driver  whenever it is ready to receive new data. Currently it gets called
> every 5 ms. The callback function sends a message to an erlang process that in
> turn delivers new data to the driver. (Using another nif function).
> This works, although I am a bit puzzled how, since the callback function that
> is called from the linux driver appearantly is running outside the Erlang VM
> and still is able to send a message to the erlang process. Could anyone
> explain how this works?

If your callback function calls enif_send to send the message and the message
arrives, then apparently it's running within the Erlang VM.

If in doubt:
1. Enable core dump generation (ulimit -c, /proc/sys/kernel/core_pattern, etc).
2. Put a call to abort() in your callback.
3. Run and watch your beam.smp crash.
4. Do post mortem with "gdb beam.smp <core-dump>"
5. Use 'backtrace' command to see who is calling you.


More information about the erlang-questions mailing list