2000-10-28 02:53:56 +08:00
|
|
|
/* autoload.cc: all dynamic load stuff.
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
2008-04-08 00:15:45 +08:00
|
|
|
#include "miscfuncs.h"
|
2021-04-06 17:51:21 +08:00
|
|
|
#include <fenv.h>
|
2001-05-16 13:07:51 +08:00
|
|
|
#define USE_SYS_TYPES_FD_SET
|
|
|
|
#include <winsock2.h>
|
|
|
|
|
2008-04-08 00:15:45 +08:00
|
|
|
bool NO_COPY wsock_started;
|
|
|
|
|
2001-05-16 13:07:51 +08:00
|
|
|
/* Macro for defining "auto-load" functions.
|
|
|
|
* Note that this is self-modifying code *gasp*.
|
|
|
|
* The first invocation of a routine will trigger the loading of
|
|
|
|
* the DLL. This will then be followed by the discovery of
|
|
|
|
* the procedure's entry point, which is placed into the location
|
|
|
|
* pointed to by the stack pointer. This code then changes
|
|
|
|
* the "call" operand which invoked it to a "jmp" which will
|
|
|
|
* transfer directly to the DLL function on the next invocation.
|
|
|
|
*
|
|
|
|
* Subsequent calls to routines whose transfer address has not been
|
|
|
|
* determined will skip the "load the dll" step, starting at the
|
|
|
|
* "discovery of the entry point" step.
|
|
|
|
*
|
|
|
|
* So, immediately following the the call to one of the above routines
|
|
|
|
* we have:
|
2013-04-23 17:44:36 +08:00
|
|
|
* DLL info (4/8 bytes) Pointer to a block of information concerning
|
2001-05-16 13:07:51 +08:00
|
|
|
* the DLL (see below).
|
2023-01-17 23:28:01 +08:00
|
|
|
* DLL notimp (2 bytes) Bool value flagging that non-existence of this
|
|
|
|
* function is not a fatal error.
|
|
|
|
* DLL error (2 bytes) Error value returned if function load fails.
|
|
|
|
* Depends on the return type of the function.
|
|
|
|
* Default is 0 == BOOL FALSE or == HANDLE NULL or
|
|
|
|
* == Pointer NULL.
|
2022-07-15 00:32:53 +08:00
|
|
|
* func addr (8 bytes) Address of the actual Win32 function. For the
|
2013-04-23 17:44:36 +08:00
|
|
|
* reason why this is necessary, see the below
|
|
|
|
* description of the load_state.
|
2001-05-16 13:07:51 +08:00
|
|
|
* func name (n bytes) asciz string containing the name of the function
|
|
|
|
* to be loaded.
|
|
|
|
*
|
|
|
|
* The DLL info block consists of the following
|
2013-04-23 17:44:36 +08:00
|
|
|
* load_state (4/8 bytes) Pointer to a word containing the routine used
|
2001-05-16 13:07:51 +08:00
|
|
|
* to eventually invoke the function. Initially
|
2013-04-23 17:44:36 +08:00
|
|
|
* points to an init function which loads the DLL,
|
|
|
|
* gets the process's load address, changes the contents
|
|
|
|
* here to point to the function address, and changes
|
|
|
|
* the address argument of the initial jmp call.
|
2022-07-15 00:32:53 +08:00
|
|
|
* On x86_64, the jmp is not tweaked directly. Rather,
|
2013-04-23 17:44:36 +08:00
|
|
|
* the address of the Win32 function is stored in the
|
|
|
|
* aforementioned Win32 function address slot and fetched
|
|
|
|
* there for a jmp *%rax call. This indirection is
|
|
|
|
* necessary to workaround the lack of a jmp opcode with
|
|
|
|
* offset values > 32 bit. If the initialization has
|
|
|
|
* been done, only the load part is done.
|
|
|
|
* DLL handle (4/8 bytes) The handle to use when loading the DLL.
|
2001-05-16 13:07:51 +08:00
|
|
|
* DLL locker (4 bytes) Word to use to avoid multi-thread access during
|
|
|
|
* initialization.
|
2013-04-23 17:44:36 +08:00
|
|
|
* extra init (4/8 bytes) Extra initialization function.
|
2001-05-16 13:07:51 +08:00
|
|
|
* DLL name (n bytes) asciz string containing the name of the DLL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* LoadDLLprime is used to prime the DLL info information, providing an
|
|
|
|
additional initialization routine to call prior to calling the first
|
|
|
|
function. */
|
2022-06-10 06:42:03 +08:00
|
|
|
#ifdef __x86_64__
|
2013-04-23 17:44:36 +08:00
|
|
|
#define LoadDLLprime(dllname, init_also, no_resolve_on_fork) __asm__ (" \n\
|
|
|
|
.ifndef " #dllname "_primed \n\
|
|
|
|
.section .data_cygwin_nocopy,\"w\" \n\
|
|
|
|
.align 8 \n\
|
|
|
|
."#dllname "_info: \n\
|
|
|
|
.quad _std_dll_init \n\
|
|
|
|
.quad " #no_resolve_on_fork " \n\
|
|
|
|
.long -1 \n\
|
|
|
|
.align 8 \n\
|
|
|
|
.quad " #init_also " \n\
|
|
|
|
.string16 \"" #dllname ".dll\" \n\
|
|
|
|
.text \n\
|
|
|
|
.set " #dllname "_primed, 1 \n\
|
|
|
|
.endif \n\
|
|
|
|
");
|
2022-06-10 06:42:03 +08:00
|
|
|
#else
|
|
|
|
#error unimplemented for this target
|
|
|
|
#endif
|
2001-05-16 13:07:51 +08:00
|
|
|
|
2004-04-18 01:53:29 +08:00
|
|
|
/* Standard DLL load macro. May invoke a fatal error if the function isn't
|
2001-05-16 13:07:51 +08:00
|
|
|
found. */
|
2023-01-17 23:28:01 +08:00
|
|
|
#define LoadDLLfunc(name, dllname) \
|
|
|
|
LoadDLLfuncEx (name, dllname, 0)
|
|
|
|
#define LoadDLLfuncEx(name, dllname, notimp) \
|
|
|
|
LoadDLLfuncEx2(name, dllname, notimp, 0)
|
|
|
|
#define LoadDLLfuncEx2(name, dllname, notimp, err) \
|
|
|
|
LoadDLLfuncEx3(name, dllname, notimp, err, 0)
|
2001-05-16 13:07:51 +08:00
|
|
|
|
|
|
|
/* Main DLL setup stuff. */
|
2022-06-10 06:42:03 +08:00
|
|
|
#ifdef __x86_64__
|
2023-01-17 23:28:01 +08:00
|
|
|
#define LoadDLLfuncEx3(name, dllname, notimp, err, no_resolve_on_fork) \
|
2013-04-23 17:44:36 +08:00
|
|
|
LoadDLLprime (dllname, dll_func_load, no_resolve_on_fork) \
|
|
|
|
__asm__ (" \n\
|
|
|
|
.section ." #dllname "_autoload_text,\"wx\" \n\
|
|
|
|
.global " #name " \n\
|
|
|
|
.global _win32_" #name " \n\
|
|
|
|
.align 16 \n\
|
|
|
|
" #name ": \n\
|
|
|
|
_win32_" #name ": \n\
|
|
|
|
movq 3f(%rip),%rax \n\
|
|
|
|
jmp *%rax \n\
|
|
|
|
1:movq 2f(%rip),%rax \n\
|
|
|
|
push %rbp # Keep 16 byte aligned \n\
|
|
|
|
push %r9 \n\
|
|
|
|
push %r8 \n\
|
|
|
|
push %rdx \n\
|
|
|
|
push %rcx \n\
|
|
|
|
call *(%rax) \n\
|
|
|
|
2:.quad ." #dllname "_info \n\
|
2023-01-17 23:28:01 +08:00
|
|
|
.hword " #notimp " \n\
|
|
|
|
.hword ((" #err ") & 0xffff) \n\
|
2013-04-23 17:44:36 +08:00
|
|
|
3:.quad 1b \n\
|
|
|
|
.asciz \"" #name "\" \n\
|
|
|
|
.text \n\
|
|
|
|
");
|
2022-06-10 06:42:03 +08:00
|
|
|
#else
|
|
|
|
#error unimplemented for this target
|
|
|
|
#endif
|
2001-05-16 13:07:51 +08:00
|
|
|
|
|
|
|
/* DLL loader helper functions used during initialization. */
|
|
|
|
|
|
|
|
/* The function which finds the address, given the name and overwrites
|
|
|
|
the call so that future invocations go straight to the function in
|
|
|
|
the DLL. */
|
|
|
|
extern "C" void dll_func_load () __asm__ ("dll_func_load");
|
|
|
|
|
|
|
|
/* Called by the primary initialization function "init_std_dll" to
|
|
|
|
setup the stack and eliminate future calls to init_std_dll for other
|
|
|
|
functions from this DLL. */
|
|
|
|
extern "C" void dll_chain () __asm__ ("dll_chain");
|
|
|
|
|
2000-10-28 02:53:56 +08:00
|
|
|
extern "C" {
|
|
|
|
|
2022-06-10 06:42:03 +08:00
|
|
|
#ifdef __x86_64__
|
2013-04-23 17:44:36 +08:00
|
|
|
__asm__ (" \n\
|
|
|
|
.section .rdata,\"r\" \n\
|
|
|
|
msg1: \n\
|
|
|
|
.ascii \"couldn't dynamically determine load address for '%s' (handle %p), %E\\0\"\n\
|
|
|
|
\n\
|
|
|
|
.text \n\
|
|
|
|
.p2align 4,,15 \n\
|
|
|
|
noload: \n\
|
|
|
|
movq 40(%rsp),%rdx # Get the address of the information block\n\
|
|
|
|
movl 8(%rdx),%eax # Should we 'ignore' the lack \n\
|
|
|
|
test $1,%eax # of this function? \n\
|
|
|
|
jz 1f # Nope. \n\
|
|
|
|
andl $0xffff0000,%eax# upper word (== desired return value) \n\
|
2023-01-17 23:28:01 +08:00
|
|
|
sarl $16,%eax # swap to low order word \n\
|
2013-04-23 17:44:36 +08:00
|
|
|
movl %eax,32(%rsp) # Save for later (in shadow space) \n\
|
|
|
|
movl $127,%ecx # ERROR_PROC_NOT_FOUND \n\
|
|
|
|
call SetLastError # Set it \n\
|
|
|
|
movl 32(%rsp),%eax # Get back return value \n\
|
|
|
|
addq $40,%rsp # Revert stack \n\
|
|
|
|
pop %r10 # Drop pointer to 'return address' \n\
|
|
|
|
pop %rcx # Restore arg registers \n\
|
|
|
|
pop %rdx \n\
|
|
|
|
pop %r8 \n\
|
|
|
|
pop %r9 \n\
|
|
|
|
pop %rbp # ...and restore frame pointer \n\
|
|
|
|
ret # Return \n\
|
|
|
|
1: \n\
|
|
|
|
movq (%rdx),%rax # Handle value \n\
|
|
|
|
movq 8(%rax),%r8 \n\
|
|
|
|
lea 20(%rdx),%rdx # Location of name of function \n\
|
|
|
|
lea msg1(%rip),%rcx # The message \n\
|
|
|
|
call api_fatal # Print message. Never returns \n\
|
|
|
|
\n\
|
|
|
|
.globl dll_func_load \n\
|
|
|
|
dll_func_load: \n\
|
|
|
|
movq (%rsp),%rdx # 'Return address' contains load info \n\
|
|
|
|
movq (%rdx),%rcx # Where handle lives \n\
|
|
|
|
movq 8(%rcx),%rcx # Address of Handle to DLL \n\
|
|
|
|
addq $20,%rdx # Address of name of function to load \n\
|
|
|
|
subq $40,%rsp # Shadow space + 8 byte for alignment \n\
|
|
|
|
call GetProcAddress # Load it \n\
|
|
|
|
test %rax,%rax # Success? \n\
|
|
|
|
jne gotit # Yes \n\
|
|
|
|
jmp noload # Issue an error or return \n\
|
|
|
|
gotit: \n\
|
|
|
|
addq $40,%rsp # Revert stack \n\
|
2020-03-11 20:23:55 +08:00
|
|
|
pop %r10 # Pointer to 'return address' \n\
|
2013-04-23 17:44:36 +08:00
|
|
|
movq %rax,12(%r10) # Move absolute address to address slot \n\
|
|
|
|
subq $25,%r10 # Point to jmp \n\
|
|
|
|
pop %rcx # Restore arg registers \n\
|
|
|
|
pop %rdx \n\
|
|
|
|
pop %r8 \n\
|
|
|
|
pop %r9 \n\
|
|
|
|
pop %rbp # ...and restore frame pointer \n\
|
|
|
|
jmp *%r10 # Jump to actual function \n\
|
|
|
|
\n\
|
|
|
|
.global dll_chain \n\
|
|
|
|
dll_chain: \n\
|
|
|
|
push %rax # Restore 'return address' \n\
|
|
|
|
jmp *%rdx # Jump to next init function \n\
|
|
|
|
");
|
2022-06-10 06:42:03 +08:00
|
|
|
#else
|
|
|
|
#error unimplemented for this target
|
|
|
|
#endif
|
2001-05-16 13:07:51 +08:00
|
|
|
|
|
|
|
/* C representations of the two info blocks described above.
|
|
|
|
FIXME: These structures confuse gdb for some reason. GDB can print
|
|
|
|
the whole structure but has problems with the name field? */
|
|
|
|
struct dll_info
|
2000-10-28 02:53:56 +08:00
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
UINT_PTR load_state;
|
2001-05-16 13:07:51 +08:00
|
|
|
HANDLE handle;
|
|
|
|
LONG here;
|
|
|
|
void (*init) ();
|
2010-08-28 16:51:21 +08:00
|
|
|
WCHAR name[];
|
2000-10-28 02:53:56 +08:00
|
|
|
};
|
|
|
|
|
2001-05-16 13:07:51 +08:00
|
|
|
struct func_info
|
|
|
|
{
|
|
|
|
struct dll_info *dll;
|
|
|
|
LONG decoration;
|
2013-04-23 17:44:36 +08:00
|
|
|
UINT_PTR func_addr;
|
2001-05-16 13:07:51 +08:00
|
|
|
char name[];
|
|
|
|
};
|
2000-10-28 02:53:56 +08:00
|
|
|
|
2001-05-16 13:07:51 +08:00
|
|
|
/* Mechanism for setting up info for passing to dll_chain routines. */
|
2013-04-23 17:44:36 +08:00
|
|
|
typedef __uint128_t two_addr_t;
|
2001-05-16 13:07:51 +08:00
|
|
|
union retchain
|
|
|
|
{
|
2013-04-23 17:44:36 +08:00
|
|
|
struct {uintptr_t high; uintptr_t low;};
|
|
|
|
two_addr_t ll;
|
2001-05-16 13:07:51 +08:00
|
|
|
};
|
|
|
|
|
2016-01-12 22:23:14 +08:00
|
|
|
/* This function handles the problem described here:
|
|
|
|
|
|
|
|
http://www.microsoft.com/technet/security/advisory/2269637.mspx
|
2016-06-24 21:42:06 +08:00
|
|
|
https://msdn.microsoft.com/library/ff919712 */
|
2011-03-01 04:55:10 +08:00
|
|
|
static __inline bool
|
2016-01-12 22:23:14 +08:00
|
|
|
dll_load (HANDLE& handle, PWCHAR name)
|
2011-02-27 07:30:33 +08:00
|
|
|
{
|
2016-01-12 22:45:17 +08:00
|
|
|
HANDLE h = NULL;
|
2016-01-27 22:43:15 +08:00
|
|
|
WCHAR dll_path[MAX_PATH];
|
2016-01-12 22:23:14 +08:00
|
|
|
|
2016-06-24 21:42:06 +08:00
|
|
|
/* Try loading with full path, which sometimes fails for no good reason. */
|
2016-01-27 22:43:15 +08:00
|
|
|
wcpcpy (wcpcpy (dll_path, windows_system_directory), name);
|
|
|
|
h = LoadLibraryW (dll_path);
|
2016-06-24 21:42:06 +08:00
|
|
|
/* If it failed, try loading just by name. */
|
2016-01-12 22:23:14 +08:00
|
|
|
if (!h)
|
2016-01-27 22:43:15 +08:00
|
|
|
h = LoadLibraryW (name);
|
2011-03-01 04:55:10 +08:00
|
|
|
if (!h)
|
|
|
|
return false;
|
|
|
|
handle = h;
|
|
|
|
return true;
|
2011-02-27 07:30:33 +08:00
|
|
|
}
|
|
|
|
|
2010-12-10 00:50:36 +08:00
|
|
|
#define RETRY_COUNT 10
|
|
|
|
|
2001-05-16 13:07:51 +08:00
|
|
|
/* The standard DLL initialization routine. */
|
2022-06-10 06:42:03 +08:00
|
|
|
#ifdef __x86_64__
|
2013-04-23 17:44:36 +08:00
|
|
|
|
|
|
|
/* On x86_64, we need assembler wrappers for std_dll_init and wsock_init.
|
|
|
|
In the x86_64 ABI it's no safe bet that frame[1] (aka 8(%rbp)) contains
|
|
|
|
the return address. Consequentially, if we try to overwrite frame[1]
|
|
|
|
with the address of dll_chain, we end up with a scrambled stack, the
|
|
|
|
result depending on the optimization settings and the current frame of
|
|
|
|
mind of the compiler. So for x86_64, we disable overwriting the return
|
|
|
|
address in the real std_dll_init/wsock_init function, but rather do this
|
|
|
|
in the wrapper, after return from the function, when we exactly know
|
|
|
|
where the original return address is stored on the stack. */
|
|
|
|
|
|
|
|
#define INIT_WRAPPER(func) \
|
|
|
|
__asm__ (" \n\
|
|
|
|
.text \n\
|
|
|
|
.p2align 4,,15 \n\
|
|
|
|
.seh_proc _" #func " \n\
|
|
|
|
_" #func ": \n\
|
|
|
|
pushq %rbp \n\
|
|
|
|
.seh_pushreg %rbp \n\
|
|
|
|
movq %rsp,%rbp \n\
|
|
|
|
.seh_setframe %rbp,0 \n\
|
|
|
|
subq $0x20,%rsp \n\
|
|
|
|
.seh_stackalloc 32 \n\
|
|
|
|
.seh_endprologue \n\
|
|
|
|
movq 0x28(%rsp),%rcx # return address as parameter \n\
|
|
|
|
call " #func " \n\
|
|
|
|
movdqa %xmm0,0x10(%rsp) # 128 bit return value in xmm0 \n\
|
|
|
|
movq 0x10(%rsp),%rax # copy over to %rax and %rdx \n\
|
|
|
|
movq 0x18(%rsp),%rdx \n\
|
|
|
|
leaq dll_chain(%rip),%rcx # load address of dll_chain \n\
|
|
|
|
movq %rcx,0x28(%rsp) # and overwrite return address \n\
|
|
|
|
addq $0x20,%rsp \n\
|
|
|
|
popq %rbp \n\
|
|
|
|
ret \n\
|
|
|
|
.seh_endproc \n\
|
|
|
|
");
|
|
|
|
|
|
|
|
INIT_WRAPPER (std_dll_init)
|
|
|
|
|
2022-06-10 06:42:03 +08:00
|
|
|
#else
|
|
|
|
#error unimplemented for this target
|
|
|
|
#endif
|
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
__attribute__ ((used, noinline)) static two_addr_t
|
|
|
|
std_dll_init (struct func_info *func)
|
2000-10-28 02:53:56 +08:00
|
|
|
{
|
2001-05-16 13:07:51 +08:00
|
|
|
struct dll_info *dll = func->dll;
|
|
|
|
retchain ret;
|
|
|
|
|
|
|
|
if (InterlockedIncrement (&dll->here))
|
|
|
|
do
|
|
|
|
{
|
|
|
|
InterlockedDecrement (&dll->here);
|
2010-03-13 07:13:48 +08:00
|
|
|
yield ();
|
2001-05-16 13:07:51 +08:00
|
|
|
}
|
|
|
|
while (InterlockedIncrement (&dll->here));
|
2011-02-27 07:30:33 +08:00
|
|
|
else if ((uintptr_t) dll->handle <= 1)
|
2001-05-16 13:07:51 +08:00
|
|
|
{
|
winsup/cygwin/ChangeLog:
* Makefile.in (DLL_OFILES): Add new fenv.o module.
(fenv_CFLAGS): New flags definition for fenv.o compile.
* autoload.cc (std_dll_init): Use fenv.h functions instead of direct
manipulation of x87 FPU registers.
* crt0.c (mainCRTStartup): Likewise.
* cygwin.din (feclearexcept, fegetexceptflag, feraiseexcept,
fesetexceptflag, fetestexcept, fegetround, fesetround, fegetenv,
feholdexcept, fesetenv, feupdateenv, fegetprec, fesetprec,
feenableexcept, fedisableexcept, fegetexcept, _feinitialise,
_fe_dfl_env, _fe_nomask_env): Export new functions and data items.
* fenv.cc: New file.
* posix.sgml: Update status of newly-implemented APIs.
* include/fenv.h: Likewise related header.
* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
2010-09-11 14:53:28 +08:00
|
|
|
fenv_t fpuenv;
|
|
|
|
fegetenv (&fpuenv);
|
2010-12-10 00:50:36 +08:00
|
|
|
DWORD err = ERROR_SUCCESS;
|
2011-02-27 07:30:33 +08:00
|
|
|
int i;
|
2010-10-02 05:53:11 +08:00
|
|
|
/* MSDN seems to imply that LoadLibrary can fail mysteriously, so,
|
|
|
|
since there have been reports of this in the mailing list, retry
|
2010-12-10 00:50:36 +08:00
|
|
|
several times before giving up. */
|
2011-02-27 07:30:33 +08:00
|
|
|
for (i = 1; i <= RETRY_COUNT; i++)
|
2010-12-10 00:50:36 +08:00
|
|
|
{
|
|
|
|
/* If loading the library succeeds, just leave the loop. */
|
2016-01-12 22:23:14 +08:00
|
|
|
if (dll_load (dll->handle, dll->name))
|
2010-12-10 00:50:36 +08:00
|
|
|
break;
|
|
|
|
/* Otherwise check error code returned by LoadLibrary. If the
|
|
|
|
error code is neither NOACCESS nor DLL_INIT_FAILED, break out
|
|
|
|
of the loop. */
|
|
|
|
err = GetLastError ();
|
|
|
|
if (err != ERROR_NOACCESS && err != ERROR_DLL_INIT_FAILED)
|
|
|
|
break;
|
|
|
|
if (i < RETRY_COUNT)
|
|
|
|
yield ();
|
|
|
|
}
|
2011-02-27 07:30:33 +08:00
|
|
|
if ((uintptr_t) dll->handle <= 1)
|
2010-12-10 00:50:36 +08:00
|
|
|
{
|
2016-01-12 22:23:14 +08:00
|
|
|
if ((func->decoration & 1))
|
2010-12-10 00:50:36 +08:00
|
|
|
dll->handle = INVALID_HANDLE_VALUE;
|
|
|
|
else
|
2016-01-12 22:23:14 +08:00
|
|
|
api_fatal ("unable to load %W, %E", dll->name);
|
2010-12-10 00:50:36 +08:00
|
|
|
}
|
2010-09-26 03:57:34 +08:00
|
|
|
fesetenv (&fpuenv);
|
2001-05-16 13:07:51 +08:00
|
|
|
}
|
|
|
|
|
2010-10-02 05:53:11 +08:00
|
|
|
/* Set "arguments" for dll_chain. */
|
2013-04-23 17:44:36 +08:00
|
|
|
ret.low = (uintptr_t) dll->init;
|
|
|
|
ret.high = (uintptr_t) func;
|
2010-09-25 03:53:18 +08:00
|
|
|
|
2001-05-16 13:07:51 +08:00
|
|
|
InterlockedDecrement (&dll->here);
|
|
|
|
return ret.ll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialization function for winsock stuff. */
|
2013-04-23 17:44:36 +08:00
|
|
|
|
2022-06-10 06:42:03 +08:00
|
|
|
#ifdef __x86_64__
|
2013-04-23 17:44:36 +08:00
|
|
|
/* See above comment preceeding std_dll_init. */
|
|
|
|
INIT_WRAPPER (wsock_init)
|
2022-06-10 06:42:03 +08:00
|
|
|
#else
|
|
|
|
#error unimplemented for this target
|
|
|
|
#endif
|
2013-04-23 17:44:36 +08:00
|
|
|
|
|
|
|
__attribute__ ((used, noinline)) static two_addr_t
|
|
|
|
wsock_init (struct func_info *func)
|
2001-05-16 13:07:51 +08:00
|
|
|
{
|
2016-03-10 05:55:28 +08:00
|
|
|
/* CV 2016-03-09: Moved wsadata into wsock_init to workaround a problem
|
|
|
|
with the NO_COPY definition of wsadata and here starting with gcc-5.3.0.
|
|
|
|
See the git log for a description. */
|
|
|
|
static WSADATA NO_COPY wsadata;
|
2001-05-16 13:07:51 +08:00
|
|
|
static LONG NO_COPY here = -1L;
|
|
|
|
struct dll_info *dll = func->dll;
|
|
|
|
|
2001-05-05 05:02:15 +08:00
|
|
|
while (InterlockedIncrement (&here))
|
2000-10-28 02:53:56 +08:00
|
|
|
{
|
2001-05-05 05:02:15 +08:00
|
|
|
InterlockedDecrement (&here);
|
2010-03-13 07:13:48 +08:00
|
|
|
yield ();
|
2000-10-28 02:53:56 +08:00
|
|
|
}
|
|
|
|
|
2004-04-16 01:38:02 +08:00
|
|
|
if (!wsock_started)
|
2001-05-16 13:07:51 +08:00
|
|
|
{
|
2022-08-05 02:53:59 +08:00
|
|
|
int (*wsastartup) (int, WSADATA *);
|
2000-10-28 02:53:56 +08:00
|
|
|
|
2005-03-03 23:12:50 +08:00
|
|
|
/* Don't use autoload to load WSAStartup to eliminate recursion. */
|
2022-08-05 02:53:59 +08:00
|
|
|
wsastartup = (int (*)(int, WSADATA *))
|
2001-09-08 05:32:07 +08:00
|
|
|
GetProcAddress ((HMODULE) (dll->handle), "WSAStartup");
|
2001-05-16 13:07:51 +08:00
|
|
|
if (wsastartup)
|
2001-09-08 05:32:07 +08:00
|
|
|
{
|
2016-01-12 22:25:15 +08:00
|
|
|
int res = wsastartup (MAKEWORD (2, 2), &wsadata);
|
2000-10-28 02:53:56 +08:00
|
|
|
|
2001-05-16 13:07:51 +08:00
|
|
|
debug_printf ("res %d", res);
|
|
|
|
debug_printf ("wVersion %d", wsadata.wVersion);
|
|
|
|
debug_printf ("wHighVersion %d", wsadata.wHighVersion);
|
|
|
|
debug_printf ("szDescription %s", wsadata.szDescription);
|
|
|
|
debug_printf ("szSystemStatus %s", wsadata.szSystemStatus);
|
|
|
|
debug_printf ("iMaxSockets %d", wsadata.iMaxSockets);
|
|
|
|
debug_printf ("iMaxUdpDg %d", wsadata.iMaxUdpDg);
|
2001-03-22 11:42:08 +08:00
|
|
|
|
2001-05-16 13:07:51 +08:00
|
|
|
wsock_started = 1;
|
2001-09-08 05:32:07 +08:00
|
|
|
}
|
2001-05-16 13:07:51 +08:00
|
|
|
}
|
2004-06-22 12:00:16 +08:00
|
|
|
InterlockedDecrement (&here);
|
2001-10-13 09:35:15 +08:00
|
|
|
volatile retchain ret;
|
2004-04-16 01:38:02 +08:00
|
|
|
/* Set "arguments for dll_chain. */
|
2013-04-23 17:44:36 +08:00
|
|
|
ret.low = (uintptr_t) dll_func_load;
|
|
|
|
ret.high = (uintptr_t) func;
|
2001-05-16 13:07:51 +08:00
|
|
|
return ret.ll;
|
2001-04-16 11:27:16 +08:00
|
|
|
}
|
|
|
|
|
2011-02-27 07:30:33 +08:00
|
|
|
LoadDLLprime (ws2_32, _wsock_init, 0)
|
2001-05-16 13:07:51 +08:00
|
|
|
|
2023-01-17 23:28:01 +08:00
|
|
|
LoadDLLfunc (CheckTokenMembership, advapi32)
|
|
|
|
LoadDLLfunc (CreateProcessAsUserW, advapi32)
|
|
|
|
LoadDLLfunc (DeregisterEventSource, advapi32)
|
|
|
|
LoadDLLfunc (DecryptFileW, advapi32)
|
|
|
|
LoadDLLfunc (EncryptFileW, advapi32)
|
|
|
|
LoadDLLfunc (LogonUserW, advapi32)
|
|
|
|
LoadDLLfunc (LookupAccountNameW, advapi32)
|
|
|
|
LoadDLLfunc (LookupAccountSidW, advapi32)
|
|
|
|
LoadDLLfunc (LsaClose, advapi32)
|
|
|
|
LoadDLLfunc (LsaEnumerateAccountRights, advapi32)
|
|
|
|
LoadDLLfunc (LsaFreeMemory, advapi32)
|
|
|
|
LoadDLLfunc (LsaLookupSids, advapi32)
|
|
|
|
LoadDLLfunc (LsaOpenPolicy, advapi32)
|
|
|
|
LoadDLLfunc (LsaQueryInformationPolicy, advapi32)
|
|
|
|
LoadDLLfunc (LsaRetrievePrivateData, advapi32)
|
|
|
|
LoadDLLfunc (LsaStorePrivateData, advapi32)
|
|
|
|
LoadDLLfunc (RegOpenUserClassesRoot, advapi32)
|
|
|
|
LoadDLLfunc (RegOpenCurrentUser, advapi32)
|
|
|
|
LoadDLLfunc (RegCloseKey, advapi32)
|
|
|
|
LoadDLLfunc (RegCreateKeyExW, advapi32)
|
|
|
|
LoadDLLfunc (RegEnumKeyExW, advapi32)
|
|
|
|
LoadDLLfunc (RegEnumValueW, advapi32)
|
|
|
|
LoadDLLfunc (RegGetKeySecurity, advapi32)
|
|
|
|
LoadDLLfunc (RegOpenKeyExW, advapi32)
|
|
|
|
LoadDLLfunc (RegQueryInfoKeyW, advapi32)
|
|
|
|
LoadDLLfunc (RegQueryValueExW, advapi32)
|
|
|
|
LoadDLLfunc (RegisterEventSourceW, advapi32)
|
|
|
|
LoadDLLfunc (ReportEventW, advapi32)
|
|
|
|
LoadDLLfunc (SystemFunction036, advapi32) /* Aka "RtlGenRandom" */
|
|
|
|
|
|
|
|
LoadDLLfunc (AuthzAccessCheck, authz)
|
|
|
|
LoadDLLfunc (AuthzFreeContext, authz)
|
|
|
|
LoadDLLfunc (AuthzInitializeContextFromSid, authz)
|
|
|
|
LoadDLLfunc (AuthzInitializeContextFromToken, authz)
|
|
|
|
LoadDLLfunc (AuthzInitializeResourceManager, authz)
|
|
|
|
|
|
|
|
LoadDLLfunc (DnsQuery_A, dnsapi)
|
|
|
|
LoadDLLfunc (DnsFree, dnsapi)
|
|
|
|
|
|
|
|
LoadDLLfunc (GetAdaptersAddresses, iphlpapi)
|
|
|
|
LoadDLLfunc (GetIfEntry, iphlpapi)
|
|
|
|
LoadDLLfunc (GetIpAddrTable, iphlpapi)
|
|
|
|
LoadDLLfunc (GetIpForwardTable, iphlpapi)
|
|
|
|
LoadDLLfunc (GetNetworkParams, iphlpapi)
|
|
|
|
LoadDLLfunc (GetTcpTable, iphlpapi)
|
|
|
|
LoadDLLfunc (GetTcp6Table, iphlpapi)
|
|
|
|
LoadDLLfunc (GetUdpTable, iphlpapi)
|
|
|
|
LoadDLLfunc (if_indextoname, iphlpapi)
|
|
|
|
LoadDLLfunc (if_nametoindex, iphlpapi)
|
|
|
|
|
2023-12-01 04:14:48 +08:00
|
|
|
LoadDLLfuncEx2 (DiscardVirtualMemory, kernel32, 1, 127)
|
2023-01-17 23:28:01 +08:00
|
|
|
LoadDLLfuncEx (ClosePseudoConsole, kernel32, 1)
|
|
|
|
LoadDLLfuncEx (CreatePseudoConsole, kernel32, 1)
|
|
|
|
LoadDLLfuncEx (IsWow64Process2, kernel32, 1)
|
|
|
|
LoadDLLfuncEx (ResizePseudoConsole, kernel32, 1)
|
2010-09-26 03:57:34 +08:00
|
|
|
|
2018-11-27 20:47:02 +08:00
|
|
|
/* MSDN claims these are exported by kernel32.dll, but only
|
|
|
|
QueryUnbiasedInterruptTime actually is. The others are only
|
|
|
|
available via KernelBase.dll. */
|
2023-01-17 23:28:01 +08:00
|
|
|
LoadDLLfunc (QueryInterruptTime, KernelBase)
|
|
|
|
LoadDLLfunc (QueryInterruptTimePrecise, KernelBase)
|
|
|
|
LoadDLLfunc (QueryUnbiasedInterruptTimePrecise, KernelBase)
|
|
|
|
LoadDLLfuncEx (SetThreadDescription, KernelBase, 1)
|
|
|
|
LoadDLLfunc (VirtualAlloc2, KernelBase)
|
|
|
|
|
|
|
|
LoadDLLfunc (NtMapViewOfSectionEx, ntdll)
|
|
|
|
|
|
|
|
LoadDLLfunc (ldap_bind_s, wldap32)
|
|
|
|
LoadDLLfunc (ldap_count_entries, wldap32)
|
|
|
|
LoadDLLfunc (ldap_count_valuesW, wldap32)
|
|
|
|
LoadDLLfunc (ldap_first_entry, wldap32)
|
|
|
|
LoadDLLfunc (ldap_get_next_page_s, wldap32)
|
|
|
|
LoadDLLfunc (ldap_get_valuesW, wldap32)
|
|
|
|
LoadDLLfunc (ldap_get_values_lenW, wldap32)
|
|
|
|
LoadDLLfunc (ldap_initW, wldap32)
|
|
|
|
LoadDLLfunc (ldap_msgfree, wldap32)
|
|
|
|
LoadDLLfunc (ldap_next_entry, wldap32)
|
|
|
|
LoadDLLfunc (ldap_search_abandon_page, wldap32)
|
|
|
|
LoadDLLfunc (ldap_search_init_pageW, wldap32)
|
|
|
|
LoadDLLfunc (ldap_search_sW, wldap32)
|
|
|
|
LoadDLLfunc (ldap_set_option, wldap32)
|
|
|
|
LoadDLLfunc (ldap_sslinitW, wldap32)
|
|
|
|
LoadDLLfunc (ldap_unbind, wldap32)
|
|
|
|
LoadDLLfunc (ldap_value_freeW, wldap32)
|
|
|
|
LoadDLLfunc (ldap_value_free_len, wldap32)
|
|
|
|
LoadDLLfunc (LdapGetLastError, wldap32)
|
|
|
|
LoadDLLfunc (LdapMapErrorToWin32, wldap32)
|
|
|
|
|
|
|
|
LoadDLLfunc (WNetCloseEnum, mpr)
|
|
|
|
LoadDLLfunc (WNetEnumResourceW, mpr)
|
|
|
|
LoadDLLfunc (WNetGetLastErrorW, mpr)
|
|
|
|
LoadDLLfunc (WNetGetProviderNameW, mpr)
|
|
|
|
LoadDLLfunc (WNetGetResourceInformationW, mpr)
|
|
|
|
LoadDLLfunc (WNetOpenEnumW, mpr)
|
|
|
|
|
|
|
|
LoadDLLfunc (DsEnumerateDomainTrustsW, netapi32)
|
|
|
|
LoadDLLfunc (DsGetDcNameW, netapi32)
|
|
|
|
LoadDLLfunc (NetApiBufferFree, netapi32)
|
|
|
|
LoadDLLfunc (NetGroupEnum, netapi32)
|
|
|
|
LoadDLLfunc (NetLocalGroupEnum, netapi32)
|
|
|
|
LoadDLLfunc (NetLocalGroupGetInfo, netapi32)
|
|
|
|
LoadDLLfunc (NetUseGetInfo, netapi32)
|
|
|
|
LoadDLLfunc (NetUserEnum, netapi32)
|
|
|
|
LoadDLLfunc (NetUserGetGroups, netapi32)
|
|
|
|
LoadDLLfunc (NetUserGetInfo, netapi32)
|
|
|
|
LoadDLLfunc (NetUserGetLocalGroups, netapi32)
|
|
|
|
|
|
|
|
LoadDLLfunc (CoTaskMemFree, ole32)
|
|
|
|
|
|
|
|
LoadDLLfunc (LsaConnectUntrusted, secur32)
|
|
|
|
LoadDLLfunc (LsaDeregisterLogonProcess, secur32)
|
|
|
|
LoadDLLfunc (LsaFreeReturnBuffer, secur32)
|
|
|
|
LoadDLLfunc (LsaLogonUser, secur32)
|
|
|
|
LoadDLLfunc (LsaLookupAuthenticationPackage, secur32)
|
|
|
|
LoadDLLfunc (LsaRegisterLogonProcess, secur32)
|
|
|
|
LoadDLLfunc (TranslateNameW, secur32)
|
|
|
|
|
|
|
|
LoadDLLfunc (SHGetDesktopFolder, shell32)
|
|
|
|
|
|
|
|
LoadDLLfunc (CreateFontW, gdi32)
|
|
|
|
LoadDLLfunc (DeleteObject, gdi32)
|
|
|
|
LoadDLLfunc (EnumFontFamiliesExW, gdi32)
|
|
|
|
LoadDLLfunc (GetGlyphIndicesW, gdi32)
|
|
|
|
LoadDLLfunc (SelectObject, gdi32)
|
|
|
|
|
|
|
|
LoadDLLfunc (CloseClipboard, user32)
|
|
|
|
LoadDLLfunc (CloseDesktop, user32)
|
|
|
|
LoadDLLfunc (CloseWindowStation, user32)
|
|
|
|
LoadDLLfunc (CreateDesktopW, user32)
|
|
|
|
LoadDLLfunc (CreateWindowExW, user32)
|
|
|
|
LoadDLLfunc (CreateWindowStationW, user32)
|
|
|
|
LoadDLLfunc (DefWindowProcW, user32)
|
|
|
|
LoadDLLfunc (DestroyWindow, user32)
|
|
|
|
LoadDLLfunc (DispatchMessageW, user32)
|
|
|
|
LoadDLLfunc (EmptyClipboard, user32)
|
|
|
|
LoadDLLfunc (EnumWindows, user32)
|
|
|
|
LoadDLLfunc (GetClipboardData, user32)
|
|
|
|
LoadDLLfunc (GetDC, user32)
|
|
|
|
LoadDLLfunc (GetForegroundWindow, user32)
|
|
|
|
LoadDLLfunc (GetKeyboardLayout, user32)
|
|
|
|
LoadDLLfunc (GetMessageW, user32)
|
|
|
|
LoadDLLfunc (GetPriorityClipboardFormat, user32)
|
|
|
|
LoadDLLfunc (GetProcessWindowStation, user32)
|
|
|
|
LoadDLLfunc (GetThreadDesktop, user32)
|
|
|
|
LoadDLLfunc (GetUserObjectInformationW, user32)
|
|
|
|
LoadDLLfunc (GetWindowThreadProcessId, user32)
|
|
|
|
LoadDLLfunc (MessageBeep, user32)
|
|
|
|
LoadDLLfunc (MessageBoxW, user32)
|
|
|
|
LoadDLLfunc (MsgWaitForMultipleObjectsEx, user32)
|
|
|
|
LoadDLLfunc (OpenClipboard, user32)
|
|
|
|
LoadDLLfunc (PeekMessageW, user32)
|
|
|
|
LoadDLLfunc (PostMessageW, user32)
|
|
|
|
LoadDLLfunc (PostQuitMessage, user32)
|
|
|
|
LoadDLLfunc (RegisterClassW, user32)
|
|
|
|
LoadDLLfunc (RegisterClipboardFormatW, user32)
|
|
|
|
LoadDLLfunc (SendNotifyMessageW, user32)
|
|
|
|
LoadDLLfunc (SetClipboardData, user32)
|
|
|
|
LoadDLLfunc (SetParent, user32)
|
|
|
|
LoadDLLfunc (SetProcessWindowStation, user32)
|
|
|
|
LoadDLLfunc (SetThreadDesktop, user32)
|
|
|
|
LoadDLLfunc (UnregisterClassW, user32)
|
|
|
|
|
|
|
|
LoadDLLfuncEx (CreateEnvironmentBlock, userenv, 1)
|
|
|
|
LoadDLLfuncEx2 (CreateProfile, userenv, 1, 1)
|
|
|
|
LoadDLLfunc (DestroyEnvironmentBlock, userenv)
|
|
|
|
LoadDLLfunc (LoadUserProfileW, userenv)
|
|
|
|
|
|
|
|
LoadDLLfuncEx3 (waveInAddBuffer, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveInClose, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveInGetNumDevs, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveInOpen, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveInPrepareHeader, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveInReset, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveInStart, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveInUnprepareHeader, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveOutClose, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveOutGetNumDevs, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveOutGetVolume, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveOutOpen, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveOutPrepareHeader, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveOutReset, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveOutSetVolume, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveOutUnprepareHeader, winmm, 1, 0, 1)
|
|
|
|
LoadDLLfuncEx3 (waveOutWrite, winmm, 1, 0, 1)
|
|
|
|
|
|
|
|
LoadDLLfunc (accept, ws2_32)
|
|
|
|
LoadDLLfunc (bind, ws2_32)
|
|
|
|
LoadDLLfunc (closesocket, ws2_32)
|
|
|
|
LoadDLLfunc (connect, ws2_32)
|
|
|
|
LoadDLLfunc (FreeAddrInfoW, ws2_32)
|
|
|
|
LoadDLLfunc (GetAddrInfoW, ws2_32)
|
|
|
|
LoadDLLfunc (GetNameInfoW, ws2_32)
|
|
|
|
LoadDLLfunc (gethostbyaddr, ws2_32)
|
|
|
|
LoadDLLfunc (gethostbyname, ws2_32)
|
|
|
|
LoadDLLfunc (gethostname, ws2_32)
|
|
|
|
LoadDLLfunc (getpeername, ws2_32)
|
|
|
|
LoadDLLfunc (getprotobyname, ws2_32)
|
|
|
|
LoadDLLfunc (getprotobynumber, ws2_32)
|
|
|
|
LoadDLLfunc (getservbyname, ws2_32)
|
|
|
|
LoadDLLfunc (getservbyport, ws2_32)
|
|
|
|
LoadDLLfunc (getsockname, ws2_32)
|
|
|
|
LoadDLLfunc (getsockopt, ws2_32)
|
|
|
|
LoadDLLfunc (ioctlsocket, ws2_32)
|
|
|
|
LoadDLLfunc (listen, ws2_32)
|
|
|
|
LoadDLLfunc (setsockopt, ws2_32)
|
|
|
|
LoadDLLfunc (shutdown, ws2_32)
|
|
|
|
LoadDLLfunc (socket, ws2_32)
|
|
|
|
LoadDLLfunc (WSAAsyncSelect, ws2_32)
|
|
|
|
LoadDLLfunc (WSADuplicateSocketW, ws2_32)
|
|
|
|
LoadDLLfunc (WSAEnumNetworkEvents, ws2_32)
|
|
|
|
LoadDLLfunc (WSAEventSelect, ws2_32)
|
|
|
|
LoadDLLfunc (WSAGetLastError, ws2_32)
|
|
|
|
LoadDLLfunc (WSAIoctl, ws2_32)
|
|
|
|
LoadDLLfunc (WSARecv, ws2_32)
|
|
|
|
LoadDLLfunc (WSARecvFrom, ws2_32)
|
|
|
|
LoadDLLfunc (WSASendMsg, ws2_32)
|
|
|
|
LoadDLLfunc (WSASendTo, ws2_32)
|
|
|
|
LoadDLLfunc (WSASetLastError, ws2_32)
|
|
|
|
LoadDLLfunc (WSASocketW, ws2_32)
|
|
|
|
// LoadDLLfunc (WSAStartup, ws2_32)
|
|
|
|
LoadDLLfunc (WSAWaitForMultipleEvents, ws2_32)
|
|
|
|
|
|
|
|
LoadDLLfunc (PdhAddEnglishCounterW, pdh)
|
|
|
|
LoadDLLfunc (PdhCollectQueryData, pdh)
|
|
|
|
LoadDLLfunc (PdhGetFormattedCounterValue, pdh)
|
|
|
|
LoadDLLfunc (PdhOpenQueryW, pdh)
|
2000-10-28 02:53:56 +08:00
|
|
|
}
|