From nobody Sat May 10 02:10:54 2025
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=gmail.com
ARC-Seal: i=1; a=rsa-sha256; t=1733480783; cv=none;
	d=zohomail.com; s=zohoarc;
	b=MaKKDKVWzVk9RJFkZ50GK98eXdbFeyXZ+gK3adfS0MAZIs0Yowqgu99ckAUbhjdh6jjcSRvqOHKPVYQQWPGgRpbc46cnz8m3aHUCBlr8GLKq6aeMQCWdnHj5Pngau8vjzCtnsDQqjdfqmo5czlIsTQaV2usP5jivZhpiec+/Vh4=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733480783;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=nbpnqNrG3cFwIZii6c5MquwA7F8Z7zU8w7rRlBPru8Q=;
	b=bFr1XJwJ6CvpA560m8JdZyoW5pmJD5RMT21F9MMbz1gM2XxG5Wv7DtNLubrlUczZrPpEgscKRuHjdwaNBXaxGeuZX3Y0hYSd8tPohew8B6YWQhJ/1saVLBFcM48PsY2/Al2YhFn3QR/Cbx3JKFFFBXVqw19z58HPYc2C7wIsFSc=
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=<rowanbhart@gmail.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733480783546606.3890732650889;
 Fri, 6 Dec 2024 02:26:23 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tJVXL-0006Hz-Qz; Fri, 06 Dec 2024 05:26:17 -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 <rowanbhart@gmail.com>)
 id 1tJVXH-0006Ax-9N
 for qemu-devel@nongnu.org; Fri, 06 Dec 2024 05:26:11 -0500
Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <rowanbhart@gmail.com>)
 id 1tJVXF-0004Re-PW
 for qemu-devel@nongnu.org; Fri, 06 Dec 2024 05:26:11 -0500
Received: by mail-pl1-x62c.google.com with SMTP id
 d9443c01a7336-215348d1977so15196585ad.3
 for <qemu-devel@nongnu.org>; Fri, 06 Dec 2024 02:26:09 -0800 (PST)
Received: from chaos.lan ([50.39.253.148]) by smtp.gmail.com with ESMTPSA id
 d9443c01a7336-215f8e3e452sm25934885ad.43.2024.12.06.02.26.07
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 06 Dec 2024 02:26:07 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1733480768; x=1734085568; darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=nbpnqNrG3cFwIZii6c5MquwA7F8Z7zU8w7rRlBPru8Q=;
 b=afoKekRJH6CkvBylIgDY/ubdr8ZLZ8q8If216Sqyed4iH1RaDQODO438NY3KqrO08i
 BleqbTFI6E3N1MpKAd51M/Vr/0hUbRVlkeWP54a3nXifQcQqV1J/NR/4QXJHxwcNUHEP
 P05yWnZSvnzi2WzYmpp6cilpjz91GWoEsnc4XEfPpoBqPuQ/1IVF/eTVj7EIsZp4nWPe
 IuZLwXLHK0yrtw808mpxwLL5LvdPihzEtWM42OVuQkpG9E/Ky0gqL6Hp7CV4q0cpwHZ+
 L2CxvRlmGyT2qS2ar+8IrPVO7jQcH0xTdNvZH7GgVKD7C3lF9J/Vb3EaS32qRUkQAHbR
 SKXg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733480768; x=1734085568;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=nbpnqNrG3cFwIZii6c5MquwA7F8Z7zU8w7rRlBPru8Q=;
 b=nV44VwmRc+XLcJ8IrAEhHvkHHwGWfuKZxOCSjkolU382PEyI4SnEAx1YCkvg9RoOg+
 rsD+lqWsczxDrzisABjQ7x+g/59ZBTq4oxYgFNhw/2xV+c7pnrTMx2YG0+45M5ruEl51
 kbxn4f8kew1setTjJk0W0iiolmgXtVJ969Gt22Q6SFFtSRHuscxzq7WI7P6+cLplcjXF
 w1EdKcBm8V+bb9Hkvkt2BJPbgMJVau3WYZ7CajQnzO4sSIRIYOfo9v4Ii3cGy+DWmVU8
 H0tay1ZlKUlWCTKppq24Iml1uTWvf7Y6nVhztd0KAaqwXR6WbUFm+wdZ6yp9tVvSSHBy
 4tCw==
X-Gm-Message-State: AOJu0Yz2KouklL6dWy+QUyUqhYRsqKjPQafplLO6z5h2RzylCnh4DhF/
 I2/imt0qR5pFJ59nF1nuqhiw7kj6eCcsPJXHhg2MyiJzBRbux+rU4vn75zurCxY=
X-Gm-Gg: ASbGncuA4TxmE7dYgP2Zb/mq8763KfTjK7iP38BKtRZX6JVJJIhyx/4H75klJfG9f8g
 rNhcrILWeLhsmVBAQ05zUBNMEKnoyni343BMfSdQQigPqoRcozj9w/vCJrW0xpTc8TQ9trZqyWJ
 XqJkx7i0nRqwoLYsrzrY8qOsNHhkKH3YVoDyIGNTU6qmHLbahcaZVtt//Gqbjgo3v1maRno+fId
 DCi2yYpgpglqwoxp9XaNlB9XJwyz9uW1uX7a7K1ZMKotzc=
X-Google-Smtp-Source: 
 AGHT+IEFzBPBAzQVhCv0JdKREivN8znDY8V/NN7F0SmTW+ZrXjCuFu5eUGoI6O3mucXA2ladKaCv+g==
