

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Project; Class: Introduction to Image Processing and Analysis; Subject: Computer Science and Engineering; University: Arizona State University - Tempe; Term: Spring 2007;
Typology: Study Guides, Projects, Research
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Revision 2 January 29, 2007 Programming project #1 is on mapped memory management. Five system calls are exercised.
**1. mmap
(6) Use printf to print out the address the string was mapped to. (7) Use putchar (or another method) to print the contents of memory starting at the address returned by mmap. (8) Change the âaâs stored in memory to âAâs and use putchar to print the new contents. (9) Close the file. (10) Use msync to synchronize memory and the file. (11) Open the file (12) read the file into a buffer and use puts (or another method) to print out the buffer contents. (13) close the file and unmap the memory. (B) mremap The second part of this program allocates a region of memory, aligns the base of the region to a page boundary, fills it with characters and prints out its base address and size. Then it uses mremap to increase its size, fills the new region with characters and prints out the new base and size. The details are: (1) Use printf to print **** remap test program **** (2) Allocate a region of memory of 5 KB using malloc. (3) Fill the region using memset. (4) Print the original region starting address. (5) Print the original region length. (6) Establish a page-aligned memory region by defining a region that starts at the page boundary that the initial allocation crossed and ending where the initial allocation ended. (7) Print starting address or region after alignment. (8) Print length of region after alignment. (9) Calculate the size of the region starting at the page-aligned base using strlen and print it out. (10) Invoke mremap to expand the region by 1024 bytes. (11) Print out the base of the remapped region. (12) Fill the new region using memset. (13) Calculate the size of the remapped region using strlen and print it out. (C) mprotect The third part of this program allocates a region of memory, with default protection (read and write), writes to it and reads back what was written, changes protection to read only and attempts to read and write to it again causing a protection violation on the write. It also sets up a signal handler to catch a SIGSEGV signal and indicate that a protection violation occurred when writing. The details are: (1) Use printf to print **** mprotect test program **** (2) Allocate a region of memory using malloc. Note: It will get the default PROT_READ | PROT_WRITE protection. (3) Set up a signal handler to catch a SIGSEGV signal that prints out the warning message: âSIGSEGV: You are not allowed to access the protected memory!â (4) Write a character to the memory. (5) Read it back and print a message indicating that is being done. (6) Use mprotect to make the memory region read-only. (7) Read the protected memory and print out a message indicating that this was done. (8) Attempt to write the protected memory leading to a SIGSEGV signal handler message printout. Note: Insert system(âuname -a") and system(âusers") at the beginning of your program.