summaryrefslogtreecommitdiff
path: root/monitor
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2026-08-28 16:04:33 +0400
committerMarc-André Lureau <marcandre.lureau@redhat.com>2026-08-29 12:07:44 +0400
commitbcf97f76064885730f491b63d4543b60c87c09fd (patch)
tree06e8a3d024ccaf4f471e82bd95b3e1e4957a28b4 /monitor
parent7f01300c044e546f72248e30cb4112472f1c9828 (diff)
downloadqemu-bcf97f76064885730f491b63d4543b60c87c09fd.tar.gz
qemu-bcf97f76064885730f491b63d4543b60c87c09fd.zip
monitor: tighten monitor_set_cpu()/get_cpu()
These functions access mon_cpu_path, which is a MonitorHMP-specific field. Narrowing their signatures from Monitor* to MonitorHMP* makes the type system enforce what was already true at runtime: every caller is in an HMP context. The expression parser's MONITOR_HMP() casts are safe because it is only reachable from handle_hmp_command(), they will be dropped with later patches. Reviewed-by: Dr. David Alan Gilbert <dave@treblig.org> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-ID: <20260828-qemu-no-hmp-v5-36-9227de146347@redhat.com>
Diffstat (limited to 'monitor')
-rw-r--r--monitor/hmp-cmds.c39
-rw-r--r--monitor/hmp.c18
-rw-r--r--monitor/monitor-internal.h2
-rw-r--r--monitor/qmp-cmds.c2
4 files changed, 29 insertions, 32 deletions
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index e2a967516e..89cc19c243 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -182,10 +182,10 @@ void hmp_cpu(MonitorHMP *hmp, const QDict *qdict)
Monitor *mon = MONITOR(hmp);
int64_t cpu_index;
- /* XXX: drop the monitor_set_cpu() usage when all HMP commands that
+ /* XXX: drop the monitor_hmp_set_cpu() usage when all HMP commands that
use it are converted to the QAPI */
cpu_index = qdict_get_int(qdict, "index");
- if (monitor_set_cpu(mon, cpu_index) < 0) {
+ if (monitor_hmp_set_cpu(hmp, cpu_index) < 0) {
monitor_printf(mon, "invalid CPU index\n");
}
}
@@ -512,9 +512,8 @@ void hmp_dumpdtb(MonitorHMP *hmp, const QDict *qdict)
#endif
/* Set the current CPU defined by the user. Callers must hold BQL. */
-int monitor_set_cpu(Monitor *mon, int cpu_index)
+int monitor_hmp_set_cpu(MonitorHMP *hmp, int cpu_index)
{
- MonitorHMP *hmp = MONITOR_HMP(mon);
CPUState *cpu;
cpu = qemu_get_cpu(cpu_index);
@@ -527,9 +526,8 @@ int monitor_set_cpu(Monitor *mon, int cpu_index)
}
/* Callers must hold BQL. */
-static CPUState *mon_get_cpu_sync(Monitor *mon, bool synchronize)
+static CPUState *monitor_hmp_get_cpu_sync(MonitorHMP *hmp, bool synchronize)
{
- MonitorHMP *hmp = MONITOR_HMP(mon);
CPUState *cpu = NULL;
if (hmp->mon_cpu_path) {
@@ -544,7 +542,7 @@ static CPUState *mon_get_cpu_sync(Monitor *mon, bool synchronize)
if (!first_cpu) {
return NULL;
}
- monitor_set_cpu(mon, first_cpu->cpu_index);
+ monitor_hmp_set_cpu(hmp, first_cpu->cpu_index);
cpu = first_cpu;
}
assert(cpu != NULL);
@@ -554,21 +552,21 @@ static CPUState *mon_get_cpu_sync(Monitor *mon, bool synchronize)
return cpu;
}
-CPUState *mon_get_cpu(Monitor *mon)
+CPUState *monitor_hmp_get_cpu(MonitorHMP *hmp)
{
- return mon_get_cpu_sync(mon, true);
+ return monitor_hmp_get_cpu_sync(hmp, true);
}
-CPUArchState *mon_get_cpu_env(Monitor *mon)
+CPUArchState *monitor_hmp_get_cpu_env(MonitorHMP *hmp)
{
- CPUState *cs = mon_get_cpu(mon);
+ CPUState *cs = monitor_hmp_get_cpu(hmp);
return cs ? cpu_env(cs) : NULL;
}
-int monitor_get_cpu_index(Monitor *mon)
+int monitor_hmp_get_cpu_index(MonitorHMP *hmp)
{
- CPUState *cs = mon_get_cpu_sync(mon, false);
+ CPUState *cs = monitor_hmp_get_cpu_sync(hmp, false);
return cs ? cs->cpu_index : UNASSIGNED_CPU_INDEX;
}
@@ -586,7 +584,7 @@ void hmp_info_registers(MonitorHMP *hmp, const QDict *qdict)
cpu_dump_state(cs, NULL, CPU_DUMP_FPU | CPU_DUMP_VPU);
}
} else {
- cs = vcpu >= 0 ? qemu_get_cpu(vcpu) : mon_get_cpu(mon);
+ cs = vcpu >= 0 ? qemu_get_cpu(vcpu) : monitor_hmp_get_cpu(hmp);
if (!cs) {
if (vcpu >= 0) {
@@ -602,13 +600,14 @@ void hmp_info_registers(MonitorHMP *hmp, const QDict *qdict)
}
}
-static void memory_dump(Monitor *mon, int count, int format, int wsize,
+static void memory_dump(MonitorHMP *hmp, int count, int format, int wsize,
uint64_t addr, bool is_physical)
{
+ Monitor *mon = MONITOR(hmp);
int l, line_size, i, max_digits, len;
uint8_t buf[16];
uint64_t v;
- CPUState *cs = mon_get_cpu(mon);
+ CPUState *cs = monitor_hmp_get_cpu(hmp);
const unsigned int addr_width = is_physical ? 8 : (target_long_bits() / 4);
const bool big_endian = target_big_endian();
@@ -712,24 +711,22 @@ static void memory_dump(Monitor *mon, int count, int format, int wsize,
void hmp_memory_dump(MonitorHMP *hmp, const QDict *qdict)
{
- Monitor *mon = MONITOR(hmp);
int count = qdict_get_int(qdict, "count");
int format = qdict_get_int(qdict, "format");
int size = qdict_get_int(qdict, "size");
vaddr addr = qdict_get_int(qdict, "addr");
- memory_dump(mon, count, format, size, addr, false);
+ memory_dump(hmp, count, format, size, addr, false);
}
void hmp_physical_memory_dump(MonitorHMP *hmp, const QDict *qdict)
{
- Monitor *mon = MONITOR(hmp);
int count = qdict_get_int(qdict, "count");
int format = qdict_get_int(qdict, "format");
int size = qdict_get_int(qdict, "size");
hwaddr addr = qdict_get_int(qdict, "addr");
- memory_dump(mon, count, format, size, addr, true);
+ memory_dump(hmp, count, format, size, addr, true);
}
void hmp_gpa2hva(MonitorHMP *hmp, const QDict *qdict)
@@ -757,7 +754,7 @@ void hmp_gva2gpa(MonitorHMP *hmp, const QDict *qdict)
{
Monitor *mon = MONITOR(hmp);
vaddr addr = qdict_get_int(qdict, "addr");
- CPUState *cs = mon_get_cpu(mon);
+ CPUState *cs = monitor_hmp_get_cpu(hmp);
TranslateForDebugResult tres;
if (!cs) {
diff --git a/monitor/hmp.c b/monitor/hmp.c
index 47fb7cef6d..2484a2310d 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -411,10 +411,10 @@ void hmp_help_cmd(Monitor *mon, const char *name)
* Set @pval to the value in the register identified by @name.
* return %true if the register is found, %false otherwise.
*/
-static bool gdb_get_register(Monitor *mon, int64_t *pval, const char *name)
+static bool gdb_get_register(MonitorHMP *hmp, int64_t *pval, const char *name)
{
g_autoptr(GArray) regs = NULL;
- CPUState *cs = mon_get_cpu(mon);
+ CPUState *cs = monitor_hmp_get_cpu(hmp);
if (cs == NULL) {
return false;
@@ -452,7 +452,7 @@ static bool gdb_get_register(Monitor *mon, int64_t *pval, const char *name)
static const char *pch;
static sigjmp_buf expr_env;
-static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name);
+static int get_monitor_def(MonitorHMP *mon, int64_t *pval, const char *name);
static G_NORETURN G_GNUC_PRINTF(2, 3)
void expr_error(Monitor *mon, const char *fmt, ...)
@@ -535,8 +535,8 @@ static int64_t expr_unary(Monitor *mon)
pch++;
}
*q = 0;
- if (!gdb_get_register(mon, &reg, buf)
- && get_monitor_def(mon, &reg, buf) < 0) {
+ if (!gdb_get_register(MONITOR_HMP(mon), &reg, buf)
+ && get_monitor_def(MONITOR_HMP(mon), &reg, buf) < 0) {
expr_error(mon, "unknown register");
}
n = reg;
@@ -1733,9 +1733,9 @@ void monitor_register_hmp_info_hrt(const char *name,
* Set @pval to the value in the register identified by @name.
* return 0 if OK, -1 if not found
*/
-static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
+static int get_monitor_def(MonitorHMP *hmp, int64_t *pval, const char *name)
{
- CPUState *cs = mon_get_cpu(mon);
+ CPUState *cs = monitor_hmp_get_cpu(hmp);
const MonitorDef *md;
void *ptr;
@@ -1750,9 +1750,9 @@ static int get_monitor_def(Monitor *mon, int64_t *pval, const char *name)
for (; md->name != NULL; md++) {
if (hmp_compare_cmd(name, md->name)) {
if (md->get_value) {
- *pval = md->get_value(mon, md, md->offset);
+ *pval = md->get_value(hmp, md, md->offset);
} else {
- CPUArchState *env = mon_get_cpu_env(mon);
+ CPUArchState *env = monitor_hmp_get_cpu_env(hmp);
ptr = (uint8_t *)env + md->offset;
*pval = *(int32_t *)ptr;
}
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index a0fa37c887..afdda13860 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -215,7 +215,7 @@ int monitor_can_read(void *opaque);
void monitor_cancel_out_watch(Monitor *mon);
void monitor_list_append(Monitor *mon);
void monitor_fdsets_cleanup(void);
-int monitor_set_cpu(Monitor *mon, int cpu_index);
+int monitor_hmp_set_cpu(MonitorHMP *mon, int cpu_index);
void qmp_send_response(MonitorQMP *mon, const QDict *rsp);
void monitor_data_destroy_qmp(MonitorQMP *mon);
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 6cb0b587fb..b16119f485 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -169,7 +169,7 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
MonitorHMP *hmp = MONITOR_HMP(object_new(TYPE_MONITOR_HMP));
if (has_cpu_index) {
- int ret = monitor_set_cpu(&hmp->parent_obj, cpu_index);
+ int ret = monitor_hmp_set_cpu(hmp, cpu_index);
if (ret < 0) {
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
"a CPU number");