-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathresults.c
More file actions
112 lines (99 loc) · 2.25 KB
/
results.c
File metadata and controls
112 lines (99 loc) · 2.25 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
/*
* Routines to update the results counters
*/
#include <errno.h>
#include <stdlib.h>
#include <sys/resource.h>
#include "locks.h"
#include "results.h"
#include "sanitise.h"
#include "shm.h"
#include "syscall.h"
#include "tables.h"
#include "trinity.h"
unsigned long get_argval(struct syscallrecord *rec, unsigned int argnum)
{
switch (argnum) {
case 1: return rec->a1;
case 2: return rec->a2;
case 3: return rec->a3;
case 4: return rec->a4;
case 5: return rec->a5;
case 6: return rec->a6;
}
unreachable();
}
static struct results * get_results_ptr(struct syscallentry *entry, unsigned int argnum)
{
return &entry->results[argnum - 1];
}
static void store_successful_fd(struct results *results, unsigned long value)
{
int fd = (int) value;
rlim_t lim = max_files_rlimit.rlim_cur;
int fdmap_size = (lim == RLIM_INFINITY || lim > 1048576) ? 1048576 : (int)lim;
if (fd < 0 || fd >= fdmap_size)
return;
if (results->fdmap == NULL) {
results->fdmap = calloc(fdmap_size, sizeof(bool));
if (results->fdmap == NULL)
return;
}
results->fdmap[fd] = true;
}
static void store_successful_len(struct results *results, unsigned long value)
{
if (!results->seen) {
results->seen = true;
results->min = value;
results->max = value;
return;
}
if (value < results->min)
results->min = value;
if (value > results->max)
results->max = value;
}
void handle_success(struct syscallrecord *rec)
{
struct syscallentry *entry;
unsigned int i, call;
call = rec->nr;
entry = syscalls[call].entry;
for_each_arg(entry, i) {
struct results *results;
enum argtype argtype = get_argtype(entry, i);
unsigned long value = get_argval(rec, i);
results = get_results_ptr(entry, i);
if (is_typed_fdarg(argtype)) {
store_successful_fd(results, value);
continue;
}
switch (argtype) {
case ARG_FD:
store_successful_fd(results, value);
break;
case ARG_LEN:
store_successful_len(results, value);
break;
case ARG_UNDEFINED:
case ARG_ADDRESS:
case ARG_MODE_T:
case ARG_NON_NULL_ADDRESS:
case ARG_PID:
case ARG_RANGE:
case ARG_OP:
case ARG_LIST:
case ARG_CPU:
case ARG_PATHNAME:
case ARG_IOVEC:
case ARG_IOVECLEN:
case ARG_SOCKADDR:
case ARG_SOCKADDRLEN:
case ARG_MMAP:
case ARG_SOCKETINFO:
default:
break;
}
}
}