Skip to content

Commit b418da1

Browse files
Christoph Hellwigtorvalds
authored andcommitted
compat: generic compat get/settimeofday
Nothing arch specific in get/settimeofday. The details of the timeval conversion varied a little from arch to arch, but all with the same results. Also add an extern declaration for sys_tz to linux/time.h because externs in .c files are fowned upon. I'll kill the externs in various other files in a sparate patch. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: David S. Miller <davem@davemloft.net> [ sparc bits ] Cc: "Luck, Tony" <tony.luck@intel.com> Cc: Ralf Baechle <ralf@linux-mips.org> Acked-by: Kyle McMartin <kyle@mcmartin.ca> Cc: Matthew Wilcox <matthew@wil.cx> Cc: Grant Grundler <grundler@parisc-linux.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent f7a5000 commit b418da1

19 files changed

Lines changed: 85 additions & 460 deletions

File tree

‎arch/ia64/ia32/ia32_entry.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ ia32_syscall_table:
251251
data8 compat_sys_setrlimit /* 75 */
252252
data8 compat_sys_old_getrlimit
253253
data8 compat_sys_getrusage
254-
data8 sys32_gettimeofday
255-
data8 sys32_settimeofday
254+
data8 compat_sys_gettimeofday
255+
data8 compat_sys_settimeofday
256256
data8 sys32_getgroups16 /* 80 */
257257
data8 sys32_setgroups16
258258
data8 sys32_old_select

‎arch/ia64/ia32/sys_ia32.c‎

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,68 +1113,12 @@ sys32_pipe (int __user *fd)
11131113
return retval;
11141114
}
11151115

1116-
static inline long
1117-
get_tv32 (struct timeval *o, struct compat_timeval __user *i)
1118-
{
1119-
return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
1120-
(__get_user(o->tv_sec, &i->tv_sec) | __get_user(o->tv_usec, &i->tv_usec)));
1121-
}
1122-
1123-
static inline long
1124-
put_tv32 (struct compat_timeval __user *o, struct timeval *i)
1125-
{
1126-
return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
1127-
(__put_user(i->tv_sec, &o->tv_sec) | __put_user(i->tv_usec, &o->tv_usec)));
1128-
}
1129-
11301116
asmlinkage unsigned long
11311117
sys32_alarm (unsigned int seconds)
11321118
{
11331119
return alarm_setitimer(seconds);
11341120
}
11351121

1136-
/* Translations due to time_t size differences. Which affects all
1137-
sorts of things, like timeval and itimerval. */
1138-
1139-
extern struct timezone sys_tz;
1140-
1141-
asmlinkage long
1142-
sys32_gettimeofday (struct compat_timeval __user *tv, struct timezone __user *tz)
1143-
{
1144-
if (tv) {
1145-
struct timeval ktv;
1146-
do_gettimeofday(&ktv);
1147-
if (put_tv32(tv, &ktv))
1148-
return -EFAULT;
1149-
}
1150-
if (tz) {
1151-
if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
1152-
return -EFAULT;
1153-
}
1154-
return 0;
1155-
}
1156-
1157-
asmlinkage long
1158-
sys32_settimeofday (struct compat_timeval __user *tv, struct timezone __user *tz)
1159-
{
1160-
struct timeval ktv;
1161-
struct timespec kts;
1162-
struct timezone ktz;
1163-
1164-
if (tv) {
1165-
if (get_tv32(&ktv, tv))
1166-
return -EFAULT;
1167-
kts.tv_sec = ktv.tv_sec;
1168-
kts.tv_nsec = ktv.tv_usec * 1000;
1169-
}
1170-
if (tz) {
1171-
if (copy_from_user(&ktz, tz, sizeof(ktz)))
1172-
return -EFAULT;
1173-
}
1174-
1175-
return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
1176-
}
1177-
11781122
struct sel_arg_struct {
11791123
unsigned int n;
11801124
unsigned int inp;

‎arch/mips/kernel/linux32.c‎

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -133,72 +133,6 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long __dummy,
133133
return sys_ftruncate(fd, merge_64(a2, a3));
134134
}
135135

