diff options
| author | Chris Metcalf <cmetcalf@ezchip.com> | 2014-11-12 15:00:06 -0500 |
|---|---|---|
| committer | Chris Metcalf <cmetcalf@ezchip.com> | 2014-11-13 09:39:26 -0500 |
| commit | ce433f8090da6784cdee754defcbf325fc66f274 (patch) | |
| tree | 81be5d2025ad1690228a18203875715e0647ff04 | |
| parent | a5c1cb63ddf400cf58c7d8aecd045049f6818279 (diff) | |
tile: avoid undefined behavior with regs[TREG_TP] etc
Recent compilers warn about accesses to arrays past the end,
which is supported for pt_regs and sigcontext with the
intended alias past the end of regs[] to sp, tp, and lr
using TREG_SP, TREG_TP, and TREG_LR.
Make the intended usage explict by providing an anonymous
union of regs[56] on the one hand, and a short __regs[53]
on the other followed by the sp, tp, and lr fields, so the
aliasing is done explicitly and is visible to the compiler.
Reviewed-by: Jeff Epler <jepler@unpythonic.net>
Signed-off-by: Chris Metcalf <cmetcalf@ezchip.com>
| -rw-r--r-- | arch/tile/include/uapi/asm/ptrace.h | 16 | ||||
| -rw-r--r-- | arch/tile/include/uapi/asm/sigcontext.h | 14 |
2 files changed, 20 insertions, 10 deletions
diff --git a/arch/tile/include/uapi/asm/ptrace.h b/arch/tile/include/uapi/asm/ptrace.h index 7757e1985fb6..d03b829857e8 100644 --- a/arch/tile/include/uapi/asm/ptrace.h +++ b/arch/tile/include/uapi/asm/ptrace.h | |||
| @@ -52,12 +52,16 @@ typedef uint_reg_t pt_reg_t; | |||
| 52 | * system call or exception. "struct sigcontext" has the same shape. | 52 | * system call or exception. "struct sigcontext" has the same shape. |
| 53 | */ | 53 | */ |
| 54 | struct pt_regs { | 54 | struct pt_regs { |
| 55 | /* Saved main processor registers; 56..63 are special. */ | 55 | union { |
| 56 | /* tp, sp, and lr must immediately follow regs[] for aliasing. */ | 56 | /* Saved main processor registers; 56..63 are special. */ |
| 57 | pt_reg_t regs[53]; | 57 | pt_reg_t regs[56]; |
| 58 | pt_reg_t tp; /* aliases regs[TREG_TP] */ | 58 | struct { |
| 59 | pt_reg_t sp; /* aliases regs[TREG_SP] */ | 59 | pt_reg_t __regs[53]; |
| 60 | pt_reg_t lr; /* aliases regs[TREG_LR] */ | 60 | pt_reg_t tp; /* aliases regs[TREG_TP] */ |
| 61 | pt_reg_t sp; /* aliases regs[TREG_SP] */ | ||
| 62 | pt_reg_t lr; /* aliases regs[TREG_LR] */ | ||
| 63 | }; | ||
| 64 | }; | ||
| 61 | 65 | ||
| 62 | /* Saved special registers. */ | 66 | /* Saved special registers. */ |
| 63 | pt_reg_t pc; /* stored in EX_CONTEXT_K_0 */ | 67 | pt_reg_t pc; /* stored in EX_CONTEXT_K_0 */ |
diff --git a/arch/tile/include/uapi/asm/sigcontext.h b/arch/tile/include/uapi/asm/sigcontext.h index 6348e59d3724..39ff5d1a232d 100644 --- a/arch/tile/include/uapi/asm/sigcontext.h +++ b/arch/tile/include/uapi/asm/sigcontext.h | |||
| @@ -24,10 +24,16 @@ | |||
| 24 | * but is simplified since we know the fault is from userspace. | 24 | * but is simplified since we know the fault is from userspace. |
| 25 | */ | 25 | */ |
| 26 | struct sigcontext { | 26 | struct sigcontext { |
| 27 | __uint_reg_t gregs[53]; /* General-purpose registers. */ | 27 | __extension__ union { |
| 28 | __uint_reg_t tp; /* Aliases gregs[TREG_TP]. */ | 28 | /* General-purpose registers. */ |
| 29 | __uint_reg_t sp; /* Aliases gregs[TREG_SP]. */ | 29 | __uint_reg_t gregs[56]; |
| 30 | __uint_reg_t lr; /* Aliases gregs[TREG_LR]. */ | 30 | __extension__ struct { |
| 31 | __uint_reg_t __gregs[53]; | ||
| 32 | __uint_reg_t tp; /* Aliases gregs[TREG_TP]. */ | ||
| 33 | __uint_reg_t sp; /* Aliases gregs[TREG_SP]. */ | ||
| 34 | __uint_reg_t lr; /* Aliases gregs[TREG_LR]. */ | ||
| 35 | }; | ||
| 36 | }; | ||
| 31 | __uint_reg_t pc; /* Program counter. */ | 37 | __uint_reg_t pc; /* Program counter. */ |
| 32 | __uint_reg_t ics; /* In Interrupt Critical Section? */ | 38 | __uint_reg_t ics; /* In Interrupt Critical Section? */ |
| 33 | __uint_reg_t faultnum; /* Fault number. */ | 39 | __uint_reg_t faultnum; /* Fault number. */ |
