Skip to contentSkip to conversation

New patches for w32, w64

Qemu-devel In review Stefan Weil 5 participants 14 messages Jul 15, 2011 – Aug 21, 2011

lore
Share & tools
lore
#0 lore raw

Here are some small patches needed for the w32 and w64 platforms.

[PATCH 1/3] Fix conversions from pointer to tcg_target_long [PATCH 2/3] w64: Add definition of FMT_pid
[PATCH 3/3] w32: Fix format string regression

Kind regards,
Stefan

#1 lore raw

PATCH 1/3 Fix conversions from pointer to tcg_target_long

tcg_gen_exit_tb takes a parameter of type tcg_target_long, so the type casts of pointer to long should be replaced by type casts of pointer to tcg_target_long.

These changes are needed for build environments where sizeof(long) != sizeof(void *), especially for w64.

See 4b4a72e55660abf7efe85aca78762dcfea5519ad which fixed the same issue for the other targets.

Cc Alexander Graf <[email protected]>
Cc Guan Xuetao <[email protected]>
---
 target-s390x/translate.c     |    2 +-
 target-unicore32/translate.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
target-s390x/translate.c +1 -1
index 77fb448..6a22fde 100644
@@ -830,7 +830,7 @@ static inline void gen_goto_tb(DisasContext *s, int tb_num, target_ulong pc)
         /* jump to same page: we can use a direct jump */
         tcg_gen_goto_tb(tb_num);
         tcg_gen_movi_i64(psw_addr, pc);
-        tcg_gen_exit_tb((long)tb + tb_num);
+        tcg_gen_exit_tb((tcg_target_long)tb + tb_num);
     } else {
         /* jump to another page: currently not optimized */
         tcg_gen_movi_i64(psw_addr, pc);
target-unicore32/translate.c +1 -1
index a15e42d..4ecb0f1 100644
@@ -1056,7 +1056,7 @@ static inline void gen_goto_tb(DisasContext *s, int n, uint32_t dest)
     if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
         tcg_gen_goto_tb(n);
         gen_set_pc_im(dest);
-        tcg_gen_exit_tb((long)tb + n);
+        tcg_gen_exit_tb((tcg_target_long)tb + n);
     } else {
         gen_set_pc_im(dest);
         tcg_gen_exit_tb(0);
Signature · 1 line
1.7.2.5
Acked-by on v1 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] Fix conversions from pointer to tcg_target_long

It's good for unicore32 bit.

Thanks & Regards.

Guan Xuetao

Quoted 44 lines · Stefan Weil

tcg_gen_exit_tb takes a parameter of type tcg_target_long, so the type casts of pointer to long should be replaced by type casts of pointer to tcg_target_long.

These changes are needed for build environments where sizeof(long) != sizeof(void *), especially for w64.

See 4b4a72e55660abf7efe85aca78762dcfea5519ad which fixed the same issue for the other targets.

Cc Alexander Graf <[email protected]>
Cc Guan Xuetao <[email protected]>
---
 target-s390x/translate.c     |    2 +-
 target-unicore32/translate.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
target-s390x/translate.c +1 -1
index 77fb448..6a22fde 100644
@@ -830,7 +830,7 @@ static inline void gen_goto_tb(DisasContext *s, int tb_num, target_ulong pc)
         /* jump to same page: we can use a direct jump */
         tcg_gen_goto_tb(tb_num);
         tcg_gen_movi_i64(psw_addr, pc);
