From nobody Tue Nov 5 08:10:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=mit.edu ARC-Seal: i=1; a=rsa-sha256; t=1670967801; cv=none; d=zohomail.com; s=zohoarc; b=aApBcNKUuVL7n7cfttif61WaMIia9JaUjI5TvxdgMcqQvIMivNQPTFCnxt0lL9pbyxFkpcKnHW0YZiNmw+5z38Nq9nyTId7Jb6I/UspWwJ+bj3UfrNseCKRP6gLaCj+BGXkNRrRP9c0kqqLjTTvf9kYEtmiFTO7rYmMbyd7EVoU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670967801; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7noylMOefmKqet5bCgbsxpsvO0xxjBERKsJphKKHIj4=; b=LZr75fmZox+euqACBi67uQC2TxRuBF02j+SVDGK+WCHphonVOXWGszJfHIu/pBh/rOo2s/2PFPAyo3/N52R9U7Ktvj1sJs7ZmIU8L3Fehg0n9oQ1r8wY3RP8qoS4duyT03LTifEwR88ebziRsL4VhIdVeQ6eD8FwiRAlguXdgmY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167096780166632.34999996426836; Tue, 13 Dec 2022 13:43:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5D0S-0001Uf-As; Tue, 13 Dec 2022 16:40:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5D0E-0001Oj-Jc for qemu-devel@nongnu.org; Tue, 13 Dec 2022 16:39:58 -0500 Received: from outgoing-auth-1.mit.edu ([18.9.28.11] helo=outgoing.mit.edu) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5D0B-0007vA-1E for qemu-devel@nongnu.org; Tue, 13 Dec 2022 16:39:52 -0500 Received: from panda194.. ([18.4.85.108]) (authenticated bits=0) (User authenticated as fasano@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 2BDLcaPE030603 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Dec 2022 16:39:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1670967585; bh=7noylMOefmKqet5bCgbsxpsvO0xxjBERKsJphKKHIj4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OUTJE2uhLQiDrzoJ4UTUMMiZw9eWUYWdkAm9KYbguwCIqCUExPZwzDA+I7dGx8IVj NVC32jzmnFia/8zw2zfMOlxjWE8nYykeirECQWIYhqq5p1hRRmrX3lN3I0VErFEwlS nkz/1tx7pAh4Fg8RGLTqibo385LiUwt6rx0dciV4gN+oVw8Np4ME8/TKURLAuQSlp9 qaZFQWwwVqsCT4tquXN6yEhLBKBRz/hJgri8fDE5evmSGBMmEr1sbRN2op16dyFXZQ RHIgiQX5qbHamJz7/giJGrG+1k4lzFEcDEZcVb1EIB+x5FARTgLSDyeNolBnUUuW8R 3VNjAij9+2O+w== From: Andrew Fasano To: qemu-devel@nongnu.org Cc: elysia.witham@ll.mit.edu, alex.bennee@linaro.org, erdnaxe@crans.org, ma.mandourr@gmail.com, Andrew Fasano Subject: [PATCH 7/8] include/qemu: added macro for QPP import function Date: Tue, 13 Dec 2022 16:37:56 -0500 Message-Id: <20221213213757.4123265-8-fasano@mit.edu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221213213757.4123265-1-fasano@mit.edu> References: <20221213213757.4123265-1-fasano@mit.edu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=18.9.28.11; envelope-from=fasano@mit.edu; helo=outgoing.mit.edu X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @mit.edu) X-ZM-MESSAGEID: 1670967803281100003 Content-Type: text/plain; charset="utf-8" From: Elysia Witham Plugins can use this macro in a header file which can be included by both the exporting and importing plugins. The macro will either use qemu_plugin_import_function to import the function or just define it if the plugin is the same one that exports it. If importing a function, "_qpp" will be appended to the end of the function name. Signed-off-by: Elysia Witham Signed-off-by: Andrew Fasano --- include/qemu/plugin-qpp.h | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 include/qemu/plugin-qpp.h diff --git a/include/qemu/plugin-qpp.h b/include/qemu/plugin-qpp.h new file mode 100644 index 0000000000..7aea98a14d --- /dev/null +++ b/include/qemu/plugin-qpp.h @@ -0,0 +1,54 @@ +#ifndef PLUGIN_QPP_H +#define PLUGIN_QPP_H + +/* + * Facilities for "Plugin to plugin" (QPP) interactions between tcg plugin= s. + * These allows for direct function calls between loaded plugins. For more + * details see docs/devel/plugin.rst. + */ + + +/* + * Internal macros + */ +#define _PLUGIN_STR(s) #s +#define PLUGIN_STR(s) _PLUGIN_STR(s) +#define _PLUGIN_CONCAT(x, y) x##y +#define PLUGIN_CONCAT(x, y) _PLUGIN_CONCAT(x, y) +#define _QPP_SETUP_NAME(fn) PLUGIN_CONCAT(_qpp_setup_, fn) + +/* + * A header file that defines an exported function should use + * the QPP_FUN_PROTOTYPE macro to create the necessary types. + * + * The generated function named after the output of QPP_SETUP_NAME should + * dynamically resolve a target function in another plugin or raise a fatal + * error on failure. This function has the constructor attribute so it will + * run immediately when the plugin shared object object is loaded. + * + * Note that the variable qemu_plugin_name must be set before this macro is + * used. In other words the plugin that includes a header file with these + * macros should set qemu_plugin_name before including such headers. When = the + * generated function is run it compares the current plugin name to the na= me + * of the plugin that provides the target function. + * + * If the target plugin is not the current plugin it will resolve the func= tion + * pointer from qemu_plugin_import_function, correctly cast it, and assign= the + * function pointer "[function_name]_qpp" which can then be used by the pl= ugin + * that imported it. + */ + +#define QPP_FUN_PROTOTYPE(plugin_name, fn_ret, fn, args) = \ + fn_ret fn(args); = \ + typedef fn_ret(*PLUGIN_CONCAT(fn, _t))(args); = \ + fn##_t fn##_qpp; = \ + void _QPP_SETUP_NAME(fn) (void); = \ + = \ + void __attribute__ ((constructor)) _QPP_SETUP_NAME(fn) (void) { = \ + if (strcmp(qemu_plugin_name, #plugin_name) !=3D 0) { = \ + fn##_qpp =3D (fn##_t)qemu_plugin_import_function( = \ + PLUGIN_STR(plugin_na= me),\ + PLUGIN_STR(fn)); = \ + } = \ + } +#endif /* PLUGIN_QPP_H */ --=20 2.34.1