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

leginee pushed a commit to branch bazel-migration
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 1ac44d4c16cd8c7fb00879e708b1c066c88ccc26
Author: Peter Kovacs <[email protected]>
AuthorDate: Sat Jul 25 10:47:53 2026 +0200

    sal/vcl: Win64 (x64) runtime source fixes -- thread key + window pointers
    
    Pointer-width fixes on the runtime boot path (all compile unchanged on x86;
    dmake-backportable):
    
    - sal osl/thread.h: oslThreadKey sal_uInt32 -> sal_uIntPtr.  The w32
      osl_createThreadKey returns a heap PTLS* stuffed into the key; on LLP64 
that
      64-bit pointer was truncated, so osl_getThreadKeyData dereferenced garbage
      (first crash: cppu getIdContainer during InitVCL).  Not present in
      origin/windows-amd64 (their thread.h/.c match trunk) -- authored here.
    - vcl win/saldata: ImplSet/GetWindowLong -> LONG_PTR + 
Set/GetWindowLongPtrW,
      SetWindowPtr/SetSalObjWindowPtr (LONG)->(LONG_PTR) (frame pointer stored 
in the
      window's extra bytes was truncated -> sign-extended garbage in
      UpdateFrameGeometry) (ref 9b64d14c8d); SAL_FRAME/OBJECT_WNDEXTRA 
sizeof(DWORD)
      -> sizeof(ULONG_PTR) so the 8-byte pointer fits the reserve (added beyond 
the
      reference, which relied on Windows over-allocating); ImplSendMessage BOOL 
->
      LRESULT (WinSalInstance::CreateFrame/CreateObject route the new
      SalFrame*/SalObject* back as the SAL_MSG_CREATE* message result -- BOOL
      truncated it, causing an AV in SalFrame::SetCallback; also fixes the 
latent
      HDC/HWND truncations at the other call sites).
    
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
    (cherry picked from commit cc0a3ed6d1e1f10040e030b974c4b0ab9c6fbf17)
---
 main/sal/inc/osl/thread.h           |  7 ++++++-
 main/vcl/inc/win/saldata.hxx        | 18 +++++++++++-------
 main/vcl/win/source/app/saldata.cxx | 18 +++++++++++-------
 3 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/main/sal/inc/osl/thread.h b/main/sal/inc/osl/thread.h
index 0378f53717..8009403730 100644
--- a/main/sal/inc/osl/thread.h
+++ b/main/sal/inc/osl/thread.h
@@ -63,7 +63,12 @@ typedef enum
 
 typedef sal_uInt32 oslThreadIdentifier;
 
-typedef sal_uInt32 oslThreadKey;
+/* oslThreadKey holds a pointer (the w32 impl returns a PTLS*, the unx impl a
+ * pthread_key_t/index); it MUST be pointer-width or the w32 
osl_createThreadKey
+ * pointer is truncated on Win64 (LLP64) → osl_getThreadKeyData derefs a bad
+ * pointer and crashes (first seen: cppu getIdContainer during InitVCL).
+ * sal_uIntPtr == sal_uInt32 on x86 (unchanged) / sal_uInt64 on x64. */
+typedef sal_uIntPtr oslThreadKey;
 
 /** Create the thread, using the function-ptr pWorker as
        its main (worker) function. This functions receives in
diff --git a/main/vcl/inc/win/saldata.hxx b/main/vcl/inc/win/saldata.hxx
index 8c40b816ad..a10e79ac2a 100644
--- a/main/vcl/inc/win/saldata.hxx
+++ b/main/vcl/inc/win/saldata.hxx
@@ -253,14 +253,18 @@ int ImplSalWICompareAscii( const wchar_t* pStr1, const 
char* pStr2 );
 // - Defines -
 // -----------
 
-#define SAL_FRAME_WNDEXTRA          sizeof( DWORD )
+/* Extra window bytes hold the WinSalFrame* (SAL_FRAME_THIS, offset 0) via
+ * Set/GetWindowLongPtr — so the reserve MUST be pointer-width, else the 8-byte
+ * store on Win64 overruns a 4-byte reserve.  sizeof(ULONG_PTR) == 4 on x86
+ * (unchanged) / 8 on x64. */
+#define SAL_FRAME_WNDEXTRA          sizeof( ULONG_PTR )
 #define SAL_FRAME_THIS              0
 #define SAL_FRAME_CLASSNAMEA        "SALFRAME"
 #define SAL_FRAME_CLASSNAMEW        L"SALFRAME"
 #define SAL_SUBFRAME_CLASSNAMEA     "SALSUBFRAME"
 #define SAL_SUBFRAME_CLASSNAMEW     L"SALSUBFRAME"
 #define SAL_TMPSUBFRAME_CLASSNAMEW  L"SALTMPSUBFRAME"
