47#define ARENA_MAGIC 0x9a548eed
204 void *new_block =
malloc (new_size);
205 if (old_block !=
NULL && new_block !=
NULL)
208 size_t min_size = new_size < old_size ? new_size : old_size;
209 memcpy (new_block, old_block, min_size);
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
struct list_elem * list_remove(struct list_elem *elem)
Removes ELEM from its list and returns the element that followed it.
struct list_elem * list_pop_front(struct list *list)
Removes the front element from LIST and returns it.
void list_push_front(struct list *list, struct list_elem *elem)
Inserts ELEM at the beginning of LIST, so that it becomes the front in LIST.
bool list_empty(struct list *list)
Returns true if LIST is empty, false otherwise.
void list_init(struct list *list)
Initializes LIST as an empty list.
void list_push_back(struct list *list, struct list_elem *elem)
Inserts ELEM at the end of LIST, so that it becomes the back in LIST.
#define list_entry(LIST_ELEM, STRUCT, MEMBER)
Converts pointer to list element LIST_ELEM into a pointer to the structure that LIST_ELEM is embedded...
void malloc_init(void)
Initializes the malloc() descriptors.
static size_t desc_cnt
Number of descriptors.
static size_t block_size(void *block)
Returns the number of bytes allocated for BLOCK.
static struct arena * block_to_arena(struct block *)
Returns the arena that block B is inside.
void * realloc(void *old_block, size_t new_size)
Attempts to resize OLD_BLOCK to NEW_SIZE bytes, possibly moving it in the process.
#define ARENA_MAGIC
Magic number for detecting arena corruption.
void * calloc(size_t a, size_t b)
Allocates and return A times B bytes initialized to zeroes.
static struct block * arena_to_block(struct arena *, size_t idx)
Returns the (IDX - 1)'th block within arena A.
void * malloc(size_t size)
Obtains and returns a new block of at least SIZE bytes.
void free(void *p)
Frees block P, which must have been previously allocated with malloc(), calloc(), or realloc().
static struct desc descs[10]
Our set of descriptors.
void * palloc_get_page(enum palloc_flags flags)
Obtains a single free page and returns its kernel virtual address.
void * palloc_get_multiple(enum palloc_flags flags, size_t page_cnt)
Obtains and returns a group of PAGE_CNT contiguous free pages.
void palloc_free_page(void *page)
Frees the page at PAGE.
void palloc_free_multiple(void *pages, size_t page_cnt)
Frees the PAGE_CNT pages starting at PAGES.
#define DIV_ROUND_UP(X, STEP)
Yields X divided by STEP, rounded up.
void * memset(void *dst_, int value, size_t size)
Sets the SIZE bytes in DST to VALUE.
void * memcpy(void *dst_, const void *src_, size_t size)
Copies SIZE bytes from SRC to DST, which must not overlap.
size_t free_cnt
Free blocks; pages in big block.
unsigned magic
Always set to ARENA_MAGIC.
struct desc * desc
Owning descriptor, null for big block.
block_sector_t size
Size in sectors.
struct list_elem free_elem
Free list element.
A simple implementation of malloc().
size_t block_size
Size of each element in bytes.
struct list free_list
List of free blocks.
size_t blocks_per_arena
Number of blocks in an arena.
void lock_release(struct lock *lock)
Releases LOCK, which must be owned by the current thread.
void lock_init(struct lock *lock)
Initializes LOCK.
void lock_acquire(struct lock *lock)
Acquires LOCK, sleeping until it becomes available if necessary.
static void * pg_round_down(const void *va)
Round down to nearest page boundary.
#define PGSIZE
Bytes in a page.
static unsigned pg_ofs(const void *va)
Offset within a page.