Commit 65c37cee authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Use exported APIs instead of virtual_map_section() to load PE modules.

parent 1581fb61
......@@ -896,6 +896,23 @@ static NTSTATUS CDECL load_so_dll( UNICODE_STRING *nt_name, void **module )
}
/* check a PE library architecture */
static BOOL is_valid_binary( HMODULE module, const SECTION_IMAGE_INFORMATION *info )
{
#ifdef __i386__
return info->Machine == IMAGE_FILE_MACHINE_I386;
#elif defined(__arm__)
return info->Machine == IMAGE_FILE_MACHINE_ARM ||
info->Machine == IMAGE_FILE_MACHINE_THUMB ||
info->Machine == IMAGE_FILE_MACHINE_ARMNT;
#elif defined(__x86_64__)
/* we don't support 32-bit IL-only builtins yet */
return info->Machine == IMAGE_FILE_MACHINE_AMD64;
#elif defined(__aarch64__)
return info->Machine == IMAGE_FILE_MACHINE_ARM64;
#endif
}
/* check if the library is the correct architecture */
/* only returns false for a valid library of the wrong arch */
static int check_library_arch( int fd )
......@@ -943,7 +960,7 @@ static inline char *prepend( char *buffer, const char *str, size_t len )
*
* Open a file for a new dll. Helper for find_dll_file.
*/
static NTSTATUS open_dll_file( const char *name, void **module, pe_image_info_t *image_info )
static NTSTATUS open_dll_file( const char *name, void **module, SECTION_IMAGE_INFORMATION *image_info )
{
struct builtin_module *builtin;
OBJECT_ATTRIBUTES attr = { sizeof(attr) };
......@@ -995,20 +1012,22 @@ static NTSTATUS open_dll_file( const char *name, void **module, pe_image_info_t
NtUnmapViewOfSection( NtCurrentProcess(), *module );
*module = NULL;
}
status = virtual_map_section( mapping, module, 0, 0, NULL, &len, 0, PAGE_EXECUTE_READ, image_info );
NtQuerySection( mapping, SectionImageInformation, image_info, sizeof(*image_info), NULL );
status = NtMapViewOfSection( mapping, NtCurrentProcess(), module, 0, 0, NULL, &len,
ViewShare, 0, PAGE_EXECUTE_READ );
if (status == STATUS_IMAGE_NOT_AT_BASE) status = STATUS_SUCCESS;
NtClose( mapping );
if (status) return status;
/* ignore non-builtins */
if (!(image_info->image_flags & IMAGE_FLAGS_WineBuiltin))
if (!(image_info->u.ImageFlags & IMAGE_FLAGS_WineBuiltin))
{
WARN( "%s found in WINEDLLPATH but not a builtin, ignoring\n", debugstr_a(name) );
status = STATUS_DLL_NOT_FOUND;
}
else if (image_info->cpu != client_cpu)
else if (!is_valid_binary( *module, image_info ))
{
TRACE( "%s is for CPU %u, continuing search\n", debugstr_a(name), image_info->cpu );
TRACE( "%s is for arch %x, continuing search\n", debugstr_a(name), image_info->Machine );
status = STATUS_IMAGE_MACHINE_TYPE_MISMATCH;
}
......@@ -1026,7 +1045,7 @@ static NTSTATUS open_dll_file( const char *name, void **module, pe_image_info_t
/***********************************************************************
* open_builtin_file
*/
static NTSTATUS open_builtin_file( char *name, void **module, pe_image_info_t *image_info )
static NTSTATUS open_builtin_file( char *name, void **module, SECTION_IMAGE_INFORMATION *image_info )
{
NTSTATUS status;
int fd;
......@@ -1046,7 +1065,7 @@ static NTSTATUS open_builtin_file( char *name, void **module, pe_image_info_t *i
if (!dlopen_dll( name, module ))
{
memset( image_info, 0, sizeof(*image_info) );
image_info->image_flags = IMAGE_FLAGS_WineBuiltin;
image_info->u.ImageFlags = IMAGE_FLAGS_WineBuiltin;
status = STATUS_SUCCESS;
}
else
......@@ -1065,7 +1084,8 @@ static NTSTATUS open_builtin_file( char *name, void **module, pe_image_info_t *i
/***********************************************************************
* load_builtin_dll
*/
static NTSTATUS CDECL load_builtin_dll( const WCHAR *name, void **module, pe_image_info_t *image_info )
static NTSTATUS CDECL load_builtin_dll( const WCHAR *name, void **module,
SECTION_IMAGE_INFORMATION *image_info )
{
unsigned int i, pos, len, namelen, maxlen = 0;
char *ptr, *file;
......@@ -1346,7 +1366,6 @@ static struct unix_funcs unix_funcs =
get_initial_directory,
get_unix_codepage_data,
get_locales,
virtual_map_section,
virtual_release_address_space,
exec_process,
set_show_dot_files,
......
......@@ -115,9 +115,6 @@ extern void CDECL get_initial_directory( UNICODE_STRING *dir ) DECLSPEC_HIDDEN;
extern void CDECL get_initial_console( HANDLE *handle, HANDLE *std_in, HANDLE *std_out, HANDLE *std_err ) DECLSPEC_HIDDEN;
extern USHORT * CDECL get_unix_codepage_data(void) DECLSPEC_HIDDEN;
extern void CDECL get_locales( WCHAR *sys, WCHAR *user ) DECLSPEC_HIDDEN;
extern NTSTATUS CDECL virtual_map_section( HANDLE handle, PVOID *addr_ptr, unsigned short zero_bits_64, SIZE_T commit_size,
const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr, ULONG alloc_type,
ULONG protect, pe_image_info_t *image_info ) DECLSPEC_HIDDEN;
extern void CDECL virtual_release_address_space(void) DECLSPEC_HIDDEN;
extern NTSTATUS CDECL exec_process( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTSTATUS status ) DECLSPEC_HIDDEN;
......
......@@ -2181,9 +2181,9 @@ static NTSTATUS map_image_into_view( struct file_view *view, int fd, void *orig_
*
* Map a file section into memory.
*/
NTSTATUS CDECL virtual_map_section( HANDLE handle, PVOID *addr_ptr, unsigned short zero_bits_64, SIZE_T commit_size,
const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr, ULONG alloc_type,
ULONG protect, pe_image_info_t *image_info )
static NTSTATUS virtual_map_section( HANDLE handle, PVOID *addr_ptr, unsigned short zero_bits_64,
SIZE_T commit_size, const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr,
ULONG alloc_type, ULONG protect, pe_image_info_t *image_info )
{
NTSTATUS res;
mem_size_t full_size;
......@@ -4163,7 +4163,7 @@ void virtual_fill_image_information( const pe_image_info_t *pe_info, SECTION_IMA
info->DllCharacteristics = pe_info->dll_charact;
info->Machine = pe_info->machine;
info->ImageContainsCode = pe_info->contains_code;
info->ImageFlags = pe_info->image_flags & ~(IMAGE_FLAGS_WineBuiltin|IMAGE_FLAGS_WineFakeDll);
info->ImageFlags = pe_info->image_flags;
info->LoaderFlags = pe_info->loader_flags;
info->ImageFileSize = pe_info->file_size;
info->CheckSum = pe_info->checksum;
......
......@@ -27,7 +27,7 @@
struct _DISPATCHER_CONTEXT;
/* increment this when you change the function table */
#define NTDLL_UNIXLIB_VERSION 99
#define NTDLL_UNIXLIB_VERSION 100
struct unix_funcs
{
......@@ -79,9 +79,6 @@ struct unix_funcs
void (CDECL *get_locales)( WCHAR *sys, WCHAR *user );
/* virtual memory functions */
NTSTATUS (CDECL *virtual_map_section)( HANDLE handle, PVOID *addr_ptr, unsigned short zero_bits_64, SIZE_T commit_size,
const LARGE_INTEGER *offset_ptr, SIZE_T *size_ptr, ULONG alloc_type,
ULONG protect, pe_image_info_t *image_info );
void (CDECL *virtual_release_address_space)(void);
/* thread/process functions */
......@@ -93,7 +90,7 @@ struct unix_funcs
/* loader functions */
NTSTATUS (CDECL *load_so_dll)( UNICODE_STRING *nt_name, void **module );
NTSTATUS (CDECL *load_builtin_dll)( const WCHAR *name, void **module,
pe_image_info_t *image_info );
SECTION_IMAGE_INFORMATION *image_info );
NTSTATUS (CDECL *unload_builtin_dll)( void *module );
void (CDECL *init_builtin_dll)( void *module );
NTSTATUS (CDECL *unwind_builtin_dll)( ULONG type, struct _DISPATCHER_CONTEXT *dispatch,
......
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