x86emul: correct DECLARE_ALIGNED()
PATCH 1/1 x86emul: correct DECLARE_ALIGNED()
Stop creating an excessively large array on the stack, by properly taking into account the array element size when establishing its element count (and of course also when calculating the pointer to be actually used to access the memory).
xen/arch/x86/x86_emulate/x86_emulate.c +4 -4
@@ -553,10 +553,10 @@ typedef union {* the compiler for automatic variables. Use this helper to instantiate a * suitably aligned variable, producing a pointer to access it. */ -#define DECLARE_ALIGNED (type, var) \ - long __##var[sizeof(type) + __alignof(type) - __alignof(long)]; \ - type *const var##p = \ - (void *)((long)(__##var + __alignof(type) - __alignof(long)) \ +#define DECLARE_ALIGNED (type, var) \ + long __##var[(sizeof(type) + __alignof(type)) / __alignof(long) - 1]; \ + type *const var##p = \ + (void *)(((long)__##var + __alignof(type) - __alignof(__##var)) \ & -__alignof(type))#ifdef __GCC_ASM_FLAG_OUTPUTS__
x86emul: correct DECLARE_ALIGNED()
Stop creating an excessively large array on the stack, by properly taking into account the array element size when establishing its element count (and of course also when calculating the pointer to be actually used to access the memory).
xen/arch/x86/x86_emulate/x86_emulate.c +4 -4
@@ -553,10 +553,10 @@ typedef union {* the compiler for automatic variables. Use this helper to instantiate a * suitably aligned variable, producing a pointer to access it. */ -#define DECLARE_ALIGNED (type, var) \ - long __##var[sizeof(type) + __alignof(type) - __alignof(long)]; \ - type *const var##p = \ - (void *)((long)(__##var + __alignof(type) - __alignof(long)) \ +#define DECLARE_ALIGNED (type, var) \ + long __##var[(sizeof(type) + __alignof(type)) / __alignof(long) - 1]; \ + type *const var##p = \ + (void *)(((long)__##var + __alignof(type) - __alignof(__##var)) \ & -__alignof(type))#ifdef __GCC_ASM_FLAG_OUTPUTS__
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 4 lines · Jan Beulich
Stop creating an excessively large array on the stack, by properly taking into account the array element size when establishing its element count (and of course also when calculating the pointer to be actually used to access the memory).
What in practice does this do? It looks like it reduces the size of the array by 4 or 8 times?
~Andrew
Quoted 13 lines
Signed-off-by Jan Beulich <[email protected]>xen/arch/x86/x86_emulate/x86_emulate.c +0
-1@@ -553,10 +553,10 @@ typedef union {* the compiler for automatic variables. Use this helper to instantiate a * suitably aligned variable, producing a pointer to access it. */ -#define DECLARE_ALIGNED (type, var) \
xen/arch/x86/x86_emulate/x86_emulate.c typedef union { · line 562
Quoted 10 lines
xen/arch/x86/x86_emulate/x86_emulate.c +4
-3- long __##var[sizeof(type) + __alignof(type) - __alignof(long)]; \ - type *const var##p = \ - (void *)((long)(__##var + __alignof(type) - __alignof(long)) \ +#define DECLARE_ALIGNED (type, var) \ + long __##var[(sizeof(type) + __alignof(type)) / __alignof(long) - 1]; \ + type *const var##p = \ + (void *)(((long)__##var + __alignof(type) - __alignof(__##var)) \ & -__alignof(type))#ifdef __GCC_ASM_FLAG_OUTPUTS__
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 16.03.17 at 14:09, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Stop creating an excessively large array on the stack, by properly taking into account the array element size when establishing its element count (and of course also when calculating the pointer to be actually used to access the memory).
What in practice does this do? It looks like it reduces the size of the array by 4 or 8 times?
Correct - it was this much oversized, bloating the stack frame of the function quite a bit.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Andrew Cooper
Reviewed-byQuoted 10 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 16.03.17 at 14:09, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
Stop creating an excessively large array on the stack, by properly taking into account the array element size when establishing its element count (and of course also when calculating the pointer to be actually used to access the memory).
What in practice does this do? It looks like it reduces the size of the array by 4 or 8 times?
Correct - it was this much oversized, bloating the stack frame of the function quite a bit.
Ok, although it would be helpful if this was called out more clearly in the commit message.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel