linux32_time.c revision 1.8 1 /* $NetBSD: linux32_time.c,v 1.8 2007/03/04 06:01:25 christos Exp $ */
2
3 /*-
4 * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Emmanuel Dreyfus
17 * 4. The name of the author may not be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE THE AUTHOR AND CONTRIBUTORS ``AS IS''
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/cdefs.h>
35
36 __KERNEL_RCSID(0, "$NetBSD: linux32_time.c,v 1.8 2007/03/04 06:01:25 christos Exp $");
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/fstypes.h>
41 #include <sys/signal.h>
42 #include <sys/dirent.h>
43 #include <sys/kauth.h>
44 #include <sys/kernel.h>
45 #include <sys/fcntl.h>
46 #include <sys/select.h>
47 #include <sys/proc.h>
48 #include <sys/ucred.h>
49 #include <sys/swap.h>
50
51 #include <machine/types.h>
52
53 #include <sys/syscallargs.h>
54
55 #include <compat/netbsd32/netbsd32.h>
56 #include <compat/netbsd32/netbsd32_conv.h>
57 #include <compat/netbsd32/netbsd32_syscallargs.h>
58
59 #include <compat/linux/common/linux_types.h>
60 #include <compat/linux/common/linux_signal.h>
61 #include <compat/linux/common/linux_machdep.h>
62 #include <compat/linux/common/linux_misc.h>
63 #include <compat/linux/common/linux_oldolduname.h>
64 #include <compat/linux/linux_syscallargs.h>
65
66 #include <compat/linux32/common/linux32_types.h>
67 #include <compat/linux32/common/linux32_signal.h>
68 #include <compat/linux32/common/linux32_machdep.h>
69 #include <compat/linux32/common/linux32_sysctl.h>
70 #include <compat/linux32/common/linux32_socketcall.h>
71 #include <compat/linux32/linux32_syscallargs.h>
72
73 extern struct timezone linux_sys_tz;
74 int
75 linux32_sys_gettimeofday(l, v, retval)
76 struct lwp *l;
77 void *v;
78 register_t *retval;
79 {
80 struct linux32_sys_gettimeofday_args /* {
81 syscallarg(netbsd32_timevalp_t) tp;
82 syscallarg(netbsd32_timezonep_t) tzp;
83 } */ *uap = v;
84 struct timeval tv;
85 struct netbsd32_timeval tv32;
86 int error;
87
88 if (NETBSD32PTR64(SCARG(uap, tp)) != NULL) {
89 microtime(&tv);
90 netbsd32_from_timeval(&tv, &tv32);
91 if ((error = copyout(&tv32,
92 (void *)NETBSD32PTR64(SCARG(uap, tp)),
93 sizeof(tv32))) != 0)
94 return error;
95 }
96
97 /* timezone size does not change */
98 if (NETBSD32PTR64(SCARG(uap, tzp)) != NULL) {
99 if ((error = copyout(&linux_sys_tz,
100 (void *)NETBSD32PTR64(SCARG(uap, tzp)),
101 sizeof(linux_sys_tz))) != 0)
102 return error;
103 }
104
105 return 0;
106 }
107
108 int
109 linux32_sys_settimeofday(l, v, retval)
110 struct lwp *l;
111 void *v;
112 register_t *retval;
113 {
114 struct linux32_sys_settimeofday_args /* {
115 syscallarg(netbsd32_timevalp_t) tp;
116 syscallarg(netbsd32_timezonep_t) tzp;
117 } */ *uap = v;
118 struct linux_sys_settimeofday_args ua;
119
120 NETBSD32TOP_UAP(tp, struct timeval);
121 NETBSD32TOP_UAP(tzp, struct timezone);
122
123 return linux_sys_settimeofday(l, &ua, retval);
124 }
125
126 int
127 linux32_sys_time(l, v, retval)
128 struct lwp *l;
129 void *v;
130 register_t *retval;
131 {
132 struct linux32_sys_time_args /* {
133 syscallcarg(linux32_timep_t) t;
134 } */ *uap = v;
135 struct timeval atv;
136 linux32_time_t tt;
137 int error;
138
139 microtime(&atv);
140
141 tt = (linux32_time_t)atv.tv_sec;
142
143 if (SCARG(uap, t) && (error = copyout(&tt,
144 NETBSD32PTR64(SCARG(uap, t)), sizeof(tt))))
145 return error;
146
147 retval[0] = tt;
148
149 return 0;
150 }
151
152
153 int
154 linux32_sys_times(l, v, retval)
155 struct lwp *l;
156 void *v;
157 register_t *retval;
158 {
159 struct linux32_sys_times_args /* {
160 syscallarg(linux32_tmsp_t) tms;
161 } */ *uap = v;
162 struct linux32_tms ltms32;
163 struct linux_tms ltms;
164 struct linux_tms *ltmsp;
165 struct linux_sys_times_args ua;
166 void *sg = stackgap_init(l->l_proc, 0);
167 int error;
168
169 ltmsp = stackgap_alloc(l->l_proc, &sg, sizeof(*ltmsp));
170 SCARG(&ua, tms) = (struct times *)ltmsp;
171
172 if ((error = linux_sys_times(l, &ua, retval)) != 0)
173 return error;
174
175 if ((error = copyin(ltmsp, <ms, sizeof(ltms))) != 0)
176 return error;
177
178 ltms32.ltms32_utime = (linux32_clock_t)ltms.ltms_utime;
179 ltms32.ltms32_stime = (linux32_clock_t)ltms.ltms_stime;
180 ltms32.ltms32_cutime = (linux32_clock_t)ltms.ltms_cutime;
181 ltms32.ltms32_cstime = (linux32_clock_t)ltms.ltms_cstime;
182
183 if ((error = copyout(<ms32,
184 NETBSD32PTR64(SCARG(uap, tms)), sizeof(ltms32))) != 0)
185 return error;
186
187 return 0;
188 }
189
190 int
191 linux32_sys_stime(l, v, retval)
192 struct lwp *l;
193 void *v;
194 register_t *retval;
195 {
196 struct linux32_sys_stime_args /* {
197 syscallarg(linux32_timep_t) t;
198 } */ *uap = v;
199 struct timespec ts;
200 linux32_time_t tt32;
201 int error;
202
203 if ((error = kauth_authorize_system(l->l_cred,
204 KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_SYSTEM, NULL, NULL,
205 NULL)) != 0)
206 return error;
207
208 if ((error = copyin(&tt32,
209 NETBSD32PTR64(SCARG(uap, t)),
210 sizeof tt32)) != 0)
211
212 ts.tv_sec = (long)tt32;
213 ts.tv_nsec = 0;
214
215 return settime(l->l_proc, &ts);
216 }
217
218 int
219 linux32_sys_utime(l, v, retval)
220 struct lwp *l;
221 void *v;
222 register_t *retval;
223 {
224 struct linux32_sys_utime_args /* {
225 syscallarg(const netbsd32_charp) path;
226 syscallarg(linux32_utimbufp_t) times;
227 } */ *uap = v;
228 struct proc *p = l->l_proc;
229 void *sg = stackgap_init(p, 0);
230 struct sys_utimes_args ua;
231 struct timeval tv[2], *tvp;
232 struct linux32_utimbuf lut;
233 int error;
234
235 NETBSD32TOP_UAP(path, const char);
236 CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
237
238
239 if (NETBSD32PTR64(SCARG(uap, times)) != NULL) {
240 if ((error = copyin(NETBSD32PTR64(SCARG(uap, times)),
241 &lut, sizeof lut)))
242 return error;
243
244 tv[0].tv_sec = (long)lut.l_actime;
245 tv[0].tv_usec = 0;
246 tv[1].tv_sec = (long)lut.l_modtime;
247 tv[1].tv_usec = 0;
248
249 tvp = (struct timeval *) stackgap_alloc(p, &sg, sizeof(tv));
250
251 if ((error = copyout(tv, tvp, sizeof(tv))))
252 return error;
253 SCARG(&ua, tptr) = tvp;
254 } else {
255 SCARG(&ua, tptr) = NULL;
256 }
257
258 return sys_utimes(l, &ua, retval);
259 }
260