summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2020-11-23 18:18:16 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2020-11-23 18:18:16 +0000
commit4815f175d0324b851509adff0e82500cdf979c73 (patch)
tree27c0c408a4044951020fd30318a9bad67fef3132
parent87a9b18d2286d185d574e7f3ffc23c446d343ca4 (diff)
Notes
-rw-r--r--sys/amd64/linux/linux_sysvec.c3
-rw-r--r--sys/amd64/linux32/linux32_sysvec.c3
-rw-r--r--sys/arm64/linux/linux_sysvec.c3
-rw-r--r--sys/compat/linux/linux_common.c15
-rw-r--r--sys/compat/linux/linux_emul.c82
-rw-r--r--sys/compat/linux/linux_emul.h6
-rw-r--r--sys/i386/linux/linux_sysvec.c20
7 files changed, 58 insertions, 74 deletions
diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c
index bf623b6c3c2e..dbfc650a916e 100644
--- a/sys/amd64/linux/linux_sysvec.c
+++ b/sys/amd64/linux/linux_sysvec.c
@@ -780,6 +780,9 @@ struct sysentvec elf_linux_sysvec = {
.sv_schedtail = linux_schedtail,
.sv_thread_detach = linux_thread_detach,
.sv_trap = linux_vsyscall,
+ .sv_onexec = linux_on_exec,
+ .sv_onexit = linux_on_exit,
+ .sv_ontdexit = linux_thread_dtor,
};
static void
diff --git a/sys/amd64/linux32/linux32_sysvec.c b/sys/amd64/linux32/linux32_sysvec.c
index 0df64b57e43b..d06a1fb17d9b 100644
--- a/sys/amd64/linux32/linux32_sysvec.c
+++ b/sys/amd64/linux32/linux32_sysvec.c
@@ -925,6 +925,9 @@ struct sysentvec elf_linux_sysvec = {
.sv_schedtail = linux_schedtail,
.sv_thread_detach = linux_thread_detach,
.sv_trap = NULL,
+ .sv_onexec = linux_on_exec,
+ .sv_onexit = linux_on_exit,
+ .sv_ontdexit = linux_thread_dtor,
};
static void
diff --git a/sys/arm64/linux/linux_sysvec.c b/sys/arm64/linux/linux_sysvec.c
index 2352cca31d08..366fe7c2dc44 100644
--- a/sys/arm64/linux/linux_sysvec.c
+++ b/sys/arm64/linux/linux_sysvec.c
@@ -419,6 +419,9 @@ struct sysentvec elf_linux_sysvec = {
.sv_schedtail = linux_schedtail,
.sv_thread_detach = linux_thread_detach,
.sv_trap = linux_vsyscall,
+ .sv_onexec = linux_on_exec,
+ .sv_onexit = linux_on_exit,
+ .sv_ontdexit = linux_thread_dtor,
};
static void
diff --git a/sys/compat/linux/linux_common.c b/sys/compat/linux/linux_common.c
index bc4fd2d41a37..5984b07ef592 100644
--- a/sys/compat/linux/linux_common.c
+++ b/sys/compat/linux/linux_common.c
@@ -34,7 +34,7 @@ __FBSDID("$FreeBSD$");
#include <sys/imgact_elf.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
-#include <sys/eventhandler.h>
+#include <sys/mutex.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
@@ -71,10 +71,6 @@ TAILQ_HEAD(, linux_ioctl_handler_element) linux_ioctl_handlers =
struct sx linux_ioctl_sx;
SX_SYSINIT(linux_ioctl, &linux_ioctl_sx, "Linux ioctl handlers");
-static eventhandler_tag linux_exec_tag;
-static eventhandler_tag linux_thread_dtor_tag;
-static eventhandler_tag linux_exit_tag;
-
static int
linux_common_modevent(module_t mod, int type, void *data)
{
@@ -87,12 +83,6 @@ linux_common_modevent(module_t mod, int type, void *data)
#endif
linux_dev_shm_create();
linux_osd_jail_register();
- linux_exit_tag = EVENTHANDLER_REGISTER(process_exit,
- linux_proc_exit, NULL, 1000);
- linux_exec_tag = EVENTHANDLER_REGISTER(process_exec,
- linux_proc_exec, NULL, 1000);
- linux_thread_dtor_tag = EVENTHANDLER_REGISTER(thread_dtor,
- linux_thread_dtor, NULL, EVENTHANDLER_PRI_ANY);
SET_FOREACH(ldhp, linux_device_handler_set)
linux_device_register_handler(*ldhp);
LIST_INIT(&futex_list);
@@ -104,9 +94,6 @@ linux_common_modevent(module_t mod, int type, void *data)
SET_FOREACH(ldhp, linux_device_handler_set)
linux_device_unregister_handler(*ldhp);
mtx_destroy(&futex_mtx);
- EVENTHANDLER_DEREGISTER(process_exit, linux_exit_tag);
- EVENTHANDLER_DEREGISTER(process_exec, linux_exec_tag);
- EVENTHANDLER_DEREGISTER(thread_dtor, linux_thread_dtor_tag);
break;
default:
return (EOPNOTSUPP);
diff --git a/sys/compat/linux/linux_emul.c b/sys/compat/linux/linux_emul.c
index 605abfaacbfd..1dfbe239ccc4 100644
--- a/sys/compat/linux/linux_emul.c
+++ b/sys/compat/linux/linux_emul.c
@@ -199,14 +199,13 @@ linux_proc_init(struct thread *td, struct thread *newtd, int flags)
}
void
-linux_proc_exit(void *arg __unused, struct proc *p)
+linux_on_exit(struct proc *p)
{
struct linux_pemuldata *pem;
struct epoll_emuldata *emd;
struct thread *td = curthread;
- if (__predict_false(SV_CURPROC_ABI() != SV_ABI_LINUX))
- return;
+ MPASS(SV_CURPROC_ABI() == SV_ABI_LINUX);
LINUX_CTR3(proc_exit, "thread(%d) proc(%d) p %p",
td->td_tid, p->p_pid, p);
@@ -313,7 +312,7 @@ linux_common_execve(struct thread *td, struct image_args *eargs)
}
void
-linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp)
+linux_on_exec(struct proc *p, struct image_params *imgp)
{
struct thread *td;
struct thread *othertd;
@@ -322,55 +321,52 @@ linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp)
#endif
td = curthread;
+ MPASS((imgp->sysent->sv_flags & SV_ABI_MASK) == SV_ABI_LINUX);
/*
- * In a case of execing to Linux binary we create Linux
- * emuldata thread entry.
+ * When execing to Linux binary, we create Linux emuldata
+ * thread entry.
*/
- if (__predict_false((imgp->sysent->sv_flags & SV_ABI_MASK) ==
- SV_ABI_LINUX)) {
- if (SV_PROC_ABI(p) == SV_ABI_LINUX) {
- /*
- * Process already was under Linuxolator
- * before exec. Update emuldata to reflect
- * single-threaded cleaned state after exec.
- */
- linux_proc_init(td, NULL, 0);
- } else {
- /*
- * We are switching the process to Linux emulator.
- */
- linux_proc_init(td, td, 0);
-
- /*
- * Create a transient td_emuldata for all suspended
- * threads, so that p->p_sysent->sv_thread_detach() ==
- * linux_thread_detach() can find expected but unused
- * emuldata.
- */
- FOREACH_THREAD_IN_PROC(td->td_proc, othertd) {
- if (othertd != td) {
- linux_proc_init(td, othertd,
- LINUX_CLONE_THREAD);
- }
- }
- }
-#if defined(__amd64__)
+ if (SV_PROC_ABI(p) == SV_ABI_LINUX) {
/*
- * An IA32 executable which has executable stack will have the
- * READ_IMPLIES_EXEC personality flag set automatically.
+ * Process already was under Linuxolator
+ * before exec. Update emuldata to reflect
+ * single-threaded cleaned state after exec.
*/
- if (SV_PROC_FLAG(td->td_proc, SV_ILP32) &&
- imgp->stack_prot & VM_PROT_EXECUTE) {
- pem = pem_find(p);
- pem->persona |= LINUX_READ_IMPLIES_EXEC;
+ linux_proc_init(td, NULL, 0);
+ } else {
+ /*
+ * We are switching the process to Linux emulator.
+ */
+ linux_proc_init(td, td, 0);
+
+ /*
+ * Create a transient td_emuldata for all suspended
+ * threads, so that p->p_sysent->sv_thread_detach() ==
+ * linux_thread_detach() can find expected but unused
+ * emuldata.
+ */
+ FOREACH_THREAD_IN_PROC(td->td_proc, othertd) {
+ if (othertd == td)
+ continue;
+ linux_proc_init(td, othertd, LINUX_CLONE_THREAD);
}
-#endif
}
+#if defined(__amd64__)
+ /*
+ * An IA32 executable which has executable stack will have the
+ * READ_IMPLIES_EXEC personality flag set automatically.
+ */
+ if (SV_PROC_FLAG(td->td_proc, SV_ILP32) &&
+ imgp->stack_prot & VM_PROT_EXECUTE) {
+ pem = pem_find(p);
+ pem->persona |= LINUX_READ_IMPLIES_EXEC;
+ }
+#endif
}
void
-linux_thread_dtor(void *arg __unused, struct thread *td)
+linux_thread_dtor(struct thread *td)
{
struct linux_emuldata *em;
diff --git a/sys/compat/linux/linux_emul.h b/sys/compat/linux/linux_emul.h
index 9104892885bc..1bbc69ad98be 100644
--- a/sys/compat/linux/linux_emul.h
+++ b/sys/compat/linux/linux_emul.h
@@ -52,10 +52,10 @@ struct linux_emuldata *em_find(struct thread *);
int linux_exec_imgact_try(struct image_params *);
void linux_proc_init(struct thread *, struct thread *, int);
-void linux_proc_exit(void *, struct proc *);
+void linux_on_exit(struct proc *);
void linux_schedtail(struct thread *);
-void linux_proc_exec(void *, struct proc *, struct image_params *);
-void linux_thread_dtor(void *arg __unused, struct thread *);
+void linux_on_exec(struct proc *, struct image_params *);
+void linux_thread_dtor(struct thread *);
void linux_thread_detach(struct thread *);
int linux_common_execve(struct thread *, struct image_args *);
diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c
index f660e9028fff..7bd1102e48a0 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$");
#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <sys/vnode.h>
-#include <sys/eventhandler.h>
#include <vm/vm.h>
#include <vm/pmap.h>
@@ -104,10 +103,6 @@ static void linux_vdso_deinstall(void *param);
static int linux_szplatform;
const char *linux_kplatform;
-static eventhandler_tag linux_exit_tag;
-static eventhandler_tag linux_exec_tag;
-static eventhandler_tag linux_thread_dtor_tag;
-
#define LINUX_T_UNKNOWN 255
static int _bsd_to_linux_trapcode[] = {
LINUX_T_UNKNOWN, /* 0 */
@@ -873,6 +868,9 @@ struct sysentvec linux_sysvec = {
.sv_schedtail = linux_schedtail,
.sv_thread_detach = linux_thread_detach,
.sv_trap = NULL,
+ .sv_onexec = linux_on_exec,
+ .sv_onexit = linux_on_exit,
+ .sv_ontdexit = linux_thread_dtor,
};
INIT_SYSENTVEC(aout_sysvec, &linux_sysvec);
@@ -907,6 +905,9 @@ struct sysentvec elf_linux_sysvec = {
.sv_schedtail = linux_schedtail,
.sv_thread_detach = linux_thread_detach,
.sv_trap = NULL,
+ .sv_onexec = linux_on_exec,
+ .sv_onexit = linux_on_exit,
+ .sv_ontdexit = linux_thread_dtor,
};
static void
@@ -1040,12 +1041,6 @@ linux_elf_modevent(module_t mod, int type, void *data)
linux_ioctl_register_handler(*lihp);
LIST_INIT(&futex_list);
mtx_init(&futex_mtx, "ftllk", NULL, MTX_DEF);
- linux_exit_tag = EVENTHANDLER_REGISTER(process_exit, linux_proc_exit,
- NULL, 1000);
- linux_exec_tag = EVENTHANDLER_REGISTER(process_exec, linux_proc_exec,
- NULL, 1000);
- linux_thread_dtor_tag = EVENTHANDLER_REGISTER(thread_dtor,
- linux_thread_dtor, NULL, EVENTHANDLER_PRI_ANY);
linux_get_machine(&linux_kplatform);
linux_szplatform = roundup(strlen(linux_kplatform) + 1,
sizeof(char *));
@@ -1072,9 +1067,6 @@ linux_elf_modevent(module_t mod, int type, void *data)
SET_FOREACH(lihp, linux_ioctl_handler_set)
linux_ioctl_unregister_handler(*lihp);
mtx_destroy(&futex_mtx);
- EVENTHANDLER_DEREGISTER(process_exit, linux_exit_tag);
- EVENTHANDLER_DEREGISTER(process_exec, linux_exec_tag);
- EVENTHANDLER_DEREGISTER(thread_dtor, linux_thread_dtor_tag);
linux_dev_shm_destroy();
linux_osd_jail_deregister();
if (bootverbose)