summaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1995-05-17 19:51:47 +0000
committerMiles Bader <miles@gnu.org>1995-05-17 19:51:47 +0000
commit5b3455338f71d2194eec9eeba02a6cbab5ee3d1a (patch)
treedc458ce20db8884ace782935eac4744226042e2d /boot
parent4fc6cc2eda19e92f48746202e020beb26d8fc8e4 (diff)
(load_image): Make sure we actually allocate enough memory to read into,
including the offset into the buffer at which the segment is read.
Diffstat (limited to 'boot')
-rw-r--r--boot/boot.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/boot/boot.c b/boot/boot.c
index 9ab14725..e2e6ef83 100644
--- a/boot/boot.c
+++ b/boot/boot.c
@@ -279,14 +279,19 @@ load_image (task_t t,
if (ph->p_type == PT_LOAD)
{
vm_address_t buf;
- vm_size_t bufsz = round_page (ph->p_filesz);
+ vm_size_t offs = ph->p_offset & (ph->p_align - 1);
+ vm_size_t bufsz = round_page (ph->p_filesz + offs);
+
vm_allocate (mach_task_self (), &buf, bufsz, 1);
+
lseek (fd, ph->p_offset, SEEK_SET);
- read (fd, buf + (ph->p_offset & (ph->p_align - 1)), ph->p_filesz);
+ read (fd, buf + offs, ph->p_filesz);
+
ph->p_memsz = ((ph->p_vaddr + ph->p_memsz + ph->p_align - 1)
& ~(ph->p_align - 1));
ph->p_vaddr &= ~(ph->p_align - 1);
ph->p_memsz -= ph->p_vaddr;
+
vm_allocate (t, (vm_address_t*)&ph->p_vaddr, ph->p_memsz, 0);
vm_write (t, ph->p_vaddr, buf, bufsz);
vm_deallocate (mach_task_self (), buf, bufsz);