qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64
@ 2023-02-20 11:12 Pierrick Bouvier
  2023-02-20 11:12 ` [PATCH v3 1/4] util/cacheflush: fix cache " Pierrick Bouvier
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-20 11:12 UTC (permalink / raw)
  To: qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell,
	Pierrick Bouvier

Since v2:

- Delete superfluous comment on unreachable code
- Fix style for multiline comments

Since v1:

- Comment why we use generic version of flush_idcache_range
- Ensure __mingw_setjmp/longjmp are available using meson
- Fix a warning by calling g_assert_not_reached() instead of initializing a
  variable

As before this was tested with:
- make check
- boot an x64 debian bullseye vm
- boot an arm64 ubuntu 22.10 vm

Thanks

Pierrick Bouvier (4):
  util/cacheflush: fix cache on windows-arm64
  sysemu/os-win32: fix setjmp/longjmp on windows-arm64
  qga/vss-win32: fix warning for clang++-15
  target/ppc: fix warning with clang-15

 include/sysemu/os-win32.h | 25 +++++++++++++++++++++++--
 meson.build               | 24 ++++++++++++++++++++++++
 qga/vss-win32/install.cpp |  2 +-
 target/ppc/dfp_helper.c   |  4 ++--
 util/cacheflush.c         | 14 +++++++++++---
 5 files changed, 61 insertions(+), 8 deletions(-)

-- 
2.30.2



^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH v3 1/4] util/cacheflush: fix cache on windows-arm64
  2023-02-20 11:12 [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64 Pierrick Bouvier
@ 2023-02-20 11:12 ` Pierrick Bouvier
  2023-02-20 15:16   ` Pierrick Bouvier
  2023-02-20 11:12 ` [PATCH v3 2/4] sysemu/os-win32: fix setjmp/longjmp " Pierrick Bouvier
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-20 11:12 UTC (permalink / raw)
  To: qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell,
	Pierrick Bouvier

ctr_el0 access is privileged on this platform and fails as an illegal
instruction.

Windows does not offer a way to flush data cache from userspace, and
only FlushInstructionCache is available in Windows API.

The generic implementation of flush_idcache_range uses,
__builtin___clear_cache, which already use the FlushInstructionCache
function. So we rely on that.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 util/cacheflush.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/util/cacheflush.c b/util/cacheflush.c
index 2c2c73e085..06c2333a60 100644
--- a/util/cacheflush.c
+++ b/util/cacheflush.c
@@ -121,8 +121,12 @@ static void sys_cache_info(int *isize, int *dsize)
 static bool have_coherent_icache;
 #endif
 
