The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/compat/osf1/osf1_misc.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* $NetBSD: osf1_misc.c,v 1.82 2008/04/22 21:29:21 ad 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 /*
   34  * Copyright (c) 1994, 1995 Carnegie-Mellon University.
   35  * All rights reserved.
   36  *
   37  * Author: Chris G. Demetriou
   38  *
   39  * Permission to use, copy, modify and distribute this software and
   40  * its documentation is hereby granted, provided that both the copyright
   41  * notice and this permission notice appear in all copies of the
   42  * software, derivative works or modified versions, and any portions
   43  * thereof, and that both notices appear in supporting documentation.
   44  *
   45  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   46  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
   47  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   48  *
   49  * Carnegie Mellon requests users of this software to return to
   50  *
   51  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   52  *  School of Computer Science
   53  *  Carnegie Mellon University
   54  *  Pittsburgh PA 15213-3890
   55  *
   56  * any improvements or extensions that they make and grant Carnegie the
   57  * rights to redistribute these changes.
   58  */
   59 
   60 #include <sys/cdefs.h>
   61 __KERNEL_RCSID(0, "$NetBSD: osf1_misc.c,v 1.82 2008/04/22 21:29:21 ad Exp $");
   62 
   63 #if defined(_KERNEL_OPT)
   64 #include "opt_syscall_debug.h"
   65 #endif
   66 
   67 #include <sys/param.h>
   68 #include <sys/systm.h>
   69 #include <sys/namei.h>
   70 #include <sys/proc.h>
   71 #include <sys/file.h>
   72 #include <sys/stat.h>
   73 #include <sys/filedesc.h>
   74 #include <sys/kernel.h>
   75 #include <sys/malloc.h>
   76 #include <sys/mman.h>
   77 #include <sys/mount.h>
   78 #include <sys/signal.h>
   79 #include <sys/signalvar.h>
   80 #include <sys/reboot.h>
   81 #include <sys/syscallargs.h>
   82 #include <sys/exec.h>
   83 #include <sys/vnode.h>
   84 #include <sys/socketvar.h>
   85 #include <sys/resource.h>
   86 #include <sys/resourcevar.h>
   87 #include <sys/user.h>
   88 #include <sys/wait.h>
   89 
   90 #include <machine/alpha.h>
   91 #include <machine/cpuconf.h>
   92 #include <machine/rpb.h>
   93 #include <machine/fpu.h>
   94 
   95 #include <compat/osf1/osf1.h>
   96 #include <compat/osf1/osf1_syscallargs.h>
   97 #include <compat/common/compat_util.h>
   98 #include <compat/osf1/osf1_cvt.h>
   99 
  100 #ifdef SYSCALL_DEBUG
  101 extern int scdebug;
  102 #endif
  103 
  104 int
  105 osf1_sys_classcntl(struct lwp *l, const struct osf1_sys_classcntl_args *uap, register_t *retval)
  106 {
  107 
  108         /* XXX */
  109         return (ENOSYS);
  110 }
  111 
  112 int
  113 osf1_sys_reboot(struct lwp *l, const struct osf1_sys_reboot_args *uap, register_t *retval)
  114 {
  115         struct sys_reboot_args a;
  116         unsigned long leftovers;
  117 
  118         /* translate opt */
  119         SCARG(&a, opt) = emul_flags_translate(osf1_reboot_opt_xtab,
  120             SCARG(uap, opt), &leftovers);
  121         if (leftovers != 0)
  122                 return (EINVAL);
  123 
  124         SCARG(&a, bootstr) = NULL;
  125 
  126         return sys_reboot(l, &a, retval);
  127 }
  128 
  129 int
  130 osf1_sys_set_program_attributes(struct lwp *l, const struct osf1_sys_set_program_attributes_args *uap, register_t *retval)
  131 {
  132         struct proc *p = l->l_proc;
  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         /* XXXSMP unlocked */
  144         p->p_vmspace->vm_taddr = SCARG(uap, taddr);
  145         p->p_vmspace->vm_tsize = tsize;
  146         p->p_vmspace->vm_daddr = SCARG(uap, daddr);
  147         p->p_vmspace->vm_dsize = dsize;
  148 
  149         return (0);
  150 }
  151 
  152 int
  153 osf1_sys_getsysinfo(struct lwp *l, const struct osf1_sys_getsysinfo_args *uap, register_t *retval)
  154 {
  155         extern int ncpus;
  156         int error;
  157         int unit;
  158         long percpu;
  159         long proctype;
  160         u_int64_t fpflags;
  161         struct osf1_cpu_info cpuinfo;
  162         const void *data;
  163         size_t datalen;
  164 
  165         error = 0;
  166 
  167         switch(SCARG(uap, op))
  168         {
  169         case OSF_GET_MAX_UPROCS:
  170                 data = &maxproc;
  171                 datalen = sizeof(maxproc);
  172                 break;
  173         case OSF_GET_PHYSMEM:
  174                 data = &physmem;
  175                 datalen = sizeof(physmem);
  176                 break;
  177         case OSF_GET_MAX_CPU:
  178         case OSF_GET_CPUS_IN_BOX:
  179                 data = &ncpus;
  180                 datalen = sizeof(ncpus);
  181                 break;
  182         case OSF_GET_IEEE_FP_CONTROL:
  183                 if (((fpflags = alpha_read_fp_c(l)) & IEEE_INHERIT) != 0) {
  184                         fpflags |= 1ULL << 63;
  185                         fpflags &= ~IEEE_INHERIT;
  186                 }
  187                 data = &fpflags;
  188                 datalen = sizeof(fpflags);
  189                 break;
  190         case OSF_GET_CPU_INFO:
  191                 memset(&cpuinfo, 0, sizeof(cpuinfo));
  192 #ifdef __alpha__
  193                 unit = alpha_pal_whami();
  194 #else
  195                 unit = 0; /* XXX */
  196 #endif
  197                 cpuinfo.current_cpu = unit;
  198                 cpuinfo.cpus_in_box = ncpus;
  199                 cpuinfo.cpu_type = LOCATE_PCS(hwrpb, unit)->pcs_proc_type;
  200                 cpuinfo.ncpus = ncpus;
  201                 cpuinfo.cpus_present = ncpus;
  202                 cpuinfo.cpus_running = ncpus;
  203                 cpuinfo.cpu_binding = 1;
  204                 cpuinfo.cpu_ex_binding = 0;
  205                 cpuinfo.mhz = hwrpb->rpb_cc_freq / 1000000;
  206                 data = &cpuinfo;
  207                 datalen = sizeof(cpuinfo);
  208                 break;
  209         case OSF_GET_PROC_TYPE:
  210 #ifdef __alpha__
  211                 unit = alpha_pal_whami();
  212                 proctype = LOCATE_PCS(hwrpb, unit)->pcs_proc_type;
  213 #else
  214                 proctype = 0;   /* XXX */
  215 #endif
  216                 data = &proctype;
  217                 datalen = sizeof(percpu);
  218                 break;
  219         case OSF_GET_HWRPB: /* note -- osf/1 doesn't have rpb_tbhint[8] */
  220                 data = hwrpb;
  221                 datalen = hwrpb->rpb_size;
  222                 break;
  223         case OSF_GET_PLATFORM_NAME:
  224                 data = platform.model;
  225                 datalen = strlen(platform.model) + 1;
  226                 break;
  227         default:
  228                 printf("osf1_getsysinfo called with unknown op=%ld\n",
  229                        SCARG(uap, op));
  230                 /* return EINVAL; */
  231                 return 0;
  232         }
  233 
  234         if (SCARG(uap, nbytes) < datalen)
  235                 return (EINVAL);
  236         error = copyout(data, SCARG(uap, buffer), datalen);
  237         if (!error)
  238                 retval[0] = 1;
  239         return (error);
  240 }
  241 
  242 int
  243 osf1_sys_setsysinfo(struct lwp *l, const struct osf1_sys_setsysinfo_args *uap, register_t *retval)
  244 {
  245         u_int64_t temp;
  246         int error;
  247 
  248         error = 0;
  249 
  250         switch(SCARG(uap, op)) {
  251         case OSF_SET_IEEE_FP_CONTROL:
  252 
  253                 if ((error = copyin(SCARG(uap, buffer), &temp, sizeof(temp))))
  254                         break;
  255                 if (temp >> 63 != 0)
  256                         temp |= IEEE_INHERIT;
  257                 alpha_write_fp_c(l, temp);
  258                 break;
  259         default:
  260                 uprintf("osf1_setsysinfo called with op=%ld\n", SCARG(uap, op));
  261                 //error = EINVAL;
  262         }
  263         retval[0] = 0;
  264         return (error);
  265 }
  266 
  267 int
  268 osf1_sys_sysinfo(struct lwp *l, const struct osf1_sys_sysinfo_args *uap, register_t *retval)
  269 {
  270         const char *string;
  271         size_t slen;
  272         int error;
  273 
  274         error = 0;
  275         switch (SCARG(uap, cmd)) {
  276         case OSF1_SI_SYSNAME:
  277                 string = ostype;
  278                 break;
  279 
  280         case OSF1_SI_HOSTNAME:
  281                 string = hostname;
  282                 break;
  283 
  284         case OSF1_SI_RELEASE:
  285                 string = osrelease;
  286                 break;
  287 
  288         case OSF1_SI_VERSION:
  289                 goto should_handle;
  290 
  291         case OSF1_SI_MACHINE:
  292                 string = MACHINE;
  293                 break;
  294 
  295         case OSF1_SI_ARCHITECTURE:
  296                 string = MACHINE_ARCH;
  297                 break;
  298 
  299         case OSF1_SI_HW_SERIAL:
  300                 string = "666";                 /* OSF/1 emulation?  YES! */
  301                 break;
  302 
  303         case OSF1_SI_HW_PROVIDER:
  304                 string = "unknown";
  305                 break;
  306 
  307         case OSF1_SI_SRPC_DOMAIN:
  308                 goto dont_care;
  309 
  310         case OSF1_SI_SET_HOSTNAME:
  311                 goto should_handle;
  312 
  313         case OSF1_SI_SET_SYSNAME:
  314                 goto should_handle;
  315 
  316         case OSF1_SI_SET_SRPC_DOMAIN:
  317                 goto dont_care;
  318 
  319         default:
  320 should_handle:
  321                 printf("osf1_sys_sysinfo(%d, %p, 0x%lx)\n", SCARG(uap, cmd),
  322                     SCARG(uap, buf), SCARG(uap,len));
  323 dont_care:
  324                 return (EINVAL);
  325         };
  326 
  327         slen = strlen(string) + 1;
  328         if (SCARG(uap, buf)) {
  329                 error = copyout(string, SCARG(uap, buf),
  330                                 min(slen, SCARG(uap, len)));
  331                 if (!error && (SCARG(uap, len) > 0) && (SCARG(uap, len) < slen))
  332                         subyte(SCARG(uap, buf) + SCARG(uap, len) - 1, 0);
  333         }
  334         if (!error)
  335                 retval[0] = slen;
  336 
  337         return (error);
  338 }
  339 
  340 int
  341 osf1_sys_uname(struct lwp *l, const struct osf1_sys_uname_args *uap, register_t *retval)
  342 {
  343         struct osf1_utsname u;
  344         const char *cp;
  345         char *dp, *ep;
  346 
  347         strncpy(u.sysname, ostype, sizeof(u.sysname));
  348         strncpy(u.nodename, hostname, sizeof(u.nodename));
  349         strncpy(u.release, osrelease, sizeof(u.release));
  350         dp = u.version;
  351         ep = &u.version[sizeof(u.version) - 1];
  352         for (cp = version; *cp && *cp != '('; cp++)
  353                 ;
  354         for (cp++; *cp && *cp != ')' && dp < ep; cp++)
  355                 *dp++ = *cp;
  356         for (; *cp && *cp != '#'; cp++)
  357                 ;
  358         for (; *cp && *cp != ':' && dp < ep; cp++)
  359                 *dp++ = *cp;
  360         *dp = '\0';
  361         strncpy(u.machine, MACHINE, sizeof(u.machine));
  362         return (copyout((void *)&u, (void *)SCARG(uap, name), sizeof u));
  363 }
  364 
  365 int
  366 osf1_sys_usleep_thread(struct lwp *l, const struct osf1_sys_usleep_thread_args *uap, register_t *retval)
  367 {
  368         struct osf1_timeval otv, endotv;
  369         struct timeval tv, ntv, endtv;
  370         u_long ticks;
  371         int error;
  372 
  373         if ((error = copyin(SCARG(uap, sleep), &otv, sizeof otv)))
  374                 return (error);
  375         tv.tv_sec = otv.tv_sec;
  376         tv.tv_usec = otv.tv_usec;
  377 
  378         ticks = howmany((u_long)tv.tv_sec * 1000000 + tv.tv_usec, tick);
  379         if (ticks == 0)
  380                 ticks = 1;
  381 
  382         getmicrotime(&tv);
  383 
  384         tsleep(l, PUSER|PCATCH, "uslpthrd", ticks);     /* XXX */
  385 
  386         if (SCARG(uap, slept) != NULL) {
  387                 getmicrotime(&ntv);
  388                 timersub(&ntv, &tv, &endtv);
  389                 if (endtv.tv_sec < 0 || endtv.tv_usec < 0)
  390                         endtv.tv_sec = endtv.tv_usec = 0;
  391 
  392                 endotv.tv_sec = endtv.tv_sec;
  393                 endotv.tv_usec = endtv.tv_usec;
  394                 error = copyout(&endotv, SCARG(uap, slept), sizeof endotv);
  395         }
  396         return (error);
  397 }
  398 
  399 int
  400 osf1_sys_wait4(struct lwp *l, const struct osf1_sys_wait4_args *uap, register_t *retval)
  401 {
  402         struct osf1_rusage osf1_rusage;
  403         struct rusage netbsd_rusage;
  404         unsigned long leftovers;
  405         int error, status, was_zombie;
  406         int options = SCARG(uap, options);
  407         int pid = SCARG(uap, pid);
  408 
  409         /* translate options */
  410         options = emul_flags_translate(osf1_wait_options_xtab,
  411             options, &leftovers);
  412         if (leftovers != 0)
  413                 return (EINVAL);
  414 
  415         error = do_sys_wait(l, & pid, &status, options | WOPTSCHECKED,
  416             SCARG(uap, rusage) != NULL ? &netbsd_rusage : NULL, &was_zombie);
  417 
  418         retval[0] = pid;
  419         if (pid == 0)
  420                 return error;
  421 
  422         if (SCARG(uap, rusage)) {
  423                 osf1_cvt_rusage_from_native(&netbsd_rusage, &osf1_rusage);
  424                 error = copyout(&osf1_rusage, SCARG(uap, rusage),
  425                     sizeof osf1_rusage);
  426         }
  427 
  428         if (error == 0 && SCARG(uap, status))
  429                 error = copyout(&status, SCARG(uap, status), sizeof(status));
  430 
  431         return error;
  432 }

Cache object: 24fe72fc4a5aaaa783259f39c12bd9ee


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.