This is an automated email from the ASF dual-hosted git repository.

jimjag pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/openoffice.git


The following commit(s) were added to refs/heads/trunk by this push:
     new d9eb145fce Switch to JIT allocation
d9eb145fce is described below

commit d9eb145fced0c4f6421491789beb1b325cb8b5e8
Author: Jim Jagielski <[email protected]>
AuthorDate: Mon Aug 3 06:27:35 2026 -0400

    Switch to JIT allocation
---
 .../source/cpp_uno/s5abi_macosx_aarch64/abi.cxx    | 15 ++++++++++
 .../cpp_uno/s5abi_macosx_aarch64/cpp2uno.cxx       |  5 +++-
 .../source/cpp_uno/shared/vtablefactory.cxx        | 35 ++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/main/bridges/source/cpp_uno/s5abi_macosx_aarch64/abi.cxx 
b/main/bridges/source/cpp_uno/s5abi_macosx_aarch64/abi.cxx
index d51c5ccf12..dc10b9fb88 100644
--- a/main/bridges/source/cpp_uno/s5abi_macosx_aarch64/abi.cxx
+++ b/main/bridges/source/cpp_uno/s5abi_macosx_aarch64/abi.cxx
@@ -212,6 +212,21 @@ bool aarch64::examine_argument( 
typelib_TypeDescriptionReference *pTypeRef, bool
 
 bool aarch64::return_in_hidden_param( typelib_TypeDescriptionReference 
*pTypeRef )
 {
+    switch ( pTypeRef->eTypeClass )
+    {
+        case typelib_TypeClass_STRING:
+        case typelib_TypeClass_TYPE:
+        case typelib_TypeClass_ANY:
+        case typelib_TypeClass_TYPEDEF:
+        case typelib_TypeClass_SEQUENCE:
+        case typelib_TypeClass_INTERFACE:
+            // These are C++ wrapper objects, not pointer-sized scalar values.
+            // Apple's arm64 C++ ABI returns them through the buffer in x8.
+            return true;
+        default:
+            break;
+    }
+
     int g, s;
     // Returned in registers iff examine_argument() says it fits; otherwise the
     // caller must pass an indirect-result buffer in x8.
diff --git a/main/bridges/source/cpp_uno/s5abi_macosx_aarch64/cpp2uno.cxx 
b/main/bridges/source/cpp_uno/s5abi_macosx_aarch64/cpp2uno.cxx
index 6fa6bac7a2..c1ed5e8be2 100644
--- a/main/bridges/source/cpp_uno/s5abi_macosx_aarch64/cpp2uno.cxx
+++ b/main/bridges/source/cpp_uno/s5abi_macosx_aarch64/cpp2uno.cxx
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <hash_map>
+#include <libkern/OSCacheControl.h>
 
 #include <rtl/alloc.h>
 #include <osl/mutex.hxx>
@@ -538,6 +539,8 @@ unsigned char * 
bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
 
 
//==================================================================================================
 void bridges::cpp_uno::shared::VtableFactory::flushCode(
-       unsigned char const *, unsigned char const * )
+       unsigned char const * begin, unsigned char const * end )
 {
+       sys_icache_invalidate(
+               const_cast<unsigned char *>(begin), end - begin );
 }
diff --git a/main/bridges/source/cpp_uno/shared/vtablefactory.cxx 
b/main/bridges/source/cpp_uno/shared/vtablefactory.cxx
index 8a2832c314..39cdee1cfb 100644
--- a/main/bridges/source/cpp_uno/shared/vtablefactory.cxx
+++ b/main/bridges/source/cpp_uno/shared/vtablefactory.cxx
@@ -53,6 +53,9 @@
 #include <unistd.h>
 #include <string.h>
 #include <sys/mman.h>
+#if defined MACOSX && defined AARCH64
+#include <pthread.h>
+#endif
 #elif defined SAL_W32
 #define WIN32_LEAN_AND_MEAN
 #ifdef _MSC_VER
@@ -74,6 +77,27 @@ using bridges::cpp_uno::shared::VtableFactory;
 
 namespace {
 
+#if defined MACOSX && defined AARCH64
+class JitWriteGuard
+{
+public:
+    JitWriteGuard(): m_active(pthread_jit_write_protect_supported_np() != 0)
+    {
+        if (m_active)
+            pthread_jit_write_protect_np(0);
+    }
+
+    ~JitWriteGuard()
+    {
+        if (m_active)
+            pthread_jit_write_protect_np(1);
+    }
+
+private:
+    bool m_active;
+};
+#endif
+
 extern "C" void * SAL_CALL allocExec(rtl_arena_type *, sal_Size * size) {
     sal_Size pagesize;
 #if defined SAL_UNX
@@ -96,17 +120,25 @@ extern "C" void * SAL_CALL allocExec(rtl_arena_type *, 
sal_Size * size) {
     sal_Size n = (*size + (pagesize - 1)) & ~(pagesize - 1);
     void * p;
 #if defined SAL_UNX
+#if defined MACOSX && defined AARCH64
+    p = mmap(
+        0, n, PROT_READ | PROT_WRITE | PROT_EXEC,
+        MAP_PRIVATE | MAP_ANON | MAP_JIT, -1, 0);
+#else
     p = mmap(
         0, n, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1,
         0);
+#endif
     if (p == MAP_FAILED) {
         p = 0;
     }
+#if !defined MACOSX || !defined AARCH64
        else if (mprotect (static_cast<char*>(p), n, PROT_READ | PROT_WRITE | 
PROT_EXEC) == -1)
        {
                munmap (static_cast<char*>(p), n);
                p = 0;
        }
+#endif
 #elif defined SAL_W32
     p = VirtualAlloc(0, n, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
 #elif defined(SAL_OS2)
@@ -342,6 +374,9 @@ void VtableFactory::createVtables(
             throw std::bad_alloc();
         }
         try {
+#if defined MACOSX && defined AARCH64
+            JitWriteGuard jitWriteGuard;
+#endif
             Slot * slots = initializeBlock(block.start, slotCount);
             unsigned char * codeBegin =
                 reinterpret_cast< unsigned char * >(slots);

Reply via email to