diff mbox series

crashes with win2008 host

Message ID 5aae1837-f6b9-a48b-7401-3aa623a084b2@adacore.com (mailing list archive)
State New, archived
Headers show
Series crashes with win2008 host | expand

Commit Message

KONRAD Frederic Sept. 13, 2018, 5:02 p.m. UTC
Hi Andrey,

I've strange crashes since this commit: (yes its old)

commit 12f8def0e02232d7c6416ad9b66640f973c531d1
Author: Andrey Shedel <ashedel@microsoft.com>
Date:   Fri Mar 24 15:01:41 2017 -0700

     win32: replace custom mutex and condition variable with
            native primitives

Basically it just crashes.. (exception 0xc0000135) like this:

(gdb) run
Starting program: C:\home\konrad\temp\qemu-system-sparc --version
[New Thread 5324.0xdf8]
gdb: unknown target exception 0xc0000135 at 0x77636698
gdb: unknown target exception 0xc0000135 at 0x77636698

Program received signal ?, Unknown signal.
0x0000000077636698 in ntdll!RtlRaiseStatus ()
    from C:\Windows\system32\ntdll.dll
(gdb) bt
#0  0x0000000077636698 in ntdll!RtlRaiseStatus ()
    from C:\Windows\system32\ntdll.dll
#1  0x00000000775dcbf7 in ntdll!LdrGetProcedureAddress ()
    from C:\Windows\system32\ntdll.dll
#2  0x00000000775a536e in ntdll!LdrInitializeThunk ()
    from C:\Windows\system32\ntdll.dll
#3  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt 
stack?)
(gdb)

Sorry the backtrace is not really helpful..

I can reproduce the same behavior with v3.0.0.. and only with
the Windows 2008 server host..

If I partially revert the patch, eg: using CriticalSection
instead of SRWL it seems to work.. But I don't understand why
because SRWL should be supported on 2008 Server..

Here is the change I did (which is wrongly making qemu_mutex
recursive for now):


@@ -69,7 +69,7 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex, 
const char *file, const int line)
      int owned;

      assert(mutex->initialized);
-    owned = TryAcquireSRWLockExclusive(&mutex->lock);
+    owned = TryEnterCriticalSection(&mutex->lock);there
      if (owned) {
          qemu_mutex_post_lock(mutex, file, line);
          return 0;
@@ -81,7 +81,7 @@ void qemu_mutex_unlock_impl(QemuMutex *mutex, 
const char *file, const int line)
  {
      assert(mutex->initialized);
      qemu_mutex_pre_unlock(mutex, file, line);
-    ReleaseSRWLockExclusive(&mutex->lock);
+    LeaveCriticalSection(&mutex->lock);
  }

  void qemu_rec_mutex_init(QemuRecMutex *mutex)
@@ -141,11 +141,12 @@ void qemu_cond_broadcast(QemuCond *cond)
      WakeAllConditionVariable(&cond->var);
  }

-void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const 
char *file, const int line)
+void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const 
char *file,
+                         const int line)
  {
      assert(cond->initialized);
      qemu_mutex_pre_unlock(mutex, file, line);
-    SleepConditionVariableSRW(&cond->var, &mutex->lock, 
INFINITE, 0);
+    SleepConditionVariableCS(&cond->var, &mutex->lock, INFINITE);
      qemu_mutex_post_lock(mutex, file, line);
  }

Comments

Zhijian Li (Fujitsu)" via Sept. 13, 2018, 5:29 p.m. UTC | #1
Does this crash always happen at startup? Is it deterministic?



c0000135 is STATUS_DLL_NOT_FOUND. I suspect ntdll is trying to demand-load another DLL to provide that API, and it is missing or corrupt on your Windows installation.



BTW, you’ll probably get a better stack trace from a native debugger (windbg, etc.) in this scenario.



Cheers,

