Fix: Avoid closing the file after loading segments to be able to lazily load from file without opening, w/ G
This commit is contained in:
@@ -623,7 +623,6 @@ load (const char *file_name, void (**eip) (void), void **esp)
|
||||
|
||||
done:
|
||||
/* We arrive here whether the load is successful or not. */
|
||||
file_close (file);
|
||||
lock_release (&filesys_lock);
|
||||
return success;
|
||||
}
|
||||
@@ -691,14 +690,13 @@ validate_segment (const struct Elf32_Phdr *phdr, struct file *file)
|
||||
or disk read error occurs. */
|
||||
static bool
|
||||
load_segment (struct file *file, off_t ofs, uint8_t *upage,
|
||||
uint32_t read_bytes, uint32_t zero_bytes, bool writable)
|
||||
uint32_t read_bytes, uint32_t zero_bytes, bool writable)
|
||||
{
|
||||
ASSERT ((read_bytes + zero_bytes) % PGSIZE == 0);
|
||||
ASSERT (pg_ofs (upage) == 0);
|
||||
ASSERT (ofs % PGSIZE == 0);
|
||||
|
||||
file_seek (file, ofs);
|
||||
while (read_bytes > 0 || zero_bytes > 0)
|
||||
while (read_bytes > 0 || zero_bytes > 0)
|
||||
{
|
||||
/* Calculate how to fill this page.
|
||||
We will read PAGE_READ_BYTES bytes from FILE
|
||||
@@ -706,15 +704,15 @@ load_segment (struct file *file, off_t ofs, uint8_t *upage,
|
||||
size_t page_read_bytes = read_bytes < PGSIZE ? read_bytes : PGSIZE;
|
||||
size_t page_zero_bytes = PGSIZE - page_read_bytes;
|
||||
|
||||
/* Add the page to the SPT */
|
||||
/* Add the page metadata to the SPT to be lazy loaded later on */
|
||||
if (page_insert (file, ofs, upage, page_read_bytes, page_zero_bytes,
|
||||
writable, PAGE_EXECUTABLE) == NULL)
|
||||
return false;
|
||||
|
||||
/* Advance. */
|
||||
ofs += page_read_bytes;
|
||||
read_bytes -= page_read_bytes;
|
||||
zero_bytes -= page_zero_bytes;
|
||||
ofs += PGSIZE;
|
||||
upage += PGSIZE;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user