summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bushnell <thomas@gnu.org>1999-04-30 11:04:07 +0000
committerThomas Bushnell <thomas@gnu.org>1999-04-30 11:04:07 +0000
commitd3fe02c2d320bfde339c87981c32f1d9b3581952 (patch)
tree1e4189918b3d00dc2cff090e6af0c90ad3288e26
parenta45f97ca1a2a30f16fd5e329160c8dae7c7b6392 (diff)
1998-09-06 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
* bunzip2.c: New file. * load.c (GZIP) (BZIP2): New cpp constants. (boot_script_exec_cmd): If GZIP is defined, gunzip engine is enabled. If BZIP2 is defined, bunzip2 engine is enabled. * Makefile (SRCS): Add bunzip2.c. (UNZIP_OBJS): Add do-bunzip2.o. (CPPFLAGS): Add -DGZIP, -DBZIP2 and -DSMALL_BZIP2. 1998-09-03 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp> * gunzip.c: New file. Copy libstore/gunzip.c and modify for use in serverboot. * load.c (struct stuff): Add members, image_addr and image_size. (mem_read) (mem_read_exec): New functions. (boot_script_exec_cmd): Add gzexe feature. * Makefile: Add unzip stuffs.
-rw-r--r--serverboot/ChangeLog19
-rw-r--r--serverboot/Makefile16
-rw-r--r--serverboot/bunzip2.c169
-rw-r--r--serverboot/gunzip.c188
-rw-r--r--serverboot/load.c134
5 files changed, 522 insertions, 4 deletions
diff --git a/serverboot/ChangeLog b/serverboot/ChangeLog
index 850a82dc..715145c4 100644
--- a/serverboot/ChangeLog
+++ b/serverboot/ChangeLog
@@ -1,3 +1,22 @@
+1998-09-06 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
+
+ * bunzip2.c: New file.
+ * load.c (GZIP) (BZIP2): New cpp constants.
+ (boot_script_exec_cmd): If GZIP is defined, gunzip engine is enabled.
+ If BZIP2 is defined, bunzip2 engine is enabled.
+ * Makefile (SRCS): Add bunzip2.c.
+ (UNZIP_OBJS): Add do-bunzip2.o.
+ (CPPFLAGS): Add -DGZIP, -DBZIP2 and -DSMALL_BZIP2.
+
+1998-09-03 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
+
+ * gunzip.c: New file.
+ Copy libstore/gunzip.c and modify for use in serverboot.
+ * load.c (struct stuff): Add members, image_addr and image_size.
+ (mem_read) (mem_read_exec): New functions.
+ (boot_script_exec_cmd): Add gzexe feature.
+ * Makefile: Add unzip stuffs.
+
1999-03-06 Roland McGrath <roland@baalperazim.frob.com>
* def_pager_setup.c (default_pager_setup): #if 0 out unused function.
diff --git a/serverboot/Makefile b/serverboot/Makefile
index 12ff6375..d2ab975d 100644
--- a/serverboot/Makefile
+++ b/serverboot/Makefile
@@ -21,10 +21,7 @@ makemode := utility
SRCS = bootstrap.c ffs_compat.c load.c wiring.c def_pager_setup.c \
ffs_file_io.c minix_ffs_compat.c default_pager.c file_io.c\
minix_file_io.c ext2_file_io.c kalloc.c strfcns.c exec.c \
- panic.c elf-load.c
-OBJS = $(subst .c,.o,$(SRCS)) boot_script.o memory_objectServer.o \
- default_pagerServer.o excServer.o bootstrapServer.o \
- memory_object_defaultServer.o
+ panic.c elf-load.c gunzip.c bunzip2.c
LCLHDRS = assert.h disk_inode_ffs.h fs.h queue.h defs.h ext2_fs.h \
minix_ffs_compat.h wiring.h dir.h ffs_compat.h minix_fs.h \
disk_inode.h file_io.h minix_super.h mach-exec.h
@@ -32,8 +29,19 @@ target = serverboot
HURDLIBS = threads
installationdir = $(prefix)/boot
+UNZIP_OBJS = unzip.o inflate.o util.o do-bunzip2.o
+OBJS = $(subst .c,.o,$(SRCS)) boot_script.o memory_objectServer.o \
+ default_pagerServer.o excServer.o bootstrapServer.o \
+ memory_object_defaultServer.o $(UNZIP_OBJS)
+
vpath boot_script.c $(srcdir)/../boot
+# Look for zip stuff
+VPATH += $(srcdir)/../exec
+# If SMALL_BZIP2 is defined, use relatively small memory.
+# It's crucial for serverboot, because swap is not enabled yet.
+CPPFLAGS += -I$(srcdir)/../exec -DGZIP -DBZIP2 -DSMALL_BZIP2
+
MIGSFLAGS = -DSEQNOS
LDFLAGS += -static
diff --git a/serverboot/bunzip2.c b/serverboot/bunzip2.c
new file mode 100644
index 00000000..9f79ade5
--- /dev/null
+++ b/serverboot/bunzip2.c
@@ -0,0 +1,169 @@
+/* Modified by okuji@kuicr.kyoto-u.ac.jp for use in serverboot. */
+/* Decompressing store backend
+
+ Copyright (C) 1997 Free Software Foundation, Inc.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <stdio.h>
+#include <string.h>
+#include <setjmp.h>
+#include <cthreads.h>
+#include <errno.h>
+
+#include <file_io.h>
+
+#define IN_BUFFERING (256*1024)
+#define OUT_BUFFERING (512*1024)
+
+static struct mutex bunzip2_lock = MUTEX_INITIALIZER;
+
+/* Uncompress the contents of FROM, which should contain a valid bzip2 file,
+ into memory, returning the result buffer in BUF & BUF_LEN. */
+int
+serverboot_bunzip2 (struct file *from, void **buf, size_t *buf_len)
+{
+ /* Callbacks from do_bunzip2 for I/O and error interface. */
+ extern int (*unzip_read) (char *buf, size_t maxread);
+ extern void (*unzip_write) (const char *buf, size_t nwrite);
+ extern void (*unzip_read_error) (void);
+ extern void (*unzip_error) (const char *msg);
+
+ /* How we return errors from our hook functions. */
+ jmp_buf zerr_jmp_buf;
+ int zerr;
+
+ size_t offset = 0; /* Offset of read point in FROM. */
+
+ /* Read at most MAXREAD (or 0 if eof) bytes into BUF from our current
+ position in FROM. */
+ int zread (char *buf, size_t maxread)
+ {
+ vm_size_t resid;
+ size_t did_read;
+
+ if (from->f_size - offset < maxread)
+ did_read = from->f_size - offset;
+ else
+ did_read = maxread;
+
+ zerr = read_file (from, offset, buf, did_read, &resid);
+ if (zerr)
+ longjmp (zerr_jmp_buf, 1);
+
+ did_read -= resid;
+ offset += did_read;
+
+ return did_read;
+ }
+
+ size_t out_buf_offs = 0; /* Position in the output buffer. */
+
+ /* Write uncompress data to our output buffer. */
+ void zwrite (const char *wbuf, size_t nwrite)
+ {
+ size_t old_buf_len = *buf_len;
+
+ if (out_buf_offs + nwrite > old_buf_len)
+ /* Have to grow the output buffer. */
+ {
+ void *old_buf = *buf;
+ void *new_buf = old_buf + old_buf_len; /* First try. */
+ size_t new_buf_len = round_page (old_buf_len + old_buf_len + nwrite);
+
+ /* Try to grow the buffer. */
+ zerr =
+ vm_allocate (mach_task_self (),
+ (vm_address_t *)&new_buf, new_buf_len - old_buf_len,
+ 0);
+ if (zerr)
+ /* Can't do that, try to make a bigger buffer elsewhere. */
+ {
+ new_buf = old_buf;
+ zerr =
+ vm_allocate (mach_task_self (),
+ (vm_address_t *)&new_buf, new_buf_len, 1);
+ if (zerr)
+ longjmp (zerr_jmp_buf, 1);
+
+ if (out_buf_offs > 0)
+ /* Copy the old buffer into the start of the new & free it. */
+ bcopy (old_buf, new_buf, out_buf_offs);
+
+ vm_deallocate (mach_task_self (),
+ (vm_address_t)old_buf, old_buf_len);
+
+ *buf = new_buf;
+ }
+
+ *buf_len = new_buf_len;
+ }
+
+ bcopy (wbuf, *buf + out_buf_offs, nwrite);
+ out_buf_offs += nwrite;
+ }
+
+ void zreaderr (void)
+ {
+ zerr = EIO;
+ longjmp (zerr_jmp_buf, 1);
+ }
+ void zerror (const char *msg)
+ {
+ zerr = EINVAL;
+ longjmp (zerr_jmp_buf, 2);
+ }
+
+ /* Try to guess a reasonable output buffer size. */
+ *buf_len = round_page (from->f_size * 2);
+ zerr = vm_allocate (mach_task_self (), (vm_address_t *)buf, *buf_len, 1);
+ if (zerr)
+ return zerr;
+
+ mutex_lock (&bunzip2_lock);
+
+ unzip_read = zread;
+ unzip_write = zwrite;
+ unzip_read_error = zreaderr;
+ unzip_error = zerror;
+
+ if (! setjmp (zerr_jmp_buf))
+ {
+ /* Call the bunzip2 engine. */
+ do_bunzip2 ();
+ zerr = 0;
+ }
+
+ mutex_unlock (&bunzip2_lock);
+
+ if (zerr)
+ {
+ if (*buf_len > 0)
+ vm_deallocate (mach_task_self (), (vm_address_t)*buf, *buf_len);
+ }
+ else if (out_buf_offs < *buf_len)
+ /* Trim the output buffer to be the right length. */
+ {
+ size_t end = round_page (out_buf_offs);
+ if (end < *buf_len)
+ vm_deallocate (mach_task_self (),
+ (vm_address_t)(*buf + end), *buf_len - end);
+ *buf_len = out_buf_offs;
+ }
+
+ return zerr;
+}
diff --git a/serverboot/gunzip.c b/serverboot/gunzip.c
new file mode 100644
index 00000000..f74da111
--- /dev/null
+++ b/serverboot/gunzip.c
@@ -0,0 +1,188 @@
+/* Modified by okuji@kuicr.kyoto-u.ac.jp for use in serverboot. */
+/* Decompressing store backend
+
+ Copyright (C) 1997 Free Software Foundation, Inc.
+ Written by Miles Bader <miles@gnu.ai.mit.edu>
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
+
+#include <stdio.h>
+#include <string.h>
+#include <setjmp.h>
+#include <cthreads.h>
+#include <errno.h>
+
+#include <file_io.h>
+
+/* gzip.h makes several annoying defines & decls, which we have to work
+ around. */
+#define file_t gzip_file_t
+#include "gzip.h"
+#undef file_t
+#undef head
+
+#define IN_BUFFERING (256*1024)
+#define OUT_BUFFERING (512*1024)
+
+static struct mutex unzip_lock = MUTEX_INITIALIZER;
+
+/* Uncompress the contents of FROM, which should contain a valid gzip file,
+ into memory, returning the result buffer in BUF & BUF_LEN. */
+int
+serverboot_gunzip (struct file *from, void **buf, size_t *buf_len)
+{
+ /* Entry points to unzip engine. */
+ int get_method (int);
+ extern long int bytes_out;
+ /* Callbacks from unzip for I/O and error interface. */
+ extern int (*unzip_read) (char *buf, size_t maxread);
+ extern void (*unzip_write) (const char *buf, size_t nwrite);
+ extern void (*unzip_read_error) (void);
+ extern void (*unzip_error) (const char *msg);
+
+ /* How we return errors from our hook functions. */
+ jmp_buf zerr_jmp_buf;
+ int zerr;
+
+ size_t offset = 0; /* Offset of read point in FROM. */
+
+ /* Read at most MAXREAD (or 0 if eof) bytes into BUF from our current
+ position in FROM. */
+ int zread (char *buf, size_t maxread)
+ {
+ vm_size_t resid;
+ size_t did_read;
+
+ if (from->f_size - offset < maxread)
+ did_read = from->f_size - offset;
+ else
+ did_read = maxread;
+
+ zerr = read_file (from, offset, buf, did_read, &resid);
+ if (zerr)
+ longjmp (zerr_jmp_buf, 1);
+
+ did_read -= resid;
+ offset += did_read;
+
+ return did_read;
+ }
+
+ size_t out_buf_offs = 0; /* Position in the output buffer. */
+
+ /* Write uncompress data to our output buffer. */
+ void zwrite (const char *wbuf, size_t nwrite)
+ {
+ size_t old_buf_len = *buf_len;
+
+ if (out_buf_offs + nwrite > old_buf_len)
+ /* Have to grow the output buffer. */
+ {
+ void *old_buf = *buf;
+ void *new_buf = old_buf + old_buf_len; /* First try. */
+ size_t new_buf_len = round_page (old_buf_len + old_buf_len + nwrite);
+
+ /* Try to grow the buffer. */
+ zerr =
+ vm_allocate (mach_task_self (),
+ (vm_address_t *)&new_buf, new_buf_len - old_buf_len,
+ 0);
+ if (zerr)
+ /* Can't do that, try to make a bigger buffer elsewhere. */
+ {
+ new_buf = old_buf;
+ zerr =
+ vm_allocate (mach_task_self (),
+ (vm_address_t *)&new_buf, new_buf_len, 1);
+ if (zerr)
+ longjmp (zerr_jmp_buf, 1);
+
+ if (out_buf_offs > 0)
+ /* Copy the old buffer into the start of the new & free it. */
+ bcopy (old_buf, new_buf, out_buf_offs);
+
+ vm_deallocate (mach_task_self (),
+ (vm_address_t)old_buf, old_buf_len);
+
+ *buf = new_buf;
+ }
+
+ *buf_len = new_buf_len;
+ }
+
+ bcopy (wbuf, *buf + out_buf_offs, nwrite);
+ out_buf_offs += nwrite;
+ }
+
+ void zreaderr (void)
+ {
+ zerr = EIO;
+ longjmp (zerr_jmp_buf, 1);
+ }
+ void zerror (const char *msg)
+ {
+ zerr = EINVAL;
+ longjmp (zerr_jmp_buf, 2);
+ }
+
+ /* Try to guess a reasonable output buffer size. */
+ *buf_len = round_page (from->f_size * 2);
+ zerr = vm_allocate (mach_task_self (), (vm_address_t *)buf, *buf_len, 1);
+ if (zerr)
+ return zerr;
+
+ mutex_lock (&unzip_lock);
+
+ unzip_read = zread;
+ unzip_write = zwrite;
+ unzip_read_error = zreaderr;
+ unzip_error = zerror;
+
+ if (! setjmp (zerr_jmp_buf))
+ {
+ if (get_method (0) != 0)
+ /* Not a happy gzip file. */
+ zerr = EINVAL;
+ else
+ /* Matched gzip magic number. Ready to unzip.
+ Set up the output stream and let 'er rip. */
+ {
+ /* Call the gunzip engine. */
+ bytes_out = 0;
+ unzip (17, 23); /* Arguments ignored. */
+ zerr = 0;
+ }
+ }
+
+ mutex_unlock (&unzip_lock);
+
+ if (zerr)
+ {
+ if (*buf_len > 0)
+ vm_deallocate (mach_task_self (), (vm_address_t)*buf, *buf_len);
+ }
+ else if (out_buf_offs < *buf_len)
+ /* Trim the output buffer to be the right length. */
+ {
+ size_t end = round_page (out_buf_offs);
+ if (end < *buf_len)
+ vm_deallocate (mach_task_self (),
+ (vm_address_t)(*buf + end), *buf_len - end);
+ *buf_len = out_buf_offs;
+ }
+
+ return zerr;
+}
diff --git a/serverboot/load.c b/serverboot/load.c
index a4bb43c3..878bddb9 100644
--- a/serverboot/load.c
+++ b/serverboot/load.c
@@ -41,6 +41,10 @@ struct stuff
struct file *fp;
task_t user_task;
+ /* uncompressed image */
+ vm_offset_t image_addr;
+ vm_size_t image_size;
+
vm_offset_t aout_symtab_ofs;
vm_size_t aout_symtab_size;
vm_offset_t aout_strtab_ofs;
@@ -149,6 +153,86 @@ static int prog_read_exec(void *handle, vm_offset_t file_ofs, vm_size_t file_siz
return 0;
}
+/* Callback functions for reading the uncompressed image. */
+static int image_read(void *handle, vm_offset_t file_ofs, void *buf,
+ vm_size_t size, vm_size_t *out_actual)
+{
+ struct stuff *st = handle;
+ bcopy(st->image_addr + file_ofs, buf, size);
+ *out_actual = size;
+ return 0;
+}
+
+static int image_read_exec(void *handle, vm_offset_t file_ofs,
+ vm_size_t file_size, vm_offset_t mem_addr,
+ vm_size_t mem_size, exec_sectype_t sec_type)
+{
+ struct stuff *st = handle;
+ vm_offset_t page_start = trunc_page(mem_addr);
+ vm_offset_t page_end = round_page(mem_addr + mem_size);
+ vm_prot_t mem_prot = sec_type & EXEC_SECTYPE_PROT_MASK;
+ vm_offset_t area_start;
+ int result;
+
+ if (sec_type & EXEC_SECTYPE_AOUT_SYMTAB)
+ {
+ st->aout_symtab_ofs = file_ofs;
+ st->aout_symtab_size = file_size;
+ }
+ if (sec_type & EXEC_SECTYPE_AOUT_STRTAB)
+ {
+ st->aout_strtab_ofs = file_ofs;
+ st->aout_strtab_size = file_size;
+ }
+
+ if (!(sec_type & EXEC_SECTYPE_ALLOC))
+ return 0;
+
+ assert(mem_size > 0);
+ assert(mem_size > file_size);
+
+ /*
+ printf("section %08x-%08x-%08x prot %08x (%08x-%08x)\n",
+ mem_addr, mem_addr+file_size, mem_addr+mem_size, mem_prot, page_start, page_end);
+ */
+
+ result = vm_allocate(mach_task_self(), &area_start, page_end - page_start, TRUE);
+ if (result) return (result);
+
+ if (file_size > 0)
+ {
+ bcopy(st->image_addr + file_ofs, area_start + (mem_addr - page_start),
+ file_size);
+ }
+
+ if (mem_size > file_size)
+ {
+ bzero((void*)area_start + (mem_addr + file_size - page_start),
+ mem_size - file_size);
+ }
+
+ result = vm_allocate(st->user_task, &page_start, page_end - page_start, FALSE);
+ if (result) return (result);
+ assert(page_start == trunc_page(mem_addr));
+
+ result = vm_write(st->user_task, page_start, area_start, page_end - page_start);
+ if (result) return (result);
+
+ result = vm_deallocate(mach_task_self(), area_start, page_end - page_start);
+ if (result) return (result);
+
+ /*
+ * Protect the segment.
+ */
+ if (load_protect_text && (mem_prot != VM_PROT_ALL)) {
+ result = vm_protect(st->user_task, page_start, page_end - page_start,
+ FALSE, mem_prot);
+ if (result) return (result);
+ }
+
+ return 0;
+}
+
mach_port_t boot_script_read_file (const char *file)
{ return MACH_PORT_NULL; } /* XXX */
@@ -216,6 +300,56 @@ boot_script_exec_cmd (task_t user_task,
st.aout_symtab_size = 0;
st.aout_strtab_size = 0;
result = exec_load(prog_read, prog_read_exec, &st, &info);
+#ifdef GZIP
+ if (result)
+ {
+ /*
+ * It might be gzip file.
+ */
+ int err;
+ extern int
+ serverboot_gunzip(struct file *, void **, size_t *);
+
+ err = serverboot_gunzip(st.fp,
+ &(st.image_addr),
+ &(st.image_size));
+ if (!err)
+ {
+ result = exec_load(image_read,
+ image_read_exec,
+ &st,
+ &info);
+ vm_deallocate(mach_task_self(),
+ st.image_addr,
+ st.image_size);
+ }
+ }
+#endif GZIP
+#ifdef BZIP2
+ if (result)
+ {
+ /*
+ * It might be bzip2 file.
+ */
+ int err;
+ extern int
+ serverboot_bunzip2(struct file *, void **, size_t *);
+
+ err = serverboot_bunzip2(st.fp,
+ &(st.image_addr),
+ &(st.image_size));
+ if (!err)
+ {
+ result = exec_load(image_read,
+ image_read_exec,
+ &st,
+ &info);
+ vm_deallocate(mach_task_self(),
+ st.image_addr,
+ st.image_size);
+ }
+ }
+#endif BZIP2
if (result)
panic("(serverboot) exec_load %s: error %d", namebuf, result);
#if 0