136-
static inline long
137-
get_tv32(struct timeval *o, struct compat_timeval __user *i)
138-
{
139-
return (!access_ok(VERIFY_READ, i, sizeof(*i)) ||
140-
(__get_user(o->tv_sec, &i->tv_sec) |
141-
__get_user(o->tv_usec, &i->tv_usec)));
142-
}
143-
144-
static inline long
145-
put_tv32(struct compat_timeval __user *o, struct timeval *i)
146-
{
147-
return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
148-
(__put_user(i->tv_sec, &o->tv_sec) |
149-
__put_user(i->tv_usec, &o->tv_usec)));
150-
}
151-
152-
extern struct timezone sys_tz;
153-
154-
asmlinkage int
155-
sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
156-
{
157-
if (tv) {
158-
struct timeval ktv;
159-
do_gettimeofday(&ktv);
160-
if (put_tv32(tv, &ktv))
161-
return -EFAULT;
162-
}
163-
if (tz) {
164-
if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
165-
return -EFAULT;
166-
}
167-
return 0;
168-
}
169-
170-
static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
171-
{
172-
long usec;
173-
174-
if (!access_ok(VERIFY_READ, i, sizeof(*i)))
175-
return -EFAULT;
176-
if (__get_user(o->tv_sec, &i->tv_sec))
177-
return -EFAULT;
178-
if (__get_user(usec, &i->tv_usec))
179-
return -EFAULT;
180-
o->tv_nsec = usec * 1000;
181-
return 0;
182-
}
183-
184-
asmlinkage int
185-
sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
186-
{
187-
struct timespec kts;
188-
struct timezone ktz;
189-
190-
if (tv) {
191-
if (get_ts32(&kts, tv))
192-
return -EFAULT;
193-
}
194-
if (tz) {
195-
if (copy_from_user(&ktz, tz, sizeof(ktz)))
196-
return -EFAULT;
197-
}
198-
199-
return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
200-
}
201-
202136
asmlinkage int sys32_llseek(unsigned int fd, unsigned int offset_high,
203137
unsigned int offset_low, loff_t __user * result,
204138
unsigned int origin)

‎arch/mips/kernel/scall64-n32.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ EXPORT(sysn32_call_table)
214214
PTR sys_fchown
215215
PTR sys_lchown
216216
PTR sys_umask
217-
PTR sys32_gettimeofday
217+
PTR compat_sys_gettimeofday
218218
PTR compat_sys_getrlimit /* 6095 */
219219
PTR compat_sys_getrusage
220220
PTR compat_sys_sysinfo
@@ -279,7 +279,7 @@ EXPORT(sysn32_call_table)
279279
PTR sys_chroot
280280
PTR sys_sync
281281
PTR sys_acct
282-
PTR sys32_settimeofday
282+
PTR compat_sys_settimeofday
283283
PTR compat_sys_mount /* 6160 */
284284
PTR sys_umount
285285
PTR sys_swapon

‎arch/mips/kernel/scall64-o32.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ sys_call_table:
283283
PTR compat_sys_setrlimit /* 4075 */
284284
PTR compat_sys_getrlimit
285285
PTR compat_sys_getrusage
286-
PTR sys32_gettimeofday
287-
PTR sys32_settimeofday
286+
PTR compat_sys_gettimeofday
287+
PTR compat_sys_settimeofday
288288
PTR sys_getgroups /* 4080 */
289289
PTR sys_setgroups
290290
PTR sys_ni_syscall /* old_select */

‎arch/parisc/kernel/sys_parisc32.c‎

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -179,64 +179,6 @@ asmlinkage long sys32_sched_rr_get_interval(pid_t pid,
179179
return ret;
180180
}
181181

