▲ | sgbeal 3 days ago | |||||||||||||||||||||||||||||||
> You can run the DLL in a "shim" subprocess that proxies function calls over IPC. That doesn't address the need of some DLLs to malloc() resources in the context of the applications linking to them. This problem _cannot_ be solved _generically_. Any solutions are extremely API-specific and impose restrictions on their users (the linking applications) which, if violated, will lead to Undefined Behavior. Edit: as an example of cases which must bind resources in the application's context: see the Classloading in C++ paper at <https://wanderinghorse.net/computing/papers/index.html#class...> (disclosure: i wrote that article). | ||||||||||||||||||||||||||||||||
▲ | LegionMammal978 3 days ago | parent | next [-] | |||||||||||||||||||||||||||||||
"Extremely" API-specific is a bit much. One way to do it would be to guard all DLL-implemented functions, and all access to DLL-associated resources, with a reference-counted token, or otherwise use a language-level mechanism (such as Rust's lifetimes) to ensure that all resources are dead by the time of closure. This would take some tedious wrapper-writing, but it's not so complex that it couldn't be done by a source generator or whatever. Of course, C/C++ applications written in the traditional model with static data everwhere would have difficulty not leaking tokens and holding the DLL open, but it's still far from impossible to write such a safe API. > That doesn't address the need of some DLLs to malloc() resources in the context of the applications linking to them. If there is a context boundary and really such a need, then the DLL can keep a list of all such resources, and destroy all those resources once closed. Access to them would similarly have to be protected by a token. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
▲ | 10000truths 3 days ago | parent | prev [-] | |||||||||||||||||||||||||||||||
True, it's application specific. The typical reason an application would need to load/unload DLLs cleanly and repeatedly (where the caveats of dlclose are in full force) is for a plugin system with hot-reload functionality. And for that use case, the expected API/ABI is known in advance, so the shim can be tailored for it. |