Skip to content

Latest commit

 

History

History
209 lines (114 loc) · 14.8 KB

File metadata and controls

209 lines (114 loc) · 14.8 KB

Wine Patches

This page documents the custom patches that are applied when building Wine for use with Unreal Engine.

Contents

CertSetCertificateContextProperty() patch

Upstream merge request: https://gitlab.winehq.org/wine/wine/-/merge_requests/10993

Status: Merged upstream in commit 213ee7e9

Patch file: cert-set-certificate-context-property.patch

The documentation for CertSetCertificateContextProperty() says pvData should contain a pointer to an NCRYPT_KEY_HANDLE, however the actual implementation of this function expects just the handle.

Without this fix, dotnet restore crashes during its initial setup.

Add case for SO_CONDITIONAL_ACCEPT in setsockopt()

Upstream merge request: None

Status: Unsuitable for submission upstream

Patch file: gdk_so_conditional_accept.patch

This patch adds a no-op case for SO_CONDITIONAL_ACCEPT in dlls/ws2_32/socket.c for setsockopt().

GlobalMemoryStatusEx cache control patch

Upstream merge request: None

Status: Unsuitable for submission upstream

Patch file: globalmemorystatusex-cache-window.patch

The Wine implementation of the GlobalMemoryStatusEx caches values from previous calls, returning the cached value if a new call is made within a specific timeframe. By default, the cache window is 1 second, but this patch makes the cache window configurable (and provides the option to disable caching altogether).

Add missing sections to ImageGetDigestStream

Upstream merge request: https://gitlab.winehq.org/wine/wine/-/merge_requests/10295

Status: Under review

Patch file: imagegetdigeststream.patch

Unreal Engine uses the Windows API ImageGetDigestStream() with the DigestLevel values of CERT_PE_IMAGE_DIGEST_RESOURCES | CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO to generate hash values using a callback function to read the given byte data and generate a hash values for each DLL listed below.

dxil.dll
dxcompiler.dll
ShaderConductor.dll

The combined DLL hash value is subsequently used with the ShaderModelHash, to generated a version hash for the given shader formats:

PCD3D_SM6
PCD3D_SM5

A DDC key is generated when processing the results of the compilation of a ShaderMap. This ShaderMap is saved to the DDC and the key is used to identify it within the DDC. This key includes the generated version hash described above for the shader type that is being compiled, either PCD3D_SM6 or PCD3D_SM5.

Wine's implementation of ImageGetDigestStream() is currently incomplete and does not include the code to process a number of PE file sections. Because of this, the byte data returned is different causing the hash values to differ for the same DLL on Wine and Windows.

To enable parity between the Windows and Wine behaviour for the Digest level CERT_PE_IMAGE_DIGEST_RESOURCES | CERT_PE_IMAGE_DIGEST_ALL_IMPORT_INFO the following changes needed to be applied:

  • The order of the returned sections .data and .rdata need to be changed.
  • The removal of the zeroing out of the data in the OptionalHeader for the fields SizeOfInitializedData and SizeOfImage to match the data returned by Windows.
  • The addition on the following PE file sections:
.pdata
.didat
.tls
.00cfg
_RDATA
.reloc
  • For signed DLL's such as dxil.dll, the byte data returned for Size and VirtualAddress in OptionalHeader[IMAGE_FILE_SECURITY_DIRECTORY] are required to be set to zero to match the Windows behaviour, as the certificate data is not used to generate hash values.

Add the minidump API set to Wine's API set schema

Upstream merge request: None

Status: Unsuitable for submission upstream

Patch file: minidump-apiset.patch

This patch adds the api-ms-win-core-debug-minidump API set to dlls/apisetschema/apisetschema.spec. This is required by some third-party SDKs.

Selective smaps_rollup patch

Upstream merge request: None

Status: Unsuitable for submission upstream

Patch file: selective-smaps-rollup.patch

By default, Wine reads process memory statistics from the file /proc/PID/status under Linux, which may report approximate values for performance reasons. This patch modifies the code to instead read the more accurate (but more expensive) values from the file /proc/PID/smaps_rollup, but only for the specific Unreal Engine thread named "ShaderCompilingThread", since this is the only thread that requires these more accurate values.

Memory patches to report cgroup usage and limit values inside containers and add support for overcommit prevention

Upstream merge request: None

Status: Unsuitable for submission upstream

Patch file: wine-overcommit-prevention-support.patch

