From abd273ce0a9ae9267f8b0a144ea9b56d8912f9b5 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 19 Jun 2012 23:31:28 +0200 Subject: add dynamic stack growing --- userprog/process.c | 54 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'userprog/process.c') diff --git a/userprog/process.c b/userprog/process.c index 15883d9..2771e76 100644 --- a/userprog/process.c +++ b/userprog/process.c @@ -552,24 +552,24 @@ load_segment (struct file *file, off_t ofs, uint8_t *upage, file_seek (file, ofs); while (read_bytes > 0 || zero_bytes > 0) - { - /* Calculate how to fill this page. - We will read PAGE_READ_BYTES bytes from FILE - and zero the final PAGE_ZERO_BYTES bytes. */ - size_t page_read_bytes = read_bytes < PGSIZE ? read_bytes : PGSIZE; - size_t page_zero_bytes = PGSIZE - page_read_bytes; - - /* add segment to page table for on demand loading */ - if (!page_table_insert_segment (file, ofs, upage, page_read_bytes, - page_zero_bytes, writable)) - return false; - - /* Advance. */ - read_bytes -= page_read_bytes; - zero_bytes -= page_zero_bytes; - ofs += page_read_bytes; - upage += PGSIZE; - } + { + /* Calculate how to fill this page. + We will read PAGE_READ_BYTES bytes from FILE + and zero the final PAGE_ZERO_BYTES bytes. */ + size_t page_read_bytes = read_bytes < PGSIZE ? read_bytes : PGSIZE; + size_t page_zero_bytes = PGSIZE - page_read_bytes; + + /* add segment to page table for on demand loading */ + if (!page_table_insert_segment (file, ofs, upage, page_read_bytes, + page_zero_bytes, writable)) + return false; + + /* Advance. */ + read_bytes -= page_read_bytes; + zero_bytes -= page_zero_bytes; + ofs += page_read_bytes; + upage += PGSIZE; + } return true; } @@ -686,6 +686,24 @@ setup_stack (uint32_t **esp, const char *args) return true; } +/* expand the stack of the process by one new page + which will be installed at the address of UPAGE */ +bool +process_grow_stack (void *upage) +{ + uint8_t *kpage = palloc_get_page (PAL_USER | PAL_ZERO); + if (kpage == NULL) + return false; + + if (!process_install_page (upage, kpage, true)) + { + palloc_free_page (kpage); + return false; + } + + return true; +} + /* Adds a mapping from user virtual address UPAGE to kernel virtual address KPAGE to the page table. If WRITABLE is true, the user process may modify the page; -- cgit v1.2.3