tm-exec.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright 2016, Cyril Bur, IBM Corp.
  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. * Syscalls can be performed provided the transactions are suspended.
  10. * The exec() class of syscall is unique as a new process is loaded.
  11. *
  12. * It makes little sense for after an exec() call for the previously
  13. * suspended transaction to still exist.
  14. */
  15. #define _GNU_SOURCE
  16. #include <errno.h>
  17. #include <inttypes.h>
  18. #include <libgen.h>
  19. #include <pthread.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <unistd.h>
  24. #include "utils.h"
  25. #include "tm.h"
  26. static char *path;
  27. static int test_exec(void)
  28. {
  29. SKIP_IF(!have_htm());
  30. asm __volatile__(
  31. "tbegin.;"
  32. "blt 1f; "
  33. "tsuspend.;"
  34. "1: ;"
  35. : : : "memory");
  36. execl(path, "tm-exec", "--child", NULL);
  37. /* Shouldn't get here */
  38. perror("execl() failed");
  39. return 1;
  40. }
  41. static int after_exec(void)
  42. {
  43. asm __volatile__(
  44. "tbegin.;"
  45. "blt 1f;"
  46. "tsuspend.;"
  47. "1: ;"
  48. : : : "memory");
  49. FAIL_IF(failure_is_nesting());
  50. return 0;
  51. }
  52. int main(int argc, char *argv[])
  53. {
  54. path = argv[0];
  55. if (argc > 1 && strcmp(argv[1], "--child") == 0)
  56. return after_exec();
  57. return test_harness(test_exec, "tm_exec");
  58. }