PKUOS - Pintos
Pintos source browser for PKU Operating System course
mmap-over-data.c
Go to the documentation of this file.
1/** Verifies that mapping over the data segment is disallowed. */
2
3#include <stdint.h>
4#include <round.h>
5#include <syscall.h>
6#include "tests/lib.h"
7#include "tests/main.h"
8
9static char x;
10
11void
12test_main (void)
13{
14 uintptr_t x_page = ROUND_DOWN ((uintptr_t) &x, 4096);
15 int handle;
16
17 CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
18 CHECK (mmap (handle, (void *) x_page) == MAP_FAILED,
19 "try to mmap over data segment");
20}
21
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
#define MAP_FAILED
Definition: syscall.h:13
#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)
tests/main.h
static char x
Verifies that mapping over the data segment is disallowed.
Definition: mmap-over-data.c:9
#define ROUND_DOWN(X, STEP)
Yields X rounded down to the nearest multiple of STEP.
Definition: round.h:14
uint32_t uintptr_t
Definition: stdint.h:36