-        tcg_gen_exit_tb((long)tb + tb_num);
+        tcg_gen_exit_tb((tcg_target_long)tb + tb_num);
     } else {
         /* jump to another page: currently not optimized */
         tcg_gen_movi_i64(psw_addr, pc);
target-unicore32/translate.c +1 -1
index a15e42d..4ecb0f1 100644
@@ -1056,7 +1056,7 @@ static inline void gen_goto_tb(DisasContext *s, int n, uint32_t dest)
     if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
         tcg_gen_goto_tb(n);
         gen_set_pc_im(dest);
-        tcg_gen_exit_tb((long)tb + n);
+        tcg_gen_exit_tb((tcg_target_long)tb + n);
     } else {
         gen_set_pc_im(dest);
         tcg_gen_exit_tb(0);
Acked-by on v1 1/3
#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] Fix conversions from pointer to tcg_target_long

In reply to Stefan Weil
Quoted 9 lines · Stefan Weil

tcg_gen_exit_tb takes a parameter of type tcg_target_long, so the type casts of pointer to long should be replaced by type casts of pointer to tcg_target_long.

These changes are needed for build environments where sizeof(long) != sizeof(void *), especially for w64.

See 4b4a72e55660abf7efe85aca78762dcfea5519ad which fixed the same issue for the other targets.

Changes the code to be aligned with the i386 target, so I'm in favor.

Alex

#4 lore raw

PATCH 2/3 w64: Add definition of FMT_pid

In reply to Stefan Weil

For mingw-w64, pid_t is _pid_t which is __int64, so this platform needs its own definition of FMT_pid.

---
 osdep.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
osdep.h +2 -0
index a817017..252d050 100644
@@ -130,6 +130,8 @@ int qemu_madvise(void *addr, size_t len, int advice);
 
 #if defined(__HAIKU__) && defined(__i386__)
 #define FMT_pid "%ld"
+#elif defined(WIN64)
+#define FMT_pid "%" PRId64
 #else
 #define FMT_pid "%d"
 #endif
Signature · 1 line
1.7.2.5
Reviewed-by on v1 2/3
#5 lore raw

Re: [Qemu-devel] [PATCH 2/3] w64: Add definition of FMT_pid

Am 15.07.2011 um 21:38 schrieb Stefan Weil:

Quoted 4 lines

For mingw-w64, pid_t is _pid_t which is __int64, so this platform needs its own definition of FMT_pid.

Ah, that's probably lld then and thus different from the existing definitions.

Andreas

Quoted 20 lines

---
osdep.h | 2 ++

1 files changed, 2 insertions(+), 0 deletions(-)
osdep.h +2 -0
index a817017..252d050 100644
@@ -130,6 +130,8 @@ int qemu_madvise(void *addr, size_t len, int  
 advice);
 
 #if defined(__HAIKU__) && defined(__i386__)
 #define FMT_pid "%ld"
+#elif defined(WIN64)
+#define FMT_pid "%" PRId64
 #else
 #define FMT_pid "%d"

#endif

Signature · 1 line
1.7.2.5
#6 lore raw

PATCH 3/3 w32: Fix format string regression

In reply to Stefan Weil

Commit 953ffe0f935f40c0d6061d69e76e0339393b54f8 introduced FMT_pid which is wrong for w32 and w64 getpid():
those getpid() implementations always return an int value.

---
 os-win32.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
os-win32.c +1 -1
index b6652af..e153058 100644
@@ -258,7 +258,7 @@ int qemu_create_pidfile(const char *filename)
     if (file == INVALID_HANDLE_VALUE) {
         return -1;
     }
-    len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid());
+    len = snprintf(buffer, sizeof(buffer), "%d\n", getpid());
     ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
 		      &overlap, NULL);
     if (ret == 0) {
Signature · 1 line
1.7.2.5
#7 lore raw

Re: [Qemu-devel] [PATCH 3/3] w32: Fix format string regression

Am 15.07.2011 um 21:38 schrieb Stefan Weil:

Quoted 3 lines

Commit 953ffe0f935f40c0d6061d69e76e0339393b54f8 introduced FMT_pid which is wrong for w32 and w64 getpid():
those getpid() implementations always return an int value.

Where is __int64 FMT_pid used then if not for the returned pid?

Andreas

Quoted 23 lines

---
os-win32.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
os-win32.c +1 -1
index b6652af..e153058 100644
@@ -258,7 +258,7 @@ int qemu_create_pidfile(const char *filename)
    if (file == INVALID_HANDLE_VALUE) {
        return -1;
    }
-    len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid());
+    len = snprintf(buffer, sizeof(buffer), "%d\n", getpid());
    ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
 		      &overlap, NULL);
    if (ret == 0) {
Signature · 1 line
1.7.2.5
#8 lore raw

Re: [Qemu-devel] [PATCH 3/3] w32: Fix format string regression

Quoted 5 lines · Andreas Färber

Am 15.07.2011 um 21:38 schrieb Stefan Weil:

Quoted 3 lines

Commit 953ffe0f935f40c0d6061d69e76e0339393b54f8 introduced FMT_pid which is wrong for w32 and w64 getpid():
those getpid() implementations always return an int value.

This is not in line with Posix:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpid.html#tag_16_243

Quoted 1 line

Where is __int64 FMT_pid used then if not for the returned pid?

For shutdown_pid which is pid_t:
src/qemu/vl.c:1200: fprintf(stderr, " from pid " FMT_pid
"\n", shutdown_pid);

Quoted 8 lines

Andreas

Quoted 6 lines

---
os-win32.c |    2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
Quoted 10 lines

os-win32.c int qemu_create_pidfile(const char *filename) · line 261

Quoted 10 lines
os-win32.c +1 -1
index b6652af..e153058 100644
@@ -258,7 +258,7 @@ int qemu_create_pidfile(const char *filename)
    if (file == INVALID_HANDLE_VALUE) {
        return -1;
    }
-    len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid());
+    len = snprintf(buffer, sizeof(buffer), "%d\n", getpid());

Another way would be to cast the result of getpid to pid_t. Then if the buggy getpid() implementations are fixed one day, there will be no truncation.