-#if defined(__aarch64__) && !defined(CONFIG_DARWIN)
-/* Apple does not expose CTR_EL0, so we must use system interfaces. */
+#if defined(__aarch64__) && !defined(CONFIG_DARWIN) && !defined(CONFIG_WIN32)
+/*
+ * Apple does not expose CTR_EL0, so we must use system interfaces.
+ * Windows neither, but we use a generic implementation of flush_idcache_range
+ * in this case.
+ */
 static uint64_t save_ctr_el0;
 static void arch_cache_info(int *isize, int *dsize)
 {
@@ -225,7 +229,11 @@ static void __attribute__((constructor)) init_cache_info(void)
 
 /* Caches are coherent and do not require flushing; symbol inline. */
 
-#elif defined(__aarch64__)
+#elif defined(__aarch64__) && !defined(CONFIG_WIN32)
+/*
+ * For Windows, we use generic implementation of flush_idcache_range, that
+ * performs a call to FlushInstructionCache, through __builtin___clear_cache.
+ */
 
 #ifdef CONFIG_DARWIN
 /* Apple does not expose CTR_EL0, so we must use system interfaces. */
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 2/4] sysemu/os-win32: fix setjmp/longjmp on windows-arm64
  2023-02-20 11:12 [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64 Pierrick Bouvier
  2023-02-20 11:12 ` [PATCH v3 1/4] util/cacheflush: fix cache " Pierrick Bouvier
@ 2023-02-20 11:12 ` Pierrick Bouvier
  2023-02-20 15:16   ` Pierrick Bouvier
  2023-02-20 11:12 ` [PATCH v3 3/4] qga/vss-win32: fix warning for clang++-15 Pierrick Bouvier
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-20 11:12 UTC (permalink / raw)
  To: qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell,
	Pierrick Bouvier

Windows implementation of setjmp/longjmp is done in
C:/WINDOWS/system32/ucrtbase.dll. Alas, on arm64, it seems to *always*
perform stack unwinding, which crashes from generated code.

By using alternative implementation built in mingw, we avoid doing stack
unwinding and this fixes crash when calling longjmp.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 include/sysemu/os-win32.h | 25 +++++++++++++++++++++++--
 meson.build               | 24 ++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index 5b38c7bd04..1f6c141d39 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -51,14 +51,35 @@ typedef struct sockaddr_un {
 extern "C" {
 #endif
 
-#if defined(_WIN64)
+#if defined(__aarch64__)
+#ifndef CONFIG_MINGW64_HAS_SETJMP_LONGJMP
+#error mingw must provide setjmp/longjmp for windows-arm64
+#endif
+/*
+ * On windows-arm64, setjmp is available in only one variant, and longjmp always
+ * does stack unwinding. This crash with generated code.
+ * Thus, we use another implementation of setjmp (not windows one), coming from
+ * mingw, which never performs stack unwinding.
+ */
+#undef setjmp
+#undef longjmp
+/*
+ * These functions are not declared in setjmp.h because __aarch64__ defines
+ * setjmp to _setjmpex instead. However, they are still defined in libmingwex.a,
+ * which gets linked automatically.
+ */
+extern int __mingw_setjmp(jmp_buf);
+extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
+#define setjmp(env) __mingw_setjmp(env)
+#define longjmp(env, val) __mingw_longjmp(env, val)
+#elif defined(_WIN64)
 /* On w64, setjmp is implemented by _setjmp which needs a second parameter.
  * If this parameter is NULL, longjump does no stack unwinding.
  * That is what we need for QEMU. Passing the value of register rsp (default)
  * lets longjmp try a stack unwinding which will crash with generated code. */
 # undef setjmp
 # define setjmp(env) _setjmp(env, NULL)
-#endif
+#endif /* __aarch64__ */
 /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify
  * "longjmp and don't touch the signal masks". Since we know that the
  * savemask parameter will always be zero we can safely define these
diff --git a/meson.build b/meson.build
index 4ba3bf3431..e968ed9e7a 100644
--- a/meson.build
+++ b/meson.build
@@ -2450,6 +2450,30 @@ if targetos == 'windows'
     }''', name: '_lock_file and _unlock_file'))
 endif
 
+if targetos == 'windows'
+  mingw_has_setjmp_longjmp = cc.links('''
+    #include <setjmp.h>
+    int main(void) {
+      /*
+       * These functions are not available in setjmp header, but may be
+       * available at link time, from libmingwex.a.
+       */
+      extern int __mingw_setjmp(jmp_buf);
+      extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
+      jmp_buf env;
+      __mingw_setjmp(env);
+      __mingw_longjmp(env, 0);
+    }
+  ''', name: 'mingw setjmp and longjmp')
+
+  config_host_data.set('CONFIG_MINGW64_HAS_SETJMP_LONGJMP',
+                       mingw_has_setjmp_longjmp)
+
+  if cpu == 'aarch64' and not mingw_has_setjmp_longjmp
+    error('mingw must provide setjmp/longjmp for windows-arm64')
+  endif
+endif
+
 ########################
 # Target configuration #
 ########################
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 3/4] qga/vss-win32: fix warning for clang++-15
  2023-02-20 11:12 [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64 Pierrick Bouvier
  2023-02-20 11:12 ` [PATCH v3 1/4] util/cacheflush: fix cache " Pierrick Bouvier
  2023-02-20 11:12 ` [PATCH v3 2/4] sysemu/os-win32: fix setjmp/longjmp " Pierrick Bouvier
@ 2023-02-20 11:12 ` Pierrick Bouvier
  2023-02-20 15:16   ` Pierrick Bouvier
  2023-02-21 10:24   ` Philippe Mathieu-Daudé
  2023-02-20 11:12 ` [PATCH v3 4/4] target/ppc: fix warning with clang-15 Pierrick Bouvier
  2023-02-20 11:33 ` [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64 Philippe Mathieu-Daudé
  4 siblings, 2 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-20 11:12 UTC (permalink / raw)
  To: qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell,
	Pierrick Bouvier

Reported when compiling with clang-windows-arm64.

../qga/vss-win32/install.cpp:537:9: error: variable 'hr' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
    if (!(ControlService(service, SERVICE_CONTROL_STOP, NULL))) {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../qga/vss-win32/install.cpp:545:12: note: uninitialized use occurs here
    return hr;
           ^~
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 qga/vss-win32/install.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
index b57508fbe0..b8087e5baa 100644
--- a/qga/vss-win32/install.cpp
+++ b/qga/vss-win32/install.cpp
@@ -518,7 +518,7 @@ namespace _com_util
 /* Stop QGA VSS provider service using Winsvc API  */
 STDAPI StopService(void)
 {
-    HRESULT hr;
+    HRESULT hr = S_OK;
     SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
     SC_HANDLE service = NULL;
 
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v3 4/4] target/ppc: fix warning with clang-15
  2023-02-20 11:12 [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64 Pierrick Bouvier
                   ` (2 preceding siblings ...)
  2023-02-20 11:12 ` [PATCH v3 3/4] qga/vss-win32: fix warning for clang++-15 Pierrick Bouvier
@ 2023-02-20 11:12 ` Pierrick Bouvier
  2023-02-20 15:16   ` Pierrick Bouvier
  2023-02-20 11:33 ` [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64 Philippe Mathieu-Daudé
  4 siblings, 1 reply; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-20 11:12 UTC (permalink / raw)
  To: qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell,
	Pierrick Bouvier

When compiling for windows-arm64 using clang-15, it reports a sometimes
uninitialized variable. This seems to be a false positive, as a default
case guards switch expressions, preventing to return an uninitialized
value, but clang seems unhappy with assert(0) definition.

Change code to g_assert_not_reached() fix the warning.

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 target/ppc/dfp_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/ppc/dfp_helper.c b/target/ppc/dfp_helper.c
index cc024316d5..5967ea07a9 100644
--- a/target/ppc/dfp_helper.c
+++ b/target/ppc/dfp_helper.c
@@ -121,7 +121,7 @@ static void dfp_set_round_mode_from_immediate(uint8_t r, uint8_t rmc,
         case 3: /* use FPSCR rounding mode */
             return;
         default:
-            assert(0); /* cannot get here */
+            g_assert_not_reached();
         }
     } else { /* r == 1 */
         switch (rmc & 3) {
@@ -138,7 +138,7 @@ static void dfp_set_round_mode_from_immediate(uint8_t r, uint8_t rmc,
             rnd = DEC_ROUND_HALF_DOWN;
             break;
         default:
-            assert(0); /* cannot get here */
+            g_assert_not_reached();
         }
     }
     decContextSetRounding(&dfp->context, rnd);
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64
  2023-02-20 11:12 [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64 Pierrick Bouvier
                   ` (3 preceding siblings ...)
  2023-02-20 11:12 ` [PATCH v3 4/4] target/ppc: fix warning with clang-15 Pierrick Bouvier
@ 2023-02-20 11:33 ` Philippe Mathieu-Daudé
  2023-02-20 15:10   ` Pierrick Bouvier
  4 siblings, 1 reply; 16+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-20 11:33 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell

Hi Pierrick,

On 20/2/23 12:12, Pierrick Bouvier wrote:
> Since v2:
> 
> - Delete superfluous comment on unreachable code
> - Fix style for multiline comments
> 
> Since v1:
> 
> - Comment why we use generic version of flush_idcache_range
> - Ensure __mingw_setjmp/longjmp are available using meson
> - Fix a warning by calling g_assert_not_reached() instead of initializing a
>    variable
> 
> As before this was tested with:
> - make check
> - boot an x64 debian bullseye vm
> - boot an arm64 ubuntu 22.10 vm
> 
> Thanks
> 
> Pierrick Bouvier (4):
>    util/cacheflush: fix cache on windows-arm64
>    sysemu/os-win32: fix setjmp/longjmp on windows-arm64
>    qga/vss-win32: fix warning for clang++-15
>    target/ppc: fix warning with clang-15

You forgot to include the 'Reviewed-by/Acked-by' tags from your previous
versions. See from these guidelines:
https://www.qemu.org/docs/master/devel/submitting-a-patch.html#proper-use-of-reviewed-by-tags-can-aid-review

   When reviewing a large series, a reviewer can reply to some of the
   patches with a Reviewed-by tag, stating that they are happy with
   that patch in isolation [...]. You should then update those commit
   messages by hand to include the Reviewed-by tag, so that in the next
   revision, reviewers can spot which patches were already clean from
   the previous round.

No need for a v4, you can reply to each patch with the missed tags.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64
  2023-02-20 11:33 ` [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64 Philippe Mathieu-Daudé
@ 2023-02-20 15:10   ` Pierrick Bouvier
  0 siblings, 0 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-20 15:10 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell

On 2/20/23 12:33, Philippe Mathieu-Daudé wrote:
> Hi Pierrick,
> 
> On 20/2/23 12:12, Pierrick Bouvier wrote:
>> Since v2:
>>
>> - Delete superfluous comment on unreachable code
>> - Fix style for multiline comments
>>
>> Since v1:
>>
>> - Comment why we use generic version of flush_idcache_range
>> - Ensure __mingw_setjmp/longjmp are available using meson
>> - Fix a warning by calling g_assert_not_reached() instead of initializing a
>>     variable
>>
>> As before this was tested with:
>> - make check
>> - boot an x64 debian bullseye vm
>> - boot an arm64 ubuntu 22.10 vm
>>
>> Thanks
>>
>> Pierrick Bouvier (4):
>>     util/cacheflush: fix cache on windows-arm64
>>     sysemu/os-win32: fix setjmp/longjmp on windows-arm64
>>     qga/vss-win32: fix warning for clang++-15
>>     target/ppc: fix warning with clang-15
> 
> You forgot to include the 'Reviewed-by/Acked-by' tags from your previous
> versions. See from these guidelines:
> https://www.qemu.org/docs/master/devel/submitting-a-patch.html#proper-use-of-reviewed-by-tags-can-aid-review
> 
>     When reviewing a large series, a reviewer can reply to some of the
>     patches with a Reviewed-by tag, stating that they are happy with
>     that patch in isolation [...]. You should then update those commit
>     messages by hand to include the Reviewed-by tag, so that in the next
>     revision, reviewers can spot which patches were already clean from
>     the previous round.
> 
> No need for a v4, you can reply to each patch with the missed tags.

Thanks for your kind guidance. I was not sure if I or a maintainer was 
"allowed" to add those tags in commit message.

I'll do it (in case a v4 is needed), and for now, just reply with 
previous ones.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 1/4] util/cacheflush: fix cache on windows-arm64
  2023-02-20 11:12 ` [PATCH v3 1/4] util/cacheflush: fix cache " Pierrick Bouvier
@ 2023-02-20 15:16   ` Pierrick Bouvier
  0 siblings, 0 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-20 15:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

On 2/20/23 12:12, Pierrick Bouvier wrote:
> ctr_el0 access is privileged on this platform and fails as an illegal
> instruction.
> 
> Windows does not offer a way to flush data cache from userspace, and
> only FlushInstructionCache is available in Windows API.
> 
> The generic implementation of flush_idcache_range uses,
> __builtin___clear_cache, which already use the FlushInstructionCache
> function. So we rely on that.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   util/cacheflush.c | 14 +++++++++++---
>   1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/util/cacheflush.c b/util/cacheflush.c
> index 2c2c73e085..06c2333a60 100644
> --- a/util/cacheflush.c
> +++ b/util/cacheflush.c
> @@ -121,8 +121,12 @@ static void sys_cache_info(int *isize, int *dsize)
>   static bool have_coherent_icache;
>   #endif
>   
> -#if defined(__aarch64__) && !defined(CONFIG_DARWIN)
> -/* Apple does not expose CTR_EL0, so we must use system interfaces. */
> +#if defined(__aarch64__) && !defined(CONFIG_DARWIN) && !defined(CONFIG_WIN32)
> +/*
> + * Apple does not expose CTR_EL0, so we must use system interfaces.
> + * Windows neither, but we use a generic implementation of flush_idcache_range
> + * in this case.
> + */
>   static uint64_t save_ctr_el0;
>   static void arch_cache_info(int *isize, int *dsize)
>   {
> @@ -225,7 +229,11 @@ static void __attribute__((constructor)) init_cache_info(void)
>   
>   /* Caches are coherent and do not require flushing; symbol inline. */
>   
> -#elif defined(__aarch64__)
> +#elif defined(__aarch64__) && !defined(CONFIG_WIN32)
> +/*
> + * For Windows, we use generic implementation of flush_idcache_range, that
> + * performs a call to FlushInstructionCache, through __builtin___clear_cache.
> + */
>   
>   #ifdef CONFIG_DARWIN
>   /* Apple does not expose CTR_EL0, so we must use system interfaces. */


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 2/4] sysemu/os-win32: fix setjmp/longjmp on windows-arm64
  2023-02-20 11:12 ` [PATCH v3 2/4] sysemu/os-win32: fix setjmp/longjmp " Pierrick Bouvier
@ 2023-02-20 15:16   ` Pierrick Bouvier
  2023-02-21  9:47     ` Pierrick Bouvier
  0 siblings, 1 reply; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-20 15:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell

Acked-by: Richard Henderson <richard.henderson@linaro.org>

On 2/20/23 12:12, Pierrick Bouvier wrote:
> Windows implementation of setjmp/longjmp is done in
> C:/WINDOWS/system32/ucrtbase.dll. Alas, on arm64, it seems to *always*
> perform stack unwinding, which crashes from generated code.
> 
> By using alternative implementation built in mingw, we avoid doing stack
> unwinding and this fixes crash when calling longjmp.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   include/sysemu/os-win32.h | 25 +++++++++++++++++++++++--
>   meson.build               | 24 ++++++++++++++++++++++++
>   2 files changed, 47 insertions(+), 2 deletions(-)
> 
> diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
> index 5b38c7bd04..1f6c141d39 100644
> --- a/include/sysemu/os-win32.h
> +++ b/include/sysemu/os-win32.h
> @@ -51,14 +51,35 @@ typedef struct sockaddr_un {
>   extern "C" {
>   #endif
>   
> -#if defined(_WIN64)
> +#if defined(__aarch64__)
> +#ifndef CONFIG_MINGW64_HAS_SETJMP_LONGJMP
> +#error mingw must provide setjmp/longjmp for windows-arm64
> +#endif
> +/*
> + * On windows-arm64, setjmp is available in only one variant, and longjmp always
> + * does stack unwinding. This crash with generated code.
> + * Thus, we use another implementation of setjmp (not windows one), coming from
> + * mingw, which never performs stack unwinding.
> + */
> +#undef setjmp
> +#undef longjmp
> +/*
> + * These functions are not declared in setjmp.h because __aarch64__ defines
> + * setjmp to _setjmpex instead. However, they are still defined in libmingwex.a,
> + * which gets linked automatically.
> + */
> +extern int __mingw_setjmp(jmp_buf);
> +extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
> +#define setjmp(env) __mingw_setjmp(env)
> +#define longjmp(env, val) __mingw_longjmp(env, val)
> +#elif defined(_WIN64)
>   /* On w64, setjmp is implemented by _setjmp which needs a second parameter.
>    * If this parameter is NULL, longjump does no stack unwinding.
>    * That is what we need for QEMU. Passing the value of register rsp (default)
>    * lets longjmp try a stack unwinding which will crash with generated code. */
>   # undef setjmp
>   # define setjmp(env) _setjmp(env, NULL)
> -#endif
> +#endif /* __aarch64__ */
>   /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify
>    * "longjmp and don't touch the signal masks". Since we know that the
>    * savemask parameter will always be zero we can safely define these
> diff --git a/meson.build b/meson.build
> index 4ba3bf3431..e968ed9e7a 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2450,6 +2450,30 @@ if targetos == 'windows'
>       }''', name: '_lock_file and _unlock_file'))
>   endif
>   
> +if targetos == 'windows'
> +  mingw_has_setjmp_longjmp = cc.links('''
> +    #include <setjmp.h>
> +    int main(void) {
> +      /*
> +       * These functions are not available in setjmp header, but may be
> +       * available at link time, from libmingwex.a.
> +       */
> +      extern int __mingw_setjmp(jmp_buf);
> +      extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
> +      jmp_buf env;
> +      __mingw_setjmp(env);
> +      __mingw_longjmp(env, 0);
> +    }
> +  ''', name: 'mingw setjmp and longjmp')
> +
> +  config_host_data.set('CONFIG_MINGW64_HAS_SETJMP_LONGJMP',
> +                       mingw_has_setjmp_longjmp)
> +
> +  if cpu == 'aarch64' and not mingw_has_setjmp_longjmp
> +    error('mingw must provide setjmp/longjmp for windows-arm64')
> +  endif
> +endif
> +
>   ########################
>   # Target configuration #
>   ########################


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 3/4] qga/vss-win32: fix warning for clang++-15
  2023-02-20 11:12 ` [PATCH v3 3/4] qga/vss-win32: fix warning for clang++-15 Pierrick Bouvier
@ 2023-02-20 15:16   ` Pierrick Bouvier
  2023-02-21 10:24   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-20 15:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell

Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>

