summaryrefslogtreecommitdiff
path: root/sys/kern/kern_exec.c
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2003-06-21 00:42:59 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2003-06-21 00:42:59 +0000
commit544e5e6a2220a000f63bbb4669c3be396524a8ac (patch)
tree3882116a373bcc0bea029332459b1aca83d94b03 /sys/kern/kern_exec.c
parentb4f011dd3afccde0013e4cab893d0336b02f2bde (diff)
add exec/fork/exit hooks per process for compat emulations.
use them to correctly emulate linux brk. update to TNF copyright in linux_exec.c. from netbsd, mostly from a diff by Kurt Miller in pr3318. this should fix java. no regressions in testing by kurt and sturm@. be prepared for "proc size mismatch" -- recompile ps and friends. ok deraadt@
Diffstat (limited to 'sys/kern/kern_exec.c')
-rw-r--r--sys/kern/kern_exec.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c
index 4002037be8e..af4347fbfe7 100644
--- a/sys/kern/kern_exec.c
+++ b/sys/kern/kern_exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_exec.c,v 1.79 2003/06/02 01:29:56 deraadt Exp $ */
+/* $OpenBSD: kern_exec.c,v 1.80 2003/06/21 00:42:58 tedu Exp $ */
/* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */
/*-
@@ -599,9 +599,32 @@ sys_execve(p, v, 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 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);
+
+ /*
+ * Call exec hook. Emulation code may NOT store reference to anything
+ * from &pack.
+ */
+ if (pack.ep_emul->e_proc_exec)
+ (*pack.ep_emul->e_proc_exec)(p, &pack);
+
+ /* 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, p->p_emul->e_name);