summaryrefslogtreecommitdiff
path: root/bridges
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-12-17 10:48:51 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-12-17 13:20:46 +0100
commit052efd869e12796815401fb29a975e49866e6ce7 (patch)
treeeca7c46833b77348dba6209cf580ae738a309f7c /bridges
parent456cc328c43f67994629204003247923d783db96 (diff)
Make the pthread_jit_write_protect_np call pair exception-safe
...just in case Change-Id: Id056ee4dfd64dd186f01d117cfede28f4b7f6c09 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107867 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'bridges')
-rw-r--r--bridges/source/cpp_uno/shared/vtablefactory.cxx81
1 files changed, 43 insertions, 38 deletions
diff --git a/bridges/source/cpp_uno/shared/vtablefactory.cxx b/bridges/source/cpp_uno/shared/vtablefactory.cxx
index 90c414290c1a..9d4c5d31dd3f 100644
--- a/bridges/source/cpp_uno/shared/vtablefactory.cxx
+++ b/bridges/source/cpp_uno/shared/vtablefactory.cxx
@@ -134,6 +134,13 @@ extern "C" void freeExec(
#endif
}
+#if defined MACOSX && defined __aarch64__
+struct JitMemoryProtectionGuard {
+ JitMemoryProtectionGuard() { pthread_jit_write_protect_np(0); }
+ ~JitMemoryProtectionGuard() { pthread_jit_write_protect_np(1); }
+};
+#endif
+
}
class VtableFactory::GuardedBlocks:
@@ -342,52 +349,50 @@ sal_Int32 VtableFactory::createVtables(
typelib_InterfaceTypeDescription * type, sal_Int32 vtableNumber,
typelib_InterfaceTypeDescription * mostDerived, bool includePrimary) const
{
+ {
#if defined MACOSX && defined __aarch64__
- // TODO: Should we handle resetting this in a exception-throwing-safe way?
- pthread_jit_write_protect_np(0);
+ JitMemoryProtectionGuard guard;
#endif
- if (includePrimary) {
- sal_Int32 slotCount
- = bridges::cpp_uno::shared::getPrimaryFunctions(type);
- Block block;
- if (!createBlock(block, slotCount)) {
- throw std::bad_alloc();
- }
- try {
- Slot * slots = initializeBlock(
- block.start, slotCount, vtableNumber, mostDerived);
- unsigned char * codeBegin =
- reinterpret_cast< unsigned char * >(slots);
- unsigned char * code = codeBegin;
- sal_Int32 vtableOffset = blocks.size() * sizeof (Slot *);
- for (typelib_InterfaceTypeDescription const * type2 = type;
- type2 != nullptr; type2 = type2->pBaseTypeDescription)
- {
- code = addLocalFunctions(
- &slots, code,
+ if (includePrimary) {
+ sal_Int32 slotCount
+ = bridges::cpp_uno::shared::getPrimaryFunctions(type);
+ Block block;
+ if (!createBlock(block, slotCount)) {
+ throw std::bad_alloc();
+ }
+ try {
+ Slot * slots = initializeBlock(
+ block.start, slotCount, vtableNumber, mostDerived);
+ unsigned char * codeBegin =
+ reinterpret_cast< unsigned char * >(slots);
+ unsigned char * code = codeBegin;
+ sal_Int32 vtableOffset = blocks.size() * sizeof (Slot *);
+ for (typelib_InterfaceTypeDescription const * type2 = type;
+ type2 != nullptr; type2 = type2->pBaseTypeDescription)
+ {
+ code = addLocalFunctions(
+ &slots, code,
#ifdef USE_DOUBLE_MMAP
- reinterpret_cast<sal_uIntPtr>(block.exec) - reinterpret_cast<sal_uIntPtr>(block.start),
+ reinterpret_cast<sal_uIntPtr>(block.exec) - reinterpret_cast<sal_uIntPtr>(block.start),
#endif
- type2,
- baseOffset.getFunctionOffset(type2->aBase.pTypeName),
- bridges::cpp_uno::shared::getLocalFunctions(type2),
- vtableOffset);
- }
- flushCode(codeBegin, code);
+ type2,
+ baseOffset.getFunctionOffset(type2->aBase.pTypeName),
+ bridges::cpp_uno::shared::getLocalFunctions(type2),
+ vtableOffset);
+ }
+ flushCode(codeBegin, code);
#ifdef USE_DOUBLE_MMAP
- //Finished generating block, swap writable pointer with executable
- //pointer
- std::swap(block.start, block.exec);
+ //Finished generating block, swap writable pointer with executable
+ //pointer
+ std::swap(block.start, block.exec);
#endif
- blocks.push_back(block);
- } catch (...) {
- freeBlock(block);
- throw;
+ blocks.push_back(block);
+ } catch (...) {
+ freeBlock(block);
+ throw;
+ }
}
}
-#if defined MACOSX && defined __aarch64__
- pthread_jit_write_protect_np(1);
-#endif
for (sal_Int32 i = 0; i < type->nBaseTypes; ++i) {
vtableNumber = createVtables(
blocks, baseOffset, type->ppBaseTypes[i],