On 9/28/2026 5:14 AM, Peter Maydell wrote:
On Wed, 23 Sept 2026 at 16:35, Brian Cain <[email protected]> wrote:
From: Matheus Tavares Bernardino <[email protected]>
Bare-metal Hexagon programs use OPENDIR, READDIR, and CLOSEDIR
semihosting calls to enumerate host directories. Directory handles are shared
by CPUs in a cluster, allowing guest indices to resolve across calls.
Use lock_user_string()/unlock_user() to read the OPENDIR path from guest
memory instead of copying it into a fixed-size buffer.
CLOSEDIR clears its slot in the directory list, so a stale index reports
EBADF instead of dereferencing a freed pointer.
Also add a functional test for the new semihosting operations.
Signed-off-by: Matheus Tavares Bernardino <[email protected]>
Signed-off-by: Brian Cain <[email protected]>
---
include/hw/hexagon/hexagon.h | 14 ++-
hw/hexagon/hex-subsys.c | 32 ++++---
target/hexagon/hexswi.c | 108 ++++++++++++++++++++++
tests/functional/hexagon/test_systests.py | 11 +++
4 files changed, 153 insertions(+), 12 deletions(-)
diff --git a/include/hw/hexagon/hexagon.h b/include/hw/hexagon/hexagon.h
index 62398eeb359..58bdcabe87e 100644
--- a/include/hw/hexagon/hexagon.h
+++ b/include/hw/hexagon/hexagon.h
@@ -11,6 +11,7 @@
#include "system/memory.h"
#include "hw/core/boards.h"
+#include "hw/cpu/cluster.h"
struct hexagon_board_boot_info {
uint64_t ram_size;
@@ -159,6 +160,17 @@ struct hexagon_machine_config {
union hexagon_config_table cfgtable;
};
+#define TYPE_HEXAGON_CLUSTER_STATE "hexagon-cluster-state"
+OBJECT_DECLARE_SIMPLE_TYPE(HexagonClusterState, HEXAGON_CLUSTER_STATE)
+
+struct HexagonClusterState {
+ CPUClusterState parent_obj;
+
+ struct {
+ GList *dir_list;
+ } semihosting;
+};
I still don't think we should be holding this semihosting
specific information in a struct in the hardware-emulation
I tossed this patch in to the series here, thinking it was fully-baked
and ready-to-roll and relevant to the series. But I agree with your
assessment, it doesn't make sense to put this state here, even if
Hexagon would be the only architecture to leverage it.
I'll drop this patch from future revisions of this series and revisit
the design before sending it for review on its own. For now, the
remainder of the patches can proceed with review focused on the coverity
issues reported.
side of the code. File descriptors aren't per-cluster, they're
shared across all of QEMU (i.e. you can open a file in
one cluster and read it from another), so opendir handles also
should have the same semantics. That also means the code for
them can be in the semihosting related files, and not spill
out into the hardawre-emulation files.
Compare semihosting/guestfd.c, where we handle filedescriptors
for the guest by tracking them in a file-scoped global variable.
-- PMM