On Mon, 14 Sept 2026 at 23:32, 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;
> +};

This looks very odd. Why do we need to track open directory handles
in this special per-cluster structure, but we don't need to do
that for e.g. open file handles returned by SYS_OPEN ? I can't
see anything in the semihosting specification that indicates
that SYS_OPENDIR has special behaviour like that.

thanks
-- PMM

Reply via email to