projects
/
pintos-anon
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add TODOs.
[pintos-anon]
/
src
/
threads
/
malloc.c
diff --git
a/src/threads/malloc.c
b/src/threads/malloc.c
index 487e93875ef4124ac314a7355429d4c2a632d1ab..8e6b4591ea87ecae09337ae5d741c89a68bdcb9a 100644
(file)
--- a/
src/threads/malloc.c
+++ b/
src/threads/malloc.c
@@
-161,7
+161,7
@@
calloc (size_t a, size_t b)
void *p;
size_t size;
void *p;
size_t size;
- /* Calculate block size. */
+ /* Calculate block size
and make sure it fits in size_t
. */
size = a * b;
if (size < a || size < b)
return NULL;
size = a * b;
if (size < a || size < b)
return NULL;
@@
-198,7
+198,7
@@
free (void *p)
}
#ifndef NDEBUG
}
#ifndef NDEBUG
- memset (b, 0xc
d
, d->block_size);
+ memset (b, 0xc
c
, d->block_size);
#endif
lock_acquire (&d->lock);
#endif
lock_acquire (&d->lock);
@@
-228,8
+228,16
@@
static struct arena *
block_to_arena (struct block *b)
{
struct arena *a = pg_round_down (b);
block_to_arena (struct block *b)
{
struct arena *a = pg_round_down (b);
+
+ /* Check that the arena is valid. */
ASSERT (a != NULL);
ASSERT (a->magic == ARENA_MAGIC);
ASSERT (a != NULL);
ASSERT (a->magic == ARENA_MAGIC);
+
+ /* Check that the block is properly aligned for the arena. */
+ ASSERT (a->desc == NULL
+ || (pg_ofs (b) - sizeof *a) % a->desc->block_size == 0);
+ ASSERT (a->desc != NULL || pg_ofs (b) == sizeof *a);
+
return a;
}
return a;
}