[PATCH v3 30/87] linux-user/i386: Create target_ptrace.h

Richard Henderson posted 87 patches 1 month ago
[PATCH v3 30/87] linux-user/i386: Create target_ptrace.h
Posted by Richard Henderson 1 month ago
Move the target_pt_regs structure from target_syscall.h.
Rename the bits according to user_regs_struct, which is
what is actually used by ELF_CORE_COPY_REGS; the layout
of the two structure definitions is identical.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/i386/target_ptrace.h  | 31 +++++++++++++++++++++++++++++++
 linux-user/i386/target_syscall.h | 18 ------------------
 2 files changed, 31 insertions(+), 18 deletions(-)
 create mode 100644 linux-user/i386/target_ptrace.h

diff --git a/linux-user/i386/target_ptrace.h b/linux-user/i386/target_ptrace.h
new file mode 100644
index 0000000000..51edb637af
--- /dev/null
+++ b/linux-user/i386/target_ptrace.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef I386_TARGET_PTRACE_H
+#define I386_TARGET_PTRACE_H
+
+/*
+ * Compare linux arch/x86/include/uapi/asm/ptrace.h (struct pt_regs) and
+ * arch/x86/include/asm/user_32.h (struct user_regs_struct).
+ * The structure layouts are identical; the user_regs_struct names are better.
+ */
+struct target_pt_regs {
+    abi_ulong bx;
+    abi_ulong cx;
+    abi_ulong dx;
+    abi_ulong si;
+    abi_ulong di;
+    abi_ulong bp;
+    abi_ulong ax;
+    abi_ulong ds;
+    abi_ulong es;
+    abi_ulong fs;
+    abi_ulong gs;
+    abi_ulong orig_ax;
+    abi_ulong ip;
+    abi_ulong cs;
+    abi_ulong flags;
+    abi_ulong sp;
+    abi_ulong ss;
+};
+
+#endif /* I386_TARGET_PTRACE_H */
diff --git a/linux-user/i386/target_syscall.h b/linux-user/i386/target_syscall.h
index aaade06b13..c214a909a6 100644
--- a/linux-user/i386/target_syscall.h
+++ b/linux-user/i386/target_syscall.h
@@ -5,24 +5,6 @@
 #define __USER_CS	(0x23)
 #define __USER_DS	(0x2B)
 
-struct target_pt_regs {
-	long ebx;
-	long ecx;
-	long edx;
-	long esi;
-	long edi;
-	long ebp;
-	long eax;
-	int  xds;
-	int  xes;
-	long orig_eax;
-	long eip;
-	int  xcs;
-	long eflags;
-	long esp;
-	int  xss;
-};
-
 /* ioctls */
 
 #define TARGET_LDT_ENTRIES      8192
-- 
2.43.0
Re: [PATCH v3 30/87] linux-user/i386: Create target_ptrace.h
Posted by Peter Maydell 1 month ago
On Thu, 28 Aug 2025 at 13:09, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> Move the target_pt_regs structure from target_syscall.h.
> Rename the bits according to user_regs_struct, which is
> what is actually used by ELF_CORE_COPY_REGS; the layout
> of the two structure definitions is identical.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  linux-user/i386/target_ptrace.h  | 31 +++++++++++++++++++++++++++++++
>  linux-user/i386/target_syscall.h | 18 ------------------
>  2 files changed, 31 insertions(+), 18 deletions(-)
>  create mode 100644 linux-user/i386/target_ptrace.h
>
> diff --git a/linux-user/i386/target_ptrace.h b/linux-user/i386/target_ptrace.h
> new file mode 100644
> index 0000000000..51edb637af
> --- /dev/null
> +++ b/linux-user/i386/target_ptrace.h
> @@ -0,0 +1,31 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +
> +#ifndef I386_TARGET_PTRACE_H
> +#define I386_TARGET_PTRACE_H
> +
> +/*
> + * Compare linux arch/x86/include/uapi/asm/ptrace.h (struct pt_regs) and
> + * arch/x86/include/asm/user_32.h (struct user_regs_struct).
> + * The structure layouts are identical; the user_regs_struct names are better.
> + */

