summaryrefslogtreecommitdiffstats
path: root/sys/compat/linux/linux_emul.c
diff options
context:
space:
mode:
authordchagin <dchagin@FreeBSD.org>2015-05-24 15:54:58 +0000
committerdchagin <dchagin@FreeBSD.org>2015-05-24 15:54:58 +0000
commitf18b3d51fa76d8d28f216bd46d2f0a5088cfc570 (patch)
tree35b3b7280c8c40a1e2ee373c55b63a07ecb0a7ea /sys/compat/linux/linux_emul.c
parentb08f3f43f9e901fdb2194f84eb02093e60665bab (diff)
downloadFreeBSD-src-f18b3d51fa76d8d28f216bd46d2f0a5088cfc570.zip
FreeBSD-src-f18b3d51fa76d8d28f216bd46d2f0a5088cfc570.tar.gz
Refund the proc emuldata struct for future use. For now move flags from
thread emuldata to proc emuldata as it was originally intended. As we can have both 64 & 32 bit Linuxulator running any eventhandler can be called twice for us. To prevent this move eventhandlers code from linux_emul.c to the linux_common.ko module. Differential Revision: https://reviews.freebsd.org/D1073
Diffstat (limited to 'sys/compat/linux/linux_emul.c')
-rw-r--r--sys/compat/linux/linux_emul.c202
1 files changed, 44 insertions, 158 deletions
diff --git a/sys/compat/linux/linux_emul.c b/sys/compat/linux/linux_emul.c
index 502e936..b9f2373 100644
--- a/sys/compat/linux/linux_emul.c
+++ b/sys/compat/linux/linux_emul.c
@@ -30,8 +30,6 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include "opt_compat.h"
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/imgact.h>
@@ -40,7 +38,6 @@ __FBSDID("$FreeBSD$");
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/mutex.h>
-#include <sys/sdt.h>
#include <sys/sx.h>
#include <sys/proc.h>
#include <sys/syscallsubr.h>
@@ -48,60 +45,13 @@ __FBSDID("$FreeBSD$");
#include <sys/sysproto.h>
#include <sys/unistd.h>
-#ifdef COMPAT_LINUX32
-#include <machine/../linux32/linux.h>
-#include <machine/../linux32/linux32_proto.h>
-#else
-#include <machine/../linux/linux.h>
-#include <machine/../linux/linux_proto.h>
-#endif
-
-#include <compat/linux/linux_dtrace.h>
#include <compat/linux/linux_emul.h>
-#include <compat/linux/linux_futex.h>
#include <compat/linux/linux_misc.h>
#include <compat/linux/linux_util.h>
-/**
- * Special DTrace provider for the linuxulator.
- *
- * In this file we define the provider for the entire linuxulator. All
- * modules (= files of the linuxulator) use it.
- *
- * We define a different name depending on the emulated bitsize, see
- * ../../<ARCH>/linux{,32}/linux.h, e.g.:
- * native bitsize = linuxulator
- * amd64, 32bit emulation = linuxulator32
- */
-LIN_SDT_PROVIDER_DEFINE(LINUX_DTRACE);
-
-/**
- * DTrace probes in this module.
- */
-LIN_SDT_PROBE_DEFINE1(emul, em_find, entry, "struct thread *");
-LIN_SDT_PROBE_DEFINE0(emul, em_find, return);
-LIN_SDT_PROBE_DEFINE3(emul, proc_init, entry, "struct thread *",
- "struct thread *", "int");
-LIN_SDT_PROBE_DEFINE0(emul, proc_init, create_thread);
-LIN_SDT_PROBE_DEFINE0(emul, proc_init, fork);
-LIN_SDT_PROBE_DEFINE0(emul, proc_init, exec);
-LIN_SDT_PROBE_DEFINE0(emul, proc_init, return);
-LIN_SDT_PROBE_DEFINE1(emul, proc_exit, entry, "struct proc *");
-LIN_SDT_PROBE_DEFINE1(emul, linux_thread_detach, entry, "struct thread *");
-LIN_SDT_PROBE_DEFINE0(emul, linux_thread_detach, futex_failed);
-LIN_SDT_PROBE_DEFINE1(emul, linux_thread_detach, child_clear_tid_error, "int");
-LIN_SDT_PROBE_DEFINE0(emul, linux_thread_detach, return);
-LIN_SDT_PROBE_DEFINE2(emul, proc_exec, entry, "struct proc *",
- "struct image_params *");
-LIN_SDT_PROBE_DEFINE0(emul, proc_exec, return);
-LIN_SDT_PROBE_DEFINE0(emul, linux_schedtail, entry);
-LIN_SDT_PROBE_DEFINE1(emul, linux_schedtail, copyout_error, "int");
-LIN_SDT_PROBE_DEFINE0(emul, linux_schedtail, return);
-LIN_SDT_PROBE_DEFINE1(emul, linux_set_tid_address, entry, "int *");
-LIN_SDT_PROBE_DEFINE0(emul, linux_set_tid_address, return);
/*
- * This returns reference to the emuldata entry (if found)
+ * This returns reference to the thread emuldata entry (if found)
*
* Hold PROC_LOCK when referencing emuldata from other threads.
*/
@@ -110,41 +60,51 @@ em_find(struct thread *td)
{
struct linux_emuldata *em;
- LIN_SDT_PROBE1(emul, em_find, entry, td);
-
em = td->td_emuldata;
- LIN_SDT_PROBE1(emul, em_find, return, em);
-
return (em);
}
+/*
+ * This returns reference to the proc pemuldata entry (if found)
+ *
+ * Hold PROC_LOCK when referencing proc pemuldata from other threads.
+ * Hold LINUX_PEM_LOCK wher referencing pemuldata members.
+ */
+struct linux_pemuldata *
+pem_find(struct proc *p)
+{
+ struct linux_pemuldata *pem;
+
+ pem = p->p_emuldata;
+
+ return (pem);
+}
+
void
linux_proc_init(struct thread *td, struct thread *newtd, int flags)
{
struct linux_emuldata *em;
-
- LIN_SDT_PROBE3(emul, proc_init, entry, td, newtd, flags);
+ struct linux_pemuldata *pem;
if (newtd != NULL) {
/* non-exec call */
em = malloc(sizeof(*em), M_TEMP, M_WAITOK | M_ZERO);
em->pdeath_signal = 0;
- em->flags = 0;
em->robust_futexes = NULL;
if (flags & LINUX_CLONE_THREAD) {
- LIN_SDT_PROBE0(emul, proc_init, create_thread);
-
em->em_tid = newtd->td_tid;
} else {
- LIN_SDT_PROBE0(emul, proc_init, fork);
em->em_tid = newtd->td_proc->p_pid;
+
+ pem = malloc(sizeof(*pem), M_TEMP, M_WAITOK | M_ZERO);
+ sx_init(&pem->pem_sx, "lpemlk");
+ newtd->td_proc->p_emuldata = pem;
}
newtd->td_emuldata = em;
} else {
/* exec */
- LIN_SDT_PROBE0(emul, proc_init, exec);
/* lookup the old one */
em = em_find(td);
@@ -155,24 +115,32 @@ linux_proc_init(struct thread *td, struct thread *newtd, int flags)
em->child_clear_tid = NULL;
em->child_set_tid = NULL;
-
- LIN_SDT_PROBE0(emul, proc_init, return);
}
void
linux_proc_exit(void *arg __unused, struct proc *p)
{
+ struct linux_pemuldata *pem;
struct thread *td = curthread;
- if (__predict_false(SV_CURPROC_ABI() != SV_ABI_LINUX)) {
- LIN_SDT_PROBE1(emul, proc_exit, entry, p);
- (p->p_sysent->sv_thread_detach)(td);
- }
+ if (__predict_false(SV_CURPROC_ABI() != SV_ABI_LINUX))
+ return;
+
+ pem = pem_find(p);
+ if (pem == NULL)
+ return;
+ (p->p_sysent->sv_thread_detach)(td);
+
+ p->p_emuldata = NULL;
+
+ sx_destroy(&pem->pem_sx);
+ free(pem, M_TEMP);
}
int
linux_common_execve(struct thread *td, struct image_args *eargs)
{
+ struct linux_pemuldata *pem;
struct linux_emuldata *em;
struct proc *p;
int error;
@@ -199,16 +167,21 @@ linux_common_execve(struct thread *td, struct image_args *eargs)
/*
* In a case of transition from Linux binary execing to
- * FreeBSD binary we destroy linux emuldata thread entry.
+ * FreeBSD binary we destroy linux emuldata thread & proc entries.
*/
if (SV_CURPROC_ABI() != SV_ABI_LINUX) {
PROC_LOCK(p);
em = em_find(td);
- KASSERT(em != NULL, ("proc_exec: emuldata not found.\n"));
+ KASSERT(em != NULL, ("proc_exec: thread emuldata not found.\n"));
td->td_emuldata = NULL;
+
+ pem = pem_find(p);
+ KASSERT(pem != NULL, ("proc_exec: proc pemuldata not found.\n"));
+ p->p_emuldata = NULL;
PROC_UNLOCK(p);
free(em, M_TEMP);
+ free(pem, M_TEMP);
}
return (0);
}
@@ -224,68 +197,11 @@ linux_proc_exec(void *arg __unused, struct proc *p, struct image_params *imgp)
*/
if (__predict_false((imgp->sysent->sv_flags & SV_ABI_MASK) ==
SV_ABI_LINUX)) {
- LIN_SDT_PROBE2(emul, proc_exec, entry, p, imgp);
if (SV_PROC_ABI(p) == SV_ABI_LINUX)
linux_proc_init(td, NULL, 0);
else
linux_proc_init(td, td, 0);
-
- LIN_SDT_PROBE0(emul, proc_exec, return);
- }
-}
-
-void
-linux_thread_detach(struct thread *td)
-{
- struct linux_sys_futex_args cup;
- struct linux_emuldata *em;
- int *child_clear_tid;
- int null = 0;
- int error;
-
- LIN_SDT_PROBE1(emul, linux_thread_detach, entry, td);
-
- em = em_find(td);
- KASSERT(em != NULL, ("thread_detach: emuldata not found.\n"));
-
- LINUX_CTR1(exit, "thread detach(%d)", em->em_tid);
-
- release_futexes(td, em);
-
- child_clear_tid = em->child_clear_tid;
-
- if (child_clear_tid != NULL) {
-
- LINUX_CTR2(exit, "thread detach(%d) %p",
- em->em_tid, child_clear_tid);
-
- error = copyout(&null, child_clear_tid, sizeof(null));
- if (error) {
- LIN_SDT_PROBE1(emul, linux_thread_detach,
- child_clear_tid_error, error);
-
- LIN_SDT_PROBE0(emul, linux_thread_detach, return);
- return;
- }
-
- cup.uaddr = child_clear_tid;
- cup.op = LINUX_FUTEX_WAKE;
- cup.val = 1; /* wake one */
- cup.timeout = NULL;
- cup.uaddr2 = NULL;
- cup.val3 = 0;
- error = linux_sys_futex(td, &cup);
- /*
- * this cannot happen at the moment and if this happens it
- * probably means there is a user space bug
- */
- if (error) {
- LIN_SDT_PROBE0(emul, linux_thread_detach, futex_failed);
- printf(LMSG("futex stuff in thread_detach failed.\n"));
- }
}
-
- LIN_SDT_PROBE0(emul, linux_thread_detach, return);
}
void
@@ -311,12 +227,10 @@ linux_schedtail(struct thread *td)
int error = 0;
int *child_set_tid;
- LIN_SDT_PROBE1(emul, linux_schedtail, entry, td);
-
p = td->td_proc;
em = em_find(td);
- KASSERT(em != NULL, ("linux_schedtail: emuldata not found.\n"));
+ KASSERT(em != NULL, ("linux_schedtail: thread emuldata not found.\n"));
child_set_tid = em->child_set_tid;
if (child_set_tid != NULL) {
@@ -324,34 +238,6 @@ linux_schedtail(struct thread *td)
sizeof(em->em_tid));
LINUX_CTR4(clone, "schedtail(%d) %p stored %d error %d",
td->td_tid, child_set_tid, em->em_tid, error);
-
- if (error != 0) {
- LIN_SDT_PROBE1(emul, linux_schedtail, copyout_error,
- error);
- }
} else
LINUX_CTR1(clone, "schedtail(%d)", em->em_tid);
-
- LIN_SDT_PROBE0(emul, linux_schedtail, return);
-}
-
-int
-linux_set_tid_address(struct thread *td, struct linux_set_tid_address_args *args)
-{
- struct linux_emuldata *em;
-
- LIN_SDT_PROBE1(emul, linux_set_tid_address, entry, args->tidptr);
-
- em = em_find(td);
- KASSERT(em != NULL, ("set_tid_address: emuldata not found.\n"));
-
- em->child_clear_tid = args->tidptr;
-
- td->td_retval[0] = em->em_tid;
-
- LINUX_CTR3(set_tid_address, "tidptr(%d) %p, returns %d",
- em->em_tid, args->tidptr, td->td_retval[0]);
-
- LIN_SDT_PROBE0(emul, linux_set_tid_address, return);
- return (0);
}
OpenPOWER on IntegriCloud