Commit 424202bd authored by Alexandre Julliard's avatar Alexandre Julliard

Moved most of the kernel resource APIs to dlls/kernel.

parent befff556
...@@ -32,6 +32,8 @@ C_SRCS = \ ...@@ -32,6 +32,8 @@ C_SRCS = \
kernel_main.c \ kernel_main.c \
lcformat.c \ lcformat.c \
locale.c \ locale.c \
resource.c \
resource16.c \
stress.c \ stress.c \
string.c \ string.c \
sync.c \ sync.c \
......
/*
* Resources
*
* Copyright 1993 Robert J. Amstadt
* Copyright 1995, 2003 Alexandre Julliard
*
* 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
*/
#include "config.h"
#include "wine/port.h"
#include "windef.h"
#include "winternl.h"
#include "winbase.h"
#include "wownt32.h"
#include "wine/winbase16.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(resource);
/* handle conversions */
#define HRSRC_32(h16) ((HRSRC)(ULONG_PTR)(h16))
#define HRSRC_16(h32) (LOWORD(h32))
#define HGLOBAL_32(h16) ((HGLOBAL)(ULONG_PTR)(h16))
#define HGLOBAL_16(h32) (LOWORD(h32))
#define HMODULE_16(h32) (LOWORD(h32))
/* retrieve the resource name to pass to the ntdll functions */
static NTSTATUS get_res_nameA( LPCSTR name, UNICODE_STRING *str )
{
if (!HIWORD(name))
{
str->Buffer = (LPWSTR)name;
return STATUS_SUCCESS;
}
if (name[0] == '#')
{
ULONG value;
if (RtlCharToInteger( name, 10, &value ) != STATUS_SUCCESS || HIWORD(value))
return STATUS_INVALID_PARAMETER;
str->Buffer = (LPWSTR)value;
return STATUS_SUCCESS;
}
RtlCreateUnicodeStringFromAsciiz( str, name );
RtlUpcaseUnicodeString( str, str, FALSE );
return STATUS_SUCCESS;
}
/* retrieve the resource name to pass to the ntdll functions */
static NTSTATUS get_res_nameW( LPCWSTR name, UNICODE_STRING *str )
{
if (!HIWORD(name))
{
str->Buffer = (LPWSTR)name;
return STATUS_SUCCESS;
}
if (name[0] == '#')
{
ULONG value;
RtlInitUnicodeString( str, name );
if (RtlUnicodeStringToInteger( str, 10, &value ) != STATUS_SUCCESS || HIWORD(value))
return STATUS_INVALID_PARAMETER;
str->Buffer = (LPWSTR)value;
return STATUS_SUCCESS;
}
RtlCreateUnicodeString( str, name );
RtlUpcaseUnicodeString( str, str, FALSE );
return STATUS_SUCCESS;
}
/**********************************************************************
* FindResourceExA (KERNEL32.@)
*/
HRSRC WINAPI FindResourceExA( HMODULE hModule, LPCSTR type, LPCSTR name, WORD lang )
{
NTSTATUS status;
UNICODE_STRING nameW, typeW;
LDR_RESOURCE_INFO info;
const IMAGE_RESOURCE_DATA_ENTRY *entry = NULL;
TRACE( "%p %s %s %04x\n", hModule, debugstr_a(type), debugstr_a(name), lang );
if (!hModule) hModule = GetModuleHandleW(0);
else if (!HIWORD(hModule))
{
return HRSRC_32( FindResource16( HMODULE_16(hModule), name, type ) );
}
nameW.Buffer = typeW.Buffer = NULL;
if ((status = get_res_nameA( name, &nameW )) != STATUS_SUCCESS) goto done;
if ((status = get_res_nameA( type, &typeW )) != STATUS_SUCCESS) goto done;
info.Type = (ULONG)typeW.Buffer;
info.Name = (ULONG)nameW.Buffer;
info.Language = lang;
status = LdrFindResource_U( hModule, &info, 3, &entry );
done:
if (HIWORD(nameW.Buffer)) HeapFree( GetProcessHeap(), 0, nameW.Buffer );
if (HIWORD(typeW.Buffer)) HeapFree( GetProcessHeap(), 0, typeW.Buffer );
if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) );
return (HRSRC)entry;
}
/**********************************************************************
* FindResourceA (KERNEL32.@)
*/
HRSRC WINAPI FindResourceA( HMODULE hModule, LPCSTR name, LPCSTR type )
{
return FindResourceExA( hModule, type, name, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ) );
}
/**********************************************************************
* FindResourceExW (KERNEL32.@)
*/
HRSRC WINAPI FindResourceExW( HMODULE hModule, LPCWSTR type, LPCWSTR name, WORD lang )
{
NTSTATUS status;
UNICODE_STRING nameW, typeW;
LDR_RESOURCE_INFO info;
const IMAGE_RESOURCE_DATA_ENTRY *entry = NULL;
TRACE( "%p %s %s %04x\n", hModule, debugstr_w(type), debugstr_w(name), lang );
if (!hModule) hModule = GetModuleHandleW(0);
else if (!HIWORD(hModule))
{
LPSTR nameA, typeA;
HRSRC16 ret;
if (HIWORD(name))
{
DWORD len = WideCharToMultiByte( CP_ACP, 0, name, -1, NULL, 0, NULL, NULL );
nameA = HeapAlloc( GetProcessHeap(), 0, len );
if (nameA) WideCharToMultiByte( CP_ACP, 0, name, -1, nameA, len, NULL, NULL );
}
else nameA = (LPSTR)name;
if (HIWORD(type))
{
DWORD len = WideCharToMultiByte( CP_ACP, 0, type, -1, NULL, 0, NULL, NULL );
typeA = HeapAlloc( GetProcessHeap(), 0, len );
if (typeA) WideCharToMultiByte( CP_ACP, 0, type, -1, typeA, len, NULL, NULL );
}
else typeA = (LPSTR)type;
ret = FindResource16( HMODULE_16(hModule), nameA, typeA );
if (HIWORD(nameA)) HeapFree( GetProcessHeap(), 0, nameA );
if (HIWORD(typeA)) HeapFree( GetProcessHeap(), 0, typeA );
return HRSRC_32(ret);
}
nameW.Buffer = typeW.Buffer = NULL;
if ((status = get_res_nameW( name, &nameW )) != STATUS_SUCCESS) goto done;
if ((status = get_res_nameW( type, &typeW )) != STATUS_SUCCESS) goto done;
info.Type = (ULONG)typeW.Buffer;
info.Name = (ULONG)nameW.Buffer;
info.Language = lang;
status = LdrFindResource_U( hModule, &info, 3, &entry );
done:
if (HIWORD(nameW.Buffer)) HeapFree( GetProcessHeap(), 0, nameW.Buffer );
if (HIWORD(typeW.Buffer)) HeapFree( GetProcessHeap(), 0, typeW.Buffer );
if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) );
return (HRSRC)entry;
}
/**********************************************************************
* FindResourceW (KERNEL32.@)
*/
HRSRC WINAPI FindResourceW( HINSTANCE hModule, LPCWSTR name, LPCWSTR type )
{
return FindResourceExW( hModule, type, name, MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ) );
}
/**********************************************************************
* LoadResource (KERNEL32.@)
*/
HGLOBAL WINAPI LoadResource( HINSTANCE hModule, HRSRC hRsrc )
{
NTSTATUS status;
void *ret = NULL;
TRACE( "%p %p\n", hModule, hRsrc );
if (hModule && !HIWORD(hModule))
/* FIXME: should convert return to 32-bit resource */
return HGLOBAL_32( LoadResource16( HMODULE_16(hModule), HRSRC_16(hRsrc) ) );
if (!hRsrc) return 0;
if (!hModule) hModule = GetModuleHandleA( NULL );
status = LdrAccessResource( hModule, (IMAGE_RESOURCE_DATA_ENTRY *)hRsrc, &ret, NULL );
if (status != STATUS_SUCCESS) SetLastError( RtlNtStatusToDosError(status) );
return ret;
}
/**********************************************************************
* LockResource (KERNEL32.@)
*/
LPVOID WINAPI LockResource( HGLOBAL handle )
{
TRACE("(%p)\n", handle );
if (HIWORD( handle )) /* 32-bit memory handle */
return (LPVOID)handle;
/* 16-bit memory handle */
return LockResource16( HGLOBAL_16(handle) );
}
/**********************************************************************
* FreeResource (KERNEL32.@)
*/
BOOL WINAPI FreeResource( HGLOBAL handle )
{
if (HIWORD(handle)) return 0; /* 32-bit memory handle: nothing to do */
return FreeResource16( HGLOBAL_16(handle) );
}
/**********************************************************************
* SizeofResource (KERNEL32.@)
*/
DWORD WINAPI SizeofResource( HINSTANCE hModule, HRSRC hRsrc )
{
if (hModule && !HIWORD(hModule))
return SizeofResource16( HMODULE_16(hModule), HRSRC_16(hRsrc) );
if (!hRsrc) return 0;
return ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->Size;
}
...@@ -22,11 +22,8 @@ C_SRCS = \ ...@@ -22,11 +22,8 @@ C_SRCS = \
$(TOPOBJDIR)/loader/module.c \ $(TOPOBJDIR)/loader/module.c \
$(TOPOBJDIR)/loader/pe_image.c \ $(TOPOBJDIR)/loader/pe_image.c \
$(TOPOBJDIR)/loader/pe_resource.c \ $(TOPOBJDIR)/loader/pe_resource.c \
$(TOPOBJDIR)/loader/resource.c \
$(TOPOBJDIR)/loader/task.c \ $(TOPOBJDIR)/loader/task.c \
$(TOPOBJDIR)/loader/ne/convert.c \
$(TOPOBJDIR)/loader/ne/module.c \ $(TOPOBJDIR)/loader/ne/module.c \
$(TOPOBJDIR)/loader/ne/resource.c \
$(TOPOBJDIR)/loader/ne/segment.c \ $(TOPOBJDIR)/loader/ne/segment.c \
$(TOPOBJDIR)/memory/atom.c \ $(TOPOBJDIR)/memory/atom.c \
$(TOPOBJDIR)/memory/codepage.c \ $(TOPOBJDIR)/memory/codepage.c \
......
...@@ -117,7 +117,7 @@ static HMODULE16 BUILTIN_DoLoadModule16( const BUILTIN16_DESCRIPTOR *descr ) ...@@ -117,7 +117,7 @@ static HMODULE16 BUILTIN_DoLoadModule16( const BUILTIN16_DESCRIPTOR *descr )
LocalInit16( GlobalHandleToSel16(pSegTable->hSeg), LocalInit16( GlobalHandleToSel16(pSegTable->hSeg),
pSegTable->minsize, minsize ); pSegTable->minsize, minsize );
if (descr->rsrc) NE_InitResourceHandler(hModule); if (descr->rsrc) NE_InitResourceHandler(pModule);
NE_RegisterModule( pModule ); NE_RegisterModule( pModule );
......
...@@ -195,6 +195,7 @@ extern void MODULE_WalkModref( DWORD id ); ...@@ -195,6 +195,7 @@ extern void MODULE_WalkModref( DWORD id );
extern NE_MODULE *NE_GetPtr( HMODULE16 hModule ); extern NE_MODULE *NE_GetPtr( HMODULE16 hModule );
extern void NE_DumpModule( HMODULE16 hModule ); extern void NE_DumpModule( HMODULE16 hModule );
extern void NE_WalkModules(void); extern void NE_WalkModules(void);
extern void NE_InitResourceHandler( NE_MODULE *pModule );
extern void NE_RegisterModule( NE_MODULE *pModule ); extern void NE_RegisterModule( NE_MODULE *pModule );
extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name ); extern WORD NE_GetOrdinal( HMODULE16 hModule, const char *name );
extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal ); extern FARPROC16 WINAPI NE_GetEntryPoint( HMODULE16 hModule, WORD ordinal );
...@@ -205,13 +206,6 @@ extern DWORD NE_StartTask(void); ...@@ -205,13 +206,6 @@ extern DWORD NE_StartTask(void);
/* loader/ne/resource.c */ /* loader/ne/resource.c */
extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16); extern HGLOBAL16 WINAPI NE_DefResourceHandler(HGLOBAL16,HMODULE16,HRSRC16);
extern BOOL NE_InitResourceHandler( HMODULE16 hModule );
extern HRSRC NE_FindResource( NE_MODULE *pModule, LPCSTR name, LPCSTR type );
extern DWORD NE_SizeofResource( NE_MODULE *pModule, HRSRC hRsrc );
extern HGLOBAL16 NE_LoadResource( NE_MODULE *pModule, HRSRC16 hRsrc );
extern BOOL16 NE_FreeResource( NE_MODULE *pModule, HGLOBAL16 handle );
extern NE_TYPEINFO *NE_FindTypeSection( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR typeId );
extern NE_NAMEINFO *NE_FindResourceFromType( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR resId );
/* loader/ne/segment.c */ /* loader/ne/segment.c */
extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum ); extern BOOL NE_LoadSegment( NE_MODULE *pModule, WORD segnum );
...@@ -222,14 +216,9 @@ extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule ); ...@@ -222,14 +216,9 @@ extern HINSTANCE16 NE_GetInstance( NE_MODULE *pModule );
extern void NE_InitializeDLLs( HMODULE16 hModule ); extern void NE_InitializeDLLs( HMODULE16 hModule );
extern void NE_DllProcessAttach( HMODULE16 hModule ); extern void NE_DllProcessAttach( HMODULE16 hModule );
/* loader/ne/convert.c */
HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size );
/* loader/pe_resource.c */ /* loader/pe_resource.c */
extern HRSRC PE_FindResourceW(HMODULE,LPCWSTR,LPCWSTR); extern HRSRC PE_FindResourceW(HMODULE,LPCWSTR,LPCWSTR);
extern HRSRC PE_FindResourceExW(HMODULE,LPCWSTR,LPCWSTR,WORD); extern HRSRC PE_FindResourceExW(HMODULE,LPCWSTR,LPCWSTR,WORD);
extern DWORD PE_SizeofResource(HRSRC);
extern HGLOBAL PE_LoadResource(HMODULE,HRSRC);
/* loader/pe_image.c */ /* loader/pe_image.c */
extern NTSTATUS PE_LoadLibraryExA(LPCSTR, DWORD, WINE_MODREF**); extern NTSTATUS PE_LoadLibraryExA(LPCSTR, DWORD, WINE_MODREF**);
......
...@@ -259,6 +259,29 @@ void NE_RegisterModule( NE_MODULE *pModule ) ...@@ -259,6 +259,29 @@ void NE_RegisterModule( NE_MODULE *pModule )
/*********************************************************************** /***********************************************************************
* NE_InitResourceHandler
*
* Fill in 'resloader' fields in the resource table.
*/
void NE_InitResourceHandler( NE_MODULE *pModule )
{
static FARPROC16 proc;
NE_TYPEINFO *pTypeInfo = (NE_TYPEINFO *)((char *)pModule + pModule->res_table + 2);
TRACE("InitResourceHandler[%04x]\n", pModule->self );
if (!proc) proc = GetProcAddress16( GetModuleHandle16("KERNEL"), "DefResourceHandler" );
while(pTypeInfo->type_id)
{
memcpy_unaligned( &pTypeInfo->resloader, &proc, sizeof(FARPROC16) );
pTypeInfo = (NE_TYPEINFO *)((char*)(pTypeInfo + 1) + pTypeInfo->count * sizeof(NE_NAMEINFO));
}
}
/***********************************************************************
* NE_GetOrdinal * NE_GetOrdinal
* *
* Lookup the ordinal for a given name. * Lookup the ordinal for a given name.
...@@ -591,7 +614,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path ) ...@@ -591,7 +614,7 @@ static HMODULE16 NE_LoadExeHeader( HANDLE handle, LPCSTR path )
pData )) pData ))
return (HMODULE16)11; /* invalid exe */ return (HMODULE16)11; /* invalid exe */
pData += ne_header.ne_restab - ne_header.ne_rsrctab; pData += ne_header.ne_restab - ne_header.ne_rsrctab;
NE_InitResourceHandler( hModule ); NE_InitResourceHandler( pModule );
} }
else pModule->res_table = 0; /* No resource table */ else pModule->res_table = 0; /* No resource table */
......
...@@ -42,17 +42,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(resource); ...@@ -42,17 +42,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(resource);
/********************************************************************** /**********************************************************************
* is_data_file_module
*
* Check if a module handle is for a LOAD_LIBRARY_AS_DATAFILE module.
*/
inline static int is_data_file_module( HMODULE hmod )
{
return (ULONG_PTR)hmod & 1;
}
/**********************************************************************
* get_resdir * get_resdir
* *
* Get the resource directory of a PE module * Get the resource directory of a PE module
...@@ -167,146 +156,6 @@ static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_nameA( const IMAGE_RESOURCE ...@@ -167,146 +156,6 @@ static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_nameA( const IMAGE_RESOURCE
/********************************************************************** /**********************************************************************
* find_entry_default
*
* Find a default entry in a resource directory
*/
static const IMAGE_RESOURCE_DIRECTORY *find_entry_default( const IMAGE_RESOURCE_DIRECTORY *dir,
const void *root )
{
const IMAGE_RESOURCE_DIRECTORY_ENTRY *entry;
entry = (const IMAGE_RESOURCE_DIRECTORY_ENTRY *)(dir + 1);
return (IMAGE_RESOURCE_DIRECTORY *)((char *)root + entry->u2.s3.OffsetToDirectory);
}
/**********************************************************************
* PE_FindResourceExW
*
* FindResourceExA/W does search in the following order:
* 1. Exact specified language
* 2. Language with neutral sublanguage
* 3. Neutral language with neutral sublanguage
* 4. Neutral language with default sublanguage
*/
HRSRC PE_FindResourceExW( HMODULE hmod, LPCWSTR name, LPCWSTR type, WORD lang )
{
const IMAGE_RESOURCE_DIRECTORY *resdirptr = get_resdir(hmod);
const void *root;
HRSRC result;
if (!resdirptr) return 0;
root = resdirptr;
if (!(resdirptr = find_entry_by_nameW(resdirptr, type, root))) return 0;
if (!(resdirptr = find_entry_by_nameW(resdirptr, name, root))) return 0;
/* 1. Exact specified language */
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
/* 2. Language with neutral sublanguage */
lang = MAKELANGID(PRIMARYLANGID(lang), SUBLANG_NEUTRAL);
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
/* 3. Neutral language with neutral sublanguage */
lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
/* 4. Neutral language with default sublanguage */
lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
result = (HRSRC)find_entry_by_id( resdirptr, lang, root );
found:
return result;
}
/**********************************************************************
* PE_FindResourceW
*
* Load[String]/[Icon]/[Menu]/[etc.] does use FindResourceA/W.
* FindResourceA/W does search in the following order:
* 1. Neutral language with neutral sublanguage
* 2. Neutral language with default sublanguage
* 3. Current locale lang id
* 4. Current locale lang id with neutral sublanguage
* 5. (!) LANG_ENGLISH, SUBLANG_DEFAULT
* 6. Return first in the list
*/
HRSRC PE_FindResourceW( HMODULE hmod, LPCWSTR name, LPCWSTR type )
{
const IMAGE_RESOURCE_DIRECTORY *resdirptr = get_resdir(hmod);
const void *root;
HRSRC result;
WORD lang;
if (!resdirptr) return 0;
root = resdirptr;
if (!(resdirptr = find_entry_by_nameW(resdirptr, type, root))) return 0;
if (!(resdirptr = find_entry_by_nameW(resdirptr, name, root))) return 0;
/* 1. Neutral language with neutral sublanguage */
lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
/* 2. Neutral language with default sublanguage */
lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
/* 3. Current locale lang id */
lang = LANGIDFROMLCID(GetUserDefaultLCID());
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
/* 4. Current locale lang id with neutral sublanguage */
lang = MAKELANGID(PRIMARYLANGID(lang), SUBLANG_NEUTRAL);
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
/* 5. (!) LANG_ENGLISH, SUBLANG_DEFAULT */
lang = MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT);
if ((result = (HRSRC)find_entry_by_id( resdirptr, lang, root ))) goto found;
/* 6. Return first in the list */
result = (HRSRC)find_entry_default( resdirptr, root );
found:
return result;
}
/**********************************************************************
* PE_LoadResource
*/
HGLOBAL PE_LoadResource( HMODULE hmod, HRSRC hRsrc )
{
DWORD offset;
if (!hRsrc) return 0;
if (!hmod) hmod = GetModuleHandleA( NULL );
offset = ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->OffsetToData;
if (is_data_file_module(hmod))
{
hmod = (HMODULE)((ULONG_PTR)hmod & ~1);
return (HGLOBAL)RtlImageRvaToVa( RtlImageNtHeader(hmod), hmod, offset, NULL );
}
else
return (HGLOBAL)((char *)hmod + offset);
}
/**********************************************************************
* PE_SizeofResource
*/
DWORD PE_SizeofResource( HRSRC hRsrc )
{
if (!hRsrc) return 0;
return ((PIMAGE_RESOURCE_DATA_ENTRY)hRsrc)->Size;
}
/**********************************************************************
* EnumResourceTypesA (KERNEL32.@) * EnumResourceTypesA (KERNEL32.@)
*/ */
BOOL WINAPI EnumResourceTypesA( HMODULE hmod, ENUMRESTYPEPROCA lpfun, LONG lparam) BOOL WINAPI EnumResourceTypesA( HMODULE hmod, ENUMRESTYPEPROCA lpfun, LONG lparam)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment