The low-level system calls mmap and munmap can be used to create and delete areas of virtual memory. We will write a C program mmapcopy.c that uses mmap to copy an arbitrary-sized disk file to stdout. The name of the input file is passed as a command line argument.
-----------------------------------------------------mmapcopy.c
#include "csapp.h"
// mmapcopy - uses mmap to copy file fd to stdout
void mmapcopy(int fd, int size)
{
char *bufp; // Pointer to memory mapped VM area
bufp = Mmap(NULL, size, PROT_READ, MPA_PRIVATE, fd, 0);
Write(1, bufp, size);
return;
}
// mmapcopy driver
int main(int argc, char **argv)
{
struct stat stat;
int fd;
// Check for required command line argument
if (argc != 2) {
prin