WASM UNO: add a minimal dummy bridge

... and use the same fake exception rethrowing code then the
mobile platforms.

Change-Id: Ic90de1cfd1e0092d6064d041a613d60d9f5f76b5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128596
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
This commit is contained in:
Thorsten Behrens 2021-09-25 18:03:31 +02:00 committed by Jan-Marek Glogowski
parent cb65cf92b9
commit c367a2781f
9 changed files with 180 additions and 11 deletions

View file

@ -572,13 +572,11 @@ $(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_URE,ure, \
))
$(eval $(call gb_Helper_register_plugins_for_install,PLAINLIBS_URE,ure, \
$(if $(filter EMSCRIPTEN,$(OS)),, \
$(if $(filter MSC,$(COM)), \
$(if $(filter INTEL,$(CPUNAME)),msci_uno) \
$(if $(filter X86_64,$(CPUNAME)),mscx_uno) \
$(if $(filter AARCH64,$(CPUNAME)),msca_uno) \
, gcc3_uno) \
) \
))
$(eval $(call gb_Helper_register_libraries_for_install,PRIVATELIBS_URE,ure, \

View file

@ -85,6 +85,9 @@ else ifeq ($(COM),MSC)
bridges_SELECTED_BRIDGE := msvc_win32_intel
bridge_exception_objects := cpp2uno uno2cpp
bridge_noopt_objects := except
else ifeq ($(OS),EMSCRIPTEN)
bridges_SELECTED_BRIDGE := gcc3_wasm
bridge_noopt_objects := cpp2uno except uno2cpp
endif
else ifeq ($(CPUNAME),M68K)

View file

@ -9,7 +9,6 @@
$(eval $(call gb_Module_Module,bridges))
ifneq ($(OS),EMSCRIPTEN)
$(eval $(call gb_Module_add_targets,bridges,\
Library_cpp_uno \
$(if $(ENABLE_JAVA),\
@ -30,6 +29,5 @@ else ifneq ($(words $(bridges_SELECTED_BRIDGE)),1)
$(call gb_Output_error,multiple bridges selected for build: $(bridges_SELECTED_BRIDGE))
endif
endif
endif
# vim: set noet sw=4 ts=4:

View file

@ -0,0 +1,47 @@
/* -*- 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/.
*/
#include <typelib/typedescription.hxx>
#include <vtablefactory.hxx>
using namespace ::com::sun::star::uno;
using bridges::cpp_uno::shared::VtableFactory;
struct VtableFactory::Slot
{
};
VtableFactory::Slot* VtableFactory::mapBlockToVtable(void* block)
{
return static_cast<Slot*>(block) + 2;
}
std::size_t VtableFactory::getBlockSize(sal_Int32 slotCount)
{
return (slotCount + 2) * sizeof(Slot);
}
VtableFactory::Slot* VtableFactory::initializeBlock(void* block, sal_Int32 slotCount, sal_Int32,
typelib_InterfaceTypeDescription*)
{
Slot* slots = mapBlockToVtable(block);
return slots + slotCount;
}
unsigned char* VtableFactory::addLocalFunctions(Slot**, unsigned char*,
typelib_InterfaceTypeDescription const*, sal_Int32,
sal_Int32, sal_Int32)
{
std::abort();
}
void VtableFactory::flushCode(unsigned char const*, unsigned char const*) {}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -0,0 +1,22 @@
/* -*- 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/.
*/
#include <cstdlib>
#include <uno/mapping.h>
#include <uno/any2.h>
namespace CPPU_CURRENT_NAMESPACE
{
void raiseException(uno_Any*, uno_Mapping*) { std::abort(); }
void fillUnoException(uno_Any*, uno_Mapping*) { std::abort(); }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -0,0 +1,93 @@
/* -*- 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/.
*/
#include <com/sun/star/uno/RuntimeException.hpp>
#include <bridge.hxx>
#include <types.hxx>
#include <unointerfaceproxy.hxx>
#include <vtables.hxx>
using namespace ::com::sun::star::uno;
namespace bridges::cpp_uno::shared
{
void unoInterfaceProxyDispatch(uno_Interface* pUnoI, const typelib_TypeDescription* pMemberDescr,
void* pReturn, void* pArgs[], uno_Any** ppException)
{
bridges::cpp_uno::shared::UnoInterfaceProxy* pThis
= static_cast<bridges::cpp_uno::shared::UnoInterfaceProxy*>(pUnoI);
switch (pMemberDescr->eTypeClass)
{
case typelib_TypeClass_INTERFACE_ATTRIBUTE:
{
std::abort();
break;
}
case typelib_TypeClass_INTERFACE_METHOD:
{
VtableSlot aVtableSlot(getVtableSlot(
reinterpret_cast<typelib_InterfaceMethodTypeDescription const*>(pMemberDescr)));
switch (aVtableSlot.index)
{
case 1: // acquire uno interface
(*pUnoI->acquire)(pUnoI);
*ppException = 0;
break;
case 2: // release uno interface
(*pUnoI->release)(pUnoI);
*ppException = 0;
break;
case 0: // queryInterface() opt
{
typelib_TypeDescription* pTD = 0;
TYPELIB_DANGER_GET(&pTD, reinterpret_cast<Type*>(pArgs[0])->getTypeLibType());
if (pTD)
{
uno_Interface* pInterface = 0;
(*pThis->getBridge()->getUnoEnv()->getRegisteredInterface)(
pThis->getBridge()->getUnoEnv(), (void**)&pInterface, pThis->oid.pData,
(typelib_InterfaceTypeDescription*)pTD);
if (pInterface)
{
::uno_any_construct(reinterpret_cast<uno_Any*>(pReturn), &pInterface,
pTD, 0);
(*pInterface->release)(pInterface);
TYPELIB_DANGER_RELEASE(pTD);
*ppException = 0;
break;
}
TYPELIB_DANGER_RELEASE(pTD);
}
} // else perform queryInterface()
[[fallthrough]];
default:
std::abort();
}
break;
}
default:
{
::com::sun::star::uno::RuntimeException aExc(
"illegal member type description!",
::com::sun::star::uno::Reference<::com::sun::star::uno::XInterface>());
Type const& rExcType = cppu::UnoType<decltype(aExc)>::get();
// binary identical null reference
::uno_type_any_construct(*ppException, &aExc, rExcType.getTypeLibType(), 0);
}
}
}
} // namespace bridges::cpp_uno::shared
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -421,6 +421,7 @@ static Mapping loadExternalMapping(
OSL_ASSERT( aExt.is() );
if (aExt.is())
return aExt;
SAL_INFO("cppu", "Could not load external mapping for " << aName);
}
#else
// find proper lib

View file

@ -168,9 +168,15 @@ ExceptionThrower::ExceptionThrower()
uno_Interface::pDispatcher = ExceptionThrower_dispatch;
}
#if defined(IOS) || (defined(__aarch64__) && defined(ANDROID)) || defined(EMSCRIPTEN)
#define RETHROW_FAKE_EXCEPTIONS 1
#else
#define RETHROW_FAKE_EXCEPTIONS 0
#endif
class theExceptionThrower : public rtl::Static<ExceptionThrower, theExceptionThrower> {};
#if defined(IOS) || (defined(__aarch64__) && defined(ANDROID))
#if RETHROW_FAKE_EXCEPTIONS
// In the native iOS / Android app, where we don't have any Java, Python,
// BASIC, or other scripting, the only thing that would use the C++/UNO bridge
// functionality that invokes codeSnippet() was cppu::throwException().
@ -208,7 +214,7 @@ void lo_mobile_throwException(css::uno::Any const& aException)
assert(false);
}
#endif // defined(IOS) || (defined(__aarch64__) && defined(ANDROID))
#endif // RETHROW_FAKE_EXCEPTIONS
} // anonymous namespace
@ -226,7 +232,7 @@ void SAL_CALL throwException( Any const & exc )
"(must be derived from com::sun::star::uno::Exception)!" );
}
#if defined(IOS) || (defined(__aarch64__) && defined(ANDROID))
#if RETHROW_FAKE_EXCEPTIONS
lo_mobile_throwException(exc);
#else
Mapping uno2cpp(Environment(UNO_LB_UNO), Environment::getCurrent());
@ -243,13 +249,14 @@ void SAL_CALL throwException( Any const & exc )
ExceptionThrower::getCppuType() );
OSL_ASSERT( xThrower.is() );
xThrower->throwException( exc );
#endif
#endif // !RETHROW_FAKE_EXCEPTIONS
}
Any SAL_CALL getCaughtException()
{
#if defined(__aarch64__) && defined(ANDROID)
// why does this differ from RETHROW_FAKE_EXCEPTIONS?
#if (defined(__aarch64__) && defined(ANDROID)) || defined(EMSCRIPTEN)
// FIXME This stuff works on 32bit ARM, let's use the shortcut only for
// the 64bit ARM.
return Any();

View file

@ -33,7 +33,7 @@
namespace {
#ifndef ANDROID
#if !(defined ANDROID || defined EMSCRIPTEN)
OUString get_this_libpath() {
static OUString s_uri = []() {
OUString uri;
@ -52,7 +52,7 @@ OUString get_this_libpath() {
}
OUString cppu::getUnoIniUri() {
#if defined ANDROID
#if defined ANDROID || defined EMSCRIPTEN
// Wouldn't it be lovely to avoid this ugly hard-coding.
// The problem is that the 'create_bootstrap_macro_expander_factory()'
// required for bootstrapping services, calls cppu::get_unorc directly