forked from Hearmen/ASTFuzz
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSHM_TEST_get.c
68 lines (58 loc) · 1.44 KB
/
SHM_TEST_get.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
//compile with gcc -o SHM_TEST_get SHM_TEST_get.c -lrt
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
#define STORAGE_ID "/SHM_TEST"
#define STORAGE_SIZE 0x100000
struct shmem_data {
uint32_t num_edges;
unsigned char edges[];
};
int main(int argc, char *argv[])
{
int res;
int fd;
char data[STORAGE_SIZE];
struct shmem_data* data1;
pid_t pid;
void *addr;
char* shm_key = getenv("SHM_ID");
pid = getpid();
// get shared memory file descriptor (NOT a file)
if (shm_key)
fd = shm_open(shm_key, O_RDONLY, S_IRUSR | S_IWUSR);
else
fd = shm_open(STORAGE_ID, O_RDONLY, S_IRUSR | S_IWUSR);
if (fd == -1)
{
perror("open");
return 10;
}
// map shared memory to process address space
addr = mmap(NULL, STORAGE_SIZE, PROT_READ, MAP_SHARED, fd, 0);
if (addr == MAP_FAILED)
{
perror("mmap");
return 30;
}
// place data into memory
//memcpy(data, addr, STORAGE_SIZE);
data1 = addr;
int counter=0;
//printf("Size %u\n", (*data1).num_edges);
for (int i=0;i<data1->num_edges;i++) {
if (0 != data1->edges[i / 8] && (1 << (i % 8))) {
//printf("cov\n");
counter++;
}
//else
// printf("-\n");
}
printf("SHM Edges %u :: %d / %u --> %6.2f coverage\n",(*data1).num_edges,counter,data1->num_edges,100.0 * counter / data1->num_edges );
return 0;
}