Why do you think the user_regs_struct names are better?
"bx" suggests a 16-bit register, but these are 32-bit, right?

> +struct target_pt_regs {
> +    abi_ulong bx;
> +    abi_ulong cx;
> +    abi_ulong dx;
> +    abi_ulong si;
> +    abi_ulong di;
> +    abi_ulong bp;
> +    abi_ulong ax;
> +    abi_ulong ds;
> +    abi_ulong es;
> +    abi_ulong fs;
> +    abi_ulong gs;
> +    abi_ulong orig_ax;
> +    abi_ulong ip;
> +    abi_ulong cs;
> +    abi_ulong flags;
> +    abi_ulong sp;
> +    abi_ulong ss;
> +};
> +
> +#endif /* I386_TARGET_PTRACE_H */
> diff --git a/linux-user/i386/target_syscall.h b/linux-user/i386/target_syscall.h
> index aaade06b13..c214a909a6 100644
> --- a/linux-user/i386/target_syscall.h
> +++ b/linux-user/i386/target_syscall.h
> @@ -5,24 +5,6 @@
>  #define __USER_CS      (0x23)
>  #define __USER_DS      (0x2B)
>
> -struct target_pt_regs {
> -       long ebx;
> -       long ecx;
> -       long edx;
> -       long esi;
> -       long edi;
> -       long ebp;
> -       long eax;
> -       int  xds;
> -       int  xes;
> -       long orig_eax;
> -       long eip;
> -       int  xcs;
> -       long eflags;
> -       long esp;
> -       int  xss;
> -};


Commit message should say something about why we're changing
the types (though clearly here the target-specific types are
more sensible than the host-specific ones).

-- PMM
Re: [PATCH v3 30/87] linux-user/i386: Create target_ptrace.h
Posted by Richard Henderson 1 month ago
On 8/29/25 00:42, Peter Maydell wrote:
> On Thu, 28 Aug 2025 at 13:09, Richard Henderson
> <richard.henderson@linaro.org> wrote:
>> +/*
>> + * Compare linux arch/x86/include/uapi/asm/ptrace.h (struct pt_regs) and
>> + * arch/x86/include/asm/user_32.h (struct user_regs_struct).
>> + * The structure layouts are identical; the user_regs_struct names are better.
>> + */
> 
> Why do you think the user_regs_struct names are better?
> "bx" suggests a 16-bit register, but these are 32-bit, right?

Mostly I really don't like xds etc.

> Commit message should say something about why we're changing
> the types (though clearly here the target-specific types are
> more sensible than the host-specific ones).

Oops, yes.  There are quite a lot of error across the various target_pt_regs structures 
that we never caught because they were never used.


r~
Re: [PATCH v3 30/87] linux-user/i386: Create target_ptrace.h
Posted by Peter Maydell 1 month ago
On Thu, 28 Aug 2025 at 23:14, Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 8/29/25 00:42, Peter Maydell wrote:
> > On Thu, 28 Aug 2025 at 13:09, Richard Henderson
> > <richard.henderson@linaro.org> wrote:
> >> +/*
> >> + * Compare linux arch/x86/include/uapi/asm/ptrace.h (struct pt_regs) and
> >> + * arch/x86/include/asm/user_32.h (struct user_regs_struct).
> >> + * The structure layouts are identical; the user_regs_struct names are better.
> >> + */
> >
> > Why do you think the user_regs_struct names are better?
> > "bx" suggests a 16-bit register, but these are 32-bit, right?
>
> Mostly I really don't like xds etc.
>
> > Commit message should say something about why we're changing
> > the types (though clearly here the target-specific types are
> > more sensible than the host-specific ones).
>
> Oops, yes.  There are quite a lot of error across the various target_pt_regs structures
> that we never caught because they were never used.

With that,
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM