PKUOS - Pintos
Pintos source browser for PKU Operating System course
mmap-zero.c
Go to the documentation of this file.
1/** Tries to map a zero-length file, which may or may not work but
2 should not terminate the process or crash.
3 Then dereferences the address that we tried to map,
4 and the process must be terminated with -1 exit code. */
5
6#include <syscall.h>
7#include "tests/lib.h"
8#include "tests/main.h"
9
10void
11test_main (void)
12{
13 char *data = (char *) 0x7f000000;
14 int handle;
15
16 CHECK (create ("empty", 0), "create empty file \"empty\"");
17 CHECK ((handle = open ("empty")) > 1, "open \"empty\"");
18
19 /* Calling mmap() might succeed or fail. We don't care. */
20 msg ("mmap \"empty\"");
21 mmap (handle, data);
22
23 /* Regardless of whether the call worked, *data should cause
24 the process to be terminated. */
25 fail ("unmapped memory is readable (%d)", *data);
26}
27
mapid_t mmap(int fd, void *addr)
Project 3 and optionally project 4.
Definition: syscall.c:145
bool create(const char *file, unsigned initial_size)
Definition: syscall.c:91
int open(const char *file)
Definition: syscall.c:103
void fail(const char *format,...)
Definition: lib.c:40
void msg(const char *format,...)
Definition: lib.c:28
#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)
Tries to map a zero-length file, which may or may not work but should not terminate the process or cr...
Definition: mmap-zero.c:11