Subject: Re: Emulations as LKM
To: None <tech-kern@netbsd.org>
From: Jaromír Dolecek <dolecek@ibis.cz>
List: tech-kern
Date: 11/12/2000 19:49:55
Hi,
I've made some progress on this. The current version of the patch
is at
	ftp://ftp.netbsd.org/pub/NetBSD/misc/jdolecek/execsw.diff
gzippped version at
	ftp://ftp.netbsd.org/pub/NetBSD/misc/jdolecek/execsw.diff.gz

This patch addresses the reogranization of emul and execsw stuff
only at this moment - I don't want to mix it with later API changes
needed for LKM.

Highlights:
* only single emulation struct per emulation, all exec format specific stuff
  moved to execsw[] (argsize, copyargs, setregs)
* contents of kern/exec_elf32.c:probe_funcs[] moved to execsw[] - struct
  execsw has pointer to probe function, which is called by
  elf{32|64}_exec_makecmds() to find out if the binary is of given
  emulation; this means that every emulation supporting elf32/elf64 has
  an entry in execsw[] and elf*_exec_makecmds() is now called multiple
  times (for each entry)
  - for ELF, if the probe function is missing (NULL), it means the entry
    is default and should be used unconditionally - this is to keep current
    semantics that unrecognized ELF binaries are executed as NetBSD
    "native" binaries
  - having multiple execsw[] entries and calling elf*_exec_makecmds()
    multiple times may be less efficient, but offers IMHO API
    clean approach to the structures - there is only one structure to patch
    to add support for given emulation/exec type pair; if performance
    is a problem here, something has to be though out to make the performance
    difference smaller. I don't expect major difference though, since
    if the executed binary is NetBSD-native, the very first entry would
    match (or second if compiled with COMPAT_NETBSD32)
  - see the patch to see what exactly it means (like bits about
    kern/exec_conf.c, kern/exec_elf32.c)
* pointer to appropriate emulation struct is now in execsw[] entry,
  individual *makecmds() or *probe() functions no longer set emulation
  field in passed exec_package structure
* new flag EXEC_HASES was added to detect recursive check_exec() call,
  used by kern/exec_script.c
* some consts sprinkled in as appropriate

At this time, only i386 MD-specific bits are updated. Also, only those
execsw[] entries appripriate to i386 are updated (with exception
with EXEC_ELF* entries, which were added all, including EXEC_ELF64 items).
System with this patch seem to work ok (I'm writing this on it), using
both NetBSD and Linux binaries.

If you have any comments about the change, please let me know.
If I won't find any major problems with this code, I'll finish the changes
for other archs than i386, update remaining execsw[] entries
and push this change into tree.

Jaromir
-- 
Jaromir Dolecek <jdolecek@NetBSD.org>      http://www.ics.muni.cz/~dolecek/
@@@@  Wanna a real operating system ? Go and get NetBSD, damn!  @@@@