blob: 2726b2d0694a6c52b69acf5e035ddc5b5750f44a [file] [log] [blame]
Dmitry V. Levinf9b455c2015-08-18 13:25:36 +00001#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <time.h>
6#include <stdio.h>
7#include <stdint.h>
8#include <unistd.h>
9#include <sys/mman.h>
10#include <sys/syscall.h>
11
12#ifdef __NR_time
13
14int
15main(void)
16{
17 const size_t page_len = sysconf(_SC_PAGESIZE);
18
19 void *p = mmap(NULL, page_len * 2, PROT_READ | PROT_WRITE,
20 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
21 if (p == MAP_FAILED || mprotect(p + page_len, page_len, PROT_NONE))
22 return 77;
23
24 time_t *p_t = p + page_len - sizeof(time_t);
25 time_t t = syscall(__NR_time, p_t);
26
27 if ((time_t) -1 == t || t != *p_t)
28 return 77;
29
30 printf("time\\(\\[%jd\\]\\) += %jd\n", (intmax_t) t, (intmax_t) t);
31
32 return 0;
33}
34
35#else
36
37int
38main(void)
39{
40 return 77;
41}
42
43#endif