X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fthreads%2Fpalloc.c;h=a0196ace19665fe13c4c369283e6928c9801d26f;hb=bf866bc97d077fa3757b4aceaa7a6b41e7298c73;hp=011816a3de49e57e6c41badd6ca4595c6b67a4b7;hpb=a98578bf3b6b5c946713654b404a886a7199dbee;p=pintos-anon diff --git a/src/threads/palloc.c b/src/threads/palloc.c index 011816a..a0196ac 100644 --- a/src/threads/palloc.c +++ b/src/threads/palloc.c @@ -1,8 +1,10 @@ #include "palloc.h" #include #include -#include #include "debug.h" +#include "init.h" +#include "loader.h" +#include "lib.h" #include "mmu.h" /* A free page owned by the page allocator. */ @@ -15,10 +17,20 @@ static struct page *free_pages; static uint8_t *uninit_start, *uninit_end; void -palloc_init (uint8_t *start, uint8_t *end) +palloc_init (void) { - uninit_start = start; - uninit_end = end; + /* Kernel static code and data, in 4 kB pages. + + We can figure this out because the linker records the start + and end of the kernel as _start and _end. See + kernel.lds. */ + extern char _start, _end; + size_t kernel_pages; + kernel_pages = (&_end - &_start + 4095) / 4096; + + /* Then we know how much is available to allocate. */ + uninit_start = ptov (LOADER_KERN_BASE + kernel_pages * PGSIZE); + uninit_end = ptov (ram_pages * PGSIZE); } void *