2 * Copyright 2021 Piotr Caban for CodeWeavers
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.
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.
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
25 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(concrt
);
30 CREATE_TYPE_INFO_VTABLE
31 CREATE_EXCEPTION_OBJECT(exception
)
33 static HMODULE msvcp140
;
35 extern const vtable_ptr exception_vtable
;
37 int CDECL
_callnewh(size_t size
);
38 void (__cdecl
*_Xmem
)(void);
39 void (__cdecl
*_Xout_of_range
)(const char*);
41 void* __cdecl
operator_new(size_t size
)
48 retval
= malloc(size
);
51 TRACE("(%Iu) returning %p\n", size
, retval
);
54 freed
= _callnewh(size
);
57 TRACE("(%Iu) out of memory\n", size
);
62 void __cdecl
operator_delete(void *mem
)
67 typedef exception runtime_error
;
68 extern const vtable_ptr runtime_error_vtable
;
70 DEFINE_THISCALL_WRAPPER(runtime_error_copy_ctor
,8)
71 runtime_error
* __thiscall
runtime_error_copy_ctor(runtime_error
*this, const runtime_error
*rhs
)
73 return __exception_copy_ctor(this, rhs
, &runtime_error_vtable
);
76 typedef exception range_error
;
77 extern const vtable_ptr range_error_vtable
;
79 DEFINE_THISCALL_WRAPPER(range_error_copy_ctor
,8)
80 range_error
* __thiscall
range_error_copy_ctor(range_error
*this, const range_error
*rhs
)
82 return __exception_copy_ctor(this, rhs
, &range_error_vtable
);
85 __ASM_BLOCK_BEGIN(vtables
)
86 __ASM_VTABLE(runtime_error
,
87 VTABLE_ADD_FUNC(exception_vector_dtor
)
88 VTABLE_ADD_FUNC(exception_what
));
89 __ASM_VTABLE(range_error
,
90 VTABLE_ADD_FUNC(exception_vector_dtor
)
91 VTABLE_ADD_FUNC(exception_what
));
94 DEFINE_RTTI_DATA1(runtime_error
, 0, &exception_rtti_base_descriptor
, ".?AVruntime_error@std@@")
95 DEFINE_CXX_TYPE_INFO(runtime_error
)
96 DEFINE_RTTI_DATA2(range_error
, 0, &runtime_error_rtti_base_descriptor
,
97 &exception_rtti_base_descriptor
, ".?AVrange_error@std@@")
98 DEFINE_CXX_DATA2(range_error
, &runtime_error_cxx_type_info
,
99 &exception_cxx_type_info
, exception_dtor
)
101 void DECLSPEC_NORETURN
throw_range_error(const char *str
)
104 __exception_ctor(&e
, str
, &range_error_vtable
);
105 _CxxThrowException(&e
, &range_error_exception_type
);
108 static BOOL
init_cxx_funcs(void)
110 msvcp140
= LoadLibraryA("msvcp140.dll");
113 FIXME("Failed to load msvcp140.dll\n");
117 _Xmem
= (void*)GetProcAddress(msvcp140
, "?_Xbad_alloc@std@@YAXXZ");
118 _Xout_of_range
= (void*)GetProcAddress(msvcp140
, sizeof(void*) > sizeof(int) ?
119 "?_Xout_of_range@std@@YAXPEBD@Z" : "?_Xout_of_range@std@@YAXPBD@Z");
120 if (!_Xmem
|| !_Xout_of_range
)
122 FreeLibrary(msvcp140
);
129 BOOL WINAPI
DllMain(HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
133 case DLL_PROCESS_ATTACH
:
134 if (!init_cxx_funcs()) return FALSE
;
136 init_exception_rtti((char*)inst
);
137 init_range_error_rtti((char*)inst
);
138 init_runtime_error_rtti((char*)inst
);
139 init_type_info_rtti((char*)inst
);
141 init_exception_cxx_type_info((char*)inst
);
142 init_runtime_error_cxx_type_info((char*)inst
);
143 init_range_error_cxx((char*)inst
);
145 msvcrt_init_concurrency(inst
);
146 init_concurrency_details(inst
);
148 case DLL_PROCESS_DETACH
:
150 FreeLibrary(msvcp140
);