mirror of
https://github.com/SmallPond/MIT6.828_OS.git
synced 2026-05-04 06:15:30 +08:00
my solution to lab5
This commit is contained in:
42
lab/user/testptelibrary.c
Normal file
42
lab/user/testptelibrary.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <inc/lib.h>
|
||||
|
||||
#define VA ((char *) 0xA0000000)
|
||||
const char *msg = "hello, world\n";
|
||||
const char *msg2 = "goodbye, world\n";
|
||||
|
||||
void childofspawn(void);
|
||||
|
||||
void
|
||||
umain(int argc, char **argv)
|
||||
{
|
||||
int r;
|
||||
|
||||
if (argc != 0)
|
||||
childofspawn();
|
||||
|
||||
if ((r = sys_page_alloc(0, VA, PTE_P|PTE_W|PTE_U|PTE_SHARE)) < 0)
|
||||
panic("sys_page_alloc: %e", r);
|
||||
|
||||
// check fork
|
||||
if ((r = fork()) < 0)
|
||||
panic("fork: %e", r);
|
||||
if (r == 0) {
|
||||
strcpy(VA, msg);
|
||||
exit();
|
||||
}
|
||||
wait(r);
|
||||
cprintf("fork handles PTE_SHARE %s\n", strcmp(VA, msg) == 0 ? "right" : "wrong");
|
||||
|
||||
// check spawn
|
||||
if ((r = spawnl("/testptelibrary", "testptelibrary", "arg", 0)) < 0)
|
||||
panic("spawn: %e", r);
|
||||
wait(r);
|
||||
cprintf("spawn handles PTE_SHARE %s\n", strcmp(VA, msg2) == 0 ? "right" : "wrong");
|
||||
}
|
||||
|
||||
void
|
||||
childofspawn(void)
|
||||
{
|
||||
strcpy(VA, msg2);
|
||||
exit();
|
||||
}
|
||||
Reference in New Issue
Block a user