Repository navigation
Expand file tree
/
Copy pathsystest.c
More file actions
123 lines (100 loc) · 2.48 KB
/
Copy pathsystest.c
File metadata and controls
123 lines (100 loc) · 2.48 KB
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
/*
* systest.c -- Test code for nooks system calls
*
* Copyright (C) 2002 Mike Swift
*
* The source code in this file can be freely used, adapted,
* and redistributed in source or binary form, so long as an
* acknowledgment appears in derived source files.
* No warranty is attached;
* we cannot take responsibility for errors or fitness for use.
*
*/
#include <sys/types.h>
#include <stdlib.h>
#include <stdio.h>
#if 0
#include <asm/unistd.h>
#endif
#include <string.h>
#include <errno.h>
#define swifi_inject_fault sys_inject_fault
#include "swifi-user.h"
#include "extra.h"
#if 0
_syscall6(long, swifi_inject_fault,
char *, module_name,
unsigned long, faultType,
unsigned long, randSeed,
unsigned long, numFaults,
void *, result,
unsigned long, do_inject);
#endif
int
main(int argc, char * argv[])
{
char * module_name = NULL;
int i;
long result = 0;
unsigned int cmd = 0;
unsigned long arg = 0;
unsigned long seed = 157;
swifi_result_t * res = NULL;
if (argc < 2) {
goto Usage;
}
for (i = 1; i < argc; i++ ) {
if (strcmp(argv[i], "-f") == 0) {
if (argc <= i+5) {
goto Usage;
}
module_name = victim_exe = argv[++i];
sscanf(argv[++i],"%u", &victim_pid);
sscanf(argv[++i],"%u", &cmd);
sscanf(argv[++i],"%lu", &arg);
sscanf(argv[++i],"%lu", &seed);
} else {
printf("Unknown command %s\n", argv[i]);
goto Usage;
}
}
res = malloc(arg * sizeof(swifi_result_t));
if (res == NULL) {
printf("Out of memory\n");
goto Cleanup;
}
memset(res, 0, sizeof(res));
/*
// Find out where the faults will be injected
*/
result = swifi_inject_fault(module_name,
cmd, /* fault type */
seed, /* random seed */
arg, /* numFaults */
res,
0); /* don't inject now */
for (i = 0; (i < arg) && (res[i].address != 0) ; i++) {
printf("Changed 0x%lx from 0x%lx to 0x%lx\n",
res[i].address,
res[i].old,
res[i].new);
}
/*
// do the injection
*/
result = swifi_inject_fault(module_name,
cmd, /* fault type */
seed, /* random seed */
arg, /* numFaults */
res,
1); /* do inject now */
printf("swifi_inject_fault returned %ld (%d)\n", result,errno);
Cleanup:
if (res != NULL) {
free(res);
}
return(0);
Usage:
printf("Usage: %s -f module_name pid fault-type fault-count seed\n", argv[0]);
goto Cleanup;
}