Operating systems provide mechanisms for applications to dynamically obtain memory resources used during processing. Frequently, such memory storage is referred to as dynamic heap memory, or heap memory. Some programming languages, including C and C++, provide application programming interfaces (APIs) that allow applications to request and return heap memory from and to the operating system. These APIs include malloc, calloc, realloc, and free. A common problem involved with the usage of heap memory involves program errors that may occur which overwrite portions of the heap memory which are not intended to be written into (i.e., “heap corruption”). Furthermore, the problem exists where applications may continue to access units of heap memory after having returned this memory to the operating system.
Many different solutions have evolved for verifying the integrity of the heap memory once it has been allocated. For example, one prior solution involves placing integrity keys before and after each unit of heap memory that is allocated. These keys contain re-creatable patterns that must be compared at some point in time in order to determine if an overwrite has occurred. Techniques for comparing the keys include having wrapper functions, which are called before and after the regular heap APIs. It is the responsibility of these wrappers to validate the keys for every unit of heap memory allocated, on every heap API that is called. Not only is this inefficient, it only allows the corruption to be detected between two heap APIs being called.
In another solution, the integrity keys are interrogated by an independent thread running from within the same process. While this removes the restriction that the corruption be detected between two heap API calls, there is still a latency between the time that the corruption occurs and the time it is detected.
Although various techniques have been provided for verifying the integrity of heap memory, none of the previous techniques offers an efficient mechanism for detecting corruption in real-time. Thus, a need exists for a technique that enables the detection of memory corruption in real-time. A further need exists for an enhanced capability that enables dynamic and real-time management of heap memory, as well as other dynamically allocated memory.