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