Skip to content

Commit c87df9c

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: pt_regs: assert pt_regs is a multiple of 16 bytes
To ensure that the stack is correctly aligned when branching to C code, we require that struct pt_regs is a multiple of 16 bytes, as noted in a comment. Add an explicit assertion for this, so that any accidental violation of this requirement will be caught by the compiler. Signed-off-by: Mark Rutland <[email protected]> Reviewed-by: Mark Brown <[email protected]> Reviewed-by: Miroslav Benes <[email protected]> Reviewed-by: Puranjay Mohan <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Josh Poimboeuf <[email protected]> Cc: Kalesh Singh <[email protected]> Cc: Madhavan T. Venkataraman <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 9852d85 commit c87df9c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/arm64/include/asm/ptrace.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ static inline unsigned long pstate_to_compat_psr(const unsigned long pstate)
149149

150150
/*
151151
* This struct defines the way the registers are stored on the stack during an
152-
* exception. Note that sizeof(struct pt_regs) has to be a multiple of 16 (for
153-
* stack alignment). struct user_pt_regs must form a prefix of struct pt_regs.
152+
* exception. struct user_pt_regs must form a prefix of struct pt_regs.
154153
*/
155154
struct pt_regs {
156155
union {
@@ -180,6 +179,9 @@ struct pt_regs {
180179
u64 exit_rcu;
181180
};
182181

182+
/* For correct stack alignment, pt_regs has to be a multiple of 16 bytes. */
183+
static_assert(IS_ALIGNED(sizeof(struct pt_regs), 16));
184+
183185
static inline bool in_syscall(struct pt_regs const *regs)
184186
{
185187
return regs->syscallno != NO_SYSCALL;

0 commit comments

Comments
 (0)