This comes from behavioral study of Windows, which doesn't seem to check if the
lock is actually exclusively held, and just simply decrement the value stored
in the lock.
This fixes a dead lock which prevents WeCom from starting up.
--
v25: ntdll: wake up SRWLOCK waiters by thread id
ntdll: allow SRWLOCKs to be quickly re-acquired
ntdll: An implementation of SRWLOCK that closer matches Windows'.
include: add atomic read/write of pointers
https://gitlab.winehq.org/wine/wine/-/merge_requests/3504
On Fri Sep 22 16:09:26 2023 +0000, eric pouech wrote:
> it has an exception handler around it, so
> * either the field is not on a readable page and the exception will be
> fired, and you'll get a NULL pointer (SAFE)
> * or the field is on a readable page but with a wrong magic value, and
> you'll get a NULL pointer (SAFE)
> * or the field is on a readable page, with the expected magic value, and
> you'll a non NULL pointer, that you can check if it fits or not in
> mapped view before reading into it (SAFE)
Oh! Okay, I will use `RtlImageNtHeader` and then do the bounds checks afterwards :)
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/3870#note_46369
On Fri Sep 22 15:55:16 2023 +0000, Aidan Khoury wrote:
> You're right, I checked again and this exception is captured and
> gracefully fails with the last error code set to 0xE0000001. So, I will
> remove this and just set the last error 0xE0000001 with a failing return
> value. I'll add some tests for this case.
this can also be done by setting an exception handler inside some functions
(in badly written pseudo code):
```
try {
// do the expected stuff
// setting ret & last error in case of error
} catch (exception e) {
throw exception(0xE0000001);
ret = FALSE;
SetLastError(0xE0000001);
}
return ret;
```
but that doesn't prevent from releasing the resources between the throw and this handler (we're not using RAEII and the current exception handling even for C code requires compiler support that we don't have)
so perhaps the safest solution is to return error codes internally (no exception) and throw the exception on top level functions
that's not nice for sure, but I fear we don't have many other options
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/3870#note_46367
On Thu Sep 21 22:33:18 2023 +0000, Aidan Khoury wrote:
> This `rebase_image` implementation could still be adapted as an imghelp
> internal function, could it not? Though that would be better to be done
> as a separate MR, I think.
I gave ReBaseImage a quick look at how it behaves in windows and it has some likely unwanted behavior (like hard to really force a new rebase address), so it's fine to leave it aside for now
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/3870#note_46359
On Fri Sep 22 15:46:59 2023 +0000, Aidan Khoury wrote:
> The native RtlImageHeader does not have boundary checks. I cannot do
> this check on RtlImageHeader's return value safely since that would be
> after RtlImageHeader has already potentially accessed an invalid address.
it has an exception handler around it, so
* either the field is not on a readable page and the exception will be fired, and you'll get a NULL pointer (SAFE)
* or the field is on a readable page but with a wrong magic value, and you'll get a NULL pointer (SAFE)
* or the field is on a readable page, with the expected magic value, and you'll a non NULL pointer, that you can check if it fits or not in mapped view before reading into it (SAFE)
--
https://gitlab.winehq.org/wine/wine/-/merge_requests/3870#note_46358