Skip to contentSkip to conversation

Filling in struct mips64_watch_regs from a 32 bit process

DISCUSSION Earl Chew 2 participants 5 messages Feb 1, 2011 MIPS

lore
Share & tools
lore

Earl Chew

author
#0 lore raw

I notice that a 32 bit process running on a 64 bit kernel is expected to know that it should fill in mips64_watch_regs --- even though it is running against a 32 bit ABI.

Is this an oversight, or am I missing something ?

[ That same 32 bit process must fill in mips32_watch_regs when running on
a 32 bit kernel. ]

In arch/mips/include/asm/ptrace.h:

struct mips32_watch_regs {
	unsigned int watchlo[8];
	...
};

and

struct mips64_watch_regs {
	unsigned long long watchlo[8];
	...
};

These are used in a union, but sizeof(mips64_watch_regs.watchlo) will not match sizeof(mips32_watch_regs.watchlo).

For a 64 bit kernel, the code in arch/mips/kernel/ptrace.c reads:

        /* Check the values. */
        for (i = 0; i < current_cpu_data.watch_reg_use_cnt; i++) {
                __get_user(lt[i], &addr->WATCH_STYLE.watchlo[i]);
#ifdef CONFIG_32BIT
                if (lt[i] & __UA_LIMIT)
                        return -EINVAL;
#else
                if (test_tsk_thread_flag(child, TIF_32BIT_ADDR)) {
                        if (lt[i] & 0xffffffff80000000UL)
                                return -EINVAL;
                } else {
                        if (lt[i] & __UA_LIMIT)
                                return -EINVAL;
                }

#endif

Thus for a 64 bit kernel, WATCH_STYLE is defined to be mips64, and the code goes on to obtain:

	addr->mips64.watchlo[i]

and to verify it based on TIF_32BIT_ADDR.

In other words, the 32 bit process is expected to fill in mips64_watch_regs when it is running on a 64 bit kernel, and mips32_watch_regs when it is running on a 32 bit kernel.

Earl

#1 lore raw
Quoted 5 lines · Earl Chew

I notice that a 32 bit process running on a 64 bit kernel is expected to know that it should fill in mips64_watch_regs --- even though it is running against a 32 bit ABI.

Is this an oversight, or am I missing something ?

It is intentional.

Quoted 14 lines

[ That same 32 bit process must fill in mips32_watch_regs when running on
a 32 bit kernel. ]

In arch/mips/include/asm/ptrace.h:

struct mips32_watch_regs {
	unsigned int watchlo[8];
	...
};

and

Quoted 8 lines
struct mips64_watch_regs {
	unsigned long long watchlo[8];
	...
};

These are used in a union, but sizeof(mips64_watch_regs.watchlo) will not match sizeof(mips32_watch_regs.watchlo).

The sizes are different and thus are ... different. struct pt_watch_regs however, has a well defined size.

The important thing is that the style element of struct pt_watch_regs is always in the same place.

Quoted 25 lines

For a 64 bit kernel, the code in arch/mips/kernel/ptrace.c reads:

         /* Check the values. */
         for (i = 0; i<  current_cpu_data.watch_reg_use_cnt; i++) {
                 __get_user(lt[i],&addr->WATCH_STYLE.watchlo[i]);
#ifdef CONFIG_32BIT
                 if (lt[i]&  __UA_LIMIT)
                         return -EINVAL;
#else
                 if (test_tsk_thread_flag(child, TIF_32BIT_ADDR)) {
                         if (lt[i]&  0xffffffff80000000UL)
                                 return -EINVAL;
                 } else {
                         if (lt[i]&  __UA_LIMIT)
                                 return -EINVAL;
                 }

#endif

Thus for a 64 bit kernel, WATCH_STYLE is defined to be mips64, and the code goes on to obtain:

Quoted 9 lines
	addr->mips64.watchlo[i]

and to verify it based on TIF_32BIT_ADDR.

In other words, the 32 bit process is expected to fill in mips64_watch_regs when it is running on a 64 bit kernel, and mips32_watch_regs when it is running on a 32 bit kernel.

Yes. The debugging agent must check struct pt_watch_regs style to determine which type of watch registers the hardware is using.

Take a look at how GDB handles this in mips-linux-nat.c.

David Daney

author
#2 lore raw
Quoted 7 lines
Quoted 5 lines

I notice that a 32 bit process running on a 64 bit kernel is expected to know that it should fill in mips64_watch_regs --- even though it is running against a 32 bit ABI.

Is this an oversight, or am I missing something ?

It is intentional.

Oh I see ... I have to call PTRACE_SET_WATCH_REGS first in order to figure out whether the kernel is expecting me to use pt_watch_style_mips32 or pt_watch_style_mips64.

Thanks.

Earl

#3 lore raw
Quoted 4 lines · Earl Chew
Quoted 4 lines
Quoted 4 lines

I notice that a 32 bit process running on a 64 bit kernel is expected to know that it should fill in mips64_watch_regs --- even though it is running against a 32 bit ABI.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Is this an oversight, or am I missing something ?

It is intentional.

Oh I see ... I have to call PTRACE_SET_WATCH_REGS first in order to figure out whether the kernel is expecting me to use pt_watch_style_mips32 or pt_watch_style_mips64.

That would be PTRACE_GET_WATCH_REGS. It will tell you the width of the registers as well as how many are available (in the num_valid field) and the properties of each (in the watch_masks[] fields).

Fill in watchlo[] and watchhi[], write them back with PTRACE_SET_WATCH_REGS, then sit back and wait for SIGTRAP.

David Daney

author
#4 lore raw
Quoted 1 line

That would be PTRACE_GET_WATCH_REGS.

Yes, that's what I thought I typed :-(

Earl