forked from mit-pdos/xv6-public
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_badclone.c
50 lines (39 loc) · 1.03 KB
/
test_badclone.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
/* When passing a non page-aligned stack to clone, clone should return -1. */
#include "types.h"
#include "user.h"
#undef NULL
#define NULL ((void*)0)
#define PGSIZE (4096)
int ppid;
#define assert(x) if (x) {} else { \
printf(1, "%s: %d ", __FILE__, __LINE__); \
printf(1, "assert failed (%s)\n", # x); \
printf(1, "TEST FAILED\n"); \
kill(ppid); \
exit(); \
}
void worker(void *arg_ptr);
int
main(int argc, char *argv[])
{
ppid = getpid();
void *stack = malloc(PGSIZE*2);
assert(stack != NULL);
if((uint)stack % PGSIZE == 0)
stack += 4;
assert(clone(worker, 0, stack) == -1); // when stack is not page-aligned, clone should fail
stack = sbrk(0);
if((uint)stack % PGSIZE){
stack = stack + (PGSIZE - (uint)stack % PGSIZE);
}
sbrk( ((uint)stack - (uint)sbrk(0)) + PGSIZE/2 );
assert((uint)stack % PGSIZE == 0);
assert((uint)sbrk(0) - (uint)stack == PGSIZE/2);
assert(clone(worker, 0, stack) == -1);
printf(1, "TEST PASSED\n");
exit();
}
void
worker(void *arg_ptr) {
exit();
}