From patchwork Wed Nov 23 20:38:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 127383 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 13B931007D6 for ; Thu, 24 Nov 2011 07:37:41 +1100 (EST) Received: from localhost ([::1]:55302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTJZa-0008Oc-Mf for incoming@patchwork.ozlabs.org; Wed, 23 Nov 2011 15:37:38 -0500 Received: from eggs.gnu.org ([140.186.70.92]:59881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTJZW-0008OK-09 for qemu-devel@nongnu.org; Wed, 23 Nov 2011 15:37:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RTJZU-0006h7-NY for qemu-devel@nongnu.org; Wed, 23 Nov 2011 15:37:33 -0500 Received: from cantor2.suse.de ([195.135.220.15]:48904 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTJZU-0006gw-Iq for qemu-devel@nongnu.org; Wed, 23 Nov 2011 15:37:32 -0500 Received: from relay1.suse.de (nat.nue.novell.com [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 73A958AD27; Wed, 23 Nov 2011 21:37:31 +0100 (CET) From: Alexander Graf To: qemu-devel Developers Date: Wed, 23 Nov 2011 21:38:27 +0100 Message-Id: <1322080707-13527-1-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.7.3.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: riku.voipio@iki.fi Subject: [Qemu-devel] [PATCH] linux-user: fix wait* syscall status returns X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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) 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: Alexander Graf --- linux-user/syscall.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3e6f3bd..f86fe4a 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4833,7 +4833,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #ifdef TARGET_NR_waitpid case TARGET_NR_waitpid: { - int status; + int status = 0; + if (arg2) { + get_user_s32(status, arg2); + } ret = get_errno(waitpid(arg1, &status, arg3)); if (!is_error(ret) && arg2 && put_user_s32(host_to_target_waitstatus(status), arg2)) @@ -6389,6 +6392,9 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, rusage_ptr = &rusage; else rusage_ptr = NULL; + if (status_ptr) { + get_user_s32(status, status_ptr); + } ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr)); if (!is_error(ret)) { if (status_ptr) {