1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
39 using namespace ::com::sun::star
;
41 void * ObjectFunction::operator new ( size_t nSize
)
43 void * pMem
= std::malloc( nSize
);
48 VirtualProtect(pMem
, nSize
, PAGE_EXECUTE_READWRITE
, &old_protect
);
50 assert(success
&& "VirtualProtect() failed!");
55 void ObjectFunction::operator delete ( void * 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
;
67 assert((void *)this == (void *)pCode
);
69 // push ObjectFunction this
71 *(void **)pCode
= this;
72 pCode
+= sizeof(void *);
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
)
86 ::uno_copyData(pExcThis
, pSource
, pThis
->_pTypeDescr
, uno::cpp_acquire
);
90 static void * __cdecl
__destruct( void * pExcThis
, ObjectFunction
* pThis
)
93 ::uno_destructData(pExcThis
, pThis
->_pTypeDescr
, uno::cpp_release
);
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 ()
103 // ObjectFunction this already on stack
104 push
[esp
+8] // source exc object this
105 push ecx
// exc object
107 add esp
, 12 // + ObjectFunction this
112 static __declspec(naked
) void destruct() throw ()
116 // ObjectFunction this already on stack
117 push ecx
// exc object
119 add esp
, 8 // + ObjectFunction this
124 ExceptionType::ExceptionType( typelib_TypeDescription
* pTypeDescr
) throw ()
129 , _n4( pTypeDescr
->nSize
)
130 , _pCopyCtor( new ObjectFunction( pTypeDescr
, copyConstruct
) )
133 _pTypeInfo
= RTTInfos::get(pTypeDescr
->pTypeName
);
136 ExceptionType::~ExceptionType() throw ()
141 RaiseInfo::RaiseInfo( typelib_TypeDescription
* pTypeDescr
) throw ()
143 , _pDtor( new ObjectFunction( pTypeDescr
, destruct
) )
149 static_assert(sizeof(sal_Int32
) == sizeof(ExceptionType
*), "### pointer size differs from sal_Int32!");
151 typelib_CompoundTypeDescription
* pCompTypeDescr
;
155 for ( pCompTypeDescr
= (typelib_CompoundTypeDescription
*)pTypeDescr
;
156 pCompTypeDescr
; pCompTypeDescr
= pCompTypeDescr
->pBaseTypeDescription
)
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);
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
];
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */