-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathp-testrwaddr.cc
64 lines (44 loc) · 1.77 KB
/
p-testrwaddr.cc
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
#include "u-lib.hh"
void process_main() {
const char msg1[] = "Type a few characters and press return:\n";
ssize_t w = sys_write(1, msg1, strlen(msg1));
assert_eq(static_cast<size_t>(w), strlen(msg1));
char buf[200];
ssize_t r = sys_read(0, buf, sizeof(buf));
assert_gt(r, 0);
// check invalid addresses
w = sys_write(1, reinterpret_cast<const char*>(0x40000000UL), 0);
assert_eq(w, 0);
w = sys_write(1, reinterpret_cast<const char*>(VA_LOWEND), 0);
assert_eq(w, 0);
w = sys_write(1, msg1, 0xFFFFFFFFFFFFFFFFUL);
assert_eq(w, E_FAULT);
w = sys_write(1, reinterpret_cast<const char*>(10), 1);
assert_eq(w, E_FAULT);
w = sys_write(1, reinterpret_cast<const char*>(rdrbp()), 16384);
assert_eq(w, E_FAULT);
r = sys_read(0, reinterpret_cast<char*>(0x40000000UL), 0);
assert_eq(r, 0);
r = sys_read(0, reinterpret_cast<char*>(VA_LOWEND), 0);
assert_eq(r, 0);
r = sys_read(0, buf, 0xFFFFFFFFFFFFFFFFUL);
assert_eq(r, E_FAULT);
r = sys_read(0, reinterpret_cast<char*>(10), 1);
assert_eq(r, E_FAULT);
r = sys_read(0, reinterpret_cast<char*>(rdrbp()), 16384);
assert_eq(r, E_FAULT);
// ensure we can get right up to the end of low canonical memory
char* pg = reinterpret_cast<char*>(VA_LOWEND - PAGESIZE);
r = sys_page_alloc(pg);
assert_eq(r, 0);
memset(pg, '-', PAGESIZE);
const char msg2[] = "Now type another few characters and press return:\n";
char* pg_msg2 = pg + PAGESIZE - strlen(msg2);
memcpy(pg_msg2, msg2, strlen(msg2));
w = sys_write(1, pg_msg2, strlen(msg2));
assert_eq(static_cast<size_t>(w), strlen(msg2));
r = sys_read(0, pg_msg2, strlen(msg2));
assert_gt(r, 0);
console_printf("testrwaddr succeeded.\n");
sys_exit(0);
}