-/* $Id: utils.c,v 1.69 2003/07/27 11:39:18 ekohl Exp $
+/* $Id: utils.c,v 1.70 2003/07/27 14:00:04 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
PLDR_MODULE Module;
Module = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof (LDR_MODULE));
assert(Module);
+ memset(Module, 0, sizeof(LDR_MODULE));
Module->BaseAddress = (PVOID)ImageBase;
Module->EntryPoint = NTHeaders->OptionalHeader.AddressOfEntryPoint;
if (Module->EntryPoint != 0)
wcsrchr(FullDosName, L'\\') + 1);
DPRINT ("BaseDllName %wZ\n", &Module->BaseDllName);
- /* FIXME: aquire loader lock */
+ RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
InsertTailList(&NtCurrentPeb()->Ldr->InLoadOrderModuleList,
&Module->InLoadOrderModuleList);
InsertTailList(&NtCurrentPeb()->Ldr->InInitializationOrderModuleList,
&Module->InInitializationOrderModuleList);
- /* FIXME: release loader lock */
+ RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
return(Module);
}
if (LdrFindEntryForName(&AdjustedName, &Module) == STATUS_SUCCESS)
{
DPRINT("DLL %wZ already loaded.\n", &AdjustedName);
- if (Module->LoadCount != -1)
- Module->LoadCount++;
*BaseAddress = Module->BaseAddress;
return STATUS_SUCCESS;
}
if (NtCurrentPeb()->Ldr == NULL)
return(STATUS_NO_MORE_ENTRIES);
+ RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
Entry = ModuleListHead->Flink;
if (Entry == ModuleListHead)
- return(STATUS_NO_MORE_ENTRIES);
+ {
+ RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
+ return(STATUS_NO_MORE_ENTRIES);
+ }
while (Entry != ModuleListHead)
{
(Address <= (ModulePtr->BaseAddress + ModulePtr->SizeOfImage)))
{
*Module = ModulePtr;
+ RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
return(STATUS_SUCCESS);
}
DPRINT("Failed to find module entry.\n");
+ RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
return(STATUS_NO_MORE_ENTRIES);
}
if (NtCurrentPeb()->Ldr == NULL)
return(STATUS_NO_MORE_ENTRIES);
+ RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
Entry = ModuleListHead->Flink;
if (Entry == ModuleListHead)
- return(STATUS_NO_MORE_ENTRIES);
+ {
+ RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
+ return(STATUS_NO_MORE_ENTRIES);
+ }
// NULL is the current process
if (Name == NULL)
{
*Module = CONTAINING_RECORD(Entry, LDR_MODULE, InLoadOrderModuleList);
+ if ((*Module)->LoadCount != -1)
+ (*Module)->LoadCount++;
+
+ RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
return(STATUS_SUCCESS);
}
0 == RtlCompareUnicodeString(&ModulePtr->FullDllName, Name, TRUE)))
{
*Module = ModulePtr;
+ if (ModulePtr->LoadCount != -1)
+ ModulePtr->LoadCount++;
+ RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
return(STATUS_SUCCESS);
}
}
DPRINT("Failed to find dll %wZ\n", Name);
-
+ RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
return(STATUS_NO_MORE_ENTRIES);
}
ULONG MaxExtend;
ULONG LastOffset;
+ if (NTHeaders->FileHeader.Characteristics & IMAGE_FILE_RELOCS_STRIPPED)
+ {
+ return STATUS_UNSUCCESSFUL;
+ }
+
Sections =
(PIMAGE_SECTION_HEADER)((PVOID)NTHeaders + sizeof(IMAGE_NT_HEADERS));
MaxExtend = 0;
if (BaseAddress == NULL)
return STATUS_SUCCESS;
+ RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
+
ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
Entry = ModuleListHead->Flink;
if (Module->LoadCount == -1)
{
/* never unload this dll */
+ RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
return STATUS_SUCCESS;
}
else if (Module->LoadCount > 1)
{
Module->LoadCount--;
+ RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
return STATUS_SUCCESS;
}
ZwClose (Module->SectionHandle);
/* remove the module entry from the list */
- RtlFreeUnicodeString (&Module->FullDllName);
+ RemoveEntryList (&Module->InLoadOrderModuleList)
+ RemoveEntryList (&Module->InInitializationOrderModuleList);
+ RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
+
+ RtlFreeUnicodeString (&Module->FullDllName);
RtlFreeUnicodeString (&Module->BaseDllName);
- RemoveEntryList (Entry);
+
RtlFreeHeap (RtlGetProcessHeap (), 0, Module);
return Status;
Entry = Entry->Flink;
}
+ RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
DPRINT("NTDLL.LDR: Dll not found\n")
DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %x)\n", BaseAddress);
Status = STATUS_DLL_NOT_FOUND;
+ RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
Entry = ModuleListHead->Flink;
while (Entry != ModuleListHead) {
Module->Flags |= 0x00040000;
Status = STATUS_SUCCESS;
}
- return Status;
+ break;
}
Entry = Entry->Flink;
}
+ RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
return Status;
}
DPRINT("FullDllName %wZ\n", &FullDllName);
+ RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
Entry = ModuleListHead->Flink;
while (Entry != ModuleListHead) {
RtlFreeUnicodeString(&FullDllName);
*BaseAddress = Module->BaseAddress;
DPRINT("BaseAddress %x\n", *BaseAddress);
+ RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
return STATUS_SUCCESS;
}
Entry = Entry->Flink;
RtlFreeUnicodeString(&FullDllName);
*BaseAddress = NULL;
+ RtlLeaveCriticalSection (NtCurrentPeb()->LoaderLock);
return STATUS_DLL_NOT_FOUND;
}