Subject: Emulation extension
To: None <tech-kern@NetBSD.ORG>
From: Frank van der Linden <>
List: tech-kern
Date: 03/05/1997 14:06:28
Sometimes special per-process data may need to be kept for emulations. An
example for this is ps_usertramp in the sigacts structure, which is just
there for SunOS emulation. To avoid polluting the NetBSD native data
structures with fields that are only needed for one kind of emulation,
a more general purpose mechanism is needed. In my case there is some
extra data needed to provide a closer Linux emulation, so that is why
i am bringing this up.

I propose the following:

* Add a new field to the proc structure, p_emuldata, of type void *
  The name is inspired by v_data in the vnode structure, as it serves
  a similar purpose. This field will be NULL if the current emulation does
  not need any special data stored.
* The following fields will be added to the emul structure (see sys/proc.h):
  - void *(*e_init(struct proc *p))
    This allocates and initializes the emulation-dependent data. Called
    at exec time.
  - void e_fork(struct proc *old, struct proc *new)
    Copy the emulation-dependent data when forking, possibly do some
    other handling necessary in the future.
  - void e_exit(struct proc *p)
    Free up emulation dependent data.

  Any of these fields may be NULL if not applicable. Usually they should
  either all be NULL, or all point to valid functions.


On a related note, but it's something that can be dealt with at some other
time: I'm not happy about the current emul structure, in the sense that they
contain information on both the OS that is being emulated, as well as
the binary type. These two are not really related, and should be seperated
in my opinion. The fields dealing with the binary format (there are only
2) are inly used at exec time, and not needed afterwards. For an emulation
like the Linux emulation, a check whether a process is an emulated Linux
processes now involves checking whether p_emul is equal either to
&emul_linux_elf or &emul_linux_aout. But the binary format is irrelevant
at runtime. Any opinions on this?

- Frank