X-Received: by 2002:a17:902:e841:b0:216:1eb9:4a48 with SMTP id
 d9443c01a7336-2161eb94e44mr10657245ad.56.1733480767960;
 Fri, 06 Dec 2024 02:26:07 -0800 (PST)
From: Rowan Hart <rowanbhart@gmail.com>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
 Eduardo Habkost <eduardo@habkost.net>,
 =?UTF-8?q?Alex=20Benn=C3=A9e?= <alex.bennee@linaro.org>,
 Alexandre Iooss <erdnaxe@crans.org>,
 Pierrick Bouvier <pierrick.bouvier@linaro.org>,
 Mahmoud Mandour <ma.mandourr@gmail.com>,
 Paolo Bonzini <pbonzini@redhat.com>,
 =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= <philmd@linaro.org>,
 novafacing <rowanbhart@gmail.com>
Subject: [PATCH v2 1/3] Expose gdb_write_register function to consumers of
 gdbstub
Date: Fri,  6 Dec 2024 02:26:02 -0800
Message-ID: <20241206102605.961658-2-rowanbhart@gmail.com>
X-Mailer: git-send-email 2.46.1
In-Reply-To: <20241206102605.961658-1-rowanbhart@gmail.com>
References: <20241206102605.961658-1-rowanbhart@gmail.com>
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=2607:f8b0:4864:20::62c;
 envelope-from=rowanbhart@gmail.com; helo=mail-pl1-x62c.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=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 @gmail.com)
X-ZM-MESSAGEID: 1733480784175116600
Content-Type: text/plain; charset="utf-8"

From: novafacing <rowanbhart@gmail.com>

Reviewed-by: Alex Benn=C3=A9e <alex.bennee@linaro.org>
---
 gdbstub/gdbstub.c      |  2 +-
 include/exec/gdbstub.h | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c
index b1def7e71d..7d87a3324c 100644
--- a/gdbstub/gdbstub.c
+++ b/gdbstub/gdbstub.c
@@ -536,7 +536,7 @@ int gdb_read_register(CPUState *cpu, GByteArray *buf, i=
nt reg)
     return 0;
 }
=20
-static int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg)
+int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg)
 {
     CPUClass *cc =3D CPU_GET_CLASS(cpu);
     GDBRegisterState *r;
diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h
index d73f424f56..584ed73fc9 100644
--- a/include/exec/gdbstub.h
+++ b/include/exec/gdbstub.h
@@ -118,6 +118,20 @@ const GDBFeature *gdb_find_static_feature(const char *=
xmlname);
  */
 int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
=20
+/**
+ * gdb_write_register() - Write a register associated with a CPU.
+ * @cpu: The CPU associated with the register.
+ * @buf: The buffer that the register contents will be set to.
+ * @reg: The register's number returned by gdb_find_feature_register().
+ *
+ * The size of @buf must be at least the size of the register being
+ * written.
+ *
+ * Return: The number of written bytes, or 0 if an error occurred (for
+ * example, an unknown register was provided).
+ */
+int gdb_write_register(CPUState *cpu, uint8_t *mem_buf, int reg);
+
 /**
  * typedef GDBRegDesc - a register description from gdbstub
  */
--=20
2.46.1
From nobody Sat May 10 02:10:54 2025
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=gmail.com
ARC-Seal: i=1; a=rsa-sha256; t=1733480809; cv=none;
	d=zohomail.com; s=zohoarc;
	b=QtvL3zMoD8vjFqyFp2HmF9P6hPYtfaPLSOxqt+EofXRXIHQvUQjwA+bt0ju+NPSnXPsSbmpVhbNaylU/mHLsoT+vWODp9PXwhHRTHfn7YCNLmuf+KH4s19yuKdTACvogPkPBpX+AWSEgh5nhByGuW1Ekq7Zqxy4iHfWT8ERszC4=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733480809;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=cip0LPHBoehxlgnIZ9C55yYW9ZMranVZsujGiSNdgNE=;
	b=M2KKS1NfJ2+GJ42TzZfrgmcQ1OpqWyAlOCy61JUh8zGb+HKpx45BmczI/tMCKa8nD88ImtQPUJdGVh6/LNVT8Hj7xqJ+mj6I/vfz3Birnl7jW7npjka2XaB39pKTs/36uyufb3rrX0BXti58/QNC+TBXmuQkOlyLgNxFIYWcROQ=
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=<rowanbhart@gmail.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733480809461602.4898414039975;
 Fri, 6 Dec 2024 02:26:49 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tJVXS-0006PK-IW; Fri, 06 Dec 2024 05:26:22 -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 <rowanbhart@gmail.com>)
 id 1tJVXM-0006J6-2C
 for qemu-devel@nongnu.org; Fri, 06 Dec 2024 05:26:17 -0500
Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <rowanbhart@gmail.com>)
 id 1tJVXG-0004Rk-Ed
 for qemu-devel@nongnu.org; Fri, 06 Dec 2024 05:26:15 -0500
Received: by mail-pl1-x632.google.com with SMTP id
 d9443c01a7336-215909152c5so21295055ad.3
 for <qemu-devel@nongnu.org>; Fri, 06 Dec 2024 02:26:10 -0800 (PST)
