-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsysc.c
99 lines (80 loc) · 2.26 KB
/
sysc.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include "drv.h"
#include "sysc.h"
extern int verbose;
/* internal syscall arg parsing state */
#define NSLICES 7
#define STKSZ 256
struct parseState {
struct sysRec *calls;
int ncalls;
struct slice slices[NSLICES];
size_t nslices;
};
static int parseArg(struct slice *b, struct parseState *st, u_int32_t *x);
// For the arguments of the ioctl
int parseSysRec(struct slice *b)
{
struct slice slices[7];
int i,nslices;
// chop input into several slices
if(getDelimSlices(b, BUFDELIM, sizeof BUFDELIM-1, NSLICES, slices, &nslices) == -1 || nslices < 1)
return -1;
b = &slices[0];
return 0;
}
// For sequencies of ioctls
// If called with the CALLDELIM then we get the sequencies of ioctls
// If called with th BUFDELIM we get the command number and its data argument
int parseSysRecArr(struct slice *b, int delim, int maxRecs, int *nRecs, struct slice *slices)
{
size_t i, nslices;
if (maxRecs > 7)
maxRecs = 7;
if (delim == 1){
if(getDelimSlices(b, CALLDELIM, sizeof(CALLDELIM)-1, maxRecs ,slices, &nslices) == -1)
return -1;
}
else if (delim == 2){
if(getDelimSlices(b, BUFDELIM, sizeof(BUFDELIM)-1, maxRecs ,slices, &nslices) == -1)
return -1;
}
*nRecs = nslices;
//printf("Code = %u and contents %s\n",*slices[0].cur,slices[1].cur);
return 0;
}
void
showSysRec(struct sysRec *x)
{
printf("syscall %d (%lx, %lx, %lx, %lx, %lx, %lx)\n", x->nr, (u_long)x->args[0], (u_long)x->args[1], (u_long)x->args[2], (u_long)x->args[3], (u_long)x->args[4], (u_long)x->args[5]);
}
void
showSysRecArr(struct sysRec *x, int n)
{
int i;
for(i = 0; i < n; i++)
showSysRec(x + i);
}
unsigned long
doSysRec(struct sysRec *x)
{
/* XXX consider doing this in asm so we can use the real syscall entry instead of the syscall() function entry */
return syscall(x->nr, x->args[0], x->args[1], x->args[2], x->args[3], x->args[4], x->args[5]);
}
unsigned long
doSysRecArr(struct sysRec *x, int n)
{
unsigned long ret;
int i;
ret = 0;
for(i = 0; i < n; i++)
ret = doSysRec(x + i);
return ret;
}