Andrew
KONRAD Frederic Sept. 14, 2018, 8:29 a.m. UTC | #2
Le 09/13/2018 à 07:29 PM, Andrew Baumann a écrit :
> Does this crash always happen at startup? Is it deterministic?
>

Hi Andrew,

Thanks for your reactivity! Yes it crashes all the time..

> 
> 
> c0000135 is STATUS_DLL_NOT_FOUND. I suspect ntdll is trying to demand-load another DLL to provide that API, and it is missing or corrupt on your Windows installation

Actually that helps! Compiling in debug mode gave me this
errors.. But it wasn't the error I was chasing..

The initial error I was chasing is the following:
   gdb: unknown target exception 0xc0000139 at 0x77636698

When I execute it in graphic mode I get the following issue:

   The procedure entry point TryAcquireSRWLockExclusive could not
   be located in the dynamic link library KERNEL32.dll.

It seems that there was the same issue raised with MySQL on
Windows server 2008:
   https://forums.mysql.com/read.php?11,642417,642417

Is there anything I can do appart swaping back locally to the CS?

Thanks,
Fred

> 
> 
> 
> BTW, you’ll probably get a better stack trace from a native debugger (windbg, etc.) in this scenario.
> 
> 
> 
> Cheers,
> 
> Andrew
> 
> 
> 
> 
> 
> ________________________________
> From: KONRAD Frederic <frederic.konrad@adacore.com>
> Sent: Thursday, September 13, 2018 10:02:56 AM
> To: Andrey Shedel
> Cc: Andrew Baumann; Paolo Bonzini; QEMU Developers
> Subject: crashes with win2008 host
> 
> Hi Andrey,
> 
> I've strange crashes since this commit: (yes its old)
> 
> commit 12f8def0e02232d7c6416ad9b66640f973c531d1
> Author: Andrey Shedel <ashedel@microsoft.com>
> Date:   Fri Mar 24 15:01:41 2017 -0700
> 
>       win32: replace custom mutex and condition variable with
>              native primitives
> 
> Basically it just crashes.. (exception 0xc0000135) like this:
> 
> (gdb) run
> Starting program: C:\home\konrad\temp\qemu-system-sparc --version
> [New Thread 5324.0xdf8]
> gdb: unknown target exception 0xc0000135 at 0x77636698
> gdb: unknown target exception 0xc0000135 at 0x77636698
> 
> Program received signal ?, Unknown signal.
> 0x0000000077636698 in ntdll!RtlRaiseStatus ()
>      from C:\Windows\system32\ntdll.dll
> (gdb) bt
> #0  0x0000000077636698 in ntdll!RtlRaiseStatus ()
>      from C:\Windows\system32\ntdll.dll
> #1  0x00000000775dcbf7 in ntdll!LdrGetProcedureAddress ()
>      from C:\Windows\system32\ntdll.dll
> #2  0x00000000775a536e in ntdll!LdrInitializeThunk ()
>      from C:\Windows\system32\ntdll.dll
> #3  0x0000000000000000 in ?? ()
> Backtrace stopped: previous frame inner to this frame (corrupt
> stack?)
> (gdb)
> 
> Sorry the backtrace is not really helpful..
> 
> I can reproduce the same behavior with v3.0.0.. and only with
> the Windows 2008 server host..
> 
> If I partially revert the patch, eg: using CriticalSection
> instead of SRWL it seems to work.. But I don't understand why
> because SRWL should be supported on 2008 Server..
> 
> Here is the change I did (which is wrongly making qemu_mutex
> recursive for now):
> 
> diff --git a/include/qemu/thread-win32.h
> b/include/qemu/thread-win32.h
> index d668d789b4..b335687604 100644
> --- a/include/qemu/thread-win32.h
> +++ b/include/qemu/thread-win32.h
> @@ -4,7 +4,8 @@
>    #include <windows.h>
> 
>    struct QemuMutex {
> -    SRWLOCK lock;
> +    CRITICAL_SECTION lock;
> +    LONG owner;
>    #ifdef CONFIG_DEBUG_MUTEX
>        const char *file;
>        int line;
> diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
> index b303188a36..09ce4fd957 100644
> --- a/util/qemu-thread-win32.c
> +++ b/util/qemu-thread-win32.c
> @@ -45,7 +45,7 @@ static void error_exit(int err, const char *msg)
> 
>    void qemu_mutex_init(QemuMutex *mutex)
>    {
> -    InitializeSRWLock(&mutex->lock);
> +    InitializeCriticalSection(&mutex->lock);
>        qemu_mutex_post_init(mutex);
>    }
> 
> @@ -53,14 +53,14 @@ void qemu_mutex_destroy(QemuMutex *mutex)
>    {
>        assert(mutex->initialized);
>        mutex->initialized = false;
> -    InitializeSRWLock(&mutex->lock);
> +    DeleteCriticalSection(&mutex->lock);
>    }
> 
>    void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file,
> const int line)
>    {
>        assert(mutex->initialized);
>        qemu_mutex_pre_lock(mutex, file, line);
> -    AcquireSRWLockExclusive(&mutex->lock);
> +    EnterCriticalSection(&mutex->lock);
>        qemu_mutex_post_lock(mutex, file, line);
>    }
> 
> @@ -69,7 +69,7 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex,
> const char *file, const int line)
>        int owned;
> 
>        assert(mutex->initialized);
> -    owned = TryAcquireSRWLockExclusive(&mutex->lock);
> +    owned = TryEnterCriticalSection(&mutex->lock);there
>        if (owned) {
>            qemu_mutex_post_lock(mutex, file, line);
>            return 0;
> @@ -81,7 +81,7 @@ void qemu_mutex_unlock_impl(QemuMutex *mutex,
> const char *file, const int line)
>    {
>        assert(mutex->initialized);
>        qemu_mutex_pre_unlock(mutex, file, line);
> -    ReleaseSRWLockExclusive(&mutex->lock);
> +    LeaveCriticalSection(&mutex->lock);
>    }
> 
>    void qemu_rec_mutex_init(QemuRecMutex *mutex)
> @@ -141,11 +141,12 @@ void qemu_cond_broadcast(QemuCond *cond)
>        WakeAllConditionVariable(&cond->var);
>    }
> 
> -void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const
> char *file, const int line)
> +void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const
> char *file,
> +                         const int line)
>    {
>        assert(cond->initialized);
>        qemu_mutex_pre_unlock(mutex, file, line);
> -    SleepConditionVariableSRW(&cond->var, &mutex->lock,
> INFINITE, 0);
> +    SleepConditionVariableCS(&cond->var, &mutex->lock, INFINITE);
>        qemu_mutex_post_lock(mutex, file, line);
>    }
> 
> --
> 2.16.2
> 
> Do you have any idea of what's happening?
> 
> Regards,
> Fred
>
KONRAD Frederic Sept. 14, 2018, 11:17 a.m. UTC | #3
Ok finally got it,