Received: from chaos.lan ([50.39.253.148]) by smtp.gmail.com with ESMTPSA id
 d9443c01a7336-215f8e3e452sm25934885ad.43.2024.12.06.02.26.08
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 06 Dec 2024 02:26:08 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1733480769; x=1734085569; darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=cip0LPHBoehxlgnIZ9C55yYW9ZMranVZsujGiSNdgNE=;
 b=gtkAnpH11I/6b28KlxQK5ZQ+oqNPx3VWGnCmbxrQGgdONa+1Usf2SncUMW+a64SoTT
 O8+p80HWP7dsmwpJ6IdjHfOEMckvFtt48Zy43zg1PjcaXX9gpo1tLv3nvmbE9w3o7LV2
 dC0pUO1BdiO9lLTAQGoPImxEQj0TpiUXbsr1JpWzynSTAFiuOyAwCBjlhOw99V1u4Ry6
 zoURWXxZ+nRXoISH3VQDHw2VlIfhqj9+pNpmEqtcOPRxJ3wEm2zFyGo+PGaNf6wvA0Ar
 ryoOlJA3QhCq5GQKShngL4/sAWZquKR3/GVAg8rYlLEZf+omFxcfHkzcBbp7zFYehtna
 Ku6g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733480769; x=1734085569;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=cip0LPHBoehxlgnIZ9C55yYW9ZMranVZsujGiSNdgNE=;
 b=jfzhiESYnWkSaAn2q6vXw27UKnvf/kMEu4KK+sGzqQKxNh+urblgtsHTzE4s+Po2QM
 DBNTc6j972irtJ1L3/eZy6BMtpURmwYeTeFupfI8KVpJ5s4PCC4tw3tDpHRm96ClgM6F
 K/t4RjV4HL1x5tNSkh9XR+Pih5WIGG+337d+CZnRSO6QxWmGGeK4rdIIO0Xh93Z0Ta/S
 txTMSxQmNAIaLLgWN2o7bH2+ssqd4KVNopvqYiCTxtOG/BKvNYGpKFLDep70uXMt3VLP
 tl5wjeVXUp7psFGoXL1dvRCDenAzVhaYouftOzaHkyIOzBjGjJuXIu3EBoV74jkU+BzF
 tQxA==
X-Gm-Message-State: AOJu0Yz5MW4lowsrmj2uBMHEVyw0GPQmHfvTnkkB8TigwFWDiplXUWxY
 10aR59gkMEog3zOPEwLh03+pQPpYcdes8J6aKz1q/SWp+XbulXPs0Fazt7Kefo0=
X-Gm-Gg: ASbGncs6RCq6ggMzUtQGHTJknLfGJBYnyCo1hhGa3JeT4fBngeBPbffp3dFiT9mkWRj
 J0vq764FHuPYk1qFn3ZumlTppmOzpnU0UlGljHmvc/eKXgTvbfQGq19gZX+goskxBuj4EBnQifP
 JqJPeYxCTnfmJwgRc6tChflJ5AF2WlR3xJJtsHD233EA900bkNmw60ST3Gm8QEZt1Utw4pJCHQk
 1DbZKHT8aCJRVwX/ZqeZQmB/qRg6bxqwHnJNd0lLrtLKUU=
X-Google-Smtp-Source: 
 AGHT+IH5OZptNUpvHYwfat6OWYw9UvSvjw40F6eztNt9BVHm5n059GPu1DTq/evqqsqEkv+K7Y+JJg==
X-Received: by 2002:a17:902:d4d1:b0:215:8270:77d6 with SMTP id
 d9443c01a7336-21614db0facmr32095465ad.27.1733480768914;
 Fri, 06 Dec 2024 02:26:08 -0800 (PST)
From: Rowan Hart <rowanbhart@gmail.com>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
 Eduardo Habkost <eduardo@habkost.net>,
 =?UTF-8?q?Alex=20Benn=C3=A9e?= <alex.bennee@linaro.org>,
 Alexandre Iooss <erdnaxe@crans.org>,
 Pierrick Bouvier <pierrick.bouvier@linaro.org>,
 Mahmoud Mandour <ma.mandourr@gmail.com>,
 Paolo Bonzini <pbonzini@redhat.com>,
 =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= <philmd@linaro.org>,
 novafacing <rowanbhart@gmail.com>
Subject: [PATCH v2 2/3] Add plugin API functions for register R/W, hwaddr R/W,
 vaddr W
Date: Fri,  6 Dec 2024 02:26:03 -0800
Message-ID: <20241206102605.961658-3-rowanbhart@gmail.com>
X-Mailer: git-send-email 2.46.1
In-Reply-To: <20241206102605.961658-1-rowanbhart@gmail.com>
References: <20241206102605.961658-1-rowanbhart@gmail.com>
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=2607:f8b0:4864:20::632;
 envelope-from=rowanbhart@gmail.com; helo=mail-pl1-x632.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 T_SPF_TEMPERROR=0.01 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=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 @gmail.com)
X-ZM-MESSAGEID: 1733480810583116600
Content-Type: text/plain; charset="utf-8"

From: novafacing <rowanbhart@gmail.com>

---
 include/qemu/qemu-plugin.h | 116 +++++++++++++++++++++++++++++++++----
 plugins/api.c              |  66 ++++++++++++++++++++-
 2 files changed, 168 insertions(+), 14 deletions(-)

diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h
index 0fba36ae02..b812593e7f 100644
--- a/include/qemu/qemu-plugin.h
+++ b/include/qemu/qemu-plugin.h
@@ -65,11 +65,18 @@ typedef uint64_t qemu_plugin_id_t;
  *
  * version 4:
  * - added qemu_plugin_read_memory_vaddr
