summaryrefslogtreecommitdiffstats
path: root/userprog/process.c
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-06-19 23:31:28 +0200
committermanuel <manuel@mausz.at>2012-06-19 23:31:28 +0200
commitabd273ce0a9ae9267f8b0a144ea9b56d8912f9b5 (patch)
tree15bf5622a6bf7665dfb53a3f557dfaa246f108aa /userprog/process.c
parente88a8c4c379d721e9901752d440a05295087da11 (diff)
downloadprogos-abd273ce0a9ae9267f8b0a144ea9b56d8912f9b5.tar.gz
progos-abd273ce0a9ae9267f8b0a144ea9b56d8912f9b5.tar.bz2
progos-abd273ce0a9ae9267f8b0a144ea9b56d8912f9b5.zip
add dynamic stack growing
Diffstat (limited to 'userprog/process.c')
-rw-r--r--userprog/process.c54
1 files changed, 36 insertions, 18 deletions
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,
552 552
553 file_seek (file, ofs); 553 file_seek (file, ofs);
554 while (read_bytes > 0 || zero_bytes > 0) 554 while (read_bytes > 0 || zero_bytes > 0)
555 { 555 {
556 /* Calculate how to fill this page. 556 /* Calculate how to fill this page.
557 We will read PAGE_READ_BYTES bytes from FILE 557 We will read PAGE_READ_BYTES bytes from FILE
558 and zero the final PAGE_ZERO_BYTES bytes. */ 558 and zero the final PAGE_ZERO_BYTES bytes. */
559 size_t page_read_bytes = read_bytes < PGSIZE ? read_bytes : PGSIZE; 559 size_t page_read_bytes = read_bytes < PGSIZE ? read_bytes : PGSIZE;
560 size_t page_zero_bytes = PGSIZE - page_read_bytes; 560 size_t page_zero_bytes = PGSIZE - page_read_bytes;
561 561
562 /* add segment to page table for on demand loading */ 562 /* add segment to page table for on demand loading */
563 if (!page_table_insert_segment (file, ofs, upage, page_read_bytes, 563 if (!page_table_insert_segment (file, ofs, upage, page_read_bytes,
564 page_zero_bytes, writable)) 564 page_zero_bytes, writable))
565 return false; 565 return false;
566 566
567 /* Advance. */ 567 /* Advance. */
568 read_bytes -= page_read_bytes; 568 read_bytes -= page_read_bytes;
569 zero_bytes -= page_zero_bytes; 569 zero_bytes -= page_zero_bytes;
570 ofs += page_read_bytes; 570 ofs += page_read_bytes;
571 upage += PGSIZE; 571 upage += PGSIZE;
572 } 572 }
573 return true; 573 return true;
574} 574}
575 575
@@ -686,6 +686,24 @@ setup_stack (uint32_t **esp, const char *args)
686 return true; 686 return true;
687} 687}
688 688
689/* expand the stack of the process by one new page
690 which will be installed at the address of UPAGE */
691bool
692process_grow_stack (void *upage)
693{
694 uint8_t *kpage = palloc_get_page (PAL_USER | PAL_ZERO);
695 if (kpage == NULL)
696 return false;
697
698 if (!process_install_page (upage, kpage, true))
699 {
700 palloc_free_page (kpage);
701 return false;
702 }
703
704 return true;
705}
706
689/* Adds a mapping from user virtual address UPAGE to kernel 707/* Adds a mapping from user virtual address UPAGE to kernel
690 virtual address KPAGE to the page table. 708 virtual address KPAGE to the page table.
691 If WRITABLE is true, the user process may modify the page; 709 If WRITABLE is true, the user process may modify the page;