Commit 203f37210a for qemu.org
commit 203f37210a57fd1f1f51c355caf9aca7ed5babc8
Author: Matheus Tavares Bernardino <matheus.bernardino@oss.qualcomm.com>
Date: Mon Aug 24 08:58:18 2026 -0700
semihosting: add ftruncate helper (to be used for hexagon)
The common semihosting syscall layer has no ftruncate
helper, but the Hexagon semihosting ABI includes an FTRUNC
operation. Add semihost_sys_ftruncate() so that Hexagon
can delegate to it rather than calling ftruncate directly.
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>
Signed-off-by: Matheus Tavares Bernardino <matheus.bernardino@oss.qualcomm.com>
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h
index 03aa45b7bb..3919ab64c7 100644
--- a/include/semihosting/syscalls.h
+++ b/include/semihosting/syscalls.h
@@ -75,4 +75,6 @@ void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete,
void semihost_sys_poll_one(CPUState *cs, gdb_syscall_complete_cb complete,
int fd, GIOCondition cond, int timeout);
+void semihost_sys_ftruncate(CPUState *cs, gdb_syscall_complete_cb complete,
+ int fd, off_t len);
#endif /* SEMIHOSTING_SYSCALLS_H */
diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c
index 20f155f869..0456db0bef 100644
--- a/semihosting/syscalls.c
+++ b/semihosting/syscalls.c
@@ -8,10 +8,12 @@
#include "qemu/osdep.h"
#include "qemu/log.h"
+#include "qemu/error-report.h"
#include "gdbstub/syscalls.h"
#include "semihosting/guestfd.h"
#include "semihosting/syscalls.h"
#include "semihosting/console.h"
+#include "semihosting/semihost.h"
#ifdef CONFIG_USER_ONLY
#include "qemu.h"
#else
@@ -541,6 +543,13 @@ static void host_poll_one(CPUState *cs, gdb_syscall_complete_cb complete,
}
#endif
+static void host_ftruncate(CPUState *cs, gdb_syscall_complete_cb complete,
+ GuestFD *gf, off_t len)
+{
+ int err = ftruncate(gf->hostfd, len);
+ complete(cs, err, err < 0 ? errno : 0);
+}
+
/*
* Static file semihosting syscall implementations.
*/
@@ -982,3 +991,23 @@ void semihost_sys_poll_one(CPUState *cs, gdb_syscall_complete_cb complete,
}
}
#endif
+
+void semihost_sys_ftruncate(CPUState *cs, gdb_syscall_complete_cb complete,
+ int fd, off_t len)
+{
+ GuestFD *gf = get_guestfd(fd);
+ if (!gf) {
+ complete(cs, -1, EBADF);
+ return;
+ }
+
+ switch (gf->type) {
+ case GuestFDHost:
+ host_ftruncate(cs, complete, gf, len);
+ break;
+ default:
+ error_report("ftruncate call not implemented "
+ "for this semihosting mode.");
+ g_assert_not_reached();
+ }
+}