forked from woai3c/MIT6.828
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendpage.c
39 lines (31 loc) · 1.08 KB
/
sendpage.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
// Test Conversation between parent and child environment
// Contributed by Varun Agrawal at Stony Brook
#include <inc/lib.h>
const char *str1 = "hello child environment! how are you?";
const char *str2 = "hello parent environment! I'm good.";
#define TEMP_ADDR ((char*)0xa00000)
#define TEMP_ADDR_CHILD ((char*)0xb00000)
void
umain(int argc, char **argv)
{
envid_t who;
if ((who = fork()) == 0) {
// Child
ipc_recv(&who, TEMP_ADDR_CHILD, 0);
cprintf("%x got message: %s\n", who, TEMP_ADDR_CHILD);
if (strncmp(TEMP_ADDR_CHILD, str1, strlen(str1)) == 0)
cprintf("child received correct message\n");
memcpy(TEMP_ADDR_CHILD, str2, strlen(str2) + 1);
ipc_send(who, 0, TEMP_ADDR_CHILD, PTE_P | PTE_W | PTE_U);
return;
}
// Parent
sys_page_alloc(thisenv->env_id, TEMP_ADDR, PTE_P | PTE_W | PTE_U);
memcpy(TEMP_ADDR, str1, strlen(str1) + 1);
ipc_send(who, 0, TEMP_ADDR, PTE_P | PTE_W | PTE_U);
ipc_recv(&who, TEMP_ADDR, 0);
cprintf("%x got message: %s\n", who, TEMP_ADDR);
if (strncmp(TEMP_ADDR, str2, strlen(str2)) == 0)
cprintf("parent received correct message\n");
return;
}