From f53c4d1d1e3fef4fbca3b2482982d042301d815d Mon Sep 17 00:00:00 2001 From: manu Date: Wed, 9 Nov 2005 14:52:18 +0000 Subject: [PATCH] Prevent integer overflow in timout calculation. changed DEBUG_LINUX to DEBUG_LINUX_FUTEX so that we have less debug messages on the console --- sys/compat/linux/common/linux_futex.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sys/compat/linux/common/linux_futex.c b/sys/compat/linux/common/linux_futex.c index 03d7f666ea5c..3756314aebba 100644 --- a/sys/compat/linux/common/linux_futex.c +++ b/sys/compat/linux/common/linux_futex.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_futex.c,v 1.3 2005/11/08 21:28:49 manu Exp $ */ +/* $NetBSD: linux_futex.c,v 1.4 2005/11/09 14:52:18 manu Exp $ */ /*- * Copyright (c) 2005 Emmanuel Dreyfus, all rights reserved. @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(1, "$NetBSD: linux_futex.c,v 1.3 2005/11/08 21:28:49 manu Exp $"); +__KERNEL_RCSID(1, "$NetBSD: linux_futex.c,v 1.4 2005/11/09 14:52:18 manu Exp $"); #include #include @@ -118,20 +118,20 @@ linux_sys_futex(l, v, retval) return error; } -#ifdef DEBUG_LINUX +#ifdef DEBUG_LINUX_FUTEX printf("FUTEX_WAIT %d.%d: val = %d, uaddr = %p, " "*uaddr = %d, timeout = %d.%09ld\n", l->l_proc->p_pid, l->l_lid, SCARG(uap, val), SCARG(uap, uaddr), val, timeout.tv_sec, timeout.tv_nsec); #endif - timeout_hz = (timeout.tv_sec * hz) - + ((timeout.tv_nsec * hz) / 1000000000); + timeout_hz = + mstohz(timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000); f = futex_get(SCARG(uap, uaddr)); ret = futex_sleep(f, l, timeout_hz); futex_put(f); -#ifdef DEBUG_LINUX +#ifdef DEBUG_LINUX_FUTEX printf("FUTEX_WAIT %d.%d: uaddr = %p, " "ret = %d\n", l->l_proc->p_pid, l->l_lid, SCARG(uap, uaddr), ret); @@ -145,14 +145,16 @@ linux_sys_futex(l, v, retval) return EINTR; break; case 0: /* FUTEX_WAKE received */ -#ifdef DEBUG_LINUX +#ifdef DEBUG_LINUX_FUTEX printf("FUTEX_WAIT %d.%d: uaddr = %p, got FUTEX_WAKE\n", l->l_proc->p_pid, l->l_lid, SCARG(uap, uaddr)); #endif return 0; break; default: +#ifdef DEBUG_LINUX_FUTEX printf("FUTEX_WAIT: unexpected ret = %d\n", ret); +#endif break; } @@ -165,7 +167,7 @@ linux_sys_futex(l, v, retval) * corresponding to the same mapped memory in the sleeping * and the waker process. */ -#ifdef DEBUG_LINUX +#ifdef DEBUG_LINUX_FUTEX printf("FUTEX_WAKE %d.%d: uaddr = %p, val = %d\n", l->l_proc->p_pid, l->l_lid, SCARG(uap, uaddr), SCARG(uap, val));