/* * Demonstration of FreeBSD vdso gettimeofday(). * MUST be compiled static due to abuse of binding to weak symbols. * * cc -static -o gettimeofday_vdso gettimeofday_vdso.c */ #include #include #include #include #include extern int __vdso_gettimeofday(struct timeval *tv, struct timezone *tz); extern int __sys_gettimeofday(struct timeval *tv, struct timezone *tz); int main(int argc, char *argv[]) { struct timeval tv; int err; char buf[64]; err = __vdso_gettimeofday(&tv, 0); if (err) printf("VDSO call failed. %s\n", strerror(err)); else printf("%ld.%ld\n", tv.tv_sec, tv.tv_usec); err = __sys_gettimeofday(&tv, 0); if (err) printf("Fallback call failed. (?) %s\n", strerror(err)); else printf("%ld.%ld\n", tv.tv_sec, tv.tv_usec); return (0); }