|
|
1.1 root 1: /*
2:
3: Copyright 1990,1991,1992 Eric R. Smith. All rights reserved.
4:
5: */
6:
7:
8:
9: /* miscellaneous DOS functions, and the DOS initialization function */
10:
11:
12:
13: #include "mint.h"
14:
15:
16:
17: #define DOS_MAX 0x140
18:
19:
20:
21: Func dos_tab[DOS_MAX];
22:
23: short dos_max = DOS_MAX;
24:
25:
26:
27: static void alarmme P_((PROC *));
28:
29:
30:
1.1.1.2 ! root 31: long ARGS_ON_STACK
1.1 root 32:
33: s_version()
34:
35: {
36:
37: return Sversion();
38:
39: }
40:
41:
42:
43: /*
44:
45: * Super(new_ssp): change to supervisor mode.
46:
47: */
48:
49:
50:
1.1.1.2 ! root 51: long ARGS_ON_STACK
1.1 root 52:
53: s_uper(new_ssp)
54:
55: long new_ssp;
56:
57: {
58:
59: int in_super;
60:
61: long r;
62:
63:
64:
1.1.1.2 ! root 65: TRACE(("Super"));
1.1 root 66:
67: in_super = curproc->ctxt[SYSCALL].sr & 0x2000;
68:
69:
70:
71: if (new_ssp == 1) {
72:
73: r = in_super ? -1L : 0;
74:
75: }
76:
77: else {
78:
79: curproc->ctxt[SYSCALL].sr ^= 0x2000;
80:
81: r = curproc->ctxt[SYSCALL].ssp;
82:
83: if (in_super) {
84:
85: if (new_ssp == 0) {
86:
1.1.1.2 ! root 87: DEBUG(("bad Super call"));
1.1 root 88:
89: raise(SIGSYS);
90:
91: }
92:
93: else {
94:
95: curproc->ctxt[SYSCALL].usp =
96:
97: curproc->ctxt[SYSCALL].ssp;
98:
99: curproc->ctxt[SYSCALL].ssp = new_ssp;
100:
101: }
102:
103: }
104:
105: else {
106:
107: curproc->ctxt[SYSCALL].ssp =
108:
109: new_ssp ? new_ssp : curproc->ctxt[SYSCALL].usp;
110:
111: }
112:
113: }
114:
115: return r;
116:
117: }
118:
119:
120:
121: /*
122:
123: * get/set time and date functions
124:
125: */
126:
1.1.1.2 ! root 127: long ARGS_ON_STACK t_getdate() { return datestamp; }
1.1 root 128:
1.1.1.2 ! root 129: long ARGS_ON_STACK t_gettime() { return timestamp; }
1.1 root 130:
131:
132:
1.1.1.2 ! root 133: long ARGS_ON_STACK t_setdate(date)
1.1 root 134:
135: int date;
136:
137: {
138:
139: long r = Tsetdate(date);
140:
141: datestamp = Tgetdate();
142:
143: return r;
144:
145: }
146:
147:
148:
1.1.1.2 ! root 149: long ARGS_ON_STACK t_settime(time)
1.1 root 150:
151: int time;
152:
153: {
154:
155: long r = Tsettime(time);
156:
157: timestamp = Tgettime();
158:
159: return r;
160:
161: }
162:
163:
164:
165: /*
166:
167: * GEMDOS extension: Syield(): give up the processor if any other
168:
169: * processes are waiting. Always returns 0.
170:
171: */
172:
173:
174:
1.1.1.2 ! root 175: long ARGS_ON_STACK
1.1 root 176:
177: s_yield()
178:
179: {
180:
181: /* reward the nice process */
182:
183: curproc->curpri = curproc->pri;
184:
185: sleep(READY_Q, curproc->wait_cond);
186:
187: return 0;
188:
189: }
190:
191:
192:
193: /*
194:
195: * GEMDOS extension:
196:
197: * Prenice(pid, delta) sets the process priority level for process pid.
198:
199: * A "nice" value < 0 increases priority, one > 0 decreases it.
200:
201: * Always returns the new priority (so Prenice(pid, 0) queries the current
202:
203: * priority).
204:
205: *
206:
207: * NOTE: for backward compatibility, Pnice(delta) is provided and is equivalent
208:
209: * to Prenice(Pgetpid(), delta)
210:
211: */
212:
213:
214:
1.1.1.2 ! root 215: long ARGS_ON_STACK
1.1 root 216:
217: p_renice(pid, delta)
218:
219: int pid, delta;
220:
221: {
222:
223: PROC *p;
224:
225:
226:
1.1.1.2 ! root 227: if (pid <= 0 || 0 == (p = pid2proc(pid))) {
1.1 root 228:
229: return EFILNF;
230:
231: }
232:
233:
234:
235: if (curproc->euid && curproc->euid != p->ruid
236:
237: && curproc->ruid != p->ruid) {
238:
1.1.1.2 ! root 239: DEBUG(("Prenice: process ownership error"));
1.1 root 240:
241: return EACCDN;
242:
243: }
244:
245: p->pri -= delta;
246:
247: if (p->pri < MIN_NICE) p->pri = MIN_NICE;
248:
249: if (p->pri > MAX_NICE) p->pri = MAX_NICE;
250:
251: p->curpri = p->pri;
252:
253: return ((long)p->pri) & 0x0ffff;
254:
255: }
256:
257:
258:
1.1.1.2 ! root 259: long ARGS_ON_STACK
1.1 root 260:
261: p_nice(delta)
262:
263: int delta;
264:
265: {
266:
267: return p_renice(curproc->pid,delta);
268:
269: }
270:
271:
272:
273: /*
274:
275: * GEMDOS extensions: routines for getting/setting process i.d.'s and
276:
277: * user i.d.'s
278:
279: */
280:
281:
282:
1.1.1.2 ! root 283: long ARGS_ON_STACK p_getpid() { return curproc->pid; }
1.1 root 284:
285:
286:
1.1.1.2 ! root 287: long ARGS_ON_STACK p_getppid() { return curproc->ppid; }
1.1 root 288:
289:
290:
1.1.1.2 ! root 291: long ARGS_ON_STACK p_getpgrp() { return curproc->pgrp; }
1.1 root 292:
293:
294:
295: /* note: Psetpgrp(0, ...) is equivalent to Psetpgrp(Pgetpid(), ...) */
296:
297: /* also note: Psetpgrp(x, 0) is equivalent to Psetpgrp(x, x) */
298:
299:
300:
1.1.1.2 ! root 301: long ARGS_ON_STACK p_setpgrp(pid, newgrp)
1.1 root 302:
303: int pid, newgrp;
304:
305: {
306:
307: PROC *p;
308:
309:
310:
311: if (pid == 0)
312:
313: p = curproc;
314:
1.1.1.2 ! root 315: else if (0 == (p = pid2proc(pid)))
1.1 root 316:
317: return EFILNF;
318:
319: if ( (curproc->euid) && (p->ruid != curproc->ruid)
320:
321: && (p->ppid != curproc->pid) )
322:
323: return EACCDN;
324:
325:
326:
327: if (newgrp == 0)
328:
329: newgrp = p->pid;
330:
331:
332:
333: return (p->pgrp = newgrp);
334:
335: }
336:
337:
338:
1.1.1.2 ! root 339: long ARGS_ON_STACK p_getuid() { return curproc->ruid; }
1.1 root 340:
1.1.1.2 ! root 341: long ARGS_ON_STACK p_getgid() { return curproc->rgid; }
1.1 root 342:
1.1.1.2 ! root 343: long ARGS_ON_STACK p_geteuid() { return curproc->euid; }
1.1 root 344:
1.1.1.2 ! root 345: long ARGS_ON_STACK p_getegid() { return curproc->egid; }
1.1 root 346:
347:
348:
1.1.1.2 ! root 349: long ARGS_ON_STACK
1.1 root 350:
351: p_setuid(id)
352:
353: int id;
354:
355: {
356:
1.1.1.2 ! root 357: if (curproc->euid == 0 || curproc->ruid == id) {
1.1 root 358:
359: curproc->ruid = curproc->euid = id;
360:
361: return id;
362:
363: }
364:
365: return EACCDN;
366:
367: }
368:
369:
370:
1.1.1.2 ! root 371: long ARGS_ON_STACK
1.1 root 372:
373: p_setgid(id)
374:
375: int id;
376:
377: {
378:
1.1.1.2 ! root 379: if (curproc->euid == 0 || curproc->egid == 0 || curproc->rgid == id) {
1.1 root 380:
381: curproc->egid = curproc->rgid = id;
382:
383: return id;
384:
385: }
386:
387: return EACCDN;
388:
389: }
390:
391:
392:
393: /*
394:
395: * a way to get/set process-specific user information. the user information
396:
397: * longword is set to "arg", unless arg is -1. In any case, the old
398:
399: * value of the longword is returned.
400:
401: */
402:
403:
404:
1.1.1.2 ! root 405: long ARGS_ON_STACK
1.1 root 406:
407: p_usrval(arg)
408:
409: long arg;
410:
411: {
412:
413: long r;
414:
415:
416:
1.1.1.2 ! root 417: TRACE(("Pusrval"));
1.1 root 418:
419: r = curproc->usrdata;
420:
421: if (arg != -1L)
422:
423: curproc->usrdata = arg;
424:
425: return r;
426:
427: }
428:
429:
430:
431: /*
432:
433: * set the file creation mask to "mode". Returns the old value of the
434:
435: * mask.
436:
437: */
438:
1.1.1.2 ! root 439: long ARGS_ON_STACK p_umask(mode)
1.1 root 440:
441: unsigned mode;
442:
443: {
444:
445: long oldmask = curproc->umask;
446:
447:
448:
449: curproc->umask = mode & (~S_IFMT);
450:
451: return oldmask;
452:
453: }
454:
455:
456:
457: /*
458:
459: * get/set the domain of a process. domain 0 is the default (TOS) domain.
460:
461: * domain 1 is the MiNT domain. for now, domain affects read/write system
462:
463: * calls and filename translation.
464:
465: */
466:
467:
468:
1.1.1.2 ! root 469: long ARGS_ON_STACK
1.1 root 470:
471: p_domain(arg)
472:
473: int arg;
474:
475: {
476:
477: long r;
478:
1.1.1.2 ! root 479: TRACE(("Pdomain(%d)", arg));
1.1 root 480:
481:
482:
483: r = curproc->domain;
484:
485: if (arg >= 0)
486:
487: curproc->domain = arg;
488:
489: return r;
490:
491: }
492:
493:
494:
495: /*
496:
497: * get process resource usage. 8 longwords are returned, as follows:
498:
499: * r[0] == system time used by process
500:
501: * r[1] == user time used by process
502:
503: * r[2] == system time used by process' children
504:
505: * r[3] == user time used by process' children
506:
507: * r[4] == memory used by process
508:
509: * r[5] - r[7]: reserved for future use
510:
511: */
512:
513:
514:
1.1.1.2 ! root 515: long ARGS_ON_STACK
1.1 root 516:
517: p_rusage(r)
518:
519: long *r;
520:
521: {
522:
523: r[0] = curproc->systime;
524:
525: r[1] = curproc->usrtime;
526:
527: r[2] = curproc->chldstime;
528:
529: r[3] = curproc->chldutime;
530:
531: r[4] = memused(curproc);
532:
533: return 0;
534:
535: }
536:
537:
538:
539: /*
540:
541: * get/set resource limits i to value v. The old limit is always returned;
542:
543: * if v == -1, the limit is unchanged, otherwise it is set to v. Possible
544:
545: * values for i are:
546:
547: * 1: max. cpu time (milliseconds)
548:
549: * 2: max. core memory allowed
550:
551: * 3: max. amount of malloc'd memory allowed
552:
553: */
554:
1.1.1.2 ! root 555: long ARGS_ON_STACK
1.1 root 556:
557: p_setlimit(i, v)
558:
559: int i;
560:
561: long v;
562:
563: {
564:
565: long oldlimit;
566:
567:
568:
569: switch(i) {
570:
571: case 1:
572:
573: oldlimit = curproc->maxcpu;
574:
575: if (v >= 0) curproc->maxcpu = v;
576:
577: break;
578:
579: case 2:
580:
581: oldlimit = curproc->maxcore;
582:
583: if (v >= 0) {
584:
585: curproc->maxcore = v;
586:
587: recalc_maxmem(curproc);
588:
589: }
590:
591: break;
592:
593: case 3:
594:
595: oldlimit = curproc->maxdata;
596:
597: if (v >= 0) {
598:
599: curproc->maxdata = v;
600:
601: recalc_maxmem(curproc);
602:
603: }
604:
605: break;
606:
607: default:
608:
1.1.1.2 ! root 609: DEBUG(("Psetlimit: invalid mode %d", i));
1.1 root 610:
611: return EINVFN;
612:
613: }
614:
1.1.1.2 ! root 615: TRACE(("p_setlimit(%d, %ld): oldlimit = %ld", i, v, oldlimit));
1.1 root 616:
617: return oldlimit;
618:
619: }
620:
621:
622:
623: /*
624:
625: * pause: just sleeps on IO_Q, with wait_cond == -1. only a signal will
626:
627: * wake us up
628:
629: */
630:
631:
632:
1.1.1.2 ! root 633: long ARGS_ON_STACK
1.1 root 634:
635: p_pause()
636:
637: {
638:
1.1.1.2 ! root 639: TRACE(("Pause"));
! 640:
1.1 root 641: sleep(IO_Q, -1L);
642:
643: return 0;
644:
645: }
646:
647:
648:
649: /*
650:
651: * helper function for t_alarm: this will be called when the timer goes
652:
653: * off, and raises SIGALRM
654:
655: */
656:
657:
658:
659: static void
660:
661: alarmme(p)
662:
663: PROC *p;
664:
665: {
666:
667: p->alarmtim = 0;
668:
669: post_sig(p, SIGALRM);
670:
671: }
672:
673:
674:
675: /*
676:
677: * t_alarm(x): set the alarm clock to go off in "x" seconds. returns the
678:
679: * old value of the alarm clock
680:
681: */
682:
683:
684:
1.1.1.2 ! root 685: long ARGS_ON_STACK
1.1 root 686:
687: t_alarm(x)
688:
689: long x;
690:
691: {
692:
693: long oldalarm;
694:
695: TIMEOUT *t;
696:
697:
698:
699: /* see how many milliseconds there were to the alarm timeout */
700:
701: oldalarm = 0;
702:
703:
704:
705: if (curproc->alarmtim) {
706:
707: for (t = tlist; t; t = t->next) {
708:
709: oldalarm += t->when;
710:
711: if (t == curproc->alarmtim)
712:
713: goto foundalarm;
714:
715: }
716:
1.1.1.2 ! root 717: DEBUG(("Talarm: old alarm not found!"));
1.1 root 718:
719: oldalarm = 0;
720:
721: curproc->alarmtim = 0;
722:
723: foundalarm:
724:
725: ;
726:
727: }
728:
729:
730:
731: oldalarm = (oldalarm+999) / 1000; /* convert to seconds */
732:
733:
734:
735: /* we were just querying the alarm */
736:
737: if (x < 0)
738:
739: return oldalarm;
740:
741:
742:
743: /* cancel old alarm */
744:
745: if (curproc->alarmtim)
746:
747: canceltimeout(curproc->alarmtim);
748:
749:
750:
751: /* add a new alarm, to occur in 1000*x milliseconds */
752:
753: if (x)
754:
755: curproc->alarmtim = addtimeout(1000*x, alarmme);
756:
757: else
758:
759: curproc->alarmtim = 0;
760:
761:
762:
763: return oldalarm;
764:
765: }
766:
767:
768:
769: /*
770:
771: * sysconf(which): returns information about system configuration.
772:
773: * "which" specifies which aspect of the system configuration is to
774:
775: * be returned:
776:
777: * -1 max. value of "which" allowed
778:
779: * 0 max. number of memory regions per proc
780:
781: * 1 max. length of Pexec() execution string {ARG_MAX}
782:
783: * 2 max. number of open files per process {OPEN_MAX}
784:
785: * 3 number of supplementary group id's {currently 0}
786:
787: * 4 max. number of processes per uid {CHILD_MAX}
788:
789: *
790:
791: * unlimited values (e.g. CHILD_MAX) are returned as 0x7fffffffL
792:
793: *
794:
795: * See also Dpathconf() in dosdir.c.
796:
797: */
798:
799:
800:
1.1.1.2 ! root 801: long ARGS_ON_STACK
1.1 root 802:
803: s_ysconf(which)
804:
805: int which;
806:
807: {
808:
809: if (which == -1)
810:
811: return 4;
812:
813:
814:
815: switch(which) {
816:
817: case 0:
818:
819: return UNLIMITED;
820:
821: case 1:
822:
823: return 126;
824:
825: case 2:
826:
827: return MAX_OPEN;
828:
829: case 3:
830:
831: return 0;
832:
833: case 4:
834:
835: return UNLIMITED;
836:
837: default:
838:
839: return EINVFN;
840:
841: }
842:
843: }
844:
845:
846:
847: /*
848:
849: * routine for initializing DOS
850:
851: *
852:
853: * NOTE: before adding new functions, check the definition of
854:
855: * DOS_MAX at the top of this file to make sure that there
856:
857: * is room; if not, increase DOS_MAX.
858:
859: */
860:
861:
862:
863: void
864:
865: init_dos()
866:
867: {
868:
869: /* miscellaneous initialization goes here */
870:
871: timestamp = Tgettime();
872:
873: datestamp = Tgetdate();
874:
875:
876:
877: /* dos table initialization */
878:
879: dos_tab[0x00] = p_term0;
880:
881: dos_tab[0x01] = c_conin;
882:
883: dos_tab[0x02] = c_conout;
884:
885: dos_tab[0x03] = c_auxin;
886:
887: dos_tab[0x04] = c_auxout;
888:
889: dos_tab[0x05] = c_prnout;
890:
891: dos_tab[0x06] = c_rawio;
892:
893: dos_tab[0x07] = c_rawcin;
894:
895: dos_tab[0x08] = c_necin;
896:
897: dos_tab[0x09] = c_conws;
898:
899: dos_tab[0x0a] = c_conrs;
900:
901: dos_tab[0x0b] = c_conis;
902:
903: dos_tab[0x0e] = d_setdrv;
904:
905: dos_tab[0x10] = c_conos;
906:
907: dos_tab[0x11] = c_prnos;
908:
909: dos_tab[0x12] = c_auxis;
910:
911: dos_tab[0x13] = c_auxos;
912:
913: dos_tab[0x14] = m_addalt;
914:
915: dos_tab[0x19] = d_getdrv;
916:
917: dos_tab[0x1a] = f_setdta;
918:
919: dos_tab[0x20] = s_uper;
920:
921: dos_tab[0x2a] = t_getdate;
922:
923: dos_tab[0x2b] = t_setdate;
924:
925: dos_tab[0x2c] = t_gettime;
926:
927: dos_tab[0x2d] = t_settime;
928:
929: dos_tab[0x2f] = f_getdta;
930:
931: dos_tab[0x30] = s_version;
932:
933: dos_tab[0x31] = p_termres;
934:
935: dos_tab[0x36] = d_free;
936:
937: dos_tab[0x39] = d_create;
938:
939: dos_tab[0x3a] = d_delete;
940:
941: dos_tab[0x3b] = d_setpath;
942:
943: dos_tab[0x3c] = f_create;
944:
945: dos_tab[0x3d] = f_open;
946:
947: dos_tab[0x3e] = f_close;
948:
949: dos_tab[0x3f] = f_read;
950:
951: dos_tab[0x40] = f_write;
952:
953: dos_tab[0x41] = f_delete;
954:
955: dos_tab[0x42] = f_seek;
956:
957: dos_tab[0x43] = f_attrib;
958:
959: dos_tab[0x44] = m_xalloc;
960:
961: dos_tab[0x45] = f_dup;
962:
963: dos_tab[0x46] = f_force;
964:
965: dos_tab[0x47] = d_getpath;
966:
967: dos_tab[0x48] = m_alloc;
968:
969: dos_tab[0x49] = m_free;
970:
971: dos_tab[0x4a] = m_shrink;
972:
973: dos_tab[0x4b] = p_exec;
974:
975: dos_tab[0x4c] = p_term;
976:
977: dos_tab[0x4e] = f_sfirst;
978:
979: dos_tab[0x4f] = f_snext;
980:
981: dos_tab[0x56] = f_rename;
982:
983: dos_tab[0x57] = f_datime;
984:
985: dos_tab[0x5c] = f_lock;
986:
987:
988:
989: /* MiNT extensions to GEMDOS */
990:
991:
992:
993: dos_tab[0xff] = s_yield;
994:
995: dos_tab[0x100] = f_pipe;
996:
997: dos_tab[0x104] = f_cntl;
998:
1.1.1.2 ! root 999: dos_tab[0x105] = f_instat;
1.1 root 1000:
1.1.1.2 ! root 1001: dos_tab[0x106] = f_outstat;
1.1 root 1002:
1.1.1.2 ! root 1003: dos_tab[0x107] = f_getchar;
1.1 root 1004:
1.1.1.2 ! root 1005: dos_tab[0x108] = f_putchar;
1.1 root 1006:
1007: dos_tab[0x109] = p_wait;
1008:
1009: dos_tab[0x10a] = p_nice;
1010:
1011: dos_tab[0x10b] = p_getpid;
1012:
1013: dos_tab[0x10c] = p_getppid;
1014:
1015: dos_tab[0x10d] = p_getpgrp;
1016:
1017: dos_tab[0x10e] = p_setpgrp;
1018:
1019: dos_tab[0x10f] = p_getuid;
1020:
1021: dos_tab[0x110] = p_setuid;
1022:
1023: dos_tab[0x111] = p_kill;
1024:
1025: dos_tab[0x112] = p_signal;
1026:
1027: dos_tab[0x113] = p_vfork;
1028:
1029: dos_tab[0x114] = p_getgid;
1030:
1031: dos_tab[0x115] = p_setgid;
1032:
1033: dos_tab[0x116] = p_sigblock;
1034:
1035: dos_tab[0x117] = p_sigsetmask;
1036:
1037: dos_tab[0x118] = p_usrval;
1038:
1039: dos_tab[0x119] = p_domain;
1040:
1041: dos_tab[0x11a] = p_sigreturn;
1042:
1043: dos_tab[0x11b] = p_fork;
1044:
1045: dos_tab[0x11c] = p_wait3;
1046:
1047: dos_tab[0x11d] = f_select;
1048:
1049: dos_tab[0x11e] = p_rusage;
1050:
1051: dos_tab[0x11f] = p_setlimit;
1052:
1053: dos_tab[0x120] = t_alarm;
1054:
1055: dos_tab[0x121] = p_pause;
1056:
1057: dos_tab[0x122] = s_ysconf;
1058:
1059: dos_tab[0x123] = p_sigpending;
1060:
1061: dos_tab[0x124] = d_pathconf;
1062:
1063: dos_tab[0x125] = p_msg;
1064:
1065: dos_tab[0x126] = f_midipipe;
1066:
1067: dos_tab[0x127] = p_renice;
1068:
1069: dos_tab[0x128] = d_opendir;
1070:
1071: dos_tab[0x129] = d_readdir;
1072:
1073: dos_tab[0x12a] = d_rewind;
1074:
1075: dos_tab[0x12b] = d_closedir;
1076:
1077: dos_tab[0x12c] = f_xattr;
1078:
1079: dos_tab[0x12d] = f_link;
1080:
1081: dos_tab[0x12e] = f_symlink;
1082:
1083: dos_tab[0x12f] = f_readlink;
1084:
1085: dos_tab[0x130] = d_cntl;
1086:
1087: dos_tab[0x131] = f_chown;
1088:
1089: dos_tab[0x132] = f_chmod;
1090:
1091: dos_tab[0x133] = p_umask;
1092:
1093: dos_tab[0x134] = p_semaphore;
1094:
1095: dos_tab[0x135] = d_lock;
1096:
1097: dos_tab[0x136] = p_sigpause;
1098:
1099: dos_tab[0x137] = p_sigaction;
1100:
1101: dos_tab[0x138] = p_geteuid;
1102:
1103: dos_tab[0x139] = p_getegid;
1104:
1.1.1.2 ! root 1105: dos_tab[0x13a] = p_waitpid;
! 1106:
! 1107: dos_tab[0x13b] = d_getcwd;
! 1108:
1.1 root 1109: }
1110:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.