netstat: Initial implementation.
[wine] / dlls / msvcp90 / msvcp90_main.c
1 /*
2  * Copyright 2010 Piotr Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22
23 #include "msvcp90.h"
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wine/debug.h"
28
29 WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
30
31 #ifdef __i386__
32
33 #define DEFINE_VTBL_WRAPPER(off)            \
34     __ASM_GLOBAL_FUNC(vtbl_wrapper_ ## off, \
35         "popl %eax\n\t"                     \
36         "popl %ecx\n\t"                     \
37         "pushl %eax\n\t"                    \
38         "movl 0(%ecx), %eax\n\t"            \
39         "jmp *" #off "(%eax)\n\t")
40
41 DEFINE_VTBL_WRAPPER(0);
42 DEFINE_VTBL_WRAPPER(4);
43 DEFINE_VTBL_WRAPPER(8);
44 DEFINE_VTBL_WRAPPER(12);
45 DEFINE_VTBL_WRAPPER(16);
46 DEFINE_VTBL_WRAPPER(20);
47 DEFINE_VTBL_WRAPPER(24);
48 DEFINE_VTBL_WRAPPER(28);
49 DEFINE_VTBL_WRAPPER(32);
50 DEFINE_VTBL_WRAPPER(36);
51 DEFINE_VTBL_WRAPPER(40);
52 DEFINE_VTBL_WRAPPER(44);
53 DEFINE_VTBL_WRAPPER(48);
54 DEFINE_VTBL_WRAPPER(52);
55 DEFINE_VTBL_WRAPPER(56);
56
57 #endif
58
59 void* (__cdecl *MSVCRT_operator_new)(MSVCP_size_t);
60 void (__cdecl *MSVCRT_operator_delete)(void*);
61 void* (__cdecl *MSVCRT_set_new_handler)(void*);
62
63 static void init_cxx_funcs(void)
64 {
65     HMODULE hmod = GetModuleHandleA("msvcrt.dll");
66
67     if (sizeof(void *) > sizeof(int))  /* 64-bit has different names */
68     {
69         MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPEAX_K@Z");
70         MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPEAX@Z");
71         MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AH_K@ZP6AH0@Z@Z");
72     }
73     else
74     {
75         MSVCRT_operator_new = (void*)GetProcAddress(hmod, "??2@YAPAXI@Z");
76         MSVCRT_operator_delete = (void*)GetProcAddress(hmod, "??3@YAXPAX@Z");
77         MSVCRT_set_new_handler = (void*)GetProcAddress(hmod, "?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z");
78     }
79 }
80
81 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
82 {
83     TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
84
85     switch (fdwReason)
86     {
87         case DLL_WINE_PREATTACH:
88             return FALSE;    /* prefer native version */
89         case DLL_PROCESS_ATTACH:
90             init_cxx_funcs();
91             init_lockit();
92             init_exception(hinstDLL);
93             init_locale(hinstDLL);
94             init_io(hinstDLL);
95             break;
96         case DLL_PROCESS_DETACH:
97             free_io();
98             free_locale();
99             free_lockit();
100             break;
101     }
102
103     return TRUE;
104 }
105
106 /* ?_BADOFF@std@@3JB -> long const std::_BADOFF */
107 /* ?_BADOFF@std@@3_JB -> __int64 const std::_BADOFF */
108 const streamoff std_BADOFF = -1;
109
110 /* ?_BADOFF_func@std@@YAABJXZ -> long const & __cdecl std::_BADOFF_func(void) */
111 /* ?_BADOFF_func@std@@YAAEB_JXZ -> __int64 const & __ptr64 __cdecl std::_BADOFF_func(void) */
112 const streamoff * __cdecl std_BADOFF_func(void)
113 {
114     return &std_BADOFF;
115 }
116
117 /* ?_Fpz@std@@3_JA  __int64 std::_Fpz */
118 __int64 std_Fpz = 0;
119
120 /* ?_Fpz_func@std@@YAAA_JXZ -> __int64 & __cdecl std::_Fpz_func(void) */
121 /* ?_Fpz_func@std@@YAAEA_JXZ -> __int64 & __ptr64 __cdecl std::_Fpz_func(void) */
122 __int64 * __cdecl std_Fpz_func(void)
123 {
124     return &std_Fpz;
125 }