Alexandre Julliard : kernel32: Change MODULE_GetBinaryType return value to make dll a flag instead of a type .
Alexandre Julliard
julliard at winehq.org
Wed Aug 12 11:09:58 CDT 2009
Module: wine
Branch: master
Commit: f274d1d03f010c267d121e2a147739dc28783b14
URL: http://source.winehq.org/git/wine.git/?a=commit;h=f274d1d03f010c267d121e2a147739dc28783b14
Author: Alexandre Julliard <julliard at winehq.org>
Date: Wed Aug 12 15:43:08 2009 +0200
kernel32: Change MODULE_GetBinaryType return value to make dll a flag instead of a type.
---
dlls/kernel32/kernel_private.h | 22 ++++++++++------------
dlls/kernel32/module.c | 19 ++++++++++---------
dlls/kernel32/process.c | 22 ++++++++++++++--------
3 files changed, 34 insertions(+), 29 deletions(-)
diff --git a/dlls/kernel32/kernel_private.h b/dlls/kernel32/kernel_private.h
index 20f6399..03819d2 100644
--- a/dlls/kernel32/kernel_private.h
+++ b/dlls/kernel32/kernel_private.h
@@ -83,21 +83,19 @@ extern DWORD __wine_emulate_instruction( EXCEPTION_RECORD *rec, CONTEXT86 *conte
extern LONG CALLBACK INSTR_vectored_handler( EXCEPTION_POINTERS *ptrs );
/* return values for MODULE_GetBinaryType */
-enum binary_type
-{
- BINARY_UNKNOWN,
- BINARY_PE_EXE,
- BINARY_PE_DLL,
- BINARY_WIN16,
- BINARY_OS216,
- BINARY_DOS,
- BINARY_UNIX_EXE,
- BINARY_UNIX_LIB
-};
+#define BINARY_UNKNOWN 0x00
+#define BINARY_PE 0x01
+#define BINARY_WIN16 0x02
+#define BINARY_OS216 0x03
+#define BINARY_DOS 0x04
+#define BINARY_UNIX_EXE 0x05
+#define BINARY_UNIX_LIB 0x06
+#define BINARY_TYPE_MASK 0x0f
+#define BINARY_FLAG_DLL 0x10
/* module.c */
extern WCHAR *MODULE_get_dll_load_path( LPCWSTR module );
-extern enum binary_type MODULE_GetBinaryType( HANDLE hfile, void **res_start, void **res_end );
+extern DWORD MODULE_GetBinaryType( HANDLE hfile, void **res_start, void **res_end );
extern BOOL NLS_IsUnicodeOnlyLcid(LCID);
diff --git a/dlls/kernel32/module.c b/dlls/kernel32/module.c
index 86675b6..02cfc2c 100644
--- a/dlls/kernel32/module.c
+++ b/dlls/kernel32/module.c
@@ -178,11 +178,10 @@ BOOL WINAPI DisableThreadLibraryCalls( HMODULE hModule )
* FIXME: is reading the module imports the only way of discerning
* old Windows binaries from OS/2 ones ? At least it seems so...
*/
-static enum binary_type MODULE_Decide_OS2_OldWin(HANDLE hfile, const IMAGE_DOS_HEADER *mz,
- const IMAGE_OS2_HEADER *ne)
+static DWORD MODULE_Decide_OS2_OldWin(HANDLE hfile, const IMAGE_DOS_HEADER *mz, const IMAGE_OS2_HEADER *ne)
{
DWORD currpos = SetFilePointer( hfile, 0, NULL, SEEK_CUR);
- enum binary_type ret = BINARY_OS216;
+ DWORD ret = BINARY_OS216;
LPWORD modtab = NULL;
LPSTR nametab = NULL;
DWORD len;
@@ -227,7 +226,7 @@ good:
/***********************************************************************
* MODULE_GetBinaryType
*/
-enum binary_type MODULE_GetBinaryType( HANDLE hfile, void **res_start, void **res_end )
+DWORD MODULE_GetBinaryType( HANDLE hfile, void **res_start, void **res_end )
{
union
{
@@ -305,13 +304,14 @@ enum binary_type MODULE_GetBinaryType( HANDLE hfile, void **res_start, void **re
{
if (len >= sizeof(ext_header.nt.FileHeader))
{
+ DWORD ret = BINARY_PE;
+ if (ext_header.nt.FileHeader.Characteristics & IMAGE_FILE_DLL) ret |= BINARY_FLAG_DLL;
if (len < sizeof(ext_header.nt)) /* clear remaining part of header if missing */
memset( (char *)&ext_header.nt + len, 0, sizeof(ext_header.nt) - len );
if (res_start) *res_start = (void *)ext_header.nt.OptionalHeader.ImageBase;
if (res_end) *res_end = (void *)(ext_header.nt.OptionalHeader.ImageBase +
ext_header.nt.OptionalHeader.SizeOfImage);
- if (ext_header.nt.FileHeader.Characteristics & IMAGE_FILE_DLL) return BINARY_PE_DLL;
- return BINARY_PE_EXE;
+ return ret;
}
return BINARY_DOS;
}
@@ -384,6 +384,7 @@ BOOL WINAPI GetBinaryTypeW( LPCWSTR lpApplicationName, LPDWORD lpBinaryType )
{
BOOL ret = FALSE;
HANDLE hfile;
+ DWORD binary_type;
TRACE("%s\n", debugstr_w(lpApplicationName) );
@@ -401,7 +402,8 @@ BOOL WINAPI GetBinaryTypeW( LPCWSTR lpApplicationName, LPDWORD lpBinaryType )
/* Check binary type
*/
- switch(MODULE_GetBinaryType( hfile, NULL, NULL ))
+ binary_type = MODULE_GetBinaryType( hfile, NULL, NULL );
+ switch (binary_type & BINARY_TYPE_MASK)
{
case BINARY_UNKNOWN:
{
@@ -424,8 +426,7 @@ BOOL WINAPI GetBinaryTypeW( LPCWSTR lpApplicationName, LPDWORD lpBinaryType )
}
break;
}
- case BINARY_PE_EXE:
- case BINARY_PE_DLL:
+ case BINARY_PE:
*lpBinaryType = SCS_32BIT_BINARY;
ret = TRUE;
break;
diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index f90b294..4a3a49e 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -1909,6 +1909,7 @@ BOOL WINAPI CreateProcessW( LPCWSTR app_name, LPWSTR cmd_line, LPSECURITY_ATTRIB
WCHAR name[MAX_PATH];
WCHAR *tidy_cmdline, *p, *envW = env;
void *res_start, *res_end;
+ DWORD binary_type;
/* Process the AppName and/or CmdLine to get module name and path */
@@ -1966,9 +1967,15 @@ BOOL WINAPI CreateProcessW( LPCWSTR app_name, LPWSTR cmd_line, LPSECURITY_ATTRIB
goto done;
}
- switch( MODULE_GetBinaryType( hFile, &res_start, &res_end ))
+ binary_type = MODULE_GetBinaryType( hFile, &res_start, &res_end );
+ if (binary_type & BINARY_FLAG_DLL)
{
- case BINARY_PE_EXE:
+ TRACE( "not starting %s since it is a dll\n", debugstr_w(name) );
+ SetLastError( ERROR_BAD_EXE_FORMAT );
+ }
+ else switch (binary_type & BINARY_TYPE_MASK)
+ {
+ case BINARY_PE:
TRACE( "starting %s as Win32 binary (%p-%p)\n", debugstr_w(name), res_start, res_end );
retv = create_process( hFile, name, tidy_cmdline, envW, cur_dir, process_attr, thread_attr,
inherit, flags, startup_info, info, unixdir, res_start, res_end, FALSE );
@@ -1980,10 +1987,6 @@ BOOL WINAPI CreateProcessW( LPCWSTR app_name, LPWSTR cmd_line, LPSECURITY_ATTRIB
retv = create_vdm_process( name, tidy_cmdline, envW, cur_dir, process_attr, thread_attr,
inherit, flags, startup_info, info, unixdir, FALSE );
break;
- case BINARY_PE_DLL:
- TRACE( "not starting %s since it is a dll\n", debugstr_w(name) );
- SetLastError( ERROR_BAD_EXE_FORMAT );
- break;
case BINARY_UNIX_LIB:
TRACE( "%s is a Unix library, starting as Winelib app\n", debugstr_w(name) );
retv = create_process( hFile, name, tidy_cmdline, envW, cur_dir, process_attr, thread_attr,
@@ -2046,6 +2049,7 @@ static void exec_process( LPCWSTR name )
void *res_start, *res_end;
STARTUPINFOW startup_info;
PROCESS_INFORMATION info;
+ DWORD binary_type;
hFile = open_exe_file( name );
if (!hFile || hFile == INVALID_HANDLE_VALUE) return;
@@ -2055,9 +2059,11 @@ static void exec_process( LPCWSTR name )
/* Determine executable type */
- switch( MODULE_GetBinaryType( hFile, &res_start, &res_end ))
+ binary_type = MODULE_GetBinaryType( hFile, &res_start, &res_end );
+ if (binary_type & BINARY_FLAG_DLL) return;
+ switch (binary_type & BINARY_TYPE_MASK)
{
- case BINARY_PE_EXE:
+ case BINARY_PE:
TRACE( "starting %s as Win32 binary (%p-%p)\n", debugstr_w(name), res_start, res_end );
create_process( hFile, name, GetCommandLineW(), NULL, NULL, NULL, NULL,
FALSE, 0, &startup_info, &info, NULL, res_start, res_end, TRUE );
More information about the wine-cvs
mailing list