Magical Values in VC

Source: Internet
Author: User
WFC Technical Note 006-Funny Memory Values

$ Revision: 1 $ Last Modified $ Date: 3/26/00 11: 01a $

Introduction

Microsoft has put quite a lot of memory leak detection helpers in Windows NT. they have not done a good job of advertising it. this document describes some of the things I 've deciphered while debugging code.
Funny Memory Values

When times while debugging programs, I will come into memory SS memory that is filled with "funny" values. after some playing around (I. e. hacking) with the Win32 API, I was able to figure out what they meant. some of these values have been incluented in places but never all together. the values for the tags presented here are hexadecimal because that's the way Developer's Studio presents them in the memory window.

 Value  Meaning
 0xAB
Or
 0xABAB 
Or
 0xABABABAB 
 Memory following a block allocatedLocalAlloc().
 0xBAADF00D  Bad Food. Get it? This is memory allocatedLocalAlloc( LMEM_FIXED, ... ). It is memory that has been allocated but not yet written.
 0xFEEE
 0xFEEEFEEE
 This seems to be memory that has been dedicated to a heap but not yet allocatedHeapAlloc()OrLocalAlloc().
 0xCC
Or
 0xCCCC
Or
 0xCCCCCCCC
 Microsoft Visual C ++ compiled code with/GZIs automatically initialized the uninitialized variable with this value.
 0xCD
Or
 0xCDCD
Or
 0xCDCDCDCD
 Microsoft Visual C ++ compiled code with memory leak detection turned on. Usually,DEBUG_NEWWas defined. Memory with this tag signifies memory that has been allocated (malloc()Ornew) But never written to the application.
 0xDD
Or
 0xDDDD
Or
 0xDDDDDDDD
 Microsoft Visual C ++ compiled code with memory leak detection turned on. Usually,DEBUG_NEWWas defined. Memory with this tag signifies memory that has been freed (free()Ordelete) By the application. it is how you can detect writing to memory that has already been freed. for example, if you look at an allocated memory structure (or C ++ class) and most of the members contain this tag value, you are probably writing to a structure that has been freed.
 0xFD
Or
 0xFDFD
Or
 0xFDFDFDFD
 Microsoft Visual C ++ compiled code with memory leak detection turned on. Usually,DEBUG_NEWWas defined. memory with this tag signifies memory that is in "no-mans-land. "These are bytes just before and just after an allocated block. they are used to detect array-out-of-bounds errors. this is great for detecting off-by-one errors.

 

 

Samuel R. Blackburn

 

Http://www.samblackburn.com/wfc/technotes/WTN006.htm

 

 

Http://en.wikipedia.org/wiki/Magic_number_ (programming)

Magic debug valuesAre specific values written to memory during allocation or deallocation, so that it will later be possible to tell whether or not they have become into upted, and to make it obvious when values taken from uninitialized memory are being used.

Since it is unlikely that any given 32-bit integer wocould take this specific value, the appearance of such a number in a debugger or memory dump can indicate common errors such as buffer overflows, or uninitialized variables.

Memory is usually viewed in hexadecimal, so common values used are often repeated digits or hexspeak.