Quoted 9 lines
Quoted 7 lines
os-win32.c +0 -1
    ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
                      &overlap, NULL);
    if (ret == 0) {
--

1.7.2.5

#9 lore raw

Re: [Qemu-devel] [PATCH 3/3] w32: Fix format string regression

Am 17.07.2011 11:03, schrieb Blue Swirl:

Quoted 8 lines · Andreas Färber
Quoted 4 lines

Am 15.07.2011 um 21:38 schrieb Stefan Weil:

Quoted 3 lines

Commit 953ffe0f935f40c0d6061d69e76e0339393b54f8 introduced FMT_pid which is wrong for w32 and w64 getpid():
those getpid() implementations always return an int value.

This is not in line with Posix:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpid.html#tag_16_243

Maybe I should have added that getpid() is a function in a vendor specific API. Microsoft does not claim that getpid() is in line with Posix
(they say it is a deprecated POSIX function, see
http://msdn.microsoft.com/en-us/library/ms235372%28v=vs.80%29.aspx).

Visual Studio uses this declaration:
_CRT_NONSTDC_DEPRECATE(_getpid) _CRTIMP int __cdecl getpid(void);

Mingw32 tries to be more POSIX like and uses (with pid_t = int) this declaration:
_CRTIMP pid_t __cdecl __MINGW_NOTHROW getpid (void);

Mingw-w64 is closer to the VS declaration:
int __cdecl getpid(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;

The replacement for getpid() is _getpid(). It also has a wrong declaration in mingw32. A patch which simply replaces getpid by _getpid is on my todo list, but not urgent, because the current code works when my patch was applied.

Regards,
Stefan

#10 lore raw

Re: [Qemu-devel] [PATCH 3/3] w32: Fix format string regression

Quoted 28 lines · Stefan Weil

Am 17.07.2011 11:03, schrieb Blue Swirl:

Quoted 6 lines
Quoted 3 lines · Andreas Färber

Am 15.07.2011 um 21:38 schrieb Stefan Weil:

Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

Commit 953ffe0f935f40c0d6061d69e76e0339393b54f8 introduced FMT_pid which is wrong for w32 and w64 getpid():
those getpid() implementations always return an int value.

This is not in line with Posix:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpid.html#tag_16_243

Maybe I should have added that getpid() is a function in a vendor specific API.
Microsoft does not claim that getpid() is in line with Posix (they say it is a deprecated POSIX function, see
http://msdn.microsoft.com/en-us/library/ms235372%28v=vs.80%29.aspx).

Visual Studio uses this declaration:
_CRT_NONSTDC_DEPRECATE(_getpid) _CRTIMP int __cdecl getpid(void);

Mingw32 tries to be more POSIX like and uses (with pid_t = int) this declaration:
_CRTIMP pid_t __cdecl __MINGW_NOTHROW getpid (void);

Quoted 7 lines

Mingw-w64 is closer to the VS declaration:
int __cdecl getpid(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;

The replacement for getpid() is _getpid(). It also has a wrong declaration in mingw32. A patch which simply replaces getpid by _getpid is on my todo list, but not urgent, because the current code works when my patch was applied.

Since for example GetProcessById uses int, it looks like pid_t is instead wrong.

#11 lore raw
In reply to Stefan Weil

Am 15.07.2011 21:38, schrieb Stefan Weil:

Quoted 8 lines

Here are some small patches needed for the w32 and w64 platforms.

[PATCH 1/3] Fix conversions from pointer to tcg_target_long [PATCH 2/3] w64: Add definition of FMT_pid
[PATCH 3/3] w32: Fix format string regression

Kind regards,
Stefan

What about these patches?

Patch 1 was acked by two developers:

    http://patchwork.ozlabs.org/patch/104889/

Patch 2 was review by Andreas:

    http://patchwork.ozlabs.org/patch/104884/

Patch 3 was discussed a lot:

    http://patchwork.ozlabs.org/patch/104885/

At least the first two patches can be applied immediately.

I also think that the third patch is correct and should be applied. It's only MinGW related and fixes a compiler error (regression) there.

Cheers,
Stefan

#12 lore raw
Quoted 16 lines · Stefan Weil

Am 15.07.2011 21:38, schrieb Stefan Weil:

Quoted 9 lines

Here are some small patches needed for the w32 and w64 platforms.

[PATCH 1/3] Fix conversions from pointer to tcg_target_long [PATCH 2/3] w64: Add definition of FMT_pid
[PATCH 3/3] w32: Fix format string regression

Kind regards,
Stefan

What about these patches?

Patch 1 was acked by two developers:
   http://patchwork.ozlabs.org/patch/104889/

Quoted 7 lines

Patch 2 was review by Andreas:
   http://patchwork.ozlabs.org/patch/104884/

Patch 3 was discussed a lot:
   http://patchwork.ozlabs.org/patch/104885/

At least the first two patches can be applied immediately.

Yes.

Quoted 2 lines

I also think that the third patch is correct and should be applied. It's only MinGW related and fixes a compiler error (regression) there.

The interfaces are broken in so many ways that I don't know what is the right fix, maybe introducing qemu_getpid() which always returned pid_t could hide this madness. Then 3/3 would not be needed.

Applied
#13 lore raw
In reply to Stefan Weil

Thanks, applied all.

Quoted 9 lines · Stefan Weil

Here are some small patches needed for the w32 and w64 platforms.

[PATCH 1/3] Fix conversions from pointer to tcg_target_long [PATCH 2/3] w64: Add definition of FMT_pid
[PATCH 3/3] w32: Fix format string regression

Kind regards,
Stefan