-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestPrivmem.c
58 lines (49 loc) · 1012 Bytes
/
testPrivmem.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
/*
* Make sure that privmem driver makes isolates filesystem changes.
*
* cc -g -Wall testPrivmem.c aflCall.o -o testPrivmem
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "drv.h"
static void showFile(char *fn)
{
char buf[256];
ssize_t n;
int fd;
fd = open(fn, O_RDONLY);
if(fd >= 0) {
n = read(fd, buf, sizeof buf);
if(n > 0)
write(1, buf, n);
close(fd);
}
}
static void writeFile(char *fn, char *dat)
{
int fd;
fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if(fd >= 0) {
write(fd, dat, strlen(dat));
close(fd);
}
}
int
main(int argc, char **argv)
{
int enableTimer = 1;
u_long sz;
char *buf;
writeFile("/data", "initial\n");
startForkserver(enableTimer);
buf = getWork(&sz);
startWork(0, 1);
showFile("/data");
writeFile("/data", "updated\n");
showFile("/data");
doneWork(0);
return 0;
}