NIF calls to enif_fprintf causing segfaults on Windows

Brett Hemes brhemes@REDACTED
Tue Jul 27 15:25:49 CEST 2021


Interesting...  so I put together a Windows native make file to use cl.exe (vs gcc) from within a Visual Studio developer prompt and in this scenario the segfaults are gone but I don’t get any output to the terminal at all.

Brett

From: Jaka Bac <jakabac@REDACTED>
Sent: Tuesday, July 27, 2021 6:32 AM
To: Brett Hemes <brhemes@REDACTED>
Cc: erlang-questions@REDACTED
Subject: [EXTERNAL] Re: NIF calls to enif_fprintf causing segfaults on Windows

Just thinking out loud...

Is the segfault a null pointer dereference?
It is possible that stdout is not what MinGW runtime expects it to be and is possibly null.
Windows Erlang is built by MSVC and it will run the MSVC CRT initialization code (which will set up stdout). Your NIF DLL is built by MinGW. And its CRT initialization possibly did not run or did not run correctly which in turn leaves the MinGW stdout undefined.

Jaka

On Mon, 26 Jul 2021 at 23:27, Brett Hemes <brhemes@REDACTED<mailto:brhemes@REDACTED>> wrote:
I have recently moved from a Linux environment to Windows and my NIFs that call `enif_fprintf` are causing segfaults.

A simple call such as `enif_fprintf(stdout, “Hello, world!\n”);` will cause issue.

My build setup is:
* Windows 10
* rebar3
* MSYS2 + MinGW 64-bit + gcc

I have tried in both `erl` and `werl` to the same effect as well as `stdout` and `stderr`...

Does anyone have any insight into what might be the issue?

Thanks,
Brett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210727/17eae544/attachment.htm>


More information about the erlang-questions mailing list