This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 30c6bdb03f419e521e592bcd02ac3d940566333a
Author: p-szafonimateusz <[email protected]>
AuthorDate: Thu Jan 9 15:37:41 2025 +0100

    libc/lib_gdbstub.c: running_regs must be aligned
    
    running_regs is passed to up_saveusercontext(), which may need it
    aligned to XCPTCONTEXT_ALIGN: on x86_64 the registers are saved with
    FXSAVE or XSAVE, which need a 16-byte or 64-byte aligned buffer.  As a
    member in the middle of struct gdb_state_s, running_regs was only
    aligned to the alignment of the struct.
    
    Allocate it on its own with lib_memalign(XCPTCONTEXT_ALIGN, ...).
    
    Signed-off-by: p-szafonimateusz <[email protected]>
---
 libs/libc/gdbstub/lib_gdbstub.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libs/libc/gdbstub/lib_gdbstub.c b/libs/libc/gdbstub/lib_gdbstub.c
index 5e2ce3d2a96..c10984011c6 100644
--- a/libs/libc/gdbstub/lib_gdbstub.c
+++ b/libs/libc/gdbstub/lib_gdbstub.c
@@ -91,7 +91,7 @@ struct gdb_state_s
   FAR char *pkt_next;                     /* Pointer to next byte in packet */
   char pkt_buf[BUFSIZE];                  /* Packet buffer */
   size_t pkt_len;                         /* Packet send and receive length */
-  uint8_t running_regs[XCPTCONTEXT_SIZE]; /* Registers of running thread */
+  FAR uint8_t *running_regs;              /* Registers of running thread */
   size_t size;                            /* Size of registers */
   uintptr_t registers[0];                 /* Registers of other threads */
 };
@@ -2047,6 +2047,7 @@ FAR struct gdb_state_s *gdb_state_init(gdb_send_func_t 
send,
   state->recv = recv;
   state->priv = priv;
   state->monitor = monitor;
+  state->running_regs = lib_memalign(XCPTCONTEXT_ALIGN, XCPTCONTEXT_SIZE);
 
 #ifdef CONFIG_LIB_GDBSTUB_DEBUG
   lib_syslograwstream_open(&state->stream);
@@ -2070,6 +2071,7 @@ void gdb_state_uninit(FAR struct gdb_state_s *state)
 {
   if (state != NULL)
     {
+      lib_free(state->running_regs);
       lib_free(state);
     }
 }

Reply via email to