-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrowd_check_desch_bounds.c
61 lines (40 loc) · 1.18 KB
/
crowd_check_desch_bounds.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
#include "types.h"
#include "user.h"
#include "memlayout.h"
#define TEST_NAME "crowd_check_desch_bounds"
#include "318_test-tapish.h"
/* Authors: Bailey & Sam */
#define STKSIZE 1024
#define S_CHILD_READY 1
#define S_PARENT_READY 2
#define S_CHILD_STILL_RUNNING 3
volatile int signal = 0;
void thread(void *a);
/* Checks that desch doesn't allow the guard to be outside the proc's memory */
int
main(void)
{
void *stack;
TEST_STRT(1);
TEST_DIAG("This test will timeout if it fails");
TEST_EXIT_IF((stack = malloc(STKSIZE)) == 0, "malloc failed");
stack += STKSIZE;
TEST_EXIT_IF(tspawn((void *) stack, thread, 0) < 0, "tspawn failed");
// Wait for child to signal that it's ready
while(signal != S_CHILD_READY);
signal = S_PARENT_READY;
// Wait (and hope) for child to awake (never get desch)
while(signal != S_CHILD_STILL_RUNNING);
TEST_FINI("desch guard bounds");
exit();
}
void thread(void *a)
{
signal = S_CHILD_READY;
// Wait for parent to signal that it's ready
while(signal != S_PARENT_READY);
desch((void *) KERNBASE);
// No one will mkrun() us so if we hit here, the desch failed as expected
signal = S_CHILD_STILL_RUNNING;
texit();
}