+ *
+ * version 5:
+ * - added qemu_plugin_write_memory_vaddr
+ * - added qemu_plugin_read_memory_hwaddr
+ * - added qemu_plugin_write_memory_hwaddr
+ * - added qemu_plugin_write_register
+ *
  */
=20
 extern QEMU_PLUGIN_EXPORT int qemu_plugin_version;
=20
-#define QEMU_PLUGIN_VERSION 4
+#define QEMU_PLUGIN_VERSION 5
=20
 /**
  * struct qemu_info_t - system information for plugins
@@ -255,8 +262,6 @@ typedef struct {
  * @QEMU_PLUGIN_CB_R_REGS: callback reads the CPU's regs
  * @QEMU_PLUGIN_CB_RW_REGS: callback reads and writes the CPU's regs
  *
- * Note: currently QEMU_PLUGIN_CB_RW_REGS is unused, plugins cannot change
- * system register state.
  */
 enum qemu_plugin_cb_flags {
     QEMU_PLUGIN_CB_NO_REGS,
@@ -893,6 +898,41 @@ typedef struct {
 QEMU_PLUGIN_API
 GArray *qemu_plugin_get_registers(void);
=20
+/**
+ * qemu_plugin_read_register() - read register for current vCPU
+ *
+ * @handle: a @qemu_plugin_reg_handle handle
+ * @buf: A GByteArray for the data owned by the plugin
+ *
+ * This function is only available in a context that register read access =
is
+ * explicitly requested via the QEMU_PLUGIN_CB_R_REGS flag.
+ *
+ * Returns the size of the read register. The content of @buf is in target=
 byte
+ * order. On failure returns -1.
+ */
+QEMU_PLUGIN_API
+int qemu_plugin_read_register(struct qemu_plugin_register *handle,
+                              GByteArray *buf);
+
+/**
+ * qemu_plugin_write_register() - write register for current vCPU
+ *
+ * @handle: a @qemu_plugin_reg_handle handle
+ * @buf: A GByteArray for the data owned by the plugin
+ *
+ * This function is only available in a context that register write access=
 is
+ * explicitly requested via the QEMU_PLUGIN_CB_W_REGS flag.
+ *
+ * The size of @buf must be at least the size of the requested register.
+ * Attempting to write a register with @buf smaller than the register size
+ * will result in a crash or other undesired behavior.
+ *
+ * Returns the number of bytes written. On failure returns 0.
+ */
+QEMU_PLUGIN_API
+int qemu_plugin_write_register(struct qemu_plugin_register *handle,
+                              GByteArray *buf);
+
 /**
  * qemu_plugin_read_memory_vaddr() - read from memory using a virtual addr=
ess
  *
@@ -916,20 +956,72 @@ bool qemu_plugin_read_memory_vaddr(uint64_t addr,
                                    GByteArray *data, size_t len);
=20
 /**
- * qemu_plugin_read_register() - read register for current vCPU
+ * qemu_plugin_write_memory_vaddr() - write to memory using a virtual addr=
ess
  *
- * @handle: a @qemu_plugin_reg_handle handle
- * @buf: A GByteArray for the data owned by the plugin
+ * @addr: A virtual address to write to=20
+ * @data: A byte array containing the data to write
  *
- * This function is only available in a context that register read access =
is
- * explicitly requested via the QEMU_PLUGIN_CB_R_REGS flag.
+ * The contents of @data will be written to memory starting at the virtual
+ * address @addr.
  *
- * Returns the size of the read register. The content of @buf is in target=
 byte
- * order. On failure returns -1.
+ * This function does not guarantee consistency of writes, nor does it ens=
ure
+ * that pending writes are flushed either before or after the write takes
+ * place, so callers should take care when calling this function in plugin
+ * callbacks to avoid depending on the existence of data written using this
+ * function which may be overwritten afterward.
+ *
+ * Returns true on success and false on failure.
  */
 QEMU_PLUGIN_API
-int qemu_plugin_read_register(struct qemu_plugin_register *handle,
-                              GByteArray *buf);
+bool qemu_plugin_write_memory_vaddr(uint64_t addr,
+                                   GByteArray *data);
+
+/**
+ * qemu_plugin_read_memory_vaddr() - read from memory using a hardware add=
ress
+ *
+ * @addr: A virtual address to read from
+ * @data: A byte array to store data into
+ * @len: The number of bytes to read, starting from @addr
+ *
+ * @len bytes of data is read starting at @addr and stored into @data. If =
@data
+ * is not large enough to hold @len bytes, it will be expanded to the nece=
ssary
+ * size, reallocating if necessary. @len must be greater than 0.
+ *
+ * This function does not ensure writes are flushed prior to reading, so
+ * callers should take care when calling this function in plugin callbacks=
 to
+ * avoid attempting to read data which may not yet be written and should u=
se
+ * the memory callback API instead.
+ *
+ * This function is only valid for softmmu targets.
+ *
+ * Returns true on success and false on failure.
+ */
+QEMU_PLUGIN_API
+bool qemu_plugin_read_memory_hwaddr(uint64_t addr,
+                                   GByteArray *data, size_t len);
+
+/**
+ * qemu_plugin_write_memory_vaddr() - write to memory using a hardware add=
ress
+ *
+ * @addr: A virtual address to write to=20
+ * @data: A byte array containing the data to write
+ *
+ * The contents of @data will be written to memory starting at the hardware
+ * address @addr.
+ *
+ * This function does not guarantee consistency of writes, nor does it ens=
ure
+ * that pending writes are flushed either before or after the write takes
+ * place, so callers should take care when calling this function in plugin
+ * callbacks to avoid depending on the existence of data written using this
+ * function which may be overwritten afterward.
+ *
+ * This function is only valid for softmmu targets.
+ *
+ * Returns true on success and false on failure.
+ */
+QEMU_PLUGIN_API
+bool qemu_plugin_write_memory_hwaddr(uint64_t addr,
+                                   GByteArray *data);
=20
 /**
  * qemu_plugin_scoreboard_new() - alloc a new scoreboard
diff --git a/plugins/api.c b/plugins/api.c
index 24ea64e2de..4a84cf4dfe 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -560,6 +560,24 @@ GArray *qemu_plugin_get_registers(void)
     return create_register_handles(regs);
 }
=20
+int qemu_plugin_read_register(struct qemu_plugin_register *reg, GByteArray=
 *buf)
+{
+    g_assert(current_cpu);
+
+    return gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg) - 1);
+}
+
+int qemu_plugin_write_register(struct qemu_plugin_register *reg, GByteArra=
y *buf)
+{
+    g_assert(current_cpu);
+
+    if (buf->len =3D=3D 0) {
+        return 0;
+    }
+
+    return gdb_write_register(current_cpu, buf->data, GPOINTER_TO_INT(reg)=
 - 1);
+}
+
 bool qemu_plugin_read_memory_vaddr(vaddr addr, GByteArray *data, size_t le=
n)
 {
     g_assert(current_cpu);
@@ -580,13 +598,57 @@ bool qemu_plugin_read_memory_vaddr(vaddr addr, GByteA=
rray *data, size_t len)
     return true;
 }
=20
-int qemu_plugin_read_register(struct qemu_plugin_register *reg, GByteArray=
 *buf)
+bool qemu_plugin_write_memory_vaddr(vaddr addr, GByteArray *data)
 {
     g_assert(current_cpu);
=20
-    return gdb_read_register(current_cpu, buf, GPOINTER_TO_INT(reg) - 1);
+    if (data->len =3D=3D 0) {
+        return false;
+    }
+
+    int result =3D cpu_memory_rw_debug(current_cpu, addr, data->data,
+                                     data->len, true);
+
+    if (result < 0) {
+        return false;
+    }
+
+    return true;
+}
+
+bool qemu_plugin_read_memory_hwaddr(hwaddr addr, GByteArray *data, size_t =
len)
+{
+#ifdef CONFIG_SOFTMMU
+    if (len =3D=3D 0) {
+        return false;
+    }
+
+    g_byte_array_set_size(data, len);
+
+    cpu_physical_memory_rw(addr, data->data, data->len, false);
+
+    return true;
+#else
+    return false;
+#endif
 }
=20
+bool qemu_plugin_write_memory_hwaddr(hwaddr addr, GByteArray *data)
+{
+#ifdef CONFIG_SOFTMMU
+    if (data->len =3D=3D 0) {
+        return false;
+    }
+
+    cpu_physical_memory_rw(addr, data->data, data->len, true);
+
+    return true;
+#else
+    return false;
+#endif
+}
+
+
 struct qemu_plugin_scoreboard *qemu_plugin_scoreboard_new(size_t element_s=
ize)
 {
     return plugin_scoreboard_new(element_size);
--=20
2.46.1
From nobody Sat May 10 02:10:54 2025
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=gmail.com
ARC-Seal: i=1; a=rsa-sha256; t=1733480823; cv=none;
	d=zohomail.com; s=zohoarc;
	b=YFFe/qek9jY4lzE/8/dBBphkSPSYR/bj9CnQ9E48l5VsHYeNu9Iry+gNXUrt1H31OcQVXrqA8b6NTyggoIosoKqEWpOpYVH0zKSUXw9jgsMa3+PUr+P2Qlu2F5YXGOn0jt4+yt3b6W835e9YXFWLvjxIzkNQi988s26IVgCWiOA=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1733480823;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=0gntkKupC4lTPUOVbKLaIg1HZfIBbFfwjMRRBqmCiaE=;
	b=elJf3Fj7ynyZwnLWHMOOV9eS5zztGqyrcKcYMtzjkF1Z7PWPMm33H3eoIrWJ2UZEGtSmmmxUQFm5QRYBWybmF+wy5PMKeCc6oiMRoCeN9GpPAODoNiud0w4SjRnjQwpOdqV3aFhqh18OiDjkVvwPox5Yc6bz5FkEpmiORCJh61Y=
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=<rowanbhart@gmail.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 1733480823027144.1117439603123;
 Fri, 6 Dec 2024 02:27:03 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tJVXR-0006MP-Fx; Fri, 06 Dec 2024 05:26:21 -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 <rowanbhart@gmail.com>)
 id 1tJVXK-0006He-K9
 for qemu-devel@nongnu.org; Fri, 06 Dec 2024 05:26:15 -0500
Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <rowanbhart@gmail.com>)
 id 1tJVXH-0004Rr-TO
 for qemu-devel@nongnu.org; Fri, 06 Dec 2024 05:26:13 -0500
Received: by mail-pf1-x432.google.com with SMTP id
 d2e1a72fcca58-725b3b9fa6cso952255b3a.3
 for <qemu-devel@nongnu.org>; Fri, 06 Dec 2024 02:26:11 -0800 (PST)
Received: from chaos.lan ([50.39.253.148]) by smtp.gmail.com with ESMTPSA id
 d9443c01a7336-215f8e3e452sm25934885ad.43.2024.12.06.02.26.09
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 06 Dec 2024 02:26:09 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1733480770; x=1734085570; darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=0gntkKupC4lTPUOVbKLaIg1HZfIBbFfwjMRRBqmCiaE=;
 b=Tp7pl0B0EwbRZ0DbpwOJKo6qyZX4HUBk4P5PVWOlJYQDEmcSR+gatak0KQSHUdNzK6
 3ZxpTf4XaD32uWoDbDLQ4Nw1q9FAEKtsT3ttryDSLTdhQ8vNPup+eQiNL0mocrFfrcf6
 gvc/pesL39IGjWw82Km5nzBR/2vejL5QhJqYiNc2k7xfn8jgm4IG53it9lhsbhiyqeQx
 xcxVO3/VV4GxBLXKAF6xSbpctAbKGjVN61zMcV+2DZwlkiOb5vB7+2IpT2kjPultWQbO
 E8hrne1GGFkf10DsT0/cYOqILnFxirWlf+YS6DvM7vlY+fl1LboTfC/2iqtWd/d82qHr
 4SZg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1733480770; x=1734085570;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=0gntkKupC4lTPUOVbKLaIg1HZfIBbFfwjMRRBqmCiaE=;
 b=uakLgegXUB9jBh+fboQkdM69NE21TfhWTpD5BEjWNBW8fjf9YCM7pSMvh1Vg8LM3oB
 ZT6MRWyd6CEYDwwvPAqZDAybvdXKN4Sh5W44nylqh+02HaX0rEpq1j4GOgqWeeIRxopb
 6YHEc1lGcuG5TcOFFKQ7WYlmP9jmhrUVkuj8J/qDNuHl4zTRnDkYn/PaFEgbF6mCiaw+
 OnIQiD2YNV75kO8nxR/nalyq7E+JSitXcfwGAS+1gz3PBBFX74n7CVPi7XW/eGLVUizD
 4En606ixpWCixsz49m5iSCt3mRhBBHSHwBV85CsDlyu90Y+411AA8I3R4xgKdAHpmpcf
 w3gQ==
X-Gm-Message-State: AOJu0YwJuojSqHUEXW+Uf22URQCuwc2scaBjx8flmMgrgHb4oo0QH04x
 YQr3ZHHN++MfzOxXv2fg6j6+R4e1Sl+KM1yy3whdWb+4kJhpAn81r9dGg+zGH4E=
X-Gm-Gg: ASbGnct3YgXhsmH3wfPTcsYrcMYPu8lwro6KpmoSYsDv5RpuABICMfB1E76r0yHwz3y
 j6cAog2emC+BKdywRFJdzJ0WYgKu6+Btqdn9povGjgOj5oHzh+Os6S0LLFRPjLp8A/sbZVB5E2E
 nOBsAhEHi5eU5EHAr552LgzeFiTHBu81cr/pp0A4LzQ2nbuhnRfF2ep8bC+EkhsAKuf6Bm1XRLp
 +W385mMRrzs16ph2Ni7O03QFex2BgJ+QVVSh7R8kKsu+sE=
X-Google-Smtp-Source: 
 AGHT+IH1jFb7dB3GAONJHhEZqDpKOW/irqFMks5vvjiJnFhYGJaSnu5R0mfXDHz9+w9zKkKPTUhcZw==
X-Received: by 2002:a17:902:da8f:b0:215:9894:5670 with SMTP id
 d9443c01a7336-21614d44589mr30219005ad.16.1733480769929;
 Fri, 06 Dec 2024 02:26:09 -0800 (PST)
From: Rowan Hart <rowanbhart@gmail.com>
To: qemu-devel@nongnu.org
Cc: Richard Henderson <richard.henderson@linaro.org>,
 Eduardo Habkost <eduardo@habkost.net>,
 =?UTF-8?q?Alex=20Benn=C3=A9e?= <alex.bennee@linaro.org>,
 Alexandre Iooss <erdnaxe@crans.org>,
 Pierrick Bouvier <pierrick.bouvier@linaro.org>,
 Mahmoud Mandour <ma.mandourr@gmail.com>,
 Paolo Bonzini <pbonzini@redhat.com>,
 =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= <philmd@linaro.org>,
 novafacing <rowanbhart@gmail.com>
Subject: [PATCH v2 3/3] Add inject plugin and x86_64 target for the inject
 plugin
Date: Fri,  6 Dec 2024 02:26:04 -0800
Message-ID: <20241206102605.961658-4-rowanbhart@gmail.com>
X-Mailer: git-send-email 2.46.1
In-Reply-To: <20241206102605.961658-1-rowanbhart@gmail.com>
References: <20241206102605.961658-1-rowanbhart@gmail.com>
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=2607:f8b0:4864:20::432;
 envelope-from=rowanbhart@gmail.com; helo=mail-pf1-x432.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=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 @gmail.com)
X-ZM-MESSAGEID: 1733480824404116600
Content-Type: text/plain; charset="utf-8"

From: novafacing <rowanbhart@gmail.com>

---
 tests/tcg/plugins/inject.c       | 206 +++++++++++++++++++++++++++++++
 tests/tcg/plugins/meson.build    |   2 +-
 tests/tcg/x86_64/Makefile.target |   1 +
 tests/tcg/x86_64/inject-target.c |  27 ++++
 4 files changed, 235 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/plugins/inject.c
 create mode 100644 tests/tcg/x86_64/inject-target.c

diff --git a/tests/tcg/plugins/inject.c b/tests/tcg/plugins/inject.c
new file mode 100644
index 0000000000..9edc2cd34e
--- /dev/null
+++ b/tests/tcg/plugins/inject.c
@@ -0,0 +1,206 @@
+/*
+ * Copyright (C) 2024, Rowan Hart <rowanbhart@gmail.com>
+ *
+ * License: GNU GPL, version 2 or later.
+ *   See the COPYING file in the top-level directory.
+ */
+#include "glib.h"
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <qemu-plugin.h>
+
+/*
+ * Specifies a Hypercall for an architecture:
+ *
+ * - Architecture name
+ * - Whether it is enabled
+ * - The hypercall instruction
+ * - The register names to pass the hypercall # and args
+ */
+struct HypercallSpec {
+    const char *name;
+    const bool enabled;
+    const char *hypercall;
+    const bool little_endian;
+    const char *num_reg;
+    const char *arg0_reg;
+    const char *arg1_reg;
+};
+
+static const struct HypercallSpec *hypercall_spec;
+
+static const struct HypercallSpec hypercall_specs[] =3D {
+    { "aarch64", false, NULL, true, 0, 0, 0 },
+    { "aarch64_be", false, NULL, false, 0, 0, 0 },
+    { "alpha", false, NULL, true, 0, 0, 0 },
+    { "arm", false, NULL, true, 0, 0, 0 },
+    { "armeb", false, NULL, false, 0, 0, 0 },
+    { "avr", false, NULL, true, 0, 0, 0 },
+    { "hexagon", false, NULL, true, 0, 0, 0 },
+    { "hppa", false, NULL, false, 0, 0, 0 },
+    { "i386", false, NULL, true, 0, 0, 0 },
+    { "loongarch64", false, NULL, true, 0, 0, 0 },
+    { "m68k", false, NULL, false, 0, 0, 0 },
+    { "microblaze", false, NULL, false, 0, 0, 0 },
+    { "microblazeel", false, NULL, true, 0, 0, 0 },
+    { "mips", false, NULL, false, 0, 0, 0 },
+    { "mips64", false, NULL, false, 0, 0, 0 },
+    { "mips64el", false, NULL, true, 0, 0, 0 },
+    { "mipsel", false, NULL, true, 0, 0, 0 },
+    { "mipsn32", false, NULL, false, 0, 0, 0 },
+    { "mipsn32el", false, NULL, true, 0, 0, 0 },
+    { "or1k", false, NULL, false, 0, 0, 0 },
+    { "ppc", false, NULL, false, 0, 0, 0 },
+    { "ppc64", false, NULL, false, 0, 0, 0 },
+    { "ppc64le", false, NULL, true, 0, 0, 0 },
+    { "riscv32", false, NULL, true, 0, 0, 0 },
+    { "riscv64", false, NULL, true, 0, 0, 0 },
+    { "rx", false, NULL, true, 0, 0, 0 },
+    { "s390x", false, NULL, false, 0, 0, 0 },
+    { "sh4", false, NULL, true, 0, 0, 0 },
+    { "sh4eb", false, NULL, false, 0, 0, 0 },
+    { "sparc", false, NULL, false, 0, 0, 0 },
+    { "sparc32plus", false, NULL, false, 0, 0, 0 },
+    { "sparc64", false, NULL, false, 0, 0, 0 },
+    { "tricore", false, NULL, true, 0, 0, 0 },
+    { "x86_64", true, "\x0f\xa2", true, "rax", "rdi", "rsi" },
+    { "xtensa", false, NULL, true, 0, 0, 0 },
+    { "xtensaeb", false, NULL, false, 0, 0, 0 },
+    { NULL, false, NULL, false, 0, 0, 0 },
+};
+
+QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION;
+
+/*
+ * Returns a handle to a register with a given name, or NULL if there is no
+ * such register.
+ */
+static struct qemu_plugin_register *get_register(const char *name)
+{
+    GArray *registers =3D qemu_plugin_get_registers();
+
+    struct qemu_plugin_register *handle =3D NULL;
+
+    qemu_plugin_reg_descriptor *reg_descriptors =3D
+        (qemu_plugin_reg_descriptor *)registers->data;
+
+    for (size_t i =3D 0; i < registers->len; i++) {
+        if (!strcmp(reg_descriptors[i].name, name)) {
+            handle =3D reg_descriptors[i].handle;
+        }
+    }
+
+    g_array_free(registers, true);
+
+    return handle;
+}
+
+/*
+ * Transforms a byte array with at most 8 entries into a uint64_t
+ * depending on the target machine's endianness.
+ */
+static uint64_t byte_array_to_uint64(GByteArray *buf)
+{
+    uint64_t value =3D 0;
+    if (hypercall_spec->little_endian) {
+        for (int i =3D 0; i < buf->len && i < sizeof(uint64_t); i++) {
+            value |=3D ((uint64_t)buf->data[i]) << (i * 8);
+        }
+    } else {
+        for (int i =3D 0; i < buf->len && i < sizeof(uint64_t); i++) {
+            value |=3D ((uint64_t)buf->data[i]) << ((buf->len - 1 - i) * 8=
);
+        }
+    }
+    return value;
+}
+
+/*
+ * Handle a "hyperacll" instruction, which has some special meaning for th=
is
+ * plugin.
+ */
+static void hypercall(unsigned int vcpu_index, void *userdata)
+{
+    uint64_t num =3D 0, arg0 =3D 0, arg1 =3D 0;
+    GByteArray *buf =3D g_byte_array_new();
+    qemu_plugin_read_register(get_register(hypercall_spec->num_reg), buf);
+    num =3D byte_array_to_uint64(buf);
+
+    g_byte_array_set_size(buf, 0);
+    qemu_plugin_read_register(get_register(hypercall_spec->arg0_reg), buf);
+    arg0 =3D byte_array_to_uint64(buf);
+
+    g_byte_array_set_size(buf, 0);
+    qemu_plugin_read_register(get_register(hypercall_spec->arg1_reg), buf);
+    arg1 =3D byte_array_to_uint64(buf);
+
+    switch (num) {
+    /*
+     * The write hypercall (#0x13371337) tells the plugin to write random =
bytes
+     * of a given size into the memory of the emulated system at a particu=
lar
+     * vaddr
+     */
+    case 0x13371337: {
+        GByteArray *data =3D g_byte_array_new();
+        g_byte_array_set_size(data, arg1);
+        for (uint64_t i =3D 0; i < arg1; i++) {
+            data->data[i] =3D (uint8_t)g_random_int();
+        }
+        qemu_plugin_write_memory_vaddr(arg0, data);
+        break;
+    }
+    default:
+        break;
+    }
+
+    g_byte_array_free(buf, TRUE);
+}
+
+/*
+ * Callback on translation of a translation block.
+ */
+static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
+{
+    for (size_t i =3D 0; i < qemu_plugin_tb_n_insns(tb); i++) {
+        struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i);
+        GByteArray *insn_data =3D g_byte_array_new();
+        size_t insn_len =3D qemu_plugin_insn_size(insn);
+        g_byte_array_set_size(insn_data, insn_len);
+        qemu_plugin_insn_data(insn, insn_data->data, insn_data->len);
+        if (!memcmp(insn_data->data, hypercall_spec->hypercall, insn_data-=
>len)) {
+            qemu_plugin_register_vcpu_insn_exec_cb(insn, hypercall,
+                                                   QEMU_PLUGIN_CB_R_REGS, =
NULL);
+        }
+        g_byte_array_free(insn_data, true);
+    }
+}
+
+
+/*
+ * Called when the plugin is installed
+ */
+QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
+                                           const qemu_info_t *info, int ar=
gc,
+                                           char **argv)
+{
+    hypercall_spec =3D &hypercall_specs[0];
+    while (hypercall_spec->name !=3D NULL) {
+        if (!strcmp(hypercall_spec->name, info->target_name)) {
+            break;
+        }
+        hypercall_spec++;
+    }
+
+    if (hypercall_spec->name =3D=3D NULL) {
+        qemu_plugin_outs("Error: no hypercall spec.");
+        return -1;
+    }
+
+    qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
+
+    return 0;
+}
diff --git a/tests/tcg/plugins/meson.build b/tests/tcg/plugins/meson.build
index f847849b1b..96782416d3 100644
--- a/tests/tcg/plugins/meson.build
+++ b/tests/tcg/plugins/meson.build
@@ -1,6 +1,6 @@
 t =3D []
 if get_option('plugins')
