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