hack winpthread for win95

This commit is contained in:
crazii
2023-12-02 20:47:34 +08:00
parent 0cbe15e2fd
commit 697a62babb
4 changed files with 92 additions and 23 deletions

View File

@@ -1,20 +0,0 @@
diff --git "a/mingw-w64-libraries/winpthreads/src/thread.c" "b/mingw-w64-libraries/winpthreads/src/thread.c"
index 2eb76db..ec0b89d 100644
--- "a/mingw-w64-libraries/winpthreads/src/thread.c"
+++ "b/mingw-w64-libraries/winpthreads/src/thread.c"
@@ -117,6 +117,7 @@ SetThreadName (DWORD dwThreadID, LPCSTR szThreadName)
{
}
#else
+#if _WIN32_WINNT >= _WIN32_WINNT_WINXP
/* Without a debugger we *must* have an exception handler,
* otherwise raising an exception will crash the process.
*/
@@ -124,6 +125,7 @@ SetThreadName (DWORD dwThreadID, LPCSTR szThreadName)
if ((!IsDebuggerPresent ()) && (SetThreadName_VEH_handle == NULL))
#else
if (!IsDebuggerPresent ())
+#endif
#endif
return;

View File

@@ -0,0 +1,54 @@
diff --git "a/mingw-w64-libraries/winpthreads/src/thread.c" "b/mingw-w64-libraries/winpthreads/src/thread.c"
index 2eb76db..2df4e79 100644
--- "a/mingw-w64-libraries/winpthreads/src/thread.c"
+++ "b/mingw-w64-libraries/winpthreads/src/thread.c"
@@ -117,6 +117,7 @@ SetThreadName (DWORD dwThreadID, LPCSTR szThreadName)
{
}
#else
+#if _WIN32_WINNT >= _WIN32_WINNT_WINXP
/* Without a debugger we *must* have an exception handler,
* otherwise raising an exception will crash the process.
*/
@@ -124,6 +125,7 @@ SetThreadName (DWORD dwThreadID, LPCSTR szThreadName)
if ((!IsDebuggerPresent ()) && (SetThreadName_VEH_handle == NULL))
#else
if (!IsDebuggerPresent ())
+#endif
#endif
return;
@@ -717,6 +719,7 @@ int
pthread_num_processors_np(void)
{
int r = 0;
+ #if _WIN32_WINNT >= _WIN32_WINNT_WINXP
DWORD_PTR ProcessAffinityMask, SystemAffinityMask;
if (GetProcessAffinityMask(GetCurrentProcess(), &ProcessAffinityMask, &SystemAffinityMask))
@@ -724,6 +727,7 @@ pthread_num_processors_np(void)
for(; ProcessAffinityMask != 0; ProcessAffinityMask >>= 1)
r += (ProcessAffinityMask & 1) != 0;
}
+ #endif
/* assume at least 1 */
return r ? r : 1;
}
@@ -733,6 +737,7 @@ pthread_num_processors_np(void)
int
pthread_set_num_processors_np(int n)
{
+#if _WIN32_WINNT >= _WIN32_WINNT_WINXP
DWORD_PTR ProcessAffinityMask, ProcessNewAffinityMask = 0, SystemAffinityMask;
int r = 0;
/* need at least 1 */
@@ -751,6 +756,9 @@ pthread_set_num_processors_np(int n)
SetProcessAffinityMask (GetCurrentProcess (),ProcessNewAffinityMask);
}
return r;
+#else
+ return 1;
+#endif
}
int

View File

@@ -0,0 +1,32 @@
diff --git "a/mingw-w64-libraries/winpthreads/src/cond.c" "b/mingw-w64-libraries/winpthreads/src/cond.c"
index d50f85b..a7d8ee6 100644
--- "a/mingw-w64-libraries/winpthreads/src/cond.c"
+++ "b/mingw-w64-libraries/winpthreads/src/cond.c"
@@ -52,6 +52,27 @@ typedef struct sCondWaitHelper {
int do_sema_b_wait_intern (HANDLE sema, int nointerrupt, DWORD timeout);
+
+typedef BOOL (WINAPI *PTRYENTERCRITICALSECTION)(LPCRITICAL_SECTION);
+static PTRYENTERCRITICALSECTION pTryEnterCriticalSection;
+static BOOL TryEnterCriticalSectionInit;
+BOOL TryEnterCriticalSectionWrapper(LPCRITICAL_SECTION cs)
+{
+ if(pTryEnterCriticalSection == NULL && !TryEnterCriticalSectionInit)
+ {
+ pTryEnterCriticalSection = GetProcAddress(GetModuleHandleA("kernel32.dll"),"TryEnterCriticalSection");
+ TryEnterCriticalSectionInit = TRUE;
+ }
+
+ if(pTryEnterCriticalSection)
+ return pTryEnterCriticalSection(cs);
+
+ EnterCriticalSection(cs);
+ return TRUE;
+}
+
+#define TryEnterCriticalSection TryEnterCriticalSectionWrapper
+
#ifdef WINPTHREAD_DBG
static int print_state = 0;
static FILE *fo;

View File

@@ -27,10 +27,12 @@ makedepends=("git"
options=('!emptydirs')
source=("mingw-w64"::"git+https://git.code.sf.net/p/mingw-w64/mingw-w64#commit=$_commit"
"0001-Define-__-de-register_frame_info-in-fake-libgcc_s.patch"
"0002-IsDebuggerPresent.patch")
"0002-IsDebuggerPresent_ProcessAffinityMask.patch"
"0003-TryEnterCriticalSection.patch")
sha256sums=('SKIP'
'd9e8af81682d9bf70e3d87506f51156cec61260b810a234bce861cb2eb3a5919'
'191A4C86ABF7AA6D82903ACED1FEF3263DE9646F0E5AA1E341B62005EED522D0')
'B0D0E21AF527FF208089EAB7BC3B635489A2C1300508278349902BBCD389555C'
'0E1CD2BA775BD6067E0011C641099A571A7310BD380FF369777CBCBA99448A0D')
pkgver() {
cd "${srcdir}/mingw-w64"
@@ -41,7 +43,8 @@ prepare() {
cd "${srcdir}/mingw-w64"
[[ -f mingw-w64-libraries/winpthreads/src/libgcc/dll_frame_info.c ]] && rm -rf mingw-w64-libraries/winpthreads/src/libgcc/dll_frame_info.c
git apply "${srcdir}"/0001-Define-__-de-register_frame_info-in-fake-libgcc_s.patch
git apply "${srcdir}"/0002-IsDebuggerPresent.patch
git apply "${srcdir}"/0002-IsDebuggerPresent_ProcessAffinityMask.patch
git apply "${srcdir}"/0003-TryEnterCriticalSection.patch
cd "${srcdir}"/mingw-w64/mingw-w64-libraries/winpthreads
autoreconf -vfi