From patchwork Tue Jul 3 10:14:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 140945 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp985062ljj; Tue, 3 Jul 2018 03:26:54 -0700 (PDT) X-Google-Smtp-Source: AAOMgpehOJBOMeVYW5p4wPNkCCEurXrAOKvmyHNdLKhkkLzF5cdpHwY/fI485iW27VbSV5Jizjw+ X-Received: by 2002:a37:5944:: with SMTP id n65-v6mr24778138qkb.107.1530613614335; Tue, 03 Jul 2018 03:26:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530613614; cv=none; d=google.com; s=arc-20160816; b=WWzalBFruv/RFbh6OQE5SJjL5Mk/e2XHn8WmV5VEmTpan5sBjhwO9YYAwe1kdlB6R2 snlz/VKtpwcCBBNoYff9L6mWAE8zagCRNI17o7KwqYraxTt1/RMUQpaspcwMZ/028J1P gZc9cKrTmqwLh5ekgTpUvQ6wF0wAF+GB9cqlWp9V2mOAwzbC171k/BYQBY8bebgcdBgb h7r5bEI4DcbZcLuOGizw7eitydrKtaCLjEY+re0SBniS12dW32FD6yRmNRhIyH+5QnNZ M8p4FIac1IogBI1Ed2w2SPgXi7nw1BSP3RXAP4m79SX95gMkw7LOGXzXkqag/wj0Ghj8 wWUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=AfY5DmZl1nsD/9JCMVOXNICjaUk2SH6MlpnIGM/R6mA=; b=nvwScXU6d4NV21Tg7z22sFIrX0v/lOgZFKrdKlfog0RwDrVYKK8J/nCkcP0qvS1ADu Fu0cfq3/s4D183U/X5960OyUvKEKGFXCal/kHeS7m19afqrvK5S2Kqou+3Yy4th3UURh Pw2I9qV8LGrvRNs2IZFvK7sbSuNK/SttMZxCgNjndzkw4lS2Xt8dPJbHAGn1RlWA/ZEv V94RwI/jXayNMnIe+hA6f1JLeunkMjV8bOCQ+bAO5lcyiOswrXdL2jqEBvES5NPFUfQP lwXyaEDWWIXuTqFdXSO70d+tCmM8yWgS9FL1GWOvIYoEv3d2hpWjFEB2dOplrJqELOxu CYrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="cr4Y3TK/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 11-v6si758728qtr.171.2018.07.03.03.26.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 03 Jul 2018 03:26:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="cr4Y3TK/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39418 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faIWL-0007fb-OC for patch@linaro.org; Tue, 03 Jul 2018 06:26:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faIKp-0006r7-7N for qemu-devel@nongnu.org; Tue, 03 Jul 2018 06:15:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faIKn-0008TX-4M for qemu-devel@nongnu.org; Tue, 03 Jul 2018 06:14:59 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:41709) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1faIKm-0008T4-Tw for qemu-devel@nongnu.org; Tue, 03 Jul 2018 06:14:57 -0400 Received: by mail-wr0-x244.google.com with SMTP id h10-v6so1357047wrq.8 for ; Tue, 03 Jul 2018 03:14:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AfY5DmZl1nsD/9JCMVOXNICjaUk2SH6MlpnIGM/R6mA=; b=cr4Y3TK/8IadOC+aBOArAmH+skup2CR5iGiCAnfvBUfJK2N4a8KSJFGj7via+8F0zl 3LTyI0aC65ITJSi3Npuu8ovxrts3bRFp4zy70WVu1KowkarEWLchD7A05MDaMXwTcCNv gnJSvmhJIdxjBIXhJUjwQZBeV3HzC0DFEsgXI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AfY5DmZl1nsD/9JCMVOXNICjaUk2SH6MlpnIGM/R6mA=; b=ZIlM50pcdhRDa0U/QAYsPIIOc44B11O9IzIEHr/c0BC2G1RDg5l9LLmKCjoPVgI+Yv Y29SlriKvwumIrLFpY2znQXLwnYZ88W3Z5y53tFzumx/gzWpajyRT6CnV0K4LpAj2ECI +SFn9u96pKwUuVDJyeIdfWerJDZhX7DNW8Ly5DyQaHSKGSzC4v7+x1GAUDbGu0VZij4M 0iDpbtxt1C67DIvGicx4nBPub175GQXVIEh58vA/5dDoqOG+O4ju73g12xYuVfVnUIy6 MMnQ+kujbz0f0IWZo8ollx6TekSao/ecOvfQKWt1vGJZKMf4dhT9coZEGo1c24+uaq/o 9fJQ== X-Gm-Message-State: APt69E0HnyWJ+zumrk043PqnMVGKHfWaI1VCHdcMfQw0xoTKCz3kiiPt jLOHXkk/mOMnNcGGs/M713JFng== X-Received: by 2002:adf:b964:: with SMTP id b33-v6mr23440546wrg.265.1530612895862; Tue, 03 Jul 2018 03:14:55 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o4-v6sm1163893wmo.20.2018.07.03.03.14.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Jul 2018 03:14:51 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 43D773E075D; Tue, 3 Jul 2018 11:14:45 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Tue, 3 Jul 2018 11:14:33 +0100 Message-Id: <20180703101444.23778-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180703101444.23778-1-alex.bennee@linaro.org> References: <20180703101444.23778-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::244 Subject: [Qemu-devel] [PULL 09/20] linux-user: introduce preexit_cleanup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: agraf@suse.de, =?utf-8?q?Alex_Benn=C3=A9e?= , Riku Voipio , richard.henderson@linaro.org, qemu-devel@nongnu.org, f4bug@amsat.org, cota@braap.org, famz@redhat.com, aurelien@aurel32.net, Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" To avoid repeating ourselves move our preexit clean-up code into a helper function. I figured the continuing effort to split of the syscalls made it worthwhile creating a new file for it now. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Daniel P. Berrangé Reviewed-by: Laurent Vivier -- 2.17.1 diff --git a/linux-user/Makefile.objs b/linux-user/Makefile.objs index 59a5c17354..b5dfb71f25 100644 --- a/linux-user/Makefile.objs +++ b/linux-user/Makefile.objs @@ -1,7 +1,7 @@ obj-y = main.o syscall.o strace.o mmap.o signal.o \ elfload.o linuxload.o uaccess.o uname.o \ safe-syscall.o $(TARGET_ABI_DIR)/signal.o \ - $(TARGET_ABI_DIR)/cpu_loop.o + $(TARGET_ABI_DIR)/cpu_loop.o exit.o obj-$(TARGET_HAS_BFLT) += flatload.o obj-$(TARGET_I386) += vm86.o diff --git a/linux-user/exit.c b/linux-user/exit.c new file mode 100644 index 0000000000..aed8713fae --- /dev/null +++ b/linux-user/exit.c @@ -0,0 +1,28 @@ +/* + * exit support for qemu + * + * Copyright (c) 2018 Alex Bennée + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ +#include "qemu/osdep.h" +#include "qemu.h" + +void preexit_cleanup(CPUArchState *env, int code) +{ +#ifdef TARGET_GPROF + _mcleanup(); +#endif + gdb_exit(env, code); +} diff --git a/linux-user/qemu.h b/linux-user/qemu.h index 793cd4df04..bb85c81aa4 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -623,6 +623,14 @@ static inline int is_error(abi_long ret) return (abi_ulong)ret >= (abi_ulong)(-4096); } +/** + * preexit_cleanup: housekeeping before the guest exits + * + * env: the CPU state + * code: the exit code + */ +void preexit_cleanup(CPUArchState *env, int code); + /* Include target-specific struct and function definitions; * they may need access to the target-independent structures * above, so include them last. diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 2117fb13b4..7c66442357 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8018,10 +8018,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, } cpu_list_unlock(); -#ifdef TARGET_GPROF - _mcleanup(); -#endif - gdb_exit(cpu_env, arg1); + preexit_cleanup(cpu_env, arg1); _exit(arg1); ret = 0; /* avoid warning */ break; @@ -10127,10 +10124,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, #ifdef __NR_exit_group /* new thread calls */ case TARGET_NR_exit_group: -#ifdef TARGET_GPROF - _mcleanup(); -#endif - gdb_exit(cpu_env, arg1); + preexit_cleanup(cpu_env, arg1); ret = get_errno(exit_group(arg1)); break; #endif