-@@ -296,6 +421,7 @@ load_segment (struct file *file, const s
- {
- void *start, *end; /* Page-rounded segment start and end. */
- uint8_t *upage; /* Iterator from start to end. */
-+ off_t file_offset; /* Offset into file. */
- off_t filesz_left; /* Bytes left of file data (as opposed to
- zero-initialized bytes). */
-
-@@ -303,7 +429,7 @@ load_segment (struct file *file, const s
- commented out. You'll want to use it when implementing VM
- to decide whether to page the segment from its executable or
- from swap. */
-- //bool read_only = (phdr->p_flags & PF_W) == 0;
-+ bool read_only = (phdr->p_flags & PF_W) == 0;
-
- ASSERT (file != NULL);
- ASSERT (phdr != NULL);
-@@ -332,73 +458,129 @@ load_segment (struct file *file, const s
- || start == 0)
- return false;
-
-- /* Load the segment page-by-page into memory. */
-+ /* Add the segment page-by-page to the hash table. */
- filesz_left = phdr->p_filesz + (phdr->p_vaddr & PGMASK);
-- file_seek (file, ROUND_DOWN (phdr->p_offset, PGSIZE));
-+ file_offset = ROUND_DOWN (phdr->p_offset, PGSIZE);
- for (upage = start; upage < (uint8_t *) end; upage += PGSIZE)
+@@ -387,79 +497,127 @@ load_segment (struct file *file, off_t o
+ ASSERT (pg_ofs (upage) == 0);
+ ASSERT (ofs % PGSIZE == 0);
+
+- file_seek (file, ofs);
+ while (read_bytes > 0 || zero_bytes > 0)