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

  1. #include        <sys/param.h>
  2. #include        <sys/types.h>
  3. #include        <sys/statfs.h>
  4. #include        <sys/stat.h>
  5. #include        <sys/times.h>
  6. #include        <sys/dirent.h>
  7. #include        <sys/swap.h>
  8. #include        <sys/utsname.h>
  9. #include        <sys/termio.h>
  10. #include        <sys/stermio.h>
  11. #include        <sys/stropts.h>
  12. #include        <sys/flio.h>
  13. #include        <sys/mtio.h>
  14. #include        <sys/fs/prfcntl.h>
  15. #include        <sys/ptrace.h>
  16. #include        <sys/immu.h>
  17. #include        <sys/sbd.h>
  18. #include        <sys/region.h>
  19. #undef    PC
  20. #if    defined(LIMITS)
  21. #include        <sys/lnode.h>
  22. #define    LIMITSoffset    (320 + SYSVoffset)
  23. #endif    /* defined(LIMITS) */
  24. #if    defined(SHARE)
  25. #include        <sys/share.h>
  26. #define    SHAREoffset    (323 + SYSVoffset)
  27. #endif    /* defined(SHARE) */
  28. #include        <sys/proc.h>
  29. #include        <sys/fstyp.h>
  30. #include        <sys/fsid.h>
  31. #define    INKERNEL    1
  32. #include        <signal.h>
  33. #undef    INKERNEL
  34. #include        <poll.h>
  35. #include        <errno.h>
  36. #include        <fcntl.h>
  37. #include        <ustat.h>
  38. #include        <sys.s>
  39. #if    !defined(SYS_setlim)
  40. #define    SYS_setlim    (0 + LIMITSoffset)
  41. #define    SYS_getlim    (1 + LIMITSoffset)
  42. #define    SYS_limonoff    (2 + LIMITSoffset)
  43. #endif    /* !defined(SYS_setlim) */
  44. #if    !defined(SYS_sharecosts)
  45. #define    SYS_sharecosts    (0 + SHAREoffset)
  46. #define    SYS_gettab    (1 + SHAREoffset)
  47. #endif    /* !defined(SYS_sharecosts) */
  48. #include        <stdio.h>
  49. #include        <unistd.h>
  50. #include        <bsd/sys/types.h>
  51. #include        <bsd/sys/socket.h>
  52. #include        <bsd/sys/uio.h>
  53. #include        <bsd/sys/wait.h>
  54. #include        <bsd/sys/time.h>
  55. #include        <bsd/sys/resource.h>
  56. #include        "register.h"
  57. #include        "symtab.h"
  58. #include        "diblock.h"
  59. #include        "instrn.h"
  60. #include        "process.h"
  61. #include        "sysentry.h"
  62. #include        "nels.h"
  63. #include        "res.h"
  64. #include        "flag.h"
  65. #include        "generic.h"
  66.  
  67. extern time_t        time();
  68.  
  69. extern int        fd_lookup();
  70. extern int        fd_open();
  71. extern void        fd_dopen();
  72. extern int        fd_close();
  73. extern int        fd_invalid();
  74. extern int        fd_nfiles();
  75. extern int        fd_sort();
  76. extern void        histo_dump();
  77. extern void        hist_dump();
  78. extern char        *malloc();
  79. extern char        *strdup();
  80. extern int        bufset();
  81. extern int        mstrlen();
  82. extern int        mgetstring();
  83. extern int        mgets();
  84. extern char        **mgetvp();
  85. extern int        magic_ok();
  86. extern int        interpreter_ok();
  87. extern int        is_a_shared_library();
  88. extern int        augment_execve_args();
  89. extern void        vis_quoted_truncated_buffer();
  90. extern void        say_time();
  91. extern char        *signal_name();
  92. extern int        printval();
  93. extern int        bsd43_sys_ioctl();
  94. extern int        sgttybsize();
  95.  
  96. extern FILE        *outfp;
  97. extern int        errno;
  98.  
  99. extern int        Aflag;
  100. extern int        Fflag;
  101. extern int        Pflag;
  102. extern int        Sflag;
  103.  
  104. extern unsigned long    arg[];
  105.  
  106. extern int        return_errno;    /* errno goes here. */
  107. extern long        return_value0;    /* Result 1 value goes here. */
  108. extern long        return_value1;    /* Result 2 value goes here. */
  109.  
  110. extern sysentry        *current_sysentp;
  111. extern char        *sys_call_buf;    /* Scratch buf. */
  112.  
  113. static int        sysv_print_received_signal();
  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.             access(filename, 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_fcntl(syscallno)
  223. int    syscallno;
  224. {
  225.     int    size;
  226.     void    *fargp;
  227.  
  228.     switch ((int)arg[1])
  229.     {
  230.     case F_DUPFD:
  231.         Rstart;
  232.         return_value0 = dup(fd_lookup((int)arg[0]));
  233.         return_errno = errno;
  234.         Rstop;
  235.  
  236.         if (return_value0 != -1)
  237.         {
  238.             int    newfd;
  239.             int    nfiles;
  240.  
  241.             for (nfiles = fd_nfiles(), newfd = (int)arg[2]; newfd < nfiles && fd_lookup(newfd) != -1; newfd++)
  242.                 ;
  243.  
  244.             if (newfd >= nfiles)
  245.             {
  246.                 (void)close(return_value0);
  247.                 errno = EMFILE;
  248.                 return 0;
  249.             }
  250.  
  251.             fd_dopen(return_value0, newfd);
  252.  
  253.             return_value0 = newfd;
  254.         }
  255.         return 0;
  256.  
  257.     case F_GETFD:
  258.     case F_SETFD:
  259.     case F_GETFL:
  260.     case F_SETFL:
  261.     case F_SETOWN:
  262.     case PFCSEXEC:
  263.     case PFCREXEC:
  264.     case PFCRUN:
  265.     case PFCSSTEP:
  266.     case PFCCSIG:
  267.         size = -1;
  268.         break;
  269.  
  270.     case PFCWSTOP:
  271.     case PFCGMASK:
  272.     case PFCSMASK:
  273.     case PFCSTOP:
  274.         size = sizeof(unsigned long);
  275.         break;
  276.  
  277.     case PFCGETPR:
  278.         size = sizeof(proc_t);
  279.         break;
  280.  
  281.     case PFCGETUSEG:
  282.         size = sizeof(struct pfcseg);
  283.         break;
  284.  
  285.     case PFCGETREGS:
  286.         size = sizeof(unsigned long) * NPTRC_REGS;
  287.         break;
  288.  
  289.     case F_SETLK:
  290.     case F_SETLKW:
  291.         size = sizeof(struct flock);
  292.         break;
  293.  
  294.     default:
  295.         return -2;
  296.     }
  297.  
  298.     if (size != -1)
  299.     {
  300.         if (bufset(size) == -1)
  301.             return -1;
  302.  
  303.         if (mget(arg[2], sys_call_buf, size, &fargp) == -1)
  304.             return -1;
  305.     }
  306.  
  307.     Rstart;
  308.     return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), (int)arg[1], (size == -1) ? (int)arg[2] : (int)fargp);
  309.     return_errno = errno;
  310.     Rstop;
  311.  
  312.     if (size != -1)
  313.     {
  314.         if (mput(arg[2], fargp, size, return_value0) == -1)
  315.             return -1;
  316.     }
  317.  
  318.     return 0;
  319. }
  320.  
  321. static
  322. int
  323. sys_fstat(syscallno)
  324. int    syscallno;
  325. {
  326.     return generic_fstat(syscallno, sizeof(struct stat));
  327. }
  328.  
  329. static
  330. int
  331. sys_fstatfs(syscallno)
  332. int    syscallno;
  333. {
  334.     int        len;
  335.     struct statfs    *bufp;
  336.  
  337.     len = arg[2];
  338.  
  339.     if (dmget(arg[1], len, &bufp) == -1)
  340.         return -1;
  341.  
  342.     Rstart;
  343.     return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), bufp, len, (int)arg[3]);
  344.     return_errno = errno;
  345.     Rstop;
  346.  
  347.     if (dmput(arg[1], bufp, len, return_value0) == -1)
  348.         return -1;
  349.  
  350.     return 0;
  351. }
  352.  
  353. static
  354. int
  355. sys_getgid(syscallno)
  356. int    syscallno;
  357. {
  358.     Rstart;
  359.     return_value0 = getgid();
  360.     return_value1 = getegid();
  361.     return_errno = errno;
  362.     Rstop;
  363.  
  364.     return 0;
  365. }
  366.  
  367. static
  368. int
  369. sys_getgroups(syscallno)
  370. int    syscallno;
  371. {
  372.     return generic_getgroups(syscallno, NGROUPS);
  373. }
  374.  
  375. static
  376. int
  377. sys_getitimer(syscallno)
  378. int    syscallno;
  379. {
  380.     return generic_getitimer(syscallno, sizeof(struct itimerval));
  381. }
  382.  
  383. #if    defined(LIMITS)
  384. static
  385. int
  386. sys_getlim(syscallno)
  387. int    syscallno;
  388. {
  389.     int    function;
  390.     lnode    *address;
  391.     int    size;
  392.     int    realsize;
  393.  
  394.     function = arg[0];
  395.     size = arg[2];
  396.  
  397.     switch (function)
  398.     {
  399.     case L_GETUID:
  400.         realsize = sizeof(lnode);
  401.         break;
  402.  
  403.     default:
  404.         realsize = size;
  405.         break;
  406.     }
  407.  
  408.     if (dmget(arg[1], realsize, &address) == -1)
  409.         return -1;
  410.  
  411.     Rstart;
  412.     return_value0 = syscall(syscallno, function, address, size);
  413.     return_errno = errno;
  414.     Rstop;
  415.  
  416.     if (dmput(arg[1], address, realsize, return_value0) == -1)
  417.         return -1;
  418.  
  419.     return 0;
  420. }
  421. #endif    /* defined(LIMITS) */
  422.  
  423. static
  424. int
  425. sys_getrlimit(syscallno)
  426. int    syscallno;
  427. {
  428.     return generic_getrlimit(syscallno, sizeof(struct rlimit));
  429. }
  430.  
  431. static
  432. int
  433. sys_getrusage(syscallno)
  434. int    syscallno;
  435. {
  436.     return generic_getrusage(syscallno, sizeof(struct rusage));
  437. }
  438.  
  439. static
  440. int
  441. sys_gettimeofday(syscallno)
  442. int    syscallno;
  443. {
  444.     struct timeval    tv;
  445.     struct timezone    tz;
  446.  
  447.     return generic_gettimeofday(syscallno, &tv, sizeof(tv), &tz, sizeof(tz));
  448. }
  449.  
  450. static
  451. int
  452. sys_getuid(syscallno)
  453. int    syscallno;
  454. {
  455.     Rstart;
  456.     return_value0 = getuid();
  457.     return_value1 = geteuid();
  458.     return_errno = errno;
  459.     Rstop;
  460.  
  461.     return 0;
  462. }
  463.  
  464. static
  465. int
  466. sys_ioctl(syscallno)
  467. int    syscallno;
  468. {
  469.     int    length;
  470.     int    need_copy_in;
  471.     int    need_copy_out;
  472.     int    arg2_is_arg;
  473.  
  474.     arg2_is_arg = 0;
  475.  
  476.     if ((arg[1] & (unsigned long)(IOC_INOUT | IOC_VOID)) == 0)
  477.     {
  478.         /*
  479.          * Old style.
  480.          */
  481.  
  482.         length = 0;
  483.         need_copy_in = 0;
  484.         need_copy_out = 0;
  485.  
  486.         switch ((int)arg[1])
  487.         {
  488.         case FIONREAD:
  489.             length = sizeof(int);
  490.             need_copy_out = 1;
  491.             break;
  492.  
  493.         case FLIOC_SENSE_DRIVE:
  494.             break;
  495.  
  496.         case I_POP:
  497.             break;
  498.  
  499.         case I_PUSH:
  500.             length = mstrlen(arg[2]) + 1;
  501.             need_copy_in = 1;
  502.             break;
  503.  
  504.         case I_SRDOPT:
  505.             length = sizeof(arg[2]);
  506.             arg2_is_arg = 1;
  507.             break;
  508.  
  509.         case STGET:
  510.             length = sizeof(struct stio);
  511.             need_copy_out = 1;
  512.             break;
  513.  
  514.         case oTCGETA:
  515.         case TCGETA:
  516.             length = sizeof(struct termio);
  517.             need_copy_out = 1;
  518.             break;
  519.  
  520.         case oTIOCGETP:
  521.             length = sgttybsize();
  522.             need_copy_out = 1;
  523.             break;
  524.  
  525.         case oTIOCSETP:
  526.             length = sgttybsize();
  527.             need_copy_in = 1;
  528.             break;
  529.  
  530.         case oTCSETA:
  531.         case TCSETA:
  532.         case oTCSETAF:
  533.         case TCSETAF:
  534.         case oTCSETAW:
  535.         case TCSETAW:
  536.             length = sizeof(struct termio);
  537.             need_copy_in = 1;
  538.             break;
  539.  
  540.         case TCFLSH:
  541.         case TCSBRK:
  542.         case TCXONC:
  543.             length = sizeof(arg[2]);
  544.             arg2_is_arg = 1;
  545.             break;
  546.  
  547.         case oFIOCLEX:
  548.         case oFIONCLEX:
  549.             break;
  550.  
  551.         case oTIOCEXCL:
  552.         case TIOCEXCL:
  553.             break;
  554.  
  555.         case TIOCGPGRP:
  556.             length = sizeof(int);
  557.             need_copy_out = 1;
  558.             break;
  559.  
  560.         case TIOCGWINSZ:
  561.             length = sizeof(struct winsize);
  562.             need_copy_out = 1;
  563.             break;
  564.  
  565.         case MTIOCGET:
  566.             /*
  567.         case oTIOCHPCL:
  568.              * Somebody has stuffed up here...
  569.              * The MTIOCGET returns a struct,
  570.              * the oTIOCHPCL doesn't but
  571.              * they've got the same ioctl encoding.
  572.              * So we try to guess based on the
  573.              * pointer arg...
  574.              */
  575.             if (arg[2] != (unsigned long)0)
  576.             {
  577.                 length = sizeof(struct mtget);
  578.                 need_copy_out = 1;
  579.             }
  580.             break;
  581.  
  582.         case MTIOCTOP:
  583.             length = sizeof(struct mtop);
  584.             need_copy_in = 1;
  585.             break;
  586.  
  587.         case oTIOCNOTTY:
  588.         case TIOCNOTTY:
  589.             break;
  590.  
  591.         case oTIOCNXCL:
  592.         case TIOCNXCL:
  593.             break;
  594.  
  595.         case TIOCOUTQ:
  596.             length = sizeof(int);
  597.             need_copy_out = 1;
  598.             break;
  599.  
  600.         case TIOCSPGRP:
  601.             length = sizeof(int);
  602.             need_copy_in = 1;
  603.             break;
  604.  
  605.         case oTIOCSTI:
  606.         case TIOCSTI:
  607.             length = sizeof(char);
  608.             need_copy_in = 1;
  609.             break;
  610.  
  611.         case TIOCSWINSZ:
  612.             length = sizeof(struct winsize);
  613.             need_copy_in = 1;
  614.             break;
  615.  
  616.         case LDSETT:
  617.             length = sizeof(struct termcb);
  618.             need_copy_in = 1;
  619.             break;
  620.  
  621.         default:
  622.             return -2;
  623.         }
  624.     }
  625.     else
  626.     {
  627.         /*
  628.          * New style.
  629.          */
  630.  
  631.         need_copy_in = arg[1] & (unsigned long)IOC_IN;
  632.         need_copy_out = arg[1] & (unsigned long)IOC_OUT;
  633.         length = (arg[1] >> (unsigned long)16) & (unsigned long)IOCPARM_MASK;
  634.     }
  635.  
  636.     if (length > 0)
  637.     {
  638.         if (bufset((unsigned int)length) == -1)
  639.             return -1;
  640.  
  641.         if (need_copy_in)
  642.         {
  643.             if (quiet_procmget(GLOBALdipc, (unsigned long)arg[2], sys_call_buf, length) == -1)
  644.                 return -1;
  645.         }
  646.     }
  647.  
  648.     /*
  649.      * TODO: But what about fd's hidden in ioctl() args?
  650.      *       strioctl() calls, for example.
  651.      */
  652.     Rstart;
  653.     return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), (int)arg[1], arg2_is_arg ? (int)arg[2] : (int)sys_call_buf);
  654.     return_errno = errno;
  655.     Rstop;
  656.  
  657.     if
  658.     (
  659.         need_copy_out
  660.         &&
  661.         return_value0 != -1
  662.         &&
  663.         quiet_procmput(GLOBALdipc, (unsigned long)arg[2], sys_call_buf, length) == -1
  664.     )
  665.         return -1;
  666.  
  667.     return 0;
  668. }
  669.  
  670. /*
  671.  * Global entry point so that the bsd43 ioctl()
  672.  * can call the sysv ioctl() when it finds that
  673.  * it is really being called with sysv arguments
  674.  * .. yes, this is fairly gross.
  675.  */
  676. int
  677. sysv_sys_ioctl()
  678. {
  679.     static int    ive_been_called_before;
  680.     int        result;
  681.  
  682.     if (ive_been_called_before)
  683.         result = -2;
  684.     else
  685.     {
  686.         ive_been_called_before = 1;
  687.         result = sys_ioctl(SYS_ioctl);
  688.     }
  689.  
  690.     ive_been_called_before = 0;
  691.  
  692.     return result;
  693. }
  694.  
  695. static
  696. int
  697. sys_lstat(syscallno)
  698. int    syscallno;
  699. {
  700.     struct stat    statb;
  701.  
  702.     return generic_lstat(syscallno, &statb, sizeof(statb));
  703. }
  704.  
  705. static
  706. int
  707. sys_ofcntl(syscallno)
  708. int    syscallno;
  709. {
  710.     switch ((int)arg[1])
  711.     {
  712.     case F_GETFL:
  713.     case F_SETFL:
  714.         Rstart;
  715.         return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), (int)arg[1], (int)arg[2]);
  716.         return_errno = errno;
  717.         Rstop;
  718.         break;
  719.  
  720.     default:
  721.         return sys_fcntl(SYS_fcntl);
  722.     }
  723.  
  724.     return 0;
  725. }
  726.  
  727. static
  728. int
  729. sys_pipe(syscallno)
  730. int    syscallno;
  731. {
  732.     int    fds[2];
  733.  
  734.     Rstart;
  735.     return_value0 = pipe(&fds[0]);
  736.     return_errno = errno;
  737.     Rstop;
  738.  
  739.     if (return_value0 != -1)
  740.     {
  741.         return_value0 = fd_open(fds[0]);
  742.         return_value1 = fd_open(fds[1]);
  743.     }
  744.  
  745.     return 0;
  746. }
  747.  
  748. static
  749. int
  750. sys_poll(syscallno)
  751. int    syscallno;
  752. {
  753.     unsigned long    nfds;
  754.     int        timeout;
  755.     int        size;
  756.     struct pollfd    *fds;
  757.     int        fd;
  758.     int        *saved_fds;
  759.  
  760.     nfds = arg[1];
  761.     timeout = arg[2];
  762.  
  763.     size = nfds * sizeof(fds[0]);
  764.  
  765.     if (bufset(size) == -1)
  766.         return -1;
  767.  
  768.     if (mget(arg[0], sys_call_buf, size, &fds) == -1)
  769.         return -1;
  770.  
  771.     if (fds != (struct pollfd *)0)
  772.     {
  773.         if ((saved_fds = (int *)malloc(nfds * sizeof(int))) == (int *)0)
  774.         {
  775.             vcouldnot("allocate space for %d poll fds", nfds);
  776.             return -1;
  777.         }
  778.  
  779.         for (fd = 0; fd < nfds; fd++)
  780.         {
  781.             saved_fds[fd] = fds[fd].fd;
  782.             fds[fd].fd = fd_lookup(fds[fd].fd);
  783.         }
  784.     }
  785.  
  786.     Rstart;
  787.     return_value0 = syscall(syscallno, fds, nfds, timeout);
  788.     return_errno = errno;
  789.     Rstop;
  790.  
  791.     if (fds != (struct pollfd *)0)
  792.     {
  793.         for (fd = 0; fd < nfds; fd++)
  794.             fds[fd].fd = saved_fds[fd];
  795.  
  796.         (void)free(saved_fds);
  797.     }
  798.  
  799.     if (mput(arg[0], fds, size, return_value0) == -1)
  800.         return -1;
  801.  
  802.     return 0;
  803. }
  804.  
  805. static
  806. int
  807. sys_recvfrom(syscallno)
  808. int    syscallno;
  809. {
  810.     struct sockaddr    from;
  811.  
  812.     return generic_recvfrom(syscallno, &from);
  813. }
  814.  
  815. static
  816. int
  817. sys_recvmsg(syscallno)
  818. int    syscallno;
  819. {
  820.     struct msghdr    local_msghdr;
  821.     struct msghdr    saved_local_msghdr;
  822.     struct iovec    *saved_msg_iov;
  823.  
  824.     if (quiet_procmget(GLOBALdipc, (unsigned long)arg[1], &local_msghdr, sizeof(local_msghdr)) == -1)
  825.         return -1;
  826.  
  827.     saved_local_msghdr = local_msghdr;
  828.  
  829.     /*
  830.      * Copy in the optional address.
  831.      */
  832.     if (local_msghdr.msg_name != (caddr_t)0)
  833.     {
  834.         caddr_t    name;
  835.  
  836.         if ((name = (caddr_t)malloc(local_msghdr.msg_namelen)) == (caddr_t)0)
  837.         {
  838.             vcouldnot("allocate buffer for msg_name of length %d bytes", local_msghdr.msg_namelen);
  839.             return -1;
  840.         }
  841.  
  842.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_name, name, (unsigned int)local_msghdr.msg_namelen) == -1)
  843.             return -1;
  844.  
  845.         local_msghdr.msg_name = name;
  846.     }
  847.  
  848.     /*
  849.      * Copy in the scatter/gather array.
  850.      */
  851.     if (local_msghdr.msg_iov != (struct iovec *)0)
  852.     {
  853.         struct iovec    *v;
  854.         int        i;
  855.  
  856.         if ((v = (struct iovec *)malloc(local_msghdr.msg_iovlen * sizeof(*v))) == (struct iovec *)0)
  857.         {
  858.             vcouldnot("allocate buffer for scatter/gather vector of %d elements", local_msghdr.msg_iovlen);
  859.             return -1;
  860.         }
  861.  
  862.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_iov, v, (unsigned int)local_msghdr.msg_iovlen * sizeof(*v)) == -1)
  863.             return -1;
  864.  
  865.         local_msghdr.msg_iov = v;
  866.  
  867.         /*
  868.          * Save a copy of the array.
  869.          */
  870.         if ((saved_msg_iov = (struct iovec *)malloc(local_msghdr.msg_iovlen * sizeof(*v))) == (struct iovec *)0)
  871.         {
  872.             vcouldnot("allocate buffer for saved scatter/gather vector of %d elements", local_msghdr.msg_iovlen);
  873.             return -1;
  874.         }
  875.  
  876.         (void)memcpy(saved_msg_iov, v, local_msghdr.msg_iovlen * sizeof(*v));
  877.  
  878.         /*
  879.          * Copy in each entry of the array.
  880.          */
  881.         for (i = 0; i < local_msghdr.msg_iovlen; i++)
  882.         {
  883.             struct iovec    *liovp;
  884.  
  885.             liovp = &(local_msghdr.msg_iov[i]);
  886.  
  887.             if (liovp->iov_base != (caddr_t)0)
  888.             {
  889.                 caddr_t    b;
  890.  
  891.                 if ((b = (caddr_t)malloc(liovp->iov_len)) == (caddr_t)0)
  892.                 {
  893.                     vcouldnot("allocate buffer for member of scatter/gather vector of %d bytes", liovp->iov_len);
  894.                     return -1;
  895.                 }
  896.  
  897.                 if (quiet_procmget(GLOBALdipc, (unsigned long)liovp->iov_base, b, (unsigned int)liovp->iov_len) == -1)
  898.                     return -1;
  899.  
  900.                 liovp->iov_base = b;
  901.             }
  902.         }
  903.     }
  904.  
  905.     /*
  906.      * Copy in the optional(?) access rights.
  907.      */
  908.     if (local_msghdr.msg_accrights != (caddr_t)0)
  909.     {
  910.         caddr_t    a;
  911.  
  912.         if ((a = (caddr_t)malloc(local_msghdr.msg_accrightslen)) == (caddr_t)0)
  913.         {
  914.             vcouldnot("allocate buffer for access rights of length %d bytes", local_msghdr.msg_accrightslen);
  915.             return -1;
  916.         }
  917.  
  918.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_accrights, a, (unsigned int)local_msghdr.msg_accrightslen) == -1)
  919.             return -1;
  920.  
  921.         local_msghdr.msg_accrights = a;
  922.     }
  923.  
  924.     Rstart;
  925.     return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), &local_msghdr, (int)arg[2]);
  926.     return_errno = errno;
  927.     Rstop;
  928.  
  929.     /*
  930.      * Copy out fields to the user, free()'ing as we go.
  931.      */
  932.  
  933.     /*
  934.      * Copy out the access rights.
  935.      */
  936.     if (saved_local_msghdr.msg_accrights != (caddr_t)0)
  937.     {
  938.         if (quiet_procmput(GLOBALdipc, (unsigned long)saved_local_msghdr.msg_accrights, local_msghdr.msg_accrights, (unsigned int)local_msghdr.msg_accrightslen) == -1)
  939.             return -1;
  940.  
  941.         (void)free((char *)local_msghdr.msg_accrights);
  942.     }
  943.  
  944.     /*
  945.      * Copy out the scatter/gather array.
  946.      */
  947.     if (saved_local_msghdr.msg_iov != (struct iovec *)0)
  948.     {
  949.         int    i;
  950.  
  951.         /*
  952.          * Copy out each entry of the array.
  953.          */
  954.         for (i = 0; i < local_msghdr.msg_iovlen; i++)
  955.         {
  956.             struct iovec    *liovp;
  957.  
  958.             liovp = &(local_msghdr.msg_iov[i]);
  959.  
  960.             if (saved_msg_iov[i].iov_base != (caddr_t)0)
  961.             {
  962.                 if (quiet_procmput(GLOBALdipc, (unsigned long)saved_msg_iov[i].iov_base, liovp->iov_base, (unsigned int)liovp->iov_len) == -1)
  963.                     return -1;
  964.                 
  965.                 (void)free(liovp->iov_base);
  966.             }
  967.         }
  968.  
  969.         (void)free(saved_msg_iov);
  970.  
  971.         /*
  972.          * Copy out the reconstructed array itself?
  973.          */
  974.  
  975.         (void)free(local_msghdr.msg_iov);
  976.     }
  977.  
  978.     /*
  979.      * Copy out the received name and its length?
  980.      */
  981.  
  982.     (void)free(local_msghdr.msg_name);
  983.  
  984.     return 0;
  985. }
  986.  
  987. #define    select_dget(a,d,pp,m,nm)    \
  988. { \
  989.     if (a == 0) \
  990.         pp = (struct fd_set *)0; \
  991.     else \
  992.     { \
  993.         struct fd_set    tfds; \
  994.         int        fd; \
  995.  \
  996.         if (quiet_procmget(GLOBALdipc, (unsigned long)a, &tfds, howmany(m, NFDBITS) * sizeof(fd_mask)) == -1) \
  997.             return -1; \
  998.  \
  999.         FD_ZERO(&d); \
  1000.  \
  1001.         for (fd = 0; fd < m; fd++) \
  1002.         { \
  1003.             int    nfd; \
  1004.  \
  1005.             if \
  1006.             ( \
  1007.                 FD_ISSET(fd, &tfds) \
  1008.                 && \
  1009.                 (nfd = fd_lookup(fd)) != -1 \
  1010.             ) \
  1011.             { \
  1012.                 FD_SET(nfd, &d); \
  1013.                 if (nfd >= nm) \
  1014.                     nm = nfd + 1; \
  1015.             } \
  1016.         } \
  1017.  \
  1018.         pp = &d; \
  1019.     } \
  1020. }
  1021.  
  1022. #define    select_tget(a,d,p,t)    \
  1023. { \
  1024.     if (a == 0) \
  1025.         p = (t *)0; \
  1026.     else \
  1027.     { \
  1028.         if (quiet_procmget(GLOBALdipc, (unsigned long)a, &d, sizeof(d)) == -1) \
  1029.             return -1; \
  1030.  \
  1031.         p = &d; \
  1032.     } \
  1033. }
  1034.  
  1035. #define    select_dput(a,pp,nn)    \
  1036. { \
  1037.     if (a != 0) \
  1038.     { \
  1039.         struct fd_set    tfds; \
  1040.         int        fd; \
  1041.  \
  1042.         FD_ZERO(&tfds); \
  1043.  \
  1044.         for (fd = 0; fd < nn; fd++) \
  1045.         { \
  1046.             int    nfd; \
  1047.  \
  1048.             if \
  1049.             ( \
  1050.                 (nfd = fd_lookup(fd)) != -1 \
  1051.                 && \
  1052.                 FD_ISSET(nfd, pp) \
  1053.             ) \
  1054.                 FD_SET(fd, &tfds); \
  1055.         } \
  1056.  \
  1057.         if (quiet_procmput(GLOBALdipc, (unsigned long)a, &tfds, howmany(nn, NFDBITS) * sizeof(fd_mask)) == -1) \
  1058.             return -1; \
  1059.     } \
  1060. }
  1061.  
  1062. static
  1063. int
  1064. sys_select(syscallno)
  1065. int    syscallno;
  1066. {
  1067.     struct fd_set    rfds;
  1068.     struct fd_set    *rfdsp;
  1069.     struct fd_set    wfds;
  1070.     struct fd_set    *wfdsp;
  1071.     struct fd_set    efds;
  1072.     struct fd_set    *efdsp;
  1073.     struct timeval    timeout;
  1074.     struct timeval    *timeoutp;
  1075.     int        nfds;
  1076.     int        newnfds;
  1077.  
  1078.     nfds = (int)arg[0];
  1079.     if (nfds > fd_nfiles())
  1080.         nfds = fd_nfiles();
  1081.     newnfds = 0;
  1082.  
  1083.     select_dget(arg[1], rfds, rfdsp, nfds, newnfds);
  1084.     select_dget(arg[2], wfds, wfdsp, nfds, newnfds);
  1085.     select_dget(arg[3], efds, efdsp, nfds, newnfds);
  1086.     select_tget(arg[4], timeout, timeoutp, struct timeval);
  1087.  
  1088.     Rstart;
  1089.     return_value0 = syscall(syscallno, newnfds, rfdsp, wfdsp, efdsp, timeoutp);
  1090.     return_errno = errno;
  1091.     Rstop;
  1092.  
  1093.     if (return_value0 != -1)
  1094.     {
  1095.         select_dput(arg[3], efdsp, nfds);
  1096.         select_dput(arg[2], wfdsp, nfds);
  1097.         select_dput(arg[1], rfdsp, nfds);
  1098.     }
  1099.  
  1100.     return 0;
  1101. }
  1102.  
  1103. static
  1104. int
  1105. sys_sendmsg(syscallno)
  1106. int    syscallno;
  1107. {
  1108.     struct msghdr    local_msghdr;
  1109.  
  1110.     if (quiet_procmget(GLOBALdipc, (unsigned long)arg[1], &local_msghdr, sizeof(local_msghdr)) == -1)
  1111.         return -1;
  1112.  
  1113. #if    0
  1114. fprintf(outfp, "local_msghdr.msg_name = 0x%x\n", local_msghdr.msg_name);
  1115. fprintf(outfp, "local_msghdr.msg_namelen = %d\n", local_msghdr.msg_namelen);
  1116. #endif    /* 0 */
  1117.  
  1118.     /*
  1119.      * Copy in the optional address.
  1120.      */
  1121.     if (local_msghdr.msg_name != (caddr_t)0)
  1122.     {
  1123.         caddr_t    name;
  1124.  
  1125.         if ((name = (caddr_t)malloc(local_msghdr.msg_namelen)) == (caddr_t)0)
  1126.         {
  1127.             vcouldnot("allocate buffer for msg_name of length %d bytes", local_msghdr.msg_namelen);
  1128.             return -1;
  1129.         }
  1130.  
  1131.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_name, name, (unsigned int)local_msghdr.msg_namelen) == -1)
  1132.             return -1;
  1133.  
  1134.         local_msghdr.msg_name = name;
  1135.  
  1136. #if    0
  1137. {
  1138.     int    i;
  1139.  
  1140.     fprintf(outfp, "msg_name =");
  1141.     for (i = 0; i < local_msghdr.msg_namelen; i++)
  1142.         fprintf(outfp, "%02x", local_msghdr.msg_name[i] & 0xFF);
  1143.     fprintf(outfp, "\n");
  1144. }
  1145. #endif    /* 0 */
  1146.     }
  1147.  
  1148. #if    0
  1149. fprintf(outfp, "local_msghdr.msg_iov = 0x%x\n", local_msghdr.msg_iov);
  1150. fprintf(outfp, "local_msghdr.msg_iovlen = %d\n", local_msghdr.msg_iovlen);
  1151. #endif    /* 0 */
  1152.  
  1153.     /*
  1154.      * Copy in the scatter/gather array.
  1155.      */
  1156.     if (local_msghdr.msg_iov != (struct iovec *)0)
  1157.     {
  1158.         struct iovec    *v;
  1159.         int        i;
  1160.  
  1161.         if ((v = (struct iovec *)malloc(local_msghdr.msg_iovlen * sizeof(*v))) == (struct iovec *)0)
  1162.         {
  1163.             vcouldnot("allocate buffer for scatter/gather vector of %d elements", local_msghdr.msg_iovlen);
  1164.             return -1;
  1165.         }
  1166.  
  1167.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_iov, v, (unsigned int)local_msghdr.msg_iovlen * sizeof(*v)) == -1)
  1168.             return -1;
  1169.  
  1170.         local_msghdr.msg_iov = v;
  1171.  
  1172.         /*
  1173.          * Copy in each entry in the array.
  1174.          */
  1175.         for (i = 0; i < local_msghdr.msg_iovlen; i++)
  1176.         {
  1177.             struct iovec    *liovp;
  1178.  
  1179.             liovp = &(local_msghdr.msg_iov[i]);
  1180.  
  1181. #if    0
  1182. fprintf(outfp, "local_msghdr.msg_iov[%d].iov_base = 0x%x\n", i, liovp->iov_base);
  1183. fprintf(outfp, "local_msghdr.msg_iov[%d].iov_len = %d\n", i, liovp->iov_len);
  1184. #endif    /* 0 */
  1185.  
  1186.             if (liovp->iov_base != (caddr_t)0)
  1187.             {
  1188.                 caddr_t    b;
  1189.  
  1190.                 if ((b = (caddr_t)malloc(liovp->iov_len)) == (caddr_t)0)
  1191.                 {
  1192.                     vcouldnot("allocate buffer for member of scatter/gather vector of %d bytes", liovp->iov_len);
  1193.                     return -1;
  1194.                 }
  1195.  
  1196.                 if (quiet_procmget(GLOBALdipc, (unsigned long)liovp->iov_base, b, (unsigned int)liovp->iov_len) == -1)
  1197.                     return -1;
  1198.  
  1199.                 liovp->iov_base = b;
  1200.             }
  1201.         }
  1202.     }
  1203.  
  1204. #if    0
  1205. fprintf(outfp, "local_msghdr.msg_accrights = %d\n", local_msghdr.msg_accrights);
  1206. fprintf(outfp, "local_msghdr.msg_accrightslen = %d\n", local_msghdr.msg_accrightslen);
  1207. #endif    /* 0 */
  1208.  
  1209.     /*
  1210.      * Copy in the optional(?) access rights.
  1211.      */
  1212.     if (local_msghdr.msg_accrights != (caddr_t)0)
  1213.     {
  1214.         caddr_t    a;
  1215.  
  1216.         if ((a = (caddr_t)malloc(local_msghdr.msg_accrightslen)) == (caddr_t)0)
  1217.         {
  1218.             vcouldnot("allocate buffer for access rights of length %d bytes", local_msghdr.msg_accrightslen);
  1219.             return -1;
  1220.         }
  1221.  
  1222.         if (quiet_procmget(GLOBALdipc, (unsigned long)local_msghdr.msg_accrights, a, (unsigned int)local_msghdr.msg_accrightslen) == -1)
  1223.             return -1;
  1224.  
  1225.         local_msghdr.msg_accrights = a;
  1226.     }
  1227.  
  1228.     Rstart;
  1229.     return_value0 = syscall(syscallno, fd_lookup((int)arg[0]), &local_msghdr, (int)arg[2]);
  1230.     return_errno = errno;
  1231.     Rstop;
  1232.  
  1233.     /*
  1234.      * Should we copy out any of these fields to the user?
  1235.      * Assuming "no" until demonstrated otherwise.
  1236.      */
  1237.     
  1238.     /*
  1239.      * Free up all the temporary space...
  1240.      */
  1241.  
  1242.     if (local_msghdr.msg_accrights != (caddr_t)0)
  1243.         (void)free((char *)local_msghdr.msg_accrights);
  1244.  
  1245.     if (local_msghdr.msg_iov != (struct iovec *)0)
  1246.     {
  1247.         int    i;
  1248.  
  1249.         for (i = 0; i < local_msghdr.msg_iovlen; i++)
  1250.         {
  1251.             struct iovec    *liovp;
  1252.  
  1253.             liovp = &local_msghdr.msg_iov[i];
  1254.  
  1255.             if (liovp->iov_base != (caddr_t)0)
  1256.                 (void)free((char *)liovp->iov_base);
  1257.         }
  1258.  
  1259.         (void)free((char *)local_msghdr.msg_iov);
  1260.     }
  1261.  
  1262.     if (local_msghdr.msg_name != (caddr_t)0)
  1263.         (void)free((char *)local_msghdr.msg_name);
  1264.  
  1265.     return 0;
  1266. }
  1267.  
  1268. static
  1269. int
  1270. sys_sendto(syscallno)
  1271. int    syscallno;
  1272. {
  1273.     struct sockaddr    to;
  1274.  
  1275.     return generic_sendto(syscallno, &to);
  1276. }
  1277.  
  1278. static
  1279. int
  1280. sys_setitimer(syscallno)
  1281. int    syscallno;
  1282. {
  1283.     struct itimerval    it;
  1284.     struct itimerval    oit;
  1285.  
  1286.     return generic_setitimer(syscallno, &it, sizeof(it), &oit, sizeof(oit));
  1287. }
  1288.  
  1289. static
  1290. int
  1291. sys_setpgrp(syscallno)
  1292. int    syscallno;
  1293. {
  1294.     Rstart;
  1295.     return_value0 = syscall(syscallno, arg[0]);
  1296.     return_errno = errno;
  1297.     Rstop;
  1298.  
  1299.     return 0;
  1300. }
  1301.  
  1302. static
  1303. int
  1304. sys_setrlimit(syscallno)
  1305. int    syscallno;
  1306. {
  1307.     return generic_setrlimit(syscallno, sizeof(struct rlimit));
  1308. }
  1309.  
  1310. #if    defined(SHARE)
  1311. static
  1312. int
  1313. sys_sharecosts(syscallno)
  1314. int    syscallno;
  1315. {
  1316.     int            function;
  1317.     struct sh_consts    *address;
  1318.     int            size;
  1319.  
  1320.     function = arg[0];
  1321.     size = arg[2];
  1322.  
  1323.     if (dmget(arg[1], size, &address) == -1)
  1324.         return -1;
  1325.  
  1326.     Rstart;
  1327.     return_value0 = syscall(syscallno, function, address, size);
  1328.     return_errno = errno;
  1329.     Rstop;
  1330.  
  1331.     if (dmput(arg[1], address, size, return_value0) == -1)
  1332.         return -1;
  1333.  
  1334.     return 0;
  1335. }
  1336. #endif    /* defined(SHARE) */
  1337.  
  1338. #if    0
  1339. #define    SIG_DEBUG    1
  1340. #endif    /* 0 */
  1341.  
  1342. #define    SH_DFL        0
  1343. #define    SH_HOLD        1
  1344.  
  1345. typedef struct siginfo    siginfo;
  1346. struct siginfo
  1347. {
  1348.     unsigned long        sig_handler;
  1349.     int            sig_handler_type;
  1350.     unsigned long        sig_tramp;
  1351.     int            sig_code;
  1352.     struct sigcontext    sig_context;
  1353.     int            sig_pending;
  1354. };
  1355.  
  1356. static siginfo        sinfo[NSIG];
  1357.  
  1358. int            sigs_pending;
  1359.  
  1360. static
  1361. void
  1362. our_handler(sig, code, scp)
  1363. int            sig;
  1364. int            code;
  1365. struct sigcontext    *scp;
  1366. {
  1367.     sinfo[sig].sig_pending++;
  1368.     sigs_pending++;
  1369.  
  1370.     sinfo[sig].sig_code = code;
  1371.     sinfo[sig].sig_context = *scp;
  1372.  
  1373. #if    defined(SIG_DEBUG)
  1374.     if (sysv_print_received_signal(U_SYSV, "sysv_debug", sinfo[sig].sig_tramp, sinfo[sig].sig_handler, sig, sinfo[sig].sig_code, scp) == -1)
  1375.         return -1;
  1376. #endif    /* defined(SIG_DEBUG) */
  1377.  
  1378.     /*
  1379.      * All of our handlers are of the "sigset()" kind.
  1380.      * Normally this would mean that:
  1381.      *    1. during the execution of the handler, any
  1382.      *       further arrivals of the same signal are held.
  1383.      *    2. on return from the handler, the same handler
  1384.      *       is restored and any held signal is delivered.
  1385.      * We want to keep the first property but we want to
  1386.      * modify the second property so that, instead of
  1387.      * restoring the signal handler and re-enabling signals
  1388.      * immediately, we continue to hold signals
  1389.      * and only release them and restore the handler at
  1390.      * a later time (i.e. when we actually simulate signal delivery).
  1391.      * This assignment to "scp->is_sigset" accomplishes this.
  1392.      */
  1393.     scp->is_sigset = 0;
  1394. }
  1395.  
  1396. dinstrn    *
  1397. deliver_signal(dipc)
  1398. dinstrn    *dipc;
  1399. {
  1400.     int            i;
  1401.     struct sigcontext    *sscp;
  1402.     int            regmask;
  1403.     int            regbit;
  1404.     int            regi;
  1405.  
  1406.     for (i = 0; i < nels(sinfo); i++)
  1407.     {
  1408.         if (sinfo[i].sig_pending > 0)
  1409.         {
  1410.             /*
  1411.              * Massage saved sigcontext.
  1412.              */
  1413.             sinfo[i].sig_context.sc_pc = dipc->di_addr;
  1414.  
  1415.             regmask = 0xFFFFFFFF;    
  1416.             sinfo[i].sig_context.sc_regmask = regmask;    
  1417.  
  1418.             sinfo[i].sig_context.sc_regs[0] = 0;
  1419.             for
  1420.             (
  1421.                 regi = 1, regbit = 1 << 1;
  1422.                 regi < nels(sinfo[i].sig_context.sc_regs);
  1423.                 regi++, regbit <<= 1
  1424.             )
  1425.             {
  1426.                 if (regmask & regbit)
  1427.                 {
  1428.                     int    saved_give_warnings;
  1429.  
  1430.                     if (PG(regi) == R_K0 || PG(regi) == R_K1)
  1431.                     {
  1432.                         saved_give_warnings = give_warnings;
  1433.                         give_warnings = 0;
  1434.                     }
  1435.  
  1436.                     if (quiet_procsget(PG(regi), &sinfo[i].sig_context.sc_regs[regi]) == -1)
  1437.                         return dipc;
  1438.  
  1439.                     if (PG(regi) == R_K0 || PG(regi) == R_K1)
  1440.                         give_warnings = saved_give_warnings;
  1441.                 }
  1442.             }
  1443.  
  1444.             if (quiet_procsget(R_HI, &sinfo[i].sig_context.sc_mdhi) == -1)
  1445.                 return dipc;
  1446.  
  1447.             if (quiet_procsget(R_LO, &sinfo[i].sig_context.sc_mdlo) == -1)
  1448.                 return dipc;
  1449. #if    0
  1450.             /*
  1451.              * TODO: floating point? exceptions?
  1452.              */
  1453.             {
  1454.                 int *srp, *frp;
  1455.                 uint *urp;
  1456.  
  1457.                 scp->sc_ownedfp = u.u_pcb.pcb_ownedfp;
  1458.  
  1459.                 if ((regmask & 1) && u.u_pcb.pcb_ownedfp)
  1460.                 {
  1461.                     checkfp (u.u_procp, 0);    /* dump fp to pcb */
  1462.                     for
  1463.                     (
  1464.                         srp = &scp->sc_fpregs[0], frp = u.u_pcb.pcb_fpregs;
  1465.                         frp < &u.u_pcb.pcb_fpregs[32];
  1466.                         srp++, frp++
  1467.                     )
  1468.                         *srp = *frp;
  1469.                     scp->sc_fpc_csr = u.u_pcb.pcb_fpc_csr;
  1470.                     scp->sc_fpc_eir = u.u_pcb.pcb_fpc_eir;
  1471.                     u.u_pcb.pcb_fpc_csr &= ~FPCSR_EXCEPTIONS;
  1472.                 }
  1473.  
  1474.                 scp->sc_cause = USER_REG(EF_CAUSE);
  1475.                 scp->sc_badvaddr = USER_REG(EF_BADVADDR);
  1476.             }
  1477. #endif    /* 0 */
  1478.  
  1479.             /*
  1480.              * Store massaged sigcontext on stack.
  1481.              */
  1482.             if (quiet_procsget(R_SP, &sscp) == -1)
  1483.                 return dipc;
  1484.  
  1485.             /*
  1486.              * Make room.
  1487.              */
  1488.             sscp--;
  1489.  
  1490.             /*
  1491.              * Ensure quad word aligned.
  1492.              */
  1493.             sscp = (struct sigcontext *)(((unsigned long)sscp) & ~0xF);
  1494.  
  1495.             if (quiet_procmput(GLOBALdipc, (unsigned long)sscp, &sinfo[i].sig_context, sizeof(sinfo[i].sig_context)) == -1)
  1496.                 return dipc;
  1497.  
  1498.             if (Pflag || Sflag)
  1499.             {
  1500.                 if (sysv_print_received_signal(U_SYSV, "sysv", sinfo[i].sig_tramp, sinfo[i].sig_handler, i, sinfo[i].sig_code, sscp) == -1)
  1501.                     return dipc;
  1502.             }
  1503.  
  1504.             /*
  1505.              * Set up arguments and SP for sig_tramp() call.
  1506.              */
  1507.             if (quiet_procsput(R_A0, i) == -1)
  1508.                 return dipc;
  1509.  
  1510.             if (quiet_procsput(R_A1, sinfo[i].sig_code) == -1)
  1511.                 return dipc;
  1512.  
  1513.             if (quiet_procsput(R_A2, sscp) == -1)
  1514.                 return dipc;
  1515.  
  1516.             if (quiet_procsput(R_SP, sscp) == -1)
  1517.                 return dipc;
  1518.  
  1519.             if (quiet_procsput(R_A3, sinfo[i].sig_handler) == -1)
  1520.                 return dipc;
  1521.  
  1522.             /*
  1523.              * Set up PC for sig_tramp() call.
  1524.              */
  1525.             if ((dipc = addr_to_decoded_instrnp(dipc, sinfo[i].sig_tramp)) == (dinstrn *)0)
  1526.                 return dipc;
  1527.  
  1528.             dipc--;
  1529.  
  1530.             sigs_pending--;
  1531.             sinfo[i].sig_pending--;
  1532.  
  1533.             if (sinfo[i].sig_handler_type == SH_DFL)
  1534.                 (void)sigset(i, SIG_DFL);
  1535.  
  1536.             break;
  1537.         }
  1538.     }
  1539.  
  1540.     return dipc;
  1541. }
  1542.  
  1543. static
  1544. int
  1545. sys_signal(syscallno)
  1546. int    syscallno;
  1547. {
  1548.     int    signo;
  1549.     int    sigbits;
  1550.  
  1551.     signo = arg[0] & SIGNO_MASK;
  1552.     sigbits = arg[0] & ~SIGNO_MASK;
  1553.  
  1554.     switch ((int)arg[1])
  1555.     {
  1556.     case SIG_IGN:
  1557.     case SIG_DFL:
  1558.     case SIG_HOLD:
  1559.         return_value0 = (long)sigset(signo, arg[1]);
  1560.         if
  1561.         (
  1562.             return_value0 != (long)SIG_ERR
  1563.             &&
  1564.             return_value0 != (long)SIG_DFL
  1565.             &&
  1566.             return_value0 != (long)SIG_IGN
  1567.             &&
  1568.             return_value0 != (long)SIG_HOLD
  1569.         )
  1570.             return_value0 = sinfo[signo].sig_handler;
  1571.  
  1572.         if (return_value0 != (long)SIG_ERR)
  1573.             sinfo[signo].sig_handler = arg[1];
  1574.         break;
  1575.  
  1576.     default:
  1577.         switch (sigbits)
  1578.         {
  1579.         case SIGHOLD:
  1580.             return_value0 = (long)sighold(signo);
  1581.             break;
  1582.  
  1583.         case SIGRELSE:
  1584.             return_value0 = (long)sigrelse(signo);
  1585.             break;
  1586.  
  1587.         case SIGIGNORE:
  1588.             return_value0 = (long)sigignore(signo);
  1589.             break;
  1590.  
  1591.         case SIGPAUSE:
  1592.             return_value0 = (long)sigpause(signo);
  1593.             break;
  1594.  
  1595.         case SIGDEFER:
  1596.             return_value0 = (long)sigset(signo, our_handler);
  1597.             if
  1598.             (
  1599.                 return_value0 != (long)SIG_ERR
  1600.                 &&
  1601.                 return_value0 != (long)SIG_DFL
  1602.                 &&
  1603.                 return_value0 != (long)SIG_IGN
  1604.                 &&
  1605.                 return_value0 != (long)SIG_HOLD
  1606.             )
  1607.                 return_value0 = sinfo[signo].sig_handler;
  1608.  
  1609.             if (return_value0 != (long)SIG_ERR)
  1610.             {
  1611.                 sinfo[signo].sig_handler = arg[1];
  1612.                 sinfo[signo].sig_handler_type = SH_HOLD;
  1613.                 sinfo[signo].sig_tramp = arg[2];
  1614.             }
  1615.             break;
  1616.  
  1617.         default:
  1618.             return_value0 = (long)sigset(signo, our_handler);
  1619.             if
  1620.             (
  1621.                 return_value0 != (long)SIG_ERR
  1622.                 &&
  1623.                 return_value0 != (long)SIG_DFL
  1624.                 &&
  1625.                 return_value0 != (long)SIG_IGN
  1626.                 &&
  1627.                 return_value0 != (long)SIG_HOLD
  1628.             )
  1629.                 return_value0 = sinfo[signo].sig_handler;
  1630.  
  1631.             if (return_value0 != (long)SIG_ERR)
  1632.             {
  1633.                 sinfo[signo].sig_handler = arg[1];
  1634.                 sinfo[signo].sig_handler_type = SH_DFL;
  1635.                 sinfo[signo].sig_tramp = arg[2];
  1636.             }
  1637.             break;
  1638.         }
  1639.         break;
  1640.     }
  1641.  
  1642.     return_errno = errno;
  1643.  
  1644.     return 0;
  1645. }
  1646.  
  1647. static
  1648. int
  1649. sys_sigreturn(syscallno)
  1650. int    syscallno;
  1651. {
  1652.     struct sigcontext    sc;
  1653.     struct sigcontext    *scp;
  1654.     int            regmask;
  1655.     int            regi;
  1656.     int            regbit;
  1657.  
  1658.     if (mget(arg[0], &sc, sizeof(sc), &scp) == -1)
  1659.         return -1;
  1660.  
  1661.     if (scp == (struct sigcontext *)0)
  1662.     {
  1663.         return_value0 = -1;
  1664.         return_errno = EFAULT;
  1665.         return 0;
  1666.     }
  1667.  
  1668. #if    0
  1669.     /*
  1670.      * TODO: floating point? exceptions?
  1671.      */
  1672.     {
  1673.         int *srp, *frp;
  1674.         uint *urp;
  1675.  
  1676.         scp->sc_ownedfp = u.u_pcb.pcb_ownedfp;
  1677.  
  1678.         if ((regmask & 1) && u.u_pcb.pcb_ownedfp)
  1679.         {
  1680.             checkfp (u.u_procp, 0);    /* dump fp to pcb */
  1681.             for
  1682.             (
  1683.                 srp = &scp->sc_fpregs[0], frp = u.u_pcb.pcb_fpregs;
  1684.                 frp < &u.u_pcb.pcb_fpregs[32];
  1685.                 srp++, frp++
  1686.             )
  1687.                 *srp = *frp;
  1688.             scp->sc_fpc_csr = u.u_pcb.pcb_fpc_csr;
  1689.             scp->sc_fpc_eir = u.u_pcb.pcb_fpc_eir;
  1690.             u.u_pcb.pcb_fpc_csr &= ~FPCSR_EXCEPTIONS;
  1691.         }
  1692.  
  1693.         scp->sc_cause = USER_REG(EF_CAUSE);
  1694.         scp->sc_badvaddr = USER_REG(EF_BADVADDR);
  1695.     }
  1696. #endif    /* 0 */
  1697.  
  1698.     if (quiet_procsput(R_HI, scp->sc_mdhi) == -1)
  1699.         return -1;
  1700.  
  1701.     if (quiet_procsput(R_LO, scp->sc_mdlo) == -1)
  1702.         return -1;
  1703.  
  1704.     regmask = scp->sc_regmask;
  1705.  
  1706.     for
  1707.     (
  1708.         regi = 1, regbit = 1 << 1;
  1709.         regi < nels(scp->sc_regs);
  1710.         regi++, regbit <<= 1
  1711.     )
  1712.     {
  1713.         if (regmask & regbit)
  1714.         {
  1715.             int    saved_give_warnings;
  1716.  
  1717.             if (PG(regi) == R_K0 || PG(regi) == R_K1)
  1718.             {
  1719.                 saved_give_warnings = give_warnings;
  1720.                 give_warnings = 0;
  1721.             }
  1722.  
  1723.             if (quiet_procsput(PG(regi), scp->sc_regs[regi]) == -1)
  1724.                 return -1;
  1725.  
  1726.             if (PG(regi) == R_K0 || PG(regi) == R_K1)
  1727.                 give_warnings = saved_give_warnings;
  1728.         }
  1729.     }
  1730.  
  1731.     /*
  1732.      * Set up PC for return.
  1733.      */
  1734.     if ((GLOBALdipc = addr_to_decoded_instrnp(GLOBALdipc, scp->sc_pc)) == (dinstrn *)0)
  1735.         return -1;
  1736.  
  1737.     GLOBALdipc--;
  1738.  
  1739.     if (scp->is_sigset != 0)
  1740.         (void)sigrelse(scp->is_sigset & SIGNO_MASK);
  1741.  
  1742.     /*
  1743.      * Set up tidy but unused return values.
  1744.      */
  1745.     return_value0 = 0;
  1746.     return_errno = 0;
  1747.  
  1748.     return -3;
  1749. }
  1750.  
  1751. static
  1752. int
  1753. sys_stat(syscallno)
  1754. int    syscallno;
  1755. {
  1756.     struct stat    statb;
  1757.  
  1758.     return generic_stat(syscallno, &statb, sizeof(statb));
  1759. }
  1760.  
  1761. static
  1762. int
  1763. sys_statfs(syscallno)
  1764. int    syscallno;
  1765. {
  1766.     char        *cp;
  1767.     int        len;
  1768.     struct statfs    buf;
  1769.     struct statfs    *bufp;
  1770.  
  1771.     if (mgets(arg[0], &cp) == -1)
  1772.         return -1;
  1773.  
  1774.     len = arg[2];
  1775.  
  1776.     if (mget(arg[1], &buf, len, &bufp) == -1)
  1777.         return -1;
  1778.  
  1779.     Rstart;
  1780.     return_value0 = syscall(syscallno, cp, bufp, len, (int)arg[3]);
  1781.     return_errno = errno;
  1782.     Rstop;
  1783.  
  1784.     if (mput(arg[1], bufp, len, return_value0) == -1)
  1785.         return -1;
  1786.  
  1787.     return 0;
  1788. }
  1789.  
  1790. static
  1791. int
  1792. sys_sysfs(syscallno)
  1793. int    syscallno;
  1794. {
  1795.     char    *cp;
  1796.     char    buf[FSTYPSZ];
  1797.  
  1798.     switch (arg[0])
  1799.     {
  1800.     case GETFSIND:
  1801.         if (mgets(arg[1], &cp) == -1)
  1802.             return -1;
  1803.  
  1804.         Rstart;
  1805.         return_value0 = syscall(syscallno, arg[0], cp);
  1806.         return_errno = errno;
  1807.         Rstop;
  1808.  
  1809.         break;
  1810.  
  1811.     case GETFSTYP:
  1812.         Rstart;
  1813.         return_value0 = syscall(syscallno, arg[0], arg[1], &buf[0]);
  1814.         return_errno = errno;
  1815.         Rstop;
  1816.  
  1817.         if (mput(arg[2], &buf[0], sizeof(buf), return_value0) == -1)
  1818.             return -1;
  1819.         break;
  1820.  
  1821.     case GETNFSTYP:
  1822.         Rstart;
  1823.         return_value0 = syscall(syscallno, arg[0]);
  1824.         return_errno = errno;
  1825.         Rstop;
  1826.         break;
  1827.  
  1828.     default:
  1829.         return -2;
  1830.     }
  1831.  
  1832.     return 0;
  1833. }
  1834.  
  1835. static
  1836. int
  1837. sys_times(syscallno)
  1838. int    syscallno;
  1839. {
  1840.     return generic_times(syscallno, sizeof(struct tms));
  1841. }
  1842.  
  1843. static
  1844. int
  1845. sys_utime(syscallno)
  1846. int    syscallno;
  1847. {
  1848.     time_t    t[2];
  1849.  
  1850.     return generic_utime(syscallno, &t[0], sizeof(t));
  1851. }
  1852.  
  1853. static
  1854. int
  1855. sys_utssys(syscallno)
  1856. int    syscallno;
  1857. {
  1858.     struct utsname    *utsnp;
  1859.     struct ustat    *ubp;
  1860.  
  1861.     switch (arg[2])
  1862.     {
  1863.     case 0:    /* uname */
  1864.         if (dmget(arg[0], sizeof(*utsnp), &utsnp) == -1)
  1865.             return -1;
  1866.  
  1867.         Rstart;
  1868.         return_value0 = syscall(syscallno, utsnp, 0, arg[2]);
  1869.         return_errno = errno;
  1870.         Rstop;
  1871.  
  1872.         if (dmput(arg[0], utsnp, sizeof(*utsnp), return_value0) == -1)
  1873.             return -1;
  1874.         break;
  1875.  
  1876.     case 2:    /* ustat */
  1877.         if (dmget(arg[0], sizeof(*ubp), &ubp) == -1)
  1878.             return -1;
  1879.  
  1880.         Rstart;
  1881.         return_value0 = syscall(syscallno, ubp, arg[1], arg[2]);
  1882.         return_errno = errno;
  1883.         Rstop;
  1884.  
  1885.         if (dmput(arg[0], ubp, sizeof(*ubp), return_value0) == -1)
  1886.             return -1;
  1887.         break;
  1888.  
  1889.     default:
  1890.         return -2;
  1891.     }
  1892.  
  1893.     return 0;
  1894. }
  1895.  
  1896. static
  1897. int
  1898. sys_wait3(syscallno)
  1899. int    syscallno;
  1900. {
  1901.     union wait    s;
  1902.     struct rusage    r;
  1903.  
  1904.     return generic_wait3(syscallno, &s, sizeof(s), &r, sizeof(r));
  1905. }
  1906.  
  1907. static sysentry    sysv_systab[]    =
  1908. {
  1909.     { "syscall",    1,    "d",    'd',    (int (*)())0,    },
  1910.     { "_exit",    1,    "d",    'e',    generic_exit,    },
  1911.     { "fork",    0,    "",    'Y',    generic_fork,    },
  1912.     { "read",    3,    "dRd",    'd',    generic_read,    },
  1913.     { "write",    3,    "dWd",    'd',    generic_write,    },
  1914.     { "open",    3,    "FOm",    'd',    generic_open,    },
  1915.     { "close",    1,    "d",    'd',    generic_close,    },
  1916.     { "Owait",    0,    "",    '\0',    (int (*)())0,    },
  1917.     { "creat",    2,    "Fm",    'd',    generic_creat,    },
  1918.     { "link",    2,    "FF",    'd',    generic_link,    },
  1919.  
  1920.     { "unlink",    1,    "F",    'd',    generic_unlink,    },
  1921.     { "Oexecv",    0,    "",    '\0',    (int (*)())0,    },
  1922.     { "chdir",    1,    "F",    'd',    generic_chdir,    },
  1923.     { "time",    1,    "v",    't',    generic_time,    },
  1924.     { "mknod",    3,    "Fmx",    'd',    generic_mknod,    },
  1925.     { "chmod",    2,    "Fm",    'd',    generic_chmod,    },
  1926.     { "chown",    3,    "Fdd",    'd',    generic_chown,    },
  1927.     { "brk",    1,    "I",    'd',    generic_brk,    },
  1928.     { "stat",    2,    "FS",    'd',    sys_stat,    },
  1929.     { "lseek",    3,    "duw",    'u',    generic_lseek,    },
  1930.  
  1931.     { "getpid",    0,    "",    'd',    generic_getpid,    },
  1932.     { "mount",    0,    "",    '\0',    (int (*)())0,    },
  1933.     { "umount",    0,    "",    '\0',    (int (*)())0,    },
  1934.     { "setuid",    1,    "d",    'd',    generic_setuid,    },
  1935.     { "getuid",    0,    "",    'Y',    sys_getuid,    },
  1936.     { "stime",    1,    "v",    'd',    generic_stime,    },
  1937.     { "ptrace",    4,    "ddxd",    'd',    generic_ptrace,    },
  1938.     { "alarm",    1,    "d",    'd',    generic_alarm,    },
  1939.     { "fstat",    2,    "dS",    'd',    sys_fstat,    },
  1940.     { "pause",    0,    "",    'd',    generic_pause,    },
  1941.  
  1942.     { "utime",    2,    "FQ",    'd',    sys_utime,    },
  1943.     { "Ostty",    0,    "",    '\0',    (int (*)())0,    },
  1944.     { "Ogtty",    0,    "",    '\0',    (int (*)())0,    },
  1945.     { "access",    2,    "FP",    'd',    generic_access,    },
  1946.     { "nice",    1,    "d",    'd',    generic_nice,    },
  1947.     { "statfs",    4,    "FXdd",    'd',    sys_statfs,    },
  1948.     { "sync",    0,    "",    'd',    generic_sync,    },
  1949.     { "kill",    2,    "dK",    'd',    generic_kill,    },
  1950.     { "fstatfs",    4,    "dXdd",    'd',    sys_fstatfs,    },
  1951.     { "setpgrp",    1,    "d",    'd',    sys_setpgrp,    },
  1952.  
  1953.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1954.     { "dup",    1,    "d",    'd',    generic_dup,    },
  1955.     { "pipe",    0,    "",    'Y',    sys_pipe,    },
  1956.     { "times",    1,    "k",    'd',    sys_times,    },
  1957.     { "profil",    4,    "Iddd",    'd',    generic_profil,    },
  1958.     { "plock",    1,    "d",    'd',    generic_plock,    },
  1959.     { "setgid",    1,    "d",    'd',    generic_setgid,    },
  1960.     { "getgid",    0,    "",    'Y',    sys_getgid,    },
  1961.     { "signal",    3,    "KJI",    'J',    sys_signal,    },
  1962.     { "msgsys",    0,    "",    '\0',    (int (*)())0,    },
  1963.  
  1964.     { "sysmips",    0,    "",    '\0',    (int (*)())0,    },
  1965.     { "acct",    1,    "F",    'd',    generic_acct,    },
  1966.     { "shmsys",    0,    "",    '\0',    (int (*)())0,    },
  1967.     { "semsys",    0,    "",    '\0',    (int (*)())0,    },
  1968.     { "ioctl",    3,    "dCA",    'd',    sys_ioctl,    },
  1969.     { "uadmin",    3,    "ddd",    'd',    generic_uadmin,    },
  1970.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1971.     { "utssys",    3,    "pdd",    'd',    sys_utssys,    },
  1972.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1973.     { "execve",    3,    "FlE",    'e',    sys_execve,    },
  1974.  
  1975.     { "umask",    1,    "x",    'x',    generic_umask,    },
  1976.     { "chroot",    1,    "F",    'd',    generic_chroot,    },
  1977.     { "ofcntl",    3,    "dxd",    'd',    sys_ofcntl,    },
  1978.     { "ulimit",    2,    "dd",    'd',    generic_ulimit,    },
  1979.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1980.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1981.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1982.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1983.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1984.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1985.  
  1986.     { "advfs",    0,    "",    '\0',    (int (*)())0,    },
  1987.     { "unadvfs",    0,    "",    '\0',    (int (*)())0,    },
  1988.     { "rmount",    0,    "",    '\0',    (int (*)())0,    },
  1989.     { "rumount",    0,    "",    '\0',    (int (*)())0,    },
  1990.     { "rfstart",    0,    "",    '\0',    (int (*)())0,    },
  1991.     { "",        0,    "",    '\0',    (int (*)())0,    },
  1992.     { "rdebug",    0,    "",    '\0',    (int (*)())0,    },
  1993.     { "rfstop",    0,    "",    '\0',    (int (*)())0,    },
  1994.     { "rfsys",    0,    "",    '\0',    (int (*)())0,    },
  1995.     { "rmdir",    1,    "F",    'd',    generic_rmdir,    },
  1996.  
  1997.     { "mkdir",    2,    "Fm",    'd',    generic_mkdir,    },
  1998.     { "getdents",    3,    "dRd",    'd',    generic_getdents,    },
  1999.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2000.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2001.     { "sysfs",    3,    "dxp",    'd',    sys_sysfs,    },
  2002.     { "getmsg",    0,    "",    '\0',    (int (*)())0,    },
  2003.     { "putmsg",    0,    "",    '\0',    (int (*)())0,    },
  2004.     { "poll",    3,    "pdd",    'd',    sys_poll,    },
  2005.     { "sigreturn",    1,    "y",    'd',    sys_sigreturn,    },
  2006.     { "accept",    3,    "dLU",    'd',    generic_accept,    },
  2007.  
  2008.     { "bind",    3,    "dLd",    'd',    generic_bind,    },
  2009.     { "connect",    3,    "dLd",    'd',    generic_connect,    },
  2010.     { "gethostid",    0,    "",    'u',    generic_gethostid,    },
  2011.     { "getpeername", 3,    "dLU",    'd',    generic_getpeername, },
  2012.     { "getsockname", 3,    "dLU",    'd',    generic_getsockname, },
  2013.     { "getsockopt", 5,    "dddxU", 'd',    generic_getsockopt,    },
  2014.     { "listen",    2,    "dd",    'd',    generic_listen,    },
  2015.     { "recv",    4,    "dRdN",    'd',    generic_recv,    },
  2016.     { "recvfrom",    6,    "dRdNLU", 'd',    sys_recvfrom,    },
  2017.     { "recvmsg",    3,    "dpN",    'd',    sys_recvmsg,    },
  2018.  
  2019.     { "select",    5,    "dDDDT", 'd',    sys_select,    },
  2020.     { "send",    4,    "dWdN",    'd',    generic_send,    },
  2021.     { "sendmsg",    3,    "dpN",    'd',    sys_sendmsg,    },
  2022.     { "sendto",    6,    "dWdNLd", 'd',    sys_sendto,    },
  2023.     { "sethostid",    1,    "u",    'd',    generic_sethostid,    },
  2024.     { "setsockopt", 5,    "dddpd", 'd',    generic_setsockopt,    },
  2025.     { "shutdown",    2,    "dd",    'd',    generic_shutdown,    },
  2026.     { "socket",    3,    "abc",    'd',    generic_socket,    },
  2027.     { "gethostname", 2,    "xd",    'd',    generic_gethostname, },
  2028.     { "sethostname", 0,    "",    '\0',    (int (*)())0,    },
  2029.  
  2030.     { "getdomainname", 2,    "xd",    'd',    generic_getdomainname,    },
  2031.     { "setdomainname", 2,    "xd",    'd',    generic_setdomainname, },
  2032.     { "truncate",    2,    "Fu",    'd',    generic_truncate,    },
  2033.     { "ftruncate",    2,    "du",    'd',    generic_ftruncate,    },
  2034.     { "rename",    2,    "FF",    'd',    generic_rename,    },
  2035.     { "symlink",    2,    "FF",    'd',    generic_symlink,    },
  2036.     { "readlink",    3,    "FRd",    'd',    generic_readlink,    },
  2037.     { "lstat",    2,    "FS",    'd',    sys_lstat,    },
  2038.     { "nfsmount",    0,    "",    '\0',    (int (*)())0,    },
  2039.     { "nfssvc",    0,    "",    'd',    generic_nfssvc,    },
  2040.  
  2041.     { "getfh",    0,    "",    '\0',    (int (*)())0,    },
  2042.     { "async_daemon", 0,    "",    'd',    generic_async_daemon, },
  2043.     { "old_exportfs", 0,    "",    '\0',    (int (*)())0,    },
  2044.     { "mmap",    0,    "",    '\0',    (int (*)())0,    },
  2045.     { "munmap",    0,    "",    '\0',    (int (*)())0,    },
  2046.     { "getitimer",    2,    "dV",    'd',    sys_getitimer,    },
  2047.     { "setitimer",    3,    "dVV",    'd',    sys_setitimer,    },
  2048.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2049.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2050.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2051.  
  2052.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2053.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2054.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2055.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2056.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2057.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2058.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2059.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2060.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2061.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2062.  
  2063.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2064.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2065.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2066.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2067.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2068.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2069.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2070.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2071.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2072.     { "",        0,    "",    '\0',    (int (*)())0,    },
  2073.  
  2074.     { "cacheflush", 3,    "Idd",    'd',    generic_cacheflush,    },
  2075.     { "cachectl",    3,    "Idd",    'd',    generic_cachectl,    },
  2076.     { "fchown",    3,    "ddd",    'd',    generic_fchown,    },
  2077.     { "fchmod",    2,    "dm",    'd',    generic_fchmod,    },
  2078.     { "wait3",    3,    "hij",    'd',    sys_wait3,    },
  2079.     { "mmap",    0,    "",    '\0',    (int (*)())0,    },
  2080.     { "munmap",    0,    "",    '\0',    (int (*)())0,    },
  2081.     { "madvise",    0,    "",    '\0',    (int (*)())0,    },
  2082.     { "getpagesize",0,    "",    'd',    generic_getpagesize, },
  2083.     { "setreuid",    2,    "dd",    'd',    generic_setreuid,    },
  2084.  
  2085.     { "setregid",    2,    "dd",    'd',    generic_setregid,    },
  2086.     { "setpgid",    2,    "dd",    'd',    generic_setpgid,    },
  2087.     { "getgroups",    2,    "dG",    'd',    sys_getgroups,    },
  2088.     { "setgroups",    2,    "dg",    'd',    generic_setgroups,    },
  2089.     { "gettimeofday", 2,    "TZ",    'd',    sys_gettimeofday, },
  2090.     { "getrusage",    2,    "dx",    'd',    sys_getrusage,    },
  2091.     { "getrlimit",    2,    "dx",    'd',    sys_getrlimit,    },
  2092.     { "setrlimit",    2,    "dx",    'd',    sys_setrlimit,    },
  2093.     { "exportfs",    0,    "",    '\0',    (int (*)())0,    },
  2094.     { "fcntl",    3,    "dBH",    'd',    sys_fcntl,    },
  2095. #if    0
  2096. And then, a long way on at 260, 261 and 262 there are:
  2097.     { "netboot",    0,    "",    '\0',    (int (*)())0,    },
  2098.     { "netunboot",    0,    "",    '\0',    (int (*)())0,    },
  2099.     { "rdump",    0,    "",    '\0',    (int (*)())0,    },
  2100. but they aren't used.
  2101. #endif    /* 0 */
  2102. };
  2103.  
  2104. #if    defined(LIMITS)
  2105. static sysentry    limits_sysv_systab[]    =
  2106. {
  2107.     { "setlim",    2,    "",    '\0',    (int (*)())0,    }, /* 320 */
  2108.     { "getlim",    3,    "dxd",    'd',    sys_getlim,    }, /* 321 */
  2109.     { "limonoff",    1,    "",    '\0',    (int (*)())0,    }, /* 322 */
  2110. };
  2111. #endif    /* defined(LIMITS) */
  2112.  
  2113. #if    defined(SHARE)
  2114. static sysentry    share_sysv_systab[]    =
  2115. {
  2116.     { "sharecosts",    3,    "dxd",    'd',    sys_sharecosts,    }, /* 323 */
  2117.     { "gettab",    4,    "",    '\0',    (int (*)())0,    }, /* 324 */
  2118. };
  2119. #endif    /* defined(SHARE) */
  2120.  
  2121. sysentry    *
  2122. sysv_systab_entry(n)
  2123. int    n;
  2124. {
  2125.     int    nn;
  2126.  
  2127.     if (n >= 0 && n < nels(sysv_systab))
  2128.         return &sysv_systab[n];
  2129.  
  2130. #if    defined(LIMITS)
  2131.     nn = n - (LIMITSoffset - SYSVoffset);
  2132.  
  2133.     if (nn >= 0 && nn < nels(limits_sysv_systab))
  2134.         return &limits_sysv_systab[nn];
  2135. #endif    /* defined(LIMITS) */
  2136.  
  2137. #if    defined(SHARE)
  2138.     nn = n - (SHAREoffset - SYSVoffset);
  2139.  
  2140.     if (nn >= 0 && nn < nels(share_sysv_systab))
  2141.         return &share_sysv_systab[nn];
  2142. #endif    /* defined(SHARE) */
  2143.  
  2144.     return (sysentry *)0;
  2145. }
  2146.  
  2147. int
  2148. sysv_print_open_flags(arg)
  2149. unsigned long    arg;
  2150. {
  2151.     need_leading_pipe = 0;
  2152.  
  2153.     if ((arg & (O_WRONLY | O_RDWR)) == 0)
  2154.     {
  2155.         say_flag(O_RDONLY, "O_RDONLY", arg);
  2156.     }
  2157.     else
  2158.     {
  2159.         say_flag(O_WRONLY, "O_WRONLY", arg);
  2160.         say_flag(O_RDWR, "O_RDWR", arg);
  2161.     }
  2162.  
  2163.     say_flag(O_APPEND, "O_APPEND", arg);
  2164.     say_flag(O_CREAT, "O_CREAT", arg);
  2165.     say_flag(O_EXCL, "O_EXCL", arg);
  2166.     say_flag(O_NDELAY, "O_NDELAY", arg);
  2167.     say_flag(O_SYNC, "O_SYNC", arg);
  2168.     say_flag(O_TRUNC, "O_TRUNC", arg);
  2169.  
  2170.     say_residual(arg);
  2171.  
  2172.     return 0;
  2173. }
  2174.  
  2175. int
  2176. sysv_print_stat(arg)
  2177. long    arg;
  2178. {
  2179.     struct stat    statbuf;
  2180.  
  2181.     if (quiet_procmget(GLOBALdipc, (unsigned long)arg, (char *)&statbuf, sizeof(statbuf)) == -1)
  2182.         return -1;
  2183.  
  2184.     fprintf(outfp, "{" /* } */ );
  2185.     fprintf(outfp, "st_dev=0x%x,", statbuf.st_dev);
  2186.     fprintf(outfp, " st_ino=%d,", statbuf.st_ino);
  2187.     fprintf(outfp, " st_mode=0x%x,", statbuf.st_mode);
  2188.     fprintf(outfp, " st_nlink=%d,", statbuf.st_nlink);
  2189.     fprintf(outfp, " st_uid=%d,", statbuf.st_uid);
  2190.     fprintf(outfp, " st_gid=%d,", statbuf.st_gid);
  2191.     fprintf(outfp, " st_rdev=0x%x,", statbuf.st_rdev);
  2192.     fprintf(outfp, " st_size=%d,", statbuf.st_size);
  2193.     fprintf(outfp, " st_atime=");
  2194.     say_time(outfp, statbuf.st_atime);
  2195.     fprintf(outfp, ",");
  2196.     fprintf(outfp, " st_mtime=");
  2197.     say_time(outfp, statbuf.st_mtime);
  2198.     fprintf(outfp, ",");
  2199.     fprintf(outfp, " st_ctime=");
  2200.     say_time(outfp, statbuf.st_ctime);
  2201.     fprintf(outfp, ",");
  2202.     fprintf(outfp, /* { */ "}");
  2203.  
  2204.     return 0;
  2205. }
  2206.  
  2207. int
  2208. sysv_print_ioctl_cmd(cmd)
  2209. unsigned long    cmd;
  2210. {
  2211.     char    *cname;
  2212.  
  2213.     switch (cmd)
  2214.     {
  2215.     case FIONREAD:
  2216.         cname = "FIONREAD";
  2217.         break;
  2218.  
  2219.     case I_POP:
  2220.         cname = "I_POP";
  2221.         break;
  2222.  
  2223.     case I_PUSH:
  2224.         cname = "I_PUSH";
  2225.         break;
  2226.  
  2227.     case I_SRDOPT:
  2228.         cname = "I_SRDOPT";
  2229.         break;
  2230.  
  2231.     case STGET:
  2232.         cname = "STGET";
  2233.         break;
  2234.  
  2235.     case oTCGETA:
  2236.         cname = "oTCGETA";
  2237.         break;
  2238.  
  2239.     case TCGETA:
  2240.         cname = "TCGETA";
  2241.         break;
  2242.  
  2243.     case oTCSETA:
  2244.         cname = "oTCSETA";
  2245.         break;
  2246.  
  2247.     case TCSETA:
  2248.         cname = "TCSETA";
  2249.         break;
  2250.  
  2251.     case oTCSETAF:
  2252.         cname = "oTCSETAF";
  2253.         break;
  2254.  
  2255.     case TCSETAF:
  2256.         cname = "TCSETAF";
  2257.         break;
  2258.  
  2259.     case oTCSETAW:
  2260.         cname = "oTCSETAW";
  2261.         break;
  2262.  
  2263.     case TCSETAW:
  2264.         cname = "TCSETAW";
  2265.         break;
  2266.  
  2267.     case TCFLSH:
  2268.         cname = "TCFLSH";
  2269.         break;
  2270.  
  2271.     case TCSBRK:
  2272.         cname = "TCSBRK";
  2273.         break;
  2274.  
  2275.     case TCXONC:
  2276.         cname = "TCXONC";
  2277.         break;
  2278.  
  2279.     case oTIOCEXCL:
  2280.         cname = "oTIOCEXCL";
  2281.         break;
  2282.  
  2283.     case TIOCEXCL:
  2284.         cname = "TIOCEXCL";
  2285.         break;
  2286.  
  2287.     case TIOCGPGRP:
  2288.         cname = "TIOCGPGRP";
  2289.         break;
  2290.  
  2291.     case TIOCGWINSZ:
  2292.         cname = "TIOCGWINSZ";
  2293.         break;
  2294.  
  2295.     case oTIOCHPCL:
  2296.         cname = "oTIOCHPCL";
  2297.         break;
  2298.  
  2299.     case oTIOCNOTTY:
  2300.         cname = "oTIOCNOTTY";
  2301.         break;
  2302.  
  2303.     case TIOCNOTTY:
  2304.         cname = "TIOCNOTTY";
  2305.         break;
  2306.  
  2307.     case oTIOCNXCL:
  2308.         cname = "oTIOCNXCL";
  2309.         break;
  2310.  
  2311.     case TIOCNXCL:
  2312.         cname = "TIOCNXCL";
  2313.         break;
  2314.  
  2315.     case TIOCOUTQ:
  2316.         cname = "TIOCOUTQ";
  2317.         break;
  2318.  
  2319.     case TIOCSPGRP:
  2320.         cname = "TIOCSPGRP";
  2321.         break;
  2322.  
  2323.     case oTIOCSTI:
  2324.         cname = "oTIOCSTI";
  2325.         break;
  2326.  
  2327.     case TIOCSTI:
  2328.         cname = "TIOCSTI";
  2329.         break;
  2330.  
  2331.     case TIOCSWINSZ:
  2332.         cname = "TIOCSWINSZ";
  2333.         break;
  2334.  
  2335.     case LDSETT:
  2336.         cname = "LDSETT";
  2337.         break;
  2338.  
  2339.     default:
  2340.         cname = (char *)0;
  2341.         break;
  2342.     }
  2343.  
  2344.     if (cname == (char *)0)
  2345.         fprintf(outfp, "0x%x", cmd);
  2346.     else
  2347.         fprintf(outfp, "%s", cname);
  2348.  
  2349.     return 0;
  2350. }
  2351.  
  2352. static
  2353. int
  2354. say_termcb(arg)
  2355. unsigned long    arg;
  2356. {
  2357.     struct termcb    tio;
  2358.  
  2359.     if (quiet_procmget(GLOBALdipc, arg, &tio, sizeof(tio)) == -1)
  2360.         return -1;
  2361.  
  2362.     fprintf(outfp, "{");
  2363.  
  2364.     /*
  2365.      * term flags.
  2366.      */
  2367.  
  2368.     fprintf(outfp, "st_flgs=");
  2369.  
  2370.     need_leading_pipe = 0;
  2371.  
  2372.     say_notflag(TM_NONE, "TM_NONE", tio.st_flgs);
  2373.     say_flag(TM_SNL, "TM_SNL", tio.st_flgs);
  2374.     say_flag(TM_ANL, "TM_ANL", tio.st_flgs);
  2375.     say_flag(TM_LCF, "TM_LCF", tio.st_flgs);
  2376.     say_flag(TM_CECHO, "TM_CECHO", tio.st_flgs);
  2377.     say_flag(TM_CINVIS, "TM_CINVIS", tio.st_flgs);
  2378.     say_flag(TM_SET, "TM_SET", tio.st_flgs);
  2379.  
  2380.     say_residual(tio.st_flgs);
  2381.  
  2382.     /*
  2383.      * term type.
  2384.      */
  2385.  
  2386.     fprintf(outfp, ", st_termt=");
  2387.  
  2388.     switch (tio.st_termt)
  2389.     {
  2390.     case TERM_NONE:
  2391.         fprintf(outfp, "TERM_NONE");
  2392.         break;
  2393.  
  2394.     case TERM_TEC:
  2395.         fprintf(outfp, "TERM_TEC");
  2396.         break;
  2397.  
  2398.     case TERM_V61:
  2399.         fprintf(outfp, "TERM_V61");
  2400.         break;
  2401.  
  2402.     case TERM_V10:
  2403.         fprintf(outfp, "TERM_V10");
  2404.         break;
  2405.  
  2406.     case TERM_TEX:
  2407.         fprintf(outfp, "TERM_TEX");
  2408.         break;
  2409.  
  2410.     case TERM_D40:
  2411.         fprintf(outfp, "TERM_D40");
  2412.         break;
  2413.  
  2414.     case TERM_H45:
  2415.         fprintf(outfp, "TERM_H45");
  2416.         break;
  2417.  
  2418.     case TERM_D42:
  2419.         fprintf(outfp, "TERM_D42");
  2420.         break;
  2421.  
  2422.     default:
  2423.         fprintf(outfp, "0x%x", tio.st_termt);
  2424.         break;
  2425.     }
  2426.  
  2427.     /*
  2428.      * gtty only - current row.
  2429.      */
  2430.     fprintf(outfp, ", st_crow=%d", tio.st_crow);
  2431.  
  2432.     /*
  2433.      * gtty only - current col.
  2434.      */
  2435.     fprintf(outfp, ", st_ccol=%d", tio.st_ccol);
  2436.  
  2437.     /*
  2438.      * variable row.
  2439.      */
  2440.     fprintf(outfp, ", st_vrow=%d", tio.st_vrow);
  2441.  
  2442.     /*
  2443.      * last row.
  2444.      */
  2445.     fprintf(outfp, ", st_lrow=%d", tio.st_lrow);
  2446.  
  2447.     fprintf(outfp, "}");
  2448.  
  2449.     return 0;
  2450. }
  2451.  
  2452. static
  2453. int
  2454. say_termiob(arg)
  2455. unsigned long    arg;
  2456. {
  2457.     struct termio    tio;
  2458.  
  2459.     if (quiet_procmget(GLOBALdipc, arg, &tio, sizeof(tio)) == -1)
  2460.         return -1;
  2461.  
  2462.     fprintf(outfp, "{");
  2463.  
  2464.     /*
  2465.      * Input modes.
  2466.      */
  2467.  
  2468.     fprintf(outfp, "c_iflag=");
  2469.  
  2470.     need_leading_pipe = 0;
  2471.  
  2472.     say_flag(IGNBRK, "IGNBRK", tio.c_iflag);
  2473.     say_flag(BRKINT, "BRKINT", tio.c_iflag);
  2474.     say_flag(IGNPAR, "IGNPAR", tio.c_iflag);
  2475.     say_flag(PARMRK, "PARMRK", tio.c_iflag);
  2476.     say_flag(INPCK, "INPCK", tio.c_iflag);
  2477.     say_flag(ISTRIP, "ISTRIP", tio.c_iflag);
  2478.     say_flag(INLCR, "INLCR", tio.c_iflag);
  2479.     say_flag(IGNCR, "IGNCR", tio.c_iflag);
  2480.     say_flag(ICRNL, "ICRNL", tio.c_iflag);
  2481.     say_flag(IUCLC, "IUCLC", tio.c_iflag);
  2482.     say_flag(IXON, "IXON", tio.c_iflag);
  2483.     say_flag(IXANY, "IXANY", tio.c_iflag);
  2484.     say_flag(IXOFF, "IXOFF", tio.c_iflag);
  2485.  
  2486.     say_residual(tio.c_iflag);
  2487.  
  2488.     /*
  2489.      * Output modes.
  2490.      */
  2491.  
  2492.     fprintf(outfp, ", c_oflag=");
  2493.  
  2494.     need_leading_pipe = 0;
  2495.  
  2496.     say_flag(OPOST, "OPOST", tio.c_oflag);
  2497.     say_flag(OLCUC, "OLCUC", tio.c_oflag);
  2498.     say_flag(ONLCR, "ONLCR", tio.c_oflag);
  2499.     say_flag(OCRNL, "OCRNL", tio.c_oflag);
  2500.     say_flag(ONOCR, "ONOCR", tio.c_oflag);
  2501.     say_flag(ONLRET, "ONLRET", tio.c_oflag);
  2502.     say_flag(OFILL, "OFILL", tio.c_oflag);
  2503.     say_flag(OFDEL, "OFDEL", tio.c_oflag);
  2504.  
  2505.     say_notflag(NLDLY, "NL0", tio.c_oflag);
  2506.     say_flag(NL1, "NL1", tio.c_oflag);
  2507.  
  2508.     say_notflag(CRDLY, "CR0", tio.c_oflag);
  2509.     say_flag(CR3, "CR3", tio.c_oflag);
  2510.     say_flag(CR2, "CR2", tio.c_oflag);
  2511.     say_flag(CR1, "CR1", tio.c_oflag);
  2512.  
  2513.     say_notflag(TABDLY, "TAB0", tio.c_oflag);
  2514.     say_flag(TAB3, "TAB3", tio.c_oflag);
  2515.     say_flag(TAB2, "TAB2", tio.c_oflag);
  2516.     say_flag(TAB1, "TAB1", tio.c_oflag);
  2517.  
  2518.     say_notflag(BSDLY, "BS0", tio.c_oflag);
  2519.     say_flag(BS1, "BS1", tio.c_oflag);
  2520.  
  2521.     say_notflag(VTDLY, "VT0", tio.c_oflag);
  2522.     say_flag(VT1, "VT1", tio.c_oflag);
  2523.  
  2524.     say_notflag(FFDLY, "FF0", tio.c_oflag);
  2525.     say_flag(FF1, "FF1", tio.c_oflag);
  2526.  
  2527.     say_residual(tio.c_oflag);
  2528.  
  2529.     /*
  2530.      * Hardware control modes.
  2531.      */
  2532.  
  2533.     fprintf(outfp, ", c_cflag=");
  2534.  
  2535.     switch (tio.c_cflag & CBAUD)
  2536.     {
  2537.     case B0:
  2538.         fprintf(outfp, "B0");
  2539.         break;
  2540.  
  2541.     case B50:
  2542.         fprintf(outfp, "B50");
  2543.         break;
  2544.  
  2545.     case B75:
  2546.         fprintf(outfp, "B75");
  2547.         break;
  2548.  
  2549.     case B110:
  2550.         fprintf(outfp, "B110");
  2551.         break;
  2552.  
  2553.     case B134:
  2554.         fprintf(outfp, "B134");
  2555.         break;
  2556.  
  2557.     case B150:
  2558.         fprintf(outfp, "B150");
  2559.         break;
  2560.  
  2561.     case B200:
  2562.         fprintf(outfp, "B200");
  2563.         break;
  2564.  
  2565.     case B300:
  2566.         fprintf(outfp, "B300");
  2567.         break;
  2568.  
  2569.     case B600:
  2570.         fprintf(outfp, "B600");
  2571.         break;
  2572.  
  2573.     case B1200:
  2574.         fprintf(outfp, "B1200");
  2575.         break;
  2576.  
  2577.     case B1800:
  2578.         fprintf(outfp, "B1800");
  2579.         break;
  2580.  
  2581.     case B2400:
  2582.         fprintf(outfp, "B2400");
  2583.         break;
  2584.  
  2585.     case B4800:
  2586.         fprintf(outfp, "B4800");
  2587.         break;
  2588.  
  2589.     case B9600:
  2590.         fprintf(outfp, "B9600");
  2591.         break;
  2592.  
  2593.     case B19200:
  2594.         fprintf(outfp, "B19200");
  2595.         break;
  2596.  
  2597.     case B38400:
  2598.         fprintf(outfp, "B38400");
  2599.         break;
  2600.     }
  2601.  
  2602.     tio.c_cflag &= ~CBAUD;
  2603.  
  2604.     need_leading_pipe = 1;
  2605.  
  2606.     say_notflag(CSIZE, "CS5", tio.c_cflag);
  2607.     say_flag(CS8, "CS8", tio.c_cflag);
  2608.     say_flag(CS7, "CS7", tio.c_cflag);
  2609.     say_flag(CS6, "CS6", tio.c_cflag);
  2610.  
  2611.     say_flag(CSTOPB, "CSTOPB", tio.c_cflag);
  2612.     say_flag(CREAD, "CREAD", tio.c_cflag);
  2613.     say_flag(PARENB, "PARENB", tio.c_cflag);
  2614.     say_flag(PARODD, "PARODD", tio.c_cflag);
  2615.     say_flag(HUPCL, "HUPCL", tio.c_cflag);
  2616.     say_flag(CLOCAL, "CLOCAL", tio.c_cflag);
  2617.     say_flag(CNEW_RTSCTS, "CNEW_RTSCTS", tio.c_cflag);
  2618.     say_flag(LOBLK, "LOBLK", tio.c_cflag);
  2619.     say_flag(CNEW_MDMBUF, "CNEW_MDMBUF", tio.c_cflag);
  2620.  
  2621.     say_residual(tio.c_cflag);
  2622.  
  2623.     /*
  2624.      * Local flags.
  2625.      */
  2626.  
  2627.     fprintf(outfp, ", c_lflag=");
  2628.  
  2629.     need_leading_pipe = 0;
  2630.  
  2631.     say_flag(ISIG, "ISIG", tio.c_lflag);
  2632.     say_flag(ICANON, "ICANON", tio.c_lflag);
  2633.     say_flag(XCASE, "XCASE", tio.c_lflag);
  2634.     say_flag(ECHO, "ECHO", tio.c_lflag);
  2635.     say_flag(ECHOE, "ECHOE", tio.c_lflag);
  2636.     say_flag(ECHOK, "ECHOK", tio.c_lflag);
  2637.     say_flag(ECHONL, "ECHONL", tio.c_lflag);
  2638.     say_flag(NOFLSH, "NOFLSH", tio.c_lflag);
  2639.     say_flag(TOSTOP, "TOSTOP", tio.c_lflag);
  2640.     say_flag(LNEW_CTLECH, "LNEW_CTLECH", tio.c_lflag);
  2641.     say_flag(LNEW_PRTERA, "LNEW_PRTERA", tio.c_lflag);
  2642.     say_flag(LNEW_CRTBS, "LNEW_CRTBS", tio.c_lflag);
  2643.     say_flag(LNEW_PENDIN, "LNEW_PENDIN", tio.c_lflag);
  2644.     say_flag(LNEW_FLUSHO, "LNEW_FLUSHO", tio.c_lflag);
  2645.  
  2646.     say_residual(tio.c_lflag);
  2647.  
  2648.     /*
  2649.      * Line discipline.
  2650.      */
  2651.  
  2652.     fprintf(outfp, ", c_line=%d", tio.c_line);
  2653.  
  2654.     /*
  2655.      * Control chars.
  2656.      */
  2657.  
  2658.     fprintf(outfp, ", c_cc=[");
  2659.     fprintf(outfp, "VINTR=0x%02x,", tio.c_cc[VINTR]);
  2660.     fprintf(outfp, "VQUIT=0x%02x,", tio.c_cc[VQUIT]);
  2661.     fprintf(outfp, "VERASE=0x%02x,", tio.c_cc[VERASE]);
  2662.     fprintf(outfp, "VKILL=0x%02x,", tio.c_cc[VKILL]);
  2663.     fprintf(outfp, "VEOF=0x%02x,", tio.c_cc[VEOF]);
  2664.     fprintf(outfp, "VEOL=0x%02x,", tio.c_cc[VEOL]);
  2665.     fprintf(outfp, "VEOL2=0x%02x,", tio.c_cc[VEOL2]);
  2666.     fprintf(outfp, "VSWTCH=0x%02x,", tio.c_cc[VSWTCH]);
  2667.     fprintf(outfp, "V_START=0x%02x,", tio.c_cc[V_START]);
  2668.     fprintf(outfp, "V_STOP=0x%02x,", tio.c_cc[V_STOP]);
  2669.     fprintf(outfp, "V_SUSP=0x%02x,", tio.c_cc[V_SUSP]);
  2670.     fprintf(outfp, "V_DSUSP=0x%02x,", tio.c_cc[V_DSUSP]);
  2671.     fprintf(outfp, "V_RPRNT=0x%02x,", tio.c_cc[V_RPRNT]);
  2672.     fprintf(outfp, "V_FLUSH=0x%02x,", tio.c_cc[V_FLUSH]);
  2673.     fprintf(outfp, "V_WERAS=0x%02x,", tio.c_cc[V_WERAS]);
  2674.     fprintf(outfp, "V_LNEXT=0x%02x,", tio.c_cc[V_LNEXT]);
  2675.     fprintf(outfp, "V_STATUS=0x%02x,", tio.c_cc[V_STATUS]);
  2676.     fprintf(outfp, "V_SAVED_EOF=0x%02x,", tio.c_cc[V_SAVED_EOF]);
  2677.     fprintf(outfp, "V_SAVED_EOL=0x%02x,", tio.c_cc[V_SAVED_EOL]);
  2678.     fprintf(outfp, "19=0x%02x,", tio.c_cc[19]);
  2679.     fprintf(outfp, "20=0x%02x,", tio.c_cc[20]);
  2680.     fprintf(outfp, "21=0x%02x,", tio.c_cc[21]);
  2681.     fprintf(outfp, "22=0x%02x,", tio.c_cc[22]);
  2682.     fprintf(outfp, "]");
  2683.  
  2684.     /*
  2685.      * (bsd43) saved flags.
  2686.      */
  2687.  
  2688.     fprintf(outfp, ", c_saved_flags=0x%x", tio.c_saved_flags);
  2689.  
  2690.     /*
  2691.      * Filler.
  2692.      */
  2693.  
  2694.     fprintf(outfp, ", c_filler=0x%x", tio.c_filler);
  2695.  
  2696.     fprintf(outfp, "}");
  2697.  
  2698.     return 0;
  2699. }
  2700.  
  2701. int
  2702. sysv_print_ioctl_arg(args)
  2703. unsigned long    *args;
  2704. {
  2705.     int    i;
  2706.  
  2707.     switch (args[1])
  2708.     {
  2709.     case FIONREAD:
  2710.         if (quiet_procmget(GLOBALdipc, (unsigned long)args[2], &i, sizeof(i)) == -1)
  2711.             return -1;
  2712.  
  2713.         fprintf(outfp, "{*(int *)0x%x=%d}", args[2], i);
  2714.         break;
  2715.  
  2716.     case TCGETA:
  2717.     case TCSETA:
  2718.     case TCSETAW:
  2719.     case TCSETAF:
  2720.         if (say_termiob(args[2]) == -1)
  2721.             return -1;
  2722.  
  2723.         break;
  2724.  
  2725.     case LDSETT:
  2726.         if (say_termcb(args[2]) == -1)
  2727.             return -1;
  2728.  
  2729.         break;
  2730.  
  2731.     default:
  2732.         fprintf(outfp, "0x%x", args[2]);
  2733.         break;
  2734.     }
  2735.  
  2736.     return 0;
  2737. }
  2738.  
  2739. int
  2740. sysv_print_fdset(nfds, arg)
  2741. int        nfds;
  2742. unsigned long    arg;
  2743. {
  2744.     if (arg == (unsigned long)0)
  2745.         fprintf(outfp, "0x%x", arg);
  2746.     else
  2747.     {
  2748.         struct fd_set    tfds;
  2749.         int        fd;
  2750.  
  2751.         if (quiet_procmget(GLOBALdipc, arg, &tfds, sizeof(tfds)) == -1)
  2752.             return -1;
  2753.  
  2754.         fprintf(outfp, "{");
  2755.  
  2756.         for (fd = 0; fd < nfds; fd++)
  2757.         {
  2758.             if (FD_ISSET(fd, &tfds))
  2759.                 fprintf(outfp, "%d,", fd);
  2760.         }
  2761.  
  2762.         fprintf(outfp, "}");
  2763.     }
  2764.  
  2765.     return 0;
  2766. }
  2767.  
  2768. int
  2769. sysv_print_whence(arg)
  2770. unsigned long    arg;
  2771. {
  2772.     switch (arg)
  2773.     {
  2774.     case SEEK_SET:
  2775.         fprintf(outfp, "SEEK_SET");
  2776.         break;
  2777.  
  2778.     case SEEK_CUR:
  2779.         fprintf(outfp, "SEEK_CUR");
  2780.         break;
  2781.  
  2782.     case SEEK_END:
  2783.         fprintf(outfp, "SEEK_END");
  2784.         break;
  2785.  
  2786.     default:
  2787.         fprintf(outfp, "0x%x", arg);
  2788.         break;
  2789.     }
  2790.  
  2791.     return 0;
  2792. }
  2793.  
  2794. int
  2795. sysv_print_statfs(arg)
  2796. unsigned long    arg;
  2797. {
  2798.     if (arg == (unsigned long)0)
  2799.         fprintf(outfp, "0x%x", arg);
  2800.     else
  2801.     {
  2802.         struct statfs    t;
  2803.  
  2804.         if (quiet_procmget(GLOBALdipc, arg, &t, sizeof(t)) == -1)
  2805.             return -1;
  2806.  
  2807.         fprintf(outfp, "{");
  2808.         fprintf(outfp, "fstyp=%d,", t.f_fstyp);
  2809.         fprintf(outfp, "bsize=%d,", t.f_bsize);
  2810.         fprintf(outfp, "frsize=%d,", t.f_frsize);
  2811.         fprintf(outfp, "blocks=%d,", t.f_blocks);
  2812.         fprintf(outfp, "bfree=%d,", t.f_bfree);
  2813.         fprintf(outfp, "files=%d,", t.f_files);
  2814.         fprintf(outfp, "ffree=%d,", t.f_ffree);
  2815.         vis_quoted_truncated_buffer(outfp, sizeof(t.f_fname), &t.f_fname[0], sizeof(t.f_fname));
  2816.         fprintf(outfp, ",");
  2817.         vis_quoted_truncated_buffer(outfp, sizeof(t.f_fpack), &t.f_fpack[0], sizeof(t.f_fpack));
  2818.         fprintf(outfp, "}");
  2819.     }
  2820.     return 0;
  2821. }
  2822.  
  2823. int
  2824. sysv_print_wait3_union_wait(arg)
  2825. unsigned long    arg;
  2826. {
  2827.     union wait    w;
  2828.     union wait    *wp;
  2829.  
  2830.     if (mget(arg, &w, sizeof(w), &wp) == -1)
  2831.         return -1;
  2832.  
  2833.     if (wp == (union wait *)0)
  2834.         fprintf(outfp, "0x%x", arg);
  2835.     else
  2836.     {
  2837.         fprintf(outfp, "{" /* } */);
  2838.  
  2839.         if (w.w_status == WSTOPPED)
  2840.         {
  2841.             fprintf(outfp, "w_stopval=WSTOPPED,");
  2842.             fprintf(outfp, "w_stopsig=%s", signal_name(w.w_stopsig));
  2843.         }
  2844.         else
  2845.         {
  2846.             fprintf(outfp, "w_termsig=%s,", signal_name(w.w_termsig));
  2847.             fprintf(outfp, "w_coredump=%d,", w.w_coredump);
  2848.             fprintf(outfp, "w_retcode=%d", w.w_retcode);
  2849.         }
  2850.  
  2851.         fprintf(outfp, /* { */ "}");
  2852.     }
  2853.  
  2854.     return 0;
  2855. }
  2856.  
  2857. int
  2858. sysv_print_wait3_options(arg)
  2859. unsigned long    arg;
  2860. {
  2861.     if (arg == (unsigned long)0)
  2862.         fprintf(outfp, "0x%x", arg);
  2863.     else
  2864.     {
  2865.         need_leading_pipe = 0;
  2866.  
  2867.         say_flag(WNOHANG, "WNOHANG", arg);
  2868.         say_flag(WUNTRACED, "WUNTRACED", arg);
  2869.  
  2870.         say_residual(arg);
  2871.     }
  2872.  
  2873.     return 0;
  2874. }
  2875.  
  2876. int
  2877. sysv_print_wait3_rusage(arg)
  2878. unsigned long    arg;
  2879. {
  2880.     fprintf(outfp, "0x%x", arg);
  2881.  
  2882.     return 0;
  2883. }
  2884.  
  2885. int
  2886. sysv_print_sigcontext(outfp, p)
  2887. FILE        *outfp;
  2888. unsigned long    p;
  2889. {
  2890.     struct sigcontext    sc;
  2891.     struct sigcontext    *scp;
  2892.     int            i;
  2893.  
  2894.     fprintf(outfp, "{" /* } */);
  2895.  
  2896.     if (mget(p, &sc, sizeof(sc), &scp) == -1)
  2897.         return -1;
  2898.  
  2899.     if (Aflag)
  2900.     {
  2901.         if (scp != (struct sigcontext *)0)
  2902.         {
  2903.             fprintf(outfp, "regmask=0x%x,", scp->sc_regmask);
  2904.             fprintf(outfp, "mask=0x%x,", scp->sc_mask);
  2905.             fprintf(outfp, "pc=%s,", proc_text_address(scp->sc_pc));
  2906.  
  2907.             for (i = 0; i < nels(scp->sc_regs); i++)
  2908.                 fprintf(outfp, "regs[%d]=0x%x,", i, scp->sc_regs[i]);
  2909.  
  2910.             fprintf(outfp, "ownedfp=0x%x,", scp->sc_ownedfp);
  2911.  
  2912.             for (i = 0; i < nels(scp->sc_fpregs); i++)
  2913.                 fprintf(outfp, "fpregs[%d]=0x%x,", i, scp->sc_fpregs[i]);
  2914.  
  2915.             fprintf(outfp, "fpc_csr=0x%x,", scp->sc_fpc_csr);
  2916.             fprintf(outfp, "fpc_eir=0x%x,", scp->sc_fpc_eir);
  2917.             fprintf(outfp, "mdhi=%d,", scp->sc_mdhi);
  2918.             fprintf(outfp, "mdlo=%d,", scp->sc_mdlo);
  2919.             fprintf(outfp, "cause=0x%x,", scp->sc_cause);
  2920.             fprintf(outfp, "badvaddr=0x%x,", scp->sc_badvaddr);
  2921.             fprintf(outfp, "badpaddr=0x%x,", scp->sc_badpaddr);
  2922.             fprintf(outfp, "sigset=%s,", signal_name(scp->is_sigset));
  2923.         }
  2924.     }
  2925.     else
  2926.         fprintf(outfp, "...");
  2927.  
  2928.     fprintf(outfp, /* { */ "}");
  2929.  
  2930.     return 0;
  2931. }
  2932.  
  2933. static
  2934. int
  2935. sysv_print_received_signal(universe, universe_name, tramp, handler, sig, code, scp)
  2936. int            universe;
  2937. char            *universe_name;
  2938. unsigned long        tramp;
  2939. unsigned long        handler;
  2940. int            sig;
  2941. int            code;
  2942. struct sigcontext    *scp;
  2943. {
  2944.     fprintf(outfp, "%6d:", P.p_pid);
  2945.  
  2946.     fprintf(outfp, "%s_SIGNAL(", universe_name);
  2947.  
  2948.     if (printval(universe, tramp, 'I', (unsigned long *)0, (unsigned long)0, (unsigned long)0, DIRN_ENTRY) == -1)
  2949.         return -1;
  2950.  
  2951.     fprintf(outfp, ", ");
  2952.  
  2953.     if (printval(universe, handler, 'I', (unsigned long *)0, (unsigned long)0, (unsigned long)0, DIRN_ENTRY) == -1)
  2954.         return -1;
  2955.  
  2956.     fprintf(outfp, ", ");
  2957.  
  2958.     if (printval(universe, sig, 'K', (unsigned long *)0, (unsigned long)0, (unsigned long)0, DIRN_ENTRY) == -1)
  2959.         return -1;
  2960.  
  2961.     fprintf(outfp, ", ");
  2962.  
  2963.     if (printval(universe, code, 'd', (unsigned long *)0, (unsigned long)0, (unsigned long)0, DIRN_ENTRY) == -1)
  2964.         return -1;
  2965.  
  2966.     fprintf(outfp, ", ");
  2967.  
  2968.     if (printval(universe, scp, 'y', (unsigned long *)0, (unsigned long)0, (unsigned long)0, DIRN_ENTRY) == -1)
  2969.         return -1;
  2970.  
  2971.     fprintf(outfp, ")");
  2972.  
  2973.     fprintf(outfp, "\n");
  2974.  
  2975.     return 0;
  2976. }
  2977.