-#define SAL_OBJECT_WNDEXTRA         sizeof( DWORD )
+#define SAL_OBJECT_WNDEXTRA         sizeof( ULONG_PTR )
 #define SAL_OBJECT_THIS             0
 #define SAL_OBJECT_CLASSNAMEA       "SALOBJECT"
 #define SAL_OBJECT_CLASSNAMEW       L"SALOBJECT"
@@ -344,17 +348,17 @@ int ImplSalWICompareAscii( const wchar_t* pStr1, const 
char* pStr2 );
 // -----------------
 
 // A/W-Wrapper
-LONG        ImplSetWindowLong( HWND hWnd, int nIndex, DWORD dwNewLong );
-LONG        ImplGetWindowLong( HWND hWnd, int nIndex );
+LONG_PTR        ImplSetWindowLong( HWND hWnd, int nIndex, LONG_PTR newLong );
+LONG_PTR        ImplGetWindowLong( HWND hWnd, int nIndex );
 BOOL    ImplPostMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );
-BOOL    ImplSendMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );
+LRESULT ImplSendMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );
 BOOL    ImplGetMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT 
wMsgFilterMax );
 BOOL    ImplPeekMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT 
wMsgFilterMax, UINT wRemoveMsg );
 LONG        ImplDispatchMessage( CONST MSG *lpMsg );
 
 inline void SetWindowPtr( HWND hWnd, WinSalFrame* pThis )
 {
-    ImplSetWindowLong( hWnd, SAL_FRAME_THIS, (LONG)pThis );
+    ImplSetWindowLong( hWnd, SAL_FRAME_THIS, (LONG_PTR)pThis );
 }
 
 inline WinSalFrame* GetWindowPtr( HWND hWnd )
@@ -364,7 +368,7 @@ inline WinSalFrame* GetWindowPtr( HWND hWnd )
 
 inline void SetSalObjWindowPtr( HWND hWnd, WinSalObject* pThis )
 {
-    ImplSetWindowLong( hWnd, SAL_OBJECT_THIS, (LONG)pThis );
+    ImplSetWindowLong( hWnd, SAL_OBJECT_THIS, (LONG_PTR)pThis );
 }
 
 inline WinSalObject* GetSalObjWindowPtr( HWND hWnd )
diff --git a/main/vcl/win/source/app/saldata.cxx 
b/main/vcl/win/source/app/saldata.cxx
index f643f07cf7..b95c08d4ce 100644
--- a/main/vcl/win/source/app/saldata.cxx
+++ b/main/vcl/win/source/app/saldata.cxx
@@ -114,16 +114,16 @@ int ImplSalWICompareAscii( const wchar_t* pStr1, const 
char* pStr2 )
 
 // =======================================================================
 
-LONG ImplSetWindowLong( HWND hWnd, int nIndex, DWORD dwNewLong )
+LONG_PTR ImplSetWindowLong( HWND hWnd, int nIndex, LONG_PTR newLong )
 {
-       return SetWindowLongW( hWnd, nIndex, dwNewLong );
+       return SetWindowLongPtrW( hWnd, nIndex, newLong );
 }
 
 // -----------------------------------------------------------------------
 
-LONG ImplGetWindowLong( HWND hWnd, int nIndex )
+LONG_PTR ImplGetWindowLong( HWND hWnd, int nIndex )
 {
-       return GetWindowLongW( hWnd, nIndex );
+       return GetWindowLongPtrW( hWnd, nIndex );
 }
 
 // -----------------------------------------------------------------------
@@ -135,10 +135,14 @@ BOOL ImplPostMessage( HWND hWnd, UINT nMsg, WPARAM 
wParam, LPARAM lParam )
 
 // -----------------------------------------------------------------------
 
-BOOL ImplSendMessage( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
+/* MUST return LRESULT (LONG_PTR), not BOOL: WinSalInstance::CreateFrame /
+ * CreateObject route the new SalFrame / SalObject pointer back as the
+ * SAL_MSG_CREATE* message result (an LRESULT).  Truncating that to 32-bit BOOL
+ * loses the high pointer bits on Win64 -> the caller derefs a truncated frame
+ * (AV in SalFrame::SetCallback during InitVCL/splash). */
+LRESULT ImplSendMessage( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam )
 {
-       BOOL bRet = SendMessageW( hWnd, nMsg, wParam, lParam );
-    return bRet;
+       return SendMessageW( hWnd, nMsg, wParam, lParam );
 }
 
 // -----------------------------------------------------------------------

Reply via email to