-  foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'syscall']
+  foreach i : ['bb', 'empty', 'inline', 'insn', 'mem', 'syscall', 'inject']
     if host_os =3D=3D 'windows'
       t +=3D shared_module(i, files(i + '.c') + '../../../contrib/plugins/=
win32_linker.c',
                         include_directories: '../../../include/qemu',
diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.t=
arget
index d6dff559c7..7c8e21636d 100644
--- a/tests/tcg/x86_64/Makefile.target
+++ b/tests/tcg/x86_64/Makefile.target
@@ -18,6 +18,7 @@ X86_64_TESTS +=3D adox
 X86_64_TESTS +=3D test-1648
 X86_64_TESTS +=3D test-2175
 X86_64_TESTS +=3D cross-modifying-code
+X86_64_TESTS +=3D inject-target
 TESTS=3D$(MULTIARCH_TESTS) $(X86_64_TESTS) test-x86_64
 else
 TESTS=3D$(MULTIARCH_TESTS)
diff --git a/tests/tcg/x86_64/inject-target.c b/tests/tcg/x86_64/inject-tar=
get.c
new file mode 100644
index 0000000000..c886e5ab8b
--- /dev/null
+++ b/tests/tcg/x86_64/inject-target.c
@@ -0,0 +1,27 @@
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+
+#define hypercall(num, arg0, arg1)                                \
+    unsigned int _a __attribute__((unused)) =3D 0;                  \
+    unsigned int _b __attribute__((unused)) =3D 0;                  \
+    unsigned int _c __attribute__((unused)) =3D 0;                  \
+    unsigned int _d __attribute__((unused)) =3D 0;                  \
+    __asm__ __volatile__("cpuid\n\t"                              \
+                         : "=3Da"(_a), "=3Db"(_b), "=3Dc"(_c), "=3Dd"(_d) \
+                         : "a"(num), "D"(arg0), "S"(arg1));
+
+int main(void)
+{
+    uint16_t value;
+
+    for (size_t i =3D 0; i < 1000000; i++) {
+        hypercall(0x13371337, &value, sizeof(value));
+        if (value =3D=3D 0x1337) {
+            printf("Victory!\n");
+            return 0;
+        }
+    }
+    return 1;
+}
+
--=20
2.46.1