projects
/
pintos-anon
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update.
[pintos-anon]
/
src
/
userprog
/
process.c
diff --git
a/src/userprog/process.c
b/src/userprog/process.c
index 5b50aa53a199e64001302574428091436809aaf8..b8d4a14462c63faecf6ac69944db4180b83d2914 100644
(file)
--- a/
src/userprog/process.c
+++ b/
src/userprog/process.c
@@
-31,7
+31,7
@@
process_execute (const char *filename)
/* Make a copy of FILENAME.
Otherwise there's a race between the caller and load(). */
/* Make a copy of FILENAME.
Otherwise there's a race between the caller and load(). */
- fn_copy = palloc_get (0);
+ fn_copy = palloc_get
_page
(0);
if (fn_copy == NULL)
return TID_ERROR;
strlcpy (fn_copy, filename, PGSIZE);
if (fn_copy == NULL)
return TID_ERROR;
strlcpy (fn_copy, filename, PGSIZE);
@@
-39,7
+39,7
@@
process_execute (const char *filename)
/* Create a new thread to execute FILENAME. */
tid = thread_create (filename, PRI_DEFAULT, execute_thread, fn_copy);
if (tid == TID_ERROR)
/* Create a new thread to execute FILENAME. */
tid = thread_create (filename, PRI_DEFAULT, execute_thread, fn_copy);
if (tid == TID_ERROR)
- palloc_free (fn_copy);
+ palloc_free
_page
(fn_copy);
return tid;
}
return tid;
}
@@
-62,7
+62,7
@@
execute_thread (void *filename_)
success = load (filename, &if_.eip, &if_.esp);
/* If load failed, quit. */
success = load (filename, &if_.eip, &if_.esp);
/* If load failed, quit. */
- palloc_free (filename);
+ palloc_free
_page
(filename);
if (!success)
thread_exit ();
if (!success)
thread_exit ();
@@
-227,7
+227,7
@@
load (const char *filename, void (**eip) (void), void **esp)
if (ehdr.e_machine != 3)
LOAD_ERROR (("ELF executable is not x86"));
if (ehdr.e_version != 1)
if (ehdr.e_machine != 3)
LOAD_ERROR (("ELF executable is not x86"));
if (ehdr.e_version != 1)
- LOAD_ERROR (("ELF executable hasunknown version %d",
+ LOAD_ERROR (("ELF executable has
unknown version %d",
(int) ehdr.e_version));
if (ehdr.e_phentsize != sizeof (struct Elf32_Phdr))
LOAD_ERROR (("bad ELF program header size"));
(int) ehdr.e_version));
if (ehdr.e_phentsize != sizeof (struct Elf32_Phdr))
LOAD_ERROR (("bad ELF program header size"));
@@
-240,7
+240,10
@@
load (const char *filename, void (**eip) (void), void **esp)
{
struct Elf32_Phdr phdr;
{
struct Elf32_Phdr phdr;
+ if (file_ofs < 0 || file_ofs > file_length (file))
+ LOAD_ERROR (("bad file offset %ld", (long) file_ofs));
file_seek (file, file_ofs);
file_seek (file, file_ofs);
+
if (file_read (file, &phdr, sizeof phdr) != sizeof phdr)
LOAD_ERROR (("error reading program header"));
file_ofs += sizeof phdr;
if (file_read (file, &phdr, sizeof phdr) != sizeof phdr)
LOAD_ERROR (("error reading program header"));
file_ofs += sizeof phdr;
@@
-316,6
+319,13
@@
load_segment (struct file *file, const struct Elf32_Phdr *phdr)
return false;
}
return false;
}
+ /* p_offset must point within file. */
+ if (phdr->p_offset < 0 || phdr->p_offset > file_length (file))
+ {
+ printf ("bad p_offset %"PE32Ox, phdr->p_offset);
+ return false;
+ }
+
/* [ELF1] 2-3 says that p_memsz must be at least as big as
p_filesz. */
if (phdr->p_memsz < phdr->p_filesz)
/* [ELF1] 2-3 says that p_memsz must be at least as big as
p_filesz. */
if (phdr->p_memsz < phdr->p_filesz)
@@
-347,14
+357,14
@@
load_segment (struct file *file, const struct Elf32_Phdr *phdr)
file into the page and zero the rest. */
size_t read_bytes = filesz_left >= PGSIZE ? PGSIZE : filesz_left;
size_t zero_bytes = PGSIZE - read_bytes;
file into the page and zero the rest. */
size_t read_bytes = filesz_left >= PGSIZE ? PGSIZE : filesz_left;
size_t zero_bytes = PGSIZE - read_bytes;
- uint8_t *kpage = palloc_get (PAL_USER);
+ uint8_t *kpage = palloc_get
_page
(PAL_USER);
if (kpage == NULL)
return false;
/* Do the reading and zeroing. */
if (file_read (file, kpage, read_bytes) != (int) read_bytes)
{
if (kpage == NULL)
return false;
/* Do the reading and zeroing. */
if (file_read (file, kpage, read_bytes) != (int) read_bytes)
{
- palloc_free (kpage);
+ palloc_free
_page
(kpage);
return false;
}
memset (kpage + read_bytes, 0, zero_bytes);
return false;
}
memset (kpage + read_bytes, 0, zero_bytes);
@@
-363,7
+373,7
@@
load_segment (struct file *file, const struct Elf32_Phdr *phdr)
/* Add the page to the process's address space. */
if (!install_page (upage, kpage))
{
/* Add the page to the process's address space. */
if (!install_page (upage, kpage))
{
- palloc_free (kpage);
+ palloc_free
_page
(kpage);
return false;
}
}
return false;
}
}
@@
-379,14
+389,14
@@
setup_stack (void **esp)
uint8_t *kpage;
bool success = false;
uint8_t *kpage;
bool success = false;
- kpage = palloc_get (PAL_USER | PAL_ZERO);
+ kpage = palloc_get
_page
(PAL_USER | PAL_ZERO);
if (kpage != NULL)
{
success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage);
if (success)
*esp = PHYS_BASE;
else
if (kpage != NULL)
{
success = install_page (((uint8_t *) PHYS_BASE) - PGSIZE, kpage);
if (success)
*esp = PHYS_BASE;
else
- palloc_free (kpage);
+ palloc_free
_page
(kpage);
}
else
printf ("failed to allocate process stack\n");
}
else
printf ("failed to allocate process stack\n");