Famous and common examples include:

  • 0x5F3759DF : Used in Quake 3 for an optimized inverse square root function.[8]
  • 0x..FACADE : Used by a number of RTOSes
  • 0xA5A5A5A5 : Used in embedded development because the alternating bit pattern (10100101) creates an easily recognized pattern on oscilloscopes and logic analyzers.
  • 0xABABABAB : Used by Microsoft's HeapAlloc () to mark "no man's land" guard bytes after allocated heap memory
  • 0xABADBABE : Used by Apple as the "Boot Zero Block" magic number
  • 0xABADCAFE : A startup to this value to initialize all free memory to catch errant pointers
  • 0xBAADF00D : Used by Microsoft's LocalAlloc (LMEM_FIXED) to mark uninitialised allocated heap memory
  • 0xBADBADBADBAD : Burroughs large systems "uninitialized" memory (48-bit words)
  • 0xBADCAB1E : Error Code returned to the Microsoft eVC debugger when connection is severed to the debuggee
  • 0xBADC0FFEE0DDF00D : Used on ibm rs/6000 64-bit systems to indicate uninitialized CPU registers
  • 0xBADDCAFE : On Sun Microsystems 'solaris, marks uninitialised kernel memory (KMEM_UNINITIALIZED_PATTERN)
  • 0xBEEFCACE : Used by Microsoft. NET as a magic number in resource files
  • 0xC0DEDBAD : A memory leak tracking tool which it will change the MMU tables so that all references to address zero
  • 0xCAFEBABE : Used by both Mach-O ("Fat binary" in both 68 k and PowerPC) to identify object files and the Java programming language to identify. class files
  • 0xCAFEFEED : Used by Sun Microsystems 'solaris debugging kernel to mark kmemfree () memory
  • 0xCEFAEDFE : Seen in Intel Mach-O binaries on Apple Computer's Mac OS X platform (see0xFEEDFACEBelow)
  • 0xCCCCCCCC : Used by Microsoft's C ++ debugging runtime library to mark uninitialised stack memory
  • 0xCDCDCDCD : Used by Microsoft's C ++ debugging runtime library to mark uninitialised heap memory
  • 0xDDDDDDDD : Used by MicroQuill's SmartHeap and Microsoft's C ++ debugging heap to mark freed heap memory
  • 0xDEADBABE : Used at the start of Silicon Graphics 'irix arena files
  • 0xDEADBEEF : Famously used on IBM systems such as the RS/6000, also used in the original Mac OS operating systems, OPENSTEP Enterprise, and the Commodore Amiga. on Sun Microsystems 'solaris, marks freed kernel memory (KMEM_FREE_PATTERN)
  • 0xDEADDEAD : A Microsoft Windows STOP Error code used when the user manually initiates the crash.
  • 0xDEADF00D : All the newly allocated memory which is not explicitly cleared when it is munged
  • 0xEBEBEBEB : From MicroQuill's SmartHeap
  • 0xFADEDEAD : Comes at the end to identify every OSA script
  • 0xFDFDFDFD : Used by Microsoft's C ++ debugging heap to mark "no man's land" guard bytes before and after allocated heap memory
  • 0xFEEDFACE : Seen in PowerPC Mach-O binaries on Apple Computer's Mac OS X platform. On Sun Microsystems 'solaris, marks the red zone (KMEM_REDZONE_PATTERN)
  • 0xFEEEFEEE : Used by Microsoft's HeapFree () to mark freed heap memory
  • 0xFEE1DEAD : Used by Linux reboot () syscall

Note that most of these are each 32 bits long-the word size of most modern computers.

The prevalence of these values in Microsoft technology is no coincidence; they are discussed in detail in Steve Maguire's bookWriting Solid CodeFrom Microsoft Press. He gives a variety of criteria for these values, such:

  • They shoshould not be useful; that is, most algorithms that operate on them shocould be expected to do something unusual. Numbers like zero don't fit this criterion.
  • They shoshould be easily recognized by the programmer as invalid values in the debugger.
  • On machines that don't have byte alignment, they shocould be odd numbers, so that dereferencing them as addresses causes an exception.
  • They shoshould cause an exception, or perhaps even a debugger break, if executed as code.

Since they were often used to mark areas of memory that were essential empty, some of these terms came to be used in phrases meaning "gone, aborted, flushed from memory"; e.g. "Your program is DEADBEEF ".

Pietr brandehörst's ZUG programming language initialized memory to either0x0000,0xDEADOr0xFFFFIn development environment and0x0000In the live environment, on the basis that uninitialised variables shocould be encouraged to misbehave under development to trap them, but encouraged to behave in a live environment to reduce errorsSince rjl 2008 "> [Citation needed].

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.