2002-03-10 00:29:33 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2002 Dmitry Timoshkov for Codeweavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2002-01-29 19:30:16 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnt.h"
|
2002-09-13 00:07:02 +02:00
|
|
|
#include "winternl.h"
|
2002-06-10 04:28:00 +02:00
|
|
|
|
|
|
|
#include "module.h"
|
2002-08-16 00:09:53 +02:00
|
|
|
#include "wine/exception.h"
|
|
|
|
#include "msvcrt/excpt.h"
|
2002-06-10 04:28:00 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
|
2002-01-29 19:30:16 +01:00
|
|
|
|
2002-08-16 00:09:53 +02:00
|
|
|
/* filter for page-fault exceptions */
|
|
|
|
static WINE_EXCEPTION_FILTER(page_fault)
|
|
|
|
{
|
|
|
|
if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-29 19:30:16 +01:00
|
|
|
NTSTATUS WINAPI LdrDisableThreadCalloutsForDll(HANDLE hModule)
|
|
|
|
{
|
|
|
|
if (DisableThreadLibraryCalls(hModule))
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
else
|
|
|
|
return STATUS_DLL_NOT_FOUND;
|
|
|
|
}
|
2002-06-10 04:28:00 +02:00
|
|
|
|
|
|
|
/* FIXME : MODULE_FindModule should depend on LdrGetDllHandle, not vice-versa */
|
|
|
|
|
|
|
|
NTSTATUS WINAPI LdrGetDllHandle(ULONG x, LONG y, PUNICODE_STRING name, PVOID *base)
|
|
|
|
{
|
|
|
|
STRING str;
|
|
|
|
WINE_MODREF *wm;
|
|
|
|
|
|
|
|
FIXME("%08lx %08lx %s %p : partial stub\n",x,y,debugstr_wn(name->Buffer,name->Length),base);
|
|
|
|
|
|
|
|
*base = 0;
|
|
|
|
|
|
|
|
RtlUnicodeStringToAnsiString(&str, name, TRUE);
|
|
|
|
wm = MODULE_FindModule(str.Buffer);
|
|
|
|
if(!wm)
|
|
|
|
return STATUS_DLL_NOT_FOUND;
|
|
|
|
*base = (PVOID) wm->module;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME : MODULE_GetProcAddress should depend on LdrGetProcedureAddress, not vice-versa */
|
|
|
|
|
|
|
|
NTSTATUS WINAPI LdrGetProcedureAddress(PVOID base, PANSI_STRING name, ULONG ord, PVOID *address)
|
|
|
|
{
|
|
|
|
WARN("%p %s %ld %p\n",base, debugstr_an(name->Buffer,name->Length), ord, address);
|
|
|
|
|
|
|
|
if(name)
|
2002-07-24 21:04:41 +02:00
|
|
|
*address = MODULE_GetProcAddress( (HMODULE) base, name->Buffer, -1, FALSE);
|
2002-06-10 04:28:00 +02:00
|
|
|
else
|
2002-07-24 21:04:41 +02:00
|
|
|
*address = MODULE_GetProcAddress( (HMODULE) base, (LPSTR) ord, -1, FALSE);
|
2002-06-10 04:28:00 +02:00
|
|
|
|
|
|
|
return (*address) ? STATUS_SUCCESS : STATUS_DLL_NOT_FOUND;
|
|
|
|
}
|
2002-08-09 21:57:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlImageNtHeader (NTDLL.@)
|
|
|
|
*/
|
|
|
|
PIMAGE_NT_HEADERS WINAPI RtlImageNtHeader(HMODULE hModule)
|
|
|
|
{
|
2002-08-16 00:09:53 +02:00
|
|
|
IMAGE_NT_HEADERS *ret;
|
2002-08-09 21:57:38 +02:00
|
|
|
|
2002-08-16 00:09:53 +02:00
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *)hModule;
|
|
|
|
|
|
|
|
ret = NULL;
|
|
|
|
if (dos->e_magic == IMAGE_DOS_SIGNATURE)
|
|
|
|
{
|
|
|
|
ret = (IMAGE_NT_HEADERS *)((char *)dos + dos->e_lfanew);
|
|
|
|
if (ret->Signature != IMAGE_NT_SIGNATURE) ret = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__EXCEPT(page_fault)
|
2002-08-09 21:57:38 +02:00
|
|
|
{
|
2002-08-16 00:09:53 +02:00
|
|
|
return NULL;
|
2002-08-09 21:57:38 +02:00
|
|
|
}
|
2002-08-16 00:09:53 +02:00
|
|
|
__ENDTRY
|
2002-08-09 21:57:38 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlImageDirectoryEntryToData (NTDLL.@)
|
|
|
|
*/
|
|
|
|
PVOID WINAPI RtlImageDirectoryEntryToData( HMODULE module, BOOL image, WORD dir, ULONG *size )
|
|
|
|
{
|
|
|
|
const IMAGE_NT_HEADERS *nt;
|
|
|
|
DWORD addr;
|
|
|
|
|
|
|
|
if ((ULONG_PTR)module & 1) /* mapped as data file */
|
|
|
|
{
|
|
|
|
module = (HMODULE)((ULONG_PTR)module & ~1);
|
|
|
|
image = FALSE;
|
|
|
|
}
|
|
|
|
if (!(nt = RtlImageNtHeader( module ))) return NULL;
|
|
|
|
if (dir >= nt->OptionalHeader.NumberOfRvaAndSizes) return NULL;
|
|
|
|
if (!(addr = nt->OptionalHeader.DataDirectory[dir].VirtualAddress)) return NULL;
|
|
|
|
*size = nt->OptionalHeader.DataDirectory[dir].Size;
|
|
|
|
if (image || addr < nt->OptionalHeader.SizeOfHeaders) return (char *)module + addr;
|
|
|
|
|
|
|
|
/* not mapped as image, need to find the section containing the virtual address */
|
|
|
|
return RtlImageRvaToVa( nt, module, addr, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlImageRvaToSection (NTDLL.@)
|
|
|
|
*/
|
|
|
|
PIMAGE_SECTION_HEADER WINAPI RtlImageRvaToSection( const IMAGE_NT_HEADERS *nt,
|
|
|
|
HMODULE module, DWORD rva )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
IMAGE_SECTION_HEADER *sec = (IMAGE_SECTION_HEADER*)((char*)&nt->OptionalHeader +
|
|
|
|
nt->FileHeader.SizeOfOptionalHeader);
|
|
|
|
for (i = 0; i < nt->FileHeader.NumberOfSections; i++, sec++)
|
|
|
|
{
|
|
|
|
if ((sec->VirtualAddress <= rva) && (sec->VirtualAddress + sec->SizeOfRawData > rva))
|
|
|
|
return sec;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RtlImageRvaToVa (NTDLL.@)
|
|
|
|
*/
|
|
|
|
PVOID WINAPI RtlImageRvaToVa( const IMAGE_NT_HEADERS *nt, HMODULE module,
|
|
|
|
DWORD rva, IMAGE_SECTION_HEADER **section )
|
|
|
|
{
|
|
|
|
IMAGE_SECTION_HEADER *sec;
|
|
|
|
|
|
|
|
if (section && *section) /* try this section first */
|
|
|
|
{
|
|
|
|
sec = *section;
|
|
|
|
if ((sec->VirtualAddress <= rva) && (sec->VirtualAddress + sec->SizeOfRawData > rva))
|
|
|
|
goto found;
|
|
|
|
}
|
|
|
|
if (!(sec = RtlImageRvaToSection( nt, module, rva ))) return NULL;
|
|
|
|
found:
|
|
|
|
if (section) *section = sec;
|
|
|
|
return (char *)module + sec->PointerToRawData + (rva - sec->VirtualAddress);
|
|
|
|
}
|