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