Linuxolator: Replace use of eventhandlers by sysent hooks.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D27309
This commit is contained in:
Konstantin Belousov 2020-11-23 18:18:16 +00:00
parent 87a9b18d22
commit 4815f175d0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=367960
7 changed files with 58 additions and 74 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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 *);

View File

@ -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)