Memory: Copy On Write

CS 321 Lecture, Dr. Lawlor, 2006/02/22

See Silberschatz Chapter 9.3 for Copy-On-Write info.

Bad Memory Handlers

When a program tries to access bad memory (memory whose pagetable entry is marked "bad"), the CPU executes the segfault interrupt handler.  This OS code gets the following information:
See the Microsoft Windows SetUnhandledExceptionFilter and ExceptionInformation for details on how this information can be delivered to a normal program.  It boils down to this code:
/**
Signal handler, called by the OS when any exception occurs.
*/
LONG WINAPI
badMemSignal(
struct _EXCEPTION_POINTERS *ExceptionInfo
)
{
EXCEPTION_RECORD *er=ExceptionInfo->ExceptionRecord;
if (er->ExceptionCode==EXCEPTION_ACCESS_VIOLATION) {
bool isWrite=er->ExceptionInformation[0];
void *badAddress=(void *)er->ExceptionInformation[1];
/* ... check address, fix memory, etc. ... */
return EXCEPTION_CONTINUE_EXECUTION;
}
return EXCEPTION_CONTINUE_SEARCH;
}

/* Call at the beginning of the program */
void badMemSetup {
SetUnhandledExceptionFilter(badMemSignal);
}

See GNU libsigsegv for a decent interface for UNIX systems.