/mmap

Implementation of mmap on JOS

Primary LanguageC

Basic MMAP On JOS

Implementation of mmap on JOS

COMPILING

make clean
make

TESTING

Run the following commands to test our JOS MMAP implementation

# Basic mmap
make run-testmmap1-nox
# Dynamic Loading test
make run-testmmap2-nox
# Test pgflt on access after unmap
make run-testmmap3-nox
# Test write back if writable file
make run-testmmap4-nox

Implementation

The main implementation is in mmap.c

See:

Sample mmap call

struct Fd *fd;
int r_open;

size_t length;
void *mmaped_addr;

char *content;
char fread_buf[512];

// First, open file 'lorem' and get the file id.
if ((r_open = open("/lorem", O_RDONLY)) < 0)
  panic("mmap(): opening file failed, ERROR CODE: %d \n", r_open);

// Start testing.
cprintf("\nTest mmaping\n");
length = PGSIZE;
mmaped_addr = mmap(NULL, length, 0, MAP_PRIVATE, r_open, (off_t) 0);

content = (char*) mmaped_addr;

cprintf("=> Read from mmapped region:\n%30s\n", content);
munmap(mmaped_addr, length);