Actually fix uno bridge on MSVC 14.0

VC runtime was substantially refactored on MSVC 14.0. Among other,
_tiddata structure defined in crt/src/mtdll.h was replaced with
__vcrt_getptd defined in crt/src/vcruntime/vcruntime_internal.h.

All members before

  unsigned long      _NLG_dwCode

were removed, so that the approach to access the member

  void *      _tpxcptinfoptrs; /* ptr to exception info pointers */

with __pxcptinfoptrs() and compute the offset to the _curexception
member of _tiddata doesn't work on MSVC 14.0.

As of MSVC 14.0 __vcrt_getptd symbol isn't exported but Microsoft
have introduced methods to access current exception, current exception
context and processing throw (the later can be accessed through C++17
std::unhandled_exceptions() that was made available in MSVC 14.0):

* __current_exception()
* __current_exception_context()
* __processing_throw() aka std::unhandled_exceptions()

Make use of __current_exception() which we can hope will be maintained
going forward.

Change-Id: Ibfffa5fba62d6928328ac976cb1b24937277363e
Reviewed-on: https://gerrit.libreoffice.org/18475
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: David Ostrovsky <david@ostrovsky.org>
This commit is contained in:
David Ostrovsky 2015-09-10 23:03:39 +02:00
parent 074d4b2362
commit 1aad95eb96
3 changed files with 53 additions and 8 deletions

View File

@ -0,0 +1,41 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BRIDGES_INC_BRIDGES_CPP_UNO_SHARED_EXCEPT_HXX
#define INCLUDED_BRIDGES_INC_BRIDGES_CPP_UNO_SHARED_EXCEPT_HXX
#if _MSC_VER >= 1900 // VC 2015 (and later?)
// extern "C" void** __cdecl __current_exception()
// is defined in MSVS14.0/VC/crt/src/vcruntime/frame.cpp:
// return &__vcrt_getptd()->_curexception;
//
// __vcrt_getptd is defined in vcruntime_internal.h:
//typedef struct __vcrt_ptd
//{
// // C++ Exception Handling (EH) state
// unsigned long _NLG_dwCode; // Required by NLG routines
//[...]
//void* _curexception; // current exception
//[...]
extern "C" void** __current_exception();
#endif
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -32,6 +32,7 @@
#include "com/sun/star/uno/Any.hxx"
#include <unordered_map>
#include "msci.hxx"
#include "bridges/cpp_uno/shared/except.hxx"
#pragma pack(push, 8)
@ -493,8 +494,11 @@ int msci_filterCppException(
if (rethrow && pRecord == pPointers->ExceptionRecord)
{
// hack to get msvcrt internal _curexception field:
pRecord = *reinterpret_cast< EXCEPTION_RECORD ** >(
#if _MSC_VER >= 1900 // VC 2015 (and later?)
__current_exception()
#else
// hack to get msvcrt internal _curexception field:
reinterpret_cast< char * >( __pxcptinfoptrs() ) +
// as long as we don't demand msvcr source as build prerequisite
// (->platform sdk), we have to code those offsets here.
@ -503,6 +507,7 @@ int msci_filterCppException(
// offsetof (_tiddata, _curexception) -
// offsetof (_tiddata, _tpxcptinfoptrs):
0x28 // msvcr80.dll (and later?)
#endif
);
}
// rethrow: handle only C++ exceptions:

View File

@ -250,6 +250,7 @@ void
#include "com/sun/star/uno/Any.hxx"
#include <unordered_map>
#include "mscx.hxx"
#include "bridges/cpp_uno/shared/except.hxx"
#pragma pack(push, 8)
@ -866,8 +867,11 @@ int mscx_filterCppException(
if (rethrow && pRecord == pPointers->ExceptionRecord)
{
// Hack to get msvcrt internal _curexception field:
pRecord = *reinterpret_cast< EXCEPTION_RECORD ** >(
#if _MSC_VER >= 1900 // VC 2015 (and later?)
__current_exception()
#else
// Hack to get msvcrt internal _curexception field
reinterpret_cast< char * >( __pxcptinfoptrs() ) +
// As long as we don't demand MSVCR source as build prerequisite,
// we have to code those offsets here.
@ -875,12 +879,7 @@ int mscx_filterCppException(
// MSVS9/crt/src/mtdll.h:
// offsetof (_tiddata, _curexception) -
// offsetof (_tiddata, _tpxcptinfoptrs):
#if _MSC_VER <= 1900 // VC 2015
//
// See dev-tools/uno/uno_exception_offset
0x48 // msvcr90.dll
#else
error, please find value for this compiler version
0x48
#endif
);
}