From: Ben Pfaff Date: Wed, 15 Dec 2004 05:50:42 +0000 (+0000) Subject: Use 0xcc (not 0xcd) for clearing malloc() blocks too. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d50ca8650fb96c13add16ef5659cc7aa6d4ab4b;p=pintos-anon Use 0xcc (not 0xcd) for clearing malloc() blocks too. Update documentation. --- diff --git a/doc/debug.texi b/doc/debug.texi index a192a73..f93eeda 100644 --- a/doc/debug.texi +++ b/doc/debug.texi @@ -374,17 +374,18 @@ above, a good place to start adding @func{printf}s is @node Debugging Tips @section Tips -The page allocator in @file{threads/palloc.c} clears all the bytes in -pages to @t{0xcc} when they are freed. Thus, if you see an attempt to +The page allocator in @file{threads/palloc.c} and the block allocator in +@file{threads/malloc.c} both clear all the bytes in pages and blocks to +@t{0xcc} when they are freed. Thus, if you see an attempt to dereference a pointer like @t{0xcccccccc}, or some other reference to @t{0xcc}, there's a good chance you're trying to reuse a page that's -already been freed. Also, byte @t{0xcc} is the CPU opcode for -``invoke interrupt 3,'' so if you see an error like @code{Interrupt -0x03 (#BP Breakpoint Exception)}, Pintos tried to execute code in a -freed page. - -Similarly, the block allocator in @file{threads/malloc.c} clears all -the bytes in freed blocks to @t{0xcd}. The two bytes @t{0xcdcd} are -a CPU opcode for ``invoke interrupt @t{0xcd},'' so @code{Interrupt -0xcd (unknown)} is a good sign that you tried to execute code in a -block freed with @func{free}. +already been freed. Also, byte @t{0xcc} is the CPU opcode for ``invoke +interrupt 3,'' so if you see an error like @code{Interrupt 0x03 (#BP +Breakpoint Exception)}, Pintos tried to execute code in a freed page or +block. + +An assertion failure on the expression @code{sec_no < d->capacity} +indicates that Pintos tried to access a file through an inode that has +been closed and freed. Freeing an inode clears its starting sector +number to @t{0xcccccccc}, which is not a valid sector number for disks +smaller than about 1.6 TB. diff --git a/src/threads/malloc.c b/src/threads/malloc.c index 2077354..0cb5f9d 100644 --- a/src/threads/malloc.c +++ b/src/threads/malloc.c @@ -198,7 +198,7 @@ free (void *p) } #ifndef NDEBUG - memset (b, 0xcd, d->block_size); + memset (b, 0xcc, d->block_size); #endif lock_acquire (&d->lock);