The SRWL API seems to be available since Vista and Server 2008
except the 'TryAcquireSRWLockExclusive' function which is
available starting Seven and Server 2008 *R2*. Hence the error
message.

So basically that means QEMU is not compatible with version older
than Seven or 2008 R2.

Cheers,
Fred

Le 09/14/2018 à 10:29 AM, KONRAD Frederic a écrit :
> 
> 
> Le 09/13/2018 à 07:29 PM, Andrew Baumann a écrit :
>> Does this crash always happen at startup? Is it deterministic?
>>
> 
> Hi Andrew,
> 
> Thanks for your reactivity! Yes it crashes all the time..
> 
>>
>>
>> c0000135 is STATUS_DLL_NOT_FOUND. I suspect ntdll is trying to 
>> demand-load another DLL to provide that API, and it is missing 
>> or corrupt on your Windows installation
> 
> Actually that helps! Compiling in debug mode gave me this
> errors.. But it wasn't the error I was chasing..
> 
> The initial error I was chasing is the following:
>    gdb: unknown target exception 0xc0000139 at 0x77636698
> 
> When I execute it in graphic mode I get the following issue:
> 
>    The procedure entry point TryAcquireSRWLockExclusive could not
>    be located in the dynamic link library KERNEL32.dll.
> 
> It seems that there was the same issue raised with MySQL on
> Windows server 2008:
>    https://forums.mysql.com/read.php?11,642417,642417
> 
> Is there anything I can do appart swaping back locally to the CS?
> 
> Thanks,
> Fred
> 
>>
>>
>>
>> BTW, you’ll probably get a better stack trace from a native 
>> debugger (windbg, etc.) in this scenario.
>>
>>
>>
>> Cheers,
>>
>> Andrew
>>
>>
>>
>>
>>
>> ________________________________
>> From: KONRAD Frederic <frederic.konrad@adacore.com>
>> Sent: Thursday, September 13, 2018 10:02:56 AM
>> To: Andrey Shedel
>> Cc: Andrew Baumann; Paolo Bonzini; QEMU Developers
>> Subject: crashes with win2008 host
>>
>> Hi Andrey,
>>
>> I've strange crashes since this commit: (yes its old)
>>
>> commit 12f8def0e02232d7c6416ad9b66640f973c531d1
>> Author: Andrey Shedel <ashedel@microsoft.com>
>> Date:   Fri Mar 24 15:01:41 2017 -0700
>>
>>       win32: replace custom mutex and condition variable with
>>              native primitives
>>
>> Basically it just crashes.. (exception 0xc0000135) like this:
>>
>> (gdb) run
>> Starting program: C:\home\konrad\temp\qemu-system-sparc --version
>> [New Thread 5324.0xdf8]
>> gdb: unknown target exception 0xc0000135 at 0x77636698
>> gdb: unknown target exception 0xc0000135 at 0x77636698
>>
>> Program received signal ?, Unknown signal.
>> 0x0000000077636698 in ntdll!RtlRaiseStatus ()
>>      from C:\Windows\system32\ntdll.dll
>> (gdb) bt
>> #0  0x0000000077636698 in ntdll!RtlRaiseStatus ()
>>      from C:\Windows\system32\ntdll.dll
>> #1  0x00000000775dcbf7 in ntdll!LdrGetProcedureAddress ()
>>      from C:\Windows\system32\ntdll.dll
>> #2  0x00000000775a536e in ntdll!LdrInitializeThunk ()
>>      from C:\Windows\system32\ntdll.dll
>> #3  0x0000000000000000 in ?? ()
>> Backtrace stopped: previous frame inner to this frame (corrupt
>> stack?)
>> (gdb)
>>
>> Sorry the backtrace is not really helpful..
>>
>> I can reproduce the same behavior with v3.0.0.. and only with
>> the Windows 2008 server host..
>>
>> If I partially revert the patch, eg: using CriticalSection
>> instead of SRWL it seems to work.. But I don't understand why
>> because SRWL should be supported on 2008 Server..
>>
>> Here is the change I did (which is wrongly making qemu_mutex
>> recursive for now):
>>
>> diff --git a/include/qemu/thread-win32.h
>> b/include/qemu/thread-win32.h
>> index d668d789b4..b335687604 100644
>> --- a/include/qemu/thread-win32.h
>> +++ b/include/qemu/thread-win32.h
>> @@ -4,7 +4,8 @@
>>    #include <windows.h>
>>
>>    struct QemuMutex {
>> -    SRWLOCK lock;
>> +    CRITICAL_SECTION lock;
>> +    LONG owner;
>>    #ifdef CONFIG_DEBUG_MUTEX
>>        const char *file;
>>        int line;
>> diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
>> index b303188a36..09ce4fd957 100644
>> --- a/util/qemu-thread-win32.c
>> +++ b/util/qemu-thread-win32.c
>> @@ -45,7 +45,7 @@ static void error_exit(int err, const char *msg)
>>
>>    void qemu_mutex_init(QemuMutex *mutex)
>>    {
>> -    InitializeSRWLock(&mutex->lock);
>> +    InitializeCriticalSection(&mutex->lock);
>>        qemu_mutex_post_init(mutex);
>>    }
>>
>> @@ -53,14 +53,14 @@ void qemu_mutex_destroy(QemuMutex *mutex)
>>    {
>>        assert(mutex->initialized);
>>        mutex->initialized = false;
>> -    InitializeSRWLock(&mutex->lock);
>> +    DeleteCriticalSection(&mutex->lock);
>>    }
>>
>>    void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file,
>> const int line)
>>    {
>>        assert(mutex->initialized);
>>        qemu_mutex_pre_lock(mutex, file, line);
>> -    AcquireSRWLockExclusive(&mutex->lock);
>> +    EnterCriticalSection(&mutex->lock);
>>        qemu_mutex_post_lock(mutex, file, line);
>>    }
>>
>> @@ -69,7 +69,7 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex,
>> const char *file, const int line)
>>        int owned;
>>
>>        assert(mutex->initialized);
>> -    owned = TryAcquireSRWLockExclusive(&mutex->lock);
>> +    owned = TryEnterCriticalSection(&mutex->lock);there
>>        if (owned) {
>>            qemu_mutex_post_lock(mutex, file, line);
>>            return 0;
>> @@ -81,7 +81,7 @@ void qemu_mutex_unlock_impl(QemuMutex *mutex,
>> const char *file, const int line)
>>    {
>>        assert(mutex->initialized);
>>        qemu_mutex_pre_unlock(mutex, file, line);
>> -    ReleaseSRWLockExclusive(&mutex->lock);
>> +    LeaveCriticalSection(&mutex->lock);
>>    }
>>
>>    void qemu_rec_mutex_init(QemuRecMutex *mutex)
>> @@ -141,11 +141,12 @@ void qemu_cond_broadcast(QemuCond *cond)
>>        WakeAllConditionVariable(&cond->var);
>>    }
>>
>> -void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const
>> char *file, const int line)
>> +void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const
>> char *file,
>> +                         const int line)
>>    {
>>        assert(cond->initialized);
>>        qemu_mutex_pre_unlock(mutex, file, line);
>> -    SleepConditionVariableSRW(&cond->var, &mutex->lock,
>> INFINITE, 0);
>> +    SleepConditionVariableCS(&cond->var, &mutex->lock, INFINITE);
>>        qemu_mutex_post_lock(mutex, file, line);
>>    }
>>
>> -- 
>> 2.16.2
>>
>> Do you have any idea of what's happening?
>>
>> Regards,
>> Fred
>>
>
Zhijian Li (Fujitsu)" via Sept. 14, 2018, 4:54 p.m. UTC | #4
Thanks for digging into this Fred, and sorry -- it seems Andrey and I both missed that subtlety with TryAcquireSRWLockExclusive when we first made this change.



