When the program below is run on Linux/x86, the following output is produced: After time(): t=-14, errno=0 After syscall(SYS_time): t=-1, errno=14 In the first line, the reported return value from time() should be -1, with errno set to EFAULT (14). Instead, the call returns -14. Could this be a configuration problem in sysdeps/unix/sysv/linux/i386/syscalls.list? Cheers, Michael ========== #define _GNU_SOURCE #include <stdio.h> #include <errno.h> #include <unistd.h> #include <sys/syscall.h> #include <time.h> #define VAL 1000 int main() { time_t t; t = time((time_t *)VAL); printf("After time(): t=%ld, errno=%d\n", (long) t, errno); t = syscall(SYS_time, (time_t *)VAL); printf("After syscall(SYS_time): t=%ld, errno=%d\n", (long) t, errno); return 0; }
time is marked with E, i.e. not returning error (which I'd say matches POSIX which doesn't define any errors for time). By passing an invalid address to the function you reach undefined behaviour territory and all answers are fine in that case.
Subject: Re: time() returns incorrect value when given bad address > time is marked with E, i.e. not returning error (which I'd say matches > POSIX which doesn't define any errors for time). By passing an invalid > address to the function you reach undefined behaviour territory and all > answers are fine in that case. Hi Jakub Thanks for your quick reply. POSIX does not define any errno values for time(), but nevertheless says: Upon successful completion, time( ) shall return the value of time. Otherwise, (time_t)−1 shall be returned. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ In my book, that means that time() should reasonably return -1 here. The POSIX.1 "No errors are defined" means that error values returned by a function or stored into a variable accessed through the symbol errno, if any, depend on the implementation. This does not (in my reading) mean that no error indication (i.e., -1 in this case) should be returned. Note also that glibc is thwarting the underlying system call, which does actually return -1 for this case (as my program demonstrates). Cheers, Michael
I've added a new implementation which will simply crash for all invalid pointers.
Subject: Re: time() returns incorrect value when given bad address > > ------- Additional Comments From drepper at redhat dot com 2005-12-20 > 07:50 ------- > I've added a new implementation which will simply crash for > all invalid pointers. Good! Thanks.