Forked from Cauterite/dmd-frontend-dll-entrypoint.d
Created
September 1, 2016 16:25
-
-
Save rjmcguire/2e03147db2f49f26c1c9491ee2dd49a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -------------------------------------------------------------------------- */ | |
import Dll_ = core.sys.windows.dll; | |
import W32_ = core.sys.windows.windows; | |
/* -------------------------------------------------------------------------- */ | |
/* --- runtime initialisation --- */ | |
version (CRuntime_DigitalMars) {} else {static assert(0);}; | |
pragma(mangle, `__acrtused_dll`) extern __gshared void* CrtData; | |
pragma(startaddress, raw_entrypoint); | |
void raw_entrypoint() { | |
asm { | |
naked; | |
/* jump to _DllMainCRTStartup */ | |
lea EAX, CrtData; | |
mov EAX, [EAX + 12]; | |
sub EAX, 0x4e; | |
jmp EAX; | |
}; | |
}; | |
/* this will be called by _DllMainCRTStartup */ | |
pragma(mangle, `DllMain`) extern(Windows) int dll_entrypoint( | |
void* Inst, uint Reason, void* | |
) { | |
switch (Reason) { | |
case W32_.DLL_PROCESS_ATTACH : { | |
Dll_.dll_process_attach(Inst, true); | |
}; break; | |
case W32_.DLL_PROCESS_DETACH : { | |
Dll_.dll_process_detach(Inst, true); | |
}; break; | |
case W32_.DLL_THREAD_ATTACH : { | |
Dll_.dll_thread_attach( true, true); | |
}; break; | |
case W32_.DLL_THREAD_DETACH : { | |
Dll_.dll_thread_detach(true, true); | |
}; break; | |
default : break; | |
}; | |
return 1; | |
}; | |
/* -------------------------------------------------------------------------- */ | |
/+ | |
+/ | |
/* -------------------------------------------------------------------------- */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment