Skip to content

Commit

Permalink
i#6953: Fix sigcontext test AVX error (#6954)
Browse files Browse the repository at this point in the history
Replaces a kill() with an inlined system call in the linux.sigcontext
test to avoid failure when compiled for AVX only, as the compiler
inserts VZEROUPPER there (VZEROUPPER is recommended by Intel to avoid a
performance penalty when switching between upper-zeroing VEX-encoded XMM
operations and legacy upper-preserving SSE* operations: so doing it at
transitions to code you don't control makes sense).

Tested on a toolchain targeting AVX.

Fixes #6953
  • Loading branch information
derekbruening authored Aug 30, 2024
1 parent dbd993e commit 48b436d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions suite/tests/linux/sigcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "tools.h"
/* we want the latest defs so we can get at ymm state */
#include "../../../core/unix/include/sigcontext.h"
#include "../../../core/unix/include/syscall.h"
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
Expand Down Expand Up @@ -183,6 +184,7 @@ main(int argc, char *argv[])
int buf[INTS_PER_XMM * NUM_SIMD_SSE_AVX_REGS];
char *ptr = (char *)buf;
int i, j;
pid_t pid = getpid();

/* do this first to avoid messing w/ xmm state */
intercept_signal(SIGUSR1, signal_handler, false);
Expand Down Expand Up @@ -323,8 +325,21 @@ main(int argc, char *argv[])
MOVE_TO_YMM(buf, 15)
# endif
# endif
/* now make sure they show up in signal context */
kill(getpid(), SIGUSR2);
/* Now make sure they show up in the signal context.
* But, it's not safe to make a regular call, as the compiler will
* insert VZEROUPPER for some configurations.
*/
# ifdef X64
__asm__ __volatile__("mov %0, %%rdi; mov %1, %%rsi; mov %2, %%rax; syscall"
:
: "m"(pid), "i"(SIGUSR2), "i"(SYS_kill)
: "rdi", "rsi", "rax");
# else
__asm__ __volatile__("mov %0, %%ebx; mov %1, %%ecx; mov %2, %%eax; int $0x80"
:
: "m"(pid), "i"(SIGUSR2), "i"(SYS_kill)
: "ebx", "ecx", "eax");
# endif

/* Ensure they are preserved across the sigreturn (xref i#3812). */
# ifdef __AVX512F__
Expand Down

0 comments on commit 48b436d

Please sign in to comment.