brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · f65f909 Raw
36 lines · cpp
1// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s2 3// musl does not define FP_XSTATE_MAGIC1.4// REQUIRES: x86_64-target-arch && glibc-2.275 6#include <pthread.h>7#include <signal.h>8#include <stdint.h>9#include <ucontext.h>10 11void 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 layout16  // 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  else22    mctx->gregs[REG_RAX] = uninit;23}24 25int main(int argc, char **argv) {26  struct sigaction act = {};27  act.sa_sigaction = handler;28  act.sa_flags = SA_SIGINFO;29  sigfillset(&act.sa_mask);30  sigaction(SIGPROF, &act, 0);31  pthread_kill(pthread_self(), SIGPROF);32  return 0;33}34 35// CHECK: WARNING: MemorySanitizer:36