Implemented dll detach on process termination

svn path=/trunk/; revision=1332
This commit is contained in:
Eric Kohl 2000-09-05 11:01:03 +00:00
parent ed32877e90
commit 19e205fb97
4 changed files with 97 additions and 7 deletions

View file

@ -1,4 +1,4 @@
/* $Id: dllmain.c,v 1.13 2000/08/15 12:39:18 ekohl Exp $
/* $Id: dllmain.c,v 1.14 2000/09/05 10:59:27 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -22,6 +22,7 @@
extern UNICODE_STRING SystemDirectory;
extern UNICODE_STRING WindowsDirectory;
static WINBOOL DllInitialized = FALSE;
WINBOOL STDCALL DllMain (HANDLE hInst,
ULONG ul_reason_for_call,
@ -75,12 +76,23 @@ WINBOOL STDCALL DllMain(HANDLE hInst,
wcscpy (SystemDirectory.Buffer, WindowsDirectory.Buffer);
wcscat (SystemDirectory.Buffer, L"\\System32");
/* Insert more dll attach stuff here! */
DllInitialized = TRUE;
break;
}
case DLL_PROCESS_DETACH:
{
DPRINT("DLL_PROCESS_DETACH\n");
HeapDestroy(NtCurrentPeb()->ProcessHeap);
if (DllInitialized == TRUE)
{
RtlFreeUnicodeString (&SystemDirectory);
RtlFreeUnicodeString (&WindowsDirectory);
/* Insert more dll detach stuff here! */
}
break;
}
default:

View file

@ -1,4 +1,4 @@
/* $Id: proc.c,v 1.33 2000/06/29 23:35:26 dwelch Exp $
/* $Id: proc.c,v 1.34 2000/09/05 11:00:07 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -22,6 +22,7 @@
#include <napi/i386/segment.h>
#include <napi/teb.h>
#include <ntdll/csr.h>
#include <ntdll/ldr.h>
#define NDEBUG
@ -444,6 +445,11 @@ ExitProcess (
UINT uExitCode
)
{
/* unload all dll's */
LdrShutdownProcess ();
/* FIXME: notify csrss of process termination */
NtTerminateProcess (NtCurrentProcess (),
uExitCode);
}

View file

@ -1,4 +1,4 @@
/* $Id: startup.c,v 1.30 2000/09/01 17:05:09 ekohl Exp $
/* $Id: startup.c,v 1.31 2000/09/05 11:01:02 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -167,6 +167,8 @@ LdrInitializeThunk (ULONG Unknown1,
InsertTailList(&Peb->Ldr->InLoadOrderModuleList,
&NtModule->InLoadOrderModuleList);
InsertTailList(&Peb->Ldr->InInitializationOrderModuleList,
&NtModule->InInitializationOrderModuleList);
/* add entry for executable (becomes first list entry) */

View file

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.33 2000/09/04 19:05:03 ekohl Exp $
/* $Id: utils.c,v 1.34 2000/09/05 11:01:03 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -399,6 +399,8 @@ LdrLoadDll (IN PWSTR SearchPath OPTIONAL,
/* FIXME: aquire loader lock */
InsertTailList(&NtCurrentPeb()->Ldr->InLoadOrderModuleList,
&Module->InLoadOrderModuleList);
InsertTailList(&NtCurrentPeb()->Ldr->InInitializationOrderModuleList,
&Module->InInitializationOrderModuleList);
/* FIXME: release loader lock */
/* initialize dll */
@ -1530,7 +1532,41 @@ LdrGetProcedureAddress (IN PVOID BaseAddress,
NTSTATUS STDCALL
LdrShutdownProcess (VOID)
{
DPRINT1("LdrShutdownProcess() called\n");
PLIST_ENTRY ModuleListHead;
PLIST_ENTRY Entry;
PLDR_MODULE Module;
DPRINT("LdrShutdownProcess() called\n");
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
ModuleListHead = &NtCurrentPeb()->Ldr->InInitializationOrderModuleList;
Entry = ModuleListHead->Blink;
while (Entry != ModuleListHead)
{
Module = CONTAINING_RECORD(Entry, LDR_MODULE, InInitializationOrderModuleList);
DPRINT(" Unloading %wZ\n",
&Module->BaseDllName);
if (Module->EntryPoint != 0)
{
PDLLMAIN_FUNC Entrypoint = (PDLLMAIN_FUNC)Module->EntryPoint;
DPRINT("Calling entry point at 0x%08x\n", Entrypoint);
Entrypoint (Module->BaseAddress,
DLL_PROCESS_DETACH,
NULL);
}
Entry = Entry->Blink;
}
RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
DPRINT("LdrShutdownProcess() done\n");
return STATUS_SUCCESS;
}
@ -1538,7 +1574,41 @@ LdrShutdownProcess (VOID)
NTSTATUS STDCALL
LdrShutdownThread (VOID)
{
DPRINT1("LdrShutdownThread() called\n");
PLIST_ENTRY ModuleListHead;
PLIST_ENTRY Entry;
PLDR_MODULE Module;
DPRINT("LdrShutdownThread() called\n");
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
ModuleListHead = &NtCurrentPeb()->Ldr->InInitializationOrderModuleList;
Entry = ModuleListHead->Blink;
while (Entry != ModuleListHead)
{
Module = CONTAINING_RECORD(Entry, LDR_MODULE, InInitializationOrderModuleList);
DPRINT(" Unloading %wZ\n",
&Module->BaseDllName);
if (Module->EntryPoint != 0)
{
PDLLMAIN_FUNC Entrypoint = (PDLLMAIN_FUNC)Module->EntryPoint;
DPRINT("Calling entry point at 0x%08x\n", Entrypoint);
Entrypoint (Module->BaseAddress,
DLL_THREAD_DETACH,
NULL);
}
Entry = Entry->Blink;
}
RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
DPRINT("LdrShutdownThread() done\n");
return STATUS_SUCCESS;
}