Commit 0433db1e authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Add a helper function to map the main exe module.

parent ebc1b099
......@@ -1663,7 +1663,7 @@ BOOL is_builtin_path( const UNICODE_STRING *path, WORD *machine )
* open_main_image
*/
static NTSTATUS open_main_image( WCHAR *image, void **module, SECTION_IMAGE_INFORMATION *info,
enum loadorder loadorder )
enum loadorder loadorder, USHORT machine )
{
static const WCHAR soW[] = {'.','s','o',0};
UNICODE_STRING nt_name;
......@@ -1684,14 +1684,8 @@ static NTSTATUS open_main_image( WCHAR *image, void **module, SECTION_IMAGE_INFO
status = open_dll_file( unix_name, &attr, &mapping );
if (!status)
{
*module = NULL;
status = NtMapViewOfSection( mapping, NtCurrentProcess(), module, 0, 0, NULL, &size,
ViewShare, 0, PAGE_EXECUTE_READ );
if (!status)
{
NtQuerySection( mapping, SectionImageInformation, info, sizeof(*info), NULL );
if (info->u.s.ComPlusNativeReady) info->Machine = native_machine;
}
status = virtual_map_module( mapping, module, &size, info, 0, machine );
if (!status && info->u.s.ComPlusNativeReady) info->Machine = native_machine;
NtClose( mapping );
}
else if (status == STATUS_INVALID_IMAGE_NOT_MZ && loadorder != LO_NATIVE)
......@@ -1732,7 +1726,7 @@ NTSTATUS load_main_exe( const WCHAR *dos_name, const char *unix_name, const WCHA
if ((status = unix_to_nt_file_name( unix_name, image ))) goto failed;
init_unicode_string( &nt_name, *image );
loadorder = get_load_order( &nt_name );
status = open_main_image( *image, module, &main_image_info, loadorder );
status = open_main_image( *image, module, &main_image_info, loadorder, 0 );
if (status != STATUS_DLL_NOT_FOUND) return status;
free( *image );
}
......@@ -1752,7 +1746,7 @@ NTSTATUS load_main_exe( const WCHAR *dos_name, const char *unix_name, const WCHA
init_unicode_string( &nt_name, *image );
if (loadorder == LO_INVALID) loadorder = get_load_order( &nt_name );
status = open_main_image( *image, module, &main_image_info, loadorder );
status = open_main_image( *image, module, &main_image_info, loadorder, 0 );
if (status != STATUS_DLL_NOT_FOUND) return status;
/* if path is in system dir, we can load the builtin even if the file itself doesn't exist */
......
......@@ -223,6 +223,8 @@ extern ULONG_PTR get_system_affinity_mask(void) DECLSPEC_HIDDEN;
extern void virtual_get_system_info( SYSTEM_BASIC_INFORMATION *info, BOOL wow64 ) DECLSPEC_HIDDEN;
extern NTSTATUS virtual_map_builtin_module( HANDLE mapping, void **module, SIZE_T *size, SECTION_IMAGE_INFORMATION *info,
ULONG_PTR limit, WORD machine, BOOL prefer_native ) DECLSPEC_HIDDEN;
extern NTSTATUS virtual_map_module( HANDLE mapping, void **module, SIZE_T *size, SECTION_IMAGE_INFORMATION *info,
ULONG_PTR limit, USHORT machine ) DECLSPEC_HIDDEN;
extern NTSTATUS virtual_create_builtin_view( void *module, const UNICODE_STRING *nt_name,
pe_image_info_t *info, void *so_handle ) DECLSPEC_HIDDEN;
extern TEB *virtual_alloc_first_teb(void) DECLSPEC_HIDDEN;
......
......@@ -3074,6 +3074,42 @@ NTSTATUS virtual_map_builtin_module( HANDLE mapping, void **module, SIZE_T *size
/***********************************************************************
* virtual_map_module
*/
NTSTATUS virtual_map_module( HANDLE mapping, void **module, SIZE_T *size, SECTION_IMAGE_INFORMATION *info,
ULONG_PTR limit, USHORT machine )
{
unsigned int status;
mem_size_t full_size;
unsigned int sec_flags;
HANDLE shared_file;
pe_image_info_t *image_info = NULL;
ACCESS_MASK access = SECTION_MAP_READ | SECTION_MAP_EXECUTE;
WCHAR *filename;
if ((status = get_mapping_info( mapping, access, &sec_flags, &full_size, &shared_file, &image_info )))
return status;
if (!image_info) return STATUS_INVALID_PARAMETER;
*module = NULL;
*size = 0;
filename = (WCHAR *)(image_info + 1);
/* check if we can replace that mapping with the builtin */
status = load_builtin( image_info, filename, machine, module, size, limit );
if (status == STATUS_IMAGE_ALREADY_LOADED)
status = virtual_map_image( mapping, access, module, size, shared_file, limit, 0,
machine, image_info, filename, FALSE );
virtual_fill_image_information( image_info, info );
if (shared_file) NtClose( shared_file );
free( image_info );
return status;
}
/***********************************************************************
* virtual_create_builtin_view
*/
NTSTATUS virtual_create_builtin_view( void *module, const UNICODE_STRING *nt_name,
......
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