182-
static int
183-
put_compat_timeval(struct compat_timeval __user *u, struct timeval *t)
184-
{
185-
struct compat_timeval t32;
186-
t32.tv_sec = t->tv_sec;
187-
t32.tv_usec = t->tv_usec;
188-
return copy_to_user(u, &t32, sizeof t32);
189-
}
190-
191-
static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
192-
{
193-
long usec;
194-
195-
if (__get_user(o->tv_sec, &i->tv_sec))
196-
return -EFAULT;
197-
if (__get_user(usec, &i->tv_usec))
198-
return -EFAULT;
199-
o->tv_nsec = usec * 1000;
200-
return 0;
201-
}
202-
203-
asmlinkage int
204-
sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
205-
{
206-
extern void do_gettimeofday(struct timeval *tv);
207-
208-
if (tv) {
209-
struct timeval ktv;
210-
do_gettimeofday(&ktv);
211-
if (put_compat_timeval(tv, &ktv))
212-
return -EFAULT;
213-
}
214-
if (tz) {
215-
extern struct timezone sys_tz;
216-
if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
217-
return -EFAULT;
218-
}
219-
return 0;
220-
}
221-
222-
asmlinkage
223-
int sys32_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
224-
{
225-
struct timespec kts;
226-
struct timezone ktz;
227-
228-
if (tv) {
229-
if (get_ts32(&kts, tv))
230-
return -EFAULT;
231-
}
232-
if (tz) {
233-
if (copy_from_user(&ktz, tz, sizeof(ktz)))
234-
return -EFAULT;
235-
}
236-
237-
return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
238-
}
239-
240182
/*** copied from mips64 ***/
241183
/*
242184
* Ooo, nasty. We need here to frob 32-bit unsigned longs to

‎arch/parisc/kernel/syscall_table.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@
149149
ENTRY_COMP(getrlimit)
150150
ENTRY_COMP(getrusage)
151151
/* struct timeval and timezone are maybe?? consistent wide and narrow */
152-
ENTRY_DIFF(gettimeofday)
153-
ENTRY_DIFF(settimeofday)
152+
ENTRY_COMP(gettimeofday)
153+
ENTRY_COMP(settimeofday)
154154
ENTRY_SAME(getgroups) /* 80 */
155155
ENTRY_SAME(setgroups)
156156
/* struct socketaddr... */

‎arch/powerpc/kernel/sys_ppc32.c‎

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -71,69 +71,6 @@ asmlinkage long compat_sys_sysfs(u32 option, u32 arg1, u32 arg2)
7171
return sys_sysfs((int)option, arg1, arg2);
7272
}
7373

74-
static inline long get_ts32(struct timespec *o, struct compat_timeval __user *i)
75-
{
76-
long usec;
77-
78-
if (!access_ok(VERIFY_READ, i, sizeof(*i)))
79-
return -EFAULT;
80-
if (__get_user(o->tv_sec, &i->tv_sec))
81-
return -EFAULT;
82-
if (__get_user(usec, &i->tv_usec))
83-
return -EFAULT;
84-
o->tv_nsec = usec * 1000;
85-
return 0;
86-
}
87-
88-
static inline long put_tv32(struct compat_timeval __user *o, struct timeval *i)
89-
{
90-
return (!access_ok(VERIFY_WRITE, o, sizeof(*o)) ||
91-
(__put_user(i->tv_sec, &o->tv_sec) |
92-
__put_user(i->tv_usec, &o->tv_usec)));
93-
}
94-
95-
96-
97-
98-
/* Translations due to time_t size differences. Which affects all
99-
sorts of things, like timeval and itimerval. */
100-
extern struct timezone sys_tz;
101-
102-
asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
103-
{
104-
if (tv) {
105-
struct timeval ktv;
106-
do_gettimeofday(&ktv);
107-
if (put_tv32(tv, &ktv))
108-
return -EFAULT;
109-
}
110-
if (tz) {
111-
if (copy_to_user(tz, &sys_tz, sizeof(sys_tz)))
112-
return -EFAULT;
113-
}
114-
115-
return 0;
116-
}
117-
118-
119-
120-
asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
121-
{
122-
struct timespec kts;
123-
struct timezone ktz;
124-
125-
if (tv) {
126-
if (get_ts32(&kts, tv))
127-
return -EFAULT;
128-
}
129-
if (tz) {
130-
if (copy_from_user(&ktz, tz, sizeof(ktz)))
131-
return -EFAULT;
132-
}
133-
134-
return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL);
135-
}
136-
13774
#ifdef CONFIG_SYSVIPC
13875
long compat_sys_ipc(u32 call, u32 first, u32 second, u32 third, compat_uptr_t ptr,
13976
u32 fifth)

0 commit comments

Comments
 (0)