Blame src/regression/syscall-sign-extend.c
|
Szabolcs Nagy |
b21548 |
// commit 5f95f965e933c5b155db75520ac27c92ddbcf400 2014-03-18
|
|
Szabolcs Nagy |
b21548 |
// syscall should not sign extend pointers on x32
|
|
Szabolcs Nagy |
b21548 |
#define _GNU_SOURCE
|
|
Szabolcs Nagy |
b21548 |
#include <string.h>
|
|
Szabolcs Nagy |
b21548 |
#include <errno.h>
|
|
Szabolcs Nagy |
b21548 |
#include <unistd.h>
|
|
Szabolcs Nagy |
b21548 |
#include <time.h>
|
|
Szabolcs Nagy |
b21548 |
#include <sys/syscall.h>
|
|
Szabolcs Nagy |
b21548 |
#include "test.h"
|
|
Szabolcs Nagy |
b21548 |
|
|
Szabolcs Nagy |
b21548 |
#define T(f) ((f) && (t_error(#f " failed: %s\n", strerror(errno)), 0))
|
|
Szabolcs Nagy |
b21548 |
|
|
Szabolcs Nagy |
b21548 |
static unsigned long long tsdiff(struct timespec ts2, struct timespec ts)
|
|
Szabolcs Nagy |
b21548 |
{
|
|
Szabolcs Nagy |
b21548 |
if (ts2.tv_nsec < ts.tv_nsec) {
|
|
Szabolcs Nagy |
b21548 |
ts2.tv_nsec += 1000000000;
|
|
Szabolcs Nagy |
b21548 |
ts2.tv_sec--;
|
|
Szabolcs Nagy |
b21548 |
}
|
|
Szabolcs Nagy |
efd761 |
if (ts2.tv_sec < ts.tv_sec) {
|
|
Szabolcs Nagy |
efd761 |
t_error("non-monotonic SYS_clock_gettime vs clock_gettime: %llu ns\n",
|
|
Szabolcs Nagy |
efd761 |
(ts.tv_sec - ts2.tv_sec)*1000000000ULL + ts.tv_nsec - ts2.tv_nsec);
|
|
Szabolcs Nagy |
efd761 |
return 0;
|
|
Szabolcs Nagy |
efd761 |
}
|
|
Szabolcs Nagy |
b21548 |
return (ts2.tv_sec - ts.tv_sec)*1000000000ULL + (ts2.tv_nsec - ts.tv_nsec);
|
|
Szabolcs Nagy |
b21548 |
}
|
|
Szabolcs Nagy |
b21548 |
|
|
Szabolcs Nagy |
b21548 |
int main(void)
|
|
Szabolcs Nagy |
b21548 |
{
|
|
Szabolcs Nagy |
b21548 |
struct timespec ts, ts2;
|
|
Szabolcs Nagy |
b21548 |
unsigned long long diff;
|
|
Szabolcs Nagy |
b21548 |
|
|
Szabolcs Nagy |
b21548 |
// test syscall with pointer
|
|
Szabolcs Nagy |
b21548 |
T(syscall(SYS_clock_gettime, CLOCK_REALTIME, &ts);;
|
|
Szabolcs Nagy |
b21548 |
|
|
Szabolcs Nagy |
b21548 |
// check if timespec is filled correctly
|
|
Szabolcs Nagy |
b21548 |
T(clock_gettime(CLOCK_REALTIME, &ts2));
|
|
Szabolcs Nagy |
efd761 |
// adjust because linux vdso is non-monotonic wrt the syscall..
|
|
Szabolcs Nagy |
efd761 |
ts.tv_nsec += 2;
|
|
Szabolcs Nagy |
b21548 |
diff = tsdiff(ts2, ts);
|
|
Szabolcs Nagy |
efd761 |
if (diff > 5 * 1000000000ULL)
|
|
Szabolcs Nagy |
b21548 |
t_error("large diff between clock_gettime calls: %llu ns\n", diff);
|
|
Szabolcs Nagy |
b21548 |
|
|
Szabolcs Nagy |
b21548 |
return t_status;
|
|
Szabolcs Nagy |
b21548 |
}
|