This combined patchset addresses two issues:

  • By default, Wine reads system memory statistics from the file /proc/meminfo under Linux, which reports values for the entire host system even when accessed from inside a container. This results in incorrect values being reported to Unreal Engine when it is running under Wine inside a Linux container. This patch adds support for querying the memory statistics of the container's cgroup instead, ensuring Unreal Engine receives values that accurately reflect the container environment.

  • Unreal Engine includes functionality for detecting Out Of Memory (OOM) conditions under Windows and reporting them via the crash reporter. This functionality relies on the fact that Windows will refuse to overcommit memory and that memory allocation requests will fail in an OOM scenario. By contrast, the Linux kernel permits overcommitting memory by default and will invoke the Out Of Memory (OOM) killer to free up memory when an OOM condition is detected. This prevents Unreal Engine's OOM handling logic from triggering correctly under Wine. Although it is possible to configure the Linux kernel to disable overcommit, this setting applies at a system-wide level and cannot be controlled for individual Linux containers. Disabling overcommit at a system level may result in erratic or unexpected behaviour when running native Linux applications that were not designed to gracefully handle memory allocation failures. This patch adds support to Wine for preventing memory overcommit by Windows applications and reporting memory allocation failures in the same manner as Windows itself. This ensures Unreal Engine's OOM handling logic is triggered correctly, whilst avoiding adverse side effects for native Linux applications running on the same system.

The code in this patchset depends on two shared libraries that are stored outside of the Wine source tree: the memory shim (which is injected into all processes to intercept memory allocation functions) and libmemory-patches (which provides shared code directly used by the code in the patchset).

Historical Wine Patches

This section describes historical patches that are no longer maintained out-of-tree because they have been merged upstream and are present in the version of Wine that we target.

wineserver: Report non-zero exit code for abnormal process termination

Upstream merge request: https://gitlab.winehq.org/wine/wine/-/merge_requests/3908

Status: Merged upstream in commit 2dfeb87f, present in Wine 9.11 and newer

By default, Wine reports an exit code of zero for Windows processes that terminate due to their corresponding Linux process receiving a signal such as SIGKILL (e.g. due to a user manually killing the process, or the Linux Out Of Memory (OOM) killer targeting the process due to memory pressure). This makes it impossible to accurately detect failures when running child processes that are terminated in OOM scenarios, which is problematic when compiling code or shaders. This patch ensures that a non-zero exit code is reported in these scenarios so that they can be correctly detected.

Minidump backport patches

This file backported the minidump code changes from Wine 9.13 to the stable Wine 9.0 release, and was kindly provided by Eric Pouech from CodeWeavers.

ntdll.dll: Update NtQueryDirectoryFile to align with current Windows behaviour

Upstream merge request: https://gitlab.winehq.org/wine/wine/-/merge_requests/6904

Status: Merged upstream in commit a44f628c, present in Wine 10.3 and newer

Patch file: ntquerydirectoryfile-reset-mask.patch

Wine's implementation of the NtQueryDirectoryFile function behaves in a manner consistent with the description in Microsoft's documentation. However, Microsoft changed the behaviour of this function in Windows 8 without updating the corresponding documentation, and some applications such as MSVC have been designed to rely on the new behaviour. This patch implements the new behaviour under Wine, which fixes errors that can occur when compiling Unreal Engine's C++ code with the Visual Studio compiler toolchain.

cryptnet: Close leaking file handle in find_cached_revocation_status

Upstream merge request: https://gitlab.winehq.org/wine/wine/-/merge_requests/9894

Status: Merged upstream in commit df706cc9, present in Wine 11.1 and newer

Fixes an issue where find_cached_revocation_status only closes file handles in failure cases. This causes a leak of stdio stream handles. This leads to .NET MSBuild failing to build sufficiently large projects once all stream I/O indexes are used up and _wfsopen fails.

cmd.exe: Fix crashes when for_ctrl->set is empty

Upstream merge request: https://gitlab.winehq.org/wine/wine/-/merge_requests/10293

Status: Merged upstream in commit 5d6905a1, present in Wine 11.5 and newer

This change fixes an issue with cmd.exe, where attempting to loop over a null set using a for loop triggers a segfault. For example, this trivial example breaks under Wine (but not under Windows):

for %%i in () do echo "no"

Fix start of word position matching in findstr

Upstream merge request: https://gitlab.winehq.org/wine/wine/-/merge_requests/10294

Status: Merged upstream in commit dc2fa8cc, present in Wine 11.5 and newer

Add support for the \< (start of word position matching) pattern in findstr. Currently, only ^ (start of line) is implemented.

Fix GetModuleFileName string termination

Upstream merge request: https://gitlab.winehq.org/wine/wine/-/merge_requests/10291

Status: Merged upstream in commit 8060d2d9, present in Wine 11.7 and newer

After Windows XP the string termination behaviour of GetModuleFileName was changed to always terminate the path returned, even if the buffer is insufficient to contain the null terminator. This patch addresses that change in behaviour to ensure strings are always null terminated, even if the buffer is too small.