CS611
Programming Assignment 7
Fall 2004
Due Sunday December 12


Write a set of C functions to augment the standard C storage allocation routines to provide memory leak detection on the Intel IA-32 architecture.

The following functions will need to be provided:

  1. void MLD_registerFunction(char *name, void (*)(void)): Inform the memory leak detector of a user function.

  2. void MLD_markGlobalsStart(void *): Provide the beginning address of the memory holding global variables.

  3. void MLD_markGlobalsEnd(void *): Provide the ending address of the memory holding global variables.

  4. void MLD_markStackBottom(void): Should be called from the main function and it will determine an address on the run-time stack beyond which the memory leak detector needs not search. Be sure your memory leak detector will consider references to allocated blocks held in local variables of the main function.

  5. void *MLD_malloc(size_t): This storage allocation will be tracked by the memory leak detector.

  6. void MLD_free(void *): This frees a block of memory being tracked by the memory leak detector.

  7. void MLD_checkForLeak(void): The memory leak detector should scan global memory, the run-time stack, the registers, and referenced allocated blocks for references to allocated blocks. Any allocated block that has not been freed and that is not reachable should be reported to stderr. Report the starting address of the block, its length, and the name of the function that allocated it.

The user is expected to register all functions. You should sort the provided function addresses and assume that a function extends from its start address to the start address of the next function in the sorted list.

When the user requests the allocation of a block, you must determine and remember which function is doing the allocation. You can do this by retrieving the return address for the call to the memory allocation routine and comparing this to the start and end addresses for registered functions.

You can call malloc and free to allocate and free blocks of memory. You might consider "over-allocating" memory in order to store control information with the allocated blocks.

When MLD_checkForLeak is called you must determine the address of the top of stack in order to bound the scan of the run-time stack.

When scanning memory for references to allocated blocks, assume that references (pointer values) will be allocated on a 32-bit boundary (i.e. address is evenly divisible by four). Also assume that if a pointer points into the middle of an allocated block, then the whole block is referenced.

Providing memory leak detection without function identification is worth 75% of the points. In this case MLD_registerFunction can do nothing, but it must be present (perhaps with a null function body).

Your implementation should be performed using C and Intel assembler. Put all your C code in the mld.c file and the Intel assembler code in the mld_asm.s file.

Your program will be graded primarily by testing it for correct functionality. However, you may lose points if your program is not properly structured or adequately documented. See the mandatory guidelines given in the course overview webpage.

Your assignment should be submitted for grading from a CIS Linux machine (e.g. turing.unh.edu). To turn in this assignment, type:
~cs611/bin/submit prog7 mld.c mld_asm.s

Do not turn in any other files!

Submissions can be checked by typing:
~cs611/bin/scheck prog7

To receive full credit for the assignment, you must turn in your files prior to 8am on Monday December 13. Programming assignments may be handed in late at a penalty of 2 points for one day late, 5 points for two days late, 10 points for three days late, 20 points for four days late, and 40 points for five days late. No program may be turned in more than 5 days late.

Your programs will be graded using an CIS Linux machine (e.g. turing.unh.edu) so be sure to test in that environment.

Remember: as always you are expected to do your own work on this assignment.


Last modified on November 29, 2004.

Comments and questions should be directed to hatcher@unh.edu