qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken
@ 2020-11-30  0:12 Dilfridge
  2020-12-05  1:27 ` [Bug 1906193] " Andreas K. Hüttel
                   ` (12 more replies)
  0 siblings, 13 replies; 15+ messages in thread
From: Dilfridge @ 2020-11-30  0:12 UTC (permalink / raw)
  To: qemu-devel

Public bug reported:

When running in a chroot with riscv32 (on x86_64; qemu git master as of
today):

The following short program forks; the child immediately returns with
exit(42). The parent checks for the return value - and obtains 40!

gcc-10.2

===============================================
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>

main(c, v)
     int c;
     char **v;
{
  pid_t pid, p;
  int s, i, n;

  s = 0;
  pid = fork();
  if (pid == 0)
    exit(42);

  /* wait for the process */
  p = wait(&s);
  if (p != pid)
    exit (255);

  if (WIFEXITED(s))
  {
     int r=WEXITSTATUS(s);
     if (r!=42) {
      printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
     }
  }
}
===============================================

(riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

===============================================
(riscv-ilp32 chroot) farino /tmp # gcc --version
gcc (Gentoo 10.2.0-r1 p2) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

(riscv-ilp32 chroot) farino /tmp # ld --version
GNU ld (Gentoo 2.34 p6) 2.34.0
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

** Affects: qemu
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  New

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
@ 2020-12-05  1:27 ` Andreas K. Hüttel
  2020-12-15 22:06 ` Andreas K. Hüttel
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Andreas K. Hüttel @ 2020-12-05  1:27 UTC (permalink / raw)
  To: qemu-devel

This is the (statically linked) binary resulting from the source; with
it the problem can be demonstrated "standalone", without any other rv32
libraries or a complete chroot, just running the binary with qemu-
riscv32.

Generated with

(riscv-ilp32 chroot) farino /tmp # gcc -static -o wait-test-short -g
wait-test-short.c


** Attachment added: "wait-test-short"
   https://bugs.launchpad.net/qemu/+bug/1906193/+attachment/5441136/+files/wait-test-short

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  New

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
  2020-12-05  1:27 ` [Bug 1906193] " Andreas K. Hüttel
@ 2020-12-15 22:06 ` Andreas K. Hüttel
  2020-12-16 20:56 ` Andreas K. Hüttel
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Andreas K. Hüttel @ 2020-12-15 22:06 UTC (permalink / raw)
  To: qemu-devel

I can confirm that the same binary works fine with qemu system
emulation:

(riscv-ilp32 qemu) (none) /tmp # ./wait-test-short 
(riscv-ilp32 qemu) (none) /tmp #

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  New

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
  2020-12-05  1:27 ` [Bug 1906193] " Andreas K. Hüttel
  2020-12-15 22:06 ` Andreas K. Hüttel
@ 2020-12-16 20:56 ` Andreas K. Hüttel
  2020-12-16 21:05 ` Andreas K. Hüttel
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Andreas K. Hüttel @ 2020-12-16 20:56 UTC (permalink / raw)
  To: qemu-devel

Here's the (abbreviated) output of strace'ing qemu:

farino ~ # strace -f /usr/bin/qemu-riscv32 /chroot/riscv-ilp32/tmp/wait-test-short
execve("/usr/bin/qemu-riscv32", ["/usr/bin/qemu-riscv32", "/chroot/riscv-ilp32/tmp/wait-tes"...], 0x7ffd95fb1330 /* 40 vars */) = 0

[...]

[pid 16569] uname({sysname="Linux", nodename="farino", ...}) = 0
[pid 16569] lstat("/chroot", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
[pid 16569] lstat("/chroot/riscv-ilp32", {st_mode=S_IFDIR|S_ISGID|0755, st_size=4096, ...}) = 0
[pid 16569] lstat("/chroot/riscv-ilp32/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=4096, ...}) = 0
[pid 16569] lstat("/chroot/riscv-ilp32/tmp/wait-test-short", {st_mode=S_IFREG|0755, st_size=445632, ...}) = 0
[pid 16569] mmap(0x413f1000, 135168, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x413f1000
[pid 16569] mprotect(0x413eb000, 8192, PROT_READ) = 0
[pid 16569] rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0
[pid 16569] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x1339710) = 16571
strace: Process 16571 attached
[pid 16571] set_robust_list(0x1339720, 24 <unfinished ...>
[pid 16569] rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0
[pid 16571] <... set_robust_list resumed>) = 0
[pid 16569] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 16571] rt_sigprocmask(SIG_SETMASK, ~[ILL FPE SEGV RTMIN RT_1], ~[KILL STOP RTMIN RT_1], 8) = 0
[pid 16571] rt_sigprocmask(SIG_BLOCK, ~[], ~[ILL FPE KILL SEGV STOP RTMIN RT_1], 8) = 0
[pid 16571] clone(child_stack=0x7fe5b73871f0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tid=[16572], tls=0x7fe5b7387640, child_tidptr=0x7fe5b7387910) = 16572
[pid 16571] rt_sigprocmask(SIG_SETMASK, ~[ILL FPE KILL SEGV STOP RTMIN RT_1], NULL, 8) = 0
[pid 16571] rt_sigprocmask(SIG_SETMASK, ~[KILL STOP RTMIN RT_1], NULL, 8) = 0
[pid 16571] gettid()                    = 16571
[pid 16571] rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], NULL, 8) = 0
[pid 16571] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 16569] waitid(P_ALL, -1,  <unfinished ...>
[pid 16571] exit_group(42)              = ?
strace: Process 16572 attached
[pid 16572] +++ exited with 42 +++
[pid 16571] +++ exited with 42 +++
[pid 16569] <... waitid resumed>{si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=16571, si_uid=0, si_status=42, si_utime=3472328296226648184, si_stime=3475143045726351408}, WEXITED, NULL) = 0
[pid 16569] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=16571, si_uid=0, si_status=42, si_utime=0, si_stime=0} ---
[pid 16569] statx(1, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_BASIC_STATS, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFCHR|0600, stx_size=0, ...}) = 0
[pid 16569] write(1, "child wants to return 42 (0x2A),"..., 74child wants to return 42 (0x2A), parent received 40 (0x28), difference -2
) = 74
[pid 16569] brk(0x13c1000)              = 0x13c1000
[pid 16569] brk(0x13c0000)              = 0x13c0000
[pid 16569] exit_group(0)               = ?
[pid 16570] <... futex resumed>)        = ?
[pid 16570] +++ exited with 0 +++
+++ exited with 0 +++

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  New

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
                   ` (2 preceding siblings ...)
  2020-12-16 20:56 ` Andreas K. Hüttel
@ 2020-12-16 21:05 ` Andreas K. Hüttel
  2020-12-19 18:16 ` Alistair Francis
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Andreas K. Hüttel @ 2020-12-16 21:05 UTC (permalink / raw)
  To: qemu-devel

Here's qemu's own strace log:

farino ~ # /usr/bin/qemu-riscv32 -strace /chroot/riscv-ilp32/tmp/wait-test-short
10123 brk(NULL) = 0x00073000
10123 brk(0x00073880) = 0x00073880
10123 uname(0x407ffed8) = 0
10123 readlinkat(AT_FDCWD,"/proc/self/exe",0x407feff0,4096) = 39
10123 brk(0x00094880) = 0x00094880
10123 brk(0x00095000) = 0x00095000
10123 mprotect(0x0006e000,8192,PROT_READ) = 0
10123 clone(CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|0x11,child_stack=0x00000000,parent_tidptr=0x00000000,tls=0x00000000,child_tidptr=0x00073068) = 10125
10123 clone(CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|0x11,child_stack=0x00000000,parent_tidptr=0x00000000,tls=0x00000000,child_tidptr=0x00073068) = 0
10125 exit_group(42)
10123 waitid(0,-1,0x407fff8c,0x4) = 0
10123 statx(1,"",AT_EMPTY_PATH,STATX_BASIC_STATS,0x407ff8e8) = 0
child wants to return 42 (0x2A), parent received 40 (0x28), difference -2
10123 write(1,0x73ad0,74) = 74
10123 exit_group(0)

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  New

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
                   ` (3 preceding siblings ...)
  2020-12-16 21:05 ` Andreas K. Hüttel
@ 2020-12-19 18:16 ` Alistair Francis
  2020-12-19 23:21 ` Andreas K. Hüttel
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Alistair Francis @ 2020-12-19 18:16 UTC (permalink / raw)
  To: qemu-devel

I have sent a patch, you can see it here:
https://patchwork.ozlabs.org/project/qemu-devel/list/?series=221381

It seems like QEMU's waitid implementation has a bug with handling the
status.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  New

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
                   ` (4 preceding siblings ...)
  2020-12-19 18:16 ` Alistair Francis
@ 2020-12-19 23:21 ` Andreas K. Hüttel
  2020-12-21 13:28 ` Andreas K. Hüttel
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Andreas K. Hüttel @ 2020-12-19 23:21 UTC (permalink / raw)
  To: qemu-devel

Thanks a lot! Will test and post the result on monday when I'm back
home.

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  New

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
                   ` (5 preceding siblings ...)
  2020-12-19 23:21 ` Andreas K. Hüttel
@ 2020-12-21 13:28 ` Andreas K. Hüttel
  2020-12-21 21:44   ` Alistair Francis
  2020-12-21 23:11 ` Richard Henderson
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 15+ messages in thread
From: Andreas K. Hüttel @ 2020-12-21 13:28 UTC (permalink / raw)
  To: qemu-devel

After applying this patch on top of qemu-5.2.0, I can confirm that it
fixes the problem.

Thank you!!

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  New

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* Re: [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-12-21 13:28 ` Andreas K. Hüttel
@ 2020-12-21 21:44   ` Alistair Francis
  0 siblings, 0 replies; 15+ messages in thread
From: Alistair Francis @ 2020-12-21 21:44 UTC (permalink / raw)
  To: Bug 1906193; +Cc: qemu-devel@nongnu.org Developers

Great! Thanks for testing that.

Do you mind supplying a Tested-by tag that I can apply to the patch?

Alistair

On Mon, Dec 21, 2020 at 5:36 AM Andreas K. Hüttel
<1906193@bugs.launchpad.net> wrote:
>
> After applying this patch on top of qemu-5.2.0, I can confirm that it
> fixes the problem.
>
> Thank you!!
>
> --
> You received this bug notification because you are a member of qemu-
> devel-ml, which is subscribed to QEMU.
> https://bugs.launchpad.net/bugs/1906193
>
> Title:
>   riscv32 user mode emulation: fork return values broken
>
> Status in QEMU:
>   New
>
> Bug description:
>   When running in a chroot with riscv32 (on x86_64; qemu git master as
>   of today):
>
>   The following short program forks; the child immediately returns with
>   exit(42). The parent checks for the return value - and obtains 40!
>
>   gcc-10.2
>
>   ===============================================
>   #include <stdlib.h>
>   #include <unistd.h>
>   #include <stdio.h>
>   #include <sys/wait.h>
>
>   main(c, v)
>        int c;
>        char **v;
>   {
>     pid_t pid, p;
>     int s, i, n;
>
>     s = 0;
>     pid = fork();
>     if (pid == 0)
>       exit(42);
>
>     /* wait for the process */
>     p = wait(&s);
>     if (p != pid)
>       exit (255);
>
>     if (WIFEXITED(s))
>     {
>        int r=WEXITSTATUS(s);
>        if (r!=42) {
>         printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
>        }
>     }
>   }
>   ===============================================
>
>   (riscv-ilp32 chroot) farino /tmp # ./wait-test-short
>   child wants to return 42 (0x2A), parent received 40 (0x28), difference -2
>
>   ===============================================
>   (riscv-ilp32 chroot) farino /tmp # gcc --version
>   gcc (Gentoo 10.2.0-r1 p2) 10.2.0
>   Copyright (C) 2020 Free Software Foundation, Inc.
>   Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
>   gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.
>
>   (riscv-ilp32 chroot) farino /tmp # ld --version
>   GNU ld (Gentoo 2.34 p6) 2.34.0
>   Copyright (C) 2020 Free Software Foundation, Inc.
>   This program is free software; you may redistribute it under the terms of
>   the GNU General Public License version 3 or (at your option) a later version.
>   This program has absolutely no warranty.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions
>


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
                   ` (6 preceding siblings ...)
  2020-12-21 13:28 ` Andreas K. Hüttel
@ 2020-12-21 23:11 ` Richard Henderson
  2020-12-26 17:53 ` Andreas K. Hüttel
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Richard Henderson @ 2020-12-21 23:11 UTC (permalink / raw)
  To: qemu-devel

** Changed in: qemu
       Status: New => Confirmed

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  Confirmed

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
                   ` (7 preceding siblings ...)
  2020-12-21 23:11 ` Richard Henderson
@ 2020-12-26 17:53 ` Andreas K. Hüttel
  2021-01-15 23:10 ` Alistair Francis
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Andreas K. Hüttel @ 2020-12-26 17:53 UTC (permalink / raw)
  To: qemu-devel

Just as a general remark, while this specific problem seems to be
solved, there may still be issues surrounding waitid().

(With this patch applied, in a rather complex environment I see bash
processes hanging in an infinite loop, with waitid involved. I am
working on isolating the problem and providing a simple test case, but
so far I have not even found the code triggering it.)

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  Confirmed

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
                   ` (8 preceding siblings ...)
  2020-12-26 17:53 ` Andreas K. Hüttel
@ 2021-01-15 23:10 ` Alistair Francis
  2021-01-16 18:58 ` Andreas K. Hüttel
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 15+ messages in thread
From: Alistair Francis @ 2021-01-15 23:10 UTC (permalink / raw)
  To: qemu-devel

Can you add a Tested-by: tag to the patch?

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  Confirmed

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
                   ` (9 preceding siblings ...)
  2021-01-15 23:10 ` Alistair Francis
@ 2021-01-16 18:58 ` Andreas K. Hüttel
  2021-02-16 20:58 ` Alistair Francis
  2021-04-30  8:57 ` Thomas Huth
  12 siblings, 0 replies; 15+ messages in thread
From: Andreas K. Hüttel @ 2021-01-16 18:58 UTC (permalink / raw)
  To: qemu-devel

Done (took a while to figure out how...)

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  Confirmed

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
                   ` (10 preceding siblings ...)
  2021-01-16 18:58 ` Andreas K. Hüttel
@ 2021-02-16 20:58 ` Alistair Francis
  2021-04-30  8:57 ` Thomas Huth
  12 siblings, 0 replies; 15+ messages in thread
From: Alistair Francis @ 2021-02-16 20:58 UTC (permalink / raw)
  To: qemu-devel

A fix has been merged into master.

** Changed in: qemu
       Status: Confirmed => Fix Committed

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  Fix Committed

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

* [Bug 1906193] Re: riscv32 user mode emulation: fork return values broken
  2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
                   ` (11 preceding siblings ...)
  2021-02-16 20:58 ` Alistair Francis
@ 2021-04-30  8:57 ` Thomas Huth
  12 siblings, 0 replies; 15+ messages in thread
From: Thomas Huth @ 2021-04-30  8:57 UTC (permalink / raw)
  To: qemu-devel

** Changed in: qemu
       Status: Fix Committed => Fix Released

-- 
You received this bug notification because you are a member of qemu-
devel-ml, which is subscribed to QEMU.
https://bugs.launchpad.net/bugs/1906193

Title:
  riscv32 user mode emulation: fork return values broken

Status in QEMU:
  Fix Released

Bug description:
  When running in a chroot with riscv32 (on x86_64; qemu git master as
  of today):

  The following short program forks; the child immediately returns with
  exit(42). The parent checks for the return value - and obtains 40!

  gcc-10.2

  ===============================================
  #include <stdlib.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <sys/wait.h>

  main(c, v)
       int c;
       char **v;
  {
    pid_t pid, p;
    int s, i, n;

    s = 0;
    pid = fork();
    if (pid == 0)
      exit(42);

    /* wait for the process */
    p = wait(&s);
    if (p != pid)
      exit (255);

    if (WIFEXITED(s))
    {
       int r=WEXITSTATUS(s);
       if (r!=42) {
        printf("child wants to return %i (0x%X), parent received %i (0x%X), difference %i\n",42,42,r,r,r-42);
       }
    }
  }
  ===============================================

  (riscv-ilp32 chroot) farino /tmp # ./wait-test-short 
  child wants to return 42 (0x2A), parent received 40 (0x28), difference -2

  ===============================================
  (riscv-ilp32 chroot) farino /tmp # gcc --version
  gcc (Gentoo 10.2.0-r1 p2) 10.2.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  Dies ist freie Software; die Kopierbedingungen stehen in den Quellen. Es
  gibt KEINE Garantie; auch nicht für MARKTGÄNGIGKEIT oder FÜR SPEZIELLE ZWECKE.

  (riscv-ilp32 chroot) farino /tmp # ld --version
  GNU ld (Gentoo 2.34 p6) 2.34.0
  Copyright (C) 2020 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License version 3 or (at your option) a later version.
  This program has absolutely no warranty.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1906193/+subscriptions


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

end of thread, other threads:[~2021-04-30  9:22 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-30  0:12 [Bug 1906193] [NEW] riscv32 user mode emulation: fork return values broken Dilfridge
2020-12-05  1:27 ` [Bug 1906193] " Andreas K. Hüttel
2020-12-15 22:06 ` Andreas K. Hüttel
2020-12-16 20:56 ` Andreas K. Hüttel
2020-12-16 21:05 ` Andreas K. Hüttel
2020-12-19 18:16 ` Alistair Francis
2020-12-19 23:21 ` Andreas K. Hüttel
2020-12-21 13:28 ` Andreas K. Hüttel
2020-12-21 21:44   ` Alistair Francis
2020-12-21 23:11 ` Richard Henderson
2020-12-26 17:53 ` Andreas K. Hüttel
2021-01-15 23:10 ` Alistair Francis
2021-01-16 18:58 ` Andreas K. Hüttel
2021-02-16 20:58 ` Alistair Francis
2021-04-30  8:57 ` Thomas Huth

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).