3400: 
3401: /*
3402:  * Everything in this file is a routine implementing a system call.
3403:  *
3404:  */
3405: 
3406: #include "../param.h"
3407: #include "../user.h"
3408: #include "../reg.h"
3409: #include "../inode.h"
3410: #include "../systm.h"
3411: #include "../proc.h"
3412: 
3413: getswit()
3414: {
3415: 
3416:         u.u_ar0[R0] = SW->integ;
3417: }
3418: /* ---------------------------       */
3419: 
3420: gtime()
3421: {
3422: 
3423:         u.u_ar0[R0] = time[0];
3424:         u.u_ar0[R1] = time[1];
3425: }
3426: /* ---------------------------       */
3427: 
3428: stime()
3429: {
3430: 
3431:         if(suser()) {
3432:                 time[0] = u.u_ar0[R0];
3433:                 time[1] = u.u_ar0[R1];
3434:                 wakeup(tout);
3435:         }
3436: }
3437: /* ---------------------------       */
3438: 
3439: setuid()
3440: {
3441:         register uid;
3442: 
3443:         uid = u.u_ar0[R0].lobyte;
3444:         if(u.u_ruid == uid.lobyte || suser()) {
3445:                 u.u_uid = uid;
3446:                 u.u_procp->p_uid = uid;
3447:                 u.u_ruid = uid;
3448:         }
3449: }
3450: /* ---------------------------       */
3451: 
3452: getuid()
3453: {
3454: 
3455:         u.u_ar0[R0].lobyte = u.u_ruid;
3456:         u.u_ar0[R0].hibyte = u.u_uid;
3457: }
3458: /* ---------------------------       */
3459: 
3460: setgid()
3461: {
3462:         register gid;
3463: 
3464:         gid = u.u_ar0[R0].lobyte;
3465:         if(u.u_rgid == gid.lobyte || suser()) {
3466:                 u.u_gid = gid;
3467:                 u.u_rgid = gid;
3468:         }
3469: }
3470: /* ---------------------------       */
3471: 
3472: getgid()
3473: {
3474: 
3475:         u.u_ar0[R0].lobyte = u.u_rgid;
3476:         u.u_ar0[R0].hibyte = u.u_gid;
3477: }
3478: /* ---------------------------       */
3479: 
3480: getpid()
3481: {
3482:         u.u_ar0[R0] = u.u_procp->p_pid;
3483: }
3484: /* ---------------------------       */
3485: 
3486: sync()
3487: {
3488: 
3489:         update();
3490: }
3491: /* ---------------------------       */
3492: 
3493: nice()
3494: {
3495:         register n;
3496: 
3497:         n = u.u_ar0[R0];
3498:         if(n > 20)
3499:                 n = 20;
3500:         if(n < 0 && !suser())
3501:                 n = 0;
3502:         u.u_procp->p_nice = n;
3503: }
3504: /* ---------------------------       */
3505: 
3506: /*
3507:  * Unlink system call.
3508:  * panic: unlink -- "cannot happen"
3509:  */
3510: unlink()
3511: {
3512:         register *ip, *pp;
3513:         extern uchar;
3514: 
3515:         pp = namei(&uchar, 2);
3516:         if(pp == NULL)
3517:                 return;
3518:         prele(pp);
3519:         ip = iget(pp->i_dev, u.u_dent.u_ino);
3520:         if(ip == NULL)
3521:                 panic("unlink -- iget");
3522:         if((ip->i_mode&IFMT)==IFDIR && !suser())
3523:                 goto out;
3524:         u.u_offset[1] =- DIRSIZ+2;
3525:         u.u_base = &u.u_dent;
3526:         u.u_count = DIRSIZ+2;
3527:         u.u_dent.u_ino = 0;
3528:         writei(pp);
3529:         ip->i_nlink--;
3530:         ip->i_flag =| IUPD;
3531: 
3532: out:
3533:         iput(pp);
3534:         iput(ip);
3535: }
3536: /* ---------------------------       */
3537: 
3538: chdir()
3539: {
3540:         register *ip;
3541:         extern uchar;
3542: 
3543:         ip = namei(&uchar, 0);
3544:         if(ip == NULL)
3545:                 return;
3546:         if((ip->i_mode&IFMT) != IFDIR) {
3547:                 u.u_error = ENOTDIR;
3548:         bad:
3549:                 iput(ip);
3550:                 return;
3551:         }
3552:         if(access(ip, IEXEC))
3553:                 goto bad;
3554:         iput(u.u_cdir);
3555:         u.u_cdir = ip;
3556:         prele(ip);
3557: }
3558: /* ---------------------------       */
3559: 
3560: chmod()
3561: {
3562:         register *ip;
3563: 
3564:         if ((ip = owner()) == NULL)
3565:                 return;
3566:         ip->i_mode =& ~07777;
3567:         if (u.u_uid)
3568:                 u.u_arg[1] =& ~ISVTX;
3569:         ip->i_mode =| u.u_arg[1]&07777;
3570:         ip->i_flag =| IUPD;
3571:         iput(ip);
3572: }
3573: /* ---------------------------       */
3574: 
3575: chown()
3576: {
3577:         register *ip;
3578: 
3579:         if (!suser() || (ip = owner()) == NULL)
3580:                 return;
3581:         ip->i_uid = u.u_arg[1].lobyte;
3582:         ip->i_gid = u.u_arg[1].hibyte;
3583:         ip->i_flag =| IUPD;
3584:         iput(ip);
3585: }
3586: /* ---------------------------       */
3587: 
3588: /*
3589:  * Change modified date of file:
3590:  * time to r0-r1; sys smdate; file
3591:  * This call has been withdrawn because it messes up
3592:  * incremental dumps (pseudo-old files aren't dumped).
3593:  * It works though and you can uncomment it if you like.
3594: 
3595: smdate()
3596: {
3597:         register struct inode *ip;
3598:         register int *tp;
3599:         int tbuf[2];
3600: 
3601:         if ((ip = owner()) == NULL)
3602:                 return;
3603:         ip->i_flag =| IUPD;
3604:         tp = &tbuf[2];
3605:         *--tp = u.u_ar0[R1];
3606:         *--tp = u.u_ar0[R0];
3607:         iupdat(ip, tp);
3608:         ip->i_flag =& ~IUPD;
3609:         iput(ip);
3610: }
3611: */
3612: /* ---------------------------       */
3613: 
3614: ssig()
3615: {
3616:         register a;
3617: 
3618:         a = u.u_arg[0];
3619:         if(a<=0 || a>=NSIG || a ==SIGKIL) {
3620:                 u.u_error = EINVAL;
3621:                 return;
3622:         }
3623:         u.u_ar0[R0] = u.u_signal[a];
3624:         u.u_signal[a] = u.u_arg[1];
3625:         if(u.u_procp->p_sig == a)
3626:                 u.u_procp->p_sig = 0;
3627: }
3628: /* ---------------------------       */
3629: 
3630: kill()
3631: {
3632:         register struct proc *p, *q;
3633:         register a;
3634:         int f;
3635: 
3636:         f = 0;
3637:         a = u.u_ar0[R0];
3638:         q = u.u_procp;
3639:         for(p = &proc[0]; p < &proc[NPROC]; p++) {
3640:                 if(p == q)
3641:                         continue;
3642:                 if(a != 0 && p->p_pid != a)
3643:                         continue;
3644:                 if(a == 0 && (p->p_ttyp != q->p_ttyp || p <= &proc[1]))
3645:                         continue;
3646:                 if(u.u_uid != 0 && u.u_uid != p->p_uid)
3647:                         continue;
3648:                 f++;
3649:                 psignal(p, u.u_arg[0]);
3650:         }
3651:         if(f == 0)
3652:                 u.u_error = ESRCH;
3653: }
3654: /* ---------------------------       */
3655: 
3656: times()
3657: {
3658:         register *p;
3659: 
3660:         for(p = &u.u_utime; p  < &u.u_utime+6;) {
3661:                 suword(u.u_arg[0], *p++);
3662:                 u.u_arg[0] =+ 2;
3663:         }
3664: }
3665: /* ---------------------------       */
3666: 
3667: profil()
3668: {
3669: 
3670:         u.u_prof[0] = u.u_arg[0] & ~1;  /* base of sample buf */
3671:         u.u_prof[1] = u.u_arg[1];       /* size of same */
3672:         u.u_prof[2] = u.u_arg[2];       /* pc offset */
3673:         u.u_prof[3] = (u.u_arg[3]>>1) & 077777; /* pc scale */
3674: }
3675: /* ---------------------------       */