1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-13 10:02:38 +00:00

MFP4: 109655

- Move linux_nanosleep() from src/sys/amd64/linux32/linux32_machdep.c to
src/sys/compat/linux/linux_time.c.
- Validate timespec ranges before use as Linux kernel does.
- Fix l_timespec structure.
- Clean up style(9) nits.
This commit is contained in:
Jung-uk Kim 2006-12-20 20:17:35 +00:00
parent 34ec45fe0d
commit 77424f4177
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=165408
4 changed files with 72 additions and 55 deletions

View File

@ -171,8 +171,8 @@ struct l_rusage {
* stat family of syscalls
*/
struct l_timespec {
l_ulong tv_sec;
l_ulong tv_nsec;
l_time_t tv_sec;
l_long tv_nsec;
} __packed;
struct l_newstat {

View File

@ -1048,27 +1048,6 @@ linux_gettimeofday(struct thread *td, struct linux_gettimeofday_args *uap)
return (error);
}
int
linux_nanosleep(struct thread *td, struct linux_nanosleep_args *uap)
{
struct timespec rqt, rmt;
struct l_timespec ats32;
int error;
error = copyin(uap->rqtp, &ats32, sizeof(ats32));
if (error != 0)
return (error);
rqt.tv_sec = ats32.tv_sec;
rqt.tv_nsec = ats32.tv_nsec;
error = kern_nanosleep(td, &rqt, &rmt);
if (uap->rmtp != NULL) {
ats32.tv_sec = rmt.tv_sec;
ats32.tv_nsec = rmt.tv_nsec;
error = copyout(&ats32, uap->rmtp, sizeof(ats32));
}
return (error);
}
int
linux_getrusage(struct thread *td, struct linux_getrusage_args *uap)
{

View File

@ -65,7 +65,7 @@ __KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.14 2006/05/14 03:40:54 christos Exp
static void native_to_linux_timespec(struct l_timespec *,
struct timespec *);
static void linux_to_native_timespec(struct timespec *,
static int linux_to_native_timespec(struct timespec *,
struct l_timespec *);
static int linux_to_native_clockid(clockid_t *, clockid_t);
@ -76,11 +76,15 @@ native_to_linux_timespec(struct l_timespec *ltp, struct timespec *ntp)
ltp->tv_nsec = ntp->tv_nsec;
}
static void
static int
linux_to_native_timespec(struct timespec *ntp, struct l_timespec *ltp)
{
if (ltp->tv_sec < 0 || ltp->tv_nsec > (l_long)999999999L)
return (EINVAL);
ntp->tv_sec = ltp->tv_sec;
ntp->tv_nsec = ltp->tv_nsec;
return (0);
}
static int
@ -97,10 +101,12 @@ linux_to_native_clockid(clockid_t *n, clockid_t l)
case LINUX_CLOCK_THREAD_CPUTIME_ID:
case LINUX_CLOCK_REALTIME_HR:
case LINUX_CLOCK_MONOTONIC_HR:
return EINVAL;
default:
return (EINVAL);
break;
}
return 0;
return (0);
}
int
@ -113,15 +119,13 @@ linux_clock_gettime(struct thread *td, struct linux_clock_gettime_args *args)
error = linux_to_native_clockid(&nwhich, args->which);
if (error != 0)
return error;
return (error);
error = kern_clock_gettime(td, nwhich, &tp);
if (error != 0)
return error;
return (error);
native_to_linux_timespec(&lts, &tp);
return copyout(&lts, args->tp, sizeof lts);
return (copyout(&lts, args->tp, sizeof lts));
}
int
@ -134,15 +138,15 @@ linux_clock_settime(struct thread *td, struct linux_clock_settime_args *args)
error = linux_to_native_clockid(&nwhich, args->which);
if (error != 0)
return error;
return (error);
error = copyin(args->tp, &lts, sizeof lts);
if (error != 0)
return error;
return (error);
error = linux_to_native_timespec(&ts, &lts);
if (error != 0)
return (error);
linux_to_native_timespec(&ts, &lts);
return kern_clock_settime(td, nwhich, &ts);
return (kern_clock_settime(td, nwhich, &ts));
}
int
@ -154,19 +158,51 @@ linux_clock_getres(struct thread *td, struct linux_clock_getres_args *args)
clockid_t nwhich = 0; /* XXX: GCC */
if (args->tp == NULL)
return (0);
return (0);
error = linux_to_native_clockid(&nwhich, args->which);
if (error != 0)
return error;
return (error);
error = kern_clock_getres(td, nwhich, &ts);
if (error != 0)
return error;
return (error);
native_to_linux_timespec(&lts, &ts);
return copyout(&lts, args->tp, sizeof lts);
return (copyout(&lts, args->tp, sizeof lts));
}
int
linux_nanosleep(struct thread *td, struct linux_nanosleep_args *args)
{
struct timespec *rmtp;
struct l_timespec lrqts, lrmts;
struct timespec rqts, rmts;
int error;
error = copyin(args->rqtp, &lrqts, sizeof lrqts);
if (error != 0)
return (error);
if (args->rmtp != NULL)
rmtp = &rmts;
else
rmtp = NULL;
error = linux_to_native_timespec(&rqts, &lrqts);
if (error != 0)
return (error);
error = kern_nanosleep(td, &rqts, rmtp);
if (error != 0)
return (error);
if (args->rmtp != NULL) {
native_to_linux_timespec(&lrmts, rmtp);
error = copyout(&lrmts, args->rmtp, sizeof(lrmts));
if (error != 0)
return (error);
}
return (0);
}
int
@ -178,31 +214,33 @@ linux_clock_nanosleep(struct thread *td, struct linux_clock_nanosleep_args *args
int error;
if (args->flags != 0)
return EINVAL; /* XXX deal with TIMER_ABSTIME */
return (EINVAL); /* XXX deal with TIMER_ABSTIME */
if (args->which != LINUX_CLOCK_REALTIME)
return EINVAL;
return (EINVAL);
error = copyin(args->rqtp, &lrqts, sizeof lrqts);
if (error != 0)
return error;
return (error);
if (args->rmtp != NULL)
rmtp = &rmts;
else
rmtp = NULL;
linux_to_native_timespec(&rqts, &lrqts);
error = linux_to_native_timespec(&rqts, &lrqts);
if (error != 0)
return (error);
error = kern_nanosleep(td, &rqts, rmtp);
if (error != 0)
return error;
return (error);
if (args->rmtp != NULL) {
native_to_linux_timespec(&lrmts, rmtp);
error = copyout(&lrmts, args->rmtp, sizeof lrmts );
if (error != 0)
return error;
return (error);
}
return 0;
return (0);
}

View File

@ -146,8 +146,8 @@ struct l_rlimit {
* stat family of syscalls
*/
struct l_timespec {
l_ulong tv_sec;
l_ulong tv_nsec;
l_time_t tv_sec;
l_long tv_nsec;
};
struct l_newstat {