Re: PATCH: Enable x86 XML target descriptions

H.J. Lu
2010-02-22T22:07:45Z

On Mon, Feb 22, 2010 at 2:02 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 02/22/2010 01:41 PM, H.J. Lu wrote:
>>>>
>>>> Please see if my latest patch is OK:
>>>>
>>>> ---
>>>>  /* Get CS register.  */
>>>>   errno = 0;
>>>>   cs = ptrace (PTRACE_PEEKUSER, tid,
>>>>                offsetof (struct user_regs_struct, cs), 0);
>>>>   if (errno != 0)
>>>>     perror_with_name (_("Couldn't get CS register"));
>>>>
>>>>   /* Value of CS register:
>>>>      1. 64bit: 0x33.
>>>>      2. 32bit: 0x23.
>>>>    */
>>>>   if (cs == 0x33)
>>>>     return tdesc_amd64_linux;
>>>>   else
>>>>     return tdesc_i386_linux;
>>>> ---
>>>>
>>>> In kernel, there is
>>>>
>>>>       regs->cs = test_thread_flag(TIF_64BIT_ILP32) ? __USER_CS : __USER32_CS;
>>>
>>> I fear that's rather fragile.  I mean, the actual value of
>>> __USER_CS/__USER32_CS is just an implementation detail isn't it?
>>>
>>
>> That is how strace checks 32bit process on Linux/x86-64  I have
>> discussed it with Peter and Suresh. It is very unlikely Linux kernel will
>> break strace.  In any case,  we will add a new ptrace option to Linux
>> 2.6.35 to get TIF_64BIT_ILP32 among other things. I will update gdb
>> to try the new ptrace option first and then fail back to CS register.
>>
>
> Uhm... TIF_64BIT_ILP32 didn't go upstream (remember, we shut down that
> project?)
>
> What I suggested was to add an strace option to get the segment
> descriptor flags, which would include the CS.L bit for 64-bit mode.
>

Oops. Wrong kernel source. The idea is the same. It is the CS.L bit
for 64-bit mode. That is

/* Value of CS register:
1. 64bit: 0x33.
2. 32bit: 0x23.
*/

--
H.J.