ocaml / flexdll

a dlopen-like API for Windows
Other
97 stars 30 forks source link

Fix parallel access crashes and misbehavior #136

Closed jmid closed 1 week ago

jmid commented 2 months ago

Parallel usage is memory unsafe (read: may crash) as documented in #120, ocaml/ocaml#11607, and ocaml/ocaml#13046.

This PR goes for the simplest possible fix: adding a single global lock by dusting off the first commit of https://github.com/dra27/flexdll/tree/sledgehammer and suitable rebasing, renaming, and error handling. Author credit thus goes to @dra27 - any errors are mine.

For the error handling, I've tried to make it fit with @shym's TLS-based error handling from #112. I'm unsure how to test these error code paths though without explicitly mocking with the source code to create an invalid lock handle.

With the fix

(these have been tested under MinGW in a Cygwin-shell)

jmid commented 1 month ago

I've addressed the last minor comment, added a CHANGES entry, and rebased on master.

dra27 commented 1 week ago

Thank you both for your work on this, and sorry for taking quite so long to merge it!