1 | // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s |
---|---|
2 | |
3 | // musl does not define FP_XSTATE_MAGIC1. |
4 | // REQUIRES: x86_64-target-arch && glibc-2.27 |
5 | |
6 | #include <pthread.h> |
7 | #include <signal.h> |
8 | #include <stdint.h> |
9 | #include <ucontext.h> |
10 | |
11 | void handler(int sig, siginfo_t *info, void *uctx) { |
12 | volatile int uninit; |
13 | auto *mctx = &static_cast<ucontext_t *>(uctx)->uc_mcontext; |
14 | auto *fpregs = mctx->fpregs; |
15 | // The member names differ across header versions, but the actual layout |
16 | // is always the same. So avoid using members, just use arithmetic. |
17 | const uint32_t *after_xmm = |
18 | reinterpret_cast<const uint32_t *>(fpregs + 1) - 24; |
19 | if (after_xmm[12] == FP_XSTATE_MAGIC1) |
20 | reinterpret_cast<_xstate *>(mctx->fpregs)->ymmh.ymmh_space[0] = uninit; |
21 | else |
22 | mctx->gregs[REG_RAX] = uninit; |
23 | } |
24 | |
25 | int main(int argc, char **argv) { |
26 | struct sigaction act = {}; |
27 | act.sa_sigaction = handler; |
28 | act.sa_flags = SA_SIGINFO; |
29 | sigfillset(set: &act.sa_mask); |
30 | sigaction(SIGPROF, act: &act, oact: 0); |
31 | pthread_kill(threadid: pthread_self(), SIGPROF); |
32 | return 0; |
33 | } |
34 | |
35 | // CHECK: WARNING: MemorySanitizer: |
36 |