#3 Add support for Windows 98
Opened 7 months ago by js. Modified 7 months ago
rpms/ js/mingw-winpthreads f39  into  f39

Add support for Windows 98
Jonathan Schleifer • 7 months ago  
file modified
+7 -2
@@ -6,7 +6,7 @@ 

  

  Name:           mingw-winpthreads

  Version:        11.0.0

- Release:        2%{?dist}

+ Release:        3%{?dist}

  Summary:        MinGW pthread library

  

  # The main license of winpthreads is MIT, but parts of this library
@@ -16,6 +16,8 @@ 

  URL:            http://mingw-w64.sourceforge.net/

  Source0:        http://downloads.sourceforge.net/mingw-w64/mingw-w64-v%{version}%{?pre:-%{pre}}.tar.bz2

  

+ Patch0:         winpthreads_win98.patch

+ 

  BuildArch:      noarch

  

  BuildRequires:  make
@@ -135,7 +137,7 @@ 

  

  

  %prep

- %autosetup -p1 -n mingw-w64-v%{version}%{?pre:-%{pre}}

+ %autosetup -p0 -n mingw-w64-v%{version}%{?pre:-%{pre}}

  

  

  %build
@@ -231,6 +233,9 @@ 

  

  

  %changelog

+ * Fri Oct 20 2023 Jonathan Schleifer <js@nil.im> - 11.0.0-3

+ - Add support for Windows 98

+ 

  * Thu Jul 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 11.0.0-2

  - Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

  

@@ -0,0 +1,85 @@ 

+ --- mingw-w64-libraries/winpthreads/src/misc.c.orig	2023-01-05 21:10:06.158696700 +0100

+ +++ mingw-w64-libraries/winpthreads/src/misc.c	2023-01-05 21:14:13.736070700 +0100

+ @@ -24,6 +24,16 @@

+  #include "windows.h"

+  #include "misc.h"

+  

+ +static ULONGLONG (*GetTickCount64FuncPtr) (VOID);

+ +

+ +static void __attribute__((constructor)) ctor (void)

+ +{

+ +  HMODULE module = LoadLibrary("kernel32.dll");

+ +  if (module == NULL) return;

+ +

+ +  GetTickCount64FuncPtr = (__typeof__(GetTickCount64FuncPtr)) GetProcAddress(module, "GetTickCount64");

+ +}

+ +

+  unsigned long long _pthread_time_in_ms(void)

+  {

+      FILETIME ft;

+ @@ -55,10 +65,9 @@

+  static unsigned long long

+  _pthread_get_tick_count (long long *frequency)

+  {

+ -#if defined (_WIN32_WINNT) && (_WIN32_WINNT >= _WIN32_WINNT_VISTA)

+ -  (void) frequency; /* unused */

+ -  return GetTickCount64 ();

+ -#else

+ +  if (GetTickCount64FuncPtr != NULL)

+ +    return GetTickCount64FuncPtr ();

+ +

+    LARGE_INTEGER freq, timestamp;

+  

+    if (*frequency == 0)

+ @@ -74,7 +83,6 @@

+  

+    /* Fallback */

+    return GetTickCount ();

+ -#endif

+  }

+  

+  /* A wrapper around WaitForSingleObject() that ensures that

+ --- mingw-w64-libraries/winpthreads/src/thread.c.orig	2022-04-03 17:08:58.000000000 +0200

+ +++ mingw-w64-libraries/winpthreads/src/thread.c	2023-01-05 18:47:08.847116100 +0100

+ @@ -74,6 +74,19 @@

+  

+    return EXCEPTION_CONTINUE_SEARCH;

+  }

+ +

+ +static PVOID (*AddVectoredExceptionHandlerFuncPtr) (ULONG, PVECTORED_EXCEPTION_HANDLER);

+ +static ULONG (*RemoveVectoredExceptionHandlerFuncPtr) (PVOID);

+ +

+ +static void __attribute__((constructor))

+ +ctor (void)

+ +{

+ +  HMODULE module = LoadLibrary("kernel32.dll");

+ +  if (module == NULL) return;

+ +

+ +  AddVectoredExceptionHandlerFuncPtr = (__typeof__(AddVectoredExceptionHandlerFuncPtr)) GetProcAddress(module, "AddVectoredExceptionHandler");

+ +  RemoveVectoredExceptionHandlerFuncPtr = (__typeof__(RemoveVectoredExceptionHandlerFuncPtr)) GetProcAddress(module, "RemoveVectoredExceptionHandler");

+ +}

+  #endif

+  

+  typedef struct _THREADNAME_INFO

+ @@ -434,7 +447,8 @@

+  #if defined(USE_VEH_FOR_MSC_SETTHREADNAME)

+        if (lpreserved == NULL && SetThreadName_VEH_handle != NULL)

+          {

+ -          RemoveVectoredExceptionHandler (SetThreadName_VEH_handle);

+ +          if (RemoveVectoredExceptionHandlerFuncPtr != NULL)

+ +            RemoveVectoredExceptionHandlerFuncPtr (SetThreadName_VEH_handle);

+            SetThreadName_VEH_handle = NULL;

+          }

+  #endif

+ @@ -443,7 +457,10 @@

+    else if (dwReason == DLL_PROCESS_ATTACH)

+      {

+  #if defined(USE_VEH_FOR_MSC_SETTHREADNAME)

+ -      SetThreadName_VEH_handle = AddVectoredExceptionHandler (1, &SetThreadName_VEH);

+ +      if (AddVectoredExceptionHandlerFuncPtr != NULL)

+ +        SetThreadName_VEH_handle = AddVectoredExceptionHandlerFuncPtr (1, &SetThreadName_VEH);

+ +      else

+ +        SetThreadName_VEH_handle = NULL;

+        /* Can't do anything on error anyway, check for NULL later */

+  #endif

+      }

Will forward-port to rawhide if this is deemed acceptable (f39 because that's where I tested it for now).

What's the rationale for this if I may ask? I'd expect many more incompatibilities of current mingw-w64 with such an ancient Windows version.

Actually, it is enough and there are no other incompatibilities. It makes ObjFW's https://objfw.nil.im/ quite extensive test suite pass entirely, which means exceptions, threads, sockets, etc. and much more work. I've been using this patch since January. It even works when compiling with clang -target i686-w64-mingw32 since Fedora 39.

If you're asking what the ultimate goal here is: I'm writing a 3D engine for old Voodoo cards which work best on Windows 98.

I've also proposed this patch upstream, but upstream is not very responsive.

Ok cool! Could you open the PR against rawhide, and then I'll do a branch merge to f39?