Don't read anything from the disk for a segment with p_filesz == 0.
[pintos-anon] / src / userprog / process.c
index 58e81fd173d36c5bb0282f5ef29a05cb71ef8cff..8c410aba98519a273d5d7a60155468f5b4ffc556 100644 (file)
@@ -71,7 +71,7 @@ execute_thread (void *filename_)
      arguments on the stack in the form of a `struct intr_frame',
      we just point the stack pointer (%esp) to our stack frame
      and jump to it. */
-  asm ("mov %%esp, %0; jmp intr_exit" :: "g" (&if_));
+  asm ("movl %0, %%esp; jmp intr_exit" :: "g" (&if_));
   NOT_REACHED ();
 }
 
@@ -333,7 +333,9 @@ load_segment (struct file *file, const struct Elf32_Phdr *phdr)
     return false; 
 
   /* Load the segment page-by-page into memory. */
-  filesz_left = phdr->p_filesz + (phdr->p_vaddr & PGMASK);
+  filesz_left = phdr->p_filesz;
+  if (filesz_left > 0)
+    filesz_left += phdr->p_vaddr & PGMASK;
   file_seek (file, ROUND_DOWN (phdr->p_offset, PGSIZE));
   for (upage = start; upage < (uint8_t *) end; upage += PGSIZE) 
     {
@@ -386,8 +388,12 @@ setup_stack (void **esp)
 }
 
 /* Adds a mapping from user virtual address UPAGE to kernel
-   virtual address KPAGE to the page table.  Fails if UPAGE is
-   already mapped or if memory allocation fails. */
+   virtual address KPAGE to the page table.
+   UPAGE must not already be mapped.
+   KPAGE should probably be a page obtained from the user pool
+   with palloc_get_page().
+   Returns true on success, false if UPAGE is already mapped or
+   if memory allocation fails. */
 static bool
 install_page (void *upage, void *kpage)
 {