PKUOS - Pintos
Pintos source browser for PKU Operating System course
Enumerations | Functions
palloc.h File Reference
#include <stddef.h>
Include dependency graph for palloc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  palloc_flags { PAL_ASSERT = 001 , PAL_ZERO = 002 , PAL_USER = 004 }
 How to allocate pages. More...
 

Functions

void palloc_init (size_t user_page_limit)
 Initializes the page allocator. More...
 
void * palloc_get_page (enum palloc_flags)
 Obtains a single free page and returns its kernel virtual address. More...
 
void * palloc_get_multiple (enum palloc_flags, size_t page_cnt)
 Obtains and returns a group of PAGE_CNT contiguous free pages. More...
 
void palloc_free_page (void *)
 Frees the page at PAGE. More...
 
void palloc_free_multiple (void *, size_t page_cnt)
 threads/palloc.h More...
 

Enumeration Type Documentation

◆ palloc_flags

How to allocate pages.

Enumerator
PAL_ASSERT 

Panic on failure.

PAL_ZERO 

Zero page contents.

PAL_USER 

User page.

Definition at line 7 of file palloc.h.

Function Documentation

◆ palloc_free_multiple()

void palloc_free_multiple ( void *  pages,
size_t  page_cnt 
)

threads/palloc.h

threads/palloc.h

Definition at line 118 of file palloc.c.

References ASSERT, pool::base, bitmap_all(), bitmap_set_multiple(), memset(), NOT_REACHED, NULL, page_from_pool(), pg_no(), pg_ofs(), PGSIZE, pool::used_map, and user_pool.

Referenced by free(), and palloc_free_page().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ palloc_free_page()

void palloc_free_page ( void *  page)

Frees the page at PAGE.

Definition at line 146 of file palloc.c.

References palloc_free_multiple().

Referenced by free(), fsutil_cat(), load_segment(), pagedir_destroy(), process_execute(), setup_stack(), start_process(), and thread_schedule_tail().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ palloc_get_multiple()

void * palloc_get_multiple ( enum palloc_flags  flags,
size_t  page_cnt 
)

Obtains and returns a group of PAGE_CNT contiguous free pages.

If PAL_USER is set, the pages are obtained from the user pool, otherwise from the kernel pool. If PAL_ZERO is set in FLAGS, then the pages are filled with zeros. If too few pages are available, returns a null pointer, unless PAL_ASSERT is set in FLAGS, in which case the kernel panics.

Definition at line 71 of file palloc.c.

References pool::base, BITMAP_ERROR, bitmap_scan_and_flip(), pool::lock, lock_acquire(), lock_release(), memset(), NULL, PAL_ASSERT, PAL_USER, PAL_ZERO, PANIC, PGSIZE, pool::used_map, and user_pool.

Referenced by malloc(), and palloc_get_page().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ palloc_get_page()

void * palloc_get_page ( enum palloc_flags  flags)

Obtains a single free page and returns its kernel virtual address.

If PAL_USER is set, the page is obtained from the user pool, otherwise from the kernel pool. 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.

Definition at line 111 of file palloc.c.

References palloc_get_multiple().

Referenced by fsutil_cat(), load_segment(), lookup_page(), malloc(), pagedir_create(), paging_init(), process_execute(), setup_stack(), thread_create(), and tss_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ palloc_init()

void palloc_init ( size_t  user_page_limit)

Initializes the page allocator.

At most USER_PAGE_LIMIT pages are put into the user pool.

Definition at line 46 of file palloc.c.

References init_pool(), init_ram_pages, PGSIZE, ptov(), user_page_limit, and user_pool.

Referenced by pintos_init().

Here is the call graph for this function:
Here is the caller graph for this function: