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