I have a .Net application that during handling of WM_NCPAINT for one of its windows
genarates exception "Arithmetic operation resulted in an overflow.". This happens
only in a 64-bit prefix and only for WPARAM that contains an HRGN handle with value
over than 0x7fffffff.
The application does the following:
public static IntPtr GetNativeDC(Message m, IntPtr handle)
{
if (m.Msg != 0x85) // WM_NCPAINT
{
return NUser32.GetWindowDC(handle);
}
int num = 0x200013; // DCX_VALIDATE | DCX_CLIPSIBLINGS | DCX_CACHE | DCX_WINDOW
IntPtr intPtr = IntPtr.Zero;
IntPtr wParam = m.WParam;
if (wParam.ToInt32() != 1)
{
num |= 0x80; // DCX_INTERSECTRGN
intPtr = CreateRectRgn(0, 0, 1, 1);
CombineRgn(intPtr, wParam, IntPtr.Zero, 5); // RGN_COPY
}
return NUser32.GetDCEx(handle, intPtr, num);
}
The exception is generated by wParam.ToInt32(). MSDN description for ToInt32()
https://learn.microsoft.com/en-us/dotnet/api/system.intptr.toint32?view=net…
states
Exceptions
OverflowException
In a 64-bit process, the value of this instance is too large or too small
to represent as a 32-bit signed integer.
MSDN also has a reference to ToInt32() source:
https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5…
public int ToInt32()
{
#if TARGET_64BIT
return checked((int)_value);
#else
return (int)_value;
#endif
}
It's not clear why a sign extension may lead to an overflow exception.
This patch fixes the problem, and provides a test case that confirms that
entry.Generation field of a GDI32 object is limited by 127 on a 64-bit
platform, while 32-bit Windows doesn't have such a limitation.
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/5777
Previously, PSDRV_ResetDC() only updated the devmode contained in the
print context, which could cause the devmode in the unix interface to be
inconsistent with the print context's devmode. This can cause problems
later when PostScript is being outputted, as get_device_caps() in the
unix interface would reference this inconsistent devmode. By calling
ResetDCW() in PSDRV_ResetDC(), these two devmodes remain in-sync.
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/5778
On Mon Jun 3 16:19:12 2024 +0000, Vibhav Pant wrote:
> I'm sorry, what are the "earlier patches" in this context? Also, I was
> not entirely sure what the component modified would be, as both
> NtCreationSection and CreateFileMapping would be affected by the patch,
> which are in different components. Would wineserver be appropriate?
Your MR at each moment should be the set of finalized patches. If you are changing something in existing patches you update / replace those without adding new patches. You set the component which your patch is directly modifying. If there is more than one (rare occasion which often means you need to split your patches) you specify higher level component. I'd really suggest to view some commit history for the related components for examples.
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/5769#note_72236
On Mon Jun 3 16:19:12 2024 +0000, Paul Gofman wrote:
> As a general note, please don't put the changes to earlier patches on
> top, just modify the patches. We also start the patch names from the
> name of the component the patch is modifying, like: "ntdll: Support xxx
> in NtYYY()." It would probably help to look at some merged MRs and
> commit history for examples.
I'm sorry, what are the "earlier patches" in this context? Also, I was not entirely sure what the component modified would be, as both NtCreationSection and CreateFileMapping would be affected by the patch, which are in different components. Would wineserver be appropriate?
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/5769#note_72234
This should help unifying the interface and get rid of the get_info callback.
Later, I think we could create bitmaps over sections shared with some DWM process and/or host compositor.
--
v3: win32u: Create a HBITMAP backing the window surface pixels.
winex11: Create a HBITMAP for the allocated surface pixels.
winex11: Create XImage before initializing the window surface.
winex11: Simplify the XSHM extension function calls.
win32u: Pass BITMAPINFO and a HBITMAP to window_surface_init.
win32u: Move the window surface color bits to the common struct.
https://gitlab.winehq.org/wine/wine/-/merge_requests/5764
As a general note, please don't put the changes to earlier patches on top, just modify the patches. We also start the patch names from the name of the component the patch is modifying, like: "ntdll: Support xxx in NtYYY()." It would probably help to look at some merged MRs and commit history for examples.
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/5769#note_72228
On Sun Jun 2 15:41:59 2024 +0000, Vibhav Pant wrote:
> From what I understand, THP support is ultimately immaterial here, as
> we're **requiring** a huge page allocation, rather than depending on
> `khugepaged`to compact `madvise`-ed ranges.
Still, are the large page sizes on Windows match those on Linux? I think in Wine we have to support what Windows supports and report the same minimum page size that Windows reports. If that can be backed by actual huge pages then great but I am not sure if we can sacrifice compatibility here. Depends on usage pattern probably but I wouldn't expect the actually backing the range with huge pages to have all that great performance impact.
Also, just as a note, mind that those huge pages allocation on Windows have other specifics, like IIRC they are always locked in memory. That potentially can have more impact than actual backing pages layout. I am wondering what does the app which uses it actually does with this mapping?
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/5769#note_72227
On Mon Jun 3 12:33:42 2024 +0000, Vibhav Pant wrote:
> changed this line in [version 7 of the diff](/wine/wine/-/merge_requests/5769/diffs?diff_id=116330&start_sha=d9cab6b6298f63cccffebb8a71e6ca56d4a3f871#2b37d5dc1c3bb6a637f043480c038caea64531bb_342_342)
While of course memfd can be accessed quicker than disk storage that doesn't justify backing all the anonymous mappings with memfd. Even for executable images only it may be very lot.
In the other thread you are mentioning Proton patch doing something similar. I think that was motivated as a workaround for a specific problems with specific types of mappings and probably would be better to be changed.
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/5769#note_72226
This MR adds support for creating file mapping objects backed by large pages on Linux, by making the following changes:
## wineserver
* On Linux, `create_temp_file` will first attempt to use memfds as the backing fd. If it fails, it'll return to the current codepath, creating a temporary file in either the server or config directory.
* The created memfd will be sealed against writes, if the caller requesting the appropriate page protection flags.
* This removes the requirement that FDs be only created on filesystems/directories that aren't `noexec`.
* In the server method `create_mapping` , if large pages have been requested by the caller, hold that the calling thread's token holds `SeLockMemoryPrivilege` .
* Additionally, add `SeLockMemoryPrivilege` to the list of privileges enabled for the Administrator.
## `ntdll`
* Add `virtual_get_min_large_page_size` and its exported wrapper `wine_unix_get_min_large_page_size`.
* On Linux, the minimum page size is determined by going through `/sys/kernel/mm/hugepages`. If hugepage support was not detected, `STATUS_NOT_SUPPORTED` is returned instead. On other platforms, the older hard-coded value of 2\*1024\*1024 is returned instead.
* `NtCreateSection` will validate certain parameters if large pages are requested. Specifically, it will return STATUS_INVALID_PARAMETER if the requested mapping is not anonymous/unnamed, or the size is not a multiple of the minimum supported page size.
## `kernelbase`
* `GetLargePageMinimum` will use `wine_unix_get_min_large_page_size`.
## `kernel32/tests`
* Add new test test_large_page_file_mapping, which validates privilege enforcements and parameter validation while creating large pages backed file mapping obejcts. The tests are skipped if `GetLargePageMinimum` returns 0.
--
v10: make_memfd_name: Fix format specifiers.
This merge request has too many patches to be relayed via email.
Please visit the URL below to see the contents of the merge request.
https://gitlab.winehq.org/wine/wine/-/merge_requests/5769
This should help unifying the interface and get rid of the get_info callback.
Later, I think we could create bitmaps over sections shared with some DWM process and/or host compositor.
--
v2: win32u: Create a HBITMAP backing the window surface pixels.
winex11: Create a HBITMAP for the allocated surface pixels.
winex11: Create XImage before initializing the window surface.
win32u: Pass BITMAPINFO and a HBITMAP to window_surface_init.
win32u: Move the window surface color bits to the common struct.
https://gitlab.winehq.org/wine/wine/-/merge_requests/5764
This MR adds support for creating file mapping objects backed by large pages on Linux, by making the following changes:
## wineserver
* On Linux, `create_temp_file` will first attempt to use memfds as the backing fd. If it fails, it'll return to the current codepath, creating a temporary file in either the server or config directory.
* The created memfd will be sealed against writes, if the caller requesting the appropriate page protection flags.
* This removes the requirement that FDs be only created on filesystems/directories that aren't `noexec`.
* In the server method `create_mapping` , if large pages have been requested by the caller, hold that the calling thread's token holds `SeLockMemoryPrivilege` .
* Additionally, add `SeLockMemoryPrivilege` to the list of privileges enabled for the Administrator.
## `ntdll`
* Add `virtual_get_min_large_page_size` and its exported wrapper `wine_unix_get_min_large_page_size`.
* On Linux, the minimum page size is determined by going through `/sys/kernel/mm/hugepages`. If hugepage support was not detected, `STATUS_NOT_SUPPORTED` is returned instead. On other platforms, the older hard-coded value of 2\*1024\*1024 is returned instead.
* `NtCreateSection` will validate certain parameters if large pages are requested. Specifically, it will return STATUS_INVALID_PARAMETER if the requested mapping is not anonymous/unnamed, or the size is not a multiple of the minimum supported page size.
## `kernelbase`
* `GetLargePageMinimum` will use `wine_unix_get_min_large_page_size`.
## `kernel32/tests`
* Add new test test_large_page_file_mapping, which validates privilege enforcements and parameter validation while creating large pages backed file mapping obejcts. The tests are skipped if `GetLargePageMinimum` returns 0.
--
v9: create_memfd: Use ftruncate to set memfd size.
create_mapping: Fix argument order to create_temp_file.
This merge request has too many patches to be relayed via email.
Please visit the URL below to see the contents of the merge request.
https://gitlab.winehq.org/wine/wine/-/merge_requests/5769
This MR adds support for creating file mapping objects backed by large pages on Linux, by making the following changes:
## wineserver
* On Linux, `create_temp_file` will first attempt to use memfds as the backing fd. If it fails, it'll return to the current codepath, creating a temporary file in either the server or config directory.
* The created memfd will be sealed against writes, if the caller requesting the appropriate page protection flags.
* This removes the requirement that FDs be only created on filesystems/directories that aren't `noexec`.
* In the server method `create_mapping` , if large pages have been requested by the caller, hold that the calling thread's token holds `SeLockMemoryPrivilege` .
* Additionally, add `SeLockMemoryPrivilege` to the list of privileges enabled for the Administrator.
## `ntdll`
* Add `virtual_get_min_large_page_size` and its exported wrapper `wine_unix_get_min_large_page_size`.
* On Linux, the minimum page size is determined by going through `/sys/kernel/mm/hugepages`. If hugepage support was not detected, `STATUS_NOT_SUPPORTED` is returned instead. On other platforms, the older hard-coded value of 2\*1024\*1024 is returned instead.
* `NtCreateSection` will validate certain parameters if large pages are requested. Specifically, it will return STATUS_INVALID_PARAMETER if the requested mapping is not anonymous/unnamed, or the size is not a multiple of the minimum supported page size.
## `kernelbase`
* `GetLargePageMinimum` will use `wine_unix_get_min_large_page_size`.
## `kernel32/tests`
* Add new test test_large_page_file_mapping, which validates privilege enforcements and parameter validation while creating large pages backed file mapping obejcts. The tests are skipped if `GetLargePageMinimum` returns 0.
--
v8: create_temp_file: Return fd when create_memfd was successful.
This merge request has too many patches to be relayed via email.
Please visit the URL below to see the contents of the merge request.
https://gitlab.winehq.org/wine/wine/-/merge_requests/5769
This table doesn't really grow when the total number of handles
exceeds the initial size. It will instead try to wrap and lead to
an access violation.
Signed-off-by: David Kahurani <k.kahurani(a)gmail.com>
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/5353
Project Kunai associates cloud account with a mix of various items,
including board serial number, resulting in several machines being
bound to the same cloud account because the momo serial number is
always empty.
Note: this patch doesn't follow the systemd guidelines of not
exposing directly /etc/machine-id content (but Wine already
exposes /etc/machine-id as Windows machine GUID).
Signed-off-by: Eric Pouech <epouech(a)codeweavers.com>
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/4773
This MR adds support for creating file mapping objects backed by large pages on Linux, by making the following changes:
## wineserver
* On Linux, `create_temp_file` will first attempt to use memfds as the backing fd. If it fails, it'll return to the current codepath, creating a temporary file in either the server or config directory.
* The created memfd will be sealed against writes, if the caller requesting the appropriate page protection flags.
* This removes the requirement that FDs be only created on filesystems/directories that aren't `noexec`.
* In the server method `create_mapping` , if large pages have been requested by the caller, hold that the calling thread's token holds `SeLockMemoryPrivilege` .
* Additionally, add `SeLockMemoryPrivilege` to the list of privileges enabled for the Administrator.
## `ntdll`
* Add `virtual_get_min_large_page_size` and its exported wrapper `wine_unix_get_min_large_page_size`.
* On Linux, the minimum page size is determined by going through `/sys/kernel/mm/hugepages`. If hugepage support was not detected, `STATUS_NOT_SUPPORTED` is returned instead. On other platforms, the older hard-coded value of 2\*1024\*1024 is returned instead.
* `NtCreateSection` will validate certain parameters if large pages are requested. Specifically, it will return STATUS_INVALID_PARAMETER if the requested mapping is not anonymous/unnamed, or the size is not a multiple of the minimum supported page size.
## `kernelbase`
* `GetLargePageMinimum` will use `wine_unix_get_min_large_page_size`.
## `kernel32/tests`
* Add new test test_large_page_file_mapping, which validates privilege enforcements and parameter validation while creating large pages backed file mapping obejcts. The tests are skipped if `GetLargePageMinimum` returns 0.
--
v6: make_memfd_name: fix format specifiers.
https://gitlab.winehq.org/wine/wine/-/merge_requests/5769
Adds the registry key
`HKEY_CURRENT_USER\\Software\\Wine\\Wayland Driver\\unaccelerated_pointer`
witch allows raw input. This makes it easier
to calculate the same sensitivity in different games,
use sensitivity calculators, and easily change values
when changing DPI and do not depend on the compositor or OS.
For example, you want to set the sensitivity to half as much,
and sensitivity curves in libinput are more difficult
to calculate than in the games themselves.
--
v7: winewayland.drv: Add unaccelerated pointer support
https://gitlab.winehq.org/wine/wine/-/merge_requests/4698
--
v3: widl: Do not write type definitions for types defined in an imported header.
widl: Update the type location in define_type().
widl: Factor out a define_type() helper.
widl: Invert "declonly".
widl: Allow using UDTs with the keyword even when the identifier is also a typedef.
https://gitlab.winehq.org/wine/wine/-/merge_requests/5724
This MR adds support for creating file mapping objects backed by large pages on Linux, by making the following changes:
## wineserver
* On Linux, `create_temp_file` will first attempt to use memfds as the backing fd. If it fails, it'll return to the current codepath, creating a temporary file in either the server or config directory.
* The created memfd will be sealed against writes, if the caller requesting the appropriate page protection flags.
* This removes the requirement that FDs be only created on filesystems/directories that aren't `noexec`.
* In the server method `create_mapping` , if large pages have been requested by the caller, hold that the calling thread's token holds `SeLockMemoryPrivilege` .
* Additionally, add `SeLockMemoryPrivilege` to the list of privileges enabled for the Administrator.
## `ntdll`
* Add `virtual_get_min_large_page_size` and its exported wrapper `wine_unix_get_min_large_page_size`.
* On Linux, the minimum page size is determined by going through `/sys/kernel/mm/hugepages`. If hugepage support was not detected, `STATUS_NOT_SUPPORTED` is returned instead. On other platforms, the older hard-coded value of 2\*1024\*1024 is returned instead.
* `NtCreateSection` will validate certain parameters if large pages are requested. Specifically, it will return STATUS_INVALID_PARAMETER if the requested mapping is not anonymous/unnamed, or the size is not a multiple of the minimum supported page size.
## `kernelbase`
* `GetLargePageMinimum` will use `wine_unix_get_min_large_page_size`.
## `kernel32/tests`
* Add new test test_large_page_file_mapping, which validates privilege enforcements and parameter validation while creating large pages backed file mapping obejcts. The tests are skipped if `GetLargePageMinimum` returns 0.
--
v5: create_user_data_mapping: Set the LargePageMinimum field.
Remove declaration for wine_unix_get_min_large_page_size.
Add checks for linux/memfd.h and memfd_create on Linux.
:NtCreateSection: remove trailing whitespace.
Remove virtual_get_large_page_min_size and its exported wine syscall
https://gitlab.winehq.org/wine/wine/-/merge_requests/5769