On Wed Feb 5 19:47:08 2025 +0000, Rémi Bernon wrote:
The owner tid is passed to the kernel when the kernel sync object is created, but it is only created once when `get_inproc_sync` is first called, and then stored in `mutex->inproc_sync` and returned in every future `get_inproc_sync` call. OTOH, I see that `mutex->owner` is changed dynamically in `do_grab` and `do_release`, when mutex is first acquired, or last released, and it doesn't seem right to create the kernel sync object only once with whatever random owner is set at that moment? I would expect, if owner can change, that some mechanism would change or recreate the kernel sync with a different owner?
When ntsync is used, no waits go to server_select [except a handful of cherry-picked internal waits that go through server_wait_for_object()]. Hence the state of the mutex object in the server [as opposed to the kernel] is never changed after creation.
Rather, the internal state of the kernel object is mutable, and when NtReleaseMutant() is called that does NTSYNC_IOC_MUTEX_UNLOCK on the underlying ntsync object which changes its state instead. Similarly for waits.
Same for events and semaphores. Other objects (timers, processes, etc.) still change state like normal, and the server alters their state using ioctls when anything happens that would change the object's signaled state.