On Sat, 2003-06-07 at 10:13, Poul-Henning Kamp wrote:
> In message <[EMAIL PROTECTED]>, David Yeske writes:
>> imgact_gzip.c seems to be pretty stale. Has anyone considered fixing this? If
>> this were fixed
>> then kldload() / linker_load_module() could deal with a gzipped .ko file, and
>> gzipped elf
>> executables would work also?
>
> At least originally imgact_gzip.c was heavily a.out aware.
Interesting.
Making imgact_gzip elf-aware would not make the kernel capable of loading gzipped
modules,
only executables. There's a separate link_elf.c that the kernel uses for linking ELF
images
into itself (rather than activating ELF executables at exec() time, with imgact_elf)
I've been fiddling a little with compressed data in the kernel already, and was able
to hack together
a patch for link_elf pretty quickly. The "quickly" means that there's no boot loader
support, and the
gzip handling is quite braindamaged, extracting the entire zipped file into allocated
memory before
parsing the ELF structure. This is mainly because the ELF parsing bits of link_elf
assume they can
make random access to the file. It'd take a bit of rework to make it work with a
serial data stream.
The whole thing's very rough around the edges, but I can gzip most of
/boot/kernel/*.ko, and load
the gzipped versions.
I can polish this up, and/or add gzipped executable support, if there's any interest
in reviewing or
committing it.
The patch adds "GZLOADER" and "INFLATE" options for the kernel, removing "GZIP" (which
was
busted anyway, and considered "inflate.c" to be part of the ELF support, while it's
pretty much a
standalone decompressor.) There's a "COMPAT_GZAOUT" option added, but it's just as
bust as
GZIP was before.
E&OE. Patch may crash your kernel, delete your data, make your cat unwell, etc.
Cheers,
Peter.Index: conf/files
===
RCS file: /pub/FreeBSD/development/FreeBSD-CVS/src/sys/conf/files,v
retrieving revision 1.791
diff -u -r1.791 files
--- conf/files 9 Jun 2003 19:25:06 - 1.791
+++ conf/files 11 Jun 2003 12:48:40 -
@@ -1011,7 +1011,7 @@
isofs/cd9660/cd9660_vnops.coptional cd9660
kern/imgact_elf.c standard
kern/imgact_shell.cstandard
-kern/inflate.c optional gzip
+kern/inflate.c optional inflate
kern/init_main.c standard
kern/init_sysent.c standard
kern/kern_acct.c standard
Index: conf/files.i386
===
RCS file: /pub/FreeBSD/development/FreeBSD-CVS/src/sys/conf/files.i386,v
retrieving revision 1.445
diff -u -r1.445 files.i386
--- conf/files.i386 31 May 2003 17:06:19 - 1.445
+++ conf/files.i386 11 Jun 2003 12:51:27 -
@@ -407,7 +407,7 @@
isa/syscons_isa.c optionalsc
isa/vga_isa.c optionalvga
kern/imgact_aout.c optionalcompat_aout
-kern/imgact_gzip.c optionalgzip
+kern/imgact_gzip.c optionalcompat_gzaout
libkern/divdi3.c standard
libkern/moddi3.c standard
libkern/qdivrem.c standard
Index: conf/options
===
RCS file: /pub/FreeBSD/development/FreeBSD-CVS/src/sys/conf/options,v
retrieving revision 1.393
diff -u -r1.393 options
--- conf/options18 May 2003 03:46:30 - 1.393
+++ conf/options11 Jun 2003 12:54:32 -
@@ -603,3 +603,8 @@
# options for hifn driver
HIFN_DEBUG opt_hifn.h
HIFN_RNDTEST opt_hifn.h
+
+# options for gzip/"inflate" related functionality
+INFLATEopt_inflate.h
+COMPAT_GZAOUT opt_gzaout.h
+GZLOADER opt_gzloader.h
Index: kern/link_elf.c
===
RCS file: /pub/FreeBSD/development/FreeBSD-CVS/src/sys/kern/link_elf.c,v
retrieving revision 1.73
diff -u -r1.73 link_elf.c
--- kern/link_elf.c 12 May 2003 15:08:10 - 1.73
+++ kern/link_elf.c 11 Jun 2003 13:24:50 -
@@ -28,6 +28,7 @@
#include "opt_ddb.h"
#include "opt_mac.h"
+#include "opt_gzloader.h"
#include
#include
@@ -42,6 +43,10 @@
#include
#include
+#ifdef GZLOADER
+#include
+#endif
+
#include
#ifdef GPROF
#include
@@ -98,9 +103,40 @@
#endif
} *elf_file_t;
+struct vnreader {
+ struct vnode *vnodep;
+ struct thread *thread;
+};
+
+#ifdef GZLOADER
+#define MAXGZPAGES (1024 * 1024 / PAGE_SIZE) // Allow modules up to 1MB (uncompressed)
+
+struct gzreader {
+ /* reading from gzipped file. */
+ int error;
+ struct vnode *vn;
+ unsigned char *inPage;
+ struct thread *td;
+ int inPageSize;
+