PKUOS - Pintos
Pintos source browser for PKU Operating System course
mmap-inherit.c
Go to the documentation of this file.
1/** Maps a file into memory and runs child-inherit to verify that
2 mappings are not inherited. */
3
4#include <string.h>
5#include <syscall.h>
6#include "tests/vm/sample.inc"
7#include "tests/lib.h"
8#include "tests/main.h"
9
10void
12{
13 char *actual = (char *) 0x54321000;
14 int handle;
15 pid_t child;
16
17 /* Open file, map, verify data. */
18 CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
19 CHECK (mmap (handle, actual) != MAP_FAILED, "mmap \"sample.txt\"");
20 if (memcmp (actual, sample, strlen (sample)))
21 fail ("read of mmap'd file reported bad data");
22
23 /* Spawn child and wait. */
24 CHECK ((child = exec ("child-inherit")) != -1, "exec \"child-inherit\"");
25 quiet = true;
26 CHECK (wait (child) == -1, "wait for child (should return -1)");
27 quiet = false;
28
29 /* Verify data again. */
30 CHECK (!memcmp (actual, sample, strlen (sample)),
31 "checking that mmap'd file still has same data");
32}
static void wait(struct intq *q, struct thread **waiter)
mapid_t mmap(int fd, void *addr)
Project 3 and optionally project 4.
Definition: syscall.c:145
int open(const char *file)
Definition: syscall.c:103
pid_t exec(const char *file)
Definition: syscall.c:79
int pid_t
Process identifier.
Definition: syscall.h:8
#define MAP_FAILED
Definition: syscall.h:13
void fail(const char *format,...)
Definition: lib.c:40
bool quiet
Definition: lib.c:9
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
void test_main(void)
Maps a file into memory and runs child-inherit to verify that mappings are not inherited.
Definition: mmap-inherit.c:11
int memcmp(const void *a_, const void *b_, size_t size)
Find the first differing byte in the two blocks of SIZE bytes at A and B.
Definition: string.c:53
size_t strlen(const char *string)
Returns the length of STRING.
Definition: string.c:293