linux32_time.c revision 1.10 1 /* $NetBSD: linux32_time.c,v 1.10 2007/03/18 21:38:32 dsl 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.10 2007/03/18 21:38:32 dsl 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 (SCARG_P32(uap, tp) != NULL) {
89 microtime(&tv);
90 netbsd32_from_timeval(&tv, &tv32);
91 if ((error = copyout(&tv32, SCARG_P32(uap, tp),
92 sizeof(tv32))) != 0)
93 return error;
94 }
95
96 /* timezone size does not change */
97 if (SCARG_P32(uap, tzp) != NULL) {
98 if ((error = copyout(&linux_sys_tz, SCARG_P32(uap, tzp),
99 sizeof(linux_sys_tz))) != 0)
100 return error;
101 }
102
103 return 0;
104 }
105
106 int
107 linux32_sys_settimeofday(l, v, retval)
108 struct lwp *l;
109 void *v;
110 register_t *retval;
111 {
112 struct linux32_sys_settimeofday_args /* {
113 syscallarg(netbsd32_timevalp_t) tp;
114 syscallarg(netbsd32_timezonep_t) tzp;
115 } */ *uap = v;
116 struct linux_sys_settimeofday_args ua;
117
118 NETBSD32TOP_UAP(tp, struct timeval);
119 NETBSD32TOP_UAP(tzp, struct timezone);
120
121 return linux_sys_settimeofday(l, &ua, retval);
122 }
123
124 int
125 linux32_sys_time(l, v, retval)
126 struct lwp *l;
127 void *v;
128 register_t *retval;
129 {
130 struct linux32_sys_time_args /* {
131 syscallcarg(linux32_timep_t) t;
132 } */ *uap = v;
133 struct timeval atv;
134 linux32_time_t tt;
135 int error;
136
137 microtime(&atv);
138
139 tt = (linux32_time_t)atv.tv_sec;
140
141 if (SCARG_P32(uap, t) && (error = copyout(&tt,
142 SCARG_P32(uap, t), sizeof(tt))))
143 return error;
144
145 retval[0] = tt;
146
147 return 0;
148 }
149
150
151 int
152 linux32_sys_times(l, v, retval)
153 struct lwp *l;
154 void *v;
155 register_t *retval;
156 {
157 struct linux32_sys_times_args /* {
158 syscallarg(linux32_tmsp_t) tms;
159 } */ *uap = v;
160 struct linux32_tms ltms32;
161 struct linux_tms ltms;
162 struct linux_tms *ltmsp;
163 struct linux_sys_times_args ua;
164 void *sg = stackgap_init(l->l_proc, 0);
165 int error;
166
167 ltmsp = stackgap_alloc(l->l_proc, &sg, sizeof(*ltmsp));
168 SCARG(&ua, tms) = (struct times *)ltmsp;
169
170 if ((error = linux_sys_times(l, &ua, retval)) != 0)
171 return error;
172
173 if ((error = copyin(ltmsp, <ms, sizeof(ltms))) != 0)
174 return error;
175
176 ltms32.ltms32_utime = (linux32_clock_t)ltms.ltms_utime;
177 ltms32.ltms32_stime = (linux32_clock_t)ltms.ltms_stime;
178 ltms32.ltms32_cutime = (linux32_clock_t)ltms.ltms_cutime;
179 ltms32.ltms32_cstime = (linux32_clock_t)ltms.ltms_cstime;
180
181 if ((error = copyout(<ms32,
182 SCARG_P32(uap, tms), sizeof(ltms32))) != 0)
183 return error;
184
185 return 0;
186 }
187
188 int
189 linux32_sys_stime(l, v, retval)
190 struct lwp *l;
191 void *v;
192 register_t *retval;
193 {
194 struct linux32_sys_stime_args /* {
195 syscallarg(linux32_timep_t) t;
196 } */ *uap = v;
197 struct timespec ts;
198 linux32_time_t tt32;
199 int error;
200
201 if ((error = kauth_authorize_system(l->l_cred,
202 KAUTH_SYSTEM_TIME, KAUTH_REQ_SYSTEM_TIME_SYSTEM, NULL, NULL,
203 NULL)) != 0)
204 return error;
205
206 if ((error = copyin(&tt32, SCARG_P32(uap, t), sizeof tt32)) != 0)
207 return error;
208
209 ts.tv_sec = (long)tt32;
210 ts.tv_nsec = 0;
211
212 return settime(l->l_proc, &ts);
213 }
214
215 int
216 linux32_sys_utime(l, v, retval)
217 struct lwp *l;
218 void *v;
219 register_t *retval;
220 {
221 struct linux32_sys_utime_args /* {
222 syscallarg(const netbsd32_charp) path;
223 syscallarg(linux32_utimbufp_t) times;
224 } */ *uap = v;
225 struct proc *p = l->l_proc;
226 void *sg = stackgap_init(p, 0);
227 struct sys_utimes_args ua;
228 struct timeval tv[2], *tvp;
229 struct linux32_utimbuf lut;
230 int error;
231
232 NETBSD32TOP_UAP(path, const char);
233 CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
234
235
236 if (SCARG_P32(uap, times) != NULL) {
237 if ((error = copyin(SCARG_P32(uap, times), &lut, sizeof lut)))
238 return error;
239
240 tv[0].tv_sec = (long)lut.l_actime;
241 tv[0].tv_usec = 0;
242 tv[1].tv_sec = (long)lut.l_modtime;
243 tv[1].tv_usec = 0;
244
245 tvp = (struct timeval *) stackgap_alloc(p, &sg, sizeof(tv));
246
247 if ((error = copyout(tv, tvp, sizeof(tv))))
248 return error;
249 SCARG(&ua, tptr) = tvp;
250 } else {
251 SCARG(&ua, tptr) = NULL;
252 }
253
254 return sys_utimes(l, &ua, retval);
255 }
256