1 1.6 riastrad /* $NetBSD: linux_osf1.c,v 1.6 2024/10/01 16:35:41 riastradh Exp $ */ 2 1.1 maxv 3 1.1 maxv /* 4 1.1 maxv * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. 5 1.1 maxv * 6 1.1 maxv * Redistribution and use in source and binary forms, with or without 7 1.1 maxv * modification, are permitted provided that the following conditions 8 1.1 maxv * are met: 9 1.1 maxv * 1. Redistributions of source code must retain the above copyright 10 1.1 maxv * notice, this list of conditions and the following disclaimer. 11 1.1 maxv * 2. Redistributions in binary form must reproduce the above copyright 12 1.1 maxv * notice, this list of conditions and the following disclaimer in the 13 1.1 maxv * documentation and/or other materials provided with the distribution. 14 1.1 maxv * 3. All advertising materials mentioning features or use of this software 15 1.1 maxv * must display the following acknowledgement: 16 1.1 maxv * This product includes software developed by Christopher G. Demetriou 17 1.1 maxv * for the NetBSD Project. 18 1.1 maxv * 4. The name of the author may not be used to endorse or promote products 19 1.1 maxv * derived from this software without specific prior written permission 20 1.1 maxv * 21 1.1 maxv * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 1.1 maxv * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 1.1 maxv * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 1.1 maxv * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 1.1 maxv * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 1.1 maxv * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 1.1 maxv * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 1.1 maxv * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 1.1 maxv * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 1.1 maxv * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 1.1 maxv */ 32 1.1 maxv 33 1.1 maxv #include <sys/cdefs.h> 34 1.6 riastrad __KERNEL_RCSID(0, "$NetBSD: linux_osf1.c,v 1.6 2024/10/01 16:35:41 riastradh Exp $"); 35 1.1 maxv 36 1.1 maxv #include <sys/param.h> 37 1.1 maxv #include <sys/systm.h> 38 1.1 maxv #include <sys/namei.h> 39 1.1 maxv #include <sys/proc.h> 40 1.1 maxv #include <sys/file.h> 41 1.1 maxv #include <sys/filedesc.h> 42 1.1 maxv #include <sys/kernel.h> 43 1.1 maxv #include <sys/mount.h> 44 1.1 maxv #include <sys/vnode.h> 45 1.1 maxv #include <sys/wait.h> 46 1.1 maxv #include <sys/select.h> 47 1.1 maxv #include <sys/syscallargs.h> 48 1.1 maxv #include <sys/vfs_syscalls.h> 49 1.1 maxv 50 1.1 maxv #include <machine/alpha.h> 51 1.1 maxv #include <machine/cpuconf.h> 52 1.1 maxv #include <machine/rpb.h> 53 1.1 maxv #include <machine/fpu.h> 54 1.1 maxv 55 1.1 maxv #include <compat/common/compat_util.h> 56 1.1 maxv #include <compat/linux/common/linux_types.h> 57 1.1 maxv #include <compat/linux/common/linux_signal.h> 58 1.1 maxv #include <compat/linux/arch/alpha/linux_signal.h> 59 1.1 maxv #include <compat/linux/arch/alpha/linux_osf1.h> 60 1.1 maxv #include <compat/linux/linux_syscallargs.h> 61 1.1 maxv 62 1.1 maxv #include <net/if.h> 63 1.1 maxv #include <netinet/in.h> 64 1.1 maxv 65 1.1 maxv #include <nfs/rpcv2.h> 66 1.1 maxv #include <nfs/nfsproto.h> 67 1.1 maxv #include <nfs/nfs.h> 68 1.1 maxv #include <nfs/nfsmount.h> 69 1.1 maxv 70 1.1 maxv #include <ufs/ufs/quota.h> 71 1.1 maxv #include <ufs/ufs/ufsmount.h> 72 1.1 maxv 73 1.1 maxv #include <machine/vmparam.h> 74 1.1 maxv 75 1.1 maxv const struct emul_flags_xtab osf1_wait_options_xtab[] = { 76 1.1 maxv { OSF1_WNOHANG, OSF1_WNOHANG, WNOHANG }, 77 1.1 maxv { OSF1_WUNTRACED, OSF1_WUNTRACED, WUNTRACED }, 78 1.1 maxv { 0 } 79 1.1 maxv }; 80 1.1 maxv 81 1.1 maxv const struct emul_flags_xtab osf1_nfs_mount_flags_xtab[] = { 82 1.1 maxv { OSF1_NFSMNT_SOFT, OSF1_NFSMNT_SOFT, NFSMNT_SOFT, }, 83 1.1 maxv { OSF1_NFSMNT_WSIZE, OSF1_NFSMNT_WSIZE, NFSMNT_WSIZE, }, 84 1.1 maxv { OSF1_NFSMNT_RSIZE, OSF1_NFSMNT_RSIZE, NFSMNT_RSIZE, }, 85 1.1 maxv { OSF1_NFSMNT_TIMEO, OSF1_NFSMNT_TIMEO, NFSMNT_TIMEO, }, 86 1.1 maxv { OSF1_NFSMNT_RETRANS, OSF1_NFSMNT_RETRANS, NFSMNT_RETRANS, }, 87 1.1 maxv #if 0 /* no equivalent; needs special handling, see below */ 88 1.1 maxv { OSF1_NFSMNT_HOSTNAME, OSF1_NFSMNT_HOSTNAME, ???, }, 89 1.1 maxv #endif 90 1.1 maxv { OSF1_NFSMNT_INT, OSF1_NFSMNT_INT, NFSMNT_INT, }, 91 1.1 maxv { OSF1_NFSMNT_NOCONN, OSF1_NFSMNT_NOCONN, NFSMNT_NOCONN, }, 92 1.1 maxv #if 0 /* no equivalents */ 93 1.1 maxv { OSF1_NFSMNT_NOAC, OSF1_NFSMNT_NOAC, ???, }, 94 1.1 maxv { OSF1_NFSMNT_ACREGMIN, OSF1_NFSMNT_ACREGMIN, ???, }, 95 1.1 maxv { OSF1_NFSMNT_ACREGMAX, OSF1_NFSMNT_ACREGMAX, ???, }, 96 1.1 maxv { OSF1_NFSMNT_ACDIRMIN, OSF1_NFSMNT_ACDIRMIN, ???, }, 97 1.1 maxv { OSF1_NFSMNT_ACDIRMAX, OSF1_NFSMNT_ACDIRMAX, ???, }, 98 1.1 maxv { OSF1_NFSMNT_NOCTO, OSF1_NFSMNT_NOCTO, ???, }, 99 1.1 maxv { OSF1_NFSMNT_POSIX, OSF1_NFSMNT_POSIX, ???, }, 100 1.1 maxv { OSF1_NFSMNT_AUTO, OSF1_NFSMNT_AUTO, ???, }, 101 1.1 maxv { OSF1_NFSMNT_SEC, OSF1_NFSMNT_SEC, ???, }, 102 1.1 maxv { OSF1_NFSMNT_TCP, OSF1_NFSMNT_TCP, ???, }, 103 1.1 maxv { OSF1_NFSMNT_PROPLIST, OSF1_NFSMNT_PROPLIST, ???, }, 104 1.1 maxv #endif 105 1.1 maxv { 0 } 106 1.1 maxv }; 107 1.1 maxv 108 1.1 maxv static void 109 1.1 maxv osf1_cvt_rusage_from_native(const struct rusage *ru, struct osf1_rusage *oru) 110 1.1 maxv { 111 1.1 maxv 112 1.5 riastrad memset(oru, 0, sizeof(*oru)); 113 1.5 riastrad 114 1.1 maxv oru->ru_utime.tv_sec = ru->ru_utime.tv_sec; 115 1.1 maxv oru->ru_utime.tv_usec = ru->ru_utime.tv_usec; 116 1.1 maxv 117 1.1 maxv oru->ru_stime.tv_sec = ru->ru_stime.tv_sec; 118 1.1 maxv oru->ru_stime.tv_usec = ru->ru_stime.tv_usec; 119 1.1 maxv 120 1.1 maxv oru->ru_maxrss = ru->ru_maxrss; 121 1.1 maxv oru->ru_ixrss = ru->ru_ixrss; 122 1.1 maxv oru->ru_idrss = ru->ru_idrss; 123 1.1 maxv oru->ru_isrss = ru->ru_isrss; 124 1.1 maxv oru->ru_minflt = ru->ru_minflt; 125 1.1 maxv oru->ru_majflt = ru->ru_majflt; 126 1.1 maxv oru->ru_nswap = ru->ru_nswap; 127 1.1 maxv oru->ru_inblock = ru->ru_inblock; 128 1.1 maxv oru->ru_oublock = ru->ru_oublock; 129 1.1 maxv oru->ru_msgsnd = ru->ru_msgsnd; 130 1.1 maxv oru->ru_msgrcv = ru->ru_msgrcv; 131 1.1 maxv oru->ru_nsignals = ru->ru_nsignals; 132 1.1 maxv oru->ru_nvcsw = ru->ru_nvcsw; 133 1.1 maxv oru->ru_nivcsw = ru->ru_nivcsw; 134 1.1 maxv } 135 1.1 maxv 136 1.1 maxv static void 137 1.1 maxv osf1_cvt_statfs_from_native(const struct statvfs *bsfs, struct osf1_statfs *osfs) 138 1.1 maxv { 139 1.1 maxv 140 1.5 riastrad memset(osfs, 0, sizeof(*osfs)); 141 1.1 maxv if (!strncmp(MOUNT_FFS, bsfs->f_fstypename, sizeof(bsfs->f_fstypename))) 142 1.1 maxv osfs->f_type = OSF1_MOUNT_UFS; 143 1.1 maxv else if (!strncmp(MOUNT_NFS, bsfs->f_fstypename, sizeof(bsfs->f_fstypename))) 144 1.1 maxv osfs->f_type = OSF1_MOUNT_NFS; 145 1.1 maxv else if (!strncmp(MOUNT_MFS, bsfs->f_fstypename, sizeof(bsfs->f_fstypename))) 146 1.1 maxv osfs->f_type = OSF1_MOUNT_MFS; 147 1.1 maxv else 148 1.1 maxv /* uh oh... XXX = PC, CDFS, PROCFS, etc. */ 149 1.1 maxv osfs->f_type = OSF1_MOUNT_ADDON; 150 1.1 maxv osfs->f_flags = bsfs->f_flag; /* XXX translate */ 151 1.1 maxv osfs->f_fsize = bsfs->f_frsize; 152 1.1 maxv osfs->f_bsize = bsfs->f_bsize; 153 1.1 maxv osfs->f_blocks = bsfs->f_blocks; 154 1.1 maxv osfs->f_bfree = bsfs->f_bfree; 155 1.1 maxv osfs->f_bavail = bsfs->f_bavail; 156 1.1 maxv osfs->f_files = bsfs->f_files; 157 1.1 maxv osfs->f_ffree = bsfs->f_ffree; 158 1.1 maxv memcpy(&osfs->f_fsid, &bsfs->f_fsidx, sizeof osfs->f_fsid); 159 1.1 maxv /* osfs->f_spare zeroed above */ 160 1.1 maxv memcpy(osfs->f_mntonname, bsfs->f_mntonname, sizeof osfs->f_mntonname); 161 1.1 maxv memcpy(osfs->f_mntfromname, bsfs->f_mntfromname, 162 1.1 maxv sizeof osfs->f_mntfromname); 163 1.1 maxv /* XXX osfs->f_xxx should be filled in... */ 164 1.1 maxv } 165 1.1 maxv 166 1.1 maxv /* --------------------------------------------------------------------- */ 167 1.1 maxv 168 1.1 maxv int 169 1.1 maxv linux_sys_osf1_wait4(struct lwp *l, const struct linux_sys_osf1_wait4_args *uap, register_t *retval) 170 1.1 maxv { 171 1.1 maxv struct osf1_rusage osf1_rusage; 172 1.1 maxv struct rusage netbsd_rusage; 173 1.1 maxv unsigned long leftovers; 174 1.1 maxv int error, status; 175 1.1 maxv int options = SCARG(uap, options); 176 1.1 maxv int pid = SCARG(uap, pid); 177 1.1 maxv 178 1.1 maxv /* translate options */ 179 1.1 maxv options = emul_flags_translate(osf1_wait_options_xtab, 180 1.1 maxv options, &leftovers); 181 1.1 maxv if (leftovers != 0) 182 1.1 maxv return (EINVAL); 183 1.1 maxv 184 1.1 maxv error = do_sys_wait(&pid, &status, options, 185 1.1 maxv SCARG(uap, rusage) != NULL ? &netbsd_rusage : NULL); 186 1.1 maxv 187 1.1 maxv retval[0] = pid; 188 1.1 maxv if (pid == 0) 189 1.1 maxv return error; 190 1.1 maxv 191 1.1 maxv if (SCARG(uap, rusage)) { 192 1.1 maxv osf1_cvt_rusage_from_native(&netbsd_rusage, &osf1_rusage); 193 1.1 maxv error = copyout(&osf1_rusage, SCARG(uap, rusage), 194 1.1 maxv sizeof osf1_rusage); 195 1.1 maxv } 196 1.1 maxv 197 1.1 maxv if (error == 0 && SCARG(uap, status)) 198 1.1 maxv error = copyout(&status, SCARG(uap, status), sizeof(status)); 199 1.1 maxv 200 1.1 maxv return error; 201 1.1 maxv } 202 1.1 maxv 203 1.1 maxv #define OSF1_MNT_WAIT 0x1 204 1.1 maxv #define OSF1_MNT_NOWAIT 0x2 205 1.1 maxv 206 1.1 maxv #define OSF1_MNT_FORCE 0x1 207 1.1 maxv #define OSF1_MNT_NOFORCE 0x2 208 1.1 maxv 209 1.1 maxv /* acceptable flags for various calls */ 210 1.1 maxv #define OSF1_GETFSSTAT_FLAGS (OSF1_MNT_WAIT|OSF1_MNT_NOWAIT) 211 1.1 maxv #define OSF1_MOUNT_FLAGS 0xffffffff /* XXX */ 212 1.1 maxv #define OSF1_UNMOUNT_FLAGS (OSF1_MNT_FORCE|OSF1_MNT_NOFORCE) 213 1.1 maxv 214 1.1 maxv static int 215 1.1 maxv osf1_mount_mfs(struct lwp *l, const struct linux_sys_osf1_mount_args *uap) 216 1.1 maxv { 217 1.1 maxv struct osf1_mfs_args osf_ma; 218 1.1 maxv struct mfs_args bsd_ma; 219 1.1 maxv int error; 220 1.1 maxv register_t dummy; 221 1.1 maxv 222 1.1 maxv if ((error = copyin(SCARG(uap, data), &osf_ma, sizeof osf_ma))) 223 1.1 maxv return error; 224 1.1 maxv 225 1.1 maxv memset(&bsd_ma, 0, sizeof bsd_ma); 226 1.1 maxv bsd_ma.fspec = osf_ma.name; 227 1.1 maxv /* XXX export args */ 228 1.1 maxv bsd_ma.base = osf_ma.base; 229 1.1 maxv bsd_ma.size = osf_ma.size; 230 1.1 maxv 231 1.1 maxv return do_sys_mount(l, "mfs", UIO_SYSSPACE, SCARG(uap, path), 232 1.1 maxv SCARG(uap, flags), &bsd_ma, UIO_SYSSPACE, sizeof bsd_ma, &dummy); 233 1.1 maxv } 234 1.1 maxv 235 1.1 maxv static int 236 1.1 maxv osf1_mount_nfs(struct lwp *l, const struct linux_sys_osf1_mount_args *uap) 237 1.1 maxv { 238 1.1 maxv struct osf1_nfs_args osf_na; 239 1.1 maxv struct nfs_args bsd_na; 240 1.1 maxv int error; 241 1.1 maxv unsigned long leftovers; 242 1.1 maxv register_t dummy; 243 1.1 maxv 244 1.1 maxv if ((error = copyin(SCARG(uap, data), &osf_na, sizeof osf_na))) 245 1.1 maxv return error; 246 1.1 maxv 247 1.1 maxv memset(&bsd_na, 0, sizeof bsd_na); 248 1.1 maxv bsd_na.addr = (struct sockaddr *)osf_na.addr; 249 1.1 maxv bsd_na.addrlen = sizeof (struct sockaddr_in); 250 1.1 maxv bsd_na.fh = osf_na.fh; 251 1.1 maxv 252 1.1 maxv /* translate flags */ 253 1.1 maxv bsd_na.flags = emul_flags_translate(osf1_nfs_mount_flags_xtab, 254 1.1 maxv osf_na.flags, &leftovers); 255 1.1 maxv if (leftovers & OSF1_NFSMNT_HOSTNAME) { 256 1.1 maxv leftovers &= ~OSF1_NFSMNT_HOSTNAME; 257 1.1 maxv bsd_na.hostname = osf_na.hostname; 258 1.1 maxv } else { 259 1.1 maxv /* XXX FILL IN HOST NAME WITH IPADDR? */ 260 1.1 maxv } 261 1.1 maxv if (leftovers & OSF1_NFSMNT_TCP) { 262 1.1 maxv leftovers &= ~OSF1_NFSMNT_TCP; 263 1.1 maxv bsd_na.sotype = SOCK_DGRAM; 264 1.1 maxv bsd_na.proto = 0; 265 1.1 maxv } else { 266 1.1 maxv bsd_na.sotype = SOCK_STREAM; 267 1.1 maxv bsd_na.proto = 0; 268 1.1 maxv } 269 1.1 maxv if (leftovers != 0) 270 1.1 maxv return (EINVAL); 271 1.1 maxv 272 1.1 maxv /* copy structure elements based on flags */ 273 1.1 maxv if (bsd_na.flags & NFSMNT_WSIZE) 274 1.1 maxv bsd_na.wsize = osf_na.wsize; 275 1.1 maxv if (bsd_na.flags & NFSMNT_RSIZE) 276 1.1 maxv bsd_na.rsize = osf_na.rsize; 277 1.1 maxv if (bsd_na.flags & NFSMNT_TIMEO) 278 1.1 maxv bsd_na.timeo = osf_na.timeo; 279 1.1 maxv if (bsd_na.flags & NFSMNT_RETRANS) 280 1.1 maxv bsd_na.retrans = osf_na.retrans; 281 1.1 maxv 282 1.1 maxv return do_sys_mount(l, "nfs", UIO_SYSSPACE, SCARG(uap, path), 283 1.1 maxv SCARG(uap, flags), &bsd_na, UIO_SYSSPACE, sizeof bsd_na, &dummy); 284 1.1 maxv } 285 1.1 maxv 286 1.1 maxv int 287 1.1 maxv linux_sys_osf1_mount(struct lwp *l, const struct linux_sys_osf1_mount_args *uap, register_t *retval) 288 1.1 maxv { 289 1.1 maxv 290 1.1 maxv if (SCARG(uap, flags) & ~OSF1_MOUNT_FLAGS) 291 1.1 maxv return (EINVAL); 292 1.1 maxv 293 1.1 maxv /* XXX - xlate flags */ 294 1.1 maxv 295 1.1 maxv switch (SCARG(uap, type)) { 296 1.1 maxv case OSF1_MOUNT_NFS: 297 1.1 maxv return osf1_mount_nfs(l, uap); 298 1.1 maxv break; 299 1.1 maxv 300 1.1 maxv case OSF1_MOUNT_MFS: 301 1.1 maxv return osf1_mount_mfs(l, uap); 302 1.1 maxv 303 1.1 maxv default: 304 1.1 maxv return (EINVAL); 305 1.1 maxv } 306 1.1 maxv } 307 1.1 maxv 308 1.1 maxv int 309 1.1 maxv linux_sys_osf1_set_program_attributes(struct lwp *l, const struct linux_sys_osf1_set_program_attributes_args *uap, register_t *retval) 310 1.1 maxv { 311 1.1 maxv struct proc *p = l->l_proc; 312 1.1 maxv segsz_t tsize, dsize; 313 1.1 maxv 314 1.1 maxv tsize = btoc(SCARG(uap, tsize)); 315 1.1 maxv dsize = btoc(SCARG(uap, dsize)); 316 1.1 maxv 317 1.1 maxv if (dsize > p->p_rlimit[RLIMIT_DATA].rlim_cur) 318 1.1 maxv return (ENOMEM); 319 1.4 christos #ifdef MAXTSIZ 320 1.1 maxv if (tsize > MAXTSIZ) 321 1.1 maxv return (ENOMEM); 322 1.4 christos #endif 323 1.1 maxv 324 1.1 maxv /* XXXSMP unlocked */ 325 1.1 maxv p->p_vmspace->vm_taddr = SCARG(uap, taddr); 326 1.1 maxv p->p_vmspace->vm_tsize = tsize; 327 1.1 maxv p->p_vmspace->vm_daddr = SCARG(uap, daddr); 328 1.1 maxv p->p_vmspace->vm_dsize = dsize; 329 1.1 maxv 330 1.1 maxv return (0); 331 1.1 maxv } 332 1.1 maxv 333 1.1 maxv int 334 1.1 maxv linux_sys_osf1_setitimer(struct lwp *l, const struct linux_sys_osf1_setitimer_args *uap, register_t *retval) 335 1.1 maxv { 336 1.1 maxv struct osf1_itimerval o_itv, o_oitv; 337 1.1 maxv struct itimerval b_itv, b_oitv; 338 1.1 maxv int which; 339 1.1 maxv int error; 340 1.1 maxv 341 1.1 maxv switch (SCARG(uap, which)) { 342 1.1 maxv case OSF1_ITIMER_REAL: 343 1.1 maxv which = ITIMER_REAL; 344 1.1 maxv break; 345 1.1 maxv 346 1.1 maxv case OSF1_ITIMER_VIRTUAL: 347 1.1 maxv which = ITIMER_VIRTUAL; 348 1.1 maxv break; 349 1.1 maxv 350 1.1 maxv case OSF1_ITIMER_PROF: 351 1.1 maxv which = ITIMER_PROF; 352 1.1 maxv break; 353 1.1 maxv 354 1.1 maxv default: 355 1.1 maxv return (EINVAL); 356 1.1 maxv } 357 1.1 maxv 358 1.1 maxv /* get the OSF/1 itimerval argument */ 359 1.1 maxv error = copyin(SCARG(uap, itv), &o_itv, sizeof o_itv); 360 1.1 maxv if (error != 0) 361 1.1 maxv return error; 362 1.1 maxv 363 1.1 maxv /* fill in and the NetBSD timeval */ 364 1.1 maxv memset(&b_itv, 0, sizeof b_itv); 365 1.1 maxv b_itv.it_interval.tv_sec = o_itv.it_interval.tv_sec; 366 1.1 maxv b_itv.it_interval.tv_usec = o_itv.it_interval.tv_usec; 367 1.1 maxv b_itv.it_value.tv_sec = o_itv.it_value.tv_sec; 368 1.1 maxv b_itv.it_value.tv_usec = o_itv.it_value.tv_usec; 369 1.1 maxv 370 1.1 maxv if (SCARG(uap, oitv) != NULL) { 371 1.1 maxv dogetitimer(l->l_proc, which, &b_oitv); 372 1.1 maxv if (error) 373 1.1 maxv return error; 374 1.1 maxv } 375 1.6 riastrad 376 1.1 maxv error = dosetitimer(l->l_proc, which, &b_itv); 377 1.1 maxv 378 1.1 maxv if (error == 0 || SCARG(uap, oitv) == NULL) 379 1.1 maxv return error; 380 1.1 maxv 381 1.1 maxv /* fill in and copy out the old timeval */ 382 1.1 maxv memset(&o_oitv, 0, sizeof o_oitv); 383 1.1 maxv o_oitv.it_interval.tv_sec = b_oitv.it_interval.tv_sec; 384 1.1 maxv o_oitv.it_interval.tv_usec = b_oitv.it_interval.tv_usec; 385 1.1 maxv o_oitv.it_value.tv_sec = b_oitv.it_value.tv_sec; 386 1.1 maxv o_oitv.it_value.tv_usec = b_oitv.it_value.tv_usec; 387 1.1 maxv 388 1.1 maxv return copyout(&o_oitv, SCARG(uap, oitv), sizeof o_oitv); 389 1.1 maxv } 390 1.1 maxv 391 1.1 maxv int 392 1.1 maxv linux_sys_osf1_select(struct lwp *l, const struct linux_sys_osf1_select_args *uap, 393 1.1 maxv register_t *retval) 394 1.1 maxv { 395 1.1 maxv struct osf1_timeval otv; 396 1.1 maxv struct timespec ats, *ts = NULL; 397 1.1 maxv int error; 398 1.1 maxv 399 1.1 maxv if (SCARG(uap, tv)) { 400 1.1 maxv /* get the OSF/1 timeval argument */ 401 1.1 maxv error = copyin(SCARG(uap, tv), &otv, sizeof otv); 402 1.1 maxv if (error != 0) 403 1.1 maxv return error; 404 1.1 maxv 405 1.1 maxv ats.tv_sec = otv.tv_sec; 406 1.1 maxv ats.tv_nsec = otv.tv_usec * 1000; 407 1.1 maxv ts = &ats; 408 1.1 maxv } 409 1.1 maxv 410 1.1 maxv return selcommon(retval, SCARG(uap, nd), SCARG(uap, in), 411 1.1 maxv SCARG(uap, ou), SCARG(uap, ex), ts, NULL); 412 1.1 maxv } 413 1.1 maxv 414 1.1 maxv int 415 1.1 maxv linux_sys_osf1_gettimeofday(struct lwp *l, const struct linux_sys_osf1_gettimeofday_args *uap, register_t *retval) 416 1.1 maxv { 417 1.1 maxv struct osf1_timeval otv; 418 1.1 maxv struct osf1_timezone otz; 419 1.1 maxv struct timeval tv; 420 1.1 maxv int error; 421 1.1 maxv 422 1.1 maxv microtime(&tv); 423 1.1 maxv memset(&otv, 0, sizeof otv); 424 1.1 maxv otv.tv_sec = tv.tv_sec; 425 1.1 maxv otv.tv_usec = tv.tv_usec; 426 1.2 christos error = copyout(&otv, SCARG(uap, tv), sizeof otv); 427 1.1 maxv 428 1.1 maxv if (error == 0 && SCARG(uap, tzp) != NULL) { 429 1.1 maxv memset(&otz, 0, sizeof otz); 430 1.1 maxv error = copyout(&otz, SCARG(uap, tzp), sizeof otz); 431 1.1 maxv } 432 1.1 maxv return (error); 433 1.1 maxv } 434 1.1 maxv 435 1.1 maxv int 436 1.1 maxv linux_sys_osf1_getrusage(struct lwp *l, const struct linux_sys_osf1_getrusage_args *uap, register_t *retval) 437 1.1 maxv { 438 1.1 maxv int error, who; 439 1.1 maxv struct osf1_rusage osf1_rusage; 440 1.1 maxv struct rusage ru; 441 1.1 maxv struct proc *p = l->l_proc; 442 1.1 maxv 443 1.1 maxv 444 1.1 maxv switch (SCARG(uap, who)) { 445 1.1 maxv case OSF1_RUSAGE_SELF: 446 1.1 maxv who = RUSAGE_SELF; 447 1.1 maxv break; 448 1.1 maxv 449 1.1 maxv case OSF1_RUSAGE_CHILDREN: 450 1.1 maxv who = RUSAGE_CHILDREN; 451 1.1 maxv break; 452 1.1 maxv 453 1.1 maxv case OSF1_RUSAGE_THREAD: /* XXX not supported */ 454 1.1 maxv default: 455 1.1 maxv return EINVAL; 456 1.1 maxv } 457 1.1 maxv 458 1.1 maxv error = getrusage1(p, who, &ru); 459 1.1 maxv if (error != 0) 460 1.1 maxv return error; 461 1.1 maxv 462 1.1 maxv osf1_cvt_rusage_from_native(&ru, &osf1_rusage); 463 1.1 maxv 464 1.1 maxv return copyout(&osf1_rusage, SCARG(uap, rusage), sizeof osf1_rusage); 465 1.1 maxv } 466 1.1 maxv 467 1.1 maxv int 468 1.1 maxv linux_sys_osf1_settimeofday(struct lwp *l, const struct linux_sys_osf1_settimeofday_args *uap, register_t *retval) 469 1.1 maxv { 470 1.1 maxv struct osf1_timeval otv; 471 1.1 maxv struct timeval tv, *tvp; 472 1.1 maxv int error = 0; 473 1.1 maxv 474 1.1 maxv if (SCARG(uap, tv) == NULL) 475 1.1 maxv tvp = NULL; 476 1.1 maxv else { 477 1.1 maxv /* get the OSF/1 timeval argument */ 478 1.1 maxv error = copyin(SCARG(uap, tv), &otv, sizeof otv); 479 1.1 maxv if (error != 0) 480 1.1 maxv return error; 481 1.1 maxv 482 1.1 maxv tv.tv_sec = otv.tv_sec; 483 1.1 maxv tv.tv_usec = otv.tv_usec; 484 1.1 maxv tvp = &tv; 485 1.1 maxv } 486 1.1 maxv 487 1.1 maxv /* NetBSD ignores the timezone field */ 488 1.1 maxv 489 1.1 maxv return settimeofday1(tvp, false, (const void *)SCARG(uap, tzp), l, true); 490 1.1 maxv } 491 1.1 maxv 492 1.1 maxv int 493 1.1 maxv linux_sys_osf1_utimes(struct lwp *l, const struct linux_sys_osf1_utimes_args *uap, register_t *retval) 494 1.1 maxv { 495 1.1 maxv struct osf1_timeval otv; 496 1.1 maxv struct timeval tv[2], *tvp; 497 1.1 maxv int error; 498 1.1 maxv 499 1.1 maxv if (SCARG(uap, tptr) == NULL) 500 1.1 maxv tvp = NULL; 501 1.1 maxv else { 502 1.1 maxv /* get the OSF/1 timeval argument */ 503 1.1 maxv error = copyin(SCARG(uap, tptr), &otv, sizeof otv); 504 1.1 maxv if (error != 0) 505 1.1 maxv return error; 506 1.1 maxv 507 1.1 maxv /* fill in and copy out the NetBSD timeval */ 508 1.1 maxv tv[0].tv_sec = otv.tv_sec; 509 1.1 maxv tv[0].tv_usec = otv.tv_usec; 510 1.1 maxv /* Set access and modified to the same time */ 511 1.1 maxv tv[1].tv_sec = otv.tv_sec; 512 1.1 maxv tv[1].tv_usec = otv.tv_usec; 513 1.1 maxv tvp = tv; 514 1.1 maxv } 515 1.1 maxv 516 1.1 maxv return do_sys_utimes(l, NULL, SCARG(uap, path), FOLLOW, 517 1.1 maxv tvp, UIO_SYSSPACE); 518 1.1 maxv } 519 1.1 maxv 520 1.1 maxv int 521 1.1 maxv linux_sys_osf1_statfs(struct lwp *l, const struct linux_sys_osf1_statfs_args *uap, register_t *retval) 522 1.1 maxv { 523 1.1 maxv struct mount *mp; 524 1.1 maxv struct statvfs *sp; 525 1.1 maxv struct osf1_statfs osfs; 526 1.1 maxv int error; 527 1.1 maxv struct vnode *vp; 528 1.1 maxv 529 1.1 maxv error = namei_simple_user(SCARG(uap, path), 530 1.1 maxv NSM_FOLLOW_TRYEMULROOT, &vp); 531 1.1 maxv if (error != 0) 532 1.1 maxv return (error); 533 1.1 maxv mp = vp->v_mount; 534 1.1 maxv sp = &mp->mnt_stat; 535 1.1 maxv vrele(vp); 536 1.1 maxv if ((error = VFS_STATVFS(mp, sp))) 537 1.1 maxv return (error); 538 1.1 maxv sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK; 539 1.1 maxv osf1_cvt_statfs_from_native(sp, &osfs); 540 1.1 maxv return copyout(&osfs, SCARG(uap, buf), uimin(sizeof osfs, 541 1.1 maxv SCARG(uap, len))); 542 1.1 maxv } 543 1.1 maxv 544 1.1 maxv int 545 1.1 maxv linux_sys_osf1_fstatfs(struct lwp *l, const struct linux_sys_osf1_fstatfs_args *uap, register_t *retval) 546 1.1 maxv { 547 1.1 maxv file_t *fp; 548 1.1 maxv struct mount *mp; 549 1.1 maxv struct statvfs *sp; 550 1.1 maxv struct osf1_statfs osfs; 551 1.1 maxv int error; 552 1.1 maxv 553 1.1 maxv /* fd_getvnode() will use the descriptor for us */ 554 1.1 maxv if ((error = fd_getvnode(SCARG(uap, fd), &fp))) 555 1.1 maxv return (error); 556 1.1 maxv mp = fp->f_vnode->v_mount; 557 1.1 maxv sp = &mp->mnt_stat; 558 1.1 maxv if ((error = VFS_STATVFS(mp, sp))) 559 1.1 maxv goto out; 560 1.1 maxv sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK; 561 1.1 maxv osf1_cvt_statfs_from_native(sp, &osfs); 562 1.1 maxv error = copyout(&osfs, SCARG(uap, buf), uimin(sizeof osfs, 563 1.1 maxv SCARG(uap, len))); 564 1.1 maxv out: 565 1.1 maxv fd_putfile(SCARG(uap, fd)); 566 1.1 maxv return (error); 567 1.1 maxv } 568 1.1 maxv 569 1.1 maxv int 570 1.1 maxv linux_sys_osf1_sysinfo(struct lwp *l, const struct linux_sys_osf1_sysinfo_args *uap, register_t *retval) 571 1.1 maxv { 572 1.1 maxv const char *string; 573 1.1 maxv size_t slen; 574 1.1 maxv int error; 575 1.1 maxv 576 1.1 maxv error = 0; 577 1.1 maxv switch (SCARG(uap, cmd)) { 578 1.1 maxv case OSF1_SI_SYSNAME: 579 1.1 maxv string = ostype; 580 1.1 maxv break; 581 1.1 maxv 582 1.1 maxv case OSF1_SI_HOSTNAME: 583 1.1 maxv string = hostname; 584 1.1 maxv break; 585 1.1 maxv 586 1.1 maxv case OSF1_SI_RELEASE: 587 1.1 maxv string = osrelease; 588 1.1 maxv break; 589 1.1 maxv 590 1.1 maxv case OSF1_SI_VERSION: 591 1.1 maxv goto should_handle; 592 1.1 maxv 593 1.1 maxv case OSF1_SI_MACHINE: 594 1.1 maxv string = MACHINE; 595 1.1 maxv break; 596 1.1 maxv 597 1.1 maxv case OSF1_SI_ARCHITECTURE: 598 1.1 maxv string = MACHINE_ARCH; 599 1.1 maxv break; 600 1.1 maxv 601 1.1 maxv case OSF1_SI_HW_SERIAL: 602 1.1 maxv string = "666"; /* OSF/1 emulation? YES! */ 603 1.1 maxv break; 604 1.1 maxv 605 1.1 maxv case OSF1_SI_HW_PROVIDER: 606 1.1 maxv string = "unknown"; 607 1.1 maxv break; 608 1.1 maxv 609 1.1 maxv case OSF1_SI_SRPC_DOMAIN: 610 1.1 maxv goto dont_care; 611 1.1 maxv 612 1.1 maxv case OSF1_SI_SET_HOSTNAME: 613 1.1 maxv goto should_handle; 614 1.1 maxv 615 1.1 maxv case OSF1_SI_SET_SYSNAME: 616 1.1 maxv goto should_handle; 617 1.1 maxv 618 1.1 maxv case OSF1_SI_SET_SRPC_DOMAIN: 619 1.1 maxv goto dont_care; 620 1.1 maxv 621 1.1 maxv default: 622 1.1 maxv should_handle: 623 1.1 maxv printf("osf1_sys_sysinfo(%d, %p, 0x%lx)\n", SCARG(uap, cmd), 624 1.1 maxv SCARG(uap, buf), SCARG(uap,len)); 625 1.1 maxv dont_care: 626 1.1 maxv return (EINVAL); 627 1.1 maxv }; 628 1.1 maxv 629 1.1 maxv slen = strlen(string) + 1; 630 1.1 maxv if (SCARG(uap, buf)) { 631 1.1 maxv error = copyout(string, SCARG(uap, buf), 632 1.1 maxv uimin(slen, SCARG(uap, len))); 633 1.1 maxv if (!error && (SCARG(uap, len) > 0) && (SCARG(uap, len) < slen)) 634 1.3 thorpej error = ustore_char(SCARG(uap, buf) 635 1.3 thorpej + SCARG(uap, len) - 1, 0); 636 1.1 maxv } 637 1.1 maxv if (!error) 638 1.1 maxv retval[0] = slen; 639 1.1 maxv 640 1.1 maxv return (error); 641 1.1 maxv } 642 1.1 maxv 643 1.1 maxv int 644 1.1 maxv linux_sys_osf1_usleep_thread(struct lwp *l, const struct linux_sys_osf1_usleep_thread_args *uap, register_t *retval) 645 1.1 maxv { 646 1.1 maxv struct osf1_timeval otv, endotv; 647 1.1 maxv struct timeval tv, ntv, endtv; 648 1.1 maxv u_long ticks; 649 1.1 maxv int error; 650 1.1 maxv 651 1.1 maxv if ((error = copyin(SCARG(uap, sleep), &otv, sizeof otv))) 652 1.1 maxv return (error); 653 1.1 maxv tv.tv_sec = otv.tv_sec; 654 1.1 maxv tv.tv_usec = otv.tv_usec; 655 1.1 maxv 656 1.1 maxv ticks = howmany((u_long)tv.tv_sec * 1000000 + tv.tv_usec, tick); 657 1.1 maxv if (ticks == 0) 658 1.1 maxv ticks = 1; 659 1.1 maxv 660 1.1 maxv getmicrotime(&tv); 661 1.1 maxv 662 1.1 maxv tsleep(l, PUSER|PCATCH, "uslpthrd", ticks); /* XXX */ 663 1.1 maxv 664 1.1 maxv if (SCARG(uap, slept) != NULL) { 665 1.1 maxv getmicrotime(&ntv); 666 1.1 maxv timersub(&ntv, &tv, &endtv); 667 1.1 maxv if (endtv.tv_sec < 0 || endtv.tv_usec < 0) 668 1.1 maxv endtv.tv_sec = endtv.tv_usec = 0; 669 1.1 maxv 670 1.5 riastrad memset(&endotv, 0, sizeof(endotv)); 671 1.1 maxv endotv.tv_sec = endtv.tv_sec; 672 1.1 maxv endotv.tv_usec = endtv.tv_usec; 673 1.1 maxv error = copyout(&endotv, SCARG(uap, slept), sizeof endotv); 674 1.1 maxv } 675 1.1 maxv return (error); 676 1.1 maxv } 677 1.1 maxv 678 1.1 maxv int 679 1.1 maxv linux_sys_osf1_getsysinfo(struct lwp *l, const struct linux_sys_osf1_getsysinfo_args *uap, register_t *retval) 680 1.1 maxv { 681 1.1 maxv extern int ncpus; 682 1.1 maxv int error; 683 1.1 maxv int unit; 684 1.1 maxv long percpu; 685 1.1 maxv long proctype; 686 1.1 maxv u_int64_t fpflags; 687 1.1 maxv struct osf1_cpu_info cpuinfo; 688 1.1 maxv const void *data; 689 1.1 maxv size_t datalen; 690 1.1 maxv 691 1.1 maxv error = 0; 692 1.1 maxv 693 1.1 maxv switch(SCARG(uap, op)) 694 1.1 maxv { 695 1.1 maxv case OSF_GET_MAX_UPROCS: 696 1.1 maxv data = &maxproc; 697 1.1 maxv datalen = sizeof(maxproc); 698 1.1 maxv break; 699 1.1 maxv case OSF_GET_PHYSMEM: 700 1.1 maxv data = &physmem; 701 1.1 maxv datalen = sizeof(physmem); 702 1.1 maxv break; 703 1.1 maxv case OSF_GET_MAX_CPU: 704 1.1 maxv case OSF_GET_CPUS_IN_BOX: 705 1.1 maxv data = &ncpus; 706 1.1 maxv datalen = sizeof(ncpus); 707 1.1 maxv break; 708 1.1 maxv case OSF_GET_IEEE_FP_CONTROL: 709 1.1 maxv if (((fpflags = alpha_read_fp_c(l)) & IEEE_INHERIT) != 0) { 710 1.1 maxv fpflags |= 1ULL << 63; 711 1.1 maxv fpflags &= ~IEEE_INHERIT; 712 1.1 maxv } 713 1.1 maxv data = &fpflags; 714 1.1 maxv datalen = sizeof(fpflags); 715 1.1 maxv break; 716 1.1 maxv case OSF_GET_CPU_INFO: 717 1.1 maxv memset(&cpuinfo, 0, sizeof(cpuinfo)); 718 1.1 maxv #ifdef __alpha__ 719 1.1 maxv unit = alpha_pal_whami(); 720 1.1 maxv #else 721 1.1 maxv unit = 0; /* XXX */ 722 1.1 maxv #endif 723 1.1 maxv cpuinfo.current_cpu = unit; 724 1.1 maxv cpuinfo.cpus_in_box = ncpus; 725 1.1 maxv cpuinfo.cpu_type = LOCATE_PCS(hwrpb, unit)->pcs_proc_type; 726 1.1 maxv cpuinfo.ncpus = ncpus; 727 1.1 maxv cpuinfo.cpus_present = ncpus; 728 1.1 maxv cpuinfo.cpus_running = ncpus; 729 1.1 maxv cpuinfo.cpu_binding = 1; 730 1.1 maxv cpuinfo.cpu_ex_binding = 0; 731 1.1 maxv cpuinfo.mhz = hwrpb->rpb_cc_freq / 1000000; 732 1.1 maxv data = &cpuinfo; 733 1.1 maxv datalen = sizeof(cpuinfo); 734 1.1 maxv break; 735 1.1 maxv case OSF_GET_PROC_TYPE: 736 1.1 maxv #ifdef __alpha__ 737 1.1 maxv unit = alpha_pal_whami(); 738 1.1 maxv proctype = LOCATE_PCS(hwrpb, unit)->pcs_proc_type; 739 1.1 maxv #else 740 1.1 maxv proctype = 0; /* XXX */ 741 1.1 maxv #endif 742 1.1 maxv data = &proctype; 743 1.1 maxv datalen = sizeof(percpu); 744 1.1 maxv break; 745 1.1 maxv case OSF_GET_HWRPB: /* note -- osf/1 doesn't have rpb_tbhint[8] */ 746 1.1 maxv data = hwrpb; 747 1.1 maxv datalen = hwrpb->rpb_size; 748 1.1 maxv break; 749 1.1 maxv case OSF_GET_PLATFORM_NAME: 750 1.1 maxv data = platform.model; 751 1.1 maxv datalen = strlen(platform.model) + 1; 752 1.1 maxv break; 753 1.1 maxv default: 754 1.1 maxv printf("osf1_getsysinfo called with unknown op=%ld\n", 755 1.1 maxv SCARG(uap, op)); 756 1.1 maxv /* return EINVAL; */ 757 1.1 maxv return 0; 758 1.1 maxv } 759 1.1 maxv 760 1.1 maxv if (SCARG(uap, nbytes) < datalen) 761 1.1 maxv return (EINVAL); 762 1.1 maxv error = copyout(data, SCARG(uap, buffer), datalen); 763 1.1 maxv if (!error) 764 1.1 maxv retval[0] = 1; 765 1.1 maxv return (error); 766 1.1 maxv } 767 1.1 maxv 768 1.1 maxv int 769 1.1 maxv linux_sys_osf1_setsysinfo(struct lwp *l, const struct linux_sys_osf1_setsysinfo_args *uap, register_t *retval) 770 1.1 maxv { 771 1.1 maxv u_int64_t temp; 772 1.1 maxv int error; 773 1.1 maxv 774 1.1 maxv error = 0; 775 1.1 maxv 776 1.1 maxv switch(SCARG(uap, op)) { 777 1.1 maxv case OSF_SET_IEEE_FP_CONTROL: 778 1.1 maxv 779 1.1 maxv if ((error = copyin(SCARG(uap, buffer), &temp, sizeof(temp)))) 780 1.1 maxv break; 781 1.1 maxv if (temp >> 63 != 0) 782 1.1 maxv temp |= IEEE_INHERIT; 783 1.1 maxv alpha_write_fp_c(l, temp); 784 1.1 maxv break; 785 1.1 maxv default: 786 1.1 maxv uprintf("osf1_setsysinfo called with op=%ld\n", SCARG(uap, op)); 787 1.1 maxv //error = EINVAL; 788 1.1 maxv } 789 1.1 maxv retval[0] = 0; 790 1.1 maxv return (error); 791 1.1 maxv } 792