On the other hand, since these OSes are a decade old (mainstream support ended; will drop out of extended support in just over a year from now), and you are the first person to report a problem in 1.5 years since the patch went in, I wonder if we could “fix” the problem by updating the required OS versions for QEMU on Windows to Windows 7 / Server 2008 R2...



Paolo, do you have any opinion? Note that backing out the patch isn’t a great idea either – it fixed a deadlock.



Andrew
Paolo Bonzini Sept. 14, 2018, 5:40 p.m. UTC | #5
On 14/09/2018 18:54, Andrew Baumann wrote:
> On the other hand, since these OSes are a decade old (mainstream support
> ended; will drop out of extended support in just over a year from now),
> and you are the first person to report a problem in 1.5 years since the
> patch went in, I wonder if we could “fix” the problem by updating the
> required OS versions for QEMU on Windows to Windows 7 / Server 2008 R2...

I agree.

> Paolo, do you have any opinion? Note that backing out the patch isn’t a
> great idea either – it fixed a deadlock.

No way we're going to back it out. :)  SRWLocks are great.

Paolo
KONRAD Frederic Sept. 17, 2018, 7:54 a.m. UTC | #6
Hi Andrew,

Le 09/14/2018 à 06:54 PM, Andrew Baumann a écrit :
> Thanks for digging into this Fred, and sorry -- it seems Andrey and I both missed that subtlety with TryAcquireSRWLockExclusive when we first made this change.
> 
> 
> 
> On the other hand, since these OSes are a decade old (mainstream support ended; will drop out of extended support in just over a year from now), and you are the first person to report a problem in 1.5 years since the patch went in, I wonder if we could “fix” the problem by updating the required OS versions for QEMU on Windows to Windows 7 / Server 2008 R2...
> 
> 
> 
> Paolo, do you have any opinion? Note that backing out the patch isn’t a great idea either – it fixed a deadlock.

