root/compat/osf1/osf1_misc.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. osf1_sys_classcntl
  2. osf1_sys_reboot
  3. osf1_sys_set_program_attributes
  4. osf1_sys_setsysinfo
  5. osf1_sys_sysinfo
  6. osf1_sys_uname
  7. osf1_sys_usleep_thread
  8. osf1_sys_wait4

    1 /* $OpenBSD: osf1_misc.c,v 1.17 2004/06/25 16:28:51 deraadt Exp $ */
    2 /* $NetBSD: osf1_misc.c,v 1.55 2000/06/28 15:39:33 mrg Exp $ */
    3 
    4 /*
    5  * Copyright (c) 1999 Christopher G. Demetriou.  All rights reserved.
    6  *
    7  * Redistribution and use in source and binary forms, with or without
    8  * modification, are permitted provided that the following conditions
    9  * are met:
   10  * 1. Redistributions of source code must retain the above copyright
   11  *    notice, this list of conditions and the following disclaimer.
   12  * 2. Redistributions in binary form must reproduce the above copyright
   13  *    notice, this list of conditions and the following disclaimer in the
   14  *    documentation and/or other materials provided with the distribution.
   15  * 3. All advertising materials mentioning features or use of this software
   16  *    must display the following acknowledgement:
   17  *      This product includes software developed by Christopher G. Demetriou
   18  *      for the NetBSD Project.
   19  * 4. The name of the author may not be used to endorse or promote products
   20  *    derived from this software without specific prior written permission
   21  *
   22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   32  */
   33 
   34 /*
   35  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
   36  * All rights reserved.
   37  *
   38  * Author: Chris G. Demetriou
   39  * 
   40  * Permission to use, copy, modify and distribute this software and
   41  * its documentation is hereby granted, provided that both the copyright
   42  * notice and this permission notice appear in all copies of the
   43  * software, derivative works or modified versions, and any portions
   44  * thereof, and that both notices appear in supporting documentation.
   45  * 
   46  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
   47  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
   48  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   49  * 
   50  * Carnegie Mellon requests users of this software to return to
   51  *
   52  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   53  *  School of Computer Science
   54  *  Carnegie Mellon University
   55  *  Pittsburgh PA 15213-3890
   56  *
   57  * any improvements or extensions that they make and grant Carnegie the
   58  * rights to redistribute these changes.
   59  */
   60 
   61 #include <sys/param.h>
   62 #include <sys/systm.h>
   63 #include <sys/namei.h>
   64 #include <sys/proc.h>
   65 #include <sys/file.h>
   66 #include <sys/stat.h>
   67 #include <sys/filedesc.h>
   68 #include <sys/kernel.h>
   69 #include <sys/malloc.h>
   70 #include <sys/mman.h>
   71 #include <sys/mount.h>
   72 #include <sys/signal.h>
   73 #include <sys/signalvar.h>
   74 #include <sys/reboot.h>
   75 #include <sys/syscallargs.h>
   76 #include <sys/exec.h>
   77 #include <sys/vnode.h>
   78 #include <sys/socketvar.h>
   79 #include <sys/resource.h>
   80 #include <sys/resourcevar.h>
   81 #include <sys/wait.h>
   82 
   83 #include <compat/osf1/osf1.h>
   84 #include <compat/osf1/osf1_syscallargs.h>
   85 #include <compat/osf1/osf1_util.h>
   86 #include <compat/osf1/osf1_cvt.h>
   87 
   88 #ifdef SYSCALL_DEBUG
   89 extern int scdebug;
   90 #endif
   91 
   92 const char osf1_emul_path[] = "/emul/osf1";
   93 
   94 int
   95 osf1_sys_classcntl(p, v, retval)
   96         struct proc *p;
   97         void *v;
   98         register_t *retval;
   99 {
  100 
  101         /* XXX */
  102         return (ENOSYS);
  103 }
  104 
  105 int
  106 osf1_sys_reboot(p, v, retval)
  107         struct proc *p;
  108         void *v;
  109         register_t *retval;
  110 {
  111         struct osf1_sys_reboot_args *uap = v;
  112         struct sys_reboot_args a;
  113         unsigned long leftovers;
  114 
  115         /* translate opt */
  116         SCARG(&a, opt) = emul_flags_translate(osf1_reboot_opt_xtab,
  117             SCARG(uap, opt), &leftovers);
  118         if (leftovers != 0)
  119                 return (EINVAL);
  120 
  121         /* SCARG(&a, bootstr) = NULL; */
  122 
  123         return sys_reboot(p, &a, retval);
  124 }
  125 
  126 int
  127 osf1_sys_set_program_attributes(p, v, retval)
  128         struct proc *p;
  129         void *v;
  130         register_t *retval;
  131 {
  132         struct osf1_sys_set_program_attributes_args *uap = v;
  133         segsz_t tsize, dsize;
  134 
  135         tsize = btoc(SCARG(uap, tsize));
  136         dsize = btoc(SCARG(uap, dsize));
  137 
  138         if (dsize > p->p_rlimit[RLIMIT_DATA].rlim_cur)
  139                 return (ENOMEM);
  140         if (tsize > MAXTSIZ)
  141                 return (ENOMEM);
  142 
  143         p->p_vmspace->vm_taddr = SCARG(uap, taddr);
  144         p->p_vmspace->vm_tsize = tsize;
  145         p->p_vmspace->vm_daddr = SCARG(uap, daddr);
  146         p->p_vmspace->vm_dsize = dsize;
  147 
  148         return (0);
  149 }
  150 
  151 int
  152 osf1_sys_setsysinfo(p, v, retval)
  153         struct proc *p;
  154         void *v;
  155         register_t *retval;
  156 {
  157 
  158         /* XXX */
  159         return (0);
  160 }
  161 
  162 int
  163 osf1_sys_sysinfo(p, v, retval)
  164         struct proc *p;
  165         void *v;
  166         register_t *retval;
  167 {
  168         struct osf1_sys_sysinfo_args *uap = v;
  169         const char *string;
  170         int error;
  171 
  172         error = 0;
  173         switch (SCARG(uap, cmd)) {
  174         case OSF1_SI_SYSNAME:
  175                 goto should_handle;
  176                 /* string = ostype; */
  177                 break;
  178 
  179         case OSF1_SI_HOSTNAME:
  180                 string = hostname;
  181                 break;
  182 
  183         case OSF1_SI_RELEASE:
  184                 string = version;
  185                 break;
  186 
  187         case OSF1_SI_VERSION:
  188                 goto should_handle;
  189 
  190         case OSF1_SI_MACHINE:
  191                 string = MACHINE;
  192                 break;
  193 
  194         case OSF1_SI_ARCHITECTURE:
  195                 string = MACHINE_ARCH;
  196                 break;
  197 
  198         case OSF1_SI_HW_SERIAL:
  199                 string = "666";                 /* OSF/1 emulation?  YES! */
  200                 break;
  201 
  202         case OSF1_SI_HW_PROVIDER:
  203                 string = "unknown";
  204                 break;
  205 
  206         case OSF1_SI_SRPC_DOMAIN:
  207                 goto dont_care;
  208 
  209         case OSF1_SI_SET_HOSTNAME:
  210                 goto should_handle;
  211 
  212         case OSF1_SI_SET_SYSNAME:
  213                 goto should_handle;
  214 
  215         case OSF1_SI_SET_SRPC_DOMAIN:
  216                 goto dont_care;
  217 
  218         default:
  219 should_handle:
  220                 printf("osf1_sys_sysinfo(%d, %p, 0x%lx)\n", SCARG(uap, cmd),
  221                     SCARG(uap, buf), SCARG(uap,len));
  222 dont_care:
  223                 error = EINVAL;
  224                 break;
  225         };
  226 
  227         if (error == 0)
  228                 error = copyoutstr(string, SCARG(uap, buf), SCARG(uap, len),
  229                     NULL);
  230 
  231         return (error);
  232 }
  233 
  234 int
  235 osf1_sys_uname(p, v, retval)
  236         struct proc *p;
  237         void *v;
  238         register_t *retval;
  239 {
  240         struct osf1_sys_uname_args *uap = v;
  241         struct osf1_utsname u;
  242         const char *cp;
  243         extern char hostname[], machine[];
  244         char *dp, *ep;
  245 
  246         /* XXX would use stackgap, but our struct utsname is too big! */
  247 
  248         bzero(&u, sizeof(u));
  249         strlcpy(u.sysname, ostype, sizeof(u.sysname));
  250         strlcpy(u.nodename, hostname, sizeof(u.nodename));
  251         strlcpy(u.release, osrelease, sizeof(u.release));
  252 
  253         dp = u.version;
  254         ep = &u.version[sizeof(u.version) - 1];
  255         for (cp = version; *cp && *cp != '('; cp++)
  256                 ;
  257         for (cp++; *cp && *cp != ')' && dp < ep; cp++)
  258                 *dp++ = *cp;
  259         for (; *cp && *cp != '#'; cp++)
  260                 ;
  261         for (; *cp && *cp != ':' && dp < ep; cp++)
  262                 *dp++ = *cp;
  263         *dp = '\0';
  264 
  265         strlcpy(u.machine, machine, sizeof(u.machine));
  266 
  267         return (copyout((caddr_t)&u, (caddr_t)SCARG(uap, name), sizeof u));
  268 }
  269 
  270 int
  271 osf1_sys_usleep_thread(p, v, retval)
  272         struct proc *p;
  273         void *v;
  274         register_t *retval;
  275 {
  276         struct osf1_sys_usleep_thread_args *uap = v;
  277         struct osf1_timeval otv, endotv;
  278         struct timeval tv, endtv;
  279         u_long ticks;
  280         int error;
  281 
  282         if ((error = copyin(SCARG(uap, sleep), &otv, sizeof otv)))
  283                 return (error);
  284         tv.tv_sec = otv.tv_sec;
  285         tv.tv_usec = otv.tv_usec;
  286 
  287         ticks = howmany((u_long)tv.tv_sec * 1000000 + tv.tv_usec, tick);
  288         if (ticks == 0)
  289                 ticks = 1;
  290 
  291         getmicrotime(&tv);
  292 
  293         tsleep(p, PUSER|PCATCH, "uslpthrd", ticks);     /* XXX */
  294 
  295         if (SCARG(uap, slept) != NULL) {
  296                 struct timeval tv2;
  297 
  298                 getmicrotime(&tv2);
  299                 timersub(&tv2, &tv, &endtv);
  300 
  301                 if (endtv.tv_sec < 0 || endtv.tv_usec < 0)
  302                         endtv.tv_sec = endtv.tv_usec = 0;
  303 
  304                 endotv.tv_sec = endtv.tv_sec;
  305                 endotv.tv_usec = endtv.tv_usec;
  306                 error = copyout(&endotv, SCARG(uap, slept), sizeof endotv);
  307         }
  308         return (error);
  309 }
  310 
  311 int
  312 osf1_sys_wait4(p, v, retval)
  313         struct proc *p;
  314         void *v;
  315         register_t *retval;
  316 {
  317         struct osf1_sys_wait4_args *uap = v;
  318         struct sys_wait4_args a;
  319         struct osf1_rusage osf1_rusage;
  320         struct rusage netbsd_rusage;
  321         unsigned long leftovers;
  322         caddr_t sg;
  323         int error;
  324 
  325         SCARG(&a, pid) = SCARG(uap, pid);
  326         SCARG(&a, status) = SCARG(uap, status);
  327 
  328         /* translate options */
  329         SCARG(&a, options) = emul_flags_translate(osf1_wait_options_xtab,
  330             SCARG(uap, options), &leftovers);
  331         if (leftovers != 0)
  332                 return (EINVAL);
  333 
  334         if (SCARG(uap, rusage) == NULL)
  335                 SCARG(&a, rusage) = NULL;
  336         else {
  337                 sg = stackgap_init(p->p_emul);
  338                 SCARG(&a, rusage) = stackgap_alloc(&sg, sizeof netbsd_rusage);
  339         }
  340 
  341         error = sys_wait4(p, &a, retval);
  342 
  343         if (error == 0 && SCARG(&a, rusage) != NULL) {
  344                 error = copyin((caddr_t)SCARG(&a, rusage),
  345                     (caddr_t)&netbsd_rusage, sizeof netbsd_rusage);
  346                 if (error == 0) {
  347                         osf1_cvt_rusage_from_native(&netbsd_rusage,
  348                             &osf1_rusage);
  349                         error = copyout((caddr_t)&osf1_rusage,
  350                             (caddr_t)SCARG(uap, rusage), sizeof osf1_rusage);
  351                 }
  352         }
  353 
  354         return (error);
  355 }

/* [<][>][^][v][top][bottom][index][help] */