diff options
author | Christoph Hellwig <hch@lst.de> | 2008-10-16 01:02:06 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-16 14:21:33 -0400 |
commit | b418da16dd44810e5d5a22bba377cca80512a524 (patch) | |
tree | 20ac32ea027bb8d978a22fbfaf6580fd34518aa5 /kernel/compat.c | |
parent | f7a5000f7a8924e9c5fad1801616601d6dc65a17 (diff) |
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>
Diffstat (limited to 'kernel/compat.c')
-rw-r--r-- | kernel/compat.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/kernel/compat.c b/kernel/compat.c index 32c254a8ab9a..143990e48cb9 100644 --- a/kernel/compat.c +++ b/kernel/compat.c | |||
@@ -26,6 +26,64 @@ | |||
26 | 26 | ||
27 | #include <asm/uaccess.h> | 27 | #include <asm/uaccess.h> |
28 | 28 | ||
29 | /* | ||
30 | * Note that the native side is already converted to a timespec, because | ||
31 | * that's what we want anyway. | ||
32 | */ | ||
33 | static int compat_get_timeval(struct timespec *o, | ||
34 | struct compat_timeval __user *i) | ||
35 | { | ||
36 | long usec; | ||
37 | |||
38 | if (get_user(o->tv_sec, &i->tv_sec) || | ||
39 | get_user(usec, &i->tv_usec)) | ||
40 | return -EFAULT; | ||
41 | o->tv_nsec = usec * 1000; | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | static int compat_put_timeval(struct compat_timeval __user *o, | ||
46 | struct timeval *i) | ||
47 | { | ||
48 | return (put_user(i->tv_sec, &o->tv_sec) || | ||
49 | put_user(i->tv_usec, &o->tv_usec)) ? -EFAULT : 0; | ||
50 | } | ||
51 | |||
52 | asmlinkage long compat_sys_gettimeofday(struct compat_timeval __user *tv, | ||
53 | struct timezone __user *tz) | ||
54 | { | ||
55 | if (tv) { | ||
56 | struct timeval ktv; | ||
57 | do_gettimeofday(&ktv); | ||
58 | if (compat_put_timeval(tv, &ktv)) | ||
59 | return -EFAULT; | ||
60 | } | ||
61 | if (tz) { | ||
62 | if (copy_to_user(tz, &sys_tz, sizeof(sys_tz))) | ||
63 | return -EFAULT; | ||
64 | } | ||
65 | |||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | asmlinkage long compat_sys_settimeofday(struct compat_timeval __user *tv, | ||
70 | struct timezone __user *tz) | ||
71 | { | ||
72 | struct timespec kts; | ||
73 | struct timezone ktz; | ||
74 | |||
75 | if (tv) { | ||
76 | if (compat_get_timeval(&kts, tv)) | ||
77 | return -EFAULT; | ||
78 | } | ||
79 | if (tz) { | ||
80 | if (copy_from_user(&ktz, tz, sizeof(ktz))) | ||
81 | return -EFAULT; | ||
82 | } | ||
83 | |||
84 | return do_sys_settimeofday(tv ? &kts : NULL, tz ? &ktz : NULL); | ||
85 | } | ||
86 | |||
29 | int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) | 87 | int get_compat_timespec(struct timespec *ts, const struct compat_timespec __user *cts) |
30 | { | 88 | { |
31 | return (!access_ok(VERIFY_READ, cts, sizeof(*cts)) || | 89 | return (!access_ok(VERIFY_READ, cts, sizeof(*cts)) || |