This introduces a faster implementation of signal and wait operations on NT
events, semaphores, and mutexes, which improves performance to native levels for
a wide variety of games and other applications.
The goal here is similar to the long-standing out-of-tree "esync" and "fsync"
patch sets, but without the flaws that make those patch sets not upstreamable.
The Linux "ntsync" driver is not currently released. It has been accepted into
the trunk Linux tree for 6.14, so barring any extraordinary circumstances, the
API is frozen and it will be released in its current form in about 2 months.
Since it has passed all relevant reviewers on the kernel side, and the API is
all but released, it seems there is no reason any more not to submit the Wine
side to match.
Some important notes:
* This patch set does *not* include any way to disable ntsync support, since
that kind of configuration often seems to be dispreferred where not necessary.
In essence, ntsync should just work everywhere.
Probably the easiest way to effectively disable ntsync, for the purposes of
testing, is to chmod the /dev/ntsync device to prevent its being opened.
Regardless, a Wine switch to disable ntsync can be added simply enough. Note
that it should probably not take the form of a registry key, however, since it
needs to be easily accessible from the server itself.
* It is, generally speaking, not possible for only some objects, or some
processes, to have backing ntsync objects, while others use the old server
path. The esync/fsync patch sets explicitly protected against this by making
sure every process had a consistent view of whether esync was enabled. This is
not provided here, since no switch is provided to toggle ntsync, and it should
not be possible to get into such an inconsistent state without gross
misconfiguration.
* Similarly, no diagnostic messages are provided to note that ntsync is in use,
or not in use. These messages are part of esync/fsync, as well as part of
ntsync "testing" trees unofficially distributed. However, if ntsync is working
correctly, no message should be necessary.
The basic structure is:
* Each type of server object which can be waited on by the client (including
events, semaphores, mutexes, but also other types such as processes, files)
must store an "inproc_sync" object.
This "inproc_sync" object is a full server object (note that this differs from
esync/fsync). A vector and server request is introduced to retrieve an NT
handle to this object from an arbitrary NT handle.
Since the actual ntsync objects are simply distinct file descriptions, we then
call get_handle_fd from the client to retrieve an fd to the object, and then
perform ioctls on it.
* Objects signaled by the server (processes, files, etc) perform ntsync ioctls
on that object. The backing object in all such cases is simply an event.
* Signal and wait operations on the client side attempt to defer to an
"inproc_*" function, falling back to the server implementation if it returns
STATUS_NOT_IMPLEMENTED. This mirrors how in-process synchronization objects
(critical sections, SRW locks, etc) used to be implemented—attempting to use
an architecture-specific "fast_*" function and falling back if it returned
STATUS_NOT_IMPLEMENTED.
* The inproc_sync handles, once retrieved, are cached per-process. This caching
takes a similar form to the fd cache. It does not reuse the same
infrastructure, however.
The primary reason for this is that the fd cache is designed to fit within a
64-bit value and uses 64-bit atomic operations to ensure consistency. However,
we need to store more than 64 bits of information. [We also need to modify
them after caching, in order to correctly implement handle closing—see below.]
The secondary reason is that retrieving the ntsync fd from the inproc_sync
handle itself uses the fd cache.
* In order to keep the Linux driver simple, it does not implement access flags
(EVENT_MODIFY_STATE etc.) Instead, the flags are cached locally and validated
there. This too mirrors the fd cache. Note that this means that a malicious
process can now modify objects it should not be able modify—which is less true
than it is with wineserver—but this is no different from the way other objects
(notably fds) are handled, and would require manual syscalls.
* In order to achieve correct behaviour related to closing objects while they
are used, this patch set essentially relies on refcounting. This is broadly
true of the server as well, but because we need to avoid server calls when
performing object operations, significantly more care must be taken.
In particular, because waits need to be interruptable by signals and then be
restarted, we need the backing ntsync object to remain valid until all users
are done with it. On a process level, this is achieved by letting multiple
processes own handles to the underlying inproc_sync server object.
On a thread level, multiple simultaneous calls need to refcount the process's
local handle. This refcount is stored in the sync object cache. When it
reaches zero, the cache is cleared.
Punting this behaviour to the Linux driver would have introduced a great deal
more complexity, which is best kept in userspace and out of the kernel.
* The cache is, as such, treated as a cache. The penultimate commit, which
introduces client support but does not yet cache the objects, effectively
illustrates this by never actually caching anything, and retrieving a new NT
handle and fd every time.
* Certain waits, on internal handles (such as async, startup_info, completion),
are delegated to the server even when ntsync is used. Those server objects do
not create an underlying ntsync object.
--
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/7226
This MR enforces alignment of TLS slots as described in PE file.
I'm not 100% happy with the deallocation scheme, as it could be slow.
If someone has a better idea, be welcome!
Didn't open the option to introduce helpers in heap.c (but maybe that's the way to go).
--
v2: ntdll: Enforce the alignment of TLS directory entries.
kernel32/tests: Add a test about TLS slot alignment.
https://gitlab.winehq.org/wine/wine/-/merge_requests/7251
On Tue Feb 4 18:49:40 2025 +0000, eric pouech wrote:
> something is not correct. you should get something like:
> ```
> Test output:
> cmd.exe:batch start programs/cmd/tests/batch.c
> 0208:err:start:parse_command_line Unknown option 'L"/foobar"'
> 02a0:err:start:parse_command_line Unknown option 'L"/foobar"'
> batch.c:454: running TEST_BUILTINS.BAT test...
> batch.c:348: Test marked todo: unexpected char 0x39 position 11 in line
> 22 (got 'ERRORLEVEL 9009', wanted 'ERRORLEVEL 3')
> batch.c:348: Test marked todo: unexpected char 0x53 position 0 in line
> 61 (got 'SUCCESS 1', wanted 'FAILURE 1')
> batch.c:348: Test marked todo: unexpected char 0x30 position 8 in line
> 64 (got 'SUCCESS 0', wanted 'SUCCESS 666')
> batch.c:348: Test marked todo: unexpected char 0x46 position 0 in line
> 69 (got 'FAILURE 1', wanted 'a@space@')
> batch.c:348: Test marked todo: unexpected char 0x2d position 0 in line
> 70 (got '---', wanted 'b@space@')
> batch.c:348: Test marked todo: unexpected char 0x2d position 0 in line
> 71 (got '---', wanted 'FAILURE 1')
> batch.c:340: Test marked todo: excess characters on line 152 (got
> 'SUCCESS 0', wanted 'SUCCESS@space@')
> batch.c:348: Test marked todo: unexpected char 0x46 position 0 in line
> 161 (got 'FAILURE 1', wanted 'SUCCESS 666')
> batch.c:348: Test marked todo: unexpected char 0x46 position 0 in line
> 162 (got 'FAILURE 1', wanted 'SUCCESS 666')
> batch.c:337: Test marked todo: unexpected end of line 212 (got 'SUCCESS
> 666', wanted '@formfeed@SUCCESS 666')
> batch.c:337: Test marked todo: unexpected end of line 213 (got 'SUCCESS
> 666', wanted '@formfeed@SUCCESS 666')
> batch.c:454: running TEST_BUILTINS.CMD test...
> batch.c:348: Test marked todo: unexpected char 0x26 position 71 in line
> 93 (got 'C:\users\eric\AppData\Local\Temp\wct>(echo the @ character
> chains until&&@echo we leave the current depth||( ', wanted '@pwd@>(echo
> the @ character chains until && ) && echo and can hide brackets || () ||@space@')
> batch.c:348: Test marked todo: unexpected char 0x65 position 0 in line
> 94 (got 'echo hidden', wanted 'the @ character chains until')
> batch.c:348: Test marked todo: unexpected char 0x29 position 0 in line
> 95 (got '))&&echo and can hide brackets||(@echo command hidden)||@(echo
> brackets hidden)', wanted 'we leave the current depth')
> batch.c:348: Test marked todo: unexpected char 0x74 position 0 in line
> 96 (got 'the @ character chains until', wanted 'and can hide brackets')
> batch.c:348: Test marked todo: unexpected char 0x77 position 0 in line
> 97 (got 'we leave the current depth', wanted '---')
> batch.c:348: Test marked todo: unexpected char 0x61 position 0 in line
> 97 (got 'and can hide brackets', wanted '---')
> batch.c:348: Test marked todo: unexpected char 0x3d position 41 in line
> 138 (got 'C:\users\eric\AppData\Local\Temp\wct>if 1==1 echo foo ',
> wanted '@pwd@>if 1 == 1 echo foo@space@')
> batch.c:348: Test marked todo: unexpected char 0x3d position 41 in line
> 141 (got 'C:\users\eric\AppData\Local\Temp\wct>if 1==1 @echo bar ',
> wanted '@pwd@>if 1 == 1@space@')
> batch.c:337: Test marked todo: unexpected end of line 428 (got 'j2',
> wanted 'j2@space@')
> batch.c:348: Test marked todo: unexpected char 0x39 position 11 in line
> 473 (got 'ERRORLEVEL 9009', wanted 'ERRORLEVEL 3')
> batch.c:348: Test marked todo: unexpected char 0x53 position 0 in line
> 512 (got 'SUCCESS 1', wanted 'FAILURE 1')
> batch.c:348: Test marked todo: unexpected char 0x30 position 8 in line
> 515 (got 'SUCCESS 0', wanted 'SUCCESS 666')
> batch.c:348: Test marked todo: unexpected char 0x46 position 0 in line
> 520 (got 'FAILURE 1', wanted 'a@space@')
> batch.c:348: Test marked todo: unexpected char 0x2d position 0 in line
> 521 (got '---', wanted 'b@space@')
> batch.c:348: Test marked todo: unexpected char 0x2d position 0 in line
> 522 (got '---', wanted 'FAILURE 1')
> batch.c:340: Test marked todo: excess characters on line 603 (got
> 'SUCCESS 0', wanted 'SUCCESS@space@')
> batch.c:348: Test marked todo: unexpected char 0x46 position 0 in line
> 612 (got 'FAILURE 1', wanted 'SUCCESS 666')
> batch.c:348: Test marked todo: unexpected char 0x46 position 0 in line
> 613 (got 'FAILURE 1', wanted 'SUCCESS 666')
> batch.c:337: Test marked todo: unexpected end of line 663 (got 'SUCCESS
> 666', wanted '@formfeed@SUCCESS 666')
> batch.c:337: Test marked todo: unexpected end of line 664 (got 'SUCCESS
> 666', wanted '@formfeed@SUCCESS 666')
> batch.c:348: Test marked todo: unexpected char 0x5e position 5 in line
> 849 (got 'after^', wanted 'after!')
> batch.c:348: Test marked todo: unexpected char 0x20 position 5 in line
> 1773 (got '
> C:\users\eric\AppData\Local\Temp\wct\foobar\baz', wanted '
>
>
>
>
> R@spaces@@drive@@path@foobar\baz@or_broken@@spaces@@drive@@path@foobar\baz@or_broken@
> R I@spaces@@drive@@path@foobar\baz')
> batch.c:348: Test marked todo: unexpected char 0x6f position 1 in line
> 1801 (got ''one two three'', wanted '' one two three'@or_broken@Skipped
> as not enough permissions')
> batch.c:348: Test marked todo: unexpected char 0x30 position 0 in line
> 1830 (got '0', wanted '1')
> batch.c:340: Test marked todo: excess characters on line 1853 (got 'cp3
> ', wanted 'cp3')
> batch.c:340: Test marked todo: excess characters on line 1942 (got
> 'ErrLev: 0', wanted 'ErrLev:@space@')
> batch.c:348: Test marked todo: unexpected char 0x30 position 8 in line
> 1945 (got 'ErrLev: 0', wanted 'ErrLev:@space@@or_broken@ErrLev: 0')
> batch.c:348: Test marked todo: unexpected char 0x35 position 1 in line
> 2062 (got '25', wanted '21')
> batch.c:348: Test marked todo: unexpected char 0x46 position 0 in line
> 2064 (got 'Failure', wanted 'Success')
> batch.c:454: running TEST_CMDLINE.CMD test...
> 01bc:batch: 2490 tests executed (40 marked as todo, 0 as flaky, 0
> failures), 0 skipped.
> cmd.exe:batch:01bc done (0) in 37s 5389B
> cmd.exe:directory start programs/cmd/tests/directory.c
> 0754:directory: 24 tests executed (0 marked as todo, 0 as flaky, 0
> failures), 0 skipped.
> cmd.exe:directory:0754 done (0) in 0s 90B
> ```
I see; I need to remove the @todo_wine@ from the passing tests.
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/7131#note_93605