From patchwork Tue Jan 31 09:29:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 138736 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 D5F1F1007D2 for ; Tue, 31 Jan 2012 20:58:43 +1100 (EST) Received: from localhost ([::1]:48845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsA2g-0005st-Cj for incoming@patchwork.ozlabs.org; Tue, 31 Jan 2012 04:30:22 -0500 Received: from eggs.gnu.org ([140.186.70.92]:58197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsA1y-0004GE-3c for qemu-devel@nongnu.org; Tue, 31 Jan 2012 04:29:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RsA1r-0002cB-7p for qemu-devel@nongnu.org; Tue, 31 Jan 2012 04:29:38 -0500 Received: from afflict.kos.to ([92.243.29.197]:37254) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsA1r-0002bS-1s for qemu-devel@nongnu.org; Tue, 31 Jan 2012 04:29:31 -0500 Received: by afflict.kos.to (Postfix, from userid 1000) id B54EB26538; Tue, 31 Jan 2012 09:29:28 +0000 (UTC) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Tue, 31 Jan 2012 11:29:20 +0200 Message-Id: X-Mailer: git-send-email 1.7.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 92.243.29.197 Cc: Alexander Graf Subject: [Qemu-devel] [PATCH 11/19] 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 From: Alexander Graf 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 Signed-off-by: Riku Voipio --- linux-user/syscall.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 29d92c4..06b19e0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4867,7 +4867,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, { int status; 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)) goto efault; } @@ -6423,7 +6423,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, rusage_ptr = NULL; ret = get_errno(wait4(arg1, &status, arg3, rusage_ptr)); if (!is_error(ret)) { - if (status_ptr) { + if (status_ptr && ret) { status = host_to_target_waitstatus(status); if (put_user_s32(status, status_ptr)) goto efault;