Module: wine
Branch: master
Commit: df5f9b7d2b5395c1a537981b802b804b9f93b8ae
URL: https://gitlab.winehq.org/wine/wine/-/commit/df5f9b7d2b5395c1a537981b802b80…
Author: Jinoh Kang <jinoh.kang.kr(a)gmail.com>
Date: Wed Mar 22 01:36:45 2023 +0900
ntdll: Don't report user (PE) stack via pthread_attr_setstack().
Today, NtCreateThreadEx() passes to pthread_attr_setstack() an address
range that spans both the user (PE) stack and the kernel (Unix) stack.
pthread_attr_setstack() accepts an address range that will be used as
the initial stack area for the thread created by pthread_create(). It
is often assumed that the initial stack will be available for the entire
duration of the thread's lifetime.
This assumption, however, conflicts with how Win32 fibers operate.
Fiber APIs allow the thread's initial stack to be freed before the
thread exits, or kept alive beyond the point of thread's termination.
This allows the lifetime of the thread's initial stack to be shorter or
longer than the originating thread's lifetime. This is possible because
each fiber has its own stack and context, and ConvertThreadToFiber()
transfers the current thread's stack to a new fiber.
This specifically causes problems in Glibc v2.31 and earlier. These
Glibc versions have a bug where madvise(2) with the MADV_DONTNEED flag
is called on the initial stack area on thread exit, even when the stack
was user-supplied (via pthread_attr_setstack). Therefore, the kernel
may zero out any portion of the initial stack at any time after the
originating thread terminates, even if the stack no longer belongs to
the current thread (either freed and reallocated, or owned by a fiber).
This may ultimately lead to memory corruption.
Fix this by only passing the syscall (kernel) portion of the stack to
pthread_attr_setstack().
---
dlls/ntdll/unix/thread.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/dlls/ntdll/unix/thread.c b/dlls/ntdll/unix/thread.c
index 4c8c04cf9fc..9b0b5f7ce22 100644
--- a/dlls/ntdll/unix/thread.c
+++ b/dlls/ntdll/unix/thread.c
@@ -1377,8 +1377,7 @@ NTSTATUS WINAPI NtCreateThreadEx( HANDLE *handle, ACCESS_MASK access, OBJECT_ATT
thread_data->param = param;
pthread_attr_init( &pthread_attr );
- pthread_attr_setstack( &pthread_attr, teb->DeallocationStack,
- (char *)thread_data->kernel_stack + kernel_stack_size - (char *)teb->DeallocationStack );
+ pthread_attr_setstack( &pthread_attr, thread_data->kernel_stack, kernel_stack_size );
pthread_attr_setguardsize( &pthread_attr, 0 );
pthread_attr_setscope( &pthread_attr, PTHREAD_SCOPE_SYSTEM ); /* force creating a kernel thread */
InterlockedIncrement( &nb_threads );
Module: wine
Branch: master
Commit: 4fab9ff230f497499da223ade9bbe3633a657f05
URL: https://gitlab.winehq.org/wine/wine/-/commit/4fab9ff230f497499da223ade9bbe3…
Author: Mohamad Al-Jaf <mohamadaljaf(a)gmail.com>
Date: Thu Feb 2 22:06:57 2023 -0500
cfgmgr32: Implement CM_MapCrToWin32Err.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53781
---
dlls/cfgmgr32/Makefile.in | 3 +++
dlls/cfgmgr32/cfgmgr32.spec | 1 +
dlls/cfgmgr32/main.c | 58 +++++++++++++++++++++++++++++++++++++++++++++
include/cfgmgr32.h | 1 +
4 files changed, 63 insertions(+)
diff --git a/dlls/cfgmgr32/Makefile.in b/dlls/cfgmgr32/Makefile.in
index 10621fa5dc7..f05b3176aa3 100644
--- a/dlls/cfgmgr32/Makefile.in
+++ b/dlls/cfgmgr32/Makefile.in
@@ -1,3 +1,6 @@
MODULE = cfgmgr32.dll
IMPORTLIB = cfgmgr32
IMPORTS = setupapi
+
+C_SRCS = \
+ main.c
diff --git a/dlls/cfgmgr32/cfgmgr32.spec b/dlls/cfgmgr32/cfgmgr32.spec
index 69ec784de68..3b4f6106618 100644
--- a/dlls/cfgmgr32/cfgmgr32.spec
+++ b/dlls/cfgmgr32/cfgmgr32.spec
@@ -126,6 +126,7 @@
@ stdcall CM_Locate_DevNodeW(ptr wstr long) setupapi.CM_Locate_DevNodeW
@ stdcall CM_Locate_DevNode_ExA(ptr str long long) setupapi.CM_Locate_DevNode_ExA
@ stdcall CM_Locate_DevNode_ExW(ptr wstr long long) setupapi.CM_Locate_DevNode_ExW
+@ stdcall CM_MapCrToWin32Err(long long)
@ stub CM_Merge_Range_List
@ stub CM_Modify_Res_Des
@ stub CM_Modify_Res_Des_Ex
diff --git a/dlls/cfgmgr32/main.c b/dlls/cfgmgr32/main.c
new file mode 100644
index 00000000000..fee3c42a5c4
--- /dev/null
+++ b/dlls/cfgmgr32/main.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2023 Mohamad Al-Jaf
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "wine/debug.h"
+#include "cfgmgr32.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
+
+/***********************************************************************
+ * CM_MapCrToWin32Err (cfgmgr32.@)
+ */
+DWORD WINAPI CM_MapCrToWin32Err( CONFIGRET code, DWORD default_error )
+{
+ TRACE( "code: %#lx, default_error: %ld\n", code, default_error );
+
+ switch (code)
+ {
+ case CR_SUCCESS: return ERROR_SUCCESS;
+ case CR_OUT_OF_MEMORY: return ERROR_NOT_ENOUGH_MEMORY;
+ case CR_INVALID_POINTER: return ERROR_INVALID_USER_BUFFER;
+ case CR_INVALID_FLAG: return ERROR_INVALID_FLAGS;
+ case CR_INVALID_DEVNODE:
+ case CR_INVALID_DEVICE_ID:
+ case CR_INVALID_MACHINENAME:
+ case CR_INVALID_PROPERTY:
+ case CR_INVALID_REFERENCE_STRING: return ERROR_INVALID_DATA;
+ case CR_NO_SUCH_DEVNODE:
+ case CR_NO_SUCH_VALUE:
+ case CR_NO_SUCH_DEVICE_INTERFACE: return ERROR_NOT_FOUND;
+ case CR_ALREADY_SUCH_DEVNODE: return ERROR_ALREADY_EXISTS;
+ case CR_BUFFER_SMALL: return ERROR_INSUFFICIENT_BUFFER;
+ case CR_NO_REGISTRY_HANDLE: return ERROR_INVALID_HANDLE;
+ case CR_REGISTRY_ERROR: return ERROR_REGISTRY_CORRUPT;
+ case CR_NO_SUCH_REGISTRY_KEY: return ERROR_FILE_NOT_FOUND;
+ case CR_REMOTE_COMM_FAILURE:
+ case CR_MACHINE_UNAVAILABLE:
+ case CR_NO_CM_SERVICES: return ERROR_SERVICE_NOT_ACTIVE;
+ case CR_ACCESS_DENIED: return ERROR_ACCESS_DENIED;
+ case CR_CALL_NOT_IMPLEMENTED: return ERROR_CALL_NOT_IMPLEMENTED;
+ }
+
+ return default_error;
+}
diff --git a/include/cfgmgr32.h b/include/cfgmgr32.h
index d300c4babaa..b78f118622e 100644
--- a/include/cfgmgr32.h
+++ b/include/cfgmgr32.h
@@ -242,6 +242,7 @@ CMAPI WORD WINAPI CM_Get_Version(void);
CMAPI CONFIGRET WINAPI CM_Locate_DevNodeA(PDEVINST,DEVINSTID_A,ULONG);
CMAPI CONFIGRET WINAPI CM_Locate_DevNodeW(PDEVINST,DEVINSTID_W,ULONG);
#define CM_Locate_DevNode WINELIB_NAME_AW(CM_Locate_DevNode)
+CMAPI DWORD WINAPI CM_MapCrToWin32Err(CONFIGRET,DWORD);
CMAPI CONFIGRET WINAPI CM_Open_DevNode_Key(DEVINST dnDevInst, REGSAM access, ULONG ulHardwareProfile,
REGDISPOSITION disposition, PHKEY phkDevice, ULONG ulFlags);
CMAPI CONFIGRET WINAPI CM_Request_Device_EjectA(DEVINST dev, PPNP_VETO_TYPE type, LPSTR name, ULONG length, ULONG flags);