From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 404DDCA9EC5 for ; Wed, 30 Oct 2019 14:52:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EEA862054F for ; Wed, 30 Oct 2019 14:51:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="oot7G9yy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEA862054F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iPpKI-00077f-HB for qemu-devel@archiver.kernel.org; Wed, 30 Oct 2019 10:51:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35234) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iPpIN-0004xC-DL for qemu-devel@nongnu.org; Wed, 30 Oct 2019 10:50:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iPpIL-0007CU-GF for qemu-devel@nongnu.org; Wed, 30 Oct 2019 10:49:59 -0400 Received: from mail-eopbgr800135.outbound.protection.outlook.com ([40.107.80.135]:59246 helo=NAM03-DM3-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iPpIJ-0006yI-Ij for qemu-devel@nongnu.org; Wed, 30 Oct 2019 10:49:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FeivO/zey5xOeKh8CPLZ5VCD+D10ofJ8oC6THE8wED+7zYGbryJuQegM0EAJ+a0/INoPVKDcnDJM4LHcMfN9UbD6IbfLsg5AWwyIN64PlBZixK2ojxMBLoStWXoCnEvmg7gHnvurVAD4XqTVx+8pc8rtYTruaIuFgGhjDHUfXNZU5GUwOlTHAMAvg+ewcXGpwk7PkN6Z1Mxn0rmc5TdSTZCRL+A7ZctOSVrxD9ypITxFKXrZOvffp42MZ/RQlY/gDGGCIKKQsH0ogWrvVfnmDheg8xekqX/mer8fgpLep47N4SFqxi/6umBOYPj5ET6oT5uzI98wGbvODHv3y2/2aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kHDy7oLagDPsTTssPObcI3Mh/tWmTTBlEyX4WTYnM0U=; b=eqO76XPjhFix8E9RwzBGrjnYK8yRJFYCMJK+1Zjm8zHywdtiQrIKvGog4p5wZZUSbAQADihjTqADUfkVggVBnkGzqWkqF6o/NhD0vAkwvUJ1HAdDZ0f++SwSkEIQn3P9eb3Ii3kuEed19PDa5wdYgeaTsP1SKpC1Vq6Fc5FQVanTKsb7yoG1WiungX50k6V/YjWXyGz9jhQDAMCOoYlkjz0icfMGmYqewXqT2Oue5GVfLPLhoOJ5VhVEBabPXAZUI5q26macsFNar/u/a93GKqYcolWrr642M7uNe/2MgI9YuIN+GO4hnpMlm1QfCC47Xb18Dy6LE6+z4Lw9ngM2Vw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kHDy7oLagDPsTTssPObcI3Mh/tWmTTBlEyX4WTYnM0U=; b=oot7G9yyVUgiErkY7yfiq3I9dV7jW5++y6rLmAw9FAsJbwHsFWXJrvPjuYgooCigEQ/m4jDGW10shf9XkWufMVtgRudP8MCY/bvQ+yVm+D2IyHYW4W/aO1lKCJG4NU9FUKu2ya6Dl6MevwPcrUee4L3ANroJgKO5qXRGZQY2U6U= Received: from MN2PR03MB4800.namprd03.prod.outlook.com (20.179.82.78) by MN2PR03MB5054.namprd03.prod.outlook.com (52.132.170.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.17; Wed, 30 Oct 2019 14:49:48 +0000 Received: from MN2PR03MB4800.namprd03.prod.outlook.com ([fe80::344f:b88:26f0:9f66]) by MN2PR03MB4800.namprd03.prod.outlook.com ([fe80::344f:b88:26f0:9f66%7]) with mapi id 15.20.2387.028; Wed, 30 Oct 2019 14:49:48 +0000 From: "Oleinik, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v4 01/20] softmmu: split off vl.c:main() into main.c Thread-Topic: [PATCH v4 01/20] softmmu: split off vl.c:main() into main.c Thread-Index: AQHVjzFGdffDW1ST1UKR7oDR1Qob0Q== Date: Wed, 30 Oct 2019 14:49:48 +0000 Message-ID: <20191030144926.11873-2-alxndr@bu.edu> References: <20191030144926.11873-1-alxndr@bu.edu> In-Reply-To: <20191030144926.11873-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: DM5PR08CA0048.namprd08.prod.outlook.com (2603:10b6:4:60::37) To MN2PR03MB4800.namprd03.prod.outlook.com (2603:10b6:208:101::14) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 163b8c42-1166-4855-ae45-08d75d486950 x-ms-traffictypediagnostic: MN2PR03MB5054: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 02065A9E77 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(366004)(396003)(346002)(136003)(39860400002)(189003)(199004)(2501003)(36756003)(476003)(86362001)(88552002)(386003)(256004)(316002)(14444005)(5640700003)(1076003)(99286004)(6916009)(75432002)(486006)(786003)(11346002)(6506007)(4326008)(54906003)(186003)(2906002)(66946007)(26005)(6116002)(14454004)(446003)(2616005)(6512007)(305945005)(71200400001)(478600001)(71190400001)(81166006)(102836004)(66556008)(64756008)(50226002)(8676002)(81156014)(66446008)(6436002)(2351001)(25786009)(5660300002)(66066001)(52116002)(66476007)(6486002)(3846002)(8936002)(7736002)(76176011); DIR:OUT; SFP:1102; SCL:1; SRVR:MN2PR03MB5054; H:MN2PR03MB4800.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 6zS2Ne2O2x6ri3i+vzS/dbJ/8g92zEuxWHNcnkP1MMdxDMx8yG3Tl6J0ND17KBIocJJMobhb3hw7Gc17iLtIemKEydfYT/ge9dttqS9QXpLTiDcg0BCeybxFPabTZqD5kGJ76dyijOPgGZf0P8P4eFxFpD5TTQsIRpC/f8OqY2Wr3aUOlApPcEx/pXlvsbu34Dnb9l2InyOEOL7S/8DEHJyv/73M9u3QYkNQgcbrJcs/KpR/vzRY6GbGtSR2CeOZ3jsQ0u0r1nTyd2fZnEbQE4zo1qZZgJo7SVvm6Tkp7hDIkGybqcSIglE2vyKV009VpMu1zvFJlzYoln5UX8Sy+FyrwOvaWenGcWgz4kHxS1/FH8+w38OMQ+KvJBSDeuqkNLY+fqwSJiC6+EIHbEW4P1ILin4khMMUagdRbWOCxlxBSAla9TtkeOM3ZBfv8qSn Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 163b8c42-1166-4855-ae45-08d75d486950 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Oct 2019 14:49:48.4067 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: yGmn3YZs621L/1gaZA3wpBqA5Kb7RSI2aiTWqR1JJAd8DBlW8zEPOO9Ip1RlDYmx X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR03MB5054 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.80.135 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Oleinik, Alexander" , Paolo Bonzini Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Alexander Oleinik A program might rely on functions implemented in vl.c, but implement its own main(). By placing main into a separate source file, there are no complaints about duplicate main()s when linking against vl.o. For example, the virtual-device fuzzer uses a main() provided by libfuzzer, and needs to perform some initialization before running the softmmu initialization. Now, main simply calls three vl.c functions which handle the guest initialization, main loop and cleanup. Signed-off-by: Alexander Oleinik --- Makefile | 1 + Makefile.objs | 2 ++ include/sysemu/sysemu.h | 4 ++++ main.c | 52 +++++++++++++++++++++++++++++++++++++++++ vl.c | 36 +++++++--------------------- 5 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 main.c diff --git a/Makefile b/Makefile index 0e994a275d..d2b2ecd3c4 100644 --- a/Makefile +++ b/Makefile @@ -474,6 +474,7 @@ $(SOFTMMU_ALL_RULES): $(crypto-obj-y) $(SOFTMMU_ALL_RULES): $(io-obj-y) $(SOFTMMU_ALL_RULES): config-all-devices.mak $(SOFTMMU_ALL_RULES): $(edk2-decompressed) +$(SOFTMMU_ALL_RULES): $(softmmu-main-y) =20 .PHONY: $(TARGET_DIRS_RULES) # The $(TARGET_DIRS_RULES) are of the form SUBDIR/GOAL, so that diff --git a/Makefile.objs b/Makefile.objs index 11ba1a36bd..9ff9b0c6f9 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -86,6 +86,8 @@ common-obj-$(CONFIG_FDT) +=3D device_tree.o # qapi =20 common-obj-y +=3D qapi/ + +softmmu-main-y =3D main.o endif =20 ####################################################################### diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 44f18eb739..03f9838b81 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -114,6 +114,10 @@ QemuOpts *qemu_get_machine_opts(void); =20 bool defaults_enabled(void); =20 +void main_loop(void); +void qemu_init(int argc, char **argv, char **envp); +void qemu_cleanup(void); + extern QemuOptsList qemu_legacy_drive_opts; extern QemuOptsList qemu_common_drive_opts; extern QemuOptsList qemu_drive_opts; diff --git a/main.c b/main.c new file mode 100644 index 0000000000..ecd6389424 --- /dev/null +++ b/main.c @@ -0,0 +1,52 @@ +/* + * QEMU System Emulator + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY= , + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "sysemu/sysemu.h" + +#ifdef CONFIG_SDL +#if defined(__APPLE__) || defined(main) +#include +int main(int argc, char **argv) +{ + return qemu_main(argc, argv, NULL); +} +#undef main +#define main qemu_main +#endif +#endif /* CONFIG_SDL */ + +#ifdef CONFIG_COCOA +#undef main +#define main qemu_main +#endif /* CONFIG_COCOA */ + +int main(int argc, char **argv, char **envp) +{ + qemu_init(argc, argv, envp); + main_loop(); + qemu_cleanup(); + + return 0; +} diff --git a/vl.c b/vl.c index c389d24b2c..472f09e12a 100644 --- a/vl.c +++ b/vl.c @@ -36,25 +36,6 @@ #include "sysemu/seccomp.h" #include "sysemu/tcg.h" =20 -#ifdef CONFIG_SDL -#if defined(__APPLE__) || defined(main) -#include -int qemu_main(int argc, char **argv, char **envp); -int main(int argc, char **argv) -{ - return qemu_main(argc, argv, NULL); -} -#undef main -#define main qemu_main -#endif -#endif /* CONFIG_SDL */ - -#ifdef CONFIG_COCOA -#undef main -#define main qemu_main -#endif /* CONFIG_COCOA */ - - #include "qemu/error-report.h" #include "qemu/sockets.h" #include "sysemu/accel.h" @@ -1797,7 +1778,7 @@ static bool main_loop_should_exit(void) return false; } =20 -static void main_loop(void) +void main_loop(void) { #ifdef CONFIG_PROFILER int64_t ti; @@ -2824,7 +2805,7 @@ static void user_register_global_props(void) global_init_func, NULL, NULL); } =20 -int main(int argc, char **argv, char **envp) +void qemu_init(int argc, char **argv, char **envp) { int i; int snapshot, linux_boot; @@ -3404,7 +3385,7 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_watchdog: if (watchdog) { error_report("only one watchdog option may be given"); - return 1; + exit(1); } watchdog =3D optarg; break; @@ -4440,7 +4421,7 @@ int main(int argc, char **argv, char **envp) if (vmstate_dump_file) { /* dump and exit */ dump_vmstate_json_to_file(vmstate_dump_file); - return 0; + exit(0); } =20 if (incoming) { @@ -4457,8 +4438,11 @@ int main(int argc, char **argv, char **envp) accel_setup_post(current_machine); os_setup_post(); =20 - main_loop(); + return; +} =20 +void qemu_cleanup(void) +{ gdbserver_cleanup(); =20 /* @@ -4495,6 +4479,4 @@ int main(int argc, char **argv, char **envp) qemu_chr_cleanup(); user_creatable_cleanup(); /* TODO: unref root container, check all devices are ok */ - - return 0; } --=20 2.23.0