-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrowd_wildpointer.c
executable file
·50 lines (43 loc) · 1000 Bytes
/
crowd_wildpointer.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
#include "param.h"
#include "types.h"
#include "stat.h"
#include "user.h"
#include "syscall.h"
#include "traps.h"
#define TEST_NAME "crowd_wildpointer"
#include "318_test-tapish.h"
#define STKSIZE 1024
#define ARG ((void *)0x15410DE0U)
/*Authors: Jose and Emily*/
/*test that bad dereferences don't kill the whole process*/
static void
goodie(void *a) {
while(1){yield(-1);}
}
static void
baddie(void *a) {
int *addr = (int *) 0xdeadbea7;
TEST_DIAG("%d", *addr);
TEST_FAIL("Baddie wasn't killed");
while(1);
}
int main() {
int i;
void *s;
TEST_STRT(1);
for (i = 0; i < 10; i++) {
TEST_EXIT_IF((s = malloc(STKSIZE)) == 0, "oom");
s += STKSIZE;
if (i == 0) {
TEST_EXIT_IF(tspawn(s, baddie, ARG) < 0,
"spawn fail at %d", i);
} else {
TEST_EXIT_IF(tspawn(s, goodie, ARG) < 0, "spawn fail at %d", i);
}
sleep(10);
}
TEST_DIAG("You can see the thread being killed well"\
" before this test finishes.");
TEST_FINI();
exit();
}