On 2/20/23 12:12, Pierrick Bouvier wrote:
> Reported when compiling with clang-windows-arm64.
> 
> ../qga/vss-win32/install.cpp:537:9: error: variable 'hr' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
>      if (!(ControlService(service, SERVICE_CONTROL_STOP, NULL))) {
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../qga/vss-win32/install.cpp:545:12: note: uninitialized use occurs here
>      return hr;
>             ^~
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   qga/vss-win32/install.cpp | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
> index b57508fbe0..b8087e5baa 100644
> --- a/qga/vss-win32/install.cpp
> +++ b/qga/vss-win32/install.cpp
> @@ -518,7 +518,7 @@ namespace _com_util
>   /* Stop QGA VSS provider service using Winsvc API  */
>   STDAPI StopService(void)
>   {
> -    HRESULT hr;
> +    HRESULT hr = S_OK;
>       SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
>       SC_HANDLE service = NULL;
>   


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 4/4] target/ppc: fix warning with clang-15
  2023-02-20 11:12 ` [PATCH v3 4/4] target/ppc: fix warning with clang-15 Pierrick Bouvier
@ 2023-02-20 15:16   ` Pierrick Bouvier
  0 siblings, 0 replies; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-20 15:16 UTC (permalink / raw)
  To: qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

On 2/20/23 12:12, Pierrick Bouvier wrote:
> When compiling for windows-arm64 using clang-15, it reports a sometimes
> uninitialized variable. This seems to be a false positive, as a default
> case guards switch expressions, preventing to return an uninitialized
> value, but clang seems unhappy with assert(0) definition.
> 
> Change code to g_assert_not_reached() fix the warning.
> 
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   target/ppc/dfp_helper.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/target/ppc/dfp_helper.c b/target/ppc/dfp_helper.c
> index cc024316d5..5967ea07a9 100644
> --- a/target/ppc/dfp_helper.c
> +++ b/target/ppc/dfp_helper.c
> @@ -121,7 +121,7 @@ static void dfp_set_round_mode_from_immediate(uint8_t r, uint8_t rmc,
>           case 3: /* use FPSCR rounding mode */
>               return;
>           default:
> -            assert(0); /* cannot get here */
> +            g_assert_not_reached();
>           }
>       } else { /* r == 1 */
>           switch (rmc & 3) {
> @@ -138,7 +138,7 @@ static void dfp_set_round_mode_from_immediate(uint8_t r, uint8_t rmc,
>               rnd = DEC_ROUND_HALF_DOWN;
>               break;
>           default:
> -            assert(0); /* cannot get here */
> +            g_assert_not_reached();
>           }
>       }
>       decContextSetRounding(&dfp->context, rnd);


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 2/4] sysemu/os-win32: fix setjmp/longjmp on windows-arm64
  2023-02-20 15:16   ` Pierrick Bouvier
@ 2023-02-21  9:47     ` Pierrick Bouvier
  2023-02-21 10:33       ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-21  9:47 UTC (permalink / raw)
  To: qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell,
	Philippe Mathieu-Daudé

