tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / bridges / source / cpp_uno / msvc_win32_intel / except.cxx
blob318bc8b7da1e6e1dec7371a621c2c4ec7dff8034
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sal/config.h>
22 #include <malloc.h>
23 #include <typeinfo>
24 #include <signal.h>
26 #include <rtl/alloc.h>
27 #include <rtl/strbuf.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include <sal/log.hxx>
30 #include <osl/mutex.hxx>
32 #include <com/sun/star/uno/Any.hxx>
33 #include <unordered_map>
34 #include <msvc/x86.hxx>
35 #include <except.hxx>
37 #pragma pack(push, 8)
39 using namespace ::com::sun::star;
41 void * ObjectFunction::operator new ( size_t nSize )
43 void * pMem = std::malloc( nSize );
44 if (pMem != 0)
46 DWORD old_protect;
47 BOOL success =
48 VirtualProtect(pMem, nSize, PAGE_EXECUTE_READWRITE, &old_protect);
49 (void) success;
50 assert(success && "VirtualProtect() failed!");
52 return pMem;
55 void ObjectFunction::operator delete ( void * pMem )
57 std::free( pMem );
60 ObjectFunction::ObjectFunction( typelib_TypeDescription * pTypeDescr, void * fpFunc ) throw ()
61 : _pTypeDescr( pTypeDescr )
63 ::typelib_typedescription_acquire( _pTypeDescr );
65 unsigned char * pCode = (unsigned char *)somecode;
66 // a must be!
67 assert((void *)this == (void *)pCode);
69 // push ObjectFunction this
70 *pCode++ = 0x68;
71 *(void **)pCode = this;
72 pCode += sizeof(void *);
73 // jmp rel32 fpFunc
74 *pCode++ = 0xe9;
75 *(sal_Int32 *)pCode = ((unsigned char *)fpFunc) - pCode - sizeof(sal_Int32);
78 ObjectFunction::~ObjectFunction() throw ()
80 ::typelib_typedescription_release( _pTypeDescr );
83 static void * __cdecl __copyConstruct( void * pExcThis, void * pSource, ObjectFunction * pThis )
84 throw ()
86 ::uno_copyData(pExcThis, pSource, pThis->_pTypeDescr, uno::cpp_acquire);
87 return pExcThis;
90 static void * __cdecl __destruct( void * pExcThis, ObjectFunction * pThis )
91 throw ()
93 ::uno_destructData(pExcThis, pThis->_pTypeDescr, uno::cpp_release);
94 return pExcThis;
97 // these are non virtual object methods; there is no this ptr on stack => ecx supplies _this_ ptr
99 static __declspec(naked) void copyConstruct() throw ()
101 __asm
103 // ObjectFunction this already on stack
104 push [esp+8] // source exc object this
105 push ecx // exc object
106 call __copyConstruct
107 add esp, 12 // + ObjectFunction this
108 ret 4
112 static __declspec(naked) void destruct() throw ()
114 __asm
116 // ObjectFunction this already on stack
117 push ecx // exc object
118 call __destruct
119 add esp, 8 // + ObjectFunction this
124 ExceptionType::ExceptionType( typelib_TypeDescription * pTypeDescr ) throw ()
125 : _n0( 0 )
126 , _n1( 0 )
127 , _n2( -1 )
128 , _n3( 0 )
129 , _n4( pTypeDescr->nSize )
130 , _pCopyCtor( new ObjectFunction( pTypeDescr, copyConstruct ) )
131 , _n5( 0 )
133 _pTypeInfo = RTTInfos::get(pTypeDescr->pTypeName);
136 ExceptionType::~ExceptionType() throw ()
138 delete _pCopyCtor;
141 RaiseInfo::RaiseInfo( typelib_TypeDescription * pTypeDescr ) throw ()
142 : _n0( 0 )
143 , _pDtor( new ObjectFunction( pTypeDescr, destruct ) )
144 , _n2( 0 )
145 , _n3( 0 )
146 , _n4( 0 )
148 // a must be
149 static_assert(sizeof(sal_Int32) == sizeof(ExceptionType *), "### pointer size differs from sal_Int32!");
151 typelib_CompoundTypeDescription * pCompTypeDescr;
153 // info count
154 sal_Int32 nLen = 0;
155 for ( pCompTypeDescr = (typelib_CompoundTypeDescription*)pTypeDescr;
156 pCompTypeDescr; pCompTypeDescr = pCompTypeDescr->pBaseTypeDescription )
158 ++nLen;
161 // info count accompanied by type info ptrs: type, base type, base base type, ...
162 _types = std::malloc( sizeof(sal_Int32) + (sizeof(ExceptionType *) * nLen) );
163 assert(_types && "Don't handle OOM conditions");
164 *(sal_Int32 *)_types = nLen;
166 ExceptionType ** ppTypes = (ExceptionType **)((sal_Int32 *)_types + 1);
168 sal_Int32 nPos = 0;
169 for ( pCompTypeDescr = (typelib_CompoundTypeDescription*)pTypeDescr;
170 pCompTypeDescr; pCompTypeDescr = pCompTypeDescr->pBaseTypeDescription )
172 ppTypes[nPos++] = new ExceptionType( (typelib_TypeDescription *)pCompTypeDescr );
176 RaiseInfo::~RaiseInfo() throw ()
178 ExceptionType ** ppTypes = (ExceptionType **)((sal_Int32 *)_types + 1);
179 for ( sal_Int32 nTypes = *(sal_Int32 *)_types; nTypes--; )
181 delete ppTypes[nTypes];
183 std::free( _types );
185 delete _pDtor;
188 #pragma pack(pop)
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */