2010-10-14 08:30:07 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 14:29:57 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 09:58:59 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 14:29:57 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 14:29:57 +00:00
|
|
|
*
|
2008-04-11 09:58:59 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 14:29:57 +00:00
|
|
|
*
|
2008-04-11 09:58:59 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 14:29:57 +00:00
|
|
|
*
|
2008-04-11 09:58:59 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 14:29:57 +00:00
|
|
|
*
|
2008-04-11 09:58:59 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 14:29:57 +00:00
|
|
|
*
|
2008-04-11 09:58:59 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 14:29:57 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 14:55:05 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_bridges.hxx"
|
|
|
|
|
2000-09-18 14:29:57 +00:00
|
|
|
#pragma warning( disable : 4237 )
|
2011-02-03 16:00:54 -07:00
|
|
|
#include <boost/unordered_map.hpp>
|
2000-09-18 14:29:57 +00:00
|
|
|
#include <sal/config.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <new.h>
|
|
|
|
#include <typeinfo.h>
|
2003-10-06 12:15:18 +00:00
|
|
|
#include <signal.h>
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2003-10-06 12:15:18 +00:00
|
|
|
#include "rtl/alloc.h"
|
2011-09-09 17:31:07 +02:00
|
|
|
#include <rtl/instance.hxx>
|
2003-10-06 12:15:18 +00:00
|
|
|
#include "rtl/strbuf.hxx"
|
|
|
|
#include "rtl/ustrbuf.hxx"
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2003-10-06 12:15:18 +00:00
|
|
|
#include "com/sun/star/uno/Any.hxx"
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
#include "msci.hxx"
|
|
|
|
|
2000-12-21 13:46:05 +00:00
|
|
|
|
2000-09-18 14:29:57 +00:00
|
|
|
#pragma pack(push, 8)
|
|
|
|
|
2001-08-01 09:09:58 +00:00
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::std;
|
|
|
|
using namespace ::osl;
|
|
|
|
using namespace ::rtl;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
namespace CPPU_CURRENT_NAMESPACE
|
|
|
|
{
|
|
|
|
|
|
|
|
//==================================================================================================
|
2001-08-01 09:09:58 +00:00
|
|
|
static inline OUString toUNOname( OUString const & rRTTIname ) throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
OUStringBuffer aRet( 64 );
|
|
|
|
OUString aStr( rRTTIname.copy( 4, rRTTIname.getLength()-4-2 ) ); // filter .?AUzzz@yyy@xxx@@
|
2001-05-15 07:41:40 +00:00
|
|
|
sal_Int32 nPos = aStr.getLength();
|
|
|
|
while (nPos > 0)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-15 07:41:40 +00:00
|
|
|
sal_Int32 n = aStr.lastIndexOf( '@', nPos );
|
|
|
|
aRet.append( aStr.copy( n +1, nPos -n -1 ) );
|
|
|
|
if (n >= 0)
|
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
aRet.append( (sal_Unicode)'.' );
|
2001-05-15 07:41:40 +00:00
|
|
|
}
|
|
|
|
nPos = n;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
return aRet.makeStringAndClear();
|
|
|
|
}
|
|
|
|
//==================================================================================================
|
2001-08-01 09:09:58 +00:00
|
|
|
static inline OUString toRTTIname( OUString const & rUNOname ) throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
OUStringBuffer aRet( 64 );
|
|
|
|
aRet.appendAscii( RTL_CONSTASCII_STRINGPARAM(".?AV") ); // class ".?AV"; struct ".?AU"
|
2001-05-15 07:41:40 +00:00
|
|
|
sal_Int32 nPos = rUNOname.getLength();
|
|
|
|
while (nPos > 0)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-05-15 07:41:40 +00:00
|
|
|
sal_Int32 n = rUNOname.lastIndexOf( '.', nPos );
|
|
|
|
aRet.append( rUNOname.copy( n +1, nPos -n -1 ) );
|
2001-08-01 09:09:58 +00:00
|
|
|
aRet.append( (sal_Unicode)'@' );
|
2001-05-15 07:41:40 +00:00
|
|
|
nPos = n;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2001-08-01 09:09:58 +00:00
|
|
|
aRet.append( (sal_Unicode)'@' );
|
2000-09-18 14:29:57 +00:00
|
|
|
return aRet.makeStringAndClear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//##################################################################################################
|
|
|
|
//#### RTTI simulation #############################################################################
|
|
|
|
//##################################################################################################
|
|
|
|
|
|
|
|
|
2011-02-03 16:00:54 -07:00
|
|
|
typedef boost::unordered_map< OUString, void *, OUStringHash, equal_to< OUString > > t_string2PtrMap;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
class RTTInfos
|
|
|
|
{
|
|
|
|
Mutex _aMutex;
|
|
|
|
t_string2PtrMap _allRTTI;
|
|
|
|
|
2001-08-01 09:09:58 +00:00
|
|
|
static OUString toRawName( OUString const & rUNOname ) throw ();
|
2000-09-18 14:29:57 +00:00
|
|
|
public:
|
2001-08-01 09:09:58 +00:00
|
|
|
type_info * getRTTI( OUString const & rUNOname ) throw ();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
RTTInfos();
|
|
|
|
~RTTInfos();
|
|
|
|
};
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
class __type_info
|
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
friend type_info * RTTInfos::getRTTI( OUString const & ) throw ();
|
2003-10-06 12:15:18 +00:00
|
|
|
friend int msci_filterCppException(
|
|
|
|
LPEXCEPTION_POINTERS, uno_Any *, uno_Mapping * );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
public:
|
2000-12-21 13:46:05 +00:00
|
|
|
virtual ~__type_info() throw ();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2001-08-01 09:09:58 +00:00
|
|
|
inline __type_info( void * m_data, const char * m_d_name ) throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
: _m_data( m_data )
|
2003-03-18 18:07:19 +00:00
|
|
|
{ ::strcpy( _m_d_name, m_d_name ); } // #100211# - checked
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void * _m_data;
|
|
|
|
char _m_d_name[1];
|
|
|
|
};
|
|
|
|
//__________________________________________________________________________________________________
|
2000-12-21 13:46:05 +00:00
|
|
|
__type_info::~__type_info() throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
2001-08-01 09:09:58 +00:00
|
|
|
type_info * RTTInfos::getRTTI( OUString const & rUNOname ) throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
// a must be
|
2001-03-12 13:43:35 +00:00
|
|
|
OSL_ENSURE( sizeof(__type_info) == sizeof(type_info), "### type info structure size differ!" );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
MutexGuard aGuard( _aMutex );
|
2001-08-01 09:09:58 +00:00
|
|
|
t_string2PtrMap::const_iterator const iFind( _allRTTI.find( rUNOname ) );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
// check if type is already available
|
|
|
|
if (iFind == _allRTTI.end())
|
|
|
|
{
|
|
|
|
// insert new type_info
|
2001-08-01 09:09:58 +00:00
|
|
|
OString aRawName( OUStringToOString( toRTTIname( rUNOname ), RTL_TEXTENCODING_ASCII_US ) );
|
|
|
|
__type_info * pRTTI = new( ::rtl_allocateMemory( sizeof(__type_info) + aRawName.getLength() ) )
|
|
|
|
__type_info( NULL, aRawName.getStr() );
|
|
|
|
|
2000-09-18 14:29:57 +00:00
|
|
|
// put into map
|
2001-08-01 09:09:58 +00:00
|
|
|
pair< t_string2PtrMap::iterator, bool > insertion(
|
|
|
|
_allRTTI.insert( t_string2PtrMap::value_type( rUNOname, pRTTI ) ) );
|
|
|
|
OSL_ENSURE( insertion.second, "### rtti insertion failed?!" );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
return (type_info *)pRTTI;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
return (type_info *)iFind->second;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
2000-12-21 13:46:05 +00:00
|
|
|
RTTInfos::RTTInfos() throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
2000-12-21 13:46:05 +00:00
|
|
|
RTTInfos::~RTTInfos() throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2003-10-06 12:15:18 +00:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
|
|
|
OSL_TRACE( "> freeing generated RTTI infos... <\n" );
|
|
|
|
#endif
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
MutexGuard aGuard( _aMutex );
|
2003-10-06 12:15:18 +00:00
|
|
|
for ( t_string2PtrMap::const_iterator iPos( _allRTTI.begin() );
|
|
|
|
iPos != _allRTTI.end(); ++iPos )
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
__type_info * pType = (__type_info *)iPos->second;
|
2000-09-18 14:29:57 +00:00
|
|
|
pType->~__type_info(); // obsolete, but good style...
|
2001-08-01 09:09:58 +00:00
|
|
|
::rtl_freeMemory( pType );
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-09 17:31:07 +02:00
|
|
|
struct RTTISingleton: public rtl::Static< RTTInfos, RTTISingleton > {};
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
//##################################################################################################
|
|
|
|
//#### Exception raising ###########################################################################
|
|
|
|
//##################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
struct ObjectFunction
|
|
|
|
{
|
|
|
|
char somecode[12];
|
|
|
|
typelib_TypeDescription * _pTypeDescr; // type of object
|
|
|
|
|
2004-03-19 12:26:17 +00:00
|
|
|
inline static void * operator new ( size_t nSize );
|
|
|
|
inline static void operator delete ( void * pMem );
|
|
|
|
|
2000-12-21 13:46:05 +00:00
|
|
|
ObjectFunction( typelib_TypeDescription * pTypeDescr, void * fpFunc ) throw ();
|
|
|
|
~ObjectFunction() throw ();
|
2000-09-18 14:29:57 +00:00
|
|
|
};
|
2004-03-19 12:26:17 +00:00
|
|
|
|
|
|
|
inline void * ObjectFunction::operator new ( size_t nSize )
|
|
|
|
{
|
|
|
|
void * pMem = rtl_allocateMemory( nSize );
|
|
|
|
if (pMem != 0)
|
|
|
|
{
|
|
|
|
DWORD old_protect;
|
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
|
|
|
BOOL success =
|
|
|
|
#endif
|
|
|
|
VirtualProtect( pMem, nSize, PAGE_EXECUTE_READWRITE, &old_protect );
|
|
|
|
OSL_ENSURE( success, "VirtualProtect() failed!" );
|
|
|
|
}
|
|
|
|
return pMem;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void ObjectFunction::operator delete ( void * pMem )
|
|
|
|
{
|
|
|
|
rtl_freeMemory( pMem );
|
|
|
|
}
|
|
|
|
|
2000-09-18 14:29:57 +00:00
|
|
|
//__________________________________________________________________________________________________
|
2000-12-21 13:46:05 +00:00
|
|
|
ObjectFunction::ObjectFunction( typelib_TypeDescription * pTypeDescr, void * fpFunc ) throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
: _pTypeDescr( pTypeDescr )
|
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
::typelib_typedescription_acquire( _pTypeDescr );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
unsigned char * pCode = (unsigned char *)somecode;
|
|
|
|
// a must be!
|
2001-03-12 13:43:35 +00:00
|
|
|
OSL_ENSURE( (void *)this == (void *)pCode, "### unexpected!" );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
// push ObjectFunction this
|
|
|
|
*pCode++ = 0x68;
|
|
|
|
*(void **)pCode = this;
|
|
|
|
pCode += sizeof(void *);
|
|
|
|
// jmp rel32 fpFunc
|
|
|
|
*pCode++ = 0xe9;
|
|
|
|
*(sal_Int32 *)pCode = ((unsigned char *)fpFunc) - pCode - sizeof(sal_Int32);
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
2000-12-21 13:46:05 +00:00
|
|
|
ObjectFunction::~ObjectFunction() throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
::typelib_typedescription_release( _pTypeDescr );
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
static void * __cdecl __copyConstruct( void * pExcThis, void * pSource, ObjectFunction * pThis )
|
2000-12-21 13:46:05 +00:00
|
|
|
throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
::uno_copyData( pExcThis, pSource, pThis->_pTypeDescr, cpp_acquire );
|
2000-09-18 14:29:57 +00:00
|
|
|
return pExcThis;
|
|
|
|
}
|
|
|
|
//==================================================================================================
|
|
|
|
static void * __cdecl __destruct( void * pExcThis, ObjectFunction * pThis )
|
2000-12-21 13:46:05 +00:00
|
|
|
throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
::uno_destructData( pExcThis, pThis->_pTypeDescr, cpp_release );
|
2000-09-18 14:29:57 +00:00
|
|
|
return pExcThis;
|
|
|
|
}
|
|
|
|
|
|
|
|
// these are non virtual object methods; there is no this ptr on stack => ecx supplies _this_ ptr
|
|
|
|
|
|
|
|
//==================================================================================================
|
2003-10-06 12:15:18 +00:00
|
|
|
static __declspec(naked) void copyConstruct() throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
// ObjectFunction this already on stack
|
|
|
|
push [esp+8] // source exc object this
|
|
|
|
push ecx // exc object
|
|
|
|
call __copyConstruct
|
|
|
|
add esp, 12 // + ObjectFunction this
|
|
|
|
ret 4
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//==================================================================================================
|
2003-10-06 12:15:18 +00:00
|
|
|
static __declspec(naked) void destruct() throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
// ObjectFunction this already on stack
|
|
|
|
push ecx // exc object
|
|
|
|
call __destruct
|
|
|
|
add esp, 8 // + ObjectFunction this
|
|
|
|
ret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
struct ExceptionType
|
|
|
|
{
|
|
|
|
sal_Int32 _n0;
|
|
|
|
type_info * _pTypeInfo;
|
|
|
|
sal_Int32 _n1, _n2, _n3, _n4;
|
|
|
|
ObjectFunction * _pCopyCtor;
|
|
|
|
sal_Int32 _n5;
|
|
|
|
|
2001-08-01 09:09:58 +00:00
|
|
|
inline ExceptionType( typelib_TypeDescription * pTypeDescr ) throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
: _n0( 0 )
|
|
|
|
, _n1( 0 )
|
|
|
|
, _n2( -1 )
|
|
|
|
, _n3( 0 )
|
|
|
|
, _n4( pTypeDescr->nSize )
|
|
|
|
, _pCopyCtor( new ObjectFunction( pTypeDescr, copyConstruct ) )
|
|
|
|
, _n5( 0 )
|
2001-08-01 09:09:58 +00:00
|
|
|
{ _pTypeInfo = msci_getRTTI( pTypeDescr->pTypeName ); }
|
|
|
|
inline ~ExceptionType() throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{ delete _pCopyCtor; }
|
|
|
|
};
|
|
|
|
//==================================================================================================
|
|
|
|
struct RaiseInfo
|
|
|
|
{
|
|
|
|
sal_Int32 _n0;
|
|
|
|
ObjectFunction * _pDtor;
|
|
|
|
sal_Int32 _n2;
|
|
|
|
void * _types;
|
|
|
|
sal_Int32 _n3, _n4;
|
|
|
|
|
2000-12-21 13:46:05 +00:00
|
|
|
RaiseInfo( typelib_TypeDescription * pTypeDescr ) throw ();
|
|
|
|
~RaiseInfo() throw ();
|
2000-09-18 14:29:57 +00:00
|
|
|
};
|
|
|
|
//__________________________________________________________________________________________________
|
2000-12-21 13:46:05 +00:00
|
|
|
RaiseInfo::RaiseInfo( typelib_TypeDescription * pTypeDescr ) throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
: _n0( 0 )
|
|
|
|
, _pDtor( new ObjectFunction( pTypeDescr, destruct ) )
|
|
|
|
, _n2( 0 )
|
|
|
|
, _n3( 0 )
|
|
|
|
, _n4( 0 )
|
|
|
|
{
|
|
|
|
// a must be
|
2001-03-12 13:43:35 +00:00
|
|
|
OSL_ENSURE( sizeof(sal_Int32) == sizeof(ExceptionType *), "### pointer size differs from sal_Int32!" );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
typelib_CompoundTypeDescription * pCompTypeDescr;
|
|
|
|
|
|
|
|
// info count
|
|
|
|
sal_Int32 nLen = 0;
|
|
|
|
for ( pCompTypeDescr = (typelib_CompoundTypeDescription*)pTypeDescr;
|
|
|
|
pCompTypeDescr; pCompTypeDescr = pCompTypeDescr->pBaseTypeDescription )
|
|
|
|
{
|
|
|
|
++nLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
// info count accompanied by type info ptrs: type, base type, base base type, ...
|
2001-08-01 09:09:58 +00:00
|
|
|
_types = ::rtl_allocateMemory( sizeof(sal_Int32) + (sizeof(ExceptionType *) * nLen) );
|
2000-09-18 14:29:57 +00:00
|
|
|
*(sal_Int32 *)_types = nLen;
|
|
|
|
|
|
|
|
ExceptionType ** ppTypes = (ExceptionType **)((sal_Int32 *)_types + 1);
|
|
|
|
|
|
|
|
sal_Int32 nPos = 0;
|
|
|
|
for ( pCompTypeDescr = (typelib_CompoundTypeDescription*)pTypeDescr;
|
|
|
|
pCompTypeDescr; pCompTypeDescr = pCompTypeDescr->pBaseTypeDescription )
|
|
|
|
{
|
|
|
|
ppTypes[nPos++] = new ExceptionType( (typelib_TypeDescription *)pCompTypeDescr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
2000-12-21 13:46:05 +00:00
|
|
|
RaiseInfo::~RaiseInfo() throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
ExceptionType ** ppTypes = (ExceptionType **)((sal_Int32 *)_types + 1);
|
|
|
|
for ( sal_Int32 nTypes = *(sal_Int32 *)_types; nTypes--; )
|
2001-08-01 09:09:58 +00:00
|
|
|
{
|
2000-09-18 14:29:57 +00:00
|
|
|
delete ppTypes[nTypes];
|
2001-08-01 09:09:58 +00:00
|
|
|
}
|
|
|
|
::rtl_freeMemory( _types );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
delete _pDtor;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
class ExceptionInfos
|
|
|
|
{
|
|
|
|
Mutex _aMutex;
|
|
|
|
t_string2PtrMap _allRaiseInfos;
|
2001-08-01 09:09:58 +00:00
|
|
|
|
2000-09-18 14:29:57 +00:00
|
|
|
public:
|
2001-08-01 09:09:58 +00:00
|
|
|
static void * getRaiseInfo( typelib_TypeDescription * pTypeDescr ) throw ();
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2000-12-21 13:46:05 +00:00
|
|
|
ExceptionInfos() throw ();
|
|
|
|
~ExceptionInfos() throw ();
|
2000-09-18 14:29:57 +00:00
|
|
|
};
|
|
|
|
//__________________________________________________________________________________________________
|
2000-12-21 13:46:05 +00:00
|
|
|
ExceptionInfos::ExceptionInfos() throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
2000-12-21 13:46:05 +00:00
|
|
|
ExceptionInfos::~ExceptionInfos() throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2003-10-06 12:15:18 +00:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
|
|
|
OSL_TRACE( "> freeing exception infos... <\n" );
|
|
|
|
#endif
|
2000-09-18 14:29:57 +00:00
|
|
|
|
|
|
|
MutexGuard aGuard( _aMutex );
|
|
|
|
for ( t_string2PtrMap::const_iterator iPos( _allRaiseInfos.begin() );
|
|
|
|
iPos != _allRaiseInfos.end(); ++iPos )
|
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
delete (RaiseInfo *)iPos->second;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
2001-08-01 09:09:58 +00:00
|
|
|
void * ExceptionInfos::getRaiseInfo( typelib_TypeDescription * pTypeDescr ) throw ()
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
static ExceptionInfos * s_pInfos = 0;
|
|
|
|
if (! s_pInfos)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
MutexGuard aGuard( Mutex::getGlobalMutex() );
|
|
|
|
if (! s_pInfos)
|
|
|
|
{
|
|
|
|
#ifdef LEAK_STATIC_DATA
|
|
|
|
s_pInfos = new ExceptionInfos();
|
|
|
|
#else
|
|
|
|
static ExceptionInfos s_allExceptionInfos;
|
|
|
|
s_pInfos = &s_allExceptionInfos;
|
|
|
|
#endif
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2001-08-01 09:09:58 +00:00
|
|
|
OSL_ASSERT( pTypeDescr &&
|
|
|
|
(pTypeDescr->eTypeClass == typelib_TypeClass_STRUCT ||
|
|
|
|
pTypeDescr->eTypeClass == typelib_TypeClass_EXCEPTION) );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2001-08-01 09:09:58 +00:00
|
|
|
void * pRaiseInfo;
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2001-08-01 09:09:58 +00:00
|
|
|
OUString const & rTypeName = *reinterpret_cast< OUString * >( &pTypeDescr->pTypeName );
|
|
|
|
MutexGuard aGuard( s_pInfos->_aMutex );
|
|
|
|
t_string2PtrMap::const_iterator const iFind(
|
|
|
|
s_pInfos->_allRaiseInfos.find( rTypeName ) );
|
|
|
|
if (iFind == s_pInfos->_allRaiseInfos.end())
|
|
|
|
{
|
|
|
|
pRaiseInfo = new RaiseInfo( pTypeDescr );
|
|
|
|
// put into map
|
|
|
|
pair< t_string2PtrMap::iterator, bool > insertion(
|
|
|
|
s_pInfos->_allRaiseInfos.insert( t_string2PtrMap::value_type( rTypeName, pRaiseInfo ) ) );
|
|
|
|
OSL_ENSURE( insertion.second, "### raise info insertion failed?!" );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// reuse existing info
|
|
|
|
pRaiseInfo = iFind->second;
|
|
|
|
}
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2001-08-01 09:09:58 +00:00
|
|
|
return pRaiseInfo;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//##################################################################################################
|
|
|
|
//#### exported ####################################################################################
|
|
|
|
//##################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
//##################################################################################################
|
2003-10-06 12:15:18 +00:00
|
|
|
type_info * msci_getRTTI( OUString const & rUNOname )
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2011-09-09 17:31:07 +02:00
|
|
|
return RTTISingleton::get().getRTTI( rUNOname );
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//##################################################################################################
|
|
|
|
void msci_raiseException( uno_Any * pUnoExc, uno_Mapping * pUno2Cpp )
|
|
|
|
{
|
2001-08-01 09:09:58 +00:00
|
|
|
// no ctor/dtor in here: this leads to dtors called twice upon RaiseException()!
|
|
|
|
// thus this obj file will be compiled without opt, so no inling of
|
|
|
|
// ExceptionInfos::getRaiseInfo()
|
|
|
|
|
|
|
|
// construct cpp exception object
|
|
|
|
typelib_TypeDescription * pTypeDescr = 0;
|
|
|
|
TYPELIB_DANGER_GET( &pTypeDescr, pUnoExc->pType );
|
|
|
|
|
|
|
|
void * pCppExc = alloca( pTypeDescr->nSize );
|
|
|
|
::uno_copyAndConvertData( pCppExc, pUnoExc->pData, pTypeDescr, pUno2Cpp );
|
|
|
|
|
|
|
|
// a must be
|
2003-10-06 12:15:18 +00:00
|
|
|
OSL_ENSURE(
|
|
|
|
sizeof(sal_Int32) == sizeof(void *),
|
|
|
|
"### pointer size differs from sal_Int32!" );
|
2001-08-01 09:09:58 +00:00
|
|
|
DWORD arFilterArgs[3];
|
2003-10-06 12:15:18 +00:00
|
|
|
arFilterArgs[0] = MSVC_magic_number;
|
2001-08-01 09:09:58 +00:00
|
|
|
arFilterArgs[1] = (DWORD)pCppExc;
|
|
|
|
arFilterArgs[2] = (DWORD)ExceptionInfos::getRaiseInfo( pTypeDescr );
|
|
|
|
|
|
|
|
// destruct uno exception
|
|
|
|
::uno_any_destruct( pUnoExc, 0 );
|
|
|
|
TYPELIB_DANGER_RELEASE( pTypeDescr );
|
|
|
|
|
|
|
|
// last point to release anything not affected by stack unwinding
|
|
|
|
RaiseException( MSVC_ExceptionCode, EXCEPTION_NONCONTINUABLE, 3, arFilterArgs );
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
2003-10-06 12:15:18 +00:00
|
|
|
//##############################################################################
|
|
|
|
int msci_filterCppException(
|
|
|
|
EXCEPTION_POINTERS * pPointers, uno_Any * pUnoExc, uno_Mapping * pCpp2Uno )
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2003-10-06 12:15:18 +00:00
|
|
|
if (pPointers == 0)
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
EXCEPTION_RECORD * pRecord = pPointers->ExceptionRecord;
|
|
|
|
// handle only C++ exceptions:
|
|
|
|
if (pRecord == 0 || pRecord->ExceptionCode != MSVC_ExceptionCode)
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
|
|
|
|
#if _MSC_VER < 1300 // MSVC -6
|
|
|
|
bool rethrow = (pRecord->NumberParameters < 3 ||
|
|
|
|
pRecord->ExceptionInformation[ 2 ] == 0);
|
|
|
|
#else
|
|
|
|
bool rethrow = __CxxDetectRethrow( &pRecord );
|
|
|
|
OSL_ASSERT( pRecord == pPointers->ExceptionRecord );
|
|
|
|
#endif
|
|
|
|
if (rethrow && pRecord == pPointers->ExceptionRecord)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2003-10-06 12:15:18 +00:00
|
|
|
// hack to get msvcrt internal _curexception field:
|
|
|
|
pRecord = *reinterpret_cast< EXCEPTION_RECORD ** >(
|
|
|
|
reinterpret_cast< char * >( __pxcptinfoptrs() ) +
|
2006-09-25 11:51:09 +00:00
|
|
|
// as long as we don't demand msvcr source as build prerequisite
|
|
|
|
// (->platform sdk), we have to code those offsets here.
|
|
|
|
//
|
2003-10-06 12:15:18 +00:00
|
|
|
// crt\src\mtdll.h:
|
|
|
|
// offsetof (_tiddata, _curexception) -
|
|
|
|
// offsetof (_tiddata, _tpxcptinfoptrs):
|
|
|
|
#if _MSC_VER < 1300
|
|
|
|
0x18 // msvcrt,dll
|
|
|
|
#elif _MSC_VER < 1310
|
|
|
|
0x20 // msvcr70.dll
|
2006-09-25 11:51:09 +00:00
|
|
|
#elif _MSC_VER < 1400
|
2003-10-06 12:15:18 +00:00
|
|
|
0x24 // msvcr71.dll
|
2006-09-25 11:51:09 +00:00
|
|
|
#else
|
|
|
|
0x28 // msvcr80.dll
|
2003-10-06 12:15:18 +00:00
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// rethrow: handle only C++ exceptions:
|
|
|
|
if (pRecord == 0 || pRecord->ExceptionCode != MSVC_ExceptionCode)
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
|
|
|
|
if (pRecord->NumberParameters == 3 &&
|
|
|
|
// pRecord->ExceptionInformation[ 0 ] == MSVC_magic_number &&
|
|
|
|
pRecord->ExceptionInformation[ 1 ] != 0 &&
|
|
|
|
pRecord->ExceptionInformation[ 2 ] != 0)
|
|
|
|
{
|
|
|
|
void * types = reinterpret_cast< RaiseInfo * >(
|
|
|
|
pRecord->ExceptionInformation[ 2 ] )->_types;
|
|
|
|
if (types != 0 && *reinterpret_cast< DWORD * >( types ) > 0) // count
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2003-10-06 12:15:18 +00:00
|
|
|
ExceptionType * pType = *reinterpret_cast< ExceptionType ** >(
|
|
|
|
reinterpret_cast< DWORD * >( types ) + 1 );
|
|
|
|
if (pType != 0 && pType->_pTypeInfo != 0)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2003-10-06 12:15:18 +00:00
|
|
|
OUString aRTTIname(
|
|
|
|
OStringToOUString(
|
|
|
|
reinterpret_cast< __type_info * >(
|
|
|
|
pType->_pTypeInfo )->_m_d_name,
|
|
|
|
RTL_TEXTENCODING_ASCII_US ) );
|
2001-08-01 09:09:58 +00:00
|
|
|
OUString aUNOname( toUNOname( aRTTIname ) );
|
2000-09-18 14:29:57 +00:00
|
|
|
|
2003-10-06 12:15:18 +00:00
|
|
|
typelib_TypeDescription * pExcTypeDescr = 0;
|
|
|
|
typelib_typedescription_getByName(
|
|
|
|
&pExcTypeDescr, aUNOname.pData );
|
|
|
|
if (pExcTypeDescr == 0)
|
2000-09-18 14:29:57 +00:00
|
|
|
{
|
2003-10-06 12:15:18 +00:00
|
|
|
OUStringBuffer buf;
|
|
|
|
buf.appendAscii(
|
|
|
|
RTL_CONSTASCII_STRINGPARAM(
|
|
|
|
"[msci_uno bridge error] UNO type of "
|
|
|
|
"C++ exception unknown: \"") );
|
|
|
|
buf.append( aUNOname );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(
|
|
|
|
"\", RTTI-name=\"") );
|
|
|
|
buf.append( aRTTIname );
|
|
|
|
buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
|
|
|
|
RuntimeException exc(
|
|
|
|
buf.makeStringAndClear(), Reference< XInterface >() );
|
|
|
|
uno_type_any_constructAndConvert(
|
|
|
|
pUnoExc, &exc,
|
|
|
|
::getCppuType( &exc ).getTypeLibType(), pCpp2Uno );
|
2006-09-25 11:51:09 +00:00
|
|
|
#if _MSC_VER < 1400 // msvcr80.dll cleans up, different from former msvcrs
|
|
|
|
// if (! rethrow):
|
2003-10-06 12:15:18 +00:00
|
|
|
// though this unknown exception leaks now, no user-defined
|
|
|
|
// exception is ever thrown thru the binary C-UNO dispatcher
|
|
|
|
// call stack.
|
2006-09-25 11:51:09 +00:00
|
|
|
#endif
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
2003-10-06 12:15:18 +00:00
|
|
|
else
|
2000-11-29 16:02:26 +00:00
|
|
|
{
|
2003-10-06 12:15:18 +00:00
|
|
|
// construct uno exception any
|
|
|
|
uno_any_constructAndConvert(
|
|
|
|
pUnoExc, (void *) pRecord->ExceptionInformation[1],
|
|
|
|
pExcTypeDescr, pCpp2Uno );
|
2006-09-25 11:51:09 +00:00
|
|
|
#if _MSC_VER < 1400 // msvcr80.dll cleans up, different from former msvcrs
|
2003-10-06 12:15:18 +00:00
|
|
|
if (! rethrow)
|
|
|
|
{
|
|
|
|
uno_destructData(
|
|
|
|
(void *) pRecord->ExceptionInformation[1],
|
|
|
|
pExcTypeDescr, cpp_release );
|
|
|
|
}
|
2006-09-25 11:51:09 +00:00
|
|
|
#endif
|
2003-10-06 12:15:18 +00:00
|
|
|
typelib_typedescription_release( pExcTypeDescr );
|
2000-11-29 16:02:26 +00:00
|
|
|
}
|
2003-10-06 12:15:18 +00:00
|
|
|
|
2000-11-29 16:02:26 +00:00
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-10-06 12:15:18 +00:00
|
|
|
// though this unknown exception leaks now, no user-defined exception
|
|
|
|
// is ever thrown thru the binary C-UNO dispatcher call stack.
|
|
|
|
RuntimeException exc(
|
|
|
|
OUString( RTL_CONSTASCII_USTRINGPARAM(
|
|
|
|
"[msci_uno bridge error] unexpected "
|
2010-12-05 19:11:58 +00:00
|
|
|
"C++ exception occurred!") ),
|
2003-10-06 12:15:18 +00:00
|
|
|
Reference< XInterface >() );
|
|
|
|
uno_type_any_constructAndConvert(
|
|
|
|
pUnoExc, &exc, ::getCppuType( &exc ).getTypeLibType(), pCpp2Uno );
|
|
|
|
return EXCEPTION_EXECUTE_HANDLER;
|
2000-09-18 14:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2010-10-14 08:30:07 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|