PERFORCE change 109655 for review
Jung-uk Kim
jkim at FreeBSD.org
Fri Nov 10 00:00:31 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=109655
Change 109655 by jkim at jkim_hammer on 2006/11/09 23:59:35
- Move linux_nanosleep() from amd64/linux32 to linux_time.c.
- Validate timespec before use as Linux kernel does.
- Fix l_timespec structure.
- Clean up styles.
This fixes LTP test case nanosleep04 (at least on amd64).
Note the test was not really blocked. Negative -> unsigned long
casting made huge number and it was normally(!) sleeping very long
time. ;-)
Affected files ...
.. //depot/projects/linuxolator/src/sys/amd64/linux32/linux.h#8 edit
.. //depot/projects/linuxolator/src/sys/amd64/linux32/linux32_machdep.c#14 edit
.. //depot/projects/linuxolator/src/sys/compat/linux/linux_time.c#2 edit
.. //depot/projects/linuxolator/src/sys/i386/linux/linux.h#7 edit
.. //depot/projects/linuxolator/src/sys/i386/linux/linux_proto.h#10 edit
.. //depot/projects/linuxolator/src/sys/i386/linux/linux_syscall.h#10 edit
.. //depot/projects/linuxolator/src/sys/i386/linux/linux_sysent.c#10 edit
.. //depot/projects/linuxolator/src/sys/i386/linux/syscalls.master#9 edit
Differences ...
==== //depot/projects/linuxolator/src/sys/amd64/linux32/linux.h#8 (text+ko) ====
@@ -173,8 +173,8 @@
* 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 {
==== //depot/projects/linuxolator/src/sys/amd64/linux32/linux32_machdep.c#14 (text+ko) ====
@@ -1100,27 +1100,6 @@
}
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)
{
struct l_rusage s32;
==== //depot/projects/linuxolator/src/sys/compat/linux/linux_time.c#2 (text+ko) ====
@@ -65,7 +65,7 @@
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 @@
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 @@
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 @@
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(<s, &tp);
- return copyout(<s, args->tp, sizeof lts);
+ return (copyout(<s, args->tp, sizeof lts));
}
int
@@ -134,15 +138,15 @@
error = linux_to_native_clockid(&nwhich, args->which);
if (error != 0)
- return error;
-
+ return (error);
error = copyin(args->tp, <s, sizeof lts);
if (error != 0)
- return error;
+ return (error);
+ error = linux_to_native_timespec(&ts, <s);
+ if (error != 0)
+ return (error);
- linux_to_native_timespec(&ts, <s);
-
- return kern_clock_settime(td, nwhich, &ts);
+ return (kern_clock_settime(td, nwhich, &ts));
}
int
@@ -154,19 +158,51 @@
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);
+ native_to_linux_timespec(<s, &ts);
+
+ return (copyout(<s, 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 = kern_clock_getres(td, nwhich, &ts);
+ 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);
+ }
- native_to_linux_timespec(<s, &ts);
-
- return copyout(<s, args->tp, sizeof lts);
+ return (0);
}
int
@@ -178,31 +214,33 @@
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);
}
==== //depot/projects/linuxolator/src/sys/i386/linux/linux.h#7 (text+ko) ====
@@ -146,8 +146,8 @@
* 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 {
==== //depot/projects/linuxolator/src/sys/i386/linux/linux_proto.h#10 (text+ko) ====
@@ -475,6 +475,10 @@
struct linux_sched_get_priority_min_args {
char policy_l_[PADL_(l_int)]; l_int policy; char policy_r_[PADR_(l_int)];
};
+struct linux_nanosleep_args {
+ char rqtp_l_[PADL_(const struct l_timespec *)]; const struct l_timespec * rqtp; char rqtp_r_[PADR_(const struct l_timespec *)];
+ char rmtp_l_[PADL_(struct l_timespec *)]; struct l_timespec * rmtp; char rmtp_r_[PADR_(struct l_timespec *)];
+};
struct linux_mremap_args {
char addr_l_[PADL_(l_ulong)]; l_ulong addr; char addr_r_[PADR_(l_ulong)];
char old_len_l_[PADL_(l_ulong)]; l_ulong old_len; char old_len_r_[PADR_(l_ulong)];
@@ -1068,6 +1072,7 @@
int linux_sched_getscheduler(struct thread *, struct linux_sched_getscheduler_args *);
int linux_sched_get_priority_max(struct thread *, struct linux_sched_get_priority_max_args *);
int linux_sched_get_priority_min(struct thread *, struct linux_sched_get_priority_min_args *);
+int linux_nanosleep(struct thread *, struct linux_nanosleep_args *);
int linux_mremap(struct thread *, struct linux_mremap_args *);
int linux_setresuid16(struct thread *, struct linux_setresuid16_args *);
int linux_getresuid16(struct thread *, struct linux_getresuid16_args *);
@@ -1319,6 +1324,7 @@
#define LINUX_SYS_AUE_linux_sched_getscheduler AUE_SCHED_GETSCHEDULER
#define LINUX_SYS_AUE_linux_sched_get_priority_max AUE_SCHED_GET_PRIORITY_MAX
#define LINUX_SYS_AUE_linux_sched_get_priority_min AUE_SCHED_GET_PRIORITY_MIN
+#define LINUX_SYS_AUE_linux_nanosleep AUE_NULL
#define LINUX_SYS_AUE_linux_mremap AUE_NULL
#define LINUX_SYS_AUE_linux_setresuid16 AUE_SETRESUID
#define LINUX_SYS_AUE_linux_getresuid16 AUE_GETRESUID
==== //depot/projects/linuxolator/src/sys/i386/linux/linux_syscall.h#10 (text+ko) ====
@@ -156,7 +156,7 @@
#define LINUX_SYS_linux_sched_get_priority_max 159
#define LINUX_SYS_linux_sched_get_priority_min 160
#define LINUX_SYS_sched_rr_get_interval 161
-#define LINUX_SYS_nanosleep 162
+#define LINUX_SYS_linux_nanosleep 162
#define LINUX_SYS_linux_mremap 163
#define LINUX_SYS_linux_setresuid16 164
#define LINUX_SYS_linux_getresuid16 165
==== //depot/projects/linuxolator/src/sys/i386/linux/linux_sysent.c#10 (text+ko) ====
@@ -181,7 +181,7 @@
{ AS(linux_sched_get_priority_max_args), (sy_call_t *)linux_sched_get_priority_max, AUE_SCHED_GET_PRIORITY_MAX, NULL, 0, 0 }, /* 159 = linux_sched_get_priority_max */
{ AS(linux_sched_get_priority_min_args), (sy_call_t *)linux_sched_get_priority_min, AUE_SCHED_GET_PRIORITY_MIN, NULL, 0, 0 }, /* 160 = linux_sched_get_priority_min */
{ AS(sched_rr_get_interval_args), (sy_call_t *)sched_rr_get_interval, AUE_SCHED_RR_GET_INTERVAL, NULL, 0, 0 }, /* 161 = sched_rr_get_interval */
- { AS(nanosleep_args), (sy_call_t *)nanosleep, AUE_NULL, NULL, 0, 0 }, /* 162 = nanosleep */
+ { AS(linux_nanosleep_args), (sy_call_t *)linux_nanosleep, AUE_NULL, NULL, 0, 0 }, /* 162 = linux_nanosleep */
{ AS(linux_mremap_args), (sy_call_t *)linux_mremap, AUE_NULL, NULL, 0, 0 }, /* 163 = linux_mremap */
{ AS(linux_setresuid16_args), (sy_call_t *)linux_setresuid16, AUE_SETRESUID, NULL, 0, 0 }, /* 164 = linux_setresuid16 */
{ AS(linux_getresuid16_args), (sy_call_t *)linux_getresuid16, AUE_GETRESUID, NULL, 0, 0 }, /* 165 = linux_getresuid16 */
==== //depot/projects/linuxolator/src/sys/i386/linux/syscalls.master#9 (text+ko) ====
@@ -282,9 +282,9 @@
l_int policy); }
161 AUE_SCHED_RR_GET_INTERVAL NOPROTO { int sched_rr_get_interval(l_pid_t pid, \
struct l_timespec *interval); }
-162 AUE_NULL NOPROTO { int nanosleep( \
- const struct timespec *rqtp, \
- struct timespec *rmtp); }
+162 AUE_NULL STD { int linux_nanosleep( \
+ const struct l_timespec *rqtp, \
+ struct l_timespec *rmtp); }
163 AUE_NULL STD { int linux_mremap(l_ulong addr, \
l_ulong old_len, l_ulong new_len, \
l_ulong flags, l_ulong new_addr); }
More information about the p4-projects
mailing list