home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / trash / part07 / bsd43.c
Encoding:
C/C++ Source or Header  |  1992-03-22  |  50.1 KB  |  2,436 lines

  1. #include        <bsd43/sys/syscall.h>
  2. #include        <bsd43/sys/param.h>
  3. #include        <bsd43/sys/types.h>
  4. #include        <bsd43/sys/vfs.h>
  5. #include        <bsd43/sys/time.h>
  6. #include        <bsd43/sys/resource.h>
  7. #include        <bsd43/sys/ioctl.h>
  8. #include        <bsd43/sys/stat.h>
  9. #include        <bsd43/sys/file.h>
  10. #include        <bsd43/sys/socket.h>
  11. #include        <bsd43/sys/uio.h>
  12. #include        <bsd43/sys/wait.h>
  13. #include        <bsd43/sys/sysmips.h>
  14. #include        <bsd43/mips/hwconf.h>
  15. #define    NFSCLIENT
  16. #include        <bsd43/sys/mount.h>
  17. #undef    NFSCLIENT
  18. #include        <bsd43/rpc/types.h>
  19. #include        <bsd43/rpc/auth.h>
  20. #include        <bsd43/nfs/nfs.h>
  21. #include        <bsd43/netinet/in.h>
  22. #include        <bsd43/nfs/nfs_clnt.h>
  23. #include        <bsd43/nfs/export.h>
  24. #include        <bsd43/fcntl.h>
  25. #include        <bsd43/signal.h>
  26. #include        <fcntl.h>
  27. #include        <errno.h>
  28. #include        <stdio.h>
  29. #include        "register.h"
  30. #include        "symtab.h"
  31. #include        "diblock.h"
  32. #include        "instrn.h"
  33. #include        "process.h"
  34. #include        "sysentry.h"
  35. #include        "res.h"
  36. #include        "nels.h"
  37. #include        "flag.h"
  38. #include        "generic.h"
  39.  
  40. extern int        fd_lookup();
  41. extern int        fd_open();
  42. extern void        fd_dopen();
  43. extern int        fd_close();
  44. extern int        fd_sort();
  45. extern void        histo_dump();
  46. extern void        hist_dump();
  47. extern char        *strdup();
  48. extern int        bufset();
  49. extern int        mstrlen();
  50. extern int        mgetstring();
  51. extern int        mgets();
  52. extern char        **mgetvp();
  53. extern int        mfreevp();
  54. extern int        augment_execve_args();
  55. extern int        mget();
  56. extern int        mput();
  57. extern void        say_time();
  58. extern char        *proc_text_address();
  59. extern char        *signal_set();
  60. extern int        sysv_sys_ioctl();
  61.  
  62. extern FILE        *outfp;
  63. extern int        errno;
  64.  
  65. extern int        Fflag;
  66.  
  67. extern unsigned long    arg[];
  68.  
  69. extern int        return_errno;    /* errno goes here. */
  70. extern long        return_value0;    /* Result 1 value goes here. */
  71. extern long        return_value1;    /* Result 2 value goes here. */
  72.  
  73. extern sysentry        *current_sysentp;
  74. extern char        *sys_call_buf;    /* Scratch buf. */
  75.  
  76. static
  77. int
  78. sys_adjtime(syscallno)
  79. int    syscallno;
  80. {
  81.     struct bsd43_timeval    tv;
  82.     struct bsd43_timeval    otv;
  83.  
  84.     return generic_adjtime(syscallno, &tv, sizeof(tv), &otv, sizeof(otv));
  85. }
  86.  
  87. static
  88. int
  89. sys_dup2(syscallno)
  90. int    syscallno;
  91. {
  92.     int    old_real_fd;
  93.  
  94.     Rstart;
  95.     return_value0 = syscall(BSD43_SYS_dup, fd_lookup((int)arg[0]));
  96.     return_errno = errno;
  97.     Rstop;
  98.  
  99.     if (return_value0 == -1)
  100.         return 0;
  101.  
  102.     if ((old_real_fd = fd_lookup((int)arg[1])) != -1)
  103.     {
  104.         (void)close(old_real_fd);
  105.         (void)fd_close((int)arg[1]);
  106.     }
  107.  
  108.     fd_dopen(return_value0, (int)arg[1]);
  109.  
  110.     return_value0 = (int)arg[1];
  111.  
  112.     return 0;
  113. }
  114.  
  115. static
  116. int
  117. sys_execve(syscallno)
  118. int    syscallno;
  119. {
  120.     char    *filename;
  121.     char    **argp;
  122.     char    **envp;
  123.     int    need_close_on_exec;
  124.  
  125.     if (mgetstring(arg[0]) == -1)
  126.         return -1;
  127.  
  128.     if ((filename = strdup(sys_call_buf)) == (char *)0)
  129.     {
  130.         vcouldnot("execve(): ran out of memory");
  131.         return -1;
  132.     }
  133.  
  134.     if ((argp = mgetvp(arg[1])) == (char **)0)
  135.         return -1;
  136.  
  137.     if ((envp = mgetvp(arg[2])) == (char **)0)
  138.         return -1;
  139.  
  140.     if (fd_sort() == -1)
  141.         return -1;
  142.  
  143.     if (Fflag)
  144.     {
  145.         int    mok;
  146.  
  147.         if
  148.         (
  149.             syscall(BSD43_SYS_access, filename, BSD43_X_OK) != 0
  150.             ||
  151.             (mok = magic_ok(filename)) == 0
  152.             ||
  153.             (mok == 2 && interpreter_ok(filename) == 0)
  154.             ||
  155.             is_a_shared_library(filename)
  156.         )
  157.         {
  158.             return_value0 = -1;
  159.             return_errno = errno;
  160.  
  161.             if (mfreevp(envp) == -1)
  162.                 return -1;
  163.  
  164.             if (mfreevp(argp) == -1)
  165.                 return -1;
  166.  
  167.             (void)free(filename);
  168.  
  169.             return 0;
  170.         }
  171.  
  172.         if (augment_execve_args(&filename, &argp, &envp) == -1)
  173.         {
  174.             (void)mfreevp(envp);
  175.             (void)mfreevp(argp);
  176.             (void)free(filename);
  177.         }
  178.  
  179.         need_close_on_exec = 0;
  180.     }
  181.     else
  182.     {
  183.         histo_dump();
  184.         hist_dump();
  185.  
  186.         if (fcntl(fileno(outfp), F_SETFD, 1) == -1)
  187.         {
  188.             vcouldnot("fcntl(%d, F_SETFD, 1)", fileno(outfp));
  189.             return -1;
  190.         }
  191.  
  192.         need_close_on_exec = 1;
  193.     }
  194.  
  195.     Rstart;
  196.     return_value0 = syscall(syscallno, filename, argp, envp);
  197.     return_errno = errno;
  198.     Rstop;
  199.  
  200.     if (need_close_on_exec)
  201.     {
  202.         if (fcntl(fileno(outfp), F_SETFD, 0) == -1)
  203.         {
  204.             vcouldnot("fcntl(%d, F_SETFD, 0)", fileno(outfp));
  205.             return -1;
  206.         }
  207.     }
  208.  
  209.     if (mfreevp(envp) == -1)
  210.         return -1;
  211.  
  212.     if (mfreevp(argp) == -1)
  213.         return -1;
  214.  
  215.     (void)free(filename);
  216.  
  217.     return 0;
  218. }
  219.  
  220. static
  221. int
  222. sys_exportfs(syscallno)
  223. int    syscallno;
  224. {
  225.     char        *dirnamep;
  226.     char        dirname[1024];
  227.     struct export    exent;
  228.     struct export    *exp;
  229.     int        first_length;
  230.     int        write_length;
  231.  
  232.     if (mgets(arg[0], &dirnamep) == -1)
  233.         return -1;
  234.  
  235.     if (dirnamep != (char *)0)
  236.     {
  237.         (void)strcpy(&dirname[0], dirnamep);
  238.         dirnamep = &dirname[0];
  239.     }
  240.  
  241.     if (arg[1] == (unsigned long)0)
  242.         exp = (struct export *)0;
  243.     else
  244.     {
  245.         if (quiet_procmget(GLOBALdipc, (unsigned long)arg[1], &exent, sizeof(exent)) == -1)
  246.             return -1;
  247.  
  248.         if (exent.ex_flags & EX_RDMOSTLY)
  249.         {
  250.             write_length = exent.ex_writeaddrs.naddrs * sizeof(struct bsd43_sockaddr);
  251. #if    0
  252. fprintf(stderr, "writenaddrs = %d, write_length = %d\n", exent.ex_writeaddrs.naddrs, write_length);
  253. #endif    /* 0 */
  254.         }
  255.         else
  256.             write_length = 0;
  257.  
  258.         switch (exent.ex_auth)
  259.         {
  260.         case AUTH_UNIX:
  261.             first_length = exent.ex_u.exunix.rootaddrs.naddrs * sizeof(struct bsd43_sockaddr);
  262. #if    0
  263. fprintf(stderr, "rootnaddrs = %d, root_length = %d\n", exent.ex_u.exunix.rootaddrs.naddrs, first_length);
  264. #endif    /* 0 */
  265.  
  266.             if (bufset((unsigned int)(first_length + write_length)) == -1)
  267.                 return -1;
  268.  
  269.             if (quiet_procmget(GLOBALdipc, (unsigned long)exent.ex_u.exunix.rootaddrs.addrvec, sys_call_buf, first_length) == -1)
  270.                 return -1;
  271.  
  272.             exent.ex_u.exunix.rootaddrs.addrvec = (struct sockaddr *)sys_call_buf;
  273.             break;
  274.  
  275.         case AUTH_DES:
  276.             /*
  277.              * No thanks -- I'll wait till I see it used.
  278.              */
  279.             return -2;
  280.  
  281.         default:
  282.             return -2;
  283.         }
  284.  
  285.         if (exent.ex_flags & EX_RDMOSTLY)
  286.         {
  287.             if (quiet_procmget(GLOBALdipc, (unsigned long)exent.ex_writeaddrs.addrvec, sys_call_buf + first_length, write_length) == -1)
  288.                 return -1;
  289.  
  290.             exent.ex_writeaddrs.addrvec = (struct sockaddr *)(sys_call_buf + first_length);
  291.         }
  292.  
  293.         exp = &exent;
  294.     }
  295.  
  296.     Rstart;
  297.     return_value0 = syscall(syscallno, dirnamep, exp);
  298.     return_errno = errno;
  299.     Rstop;
  300.  
  301.     return 0;
  302. }
  303.  
  304. static
  305. int
  306. sys_fcntl(syscallno)
  307. int    syscallno;
  308. {
  309.     switch ((int)arg[1])
  310.     {
  311.     case BSD43_F_DUPFD:
  312.         Rstart;
  313.         return_value0 = syscall(BSD43_SYS_dup, fd_lookup((int)arg[0]));
  314.         return_errno = errno;
  315.         Rstop;
  316.  
  317.         if (return_value0 != -1)
  318.         {
  319.             int    newfd;
  320.             int    nfiles;
  321.  
  322.             for (nfiles = fd_nfiles(), newfd = (int)arg[2]; newfd < nfiles && fd_lookup(newfd) != -1; newfd++)
  323.                 ;
  324.  
  325.             if (newfd >= nfiles)
  326.             {
  327.                 (void)close(return_value0);
  328.                 errno = EMFILE;
  329.                 return 0;
  330.             }
  331.  
  332.             fd_dopen(return_value0, newfd);
  333.  
  334.             return_value0 = newfd;
  335.         }
  336.         break;
  337.  
  338.     case BSD43_F_GETFD:
  339.     case BSD43_F_SETFD:
  340.     case BSD43_F_GETFL:
  341.     case BSD43_F_SETFL:
  342.     case BSD43_F_SETOWN:
  343.         Rstart;
  344.         return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), (int)arg[1], (int)arg[2]);
  345.         return_errno = errno;
  346.         Rstop;
  347.         break;
  348.  
  349.     default:
  350.         return -2;
  351.     }
  352.  
  353.     return 0;
  354. }
  355.  
  356. static
  357. int
  358. sys_fstat(syscallno)
  359. int    syscallno;
  360. {
  361.     return generic_fstat(syscallno, sizeof(struct bsd43_stat));
  362. }
  363.  
  364. static
  365. int
  366. sys_fstatfs(syscallno)
  367. int    syscallno;
  368. {
  369.     struct bsd43_statfs    *bufp;
  370.  
  371.     if (dmget(arg[1], sizeof(*bufp), &bufp) == -1)
  372.         return -1;
  373.  
  374.     Rstart;
  375.     return_value0 = syscall(syscallno, arg[0], bufp);
  376.     return_errno = errno;
  377.     Rstop;
  378.  
  379.     if (mput(arg[1], bufp, sizeof(*bufp), return_value0) == -1)
  380.         return -1;
  381.  
  382.     return 0;
  383. }
  384.  
  385. static
  386. int
  387. sys_getgid(syscallno)
  388. int    syscallno;
  389. {
  390.     /*
  391.      * TODO: second return value for BSD43 getgid().
  392.      */
  393.     Rstart;
  394.     return_value0 = syscall(syscallno);
  395.     return_value1 = getegid();    /* Not really correct. */
  396.     return_errno = errno;
  397.     Rstop;
  398.  
  399.     return 0;
  400. }
  401.  
  402. static
  403. int
  404. sys_getgroups(syscallno)
  405. int    syscallno;
  406. {
  407.     return generic_getgroups(syscallno, BSD43_NGROUPS);
  408. }
  409.  
  410. static
  411. int
  412. sys_getitimer(syscallno)
  413. int    syscallno;
  414. {
  415.     return generic_getitimer(syscallno, sizeof(struct bsd43_itimerval));
  416. }
  417.  
  418. static
  419. int
  420. sys_getpgrp(syscallno)
  421. int    syscallno;
  422. {
  423.     Rstart;
  424.     return_value0 = syscall(syscallno, (int)arg[0]);
  425.     return_errno = errno;
  426.     Rstop;
  427.  
  428.     return 0;
  429. }
  430.  
  431. static
  432. int
  433. sys_getrlimit(syscallno)
  434. int    syscallno;
  435. {
  436.     return generic_getrlimit(syscallno, sizeof(struct bsd43_rlimit));
  437. }
  438.  
  439. static
  440. int
  441. sys_getrusage(syscallno)
  442. int    syscallno;
  443. {
  444.     return generic_getrusage(syscallno, sizeof(struct bsd43_rusage));
  445. }
  446.  
  447. static
  448. int
  449. sys_gettimeofday(syscallno)
  450. int    syscallno;
  451. {
  452.     struct bsd43_timeval    tv;
  453.     struct bsd43_timezone    tz;
  454.  
  455.     return generic_gettimeofday(syscallno, &tv, sizeof(tv), &tz, sizeof(tz));
  456. }
  457.  
  458. static
  459. int
  460. sys_getuid(syscallno)
  461. int    syscallno;
  462. {
  463.     /*
  464.      * TODO: second return value for BSD43 getuid().
  465.      */
  466.     Rstart;
  467.     return_value0 = syscall(syscallno);
  468.     return_value1 = geteuid();    /* Not really correct. */
  469.     return_errno = errno;
  470.     Rstop;
  471.  
  472.     return 0;
  473. }
  474.  
  475. typedef union bsd43_ifcu    bsd43_ifcu;
  476. union bsd43_ifcu
  477. {
  478.     caddr_t        ifcu_buf;
  479.     struct ifreq    *ifcu_req;
  480. };
  481.  
  482. typedef struct bsd43_ifconf    bsd43_ifconf;
  483. struct bsd43_ifconf
  484. {
  485.     int        ifc_len;    /* size of associated buffer */
  486.     bsd43_ifcu    ifc_ifcu;
  487. };
  488.  
  489. #define    ifconf    bsd43_ifconf
  490.  
  491. /*
  492.  * See /bsd43/usr/include/sys/ioctl.h.
  493.  */
  494. static
  495. int
  496. sys_ioctl(syscallno)
  497. int    syscallno;
  498. {
  499.     int        length;
  500.     int        need_copy_in;
  501.     int        need_copy_out;
  502.     char        iocbuf[BSD43_IOCPARM_MASK];
  503.     bsd43_ifconf    *ifp;
  504.     caddr_t        saved_ifcu_buf;
  505.  
  506.     if ((arg[1] & (unsigned long)(BSD43_IOC_INOUT | BSD43_IOC_VOID)) == 0)
  507.         return sysv_sys_ioctl();
  508.  
  509.     need_copy_in = arg[1] & (unsigned long)BSD43_IOC_IN;
  510.     need_copy_out = arg[1] & (unsigned long)BSD43_IOC_OUT;
  511.     length = (arg[1] >> (unsigned long)16) & (unsigned long)BSD43_IOCPARM_MASK;
  512.  
  513.     if (need_copy_in)
  514.     {
  515.         if (quiet_procmget(GLOBALdipc, (unsigned long)arg[2], &iocbuf[0], length) == -1)
  516.             return -1;
  517.     }
  518.  
  519.     /*
  520.      * Sadly, the bsd43 ioctl encoding scheme only handles
  521.      * one level of indirection, so ...
  522.      */
  523.     switch (arg[1])
  524.     {
  525.     case BSD43_SIOCGIFCONF:
  526.         /*
  527.          * if(7)
  528.          */
  529.         ifp = (bsd43_ifconf *)&iocbuf[0];
  530.  
  531.         if (bufset((unsigned int)ifp->ifc_len) == -1)
  532.             return -1;
  533.  
  534.         saved_ifcu_buf = ifp->ifc_ifcu.ifcu_buf;
  535.         ifp->ifc_ifcu.ifcu_buf = sys_call_buf;
  536.         break;
  537.     }
  538.  
  539.     /*
  540.      * TODO: But what about fd's hidden in ioctl() args?
  541.      *       strioctl() calls, for example.
  542.      */
  543.     Rstart;
  544.     return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), (int)arg[1], &iocbuf[0]);
  545.     return_errno = errno;
  546.     Rstop;
  547.  
  548.     if (return_value0 != -1 && need_copy_out)
  549.     {
  550.         switch (arg[1])
  551.         {
  552.         case BSD43_SIOCGIFCONF:
  553.             ifp = (bsd43_ifconf *)&iocbuf[0];
  554.  
  555.             if (quiet_procmput(GLOBALdipc, (unsigned long)saved_ifcu_buf, sys_call_buf, ifp->ifc_len) == -1)
  556.                 return -1;
  557.  
  558.             ifp->ifc_ifcu.ifcu_buf = saved_ifcu_buf;
  559.             break;
  560.         }
  561.  
  562.         if (quiet_procmput(GLOBALdipc, (unsigned long)arg[2], &iocbuf[0], length) == -1)
  563.             return -1;
  564.     }
  565.  
  566.     return 0;
  567. }
  568.  
  569. /*
  570.  * Global entry point so that the sysv ioctl()
  571.  * can call the bsd43 ioctl() when it finds that
  572.  * it is really being called with bsd43 arguments
  573.  * .. yes, this is fairly gross.
  574.  */
  575. int
  576. bsd43_sys_ioctl()
  577. {
  578.     static int    ive_been_called_before;
  579.     int        result;
  580.  
  581.     if (ive_been_called_before)
  582.         result = -2;
  583.     else
  584.     {
  585.         ive_been_called_before = 1;
  586.         result = sys_ioctl(BSD43_SYS_ioctl);
  587.     }
  588.  
  589.     ive_been_called_before = 0;
  590.  
  591.     return result;
  592. }
  593.  
  594. static
  595. int
  596. sys_lstat(syscallno)
  597. int    syscallno;
  598. {
  599.     struct bsd43_stat    statb;
  600.  
  601.     return generic_lstat(syscallno, &statb, sizeof(statb));
  602. }
  603.  
  604. static
  605. int
  606. sys_mount(syscallno)
  607. int    syscallno;
  608. {
  609.     char                *typenamep;
  610.     char                typename[1024];
  611.     char                *dirnamep;
  612.     char                dirname[1024];
  613.     char                *normal_argsp;
  614.     char                normal_args[1024];
  615.     struct bsd43_nfs_args        nfsargs;
  616.     /*
  617.      * Should be:
  618.  
  619.     struct bsd43_sockaddr_in    sock;
  620.  
  621.      * but there doesn't seem to be such
  622.      * a definition in any of the include
  623.      * files I've looked through, so...
  624.      */
  625.     struct sockaddr_in        sock;
  626.     fhandle_t            fh;
  627.     char                *data;
  628.     char                shostname[HOSTNAMESZ];
  629.     char                snetname[MAXNETNAMELEN + 1];
  630.  
  631.     if (mgets(arg[0], &typenamep) == -1)
  632.         return -1;
  633.  
  634.     if (typenamep != (char *)0)
  635.     {
  636.         (void)strcpy(&typename[0], typenamep);
  637.         typenamep = &typename[0];
  638.     }
  639.  
  640.     if (mgets(arg[1], &dirnamep) == -1)
  641.         return -1;
  642.  
  643.     if (dirnamep != (char *)0)
  644.     {
  645.         (void)strcpy(&dirname[0], dirnamep);
  646.         dirnamep = &dirname[0];
  647.     }
  648.  
  649.     if
  650.     (
  651.         strcmp(&typename[0], "ffs") == 0
  652.         ||
  653.         strcmp(&typename[0], "ufs") == 0
  654.         ||
  655.         strcmp(&typename[0], "4.3") == 0
  656.     )
  657.     {
  658.         if (mgets(arg[3], &normal_argsp) == -1)
  659.             return -1;
  660.  
  661.         if (normal_argsp != (char *)0)
  662.         {
  663.             (void)strcpy(&normal_args[0], normal_argsp);
  664.             normal_argsp = &normal_args[0];
  665.         }
  666.  
  667.         data = normal_argsp;
  668.     }
  669.     else    /* "nfs" */
  670.     {
  671.         if (quiet_procmget(GLOBALdipc, (unsigned long)arg[3], &nfsargs, sizeof(nfsargs)) == -1)
  672.             return -1;
  673.  
  674.         if (quiet_procmget(GLOBALdipc, (unsigned long)nfsargs.addr, &sock, sizeof(sock)) == -1)
  675.             return -1;
  676.  
  677.         /*
  678.          * This cast is wrong but see comment
  679.          * above at start of this routine.
  680.          */
  681.         *(char **)&nfsargs.addr = (char *)&sock;
  682.  
  683.         if (quiet_procmget(GLOBALdipc, (unsigned long)nfsargs.fh, &fh, sizeof(fh)) == -1)
  684.             return -1;
  685.  
  686.         nfsargs.fh = (caddr_t)&fh;
  687.  
  688.         if (nfsargs.flags & BSD43_NFSMNT_HOSTNAME)
  689.         {
  690.             if (quiet_procmget(GLOBALdipc, (unsigned long)nfsargs.bsd43_hostname, &shostname[0], sizeof(shostname)) == -1)
  691.                 return -1;
  692.  
  693.             nfsargs.bsd43_hostname = &shostname[0];
  694.         }
  695.  
  696.         if (nfsargs.flags & BSD43_NFSMNT_SECURE)
  697.         {
  698.             if (quiet_procmget(GLOBALdipc, (unsigned long)nfsargs.netname, &snetname[0], sizeof(snetname)) == -1)
  699.                 return -1;
  700.  
  701.             nfsargs.netname = &snetname[0];
  702.         }
  703.  
  704.         data = (char *)&nfsargs;
  705.     }
  706.  
  707.     Rstart;
  708.     return_value0 = syscall(syscallno, typenamep, dirnamep, (int)arg[2], (int)data);
  709.     return_errno = errno;
  710.     Rstop;
  711.  
  712.     return 0;
  713. }
  714.  
  715. static
  716. int
  717. sys_pipe(syscallno)
  718. int    syscallno;
  719. {
  720.     /*
  721.      * TODO: do real bsd43 syscall for pipe()
  722.      */
  723.     int    fds[2];
  724.  
  725.     Rstart;
  726.     return_value0 = pipe(&fds[0]);
  727.     return_errno = errno;
  728.     Rstop;
  729.  
  730.     if (return_value0 != -1)
  731.     {
  732.         return_value0 = fd_open(fds[0]);
  733.         return_value1 = fd_open(fds[1]);
  734.     }
  735.  
  736.     return 0;
  737. }
  738.  
  739. static
  740. int
  741. sys_readv(syscallno)
  742. int    syscallno;
  743. {
  744.     struct bsd43_iovec    *saved_iov;
  745.     struct bsd43_iovec    *iov;
  746.     int            iovcnt;
  747.     int            i;
  748.  
  749.     iovcnt = arg[2];
  750.  
  751.     /*
  752.      * Copy in the scatter/gather array.
  753.      */
  754.     if ((struct bsd43_iovec *)arg[1] != (struct bsd43_iovec *)0)
  755.     {
  756.         if ((iov = (struct bsd43_iovec *)malloc(iovcnt * sizeof(*iov))) == (struct bsd43_iovec *)0)
  757.         {
  758.             vcouldnot("allocate buffer for scatter/gather vector of %d elements", iovcnt);
  759.             return -1;
  760.         }
  761.  
  762.         if (quiet_procmget(GLOBALdipc, (unsigned long)arg[1], iov, (unsigned int)iovcnt * sizeof(*iov)) == -1)
  763.             return -1;
  764.  
  765.         /*
  766.          * Save a copy of the array.
  767.          */
  768.         if ((saved_iov = (struct bsd43_iovec *)malloc(iovcnt * sizeof(*iov))) == (struct bsd43_iovec *)0)
  769.         {
  770.             vcouldnot("allocate buffer for saved scatter/gather vector of %d elements", iovcnt);
  771.             return -1;
  772.         }
  773.  
  774.         (void)memcpy(saved_iov, iov, iovcnt * sizeof(*iov));
  775.  
  776.         /*
  777.          * Copy in each entry of the array.
  778.          */
  779.         for (i = 0; i < iovcnt; i++)
  780.         {
  781.             struct bsd43_iovec    *liovp;
  782.  
  783.             liovp = &iov[i];
  784.  
  785.             if (liovp->iov_base != (caddr_t)0)
  786.             {
  787.                 caddr_t    b;
  788.  
  789.                 if ((b = (caddr_t)malloc(liovp->iov_len)) == (caddr_t)0)
  790.                 {
  791.                     vcouldnot("allocate buffer for member of scatter/gather vector of %d bytes", liovp->iov_len);
  792.                     return -1;
  793.                 }
  794.  
  795.                 if (quiet_procmget(GLOBALdipc, (unsigned long)liovp->iov_base, b, (unsigned int)liovp->iov_len) == -1)
  796.                     return -1;
  797.  
  798.                 liovp->iov_base = b;
  799.             }
  800.         }
  801.     }
  802.  
  803.     Rstart;
  804.     return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), iov, iovcnt);
  805.     return_errno = errno;
  806.     Rstop;
  807.  
  808.     /*
  809.      * Copy out fields to the user, free()'ing as we go.
  810.      */
  811.  
  812.     /*
  813.      * Copy out the scatter/gather array.
  814.      */
  815.     if ((struct bsd43_iovec *)(arg[1]) != (struct bsd43_iovec *)0)
  816.     {
  817.         /*
  818.          * Copy out each entry of the array.
  819.          */
  820.         for (i = 0; i < iovcnt; i++)
  821.         {
  822.             struct bsd43_iovec    *liovp;
  823.  
  824.             liovp = &iov[i];
  825.  
  826.             if (saved_iov[i].iov_base != (caddr_t)0)
  827.             {
  828.                 if (quiet_procmput(GLOBALdipc, (unsigned long)saved_iov[i].iov_base, liovp->iov_base, (unsigned int)liovp->iov_len) == -1)
  829.                     return -1;
  830.  
  831.                 (void)free(liovp->iov_base);
  832.             }
  833.         }
  834.  
  835.         (void)free(saved_iov);
  836.  
  837.         /*
  838.          * Copy out the reconstructed array itself?
  839.          */
  840.  
  841.         (void)free(iov);
  842.     }
  843.  
  844.     return 0;
  845. }
  846.  
  847. static
  848. int
  849. sys_recvfrom(syscallno)
  850. int    syscallno;
  851. {
  852.     struct bsd43_sockaddr    from;
  853.  
  854.     return generic_recvfrom(syscallno, &from);
  855. }
  856.  
  857. static
  858. int
  859. sys_recvmsg(syscallno)
  860. int    syscallno;
  861. {
  862.     struct bsd43_msghdr    local_msghdr;
  863.     struct bsd43_msghdr    saved_local_msghdr;
  864.     struct bsd43_iovec    *saved_msg_iov;
  865.  
  866.     if (quiet_procmget(GLOBALdipc, (unsigned long)arg[1], &local_msghdr, sizeof(local_msghdr)) == -1)
  867.         return -1;
  868.  
  869.     saved_local_msghdr = local_msghdr;
  870.  
  871.     /*
  872.      * Copy in the optional address.
  873.      */
  874.     if (local_msghdr.msg_name != (caddr_t)0)
  875.     {
  876.         caddr_t    name;
  877.  
  878.         if ((name = (caddr_t)malloc(local_msghdr.msg_namelen)) == (caddr_t)0)
  879.         {
  880.             vcouldnot("allocate buffer for msg_name of length %d bytes", local_msghdr.msg_namelen);
  881.             return -1;
  882.         }
  883.  
  884.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_name, name, (unsigned int)local_msghdr.msg_namelen) == -1)
  885.             return -1;
  886.  
  887.         local_msghdr.msg_name = name;
  888.     }
  889.  
  890.     /*
  891.      * Copy in the scatter/gather array.
  892.      */
  893.     if (local_msghdr.msg_iov != (struct bsd43_iovec *)0)
  894.     {
  895.         struct bsd43_iovec    *v;
  896.         int            i;
  897.  
  898.         if ((v = (struct bsd43_iovec *)malloc(local_msghdr.msg_iovlen * sizeof(*v))) == (struct bsd43_iovec *)0)
  899.         {
  900.             vcouldnot("allocate buffer for scatter/gather vector of %d elements", local_msghdr.msg_iovlen);
  901.             return -1;
  902.         }
  903.  
  904.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_iov, v, (unsigned int)local_msghdr.msg_iovlen * sizeof(*v)) == -1)
  905.             return -1;
  906.  
  907.         local_msghdr.msg_iov = v;
  908.  
  909.         /*
  910.          * Save a copy of the array.
  911.          */
  912.         if ((saved_msg_iov = (struct bsd43_iovec *)malloc(local_msghdr.msg_iovlen * sizeof(*v))) == (struct bsd43_iovec *)0)
  913.         {
  914.             vcouldnot("allocate buffer for saved scatter/gather vector of %d elements", local_msghdr.msg_iovlen);
  915.             return -1;
  916.         }
  917.  
  918.         (void)memcpy(saved_msg_iov, v, local_msghdr.msg_iovlen * sizeof(*v));
  919.  
  920.         /*
  921.          * Copy in each entry of the array.
  922.          */
  923.         for (i = 0; i < local_msghdr.msg_iovlen; i++)
  924.         {
  925.             struct bsd43_iovec    *liovp;
  926.  
  927.             liovp = &(local_msghdr.msg_iov[i]);
  928.  
  929.             if (liovp->iov_base != (caddr_t)0)
  930.             {
  931.                 caddr_t    b;
  932.  
  933.                 if ((b = (caddr_t)malloc(liovp->iov_len)) == (caddr_t)0)
  934.                 {
  935.                     vcouldnot("allocate buffer for member of scatter/gather vector of %d bytes", liovp->iov_len);
  936.                     return -1;
  937.                 }
  938.  
  939.                 if (quiet_procmget(GLOBALdipc, (unsigned long)liovp->iov_base, b, (unsigned int)liovp->iov_len) == -1)
  940.                     return -1;
  941.  
  942.                 liovp->iov_base = b;
  943.             }
  944.         }
  945.     }
  946.  
  947.     /*
  948.      * Copy in the optional(?) access rights.
  949.      */
  950.     if (local_msghdr.msg_accrights != (caddr_t)0)
  951.     {
  952.         caddr_t    a;
  953.  
  954.         if ((a = (caddr_t)malloc(local_msghdr.msg_accrightslen)) == (caddr_t)0)
  955.         {
  956.             vcouldnot("allocate buffer for access rights of length %d bytes", local_msghdr.msg_accrightslen);
  957.             return -1;
  958.         }
  959.  
  960.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_accrights, a, (unsigned int)local_msghdr.msg_accrightslen) == -1)
  961.             return -1;
  962.  
  963.         local_msghdr.msg_accrights = a;
  964.     }
  965.  
  966.     Rstart;
  967.     return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), &local_msghdr, (int)arg[2]);
  968.     return_errno = errno;
  969.     Rstop;
  970.  
  971.     /*
  972.      * Copy out fields to the user, free()'ing as we go.
  973.      */
  974.  
  975.     /*
  976.      * Copy out the access rights.
  977.      */
  978.     if (saved_local_msghdr.msg_accrights != (caddr_t)0)
  979.     {
  980.         if (quiet_procmput(GLOBALdipc, (unsigned long)saved_local_msghdr.msg_accrights, local_msghdr.msg_accrights, (unsigned int)local_msghdr.msg_accrightslen) == -1)
  981.             return -1;
  982.  
  983.         (void)free((char *)local_msghdr.msg_accrights);
  984.     }
  985.  
  986.     /*
  987.      * Copy out the scatter/gather array.
  988.      */
  989.     if (saved_local_msghdr.msg_iov != (struct bsd43_iovec *)0)
  990.     {
  991.         int    i;
  992.  
  993.         /*
  994.          * Copy out each entry of the array.
  995.          */
  996.         for (i = 0; i < local_msghdr.msg_iovlen; i++)
  997.         {
  998.             struct bsd43_iovec    *liovp;
  999.  
  1000.             liovp = &(local_msghdr.msg_iov[i]);
  1001.  
  1002.             if (saved_msg_iov[i].iov_base != (caddr_t)0)
  1003.             {
  1004.                 if (quiet_procmput(GLOBALdipc, (unsigned long)saved_msg_iov[i].iov_base, liovp->iov_base, (unsigned int)liovp->iov_len) == -1)
  1005.                     return -1;
  1006.                 
  1007.                 (void)free(liovp->iov_base);
  1008.             }
  1009.         }
  1010.  
  1011.         (void)free(saved_msg_iov);
  1012.  
  1013.         /*
  1014.          * Copy out the reconstructed array itself?
  1015.          */
  1016.  
  1017.         (void)free(local_msghdr.msg_iov);
  1018.     }
  1019.  
  1020.     /*
  1021.      * Copy out the received name and its length?
  1022.      */
  1023.  
  1024.     (void)free(local_msghdr.msg_name);
  1025.  
  1026.     return 0;
  1027. }
  1028.  
  1029. #define    select_dget(a,d,pp,m,nm)    \
  1030. { \
  1031.     if (a == 0) \
  1032.         pp = (struct bsd43_fd_set *)0; \
  1033.     else \
  1034.     { \
  1035.         struct bsd43_fd_set    tfds; \
  1036.         int            fd; \
  1037.  \
  1038.         if (quiet_procmget(GLOBALdipc, (unsigned long)a, &tfds, howmany(m, NFDBITS) * sizeof(bsd43_fd_mask)) == -1) \
  1039.             return -1; \
  1040.  \
  1041.         BSD43_FD_ZERO(&d); \
  1042.  \
  1043.         for (fd = 0; fd < m; fd++) \
  1044.         { \
  1045.             int    nfd; \
  1046.  \
  1047.             if \
  1048.             ( \
  1049.                 BSD43_FD_ISSET(fd, &tfds) \
  1050.                 && \
  1051.                 (nfd = fd_lookup(fd)) != -1 \
  1052.             ) \
  1053.             { \
  1054.                 BSD43_FD_SET(nfd, &d); \
  1055.                 if (nfd >= nm) \
  1056.                     nm = nfd + 1; \
  1057.             } \
  1058.         } \
  1059.  \
  1060.         pp = &d; \
  1061.     } \
  1062. }
  1063.  
  1064. #define    select_tget(a,d,p,t)    \
  1065. { \
  1066.     if (a == 0) \
  1067.         p = (t *)0; \
  1068.     else \
  1069.     { \
  1070.         if (quiet_procmget(GLOBALdipc, (unsigned long)a, &d, sizeof(d)) == -1) \
  1071.             return -1; \
  1072.  \
  1073.         p = &d; \
  1074.     } \
  1075. }
  1076.  
  1077. #define    select_dput(a,pp,nn)    \
  1078. { \
  1079.     if (a != 0) \
  1080.     { \
  1081.         struct bsd43_fd_set    tfds; \
  1082.         int            fd; \
  1083.  \
  1084.         BSD43_FD_ZERO(&tfds); \
  1085.  \
  1086.         for (fd = 0; fd < nn; fd++) \
  1087.         { \
  1088.             int    nfd; \
  1089.  \
  1090.             if \
  1091.             ( \
  1092.                 (nfd = fd_lookup(fd)) != -1 \
  1093.                 && \
  1094.                 BSD43_FD_ISSET(nfd, pp) \
  1095.             ) \
  1096.                 BSD43_FD_SET(fd, &tfds); \
  1097.         } \
  1098.  \
  1099.         if (quiet_procmput(GLOBALdipc, (unsigned long)a, &tfds, howmany(nn, BSD43_NFDBITS) * sizeof(bsd43_fd_mask)) == -1) \
  1100.             return -1; \
  1101.     } \
  1102. }
  1103.  
  1104. static
  1105. int
  1106. sys_select(syscallno)
  1107. int    syscallno;
  1108. {
  1109.     struct bsd43_fd_set    rfds;
  1110.     struct bsd43_fd_set    *rfdsp;
  1111.     struct bsd43_fd_set    wfds;
  1112.     struct bsd43_fd_set    *wfdsp;
  1113.     struct bsd43_fd_set    efds;
  1114.     struct bsd43_fd_set    *efdsp;
  1115.     struct bsd43_timeval    timeout;
  1116.     struct bsd43_timeval    *timeoutp;
  1117.     int            nfds;
  1118.     int            newnfds;
  1119.  
  1120.     nfds = (int)arg[0];
  1121.     if (nfds > fd_nfiles())
  1122.         nfds = fd_nfiles();
  1123.     newnfds = 0;
  1124.  
  1125.     select_dget(arg[1], rfds, rfdsp, nfds, newnfds);
  1126.     select_dget(arg[2], wfds, wfdsp, nfds, newnfds);
  1127.     select_dget(arg[3], efds, efdsp, nfds, newnfds);
  1128.     select_tget(arg[4], timeout, timeoutp, struct bsd43_timeval);
  1129.  
  1130.     Rstart;
  1131.     return_value0 = syscall(syscallno, newnfds, rfdsp, wfdsp, efdsp, timeoutp);
  1132.     return_errno = errno;
  1133.     Rstop;
  1134.  
  1135.     if (return_value0 != -1)
  1136.     {
  1137.         select_dput(arg[3], efdsp, nfds);
  1138.         select_dput(arg[2], wfdsp, nfds);
  1139.         select_dput(arg[1], rfdsp, nfds);
  1140.     }
  1141.  
  1142.     return 0;
  1143. }
  1144.  
  1145. static
  1146. int
  1147. sys_sendmsg(syscallno)
  1148. int    syscallno;
  1149. {
  1150.     struct bsd43_msghdr    local_msghdr;
  1151.  
  1152.     if (quiet_procmget(GLOBALdipc, (unsigned long)arg[1], &local_msghdr, sizeof(local_msghdr)) == -1)
  1153.         return -1;
  1154.  
  1155. #if    0
  1156. fprintf(outfp, "local_msghdr.msg_name = 0x%x\n", local_msghdr.msg_name);
  1157. fprintf(outfp, "local_msghdr.msg_namelen = %d\n", local_msghdr.msg_namelen);
  1158. #endif    /* 0 */
  1159.  
  1160.     /*
  1161.      * Copy in the optional address.
  1162.      */
  1163.     if (local_msghdr.msg_name != (caddr_t)0)
  1164.     {
  1165.         caddr_t    name;
  1166.  
  1167.         if ((name = (caddr_t)malloc(local_msghdr.msg_namelen)) == (caddr_t)0)
  1168.         {
  1169.             vcouldnot("allocate buffer for msg_name of length %d bytes", local_msghdr.msg_namelen);
  1170.             return -1;
  1171.         }
  1172.  
  1173.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_name, name, (unsigned int)local_msghdr.msg_namelen) == -1)
  1174.             return -1;
  1175.  
  1176.         local_msghdr.msg_name = name;
  1177.  
  1178. #if    0
  1179. {
  1180.     int    i;
  1181.  
  1182.     fprintf(outfp, "msg_name =");
  1183.     for (i = 0; i < local_msghdr.msg_namelen; i++)
  1184.         fprintf(outfp, "%02x", local_msghdr.msg_name[i] & 0xFF);
  1185.     fprintf(outfp, "\n");
  1186. }
  1187. #endif    /* 0 */
  1188.     }
  1189.  
  1190. #if    0
  1191. fprintf(outfp, "local_msghdr.msg_iov = 0x%x\n", local_msghdr.msg_iov);
  1192. fprintf(outfp, "local_msghdr.msg_iovlen = %d\n", local_msghdr.msg_iovlen);
  1193. #endif    /* 0 */
  1194.  
  1195.     /*
  1196.      * Copy in the scatter/gather array.
  1197.      */
  1198.     if (local_msghdr.msg_iov != (struct bsd43_iovec *)0)
  1199.     {
  1200.         struct bsd43_iovec    *v;
  1201.         int            i;
  1202.  
  1203.         if ((v = (struct bsd43_iovec *)malloc(local_msghdr.msg_iovlen * sizeof(*v))) == (struct bsd43_iovec *)0)
  1204.         {
  1205.             vcouldnot("allocate buffer for scatter/gather vector of %d elements", local_msghdr.msg_iovlen);
  1206.             return -1;
  1207.         }
  1208.  
  1209.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_iov, v, (unsigned int)local_msghdr.msg_iovlen * sizeof(*v)) == -1)
  1210.             return -1;
  1211.  
  1212.         local_msghdr.msg_iov = v;
  1213.  
  1214.         /*
  1215.          * Copy in each entry in the array.
  1216.          */
  1217.         for (i = 0; i < local_msghdr.msg_iovlen; i++)
  1218.         {
  1219.             struct bsd43_iovec    *liovp;
  1220.  
  1221.             liovp = &(local_msghdr.msg_iov[i]);
  1222.  
  1223. #if    0
  1224. fprintf(outfp, "local_msghdr.msg_iov[%d].iov_base = 0x%x\n", i, liovp->iov_base);
  1225. fprintf(outfp, "local_msghdr.msg_iov[%d].iov_len = %d\n", i, liovp->iov_len);
  1226. #endif    /* 0 */
  1227.  
  1228.             if (liovp->iov_base != (caddr_t)0)
  1229.             {
  1230.                 caddr_t    b;
  1231.  
  1232.                 if ((b = (caddr_t)malloc(liovp->iov_len)) == (caddr_t)0)
  1233.                 {
  1234.                     vcouldnot("allocate buffer for member of scatter/gather vector of %d bytes", liovp->iov_len);
  1235.                     return -1;
  1236.                 }
  1237.  
  1238.                 if (quiet_procmget(GLOBALdipc, (unsigned long)liovp->iov_base, b, (unsigned int)liovp->iov_len) == -1)
  1239.                     return -1;
  1240.  
  1241.                 liovp->iov_base = b;
  1242.             }
  1243.         }
  1244.     }
  1245.  
  1246. #if    0
  1247. fprintf(outfp, "local_msghdr.msg_accrights = %d\n", local_msghdr.msg_accrights);
  1248. fprintf(outfp, "local_msghdr.msg_accrightslen = %d\n", local_msghdr.msg_accrightslen);
  1249. #endif    /* 0 */
  1250.  
  1251.     /*
  1252.      * Copy in the optional(?) access rights.
  1253.      */
  1254.     if (local_msghdr.msg_accrights != (caddr_t)0)
  1255.     {
  1256.         caddr_t    a;
  1257.  
  1258.         if ((a = (caddr_t)malloc(local_msghdr.msg_accrightslen)) == (caddr_t)0)
  1259.         {
  1260.             vcouldnot("allocate buffer for access rights of length %d bytes", local_msghdr.msg_accrightslen);
  1261.             return -1;
  1262.         }
  1263.  
  1264.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_accrights, a, (unsigned int)local_msghdr.msg_accrightslen) == -1)
  1265.             return -1;
  1266.  
  1267.         local_msghdr.msg_accrights = a;
  1268.     }
  1269.  
  1270.     Rstart;
  1271.     return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), &local_msghdr, (int)arg[2]);
  1272.     return_errno = errno;
  1273.     Rstop;
  1274.  
  1275.     /*
  1276.      * Should we copy out any of these fields to the user?
  1277.      * Assuming "no" until demonstrated otherwise.
  1278.      */
  1279.  
  1280.     /*
  1281.      * Free up all the temporary space...
  1282.      */
  1283.  
  1284.     if (local_msghdr.msg_accrights != (caddr_t)0)
  1285.         (void)free((char *)local_msghdr.msg_accrights);
  1286.  
  1287.     if (local_msghdr.msg_iov != (struct bsd43_iovec *)0)
  1288.     {
  1289.         int    i;
  1290.  
  1291.         for (i = 0; i < local_msghdr.msg_iovlen; i++)
  1292.         {
  1293.             struct bsd43_iovec    *liovp;
  1294.  
  1295.             liovp = &local_msghdr.msg_iov[i];
  1296.  
  1297.             if (liovp->iov_base != (caddr_t)0)
  1298.                 (void)free((char *)liovp->iov_base);
  1299.         }
  1300.  
  1301.         (void)free((char *)local_msghdr.msg_iov);
  1302.     }
  1303.  
  1304.     if (local_msghdr.msg_name != (caddr_t)0)
  1305.         (void)free((char *)local_msghdr.msg_name);
  1306.  
  1307.     return 0;
  1308. }
  1309.  
  1310. static
  1311. int
  1312. sys_sendto(syscallno)
  1313. int    syscallno;
  1314. {
  1315.     struct bsd43_sockaddr    to;
  1316.  
  1317.     return generic_sendto(syscallno, &to);
  1318. }
  1319.  
  1320. static
  1321. int
  1322. sys_setitimer(syscallno)
  1323. int    syscallno;
  1324. {
  1325.     struct bsd43_itimerval    it;
  1326.     struct bsd43_itimerval    oit;
  1327.  
  1328.     return generic_setitimer(syscallno, &it, sizeof(it), &oit, sizeof(oit));
  1329. }
  1330.  
  1331. static
  1332. int
  1333. sys_setpgrp(syscallno)
  1334. int    syscallno;
  1335. {
  1336.     Rstart;
  1337.     return_value0 = syscall(syscallno, (int)arg[0], (int)arg[1]);
  1338.     return_errno = errno;
  1339.     Rstop;
  1340.  
  1341.     return 0;
  1342. }
  1343.  
  1344. static
  1345. int
  1346. sys_setrlimit(syscallno)
  1347. int    syscallno;
  1348. {
  1349.     return generic_setrlimit(syscallno, sizeof(struct bsd43_rlimit));
  1350. }
  1351.  
  1352. static
  1353. int
  1354. sys_settimeofday(syscallno)
  1355. int    syscallno;
  1356. {
  1357.     struct bsd43_timeval    tv;
  1358.     struct bsd43_timezone    tz;
  1359.  
  1360.     return generic_settimeofday(syscallno, &tv, sizeof(tv), &tz, sizeof(tz));
  1361. }
  1362.  
  1363. static
  1364. int
  1365. sys_sigblock(syscallno)
  1366. int    syscallno;
  1367. {
  1368.     /*
  1369.      * TODO - sys_sigblock().
  1370.      */
  1371.     Rstart;
  1372.     return_value0 = syscall(syscallno, (int)arg[0]);
  1373.     return_errno = errno;
  1374.     Rstop;
  1375.  
  1376.     return 0;
  1377. }
  1378.  
  1379. static
  1380. int
  1381. sys_sigpause(syscallno)
  1382. int    syscallno;
  1383. {
  1384.     /*
  1385.      * TODO - sys_sigpause().
  1386.      */
  1387.     Rstart;
  1388.     return_value0 = syscall(syscallno, (int)arg[0]);
  1389.     return_errno = errno;
  1390.     Rstop;
  1391.  
  1392.     return 0;
  1393. }
  1394.  
  1395. static
  1396. int
  1397. sys_sigreturn(syscallno)
  1398. int    syscallno;
  1399. {
  1400.     /*
  1401.      * TODO - sys_sigreturn().
  1402.      */
  1403.     return_value0 = -1;
  1404.     return_errno = EFAULT;
  1405.  
  1406.     return 0;
  1407. }
  1408.  
  1409. static
  1410. int
  1411. sys_sigsetmask(syscallno)
  1412. int    syscallno;
  1413. {
  1414.     /*
  1415.      * TODO - sys_sigsetmask().
  1416.      */
  1417.     Rstart;
  1418.     return_value0 = syscall(syscallno, (int)arg[0]);
  1419.     return_errno = errno;
  1420.     Rstop;
  1421.  
  1422.     return 0;
  1423. }
  1424.  
  1425. static
  1426. int
  1427. sys_sigstack(syscallno)
  1428. int    syscallno;
  1429. {
  1430.     /*
  1431.      * TODO - sys_sigstack().
  1432.      */
  1433.     return_value0 = 0;
  1434.     return_errno = errno;
  1435.  
  1436.     return 0;
  1437. }
  1438.  
  1439. static
  1440. int
  1441. sys_sigvec(syscallno)
  1442. int    syscallno;
  1443. {
  1444.     struct bsd43_sigvec    sv;
  1445.     struct bsd43_sigvec    *svp;
  1446.     struct bsd43_sigvec    osv;
  1447.     struct bsd43_sigvec    *osvp;
  1448.  
  1449.     if (mget(arg[1], &sv, sizeof(sv), &svp) == -1)
  1450.         return -1;
  1451.  
  1452.     if (mget(arg[2], &osv, sizeof(osv), &osvp) == -1)
  1453.         return -1;
  1454.  
  1455.     if
  1456.     (
  1457.         svp == (struct bsd43_sigvec *)0
  1458.         ||
  1459.         sv.sv_handler == BSD43_SIG_DFL
  1460.         ||
  1461.         sv.sv_handler == BSD43_SIG_IGN
  1462.     )
  1463.     {
  1464.         Rstart;
  1465.         return_value0 = syscall(syscallno, arg[0], svp, osvp);
  1466.         return_errno = errno;
  1467.         Rstop;
  1468.     }
  1469.     else
  1470.     {
  1471.         /*
  1472.          * TODO - rest of sys_sigvec().
  1473.          */
  1474.         return_value0 = 0;
  1475.         return_errno = errno;
  1476.     }
  1477.  
  1478.     if (mput(arg[2], osvp, sizeof(osv), return_value0) == -1)
  1479.         return -1;
  1480.  
  1481.     if (mput(arg[1], svp, sizeof(sv), return_value0) == -1)
  1482.         return -1;
  1483.  
  1484.     return 0;
  1485. }
  1486.  
  1487. static
  1488. int
  1489. sys_stat(syscallno)
  1490. int    syscallno;
  1491. {
  1492.     struct bsd43_stat    statb;
  1493.  
  1494.     return generic_stat(syscallno, &statb, sizeof(statb));
  1495. }
  1496.  
  1497. static
  1498. int
  1499. sys_statfs(syscallno)
  1500. int    syscallno;
  1501. {
  1502.     char            *cp;
  1503.     struct bsd43_statfs    buf;
  1504.     struct bsd43_statfs    *bufp;
  1505.  
  1506.     if (mgets(arg[0], &cp) == -1)
  1507.         return -1;
  1508.  
  1509.     if (mget(arg[1], &buf, sizeof(buf), &bufp) == -1)
  1510.         return -1;
  1511.  
  1512.     Rstart;
  1513.     return_value0 = syscall(syscallno, cp, bufp);
  1514.     return_errno = errno;
  1515.     Rstop;
  1516.  
  1517.     if (mput(arg[1], bufp, sizeof(buf), return_value0) == -1)
  1518.         return -1;
  1519.  
  1520.     return 0;
  1521. }
  1522.  
  1523. static
  1524. int
  1525. sys_sysmips(syscallno)
  1526. int    syscallno;
  1527. {
  1528.     struct bsd43_hw_config    *hwcp;
  1529.     struct bsd43_rusage    *rusep;
  1530.     union bsd43_wait    status;
  1531.     union bsd43_wait    *statusp;
  1532.  
  1533.     switch (arg[0])
  1534.     {
  1535.     case BSD43_MIPS_HWCONF:
  1536.         if (dmget(arg[2], sizeof(*hwcp), &hwcp) == -1)
  1537.             return -1;
  1538.  
  1539.         Rstart;
  1540.         return_value0 = syscall(syscallno, arg[0], arg[1], hwcp, arg[3]);
  1541.         return_errno = errno;
  1542.         Rstop;
  1543.  
  1544.         if (dmput(arg[2], hwcp, sizeof(*hwcp), return_value0) == -1)
  1545.             return -1;
  1546.  
  1547.         break;
  1548.  
  1549.     case BSD43_MIPS_GETRUSAGE:
  1550.         if (dmget(arg[2], arg[3], &rusep) == -1)
  1551.             return -1;
  1552.  
  1553.         Rstart;
  1554.         return_value0 = syscall(syscallno, arg[0], arg[1], rusep, arg[3]);
  1555.         return_errno = errno;
  1556.         Rstop;
  1557.  
  1558.         if (dmput(arg[2], rusep, arg[3], return_value0) == -1)
  1559.             return -1;
  1560.  
  1561.         break;
  1562.  
  1563.     case BSD43_MIPS_WAIT3:
  1564.         if (mget(arg[1], &status, sizeof(status), &statusp) == -1)
  1565.             return -1;
  1566.  
  1567.         if (dmget(arg[3], arg[4], &rusep) == -1)
  1568.             return -1;
  1569.  
  1570.         Rstart;
  1571.         return_value0 = syscall(syscallno, arg[0], statusp, arg[2], rusep, arg[4]);
  1572.         return_errno = errno;
  1573.         Rstop;
  1574.  
  1575.         if (dmput(arg[3], rusep, arg[4], return_value0) == -1)
  1576.             return -1;
  1577.  
  1578.         if (mput(arg[1], statusp, sizeof(status), return_value0) == -1)
  1579.             return -1;
  1580.  
  1581.         break;
  1582.  
  1583.     default:
  1584.         return -2;
  1585.     }
  1586.  
  1587.     return 0;
  1588. }
  1589.  
  1590. static
  1591. int
  1592. sys_utimes(syscallno)
  1593. int    syscallno;
  1594. {
  1595.     struct bsd43_timeval    tv[2];
  1596.  
  1597.     return generic_utimes(syscallno, &tv[0], sizeof(tv));
  1598. }
  1599.  
  1600. static
  1601. int
  1602. sys_vfork(syscallno)
  1603. int    syscallno;
  1604. {
  1605.     int    parent_pid;
  1606.  
  1607.     parent_pid = getpid();
  1608.  
  1609.     /*
  1610.      * Not right for vfork() but close
  1611.      * enough for now.
  1612.      * Can't be a real vfork() here
  1613.      * because the child must be allowed to
  1614.      * return from this routine (aka stack frame).
  1615.      * So this will break programs
  1616.      * that rely on (e.g.) the shared memory
  1617.      * properties of vfork()...
  1618.      *
  1619.      * TODO -- proper vfork().
  1620.      */
  1621.     errno = 0;
  1622.     Rstart;
  1623.     return_value0 = syscall(BSD43_SYS_fork);
  1624.     return_errno = errno;
  1625.     Rstop;
  1626.  
  1627.     if ((P.p_pid = getpid()) != parent_pid)
  1628.         return_value0 = 0;
  1629.  
  1630.     switch (return_value0)
  1631.     {
  1632.     case -1:    /* error */
  1633.         break;
  1634.  
  1635.     case 0:        /* child */
  1636.         return_value1 = 1;
  1637.         break;
  1638.  
  1639.     default:    /* parent */
  1640.         return_value1 = 0;
  1641.         break;
  1642.     }
  1643.  
  1644.     return 0;
  1645. }
  1646.  
  1647. static
  1648. int
  1649. sys_writev(syscallno)
  1650. int    syscallno;
  1651. {
  1652.     struct bsd43_iovec    *iov;
  1653.     int            iovcnt;
  1654.     int            i;
  1655.  
  1656.     /*
  1657.      * Copy in the scatter/gather array.
  1658.      */
  1659.     if ((struct bsd43_iovec *)arg[1] == (struct bsd43_iovec *)0)
  1660.         iov = (struct bsd43_iovec *)0;
  1661.     else
  1662.     {
  1663.         iovcnt = arg[2];
  1664.  
  1665.         if ((iov = (struct bsd43_iovec *)malloc(iovcnt * sizeof(*iov))) == (struct bsd43_iovec *)0)
  1666.         {
  1667.             vcouldnot("allocate buffer for scatter/gather vector of %d elements", iovcnt);
  1668.             return -1;
  1669.         }
  1670.  
  1671.         if (quiet_procmget(GLOBALdipc, (unsigned long)arg[1], iov, (unsigned int)iovcnt * sizeof(*iov)) == -1)
  1672.             return -1;
  1673.  
  1674.         /*
  1675.          * Copy in each entry in the array.
  1676.          */
  1677.         for (i = 0; i < iovcnt; i++)
  1678.         {
  1679.             struct bsd43_iovec    *liovp;
  1680.  
  1681.             liovp = &iov[i];
  1682.  
  1683.             if (liovp->iov_base != (caddr_t)0)
  1684.             {
  1685.                 caddr_t    b;
  1686.  
  1687.                 if ((b = (caddr_t)malloc(liovp->iov_len)) == (caddr_t)0)
  1688.                 {
  1689.                     vcouldnot("allocate buffer for member of scatter/gather vector of %d bytes", liovp->iov_len);
  1690.                     return -1;
  1691.                 }
  1692.  
  1693.                 if (quiet_procmget(GLOBALdipc, (unsigned long)liovp->iov_base, b, (unsigned int)liovp->iov_len) == -1)
  1694.                     return -1;
  1695.  
  1696.                 liovp->iov_base = b;
  1697.             }
  1698.         }
  1699.     }
  1700.  
  1701.     Rstart;
  1702.     return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), iov, iovcnt);
  1703.     return_errno = errno;
  1704.     Rstop;
  1705.  
  1706.     /*
  1707.      * Should we copy out any of these fields to the user?
  1708.      * Assuming "no" until demonstrated otherwise.
  1709.      */
  1710.  
  1711.     /*
  1712.      * Free up all the temporary space...
  1713.      */
  1714.  
  1715.     if (iov != (struct bsd43_iovec *)0)
  1716.     {
  1717.         for (i = 0; i < iovcnt; i++)
  1718.         {
  1719.             struct bsd43_iovec    *liovp;
  1720.  
  1721.             liovp = &iov[i];
  1722.  
  1723.             if (liovp->iov_base != (caddr_t)0)
  1724.                 (void)free((char *)liovp->iov_base);
  1725.         }
  1726.  
  1727.         (void)free((char *)iov);
  1728.     }
  1729.  
  1730.     return 0;
  1731. }
  1732.  
  1733. static
  1734. int
  1735. sys_wait3(syscallno)
  1736. int    syscallno;
  1737. {
  1738.     union bsd43_wait    s;
  1739.     struct bsd43_rusage    r;
  1740.  
  1741.     return generic_wait3(syscallno, &s, sizeof(s), &r, sizeof(r));
  1742. }
  1743.  
  1744. static sysentry    bsd43_systab[]    =
  1745. {
  1746.     { "syscall",    0,    "d",    'd',    (int (*)())0,    },
  1747.     { "_exit",    1,    "d",    'e',    generic_exit,    },
  1748.     { "fork",    0,    "",    'Y',    generic_fork,    },
  1749.     { "read",    3,    "dRd",    'd',    generic_read,    },
  1750.     { "write",    3,    "dWd",    'd',    generic_write,    },
  1751.     { "open",    3,    "FOm",    'd',    generic_open,    },
  1752.     { "close",    1,    "d",    'd',    generic_close,    },
  1753.     { "Owait",    0,    "",    '\0',    (int (*)())0,    },
  1754.     { "creat",    2,    "Fm",    'd',    generic_creat,     },
  1755.     { "link",    2,    "FF",    'd',    generic_link,    },
  1756.  
  1757.     { "unlink",    1,    "F",    'd',    generic_unlink,    },
  1758.     { "Oexecv",    0,    "",    '\0',    (int (*)())0,    },
  1759.     { "chdir",    1,    "F",    'd',    generic_chdir,    },
  1760.     { "Otime",    0,    "",    '\0',    (int (*)())0,    },
  1761.     { "mknod",    3,    "Fmx",    'd',    generic_mknod,    },
  1762.     { "chmod",    2,    "Fm",    'd',    generic_chmod,    },
  1763.     { "chown",    3,    "Fdd",    'd',    generic_chown,    },
  1764.     { "brk",    1,    "I",    'd',    generic_brk,    },
  1765.     { "Ostat",    0,    "",    '\0',    (int (*)())0,    },
  1766.     { "lseek",    3,    "duw",    'u',    generic_lseek,     },
  1767.  
  1768.     { "getpid",    0,    "",    'd',    generic_getpid,    },
  1769.     { "Omount",    0,    "",    '\0',    (int (*)())0,    },
  1770.     { "Oumount",    0,    "",    '\0',    (int (*)())0,    },
  1771.     { "Osetuid",    0,    "",    '\0',    (int (*)())0,    },
  1772.     { "getuid",    0,    "",    'Y',    sys_getuid,    },
  1773.     { "Ostime",    0,    "",    '\0',    (int (*)())0,    },
  1774.     { "ptrace",    4,    "ddxd",    'd',    generic_ptrace,    },
  1775.     { "Oalarm",    0,    "",    '\0',    (int (*)())0,    },
  1776.     { "Ofstat",    0,    "",    '\0',    (int (*)())0,    },
  1777.     { "Opause",    0,    "",    '\0',    (int (*)())0,    },
  1778.  
  1779.     { "Outime",    0,    "",    '\0',    (int (*)())0,    },
  1780.     { "Ostty",    0,    "",    '\0',    (int (*)())0,    },
  1781.     { "Ogtty",    0,    "",    '\0',    (int (*)())0,    },
  1782.     { "access",    2,    "FP",    'd',    generic_access,    },
  1783.     { "Onice",    0,    "",    '\0',    (int (*)())0,    },
  1784.     { "Oftime",    0,    "",    '\0',    (int (*)())0,    },
  1785.     { "sync",    0,    "",    'd',    generic_sync,    },
  1786.     { "kill",    2,    "dK",    'd',    generic_kill,    },
  1787.     { "stat",    2,    "FS",    'd',    sys_stat,    },
  1788.     { "Osetpgrp",    0,    "",    '\0',    (int (*)())0,    },
  1789.  
  1790.     { "lstat",    2,    "FS",    'd',    sys_lstat,    },
  1791.     { "dup",    1,    "d",    'd',    generic_dup,    },
  1792.     { "pipe",    0,    "",    'Y',    sys_pipe,    },
  1793.     { "Otimes",    0,    "",    '\0',    (int (*)())0,    },
  1794.     { "profil",    4,    "Iddd",    'd',    generic_profil,    },
  1795.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1796.     { "Osetgid",    0,    "",    '\0',    (int (*)())0,    },
  1797.     { "getgid",    0,    "",    'Y',    sys_getgid,    },
  1798.     { "Osigsys",    0,    "",    '\0',    (int (*)())0,    },
  1799.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1800.  
  1801.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1802.     { "acct",    1,    "F",    'd',    generic_acct,    },
  1803.     { "Ophys",    0,    "",    '\0',    (int (*)())0,    },
  1804.     { "Osyslock",    0,    "",    '\0',    (int (*)())0,    },
  1805.     { "ioctl",    3,    "dCA",    'd',    sys_ioctl,    },
  1806.     { "reboot",    0,    "",    '\0',    (int (*)())0,    },
  1807.     { "Ompxchan",    0,    "",    '\0',    (int (*)())0,    },
  1808.     { "symlink",    2,    "FF",    'd',    generic_symlink,    },
  1809.     { "readlink",    3,    "FRd",    'd',    generic_readlink,    },
  1810.     { "execve",    3,    "FlE",    'e',    sys_execve,    },
  1811.  
  1812.     { "umask",    1,    "x",    'x',    generic_umask,    },
  1813.     { "chroot",    1,    "F",    'd',    generic_chroot,    },
  1814.     { "fstat",    2,    "dS",    'd',    sys_fstat,    },
  1815.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1816.     { "getpagesize", 0,    "",    'd',    generic_getpagesize, },
  1817.     { "mremap",    0,    "",    '\0',    (int (*)())0,    },
  1818.     { "vfork",    0,    "",    'Y',    sys_vfork,    },
  1819.     { "Ovread",    0,    "",    '\0',    (int (*)())0,    },
  1820.     { "Ovwrite",    0,    "",    '\0',    (int (*)())0,    },
  1821.     { "sbrk",    0,    "",    '\0',    (int (*)())0,    },
  1822.  
  1823.     { "sstk",    0,    "",    '\0',    (int (*)())0,    },
  1824.     { "mmap",    0,    "",    '\0',    (int (*)())0,    },
  1825.     { "Ovadvise",    0,    "",    '\0',    (int (*)())0,    },
  1826.     { "munmap",    0,    "",    '\0',    (int (*)())0,    },
  1827.     { "mprotec",    0,    "",    '\0',    (int (*)())0,    },
  1828.     { "madvise",    0,    "",    '\0',    (int (*)())0,    },
  1829.     { "vhangup",    0,    "",    'd',    generic_vhangup,    },
  1830.     { "Ovlimit",    0,    "",    '\0',    (int (*)())0,    },
  1831.     { "mincore",    0,    "",    '\0',    (int (*)())0,    },
  1832.     { "getgroups",    2,    "dG",    'd',    sys_getgroups,    },
  1833.  
  1834.     { "setgroups",    2,    "dg",    'd',    generic_setgroups,    },
  1835.     { "getpgrp",    1,    "d",    'd',    sys_getpgrp,    },
  1836.     { "setpgrp",    2,    "dd",    'd',    sys_setpgrp,    },
  1837.     { "setitimer",    3,    "dVV",    'd',    sys_setitimer,    },
  1838.     { "wait3",    3,    "xxx",    'd',    sys_wait3,    },
  1839.     { "swapon",    0,    "",    '\0',    (int (*)())0,    },
  1840.     { "getitimer",    2,    "dV",    'd',    sys_getitimer,    },
  1841.     { "gethostname", 2,    "xd",    'd',    generic_gethostname, },
  1842.     { "sethostname", 0,    "",    '\0',    (int (*)())0,    },
  1843.     { "getdtablesize", 0,    "",    'd',    generic_getdtablesize, },
  1844.  
  1845.     { "dup2",    2,    "dd",    'd',    sys_dup2,    },
  1846.     { "getdopt",    0,    "",    '\0',    (int (*)())0,    },
  1847.     { "fcntl",    3,    "dBH",    'd',    sys_fcntl,    },
  1848.     { "select",    5,    "dDDDT", 'd',    sys_select,    },
  1849.     { "setdopt",    0,    "",    '\0',    (int (*)())0,    },
  1850.     { "fsync",    1,    "d",    'd',    generic_fsync,    },
  1851.     { "setpriority", 3,    "ddd",    'd',    generic_setpriority, },
  1852.     { "socket",    3,    "abc",    'd',    generic_socket,    },
  1853.     { "connect",    3,    "dLd",    'd',    generic_connect,    },
  1854.     { "accept",    3,    "dLU",    'd',    generic_accept,    },
  1855.  
  1856.     { "getpriority", 2,    "dd",    'd',    generic_getpriority, },
  1857.     { "send",    4,    "dWdN",    'd',    generic_send,    },
  1858.     { "recv",    4,    "dRdN",    'd',    generic_recv,    },
  1859.     { "sigreturn",    1,    "I",    'd',    sys_sigreturn,    },
  1860.     { "bind",    3,    "dLd",    'd',    generic_bind,    },
  1861.     { "setsockopt", 5,    "dddpd", 'd',    generic_setsockopt, },
  1862.     { "listen",    2,    "dd",    'd',    generic_listen,    },
  1863.     { "Ovtimes",    0,    "",    '\0',    (int (*)())0,    },
  1864.     { "sigvec",    3,    "Kff",    'd',    sys_sigvec,    },
  1865.     { "sigblock",    1,    "M",    'M',    sys_sigblock,    },
  1866.  
  1867.     { "sigsetmask", 1,    "M",    'M',    sys_sigsetmask, },
  1868.     { "sigpause",    1,    "K",    'd',    sys_sigpause,    },
  1869.     { "sigstack",    2,    "II",    'd',    sys_sigstack,    },
  1870.     { "recvmsg",    3,    "dpN",    'd',    sys_recvmsg,    },
  1871.     { "sendmsg",    3,    "dpN",    'd',    sys_sendmsg,    },
  1872.     { "Ovtrace",    0,    "",    '\0',    (int (*)())0,    },
  1873.     { "gettimeofday", 2,    "TZ",    'd',    sys_gettimeofday, },
  1874.     { "getrusage",    2,    "dx",    'd',    sys_getrusage,    },
  1875.     { "getsockopt", 5,    "dddxU", 'd',    generic_getsockopt,    },
  1876.     { "Oresuba",    0,    "",    '\0',    (int (*)())0,    },
  1877.  
  1878.     { "readv",    3,    "dpd",    'd',    sys_readv,    },
  1879.     { "writev",    3,    "dpd",    'd',    sys_writev,    },
  1880.     { "settimeofday", 2,    "TZ",    'd',    sys_settimeofday, },
  1881.     { "fchown",    3,    "ddd",    'd',    generic_fchown,    },
  1882.     { "fchmod",    2,    "dm",    'd',    generic_fchmod,    },
  1883.     { "recvfrom",    6,    "dRdNLU", 'd',    sys_recvfrom,    },
  1884.     { "setreuid",    2,    "dd",    'd',    generic_setreuid,    },
  1885.     { "setregid",    2,    "dd",    'd',    generic_setregid,    },
  1886.     { "rename",    2,    "FF",    'd',    generic_rename,    },
  1887.     { "truncate",    2,    "Fu",    'd',    generic_truncate,    },
  1888.  
  1889.     { "ftruncate",    2,    "du",    'd',    generic_ftruncate,    },
  1890.     { "flock",    2,    "dd",    'd',    generic_flock,    },
  1891.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1892.     { "sendto",    6,    "dWdNLd", 'd',    sys_sendto,    },
  1893.     { "shutdown",    2,    "dd",    'd',    generic_shutdown,    },
  1894.     { "socketpair", 4,    "abcQ",    'd',    generic_socketpair,    },
  1895.     { "mkdir",    2,    "Fm",    'd',    generic_mkdir,    },
  1896.     { "rmdir",    1,    "F",    'd',    generic_rmdir,    },
  1897.     { "utimes",    2,    "FV",    'd',    sys_utimes,    },
  1898.     { "sigcleanup", 0,    "",    '\0',    (int (*)())0,    },
  1899.  
  1900.     { "adjtime",    2,    "TT",    'd',    sys_adjtime,    },
  1901.     { "getpeername", 3,    "dLU",    'd',    generic_getpeername, },
  1902.     { "gethostid",    0,    "",    'u',    generic_gethostid,    },
  1903.     { "sethostid",    1,    "u",    'd',    generic_sethostid,    },
  1904.     { "getrlimit",    2,    "dx",    'd',    sys_getrlimit,    },
  1905.     { "setrlimit",    2,    "dx",    'd',    sys_setrlimit,    },
  1906.     { "killpg",    2,    "dK",    'd',    generic_killpg,    },
  1907.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1908.     { "Osetquota",    0,    "",    '\0',    (int (*)())0,    },
  1909.     { "Oquota",    0,    "",    '\0',    (int (*)())0,    },
  1910.  
  1911.     { "getsockname", 3,    "dLU",    'd',    generic_getsockname, },
  1912.     { "sysmips",    4,    "dxxx",    'd',    sys_sysmips,    },
  1913.     { "cacheflush", 3,    "Idd",    'd',    generic_cacheflush,    },
  1914.     { "cachectl",    3,    "Idd",    'd',    generic_cachectl,    },
  1915.     { "debug",    0,    "",    '\0',    (int (*)())0,    },
  1916.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1917.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1918.     { "Onfs_mount",    0,    "",    '\0',    (int (*)())0,    },
  1919.     { "nfssvc",    1,    "d",    'd',    generic_nfssvc,    },
  1920.     { "getdirentries", 4,    "dRdU",    'd',    generic_getdirentries, },
  1921.  
  1922.     { "statfs",    2,    "FX",    'd',    sys_statfs,    },
  1923.     { "fstatfs",    2,    "dX",    'd',    sys_fstatfs,    },
  1924.     { "unmount",    1,    "F",    'd',    generic_unmount,    },
  1925.     { "async_daemon", 0,    "",    'd',    generic_async_daemon, },
  1926.     { "getfh",    0,    "",    '\0',    (int (*)())0,    },
  1927.     { "getdomainname", 2,    "xd",    'd',    generic_getdomainname, },
  1928.     { "setdomainname", 2,    "xd",    'd',    generic_setdomainname, },
  1929.     { "Opcfs_mount", 0,    "",    '\0',    (int (*)())0,    },
  1930.     { "quotactl",    0,    "",    '\0',    (int (*)())0,    },
  1931.     { "old_exportfs", 0,    "",    '\0',    (int (*)())0,    },
  1932.  
  1933.     { "mount",    4,    "FFxp",    'd',    sys_mount,    },
  1934.     { "hdwconf",    0,    "",    '\0',    (int (*)())0,    },
  1935.     { "exportfs",    2,    "Fp",    'd',    sys_exportfs,    },
  1936.     { "nfsfh_open", 0,    "",    '\0',    (int (*)())0,    },
  1937.     { "libattach",    0,    "",    '\0',    (int (*)())0,    },
  1938.     { "libdetach",    0,    "",    '\0',    (int (*)())0,    },
  1939. };
  1940.  
  1941. sysentry    *
  1942. bsd43_systab_entry(n)
  1943. int    n;
  1944. {
  1945.     if (n >= 0 && n < nels(bsd43_systab))
  1946.         return &bsd43_systab[n];
  1947.  
  1948.     return (sysentry *)0;
  1949. }
  1950.  
  1951. int
  1952. bsd43_print_open_flags(arg)
  1953. long    arg;
  1954. {
  1955.     need_leading_pipe = 0;
  1956.  
  1957.     if ((arg & (BSD43_O_WRONLY | BSD43_O_RDWR)) == 0)
  1958.     {
  1959.         say_flag(BSD43_O_RDONLY, "O_RDONLY", arg);
  1960.     }
  1961.     else
  1962.     {
  1963.         say_flag(BSD43_O_WRONLY, "O_WRONLY", arg);
  1964.         say_flag(BSD43_O_RDWR, "O_RDWR", arg);
  1965.     }
  1966.  
  1967.     say_flag(BSD43_O_APPEND, "O_APPEND", arg);
  1968.     say_flag(BSD43_O_CREAT, "O_CREAT", arg);
  1969.     say_flag(BSD43_O_EXCL, "O_EXCL", arg);
  1970.     say_flag(BSD43_O_NDELAY, "O_NDELAY", arg);
  1971.     say_flag(BSD43_O_TRUNC, "O_TRUNC", arg);
  1972.  
  1973.     say_residual(arg);
  1974.  
  1975.     return 0;
  1976. }
  1977.  
  1978. int
  1979. bsd43_print_stat(arg)
  1980. long    arg;
  1981. {
  1982.     struct bsd43_stat    statbuf;
  1983.  
  1984.     if (quiet_procmget(GLOBALdipc, (unsigned long)arg, (char *)&statbuf, sizeof(statbuf)) == -1)
  1985.         return -1;
  1986.  
  1987.     fprintf(outfp, "{" /* } */ );
  1988.     fprintf(outfp, "st_dev=0x%x,", statbuf.st_dev);
  1989.     fprintf(outfp, " st_ino=%d,", statbuf.st_ino);
  1990.     fprintf(outfp, " st_mode=0x%x,", statbuf.st_mode);
  1991.     fprintf(outfp, " st_nlink=%d,", statbuf.st_nlink);
  1992.     fprintf(outfp, " st_uid=%d,", statbuf.st_uid);
  1993.     fprintf(outfp, " st_gid=%d,", statbuf.st_gid);
  1994.     fprintf(outfp, " st_rdev=0x%x,", statbuf.st_rdev);
  1995.     fprintf(outfp, " st_size=%d,", statbuf.st_size);
  1996.     fprintf(outfp, " st_atime=");
  1997.     say_time(outfp, statbuf.st_atime);
  1998.     fprintf(outfp, ",");
  1999.     fprintf(outfp, " st_mtime=");
  2000.     say_time(outfp, statbuf.st_mtime);
  2001.     fprintf(outfp, ",");
  2002.     fprintf(outfp, " st_ctime=");
  2003.     say_time(outfp, statbuf.st_ctime);
  2004.     fprintf(outfp, ",");
  2005.     fprintf(outfp, " st_blksize=%d,", statbuf.st_blksize);
  2006.     fprintf(outfp, " st_blocks=%d,", statbuf.st_blocks);
  2007.     fprintf(outfp, /* { */ "}");
  2008.  
  2009.     return 0;
  2010. }
  2011.  
  2012. int
  2013. bsd43_print_ioctl_cmd(cmd)
  2014. unsigned long    cmd;
  2015. {
  2016.     switch (cmd)
  2017.     {
  2018.     case BSD43_TIOCGETP:
  2019.         fprintf(outfp, "TIOCGETP");
  2020.         break;
  2021.  
  2022.     case BSD43_TIOCSETP:
  2023.         fprintf(outfp, "TIOCSETP");
  2024.         break;
  2025.  
  2026.     case BSD43_TIOCSETN:
  2027.         fprintf(outfp, "TIOCSETN");
  2028.         break;
  2029.  
  2030.     case BSD43_TIOCGWINSZ:
  2031.         fprintf(outfp, "TIOCGWINSZ");
  2032.         break;
  2033.  
  2034.     case BSD43_TIOCLGET:
  2035.         fprintf(outfp, "TIOCLGET");
  2036.         break;
  2037.  
  2038.     case BSD43_TIOCLSET:
  2039.         fprintf(outfp, "TIOCLSET");
  2040.         break;
  2041.  
  2042.     case BSD43_TIOCGETC:
  2043.         fprintf(outfp, "TIOCGETC");
  2044.         break;
  2045.  
  2046.     case BSD43_TIOCSETC:
  2047.         fprintf(outfp, "TIOCSETC");
  2048.         break;
  2049.  
  2050.     case BSD43_TIOCGLTC:
  2051.         fprintf(outfp, "TIOCGLTC");
  2052.         break;
  2053.  
  2054.     case BSD43_TIOCSLTC:
  2055.         fprintf(outfp, "TIOCSLTC");
  2056.         break;
  2057.  
  2058.     case BSD43_FIONBIO:
  2059.         fprintf(outfp, "FIONBIO");
  2060.         break;
  2061.  
  2062.     case BSD43_TIOCGPGRP:
  2063.         fprintf(outfp, "TIOCGPGRP");
  2064.         break;
  2065.  
  2066.     default:
  2067.         fprintf(outfp, "0x%x", cmd);
  2068.         break;
  2069.     }
  2070.  
  2071.     return 0;
  2072. }
  2073.  
  2074. static
  2075. int
  2076. say_sgttyb(arg)
  2077. unsigned long    arg;
  2078. {
  2079.     struct bsd43_sgttyb    sgb;
  2080.  
  2081.     if (quiet_procmget(GLOBALdipc, arg, (char *)&sgb, sizeof(sgb)) == -1)
  2082.         return -1;
  2083.  
  2084.     fprintf
  2085.     (
  2086.         outfp,
  2087.         "{sg_ispeed=%d, sg_ospeed=%d, sg_erase=0x%02x, sg_kill=0x%02x, sg_flags=",
  2088.         sgb.sg_ispeed & 0xFF,
  2089.         sgb.sg_ospeed & 0xFF,
  2090.         sgb.sg_erase & 0xFF,
  2091.         sgb.sg_kill & 0xFF
  2092.     );
  2093.  
  2094.     need_leading_pipe = 0;
  2095.  
  2096.     say_notflag(BSD43_BSDELAY, "BS0", sgb.sg_flags);
  2097.     say_flag(BSD43_BS1, "BS1", sgb.sg_flags);
  2098.     say_notflag(BSD43_VTDELAY, "FF0", sgb.sg_flags);
  2099.     say_flag(BSD43_FF1, "FF1", sgb.sg_flags);
  2100.     say_notflag(BSD43_CRDELAY, "CR0", sgb.sg_flags);
  2101.     say_flag(BSD43_CR3, "CR3", sgb.sg_flags);
  2102.     say_flag(BSD43_CR2, "CR2", sgb.sg_flags);
  2103.     say_flag(BSD43_CR1, "CR1", sgb.sg_flags);
  2104.     say_notflag(BSD43_TBDELAY, "TAB0", sgb.sg_flags);
  2105.     say_flag(BSD43_XTABS, "XTABS", sgb.sg_flags);
  2106.     say_flag(BSD43_TAB2, "TAB2", sgb.sg_flags);
  2107.     say_flag(BSD43_TAB1, "TAB1", sgb.sg_flags);
  2108.     say_notflag(BSD43_NLDELAY, "NL0", sgb.sg_flags);
  2109.     say_flag(BSD43_NL3, "NL3", sgb.sg_flags);
  2110.     say_flag(BSD43_NL2, "NL2", sgb.sg_flags);
  2111.     say_flag(BSD43_NL1, "NL1", sgb.sg_flags);
  2112.  
  2113.     say_flag(BSD43_EVENP, "EVENP", sgb.sg_flags);
  2114.     say_flag(BSD43_ODDP, "ODDP", sgb.sg_flags);
  2115.     say_flag(BSD43_RAW, "RAW", sgb.sg_flags);
  2116.     say_flag(BSD43_CRMOD, "CRMOD", sgb.sg_flags);
  2117.     say_flag(BSD43_ECHO, "ECHO", sgb.sg_flags);
  2118.     say_flag(BSD43_LCASE, "LCASE", sgb.sg_flags);
  2119.     say_flag(BSD43_CBREAK, "CBREAK", sgb.sg_flags);
  2120.     say_flag(BSD43_TANDEM, "TANDEM", sgb.sg_flags);
  2121.  
  2122.     fprintf(outfp, "}");
  2123.  
  2124.     return 0;
  2125. }
  2126.  
  2127. static
  2128. int
  2129. say_lmword(arg)
  2130. unsigned long    arg;
  2131. {
  2132.     int    local_mode_word;
  2133.  
  2134.     if (quiet_procmget(GLOBALdipc, arg, (char *)&local_mode_word, sizeof(local_mode_word)) == -1)
  2135.         return -1;
  2136.  
  2137.     need_leading_pipe = 0;
  2138.  
  2139.     say_flag(BSD43_LCRTBS, "LCRTBS", local_mode_word);
  2140.     say_flag(BSD43_LPRTERA, "LPRTERA", local_mode_word);
  2141.     say_flag(BSD43_LCRTERA, "LCRTERA", local_mode_word);
  2142.     say_flag(BSD43_LTILDE, "LTILDE", local_mode_word);
  2143.     say_flag(BSD43_LMDMBUF, "LMDMBUF", local_mode_word);
  2144.     say_flag(BSD43_LLITOUT, "LLITOUT", local_mode_word);
  2145.     say_flag(BSD43_LTOSTOP, "LTOSTOP", local_mode_word);
  2146.     say_flag(BSD43_LFLUSHO, "LFLUSHO", local_mode_word);
  2147.     say_flag(BSD43_LNOHANG, "LNOHANG", local_mode_word);
  2148. #ifndef    BSD43_LETXACK
  2149. #ifndef    BSD43_ETXACK
  2150. #define    BSD43_ETXACK    (BSD43_L001000 >> 16)
  2151. #endif    /* BSD43_ETXACK */
  2152. #define    BSD43_LETXACK    (BSD43_ETXACK >> 16)
  2153. #endif    /* BSD43_LETXACK */
  2154.     say_flag(BSD43_LETXACK, "LETXACK", local_mode_word);
  2155.     say_flag(BSD43_LCRTKIL, "LCRTKIL", local_mode_word);
  2156.     say_flag(BSD43_LPASS8, "LPASS8", local_mode_word);
  2157.     say_flag(BSD43_LCTLECH, "LCTLECH", local_mode_word);
  2158.     say_flag(BSD43_LPENDIN, "LPENDIN", local_mode_word);
  2159.     say_flag(BSD43_LDECCTQ, "LDECCTQ", local_mode_word);
  2160.     say_flag(BSD43_LNOFLSH, "LNOFLSH", local_mode_word);
  2161.  
  2162.     say_residual(local_mode_word);
  2163.  
  2164.     return 0;
  2165. }
  2166.  
  2167. static
  2168. int
  2169. say_ltc(arg)
  2170. unsigned long    arg;
  2171. {
  2172.     struct bsd43_tchars    tcs;
  2173.  
  2174.     if (quiet_procmget(GLOBALdipc, arg, (char *)&tcs, sizeof(tcs)) == -1)
  2175.         return -1;
  2176.  
  2177.     fprintf(outfp, "{");
  2178.     fprintf(outfp, "t_intrc=0x%02x, ", tcs.t_intrc);
  2179.     fprintf(outfp, "t_quitc=0x%02x, ", tcs.t_quitc);
  2180.     fprintf(outfp, "t_startc=0x%02x, ", tcs.t_startc);
  2181.     fprintf(outfp, "t_stopc=0x%02x, ", tcs.t_stopc);
  2182.     fprintf(outfp, "t_eofc=0x%02x, ", tcs.t_eofc);
  2183.     fprintf(outfp, "t_brkc=0x%02x, ", tcs.t_brkc);
  2184.     fprintf(outfp, "}");
  2185.  
  2186.     return 0;
  2187. }
  2188.  
  2189. static
  2190. int
  2191. say_sltc(arg)
  2192. unsigned long    arg;
  2193. {
  2194.     struct bsd43_ltchars    ltcs;
  2195.  
  2196.     if (quiet_procmget(GLOBALdipc, arg, (char *)<cs, sizeof(ltcs)) == -1)
  2197.         return -1;
  2198.  
  2199.     fprintf(outfp, "{");
  2200.     fprintf(outfp, "t_suspc=0x%02x, ", ltcs.t_suspc);
  2201.     fprintf(outfp, "t_dsuspc=0x%02x, ", ltcs.t_dsuspc);
  2202.     fprintf(outfp, "t_rprntc=0x%02x, ", ltcs.t_rprntc);
  2203.     fprintf(outfp, "t_flushc=0x%02x, ", ltcs.t_flushc);
  2204.     fprintf(outfp, "t_werasc=0x%02x, ", ltcs.t_werasc);
  2205.     fprintf(outfp, "t_lnextc=0x%02x, ", ltcs.t_lnextc);
  2206.     fprintf(outfp, "}");
  2207.  
  2208.     return 0;
  2209. }
  2210.  
  2211. static
  2212. int
  2213. say_int(arg)
  2214. unsigned long    arg;
  2215. {
  2216.     int    i;
  2217.  
  2218.     if (quiet_procmget(GLOBALdipc, arg, (char *)&i, sizeof(i)) == -1)
  2219.         return -1;
  2220.  
  2221.     fprintf(outfp, "{");
  2222.     fprintf(outfp, "i=%d", i);
  2223.     fprintf(outfp, "}");
  2224.  
  2225.     return 0;
  2226. }
  2227.  
  2228. static
  2229. int
  2230. say_winsize(arg)
  2231. unsigned long    arg;
  2232. {
  2233.     struct bsd43_winsize    w;
  2234.  
  2235.     if (quiet_procmget(GLOBALdipc, arg, (char *)&w, sizeof(w)) == -1)
  2236.         return -1;
  2237.  
  2238.     fprintf(outfp, "{");
  2239.     fprintf(outfp, "row=%d,", w.ws_row);
  2240.     fprintf(outfp, "col=%d,", w.ws_col);
  2241.     fprintf(outfp, "xpixel=%d,", w.ws_xpixel);
  2242.     fprintf(outfp, "ypixel=%d,", w.ws_ypixel);
  2243.     fprintf(outfp, "}");
  2244.  
  2245.     return 0;
  2246. }
  2247.  
  2248. int
  2249. bsd43_print_ioctl_arg(args)
  2250. unsigned long    *args;
  2251. {
  2252.     switch (args[1])
  2253.     {
  2254.     case BSD43_TIOCGETP:
  2255.     case BSD43_TIOCSETN:
  2256.     case BSD43_TIOCSETP:
  2257.         if (say_sgttyb(args[2]) == -1)
  2258.             return -1;
  2259.         break;
  2260.  
  2261.     case BSD43_TIOCLGET:
  2262.     case BSD43_TIOCLSET:
  2263.         if (say_lmword(args[2]) == -1)
  2264.             return -1;
  2265.         break;
  2266.  
  2267.     case BSD43_TIOCGETC:
  2268.     case BSD43_TIOCSETC:
  2269.         if (say_ltc(args[2]) == -1)
  2270.             return -1;
  2271.         break;
  2272.  
  2273.     case BSD43_TIOCGLTC:
  2274.     case BSD43_TIOCSLTC:
  2275.         if (say_sltc(args[2]) == -1)
  2276.             return -1;
  2277.         break;
  2278.  
  2279.     case BSD43_FIONBIO:
  2280.     case BSD43_TIOCGPGRP:
  2281.         if (say_int(args[2]) == -1)
  2282.             return -1;
  2283.         break;
  2284.  
  2285.     case BSD43_TIOCGWINSZ:
  2286.         if (say_winsize(args[2]) == -1)
  2287.             return -1;
  2288.         break;
  2289.  
  2290.     default:
  2291.         fprintf(outfp, "0x%x", args[2]);
  2292.         break;
  2293.     }
  2294.  
  2295.     return 0;
  2296. }
  2297.  
  2298. int
  2299. bsd43_print_fdset(nfds, arg)
  2300. int        nfds;
  2301. unsigned long    arg;
  2302. {
  2303.     if (arg == (unsigned long)0)
  2304.         fprintf(outfp, "0x%x", arg);
  2305.     else
  2306.     {
  2307.         struct bsd43_fd_set    tfds;
  2308.         int            fd;
  2309.  
  2310.         if (quiet_procmget(GLOBALdipc, arg, &tfds, sizeof(tfds)) == -1)
  2311.             return -1;
  2312.  
  2313.         fprintf(outfp, "{");
  2314.  
  2315.         for (fd = 0; fd < nfds; fd++)
  2316.         {
  2317.             if (BSD43_FD_ISSET(fd, &tfds))
  2318.                 fprintf(outfp, "%d,", fd);
  2319.         }
  2320.  
  2321.         fprintf(outfp, "}");
  2322.     }
  2323.  
  2324.     return 0;
  2325. }
  2326.  
  2327. int
  2328. bsd43_print_whence(arg)
  2329. unsigned long    arg;
  2330. {
  2331.     switch (arg)
  2332.     {
  2333.     case BSD43_L_SET:
  2334.         fprintf(outfp, "L_SET");
  2335.         break;
  2336.  
  2337.     case BSD43_L_INCR:
  2338.         fprintf(outfp, "L_INCR");
  2339.         break;
  2340.  
  2341.     case BSD43_L_XTND:
  2342.         fprintf(outfp, "L_XTND");
  2343.         break;
  2344.  
  2345.     default:
  2346.         fprintf(outfp, "0x%x", arg);
  2347.         break;
  2348.     }
  2349.  
  2350.     return 0;
  2351. }
  2352.  
  2353. int
  2354. bsd43_print_statfs(arg)
  2355. unsigned long    arg;
  2356. {
  2357.     if (arg == (unsigned long)0)
  2358.         fprintf(outfp, "0x%x", arg);
  2359.     else
  2360.     {
  2361.         struct bsd43_statfs    t;
  2362.  
  2363.         if (quiet_procmget(GLOBALdipc, arg, &t, sizeof(t)) == -1)
  2364.             return -1;
  2365.  
  2366.         fprintf(outfp, "{");
  2367.         fprintf(outfp, "type=%d,", t.f_type);
  2368.         fprintf(outfp, "bsize=%d,", t.f_bsize);
  2369.         fprintf(outfp, "blocks=%d,", t.f_blocks);
  2370.         fprintf(outfp, "bfree=%d,", t.f_bfree);
  2371.         fprintf(outfp, "bavail=%d,", t.f_bavail);
  2372.         fprintf(outfp, "files=%d,", t.f_files);
  2373.         fprintf(outfp, "ffree=%d,", t.f_ffree);
  2374.         fprintf(outfp, "fsid.val[0]=%d,", t.f_fsid.val[0]);
  2375.         fprintf(outfp, "fsid.val[1]=%d,", t.f_fsid.val[1]);
  2376.         fprintf(outfp, "}");
  2377.     }
  2378.     return 0;
  2379. }
  2380.  
  2381. int
  2382. bsd43_print_sigvec(arg)
  2383. unsigned long    arg;
  2384. {
  2385.     if (arg == (unsigned long)0)
  2386.         fprintf(outfp, "0x%x", arg);
  2387.     else
  2388.     {
  2389.         struct bsd43_sigvec    t;
  2390.  
  2391.         if (quiet_procmget(GLOBALdipc, arg, &t, sizeof(t)) == -1)
  2392.             return -1;
  2393.  
  2394.         fprintf(outfp, "{");
  2395.  
  2396.         fprintf(outfp, "handler=");
  2397.         switch ((int)t.sv_handler)
  2398.         {
  2399.         case BSD43_BADSIG:
  2400.             fprintf(outfp, "BADSIG");
  2401.             break;
  2402.  
  2403.         case BSD43_SIG_DFL:
  2404.             fprintf(outfp, "SIG_DFL");
  2405.             break;
  2406.  
  2407.         case BSD43_SIG_IGN:
  2408.             fprintf(outfp, "SIG_IGN");
  2409.             break;
  2410.  
  2411.         default:
  2412.             fprintf(outfp, "%s", proc_text_address(t.sv_handler));
  2413.             break;
  2414.         }
  2415.         fprintf(outfp, ",");
  2416.  
  2417.         fprintf(outfp, "mask=%s,", signal_set(t.sv_mask));
  2418.         fprintf(outfp, "flags={");
  2419.         need_leading_pipe = 0;
  2420.         say_flag(BSD43_SV_ONSTACK, "SV_ONSTACK", t.sv_flags);
  2421.         say_flag(BSD43_SV_INTERRUPT, "SV_INTERRUPT", t.sv_flags);
  2422.         say_residual(t.sv_flags);
  2423.         fprintf(outfp, "}");
  2424.         fprintf(outfp, "}");
  2425.     }
  2426.     return 0;
  2427. }
  2428.  
  2429. void
  2430. bsd43_print_sigcontext(outfp, p)
  2431. FILE        *outfp;
  2432. unsigned long    p;
  2433. {
  2434.     fprintf(outfp, "0x%x");
  2435. }
  2436.