From c599ec149431a447084a347d381e7897b2102b72 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 29 Jan 2020 10:49:40 +0100 Subject: [PATCH] libwine: Make some loader functions obsolete. Signed-off-by: Alexandre Julliard --- dlls/ntdll/loader.c | 2 +- include/wine/library.h | 5 -- libs/wine/loader.c | 183 +++++++++++++++++++++-------------------- libs/wine/wine.map | 8 +- 4 files changed, 101 insertions(+), 97 deletions(-) diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 567e74ebd71..b865d4f9ed5 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -3582,7 +3582,7 @@ static void free_modref( WINE_MODREF *wm ) free_tls_slot( &wm->ldr ); RtlReleaseActivationContext( wm->ldr.ActivationContext ); if ((wm->ldr.Flags & LDR_WINE_INTERNAL) && wm->ldr.SectionHandle) - wine_dll_unload( wm->ldr.SectionHandle ); + wine_dlclose( wm->ldr.SectionHandle, NULL, 0 ); NtUnmapViewOfSection( NtCurrentProcess(), wm->ldr.BaseAddress ); if (cached_modref == wm) cached_modref = NULL; RtlFreeUnicodeString( &wm->ldr.FullDllName ); diff --git a/include/wine/library.h b/include/wine/library.h index 9e1aff1cebd..a6fe28059f3 100644 --- a/include/wine/library.h +++ b/include/wine/library.h @@ -59,12 +59,7 @@ extern void *wine_dlopen( const char *filename, int flag, char *error, size_t er extern void *wine_dlsym( void *handle, const char *symbol, char *error, size_t errorsize ); extern int wine_dlclose( void *handle, char *error, size_t errorsize ); extern void wine_dll_set_callback( load_dll_callback_t load ); -extern void *wine_dll_load( const char *filename, char *error, int errorsize, int *file_exists ); -extern void *wine_dll_load_main_exe( const char *name, char *error, int errorsize, - int test_only, int *file_exists ); -extern void wine_dll_unload( void *handle ); extern const char *wine_dll_enum_load_path( unsigned int index ); -extern int wine_dll_get_owner( const char *name, char *buffer, int size, int *file_exists ); extern int __wine_main_argc; extern char **__wine_main_argv; diff --git a/libs/wine/loader.c b/libs/wine/loader.c index 649aa221d1c..2a569f5b739 100644 --- a/libs/wine/loader.c +++ b/libs/wine/loader.c @@ -62,6 +62,7 @@ extern char **environ; #define NONAMELESSSTRUCT #include "windef.h" #include "winbase.h" +#include "wine/asm.h" #include "wine/library.h" /* argc/argv for the Windows application */ @@ -159,56 +160,6 @@ static void build_dll_path(void) } } -/* 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 ) -{ -#ifdef __APPLE__ - struct /* Mach-O header */ - { - unsigned int magic; - unsigned int cputype; - } header; - - if (read( fd, &header, sizeof(header) ) != sizeof(header)) return 1; - if (header.magic != 0xfeedface) return 1; - if (sizeof(void *) == sizeof(int)) return !(header.cputype >> 24); - else return (header.cputype >> 24) == 1; /* CPU_ARCH_ABI64 */ -#else - struct /* ELF header */ - { - unsigned char magic[4]; - unsigned char class; - unsigned char data; - unsigned char version; - } header; - - if (read( fd, &header, sizeof(header) ) != sizeof(header)) return 1; - if (memcmp( header.magic, "\177ELF", 4 )) return 1; - if (header.version != 1 /* EV_CURRENT */) return 1; -#ifdef WORDS_BIGENDIAN - if (header.data != 2 /* ELFDATA2MSB */) return 1; -#else - if (header.data != 1 /* ELFDATA2LSB */) return 1; -#endif - if (sizeof(void *) == sizeof(int)) return header.class == 1; /* ELFCLASS32 */ - else return header.class == 2; /* ELFCLASS64 */ -#endif -} - -/* check if a given file can be opened */ -static inline int file_exists( const char *name ) -{ - int ret = 0; - int fd = open( name, O_RDONLY ); - if (fd != -1) - { - ret = check_library_arch( fd ); - close( fd ); - } - return ret; -} - static inline char *prepend( char *buffer, const char *str, size_t len ) { return memcpy( buffer - len, str, len ); @@ -278,26 +229,6 @@ static inline void free_dll_path( struct dll_path_context *context ) } -/* open a library for a given dll, searching in the dll path - * 'name' must be the Windows dll name (e.g. "kernel32.dll") */ -static void *dlopen_dll( const char *name, char *error, int errorsize, - int test_only, int *exists ) -{ - struct dll_path_context context; - char *path; - void *ret = NULL; - - *exists = 0; - for (path = first_dll_path( name, 0, &context ); path; path = next_dll_path( &context )) - { - if (!test_only && (ret = wine_dlopen( path, RTLD_NOW, error, errorsize ))) break; - if ((*exists = file_exists( path ))) break; /* exists but cannot be loaded, return the error */ - } - free_dll_path( &context ); - return ret; -} - - /* adjust an array of pointers to make them into RVAs */ static inline void fixup_rva_ptrs( void *array, BYTE *base, unsigned int count ) { @@ -563,12 +494,96 @@ void wine_dll_set_callback( load_dll_callback_t load ) } +/*********************************************************************** + * wine_dll_enum_load_path + * + * Enumerate the dll load path. + */ +const char *wine_dll_enum_load_path( unsigned int index ) +{ + if (index >= nb_dll_paths) return NULL; + return dll_paths[index]; +} + + +#ifdef __ASM_OBSOLETE + +/* 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 ) +{ +#ifdef __APPLE__ + struct /* Mach-O header */ + { + unsigned int magic; + unsigned int cputype; + } header; + + if (read( fd, &header, sizeof(header) ) != sizeof(header)) return 1; + if (header.magic != 0xfeedface) return 1; + if (sizeof(void *) == sizeof(int)) return !(header.cputype >> 24); + else return (header.cputype >> 24) == 1; /* CPU_ARCH_ABI64 */ +#else + struct /* ELF header */ + { + unsigned char magic[4]; + unsigned char class; + unsigned char data; + unsigned char version; + } header; + + if (read( fd, &header, sizeof(header) ) != sizeof(header)) return 1; + if (memcmp( header.magic, "\177ELF", 4 )) return 1; + if (header.version != 1 /* EV_CURRENT */) return 1; +#ifdef WORDS_BIGENDIAN + if (header.data != 2 /* ELFDATA2MSB */) return 1; +#else + if (header.data != 1 /* ELFDATA2LSB */) return 1; +#endif + if (sizeof(void *) == sizeof(int)) return header.class == 1; /* ELFCLASS32 */ + else return header.class == 2; /* ELFCLASS64 */ +#endif +} + +/* check if a given file can be opened */ +static int file_exists( const char *name ) +{ + int ret = 0; + int fd = open( name, O_RDONLY ); + if (fd != -1) + { + ret = check_library_arch( fd ); + close( fd ); + } + return ret; +} + +/* open a library for a given dll, searching in the dll path + * 'name' must be the Windows dll name (e.g. "kernel32.dll") */ +static void *dlopen_dll( const char *name, char *error, int errorsize, + int test_only, int *exists ) +{ + struct dll_path_context context; + char *path; + void *ret = NULL; + + *exists = 0; + for (path = first_dll_path( name, 0, &context ); path; path = next_dll_path( &context )) + { + if (!test_only && (ret = wine_dlopen( path, RTLD_NOW, error, errorsize ))) break; + if ((*exists = file_exists( path ))) break; /* exists but cannot be loaded, return the error */ + } + free_dll_path( &context ); + return ret; +} + + /*********************************************************************** * wine_dll_load * * Load a builtin dll. */ -void *wine_dll_load( const char *filename, char *error, int errorsize, int *file_exists ) +void *wine_dll_load_obsolete( const char *filename, char *error, int errorsize, int *file_exists ) { int i; @@ -598,7 +613,7 @@ void *wine_dll_load( const char *filename, char *error, int errorsize, int *file * * Unload a builtin dll. */ -void wine_dll_unload( void *handle ) +void wine_dll_unload_obsolete( void *handle ) { if (handle != (void *)1) wine_dlclose( handle, NULL, 0 ); @@ -610,32 +625,20 @@ void wine_dll_unload( void *handle ) * * Try to load the .so for the main exe. */ -void *wine_dll_load_main_exe( const char *name, char *error, int errorsize, - int test_only, int *file_exists ) +void *wine_dll_load_main_exe_obsolete( const char *name, char *error, int errorsize, + int test_only, int *file_exists ) { return dlopen_dll( name, error, errorsize, test_only, file_exists ); } -/*********************************************************************** - * wine_dll_enum_load_path - * - * Enumerate the dll load path. - */ -const char *wine_dll_enum_load_path( unsigned int index ) -{ - if (index >= nb_dll_paths) return NULL; - return dll_paths[index]; -} - - /*********************************************************************** * wine_dll_get_owner * * Retrieve the name of the 32-bit owner dll for a 16-bit dll. * Return 0 if OK, -1 on error. */ -int wine_dll_get_owner( const char *name, char *buffer, int size, int *exists ) +int wine_dll_get_owner_obsolete( const char *name, char *buffer, int size, int *exists ) { int ret = -1; char *path; @@ -661,6 +664,12 @@ int wine_dll_get_owner( const char *name, char *buffer, int size, int *exists ) return ret; } +__ASM_OBSOLETE(wine_dll_get_owner); +__ASM_OBSOLETE(wine_dll_load); +__ASM_OBSOLETE(wine_dll_load_main_exe); +__ASM_OBSOLETE(wine_dll_unload); + +#endif /* __ASM_OBSOLETE */ /*********************************************************************** * set_max_limit diff --git a/libs/wine/wine.map b/libs/wine/wine.map index 50ae4797884..17c91fd1628 100644 --- a/libs/wine/wine.map +++ b/libs/wine/wine.map @@ -18,11 +18,7 @@ WINE_1.0 wine_cpsymbol_wcstombs; wine_dlclose; wine_dll_enum_load_path; - wine_dll_get_owner; - wine_dll_load; - wine_dll_load_main_exe; wine_dll_set_callback; - wine_dll_unload; wine_dlopen; wine_dlsym; wine_exec_wine_binary; @@ -117,6 +113,10 @@ WINE_1.0 wine_dbg_sprintf; wine_dbgstr_an; wine_dbgstr_wn; + wine_dll_get_owner; + wine_dll_load; + wine_dll_load_main_exe; + wine_dll_unload; wine_pthread_get_functions; wine_pthread_set_functions; wine_switch_to_stack;