Reverting was not the idea, I was just confused by the fact that
it was theorically possible to run this QEMU under Vista and
Server 2008 and looked for a workaround.. Bumping the requirement
seems a good idea to me.

Fred
> 
> 
> 
> Andrew
> 
> 
> 
> ________________________________
> From: KONRAD Frederic <frederic.konrad@adacore.com>
> Sent: Friday, September 14, 2018 4:17:36 AM
> To: Andrew Baumann; Andrey Shedel
> Cc: Paolo Bonzini; QEMU Developers
> Subject: Re: [Qemu-devel] crashes with win2008 host
> 
> Ok finally got it,
> 
> The SRWL API seems to be available since Vista and Server 2008
> except the 'TryAcquireSRWLockExclusive' function which is
> available starting Seven and Server 2008 *R2*. Hence the error
> message.
> 
> So basically that means QEMU is not compatible with version older
> than Seven or 2008 R2.
> 
> Cheers,
> Fred
> 
> Le 09/14/2018 à 10:29 AM, KONRAD Frederic a écrit :
>>
>>
>> Le 09/13/2018 à 07:29 PM, Andrew Baumann a écrit :
>>> Does this crash always happen at startup? Is it deterministic?
>>>
>>
>> Hi Andrew,
>>
>> Thanks for your reactivity! Yes it crashes all the time..
>>
>>>
>>>
>>> c0000135 is STATUS_DLL_NOT_FOUND. I suspect ntdll is trying to
>>> demand-load another DLL to provide that API, and it is missing
>>> or corrupt on your Windows installation
>>
>> Actually that helps! Compiling in debug mode gave me this
>> errors.. But it wasn't the error I was chasing..
>>
>> The initial error I was chasing is the following:
>>     gdb: unknown target exception 0xc0000139 at 0x77636698
>>
>> When I execute it in graphic mode I get the following issue:
>>
>>     The procedure entry point TryAcquireSRWLockExclusive could not
>>     be located in the dynamic link library KERNEL32.dll.
>>
>> It seems that there was the same issue raised with MySQL on
>> Windows server 2008:
>>     https://forums.mysql.com/read.php?11,642417,642417
>>
>> Is there anything I can do appart swaping back locally to the CS?
>>
>> Thanks,
>> Fred
>>
>>>
>>>
>>>
>>> BTW, you’ll probably get a better stack trace from a native
>>> debugger (windbg, etc.) in this scenario.
>>>
>>>
>>>
>>> Cheers,
>>>
>>> Andrew
>>>
>>>
>>>
>>>
>>>
>>> ________________________________
>>> From: KONRAD Frederic <frederic.konrad@adacore.com>
>>> Sent: Thursday, September 13, 2018 10:02:56 AM
>>> To: Andrey Shedel
>>> Cc: Andrew Baumann; Paolo Bonzini; QEMU Developers
>>> Subject: crashes with win2008 host
>>>
>>> Hi Andrey,
>>>
>>> I've strange crashes since this commit: (yes its old)
>>>
>>> commit 12f8def0e02232d7c6416ad9b66640f973c531d1
>>> Author: Andrey Shedel <ashedel@microsoft.com>
>>> Date:   Fri Mar 24 15:01:41 2017 -0700
>>>
>>>        win32: replace custom mutex and condition variable with
>>>               native primitives
>>>
>>> Basically it just crashes.. (exception 0xc0000135) like this:
>>>
>>> (gdb) run
>>> Starting program: C:\home\konrad\temp\qemu-system-sparc --version
>>> [New Thread 5324.0xdf8]
>>> gdb: unknown target exception 0xc0000135 at 0x77636698
>>> gdb: unknown target exception 0xc0000135 at 0x77636698
>>>
>>> Program received signal ?, Unknown signal.
>>> 0x0000000077636698 in ntdll!RtlRaiseStatus ()
>>>       from C:\Windows\system32\ntdll.dll
>>> (gdb) bt
>>> #0  0x0000000077636698 in ntdll!RtlRaiseStatus ()
>>>       from C:\Windows\system32\ntdll.dll
>>> #1  0x00000000775dcbf7 in ntdll!LdrGetProcedureAddress ()
>>>       from C:\Windows\system32\ntdll.dll
>>> #2  0x00000000775a536e in ntdll!LdrInitializeThunk ()
>>>       from C:\Windows\system32\ntdll.dll
>>> #3  0x0000000000000000 in ?? ()
>>> Backtrace stopped: previous frame inner to this frame (corrupt
>>> stack?)
>>> (gdb)
>>>
>>> Sorry the backtrace is not really helpful..
>>>
>>> I can reproduce the same behavior with v3.0.0.. and only with
>>> the Windows 2008 server host..
>>>
>>> If I partially revert the patch, eg: using CriticalSection
>>> instead of SRWL it seems to work.. But I don't understand why
>>> because SRWL should be supported on 2008 Server..
>>>
>>> Here is the change I did (which is wrongly making qemu_mutex
>>> recursive for now):
>>>
>>> diff --git a/include/qemu/thread-win32.h
>>> b/include/qemu/thread-win32.h
>>> index d668d789b4..b335687604 100644
>>> --- a/include/qemu/thread-win32.h
>>> +++ b/include/qemu/thread-win32.h
>>> @@ -4,7 +4,8 @@
>>>     #include <windows.h>
>>>
>>>     struct QemuMutex {
>>> -    SRWLOCK lock;
>>> +    CRITICAL_SECTION lock;
>>> +    LONG owner;
>>>     #ifdef CONFIG_DEBUG_MUTEX
>>>         const char *file;
>>>         int line;
>>> diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
>>> index b303188a36..09ce4fd957 100644
>>> --- a/util/qemu-thread-win32.c
>>> +++ b/util/qemu-thread-win32.c
>>> @@ -45,7 +45,7 @@ static void error_exit(int err, const char *msg)
>>>
>>>     void qemu_mutex_init(QemuMutex *mutex)
>>>     {
>>> -    InitializeSRWLock(&mutex->lock);
>>> +    InitializeCriticalSection(&mutex->lock);
>>>         qemu_mutex_post_init(mutex);
>>>     }
>>>
>>> @@ -53,14 +53,14 @@ void qemu_mutex_destroy(QemuMutex *mutex)
>>>     {
>>>         assert(mutex->initialized);
>>>         mutex->initialized = false;
>>> -    InitializeSRWLock(&mutex->lock);
>>> +    DeleteCriticalSection(&mutex->lock);
>>>     }
>>>
>>>     void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file,
>>> const int line)
>>>     {
>>>         assert(mutex->initialized);
>>>         qemu_mutex_pre_lock(mutex, file, line);
>>> -    AcquireSRWLockExclusive(&mutex->lock);
>>> +    EnterCriticalSection(&mutex->lock);
>>>         qemu_mutex_post_lock(mutex, file, line);
>>>     }
>>>
>>> @@ -69,7 +69,7 @@ int qemu_mutex_trylock_impl(QemuMutex *mutex,
>>> const char *file, const int line)
>>>         int owned;
>>>
>>>         assert(mutex->initialized);
>>> -    owned = TryAcquireSRWLockExclusive(&mutex->lock);
>>> +    owned = TryEnterCriticalSection(&mutex->lock);there
>>>         if (owned) {
>>>             qemu_mutex_post_lock(mutex, file, line);
>>>             return 0;
>>> @@ -81,7 +81,7 @@ void qemu_mutex_unlock_impl(QemuMutex *mutex,
>>> const char *file, const int line)
>>>     {
>>>         assert(mutex->initialized);
>>>         qemu_mutex_pre_unlock(mutex, file, line);
>>> -    ReleaseSRWLockExclusive(&mutex->lock);
>>> +    LeaveCriticalSection(&mutex->lock);
>>>     }
>>>
>>>     void qemu_rec_mutex_init(QemuRecMutex *mutex)
>>> @@ -141,11 +141,12 @@ void qemu_cond_broadcast(QemuCond *cond)
>>>         WakeAllConditionVariable(&cond->var);
>>>     }
>>>
>>> -void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const
>>> char *file, const int line)
>>> +void qemu_cond_wait_impl(QemuCond *cond, QemuMutex *mutex, const
>>> char *file,
>>> +                         const int line)
>>>     {
>>>         assert(cond->initialized);
>>>         qemu_mutex_pre_unlock(mutex, file, line);
>>> -    SleepConditionVariableSRW(&cond->var, &mutex->lock,
>>> INFINITE, 0);
>>> +    SleepConditionVariableCS(&cond->var, &mutex->lock, INFINITE);
>>>         qemu_mutex_post_lock(mutex, file, line);
>>>     }
>>>
>>> --
>>> 2.16.2
>>>
>>> Do you have any idea of what's happening?
>>>
>>> Regards,
>>> Fred
>>>
>>
>
diff mbox series

