-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.c
143 lines (124 loc) · 2.64 KB
/
system.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Copyright (c) 1992-1993 The Regents of the University of California.
All rights reserved. See copyright.h for copyright notice and limitation
of liability and disclaimer of warranty provisions.
*/
#include "copyright.h"
#include <stdio.h>
#include <syscall.h>
#include "int.h"
extern int Reg[];
extern char mem[];
extern int Traptrace;
char *u_to_int_addr();
/* handle system calls */
system_break()
{
if ( Traptrace )
printf("**breakpoint ");
system_trap();
}
system_trap()
{
int o0, o1, o2; /* user out register values */
int syscallno;
extern long lseek();
if ( Traptrace )
{
printf("**System call %d\n", Reg[2]);
dump_reg();
}
/* if (Reg[1] == 0)
/* { /* SYS_indir */
/* syscallno = Reg[8]; /* out reg 0 */
/* o0 = Reg[9];
/* o1 = Reg[10];
/* o2 = Reg[11];
/* }
/* else /* */
{
syscallno = Reg[2];
o0 = Reg[4];
o1 = Reg[5];
o2 = Reg[6];
}
switch (syscallno)
{
case SYS_exit: /*1*/
printstatistics();
fflush(stdout);
exit(0);
break;
case SYS_read: /*3*/
Reg[1] =
read(u_to_int_fd(o0), u_to_int_addr(o1), o2);
break;
case SYS_write: /*4*/
Reg[1] =
write(u_to_int_fd(o0), u_to_int_addr(o1), o2);
break;
case SYS_open: /*5*/
Reg[1] = open(u_to_int_addr(o0), o1, o2); /* */
break;
case SYS_close: /*6*/
Reg[1] = 0; /* hack */
break;
case 17: /* 17 */
/* old sbreak. where did it go? */
Reg[1] = ((o0 / 8192) + 1) * 8192;
break;
case SYS_lseek: /*19*/
Reg[1] = (int) lseek(u_to_int_fd(o0), (long) o1, o2);
break;
case SYS_ioctl:/* 54 */
{ /* copied from sas -- I don't understand yet. */
/* see dave weaver */
#define IOCPARM_MASK 0x7f /* parameters must be < 128 bytes */
int size = (o1 >> 16) & IOCPARM_MASK;
char ioctl_group = (o1 >> 8) & 0x00ff;
if ((ioctl_group == 't') && (size == 8))
{
size = 6;
o1 = (o1 & ~((IOCPARM_MASK << 16)))
| (size << 16);
}
}
Reg[1] = ioctl(u_to_int_fd(o0),o1,u_to_int_addr(o2));
Reg[1] = 0; /* hack */
break;
case SYS_fstat: /* 62 */
Reg[1] = fstat(o1, o2);
break;
case SYS_getpagesize: /* 64 */
Reg[1] = getpagesize();
break;
default:
printf("Unknown System call %d\n", syscallno);
if ( ! Traptrace )
dump_reg();
exit(2);
break;
}
if ( Traptrace )
{
printf("**Afterwards:\n");
dump_reg();
}
}
char *u_to_int_addr(ptr)
int ptr;
{ /* convert a user pointer to the real address */
/* used in the interpreter */
return ((char *) ((int) mem - memoffset + ptr));
}
u_to_int_fd(fd)
{
if (fd > 2)
{
/*
printf("No general file descriptors yet\n");
exit(2);
*/
}
return (fd); /* assume we can handle it for now */
}