4 * Rapidly switch between threads with different TLS pointers to
5 * test that the operating system properly switches the TLS segment.
7 * $DragonFly: src/test/stress/eattls.c,v 1.3 2007/04/13 12:12:27 corecode Exp $
10 #include <sys/types.h>
16 #define BIGSIZE (16 * 1024 * 1024)
23 static int getdata(int offset
);
26 main(int ac
, char **av
)
39 buf
= malloc(BIGSIZE
);
40 buf
+= random() % (BIGSIZE
- sizeof(struct test
));
43 info
.size
= sizeof(struct test
);
44 if ((gs
= set_tls_area(2, &info
, sizeof(info
))) < 0) {
45 perror("set_tls_area");
48 test
->random1
= random1
;
49 test
->random2
= random2
;
50 printf("setting %%gs to 0x%02x segment at %p\n", gs
, test
);
51 __asm
__volatile("mov %0,%%gs" : : "g" (gs
));
53 if (getdata(0) != random1
|| getdata(4) != random2
)
54 printf("data verification failed!\n");
55 if (random() % 1000 > 500)
56 usleep(random() % 1000);
66 __asm
__volatile("movl %%gs:(%0),%%eax; movl %%eax,%1" :
67 "+r" (offset
) : "m" (rv
) : "ax");