tm-fork.c 780 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright 2015, Michael Neuling, IBM Corp.
  3. * Licensed under GPLv2.
  4. *
  5. * Edited: Rashmica Gupta, Nov 2015
  6. *
  7. * This test does a fork syscall inside a transaction. Basic sniff test
  8. * to see if we can enter the kernel during a transaction.
  9. */
  10. #include <errno.h>
  11. #include <inttypes.h>
  12. #include <pthread.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <unistd.h>
  16. #include "utils.h"
  17. #include "tm.h"
  18. int test_fork(void)
  19. {
  20. SKIP_IF(!have_htm());
  21. asm __volatile__(
  22. "tbegin.;"
  23. "blt 1f; "
  24. "li 0, 2;" /* fork syscall */
  25. "sc ;"
  26. "tend.;"
  27. "1: ;"
  28. : : : "memory", "r0");
  29. /* If we reach here, we've passed. Otherwise we've probably crashed
  30. * the kernel */
  31. return 0;
  32. }
  33. int main(int argc, char *argv[])
  34. {
  35. return test_harness(test_fork, "tm_fork");
  36. }