Kaydet (Commit) d398fd13 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Now the C++-UNO bridge on x64 Windows works a bit better

I had implemented a couple of basic things quite wrong, partly because
of easily misunderstood Microsoft documentation. A couple of things I
just had forgot to do properly.

Attempt to make the source code more consistent in spacing and
variable naming. Clean away meaningless vertical space wasting
non-verbal comments.

The bridgetest over in testtools now runs through quite a lot of its
paces successfully. But exception handling and RTTI, the stuff in
except.cxx, is still not really done at all. And even if I comment out
those checks in bridgetest so that no exceptios are thrown, I then get
a crash later.
üst fd17eed8
...@@ -64,10 +64,11 @@ ...@@ -64,10 +64,11 @@
;; This one is actually more readable: "Improving Automated Analysis ;; This one is actually more readable: "Improving Automated Analysis
;; of Windows x64 Binaries": http://www.uninformed.org/?v=4&a=1 ;; of Windows x64 Binaries": http://www.uninformed.org/?v=4&a=1
;; For exception handling and unwinding to work across the generated ;; This one has a mass of information about different architectures
;; functions (as I assume we want?), we would need call ;; and compilers, and contains some details about the x64 Windows
;; RtlAddFunctionTable() (and RtlDeleteFunctionTable()). See Windows ;; calling convention in particular that Microsoft doesn't mention
;; SDK documentation. ;; above:
;; http://www.agner.org/optimize/calling_conventions.pdf
;; Random interesting discussion threads: ;; Random interesting discussion threads:
;; http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/300bd6d3-9381-4d2d-8129-e48b392c05d8 ;; http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/300bd6d3-9381-4d2d-8129-e48b392c05d8
......
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
#include "mscx.hxx" #include "mscx.hxx"
#pragma pack(push, 8) #pragma pack(push, 8)
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
...@@ -56,8 +55,9 @@ using namespace ::rtl; ...@@ -56,8 +55,9 @@ using namespace ::rtl;
namespace CPPU_CURRENT_NAMESPACE namespace CPPU_CURRENT_NAMESPACE
{ {
//================================================================================================== static inline OUString toUNOname(
static inline OUString toUNOname( OUString const & rRTTIname ) throw () OUString const & rRTTIname )
throw ()
{ {
OUStringBuffer aRet( 64 ); OUStringBuffer aRet( 64 );
OUString aStr( rRTTIname.copy( 4, rRTTIname.getLength()-4-2 ) ); // filter .?AUzzz@yyy@xxx@@ OUString aStr( rRTTIname.copy( 4, rRTTIname.getLength()-4-2 ) ); // filter .?AUzzz@yyy@xxx@@
...@@ -74,8 +74,10 @@ static inline OUString toUNOname( OUString const & rRTTIname ) throw () ...@@ -74,8 +74,10 @@ static inline OUString toUNOname( OUString const & rRTTIname ) throw ()
} }
return aRet.makeStringAndClear(); return aRet.makeStringAndClear();
} }
//==================================================================================================
static inline OUString toRTTIname( OUString const & rUNOname ) throw () static inline OUString toRTTIname(
OUString const & rUNOname )
throw ()
{ {
OUStringBuffer aRet( 64 ); OUStringBuffer aRet( 64 );
aRet.appendAscii( RTL_CONSTASCII_STRINGPARAM(".?AV") ); // class ".?AV"; struct ".?AU" aRet.appendAscii( RTL_CONSTASCII_STRINGPARAM(".?AV") ); // class ".?AV"; struct ".?AU"
...@@ -91,15 +93,10 @@ static inline OUString toRTTIname( OUString const & rUNOname ) throw () ...@@ -91,15 +93,10 @@ static inline OUString toRTTIname( OUString const & rUNOname ) throw ()
return aRet.makeStringAndClear(); return aRet.makeStringAndClear();
} }
//RTTI simulation
//##################################################################################################
//#### RTTI simulation #############################################################################
//##################################################################################################
typedef hash_map< OUString, void *, OUStringHash, equal_to< OUString > > t_string2PtrMap; typedef hash_map< OUString, void *, OUStringHash, equal_to< OUString > > t_string2PtrMap;
//==================================================================================================
class RTTInfos class RTTInfos
{ {
Mutex _aMutex; Mutex _aMutex;
...@@ -113,7 +110,6 @@ public: ...@@ -113,7 +110,6 @@ public:
~RTTInfos(); ~RTTInfos();
}; };
//==================================================================================================
class __type_info class __type_info
{ {
friend type_info * RTTInfos::getRTTI( OUString const & ) throw (); friend type_info * RTTInfos::getRTTI( OUString const & ) throw ();
...@@ -131,11 +127,11 @@ private: ...@@ -131,11 +127,11 @@ private:
void * _m_data; void * _m_data;
char _m_d_name[1]; char _m_d_name[1];
}; };
//__________________________________________________________________________________________________
__type_info::~__type_info() throw () __type_info::~__type_info() throw ()
{ {
} }
//__________________________________________________________________________________________________
type_info * RTTInfos::getRTTI( OUString const & rUNOname ) throw () type_info * RTTInfos::getRTTI( OUString const & rUNOname ) throw ()
{ {
// a must be // a must be
...@@ -164,11 +160,11 @@ type_info * RTTInfos::getRTTI( OUString const & rUNOname ) throw () ...@@ -164,11 +160,11 @@ type_info * RTTInfos::getRTTI( OUString const & rUNOname ) throw ()
return (type_info *)iFind->second; return (type_info *)iFind->second;
} }
} }
//__________________________________________________________________________________________________
RTTInfos::RTTInfos() throw () RTTInfos::RTTInfos() throw ()
{ {
} }
//__________________________________________________________________________________________________
RTTInfos::~RTTInfos() throw () RTTInfos::~RTTInfos() throw ()
{ {
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
...@@ -185,13 +181,6 @@ RTTInfos::~RTTInfos() throw () ...@@ -185,13 +181,6 @@ RTTInfos::~RTTInfos() throw ()
} }
} }
//##################################################################################################
//#### Exception raising ###########################################################################
//##################################################################################################
//==================================================================================================
struct ObjectFunction struct ObjectFunction
{ {
char somecode[12]; char somecode[12];
...@@ -204,7 +193,8 @@ struct ObjectFunction ...@@ -204,7 +193,8 @@ struct ObjectFunction
~ObjectFunction() throw (); ~ObjectFunction() throw ();
}; };
inline void * ObjectFunction::operator new ( size_t nSize ) inline void * ObjectFunction::operator new(
size_t nSize )
{ {
void * pMem = rtl_allocateMemory( nSize ); void * pMem = rtl_allocateMemory( nSize );
if (pMem != 0) if (pMem != 0)
...@@ -219,13 +209,15 @@ inline void * ObjectFunction::operator new ( size_t nSize ) ...@@ -219,13 +209,15 @@ inline void * ObjectFunction::operator new ( size_t nSize )
return pMem; return pMem;
} }
inline void ObjectFunction::operator delete ( void * pMem ) inline void ObjectFunction::operator delete(
void * pMem )
{ {
rtl_freeMemory( pMem ); rtl_freeMemory( pMem );
} }
//__________________________________________________________________________________________________ ObjectFunction::ObjectFunction(
ObjectFunction::ObjectFunction( typelib_TypeDescription * pTypeDescr, void * fpFunc ) throw () typelib_TypeDescription * pTypeDescr,
void * fpFunc ) throw ()
: _pTypeDescr( pTypeDescr ) : _pTypeDescr( pTypeDescr )
{ {
::typelib_typedescription_acquire( _pTypeDescr ); ::typelib_typedescription_acquire( _pTypeDescr );
...@@ -242,28 +234,32 @@ ObjectFunction::ObjectFunction( typelib_TypeDescription * pTypeDescr, void * fpF ...@@ -242,28 +234,32 @@ ObjectFunction::ObjectFunction( typelib_TypeDescription * pTypeDescr, void * fpF
*pCode++ = 0xe9; *pCode++ = 0xe9;
*(sal_Int64 *)pCode = ((unsigned char *)fpFunc) - pCode - sizeof(sal_Int64); *(sal_Int64 *)pCode = ((unsigned char *)fpFunc) - pCode - sizeof(sal_Int64);
} }
//__________________________________________________________________________________________________
ObjectFunction::~ObjectFunction() throw () ObjectFunction::~ObjectFunction() throw ()
{ {
::typelib_typedescription_release( _pTypeDescr ); ::typelib_typedescription_release( _pTypeDescr );
} }
//==================================================================================================
void * __cdecl __copyConstruct( void * pExcThis, void * pSource, ObjectFunction * pThis ) void * __cdecl __copyConstruct(
void * pExcThis,
void * pSource,
ObjectFunction * pThis )
throw () throw ()
{ {
::uno_copyData( pExcThis, pSource, pThis->_pTypeDescr, cpp_acquire ); ::uno_copyData( pExcThis, pSource, pThis->_pTypeDescr, cpp_acquire );
return pExcThis; return pExcThis;
} }
//==================================================================================================
void * __cdecl __destruct( void * pExcThis, ObjectFunction * pThis ) void * __cdecl __destruct(
void * pExcThis,
ObjectFunction * pThis )
throw () throw ()
{ {
::uno_destructData( pExcThis, pThis->_pTypeDescr, cpp_release ); ::uno_destructData( pExcThis, pThis->_pTypeDescr, cpp_release );
return pExcThis; return pExcThis;
} }
#if 0 #if 0
// These are machine code snippets in asmbits.asm // These are machine code snippets in asmbits.asm
...@@ -285,7 +281,6 @@ static void whatthefuck_dtor(sal_Int64 i, ...) ...@@ -285,7 +281,6 @@ static void whatthefuck_dtor(sal_Int64 i, ...)
#endif #endif
//==================================================================================================
struct ExceptionType struct ExceptionType
{ {
sal_Int32 _n0; sal_Int32 _n0;
...@@ -310,7 +305,7 @@ struct ExceptionType ...@@ -310,7 +305,7 @@ struct ExceptionType
inline ~ExceptionType() throw () inline ~ExceptionType() throw ()
{ delete _pCopyCtor; } { delete _pCopyCtor; }
}; };
//==================================================================================================
struct RaiseInfo struct RaiseInfo
{ {
sal_Int32 _n0; sal_Int32 _n0;
...@@ -322,7 +317,7 @@ struct RaiseInfo ...@@ -322,7 +317,7 @@ struct RaiseInfo
RaiseInfo( typelib_TypeDescription * pTypeDescr ) throw (); RaiseInfo( typelib_TypeDescription * pTypeDescr ) throw ();
~RaiseInfo() throw (); ~RaiseInfo() throw ();
}; };
//__________________________________________________________________________________________________
RaiseInfo::RaiseInfo( typelib_TypeDescription * pTypeDescr ) throw () RaiseInfo::RaiseInfo( typelib_TypeDescription * pTypeDescr ) throw ()
: _n0( 0 ) : _n0( 0 )
#if 0 #if 0
...@@ -357,7 +352,7 @@ RaiseInfo::RaiseInfo( typelib_TypeDescription * pTypeDescr ) throw () ...@@ -357,7 +352,7 @@ RaiseInfo::RaiseInfo( typelib_TypeDescription * pTypeDescr ) throw ()
ppTypes[nPos++] = new ExceptionType( (typelib_TypeDescription *)pCompTypeDescr ); ppTypes[nPos++] = new ExceptionType( (typelib_TypeDescription *)pCompTypeDescr );
} }
} }
//__________________________________________________________________________________________________
RaiseInfo::~RaiseInfo() throw () RaiseInfo::~RaiseInfo() throw ()
{ {
ExceptionType ** ppTypes = (ExceptionType **)((sal_Int64 *)_types + 1); ExceptionType ** ppTypes = (ExceptionType **)((sal_Int64 *)_types + 1);
...@@ -370,7 +365,6 @@ RaiseInfo::~RaiseInfo() throw () ...@@ -370,7 +365,6 @@ RaiseInfo::~RaiseInfo() throw ()
delete _pDtor; delete _pDtor;
} }
//==================================================================================================
class ExceptionInfos class ExceptionInfos
{ {
Mutex _aMutex; Mutex _aMutex;
...@@ -382,11 +376,11 @@ public: ...@@ -382,11 +376,11 @@ public:
ExceptionInfos() throw (); ExceptionInfos() throw ();
~ExceptionInfos() throw (); ~ExceptionInfos() throw ();
}; };
//__________________________________________________________________________________________________
ExceptionInfos::ExceptionInfos() throw () ExceptionInfos::ExceptionInfos() throw ()
{ {
} }
//__________________________________________________________________________________________________
ExceptionInfos::~ExceptionInfos() throw () ExceptionInfos::~ExceptionInfos() throw ()
{ {
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
...@@ -400,8 +394,8 @@ ExceptionInfos::~ExceptionInfos() throw () ...@@ -400,8 +394,8 @@ ExceptionInfos::~ExceptionInfos() throw ()
delete (RaiseInfo *)iPos->second; delete (RaiseInfo *)iPos->second;
} }
} }
//__________________________________________________________________________________________________ void * ExceptionInfos::getRaiseInfo(
void * ExceptionInfos::getRaiseInfo( typelib_TypeDescription * pTypeDescr ) throw () typelib_TypeDescription * pTypeDescr ) throw ()
{ {
static ExceptionInfos * s_pInfos = 0; static ExceptionInfos * s_pInfos = 0;
if (! s_pInfos) if (! s_pInfos)
...@@ -445,14 +439,8 @@ void * ExceptionInfos::getRaiseInfo( typelib_TypeDescription * pTypeDescr ) thro ...@@ -445,14 +439,8 @@ void * ExceptionInfos::getRaiseInfo( typelib_TypeDescription * pTypeDescr ) thro
return pRaiseInfo; return pRaiseInfo;
} }
type_info * mscx_getRTTI(
//################################################################################################## OUString const & rUNOname )
//#### exported ####################################################################################
//##################################################################################################
//##################################################################################################
type_info * mscx_getRTTI( OUString const & rUNOname )
{ {
static RTTInfos * s_pRTTIs = 0; static RTTInfos * s_pRTTIs = 0;
if (! s_pRTTIs) if (! s_pRTTIs)
...@@ -471,8 +459,9 @@ type_info * mscx_getRTTI( OUString const & rUNOname ) ...@@ -471,8 +459,9 @@ type_info * mscx_getRTTI( OUString const & rUNOname )
return s_pRTTIs->getRTTI( rUNOname ); return s_pRTTIs->getRTTI( rUNOname );
} }
//################################################################################################## void mscx_raiseException(
void mscx_raiseException( uno_Any * pUnoExc, uno_Mapping * pUno2Cpp ) uno_Any * pUnoExc,
uno_Mapping * pUno2Cpp )
{ {
// no ctor/dtor in here: this leads to dtors called twice upon RaiseException()! // 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 // thus this obj file will be compiled without opt, so no inling of
...@@ -498,9 +487,10 @@ void mscx_raiseException( uno_Any * pUnoExc, uno_Mapping * pUno2Cpp ) ...@@ -498,9 +487,10 @@ void mscx_raiseException( uno_Any * pUnoExc, uno_Mapping * pUno2Cpp )
RaiseException( MSVC_ExceptionCode, EXCEPTION_NONCONTINUABLE, 3, arFilterArgs ); RaiseException( MSVC_ExceptionCode, EXCEPTION_NONCONTINUABLE, 3, arFilterArgs );
} }
//##############################################################################
int mscx_filterCppException( int mscx_filterCppException(
EXCEPTION_POINTERS * pPointers, uno_Any * pUnoExc, uno_Mapping * pCpp2Uno ) EXCEPTION_POINTERS * pPointers,
uno_Any * pUnoExc,
uno_Mapping * pCpp2Uno )
{ {
if (pPointers == 0) if (pPointers == 0)
return EXCEPTION_CONTINUE_SEARCH; return EXCEPTION_CONTINUE_SEARCH;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment