-#include "palloc.h"
+#include "threads/palloc.h"
+#include <debug.h>
+#include <list.h>
#include <stddef.h>
#include <stdint.h>
-#include "debug.h"
-#include "init.h"
-#include "loader.h"
-#include "lib.h"
-#include "list.h"
-#include "mmu.h"
-#include "synch.h"
+#include <string.h>
+#include "threads/init.h"
+#include "threads/loader.h"
+#include "threads/mmu.h"
+#include "threads/synch.h"
/* Page allocator. Hands out memory in page-size chunks.
See malloc.h for an allocator that hands out smaller
list_init (&free_pages);
}
+/* Obtains and returns a free page. If PAL_ZERO is set in FLAGS,
+ then the page is filled with zeros. If no pages are
+ available, returns a null pointer, unless PAL_ASSERT is set in
+ FLAGS, in which case the kernel panics. */
void *
palloc_get (enum palloc_flags flags)
{
lock_acquire (&lock);
+ /* If there's a page in the free list, take it.
+ Otherwise, if there's a page not yet added to the free list,
+ use it.
+ Otherwise, we're out of memory. */
if (!list_empty (&free_pages))
page = list_entry (list_pop_front (&free_pages), struct page, free_elem);
else if (uninit_start < uninit_end)
return page;
}
+/* Frees PAGE. */
void
palloc_free (void *page_)
{