copy_paste_unaligned_common.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2016, Chris Smart, IBM Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * Common code for copy, copy_first, paste and paste_last unaligned
  10. * tests.
  11. *
  12. */
  13. #include <signal.h>
  14. #include <string.h>
  15. #include <unistd.h>
  16. #include "utils.h"
  17. #include "instructions.h"
  18. #include "copy_paste_unaligned_common.h"
  19. unsigned int expected_instruction;
  20. unsigned int instruction_mask;
  21. char cacheline_buf[128] __cacheline_aligned;
  22. void signal_action_handler(int signal_num, siginfo_t *info, void *ptr)
  23. {
  24. ucontext_t *ctx = ptr;
  25. #if defined(__powerpc64__)
  26. unsigned int *pc = (unsigned int *)ctx->uc_mcontext.gp_regs[PT_NIP];
  27. #else
  28. unsigned int *pc = (unsigned int *)ctx->uc_mcontext.uc_regs->gregs[PT_NIP];
  29. #endif
  30. /*
  31. * Check that the signal was on the correct instruction, using a
  32. * mask because the compiler assigns the register at RB.
  33. */
  34. if ((*pc & instruction_mask) == expected_instruction)
  35. _exit(0); /* We hit the right instruction */
  36. _exit(1);
  37. }
  38. void setup_signal_handler(void)
  39. {
  40. struct sigaction signal_action;
  41. memset(&signal_action, 0, sizeof(signal_action));
  42. signal_action.sa_sigaction = signal_action_handler;
  43. signal_action.sa_flags = SA_SIGINFO;
  44. sigaction(SIGBUS, &signal_action, NULL);
  45. }