Preparing for the next release: call for testing
Dmitry V. Levin
ldv at altlinux.org
Tue Dec 15 16:30:12 UTC 2015
On Mon, Dec 14, 2015 at 04:45:33PM -0500, Mike Frysinger wrote:
> On 15 Dec 2015 00:03, Dmitry V. Levin wrote:
> > On Mon, Dec 14, 2015 at 03:45:40PM -0500, Mike Frysinger wrote:
> > > On 11 Dec 2015 06:30, Dmitry V. Levin wrote:
> > > > On Thu, Dec 10, 2015 at 09:37:35PM -0500, Mike Frysinger wrote:
> > [...]
> > > > > vFAIL: test; x86_64 32-bit/LSB linux-4.1.6 kernel-headers-4.1.0 glibc-2.21 gcc-4.9.2
> > > > > < times({tms_utime=22, tms_stime=17, tms_cutime=33, tms_cstime=26}) = 18446744071580810102
> > > > > ---
> > > > > > times({tms_utime=22, tms_stime=17, tms_cutime=33, tms_cstime=26}) = 2166225782
> > > >
> > > > Looks like a sign extension bug in libc.
> > > > Is there any safe way on x32 to call times(2) directly?
> > >
> > > time_t/clock_t/unsigned long long are 64bit in x32.
> >
> > Yes, but the value returned by times syscall in this case is 2166225782.
> > I suppose it's libc that sign-extended 2166225782 to 18446744071580810102.
> > That's why I'd like to avoid libc wrapper and call times syscall
> > directly. Unfortunately, syscall() returns long which is not appropriate
> > for times syscall on x32.
>
> yes, it looks like a bug in glibc. i'll follow up with them.
>
> wrt syscall, i vaguely recall i raised that issue a while back,
> but not sure what happened to it. i'll have to dig it up again.
I'm going to apply the following workaround for this libc bug.
Or is it too good for x32?
--- a/tests/times.c
+++ b/tests/times.c
@@ -69,9 +69,29 @@ main (void)
* prefer direct times syscall over libc's times function because
* the latter is more prone to return value truncation.
*/
-#if !defined __NR_times \
- || defined LINUX_MIPSN32 \
- || defined __x86_64__ && defined __ILP32__
+#undef USE_LIBC_SYSCALL
+#if defined __NR_times && \
+ !defined(LINUX_MIPSN32) && \
+ !(defined __x86_64__ && defined __ILP32__)
+# define USE_LIBC_SYSCALL 1
+#endif
+
+#if defined USE_LIBC_SYSCALL
+ long res = syscall(__NR_times, &tbuf);
+
+ if (-1L == res)
+ return 77;
+ else
+ llres = (unsigned long) res;
+#elif defined __NR_times && defined __x86_64__ && defined __ILP32__
+ register long arg asm("rdi") = (long) &tbuf;
+ asm volatile("syscall\n\t"
+ : "=a"(llres)
+ : "0"(__NR_times), "r"(arg)
+ : "memory", "cc", "r11", "cx");
+ if (llres > 0xfffffffffffff000)
+ return 77;
+#else
clock_t res = times(&tbuf);
if ((clock_t) -1 == res)
@@ -80,13 +100,6 @@ main (void)
llres = (unsigned long) res;
else
llres = res;
-#else
- long res = syscall(__NR_times, &tbuf);
-
- if (-1L == res)
- return 77;
- else
- llres = (unsigned long) res;
#endif
printf("times({tms_utime=%llu, tms_stime=%llu, ",
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20151215/55f337ed/attachment.bin>
More information about the Strace-devel
mailing list