ntdll: Also store dynamic loader information in the PEB on Linux.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2017-04-25 16:38:23 +02:00
parent b6d32239d6
commit d3bbd03c8f
4 changed files with 64 additions and 21 deletions

2
configure vendored
View File

@ -6888,6 +6888,7 @@ for ac_header in \
stropts.h \ stropts.h \
sys/asoundlib.h \ sys/asoundlib.h \
sys/attr.h \ sys/attr.h \
sys/auxv.h \
sys/cdio.h \ sys/cdio.h \
sys/elf32.h \ sys/elf32.h \
sys/epoll.h \ sys/epoll.h \
@ -15302,6 +15303,7 @@ for ac_func in \
futimes \ futimes \
futimesat \ futimesat \
getattrlist \ getattrlist \
getauxval \
getopt_long_only \ getopt_long_only \
getpwuid \ getpwuid \
gettimeofday \ gettimeofday \

View File

@ -465,6 +465,7 @@ AC_CHECK_HEADERS(\
stropts.h \ stropts.h \
sys/asoundlib.h \ sys/asoundlib.h \
sys/attr.h \ sys/attr.h \
sys/auxv.h \
sys/cdio.h \ sys/cdio.h \
sys/elf32.h \ sys/elf32.h \
sys/epoll.h \ sys/epoll.h \
@ -2012,6 +2013,7 @@ AC_CHECK_FUNCS(\
futimes \ futimes \
futimesat \ futimesat \
getattrlist \ getattrlist \
getauxval \
getopt_long_only \ getopt_long_only \
getpwuid \ getpwuid \
gettimeofday \ gettimeofday \

View File

@ -185,13 +185,56 @@ done:
return status; return status;
} }
#ifdef __APPLE__ #ifdef __linux__
#ifdef HAVE_ELF_H
# include <elf.h>
#endif
#ifdef HAVE_LINK_H
# include <link.h>
#endif
#ifdef HAVE_SYS_AUXV_H
# include <sys/auxv.h>
#endif
#ifndef HAVE_GETAUXVAL
static unsigned long getauxval( unsigned long id )
{
extern char **__wine_main_environ;
char **ptr = __wine_main_environ;
ElfW(auxv_t) *auxv;
while (*ptr) ptr++;
while (!*ptr) ptr++;
for (auxv = (ElfW(auxv_t) *)ptr; auxv->a_type; auxv++)
if (auxv->a_type == id) return auxv->a_un.a_val;
return 0;
}
#endif
static ULONG_PTR get_image_addr(void)
{
ULONG_PTR size, num, phdr_addr = getauxval( AT_PHDR );
ElfW(Phdr) *phdr;
if (!phdr_addr) return 0;
phdr = (ElfW(Phdr) *)phdr_addr;
size = getauxval( AT_PHENT );
num = getauxval( AT_PHNUM );
while (num--)
{
if (phdr->p_type == PT_PHDR) return phdr_addr - phdr->p_offset;
phdr = (ElfW(Phdr) *)((char *)phdr + size);
}
return 0;
}
#elif defined(__APPLE__)
#include <mach/mach.h> #include <mach/mach.h>
#include <mach/mach_error.h> #include <mach/mach_error.h>
static ULONG64 get_dyld_image_info_addr(void) static ULONG_PTR get_image_addr(void)
{ {
ULONG64 ret = 0; ULONG_PTR ret = 0;
#ifdef TASK_DYLD_INFO #ifdef TASK_DYLD_INFO
struct task_dyld_info dyld_info; struct task_dyld_info dyld_info;
mach_msg_type_number_t size = TASK_DYLD_INFO_COUNT; mach_msg_type_number_t size = TASK_DYLD_INFO_COUNT;
@ -200,7 +243,13 @@ static ULONG64 get_dyld_image_info_addr(void)
#endif #endif
return ret; return ret;
} }
#endif /* __APPLE__ */
#else
static ULONG_PTR get_image_addr(void)
{
return 0;
}
#endif
/*********************************************************************** /***********************************************************************
* thread_init * thread_init
@ -219,9 +268,6 @@ HANDLE thread_init(void)
NTSTATUS status; NTSTATUS status;
struct ntdll_thread_data *thread_data; struct ntdll_thread_data *thread_data;
static struct debug_info debug_info; /* debug info for initial thread */ static struct debug_info debug_info; /* debug info for initial thread */
#ifdef __APPLE__
ULONG64 dyld_image_info;
#endif
virtual_init(); virtual_init();
@ -270,20 +316,7 @@ HANDLE thread_init(void)
InitializeListHead( &ldr.InLoadOrderModuleList ); InitializeListHead( &ldr.InLoadOrderModuleList );
InitializeListHead( &ldr.InMemoryOrderModuleList ); InitializeListHead( &ldr.InMemoryOrderModuleList );
InitializeListHead( &ldr.InInitializationOrderModuleList ); InitializeListHead( &ldr.InInitializationOrderModuleList );
#ifdef __APPLE__ *(ULONG_PTR *)peb->Reserved = get_image_addr();
dyld_image_info = get_dyld_image_info_addr();
#ifdef __LP64__
#ifdef WORDS_BIGENDIAN
peb->Reserved[1] = dyld_image_info & 0xFFFFFFFF;
peb->Reserved[0] = dyld_image_info >> 32;
#else
peb->Reserved[0] = dyld_image_info & 0xFFFFFFFF;
peb->Reserved[1] = dyld_image_info >> 32;
#endif
#else
peb->Reserved[0] = dyld_image_info & 0xFFFFFFFF;
#endif
#endif
/* /*
* Starting with Vista, the first user to log on has session id 1. * Starting with Vista, the first user to log on has session id 1.

View File

@ -201,6 +201,9 @@
/* Define to 1 if you have the `getattrlist' function. */ /* Define to 1 if you have the `getattrlist' function. */
#undef HAVE_GETATTRLIST #undef HAVE_GETATTRLIST
/* Define to 1 if you have the `getauxval' function. */
#undef HAVE_GETAUXVAL
/* Define to 1 if you have the `getnameinfo' function. */ /* Define to 1 if you have the `getnameinfo' function. */
#undef HAVE_GETNAMEINFO #undef HAVE_GETNAMEINFO
@ -1035,6 +1038,9 @@
/* Define to 1 if you have the <sys/attr.h> header file. */ /* Define to 1 if you have the <sys/attr.h> header file. */
#undef HAVE_SYS_ATTR_H #undef HAVE_SYS_ATTR_H
/* Define to 1 if you have the <sys/auxv.h> header file. */
#undef HAVE_SYS_AUXV_H
/* Define to 1 if you have the <sys/cdio.h> header file. */ /* Define to 1 if you have the <sys/cdio.h> header file. */
#undef HAVE_SYS_CDIO_H #undef HAVE_SYS_CDIO_H