1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <inttypes.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <unistd.h>
28#include <sys/mman.h>
29#include <string.h>
30#include <assert.h>
31
32#include "tm.h"
33#include "utils.h"
34
35int test_vmxcopy()
36{
37 long double vecin = 1.3;
38 long double vecout;
39 unsigned long pgsize = getpagesize();
40 int i;
41 int fd;
42 int size = pgsize*16;
43 char tmpfile[] = "/tmp/page_faultXXXXXX";
44 char buf[pgsize];
45 char *a;
46 uint64_t aborted = 0;
47
48 SKIP_IF(!have_htm());
49
50 fd = mkstemp(tmpfile);
51 assert(fd >= 0);
52
53 memset(buf, 0, pgsize);
54 for (i = 0; i < size; i += pgsize)
55 assert(write(fd, buf, pgsize) == pgsize);
56
57 unlink(tmpfile);
58
59 a = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
60 assert(a != MAP_FAILED);
61
62 asm __volatile__(
63 "lxvd2x 40,0,%[vecinptr];"
64 "tbegin.;"
65 "beq 3f;"
66 "tsuspend.;"
67 "xxlxor 40,40,40;"
68 "std 5, 0(%[map]);"
69 "tabort. 0;"
70 "tresume.;"
71 "tend.;"
72 "li %[res], 0;"
73 "b 5f;"
74
75
76 "3:;"
77 "li %[res], 1;"
78
79 "5:;"
80 "stxvd2x 40,0,%[vecoutptr];"
81 : [res]"=r"(aborted)
82 : [vecinptr]"r"(&vecin),
83 [vecoutptr]"r"(&vecout),
84 [map]"r"(a)
85 : "memory", "r0", "r3", "r4", "r5", "r6", "r7");
86
87 if (aborted && (vecin != vecout)){
88 printf("FAILED: vector state leaked on abort %f != %f\n",
89 (double)vecin, (double)vecout);
90 return 1;
91 }
92
93 munmap(a, size);
94
95 close(fd);
96
97 return 0;
98}
99
100int main(void)
101{
102 return test_harness(test_vmxcopy, "tm_vmxcopy");
103}
104