SORU
16 Aralık 2008, Salı


Ne zaman ve neden bir işletim sistemi 0xCD, 0xDD, vb bellek yeniden. malloc/free/yeni/sil?

İşletim sistemi bazen 0xCD ve 0xDD gibi belirli kalıpları ile hafıza yeniden olacağını biliyorum. Ne bilmek istiyorumne zamanvenedenbu olur.

Ne zaman

Bu derleyici kullanılan özgüdür?

Malloc/yeni ve boş/sil bu konu ile ilgili olarak aynı şekilde çalışır?

Belirli bir platform mu?

Diğer işletim sistemleri, Linux veya VxWorks gibi ortaya çıkar?

Neden

Benim anladığım bu sadece Win32 hata ayıklama yapılandırma oluşur ve hafıza taşması tespit etmek ve derleyici özel durumları yakalamak için kullanılır.

Bu işlemi nasıl yararlı olduğunu için pratik olarak herhangi bir örnek verebilir misiniz?

Hatırlıyorum okurken bir şey (belki de Kod Tamamlama 2) İyi için yeniden hafıza için bilinen bir desen zaman ayırarak ve belli bir şablon olacak tetik kesme Win32 hangi sonuçlara yol istisnalar gösteren hata.

Nasıl taşınabilir?

CEVAP
16 Aralık 2008, Salı


Microsoft'un derleyicileri sahipsiz/çeşitli uçları için ne hızlı bir özet için hata ayıklama modunda derlenmiş bellek (destek derleyici sürümüne göre değişebilir) başlatılmamış:

Value     Name           Description 
------   --------        -------------------------
0xCD     Clean Memory    Allocated memory via malloc or new but never 
                         written by the application. 

0xDD     Dead Memory     Memory that has been released with delete or free. 
                         Used to detect writing through dangling pointers. 

0xED or  Aligned Fence   'No man's land' for aligned allocations. Using a 
0xBD                     different value here than 0xFD allows the runtime
                         to detect not only writing outside the allocation,
                         but to also detect mixing alignment-specific
                         allocation/deallocation routines with the regular
                         ones.

0xFD     Fence Memory    Also known as "no mans land." This is used to wrap 
                         the allocated memory (surrounding it with a fence) 
                         and is used to detect indexing arrays out of 
                         bounds or other accesses (especially writes) past
                         the end (or start) of an allocated block.

0xFD or  Buffer slack    Used to fill slack space in some memory buffers 
0xFE                     (unused parts of `std::string` or the user buffer 
                         passed to `fread()`). 0xFD is used in VS 2005 (maybe 
                         some prior versions, too), 0xFE is used in VS 2008 
                         and later.

0xCC                     When the code is compiled with the /GZ option,
                         uninitialized variables are automatically assigned 
                         to this value (at byte level). 


// the following magic values are done by the OS, not the C runtime:

0xAB  (Allocated Block?) Memory allocated by LocalAlloc(). 

0xBAADF00D Bad Food      Memory allocated by LocalAlloc() with LMEM_FIXED,but 
                         not yet written to. 

0xFEEEFEEE               OS fill heap memory, which was marked for usage, 
                         but wasn't allocated by HeapAlloc() or LocalAlloc(). 
                         Or that memory just has been freed by HeapFree(). 

Yasal Uyarı: tablo - 100% doğru olmayabilir ortalıkta bazı notlar (ya da uyumlu).

Bu değerler birçok vc/crt/src/dbgheap tanımlanır.c:

/*
 * The following values are non-zero, constant, odd, large, and atypical
 *      Non-zero values help find bugs assuming zero filled data.
 *      Constant values are good so that memory filling is deterministic
 *          (to help make bugs reproducable).  Of course it is bad if
 *          the constant filling of weird values masks a bug.
 *      Mathematically odd numbers are good for finding bugs assuming a cleared
 *          lower bit.
 *      Large numbers (byte values at least) are less typical, and are good
 *          at finding bad addresses.
 *      Atypical values (i.e. not too often) are good since they typically
 *          cause early detection in code.
 *      For the case of no-man's land and free blocks, if you store to any
 *          of these locations, the memory integrity checker will detect it.
 *
 *      _bAlignLandFill has been changed from 0xBD to 0xED, to ensure that
 *      4 bytes of that (0xEDEDEDED) would give an inaccessible address under 3gb.
 */

static unsigned char _bNoMansLandFill = 0xFD;   /* fill no-man's land with this */
static unsigned char _bAlignLandFill  = 0xED;   /* fill no-man's land for aligned routines */
static unsigned char _bDeadLandFill   = 0xDD;   /* fill free objects with this */
static unsigned char _bCleanLandFill  = 0xCD;   /* fill new objects with this */

Orada da bir kaç kez nerede hata ayıklama zamanı yaz tamponlar (veya parçaları tamponlar) ile bilinen bir değer, örneğin 'bolluk' uzayda std::string'In ayırma veya arabellek geçti fread(). Bu durumlarda bir değeri 6* *adı (crtdefs.h tanımlı) verilen kullanın. Tam olarak tanıtıldığından emin değilim, ama VS 2005 en azından hata ayıklama zamanı (VC 8) oldu.

Başlangıçta değeri bu tamponlar doldurmak için kullanılır 0xFD - aynı değere no man's land için kullanıldı. Ancak VS 2008 (VC 9) değeri 0xFE olarak değiştirilmiştir. Sanırım bu, çünkü orada olabilir durumlarda, dolgu işlemi ki koşan end tampon, örneğin arayan geçirilen arabellek boyutu çok büyük fread(). Bu durumda, değer 0xFD olmayabilir tetik algılama bu yana eğer taşması arabellek boyutu çok büyük bir dolgu değeri olurdu aynı no man's land değeri kullanılan başlatmak Kanarya. No man's land bir değişiklik yok taşması fark olmaz demektir.

Dolgu değeri böyle bir dava no man's land Kanarya, çalışma zamanı tarafından sorun tespiti sonucu değiştirecek bu yüzden VS 2008'de değiştirildi.

Başkaları var not, bir anahtar özellikleri Bu değerler olduğu bir işaretçi değişkeni ile bu değerler için başvuru yapıldı, bu olacak erişim ihlaline beri bir standart 32-bit Windows yapılandırma, kullanıcı modu adresleri gitmem daha yüksek 0x7fffffff.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • FOSDEM

    FOSDEM

    13 Ocak 2009
  • Kayla Caton - Peet

    Kayla Caton

    23 HAZİRAN 2012
  • MrChiCity3

    MrChiCity3

    14 NİSAN 2008