regex memory corruption regression test
[libc-test] / src / regression / syscall-sign-extend.c
1 // commit 5f95f965e933c5b155db75520ac27c92ddbcf400 2014-03-18
2 // syscall should not sign extend pointers on x32
3 #define _GNU_SOURCE
4 #include <string.h>
5 #include <errno.h>
6 #include <unistd.h>
7 #include <time.h>
8 #include <sys/syscall.h>
9 #include "test.h"
10
11 #define T(f) ((f) && (t_error(#f " failed: %s\n", strerror(errno)), 0))
12
13 static unsigned long long tsdiff(struct timespec ts2, struct timespec ts)
14 {
15         if (ts2.tv_nsec < ts.tv_nsec) {
16                 ts2.tv_nsec += 1000000000;
17                 ts2.tv_sec--;
18         }
19         if (ts2.tv_sec < ts.tv_sec) {
20                 t_error("non-monotonic SYS_clock_gettime vs clock_gettime: %llu ns\n",
21                         (ts.tv_sec - ts2.tv_sec)*1000000000ULL + ts.tv_nsec - ts2.tv_nsec);
22                 return 0;
23         }
24         return (ts2.tv_sec - ts.tv_sec)*1000000000ULL + (ts2.tv_nsec - ts.tv_nsec);
25 }
26
27 int main(void)
28 {
29         struct timespec ts, ts2;
30         unsigned long long diff;
31
32         // test syscall with pointer
33         T(syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts));
34
35         // check if timespec is filled correctly
36         T(clock_gettime(CLOCK_REALTIME, &ts2));
37         // adjust because linux vdso is non-monotonic wrt the syscall..
38         ts.tv_nsec += 2;
39         diff = tsdiff(ts2, ts);
40         if (diff > 5 * 1000000000ULL)
41                 t_error("large diff between clock_gettime calls: %llu ns\n", diff);
42
43         return t_status;
44 }