add void *p_emuldata into struct proc - this can be used to hold per-process

emulation-specific data
add process exit, exec and fork function hooks into struct emul:
* e_proc_fork() - called in fork1() after the new forked process is setup
* e_proc_exec() - called in sys_execve() after the executed process is setup
* e_proc_exit() - called in exit1() after all the other process cleanups are
  done, right before machine-dependant switch to new context; also called
  for "old" emulation from sys_execve() if emulation of executed program and
  the original process is different

This was discussed on tech-kern.
This commit is contained in:
jdolecek 2000-11-07 12:41:52 +00:00
parent 75823fcfc2
commit 7d8eefdffc
4 changed files with 42 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_exec.c,v 1.121 2000/09/28 19:05:07 eeh Exp $ */
/* $NetBSD: kern_exec.c,v 1.122 2000/11/07 12:41:52 jdolecek Exp $ */
/*-
* Copyright (C) 1993, 1994, 1996 Christopher G. Demetriou
@ -526,9 +526,27 @@ sys_execve(struct proc *p, void *v, register_t *retval)
if (p->p_flag & P_TRACED)
psignal(p, SIGTRAP);
p->p_emul = pack.ep_emul;
free(pack.ep_hdr, M_EXEC);
/*
* Call emulation specific exec hook. This can setup setup per-process
* p->p_emuldata or do any other per-process stuff an emulation needs.
*
* If we are executing process of different emulation than the
* original forked process, call e_proc_exit() of the old emulation
* first, then e_proc_exec() of new emulation. If the emulation is
* same, the exec hook code should deallocate any old emulation
* resources held previously by this process.
*/
if (p->p_emul && p->p_emul->e_proc_exit && p->p_emul != pack.ep_emul)
(*p->p_emul->e_proc_exit)(p);
if (pack.ep_emul->e_proc_exec)
(*pack.ep_emul->e_proc_exec)(p);
/* update p_emul, the old value is no longer needed */
p->p_emul = pack.ep_emul;
#ifdef KTRACE
if (KTRPOINT(p, KTR_EMUL))
ktremul(p);

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_exit.c,v 1.85 2000/08/22 17:28:28 thorpej Exp $ */
/* $NetBSD: kern_exit.c,v 1.86 2000/11/07 12:41:52 jdolecek Exp $ */
/*-
* Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@ -320,6 +320,12 @@ exit1(struct proc *p, int rv)
limfree(p->p_limit);
p->p_limit = NULL;
/*
* If emulation has process exit hook, call it now.
*/
if (p->p_emul->e_proc_exit)
(*p->p_emul->e_proc_exit)(p);
/* This process no longer needs to hold the kernel lock. */
KERNEL_PROC_UNLOCK(p);

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_fork.c,v 1.74 2000/11/07 12:31:17 jdolecek Exp $ */
/* $NetBSD: kern_fork.c,v 1.75 2000/11/07 12:41:52 jdolecek Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1991, 1993
@ -346,6 +346,12 @@ again:
else
p2->p_sigacts = sigactsinit(p1);
/*
* If emulation has process fork hook, call it now.
*/
if (p2->p_emul->e_proc_fork)
(*p2->p_emul->e_proc_fork)(p2, p1);
/*
* This begins the section where we must prevent the parent
* from being swapped.

View File

@ -1,4 +1,4 @@
/* $NetBSD: proc.h,v 1.105 2000/09/05 16:27:51 bouyer Exp $ */
/* $NetBSD: proc.h,v 1.106 2000/11/07 12:41:53 jdolecek Exp $ */
/*-
* Copyright (c) 1986, 1989, 1991, 1993
@ -103,6 +103,11 @@ struct emul {
char *e_sigcode; /* Start of sigcode */
char *e_esigcode; /* End of sigcode */
/* Per-process hooks */
void (*e_proc_exec) __P((struct proc *));
void (*e_proc_fork) __P((struct proc *p, struct proc *parent));
void (*e_proc_exit) __P((struct proc *));
};
/*
@ -183,6 +188,8 @@ struct proc {
int p_holdcnt; /* If non-zero, don't swap. */
struct emul *p_emul; /* Emulation information */
void *p_emuldata; /* Per-process emulation data, or NULL.
* Malloc type M_EMULDATA */
/* End area that is zeroed on creation. */
#define p_endzero p_startcopy