@Philippe Mathieu-Daudé, is that version satisfying for you, regarding 
your initial comments about setjmp/longjmp detection in meson?

I can integrate more changes if needed.

Thanks,
Pierrick

On 2/20/23 16:16, Pierrick Bouvier wrote:
> Acked-by: Richard Henderson <richard.henderson@linaro.org>
> 
> On 2/20/23 12:12, Pierrick Bouvier wrote:
>> Windows implementation of setjmp/longjmp is done in
>> C:/WINDOWS/system32/ucrtbase.dll. Alas, on arm64, it seems to *always*
>> perform stack unwinding, which crashes from generated code.
>>
>> By using alternative implementation built in mingw, we avoid doing stack
>> unwinding and this fixes crash when calling longjmp.
>>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>>    include/sysemu/os-win32.h | 25 +++++++++++++++++++++++--
>>    meson.build               | 24 ++++++++++++++++++++++++
>>    2 files changed, 47 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
>> index 5b38c7bd04..1f6c141d39 100644
>> --- a/include/sysemu/os-win32.h
>> +++ b/include/sysemu/os-win32.h
>> @@ -51,14 +51,35 @@ typedef struct sockaddr_un {
>>    extern "C" {
>>    #endif
>>    
>> -#if defined(_WIN64)
>> +#if defined(__aarch64__)
>> +#ifndef CONFIG_MINGW64_HAS_SETJMP_LONGJMP
>> +#error mingw must provide setjmp/longjmp for windows-arm64
>> +#endif
>> +/*
>> + * On windows-arm64, setjmp is available in only one variant, and longjmp always
>> + * does stack unwinding. This crash with generated code.
>> + * Thus, we use another implementation of setjmp (not windows one), coming from
>> + * mingw, which never performs stack unwinding.
>> + */
>> +#undef setjmp
>> +#undef longjmp
>> +/*
>> + * These functions are not declared in setjmp.h because __aarch64__ defines
>> + * setjmp to _setjmpex instead. However, they are still defined in libmingwex.a,
>> + * which gets linked automatically.
>> + */
>> +extern int __mingw_setjmp(jmp_buf);
>> +extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
>> +#define setjmp(env) __mingw_setjmp(env)
>> +#define longjmp(env, val) __mingw_longjmp(env, val)
>> +#elif defined(_WIN64)
>>    /* On w64, setjmp is implemented by _setjmp which needs a second parameter.
>>     * If this parameter is NULL, longjump does no stack unwinding.
>>     * That is what we need for QEMU. Passing the value of register rsp (default)
>>     * lets longjmp try a stack unwinding which will crash with generated code. */
>>    # undef setjmp
>>    # define setjmp(env) _setjmp(env, NULL)
>> -#endif
>> +#endif /* __aarch64__ */
>>    /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify
>>     * "longjmp and don't touch the signal masks". Since we know that the
>>     * savemask parameter will always be zero we can safely define these
>> diff --git a/meson.build b/meson.build
>> index 4ba3bf3431..e968ed9e7a 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -2450,6 +2450,30 @@ if targetos == 'windows'
>>        }''', name: '_lock_file and _unlock_file'))
>>    endif
>>    
>> +if targetos == 'windows'
>> +  mingw_has_setjmp_longjmp = cc.links('''
>> +    #include <setjmp.h>
>> +    int main(void) {
>> +      /*
>> +       * These functions are not available in setjmp header, but may be
>> +       * available at link time, from libmingwex.a.
>> +       */
>> +      extern int __mingw_setjmp(jmp_buf);
>> +      extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
>> +      jmp_buf env;
>> +      __mingw_setjmp(env);
>> +      __mingw_longjmp(env, 0);
>> +    }
>> +  ''', name: 'mingw setjmp and longjmp')
>> +
>> +  config_host_data.set('CONFIG_MINGW64_HAS_SETJMP_LONGJMP',
>> +                       mingw_has_setjmp_longjmp)
>> +
>> +  if cpu == 'aarch64' and not mingw_has_setjmp_longjmp
>> +    error('mingw must provide setjmp/longjmp for windows-arm64')
>> +  endif
>> +endif
>> +
>>    ########################
>>    # Target configuration #
>>    ########################

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 3/4] qga/vss-win32: fix warning for clang++-15
  2023-02-20 11:12 ` [PATCH v3 3/4] qga/vss-win32: fix warning for clang++-15 Pierrick Bouvier
  2023-02-20 15:16   ` Pierrick Bouvier
@ 2023-02-21 10:24   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 16+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-21 10:24 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell

On 20/2/23 12:12, Pierrick Bouvier wrote:
> Reported when compiling with clang-windows-arm64.
> 
> ../qga/vss-win32/install.cpp:537:9: error: variable 'hr' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
>      if (!(ControlService(service, SERVICE_CONTROL_STOP, NULL))) {
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../qga/vss-win32/install.cpp:545:12: note: uninitialized use occurs here
>      return hr;
>             ^~
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
>   qga/vss-win32/install.cpp | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
> index b57508fbe0..b8087e5baa 100644
> --- a/qga/vss-win32/install.cpp
> +++ b/qga/vss-win32/install.cpp
> @@ -518,7 +518,7 @@ namespace _com_util
>   /* Stop QGA VSS provider service using Winsvc API  */
>   STDAPI StopService(void)
>   {
> -    HRESULT hr;
> +    HRESULT hr = S_OK;
>       SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
>       SC_HANDLE service = NULL;
>   

Fixes: 917ebcb170 ("qga-win: Fix QGA VSS Provider service stop failure")
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 2/4] sysemu/os-win32: fix setjmp/longjmp on windows-arm64
  2023-02-21  9:47     ` Pierrick Bouvier
@ 2023-02-21 10:33       ` Philippe Mathieu-Daudé
  2023-02-21 13:16         ` Pierrick Bouvier
  0 siblings, 1 reply; 16+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-21 10:33 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell

On 21/2/23 10:47, Pierrick Bouvier wrote:
> @Philippe Mathieu-Daudé, is that version satisfying for you, regarding 
> your initial comments about setjmp/longjmp detection in meson?

Yes, the meson check is what I had in mind.

> I can integrate more changes if needed.
> 
> Thanks,
> Pierrick
> 
> On 2/20/23 16:16, Pierrick Bouvier wrote:
>> Acked-by: Richard Henderson <richard.henderson@linaro.org>
>>
>> On 2/20/23 12:12, Pierrick Bouvier wrote:
>>> Windows implementation of setjmp/longjmp is done in
>>> C:/WINDOWS/system32/ucrtbase.dll. Alas, on arm64, it seems to *always*
>>> perform stack unwinding, which crashes from generated code.
>>>
>>> By using alternative implementation built in mingw, we avoid doing stack
>>> unwinding and this fixes crash when calling longjmp.
>>>
>>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>>> ---
>>>    include/sysemu/os-win32.h | 25 +++++++++++++++++++++++--
>>>    meson.build               | 24 ++++++++++++++++++++++++
>>>    2 files changed, 47 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
>>> index 5b38c7bd04..1f6c141d39 100644
>>> --- a/include/sysemu/os-win32.h
>>> +++ b/include/sysemu/os-win32.h
>>> @@ -51,14 +51,35 @@ typedef struct sockaddr_un {
>>>    extern "C" {
>>>    #endif
>>> -#if defined(_WIN64)
>>> +#if defined(__aarch64__)
>>> +#ifndef CONFIG_MINGW64_HAS_SETJMP_LONGJMP
>>> +#error mingw must provide setjmp/longjmp for windows-arm64

Per the meson error [*], this now seems impossible, thus we can
simply drop the CONFIG_MINGW64_HAS_SETJMP_LONGJMP definition?

>>> +#endif
>>> +/*
>>> + * On windows-arm64, setjmp is available in only one variant, and 
>>> longjmp always
>>> + * does stack unwinding. This crash with generated code.
>>> + * Thus, we use another implementation of setjmp (not windows one), 
>>> coming from
>>> + * mingw, which never performs stack unwinding.
>>> + */
>>> +#undef setjmp
>>> +#undef longjmp
>>> +/*
>>> + * These functions are not declared in setjmp.h because __aarch64__ 
>>> defines
>>> + * setjmp to _setjmpex instead. However, they are still defined in 
>>> libmingwex.a,
>>> + * which gets linked automatically.
>>> + */
>>> +extern int __mingw_setjmp(jmp_buf);
>>> +extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
>>> +#define setjmp(env) __mingw_setjmp(env)
>>> +#define longjmp(env, val) __mingw_longjmp(env, val)
>>> +#elif defined(_WIN64)
>>>    /* On w64, setjmp is implemented by _setjmp which needs a second 
>>> parameter.
>>>     * If this parameter is NULL, longjump does no stack unwinding.
>>>     * That is what we need for QEMU. Passing the value of register 
>>> rsp (default)
>>>     * lets longjmp try a stack unwinding which will crash with 
>>> generated code. */
>>>    # undef setjmp
>>>    # define setjmp(env) _setjmp(env, NULL)
>>> -#endif
>>> +#endif /* __aarch64__ */

This comment doesn't seem accurate. Maybe "64-bit"?

>>>    /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify
>>>     * "longjmp and don't touch the signal masks". Since we know that the
>>>     * savemask parameter will always be zero we can safely define these
>>> diff --git a/meson.build b/meson.build
>>> index 4ba3bf3431..e968ed9e7a 100644
>>> --- a/meson.build
>>> +++ b/meson.build
>>> @@ -2450,6 +2450,30 @@ if targetos == 'windows'
>>>        }''', name: '_lock_file and _unlock_file'))
>>>    endif
>>> +if targetos == 'windows'
>>> +  mingw_has_setjmp_longjmp = cc.links('''
>>> +    #include <setjmp.h>
>>> +    int main(void) {
>>> +      /*
>>> +       * These functions are not available in setjmp header, but may be
>>> +       * available at link time, from libmingwex.a.
>>> +       */
>>> +      extern int __mingw_setjmp(jmp_buf);
>>> +      extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, 
>>> int);
>>> +      jmp_buf env;
>>> +      __mingw_setjmp(env);
>>> +      __mingw_longjmp(env, 0);
>>> +    }
>>> +  ''', name: 'mingw setjmp and longjmp')
>>> +
>>> +  config_host_data.set('CONFIG_MINGW64_HAS_SETJMP_LONGJMP',
>>> +                       mingw_has_setjmp_longjmp)
>>> +
>>> +  if cpu == 'aarch64' and not mingw_has_setjmp_longjmp
>>> +    error('mingw must provide setjmp/longjmp for windows-arm64')

