15.09.2012 16:03, Jacob Carlborg пишет:
On 2012-09-14 20:53, alex wrote:

The primary injection routine and how it works is not the problem - I
can successfully insert a MSVC++ Dll without any problems into a D
program. (I've used this https://github.com/jeffora/extemory library btw
- it's for c# :-))
Anyway, on a DLL built with dmc or dmd 1/2, the main program immediately
crashes or unloads the dll when returning false in the DllMain()

So how to insert a D DLL into a D program?

I don't know the status on Windows but in general D dynamic libraries
don't properly work. The problems are TLS, exception handing tables and
module infos. There might be other problems as well.


TLS is the problem on Windows 5.x (XP, Server 2003), not 6.x. D DLL will use incomplete ugly hacks to fix it and will be unable to unload because of hacks incompleteness. By the way I have created a complete hack version to solve TLS problems in XP forever for all programs independently of its source availability that injects itself into running process, fixes everything and injects itself to all it's children, etc. Sorry for such a long story about my just another project nobody needs.

Lets return to the toppic.

The common practice of DLL-s injection is creating a new thread in remote process and calling LoadLibrary from there but it is incorrect because: * it wastes resources (requires a copy of TLS local variables, calls of module thread local constructors (for D) and all loading DLL-s DllMains to attach new thread (and then to detach of course)) * injecting DLL's DllMain will be called not in main thread but the DLL may expect to be in main one * for D DLL it will just fail because of Digital Mars C runtime library (honestly I'm not sure here but everything looks like it is so)

Again, Digital Mars C runtime library is the problem for everything in D language including DLL-s.

--
Денис В. Шеломовский
Denis V. Shelomovskij

Reply via email to