binfmts ...

nivoit_jea@lsi.supelec.fr
Tue, 22 Oct 1996 16:52:18 +0200


Hi every1,

I'm new to this mailing list, and I was not sure whether to send patches
for the kernel here or not...

You'll find at the end of this mail a patch for the 2.0.22 kernel that
simply adds a mew entry in /proc, which I called binfmt, and allows one to know
which binary formats are recognized by the kernel (elf, aout, script, or even
java :-)

The idea of this came quite naturally a week ago, when I was talking
with another linuxer who had an elf-system and some problems: he had an obscure
message from the kernel at the boot (I don't remember what is was exactly), but
finally we found he had no aout support in his kernel... so I thought having
such an entry in /proc would have been an easy way to see that! So I gave it a
try, it took me a few hours (I have never read the sources of the kernel, so I
had to look for places to modify).

I tested it with ELF, aout, Java, and two little wrappers I made,
binfmt_gz(which allows one to execute gzipped file, by calling Gzip) and
binfmt_python(which allows one to execute .pyc pre-compiled python files, simply
by calling the python interpreter when recognizing the magic number of these
files). It seems to work.

I made the patch on 2.0.22 . But the point is that we need to modify the
linux_binprm structure in linux/binfmts.h , in order to add a field containing
the name of the binary format....

It looks useful to me, as useful as /proc/filesystems can be.

I'd like your opinions..

And please tell me who I have to send the patch !

Jb.
Jean-Baptiste Nivoit
3rd year CS student,
Supelec, France

----Patch follows-(6Ko)---------------------------------------------------------
Only in /mnt/linux-2.0.22: .config
Only in /mnt/linux-2.0.22: .config.old
Only in /mnt/linux-2.0.22: .config~
Only in /mnt/linux-2.0.22: .depend
Only in /mnt/linux-2.0.22: .hdepend
Only in /mnt/linux-2.0.22: .version
diff -r linux/Makefile /mnt/linux-2.0.22/Makefile
36c36
< CC =$(CROSS_COMPILE)gcc -D__KERNEL__ -I$(HPATH)

---
> CC	=$(CROSS_COMPILE)gcc -D__KERNEL__ -DBINFMT_NAMES -I$(HPATH)
Only in /mnt/linux-2.0.22/arch: alpha
Only in /mnt/linux-2.0.22/arch/i386/kernel: .depend
Only in /mnt/linux-2.0.22/arch/i386/lib: .depend
Only in /mnt/linux-2.0.22/arch/i386/mm: .depend
Only in /mnt/linux-2.0.22/arch: m68k
Only in /mnt/linux-2.0.22/arch: mips
Only in /mnt/linux-2.0.22/arch: ppc
Only in /mnt/linux-2.0.22/arch: sparc
Only in /mnt/linux-2.0.22/drivers/block: .depend
Only in /mnt/linux-2.0.22/drivers/cdrom: .depend
Only in /mnt/linux-2.0.22/drivers/char: .depend
Only in /mnt/linux-2.0.22/drivers/char: conmakehash
Only in /mnt/linux-2.0.22/drivers/char/ftape: .depend
Only in /mnt/linux-2.0.22/drivers/char: uni_hash.tbl
Only in /mnt/linux-2.0.22/drivers/isdn: .depend
Only in /mnt/linux-2.0.22/drivers/isdn/icn: .depend
Only in /mnt/linux-2.0.22/drivers/isdn/pcbit: .depend
Only in /mnt/linux-2.0.22/drivers/isdn/teles: .depend
Only in /mnt/linux-2.0.22/drivers/net: .depend
Only in /mnt/linux-2.0.22/drivers/pci: .depend
Only in /mnt/linux-2.0.22/drivers/sbus: .depend
Only in /mnt/linux-2.0.22/drivers/sbus/char: .depend
Only in /mnt/linux-2.0.22/drivers/scsi: .depend
Only in /mnt/linux-2.0.22/drivers/sound: .defines
Only in /mnt/linux-2.0.22/drivers/sound: .depend
Only in /mnt/linux-2.0.22/drivers/sound: local.h
Only in /mnt/linux-2.0.22/fs: .depend
Only in /mnt/linux-2.0.22/fs/affs: .depend
diff -r linux/fs/binfmt_aout.c /mnt/linux-2.0.22/fs/binfmt_aout.c
35a36,39
> #ifdef BINFMT_NAMES
> #define AOUT_BINFMT_NAME "aout"
> #endif
> 
36a41,43
> #ifdef BINFMT_NAMES
> 	AOUT_BINFMT_NAME,
> #endif
diff -r linux/fs/binfmt_elf.c /mnt/linux-2.0.22/fs/binfmt_elf.c
57a58,61
> #ifdef BINFMT_NAMES
> #define ELF_BINFMT_NAME "elf"
> #endif
> 
58a63,65
> #ifdef BINFMT_NAMES
> 	ELF_BINFMT_NAME,
> #endif
diff -r linux/fs/binfmt_java.c /mnt/linux-2.0.22/fs/binfmt_java.c
14,15c14,15
< #define _PATH_JAVA	"/usr/bin/java"
< #define _PATH_APPLET	"/usr/bin/appletviewer"
---
> #define _PATH_JAVA	"/usr/local/java/bin/java"
> #define _PATH_APPLET	"/usr/local/java/bin/appletviewer"
20a21,25
> #ifdef BINFMT_NAMES
> #define JAVA_BINFMT_NAME "java"
> #define JAVA_APPLET_BINFMT_NAME "java applet"
> #endif
> 
147a153,155
> #ifdef BINFMT_NAMES
> 	JAVA_BINFMT_NAME,
> #endif
164a173,175
> #ifdef BINFMT_NAMES
> 	JAVA_APPLET_BINFMT_NAME,
> #endif
diff -r linux/fs/binfmt_script.c /mnt/linux-2.0.22/fs/binfmt_script.c
97a98,101
> #ifdef BINFMT_NAMES
> #define SCRIPT_BINFMT_NAME "script" 
> #endif
> 
98a103,105
> #ifdef BINFMT_NAMES
> 	SCRIPT_BINFMT_NAME,
> #endif
diff -r linux/fs/exec.c /mnt/linux-2.0.22/fs/exec.c
666a667,696
> 
> #ifdef BINFMT_NAMES
> 
> #define STRCPY(dest,src) while (*src) { *dest++ = *src++ ; } 
> 
> int get_binfmt_list(char *buf) {
> 	char *bufcur = buf; /* cursive pointer within the buffer */
> 	struct linux_binfmt *pfmt = formats ;
> 	char *pname ;
> 
> /* #define BINFMT_DEBUG  in order to have debugging msgs */
> 
> #ifdef BINFMT_DEBUG
> 	printk("Entering get_binfmt_list()\n");
> #endif
> 	
> 	while ((pfmt != NULL) && 
> 		(bufcur - buf + sizeof(char)*BINFMT_NAME_LEN< PAGE_SIZE)) {
> 		pname = pfmt->name ;
> 		*bufcur++ = '\t' ;
> #ifdef BINFMT_DEBUG
> 		printk("binary format : %s\n",pname);
> #endif
> 		STRCPY(bufcur,pname)
> 		*bufcur++ = '\n' ;
> 		pfmt = pfmt->next ;
> 		}
> 	return (bufcur - buf) ;
> }
> #endif
Only in /mnt/linux-2.0.22/fs/ext: .depend
Only in /mnt/linux-2.0.22/fs/ext2: .depend
Only in /mnt/linux-2.0.22/fs/fat: .depend
Only in /mnt/linux-2.0.22/fs/hpfs: .depend
Only in /mnt/linux-2.0.22/fs/isofs: .depend
Only in /mnt/linux-2.0.22/fs/minix: .depend
Only in /mnt/linux-2.0.22/fs/msdos: .depend
Only in /mnt/linux-2.0.22/fs/ncpfs: .depend
Only in /mnt/linux-2.0.22/fs/nfs: .depend
Only in /mnt/linux-2.0.22/fs/proc: .depend
diff -r linux/fs/proc/array.c /mnt/linux-2.0.22/fs/proc/array.c
968a969,971
> #ifdef BINFMT_NAMES
> extern int get_binfmt_list(char *) ;
> #endif
1018c1021,1024
< 
---
> #ifdef BINFMT_NAMES
> 		case PROC_BINFMT:
> 			return get_binfmt_list(page);
> #endif
diff -r linux/fs/proc/root.c /mnt/linux-2.0.22/fs/proc/root.c
320a321,326
> #ifdef BINFMT_NAMES
> 	proc_register(&proc_root, &(struct proc_dir_entry) {
>  		PROC_BINFMT, 6, "binfmt",
>  		S_IFREG | S_IRUGO, 1, 0, 0,
>  	});
> #endif
Only in /mnt/linux-2.0.22/fs/smbfs: .depend
Only in /mnt/linux-2.0.22/fs/sysv: .depend
Only in /mnt/linux-2.0.22/fs/ufs: .depend
Only in /mnt/linux-2.0.22/fs/umsdos: .depend
Only in /mnt/linux-2.0.22/fs/vfat: .depend
Only in /mnt/linux-2.0.22/fs/xiafs: .depend
Only in /mnt/linux-2.0.22/include: asm
Only in /mnt/linux-2.0.22/include/linux: autoconf.h
diff -r linux/include/linux/binfmts.h /mnt/linux-2.0.22/include/linux/binfmts.h
32a33,36
> #ifdef BINFMT_NAMES
> #define BINFMT_NAME_LEN 12
> #endif
> 
33a38,40
> #ifdef BINFMT_NAMES
> 	char name[BINFMT_NAME_LEN] ;
> #endif
diff -r linux/include/linux/proc_fs.h /mnt/linux-2.0.22/include/linux/proc_fs.h
29a30,32
> #ifdef BINFMT_NAMES
> 	PROC_BINFMT,
> #endif
Only in /mnt/linux-2.0.22/include/linux: version.h
Only in /mnt/linux-2.0.22/ipc: .depend
Only in /mnt/linux-2.0.22/kernel: .depend
Only in /mnt/linux-2.0.22/lib: .depend
Only in /mnt/linux-2.0.22/mm: .depend
Only in /mnt/linux-2.0.22/net: .depend
Only in /mnt/linux-2.0.22/net/802: .depend
Only in /mnt/linux-2.0.22/net/appletalk: .depend
Only in /mnt/linux-2.0.22/net/ax25: .depend
Only in /mnt/linux-2.0.22/net/bridge: .depend
Only in /mnt/linux-2.0.22/net/core: .depend
Only in /mnt/linux-2.0.22/net/ethernet: .depend
Only in /mnt/linux-2.0.22/net/ipv4: .depend
Only in /mnt/linux-2.0.22/net/ipx: .depend
Only in /mnt/linux-2.0.22/net/netrom: .depend
Only in /mnt/linux-2.0.22/net/unix: .depend
Only in /mnt/linux-2.0.22/scripts: mkdep