Commit 5379557b authored by Alexander Graf's avatar Alexander Graf Committed by Riku Voipio

linux-user: fix wait* syscall status returns

When calling wait4 or waitpid with a status pointer and WNOHANG, the
syscall can potentially not modify the status pointer input. Now if we
have guest code like:

  int status = 0;
  waitpid(pid, &status, WNOHANG);
  if (status)
     <breakage>

then we have to make sure that in case status did not change we actually
return the guest's initialized status variable instead of our own uninitialized.
We fail to do so today, as we proxy everything through an uninitialized status
variable which for me ended up always containing the last error code.

This patch fixes some test cases when building yast2-core in OBS for ARM.
Signed-off-by: default avatarAlexander Graf <agraf@suse.de>
Signed-off-by: default avatarRiku Voipio <riku.voipio@linaro.org>
parent 2a7e1245
...@@ -4867,7 +4867,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ...@@ -4867,7 +4867,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
{ {
int status; int status;
ret = get_errno(waitpid(arg1, &status, arg3)); ret = get_errno(waitpid(arg1, &status, arg3));
if (!is_error(ret) && arg2 if (!is_error(ret) && arg2 && ret
&& put_user_s32(host_to_target_waitstatus(status), arg2)) && put_user_s32(host_to_target_waitstatus(status), arg2))
goto efault; goto efault;
} }
...@@ -6423,7 +6423,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, ...@@ -6423,7 +6423,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
rusage_ptr = NULL; rusage_ptr = NULL;
ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr)); ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr));
if (!is_error(ret)) { if (!is_error(ret)) {
if (status_ptr) { if (status_ptr && ret) {
status = host_to_target_waitstatus(status); status = host_to_target_waitstatus(status);
if (put_user_s32(status, status_ptr)) if (put_user_s32(status, status_ptr))
goto efault; goto efault;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment