From patchwork Fri Apr 6 16:35:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 151266 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C16F4B709A for ; Sat, 7 Apr 2012 06:21:55 +1000 (EST) Received: from localhost ([::1]:33997 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SGEUk-0007jf-3h for incoming@patchwork.ozlabs.org; Fri, 06 Apr 2012 15:06:50 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SGCGp-0004Ej-CM for qemu-devel@nongnu.org; Fri, 06 Apr 2012 12:44:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SGCGn-0006gZ-G1 for qemu-devel@nongnu.org; Fri, 06 Apr 2012 12:44:18 -0400 Received: from afflict.kos.to ([92.243.29.197]:59824) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SGC88-0004wK-Jh for qemu-devel@nongnu.org; Fri, 06 Apr 2012 12:35:20 -0400 Received: by afflict.kos.to (Postfix, from userid 1000) id 6596426531; Fri, 6 Apr 2012 16:35:17 +0000 (UTC) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Fri, 6 Apr 2012 19:35:01 +0300 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 X-Mailman-Approved-At: Fri, 06 Apr 2012 15:05:48 -0400 Cc: Fabio Erculiani Subject: [Qemu-devel] [PATCH 01/17] linux-user: improve fake /proc/self/stat making `ps` not segfault. 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: Fabio Erculiani With the current fake /proc/self/stat implementation `ps` is segfaulting because it expects to read PID and argv[0] as first and second field respectively, with the latter being enclosed between backets. Reproducing is as easy as running: `ps` inside qemu-user chroot with /proc mounted. Signed-off-by: Fabio Erculiani Acked-by: Alexander Graf Signed-off-by: Alexander Graf Signed-off-by: Riku Voipio --- linux-user/syscall.c | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 9f5e53a..0e74ee0 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4662,11 +4662,22 @@ static int open_self_stat(void *cpu_env, int fd) int len; uint64_t val = 0; - if (i == 27) { - /* stack bottom */ - val = start_stack; + if (i == 0) { + /* pid */ + val = getpid(); + snprintf(buf, sizeof(buf), "%"PRId64 " ", val); + } else if (i == 1) { + /* app name */ + snprintf(buf, sizeof(buf), "(%s) ", ts->bprm->argv[0]); + } else if (i == 27) { + /* stack bottom */ + val = start_stack; + snprintf(buf, sizeof(buf), "%"PRId64 " ", val); + } else { + /* for the rest, there is MasterCard */ + snprintf(buf, sizeof(buf), "0%c", i == 43 ? '\n' : ' '); } - snprintf(buf, sizeof(buf), "%"PRId64 "%c", val, i == 43 ? '\n' : ' '); + len = strlen(buf); if (write(fd, buf, len) != len) { return -1;