(This is the [*] error I mentioned earlier).

>>> +  endif
>>> +endif
>>> +
>>>    ########################
>>>    # Target configuration #
>>>    ########################



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 2/4] sysemu/os-win32: fix setjmp/longjmp on windows-arm64
  2023-02-21 10:33       ` Philippe Mathieu-Daudé
@ 2023-02-21 13:16         ` Pierrick Bouvier
  2023-02-21 14:27           ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 16+ messages in thread
From: Pierrick Bouvier @ 2023-02-21 13:16 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell

On 2/21/23 11:33, Philippe Mathieu-Daudé wrote:
> On 21/2/23 10:47, Pierrick Bouvier wrote:
>> @Philippe Mathieu-Daudé, is that version satisfying for you, regarding
>> your initial comments about setjmp/longjmp detection in meson?
> 
> Yes, the meson check is what I had in mind.
> 
>> I can integrate more changes if needed.
>>
>> Thanks,
>> Pierrick
>>
>> On 2/20/23 16:16, Pierrick Bouvier wrote:
>>> Acked-by: Richard Henderson <richard.henderson@linaro.org>
>>>
>>> On 2/20/23 12:12, Pierrick Bouvier wrote:
>>>> Windows implementation of setjmp/longjmp is done in
>>>> C:/WINDOWS/system32/ucrtbase.dll. Alas, on arm64, it seems to *always*
>>>> perform stack unwinding, which crashes from generated code.
>>>>
>>>> By using alternative implementation built in mingw, we avoid doing stack
>>>> unwinding and this fixes crash when calling longjmp.
>>>>
>>>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>>>> ---
>>>>     include/sysemu/os-win32.h | 25 +++++++++++++++++++++++--
>>>>     meson.build               | 24 ++++++++++++++++++++++++
>>>>     2 files changed, 47 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
>>>> index 5b38c7bd04..1f6c141d39 100644
>>>> --- a/include/sysemu/os-win32.h
>>>> +++ b/include/sysemu/os-win32.h
>>>> @@ -51,14 +51,35 @@ typedef struct sockaddr_un {
>>>>     extern "C" {
>>>>     #endif
>>>> -#if defined(_WIN64)
>>>> +#if defined(__aarch64__)
>>>> +#ifndef CONFIG_MINGW64_HAS_SETJMP_LONGJMP
>>>> +#error mingw must provide setjmp/longjmp for windows-arm64
> 
> Per the meson error [*], this now seems impossible, thus we can
> simply drop the CONFIG_MINGW64_HAS_SETJMP_LONGJMP definition?
>

I think it's redundant too.

>>>> +#endif
>>>> +/*
>>>> + * On windows-arm64, setjmp is available in only one variant, and
>>>> longjmp always
>>>> + * does stack unwinding. This crash with generated code.
>>>> + * Thus, we use another implementation of setjmp (not windows one),
>>>> coming from
>>>> + * mingw, which never performs stack unwinding.
>>>> + */
>>>> +#undef setjmp
>>>> +#undef longjmp
>>>> +/*
>>>> + * These functions are not declared in setjmp.h because __aarch64__
>>>> defines
>>>> + * setjmp to _setjmpex instead. However, they are still defined in
>>>> libmingwex.a,
>>>> + * which gets linked automatically.
>>>> + */
>>>> +extern int __mingw_setjmp(jmp_buf);
>>>> +extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int);
>>>> +#define setjmp(env) __mingw_setjmp(env)
>>>> +#define longjmp(env, val) __mingw_longjmp(env, val)
>>>> +#elif defined(_WIN64)
>>>>     /* On w64, setjmp is implemented by _setjmp which needs a second
>>>> parameter.
>>>>      * If this parameter is NULL, longjump does no stack unwinding.
>>>>      * That is what we need for QEMU. Passing the value of register
>>>> rsp (default)
>>>>      * lets longjmp try a stack unwinding which will crash with
>>>> generated code. */
>>>>     # undef setjmp
>>>>     # define setjmp(env) _setjmp(env, NULL)
>>>> -#endif
>>>> +#endif /* __aarch64__ */
> 
> This comment doesn't seem accurate. Maybe "64-bit"?
> 

I'd like to use windows-x64. IMHO,  it's clearer and on par with 
windows-arm64. But I know some people don't like x64 nomenclature.

Alas, several projects are using w32 and w64 names, and there is no 
consensus yet on how win-arm64 should be named.

>>>>     /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify
>>>>      * "longjmp and don't touch the signal masks". Since we know that the
>>>>      * savemask parameter will always be zero we can safely define these
>>>> diff --git a/meson.build b/meson.build
>>>> index 4ba3bf3431..e968ed9e7a 100644
>>>> --- a/meson.build
>>>> +++ b/meson.build
>>>> @@ -2450,6 +2450,30 @@ if targetos == 'windows'
>>>>         }''', name: '_lock_file and _unlock_file'))
>>>>     endif
>>>> +if targetos == 'windows'
>>>> +  mingw_has_setjmp_longjmp = cc.links('''
>>>> +    #include <setjmp.h>
>>>> +    int main(void) {
>>>> +      /*
>>>> +       * These functions are not available in setjmp header, but may be
>>>> +       * available at link time, from libmingwex.a.
>>>> +       */
>>>> +      extern int __mingw_setjmp(jmp_buf);
>>>> +      extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf,
>>>> int);
>>>> +      jmp_buf env;
>>>> +      __mingw_setjmp(env);
>>>> +      __mingw_longjmp(env, 0);
>>>> +    }
>>>> +  ''', name: 'mingw setjmp and longjmp')
>>>> +
>>>> +  config_host_data.set('CONFIG_MINGW64_HAS_SETJMP_LONGJMP',
>>>> +                       mingw_has_setjmp_longjmp)
>>>> +
>>>> +  if cpu == 'aarch64' and not mingw_has_setjmp_longjmp
>>>> +    error('mingw must provide setjmp/longjmp for windows-arm64')
> 
> (This is the [*] error I mentioned earlier).
> 
>>>> +  endif
>>>> +endif
>>>> +
>>>>     ########################
>>>>     # Target configuration #
>>>>     ########################
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v3 2/4] sysemu/os-win32: fix setjmp/longjmp on windows-arm64
  2023-02-21 13:16         ` Pierrick Bouvier
@ 2023-02-21 14:27           ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 16+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-21 14:27 UTC (permalink / raw)
  To: Pierrick Bouvier, qemu-devel
  Cc: sw, kkostiuk, clg, richard.henderson, alex.bennee, peter.maydell

On 21/2/23 14:16, Pierrick Bouvier wrote:
> On 2/21/23 11:33, Philippe Mathieu-Daudé wrote:
>> On 21/2/23 10:47, Pierrick Bouvier wrote:
>>> @Philippe Mathieu-Daudé, is that version satisfying for you, regarding
>>> your initial comments about setjmp/longjmp detection in meson?
>>
>> Yes, the meson check is what I had in mind.
>>
>>> I can integrate more changes if needed.
>>>
>>> Thanks,
>>> Pierrick
>>>
>>> On 2/20/23 16:16, Pierrick Bouvier wrote:
>>>> Acked-by: Richard Henderson <richard.henderson@linaro.org>
>>>>
>>>> On 2/20/23 12:12, Pierrick Bouvier wrote:
>>>>> Windows implementation of setjmp/longjmp is done in
>>>>> C:/WINDOWS/system32/ucrtbase.dll. Alas, on arm64, it seems to *always*
>>>>> perform stack unwinding, which crashes from generated code.
>>>>>
>>>>> By using alternative implementation built in mingw, we avoid doing 
>>>>> stack
>>>>> unwinding and this fixes crash when calling longjmp.
>>>>>
>>>>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>>>>> ---
>>>>>     include/sysemu/os-win32.h | 25 +++++++++++++++++++++++--
>>>>>     meson.build               | 24 ++++++++++++++++++++++++
>>>>>     2 files changed, 47 insertions(+), 2 deletions(-)


>>>>> -#if defined(_WIN64)
>>>>> +#if defined(__aarch64__)
>>>>> +#ifndef CONFIG_MINGW64_HAS_SETJMP_LONGJMP
>>>>> +#error mingw must provide setjmp/longjmp for windows-arm64
>>
>> Per the meson error [*], this now seems impossible, thus we can
>> simply drop the CONFIG_MINGW64_HAS_SETJMP_LONGJMP definition?
>>
> 
> I think it's redundant too.

>>>>> -#endif
>>>>> +#endif /* __aarch64__ */
>>
>> This comment doesn't seem accurate. Maybe "64-bit"?
>>
> 
> I'd like to use windows-x64. IMHO,  it's clearer and on par with 
> windows-arm64. But I know some people don't like x64 nomenclature.

Fine by me :)



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-02-21 14:28 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-20 11:12 [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64 Pierrick Bouvier
2023-02-20 11:12 ` [PATCH v3 1/4] util/cacheflush: fix cache " Pierrick Bouvier
2023-02-20 15:16   ` Pierrick Bouvier
2023-02-20 11:12 ` [PATCH v3 2/4] sysemu/os-win32: fix setjmp/longjmp " Pierrick Bouvier
2023-02-20 15:16   ` Pierrick Bouvier
2023-02-21  9:47     ` Pierrick Bouvier
2023-02-21 10:33       ` Philippe Mathieu-Daudé
2023-02-21 13:16         ` Pierrick Bouvier
2023-02-21 14:27           ` Philippe Mathieu-Daudé
2023-02-20 11:12 ` [PATCH v3 3/4] qga/vss-win32: fix warning for clang++-15 Pierrick Bouvier
2023-02-20 15:16   ` Pierrick Bouvier
2023-02-21 10:24   ` Philippe Mathieu-Daudé
2023-02-20 11:12 ` [PATCH v3 4/4] target/ppc: fix warning with clang-15 Pierrick Bouvier
2023-02-20 15:16   ` Pierrick Bouvier
2023-02-20 11:33 ` [PATCH v3 0/4] Adds support for running QEMU natively on windows-arm64 Philippe Mathieu-Daudé
2023-02-20 15:10   ` Pierrick Bouvier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).