Patch

diff --git a/include/qemu/thread-win32.h 
b/include/qemu/thread-win32.h
index d668d789b4..b335687604 100644
--- a/include/qemu/thread-win32.h
+++ b/include/qemu/thread-win32.h
@@ -4,7 +4,8 @@ 
  #include <windows.h>

  struct QemuMutex {
-    SRWLOCK lock;
+    CRITICAL_SECTION lock;
+    LONG owner;
  #ifdef CONFIG_DEBUG_MUTEX
      const char *file;
      int line;
diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
index b303188a36..09ce4fd957 100644
--- a/util/qemu-thread-win32.c
+++ b/util/qemu-thread-win32.c
@@ -45,7 +45,7 @@  static void error_exit(int err, const char *msg)

  void qemu_mutex_init(QemuMutex *mutex)
  {
-    InitializeSRWLock(&mutex->lock);
+    InitializeCriticalSection(&mutex->lock);
      qemu_mutex_post_init(mutex);
  }

@@ -53,14 +53,14 @@  void qemu_mutex_destroy(QemuMutex *mutex)
  {
      assert(mutex->initialized);
      mutex->initialized = false;
-    InitializeSRWLock(&mutex->lock);
+    DeleteCriticalSection(&mutex->lock);
  }

  void qemu_mutex_lock_impl(QemuMutex *mutex, const char *file, 
const int line)
  {
      assert(mutex->initialized);
      qemu_mutex_pre_lock(mutex, file, line);
-    AcquireSRWLockExclusive(&mutex->lock);
+    EnterCriticalSection(&mutex->lock);
      qemu_mutex_post_lock(mutex, file, line);
  }