Subject: Re: Emulations as LKM (final)
To: None <>
From: Jaromír Dolecek <>
List: tech-kern
Date: 11/30/2000 23:24:19
the final changes to make emulations loadable as LKMs are available
for review at

I made the code to treat emulations and exec formats separately
after some though. I found out it's actually easy to do so (exec
code is commonly happy with stuff got from struct emul and doesn't
need extra symbols from emulation code), and it's IMHO right
to do so. There will be separate LKM to load emulation and separate
LKM to load appropriate executable-type support.

The patch doesn't contain the lkm/{compat|exec}/* changes.

Code changes:
* new emul_register(), emul_unregister() - these functions register
  loaded emulations, so that it's possible to find loaded emulation
  using it's name; to be used by LKM when loading executable support code
  these are only available if kernel is compiled with LKM
* new exec_add()/exec_remove() - these are for adding/removing stuff
  to/from execsw; only available for LKM kernel
* foo_emul_path (emulation path, like "/emul/ibcs2") is now part of struct emul;
	changed to use that via p->p_emul->e_path, FOO_CHECK_ALT_{EXIST|CREATE}
	eliminated; where not applicable
	(such as emul_find() calls in various probe functions),
	the path is taken from execsw passed to probe function
* there is a pointer to syscall function in struct emul; MD code
  needs to be changed to call the function if the pointer is not null;
  the syscall() split is done for i386 as example
* exec-specific code split to separate files, i.e. there is separate
  freebsd_exec_elf32.c, freebsd_exec_aout.c and so on. This is to make it easier
  to compile a LKM module which adds support for single exec format only
* struct emul has got a 'flags' entry - this is now used for three
	o say if emulation has SYS___syscall syscall (previously, it was
	  done as check agains syscallp)
	o say if parent pid should also be passed in getpid(2)
	o say if effective cred should be also passed for get[ug]id(2)
* Linux emulation:
	o some compat_09 and compat_12 copied from compat/common/*, so that
	  it's not dependant upon COMPAT_{09|12}
	o some code has been merged to single files, ifdeffed out
	  upon presence of architecture-specific define
	o sys_uselib() put in separate file
* kern_lkm.c:
	o LM_EXEC code uses exec_add()/exec_remove()
 	o new LM_EMUL, uses emul_register()/emul_unregister()
* that's all, unless I forgot something :)

Remaining problems:
* implicit dependency on compat_43 and other compat/common stuff - I won't
  make anything about this now; it's just the way it is, however the emulations
  should be totally standalone in the future and not require COMPAT_43 in kernel
* some exec code needs *_setargs() or *_copyargs(), which is used
  by all exec format's supported by given emulation; since I'd like to avoid
  all symbol dependencies between emulation and appropriate exec code
  (to ease loading via LKM), these would be changed to inlines or
  a pointer to those functions may be added to struct emul
* MD code would need to be adjusted and tested, to make sure the LKM
  modules are loadable and work correctly; this would be done after
  the changes would be in tree, since I don't feel like doing it all alone

I'm running with that code now and it seems stable (at least stable
enough to run the couple Linux applications I use).

Comments/criticism is welcome. The code would be propagated to tree

Jaromir Dolecek <>
@@@@  Wanna a real operating system ? Go and get NetBSD, damn!  @@@@