linux_common.c revision 283423
1178481Sjb/*-
2178481Sjb * Copyright (c) 2014 Vassilis Laganakos
3178481Sjb * All rights reserved.
4178481Sjb *
5178481Sjb * Redistribution and use in source and binary forms, with or without
6178481Sjb * modification, are permitted provided that the following conditions
7178481Sjb * are met:
8178481Sjb * 1. Redistributions of source code must retain the above copyright
9178481Sjb *    notice, this list of conditions and the following disclaimer.
10178481Sjb * 2. Redistributions in binary form must reproduce the above copyright
11178481Sjb *    notice, this list of conditions and the following disclaimer in the
12178481Sjb *    documentation and/or other materials provided with the distribution.
13178481Sjb *
14178481Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15178481Sjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16178481Sjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17178481Sjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18178481Sjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19178481Sjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20178481Sjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21178481Sjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22178481Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23178481Sjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24178481Sjb * SUCH DAMAGE.
25178481Sjb */
26178481Sjb
27178481Sjb#include <sys/cdefs.h>
28178481Sjb__FBSDID("$FreeBSD: head/sys/compat/linux/linux_common.c 283423 2015-05-24 16:00:01Z dchagin $");
29178481Sjb
30178481Sjb#include <sys/param.h>
31178481Sjb#include <sys/systm.h>
32178481Sjb#include <sys/exec.h>
33178481Sjb#include <sys/imgact.h>
34178481Sjb#include <sys/imgact_elf.h>
35178481Sjb#include <sys/kernel.h>
36178481Sjb#include <sys/malloc.h>
37178481Sjb#include <sys/eventhandler.h>
38178481Sjb#include <sys/sysctl.h>
39178481Sjb
40178481Sjb#include <compat/linux/linux_emul.h>
41178481Sjb#include <compat/linux/linux_mib.h>
42178481Sjb#include <compat/linux/linux_util.h>
43178481Sjb
44178481SjbFEATURE(linuxulator_v4l, "V4L ioctl wrapper support in the linuxulator");
45178481SjbFEATURE(linuxulator_v4l2, "V4L2 ioctl wrapper support in the linuxulator");
46178481Sjb
47178481SjbMODULE_VERSION(linux_common, 1);
48178481Sjb
49178481SjbSET_DECLARE(linux_device_handler_set, struct linux_device_handler);
50178481Sjb
51178481Sjbstatic eventhandler_tag linux_exec_tag;
52178481Sjbstatic eventhandler_tag linux_thread_dtor_tag;
53178481Sjbstatic eventhandler_tag	linux_exit_tag;
54178481Sjb
55178481Sjb
56178481Sjbstatic int
57178481Sjblinux_common_modevent(module_t mod, int type, void *data)
58178481Sjb{
59178481Sjb	struct linux_device_handler **ldhp;
60178481Sjb
61178481Sjb	switch(type) {
62178481Sjb	case MOD_LOAD:
63178481Sjb		linux_osd_jail_register();
64178481Sjb		linux_exit_tag = EVENTHANDLER_REGISTER(process_exit,
65178481Sjb		    linux_proc_exit, NULL, 1000);
66178481Sjb		linux_exec_tag = EVENTHANDLER_REGISTER(process_exec,
67178481Sjb		    linux_proc_exec, NULL, 1000);
68178481Sjb		linux_thread_dtor_tag = EVENTHANDLER_REGISTER(thread_dtor,
69178481Sjb		    linux_thread_dtor, NULL, EVENTHANDLER_PRI_ANY);
70178481Sjb		SET_FOREACH(ldhp, linux_device_handler_set)
71178481Sjb			linux_device_register_handler(*ldhp);
72178481Sjb		break;
73178481Sjb	case MOD_UNLOAD:
74178481Sjb		linux_osd_jail_deregister();
75178481Sjb		SET_FOREACH(ldhp, linux_device_handler_set)
76178481Sjb			linux_device_unregister_handler(*ldhp);
77178481Sjb		EVENTHANDLER_DEREGISTER(process_exit, linux_exit_tag);
78178481Sjb		EVENTHANDLER_DEREGISTER(process_exec, linux_exec_tag);
79178481Sjb		EVENTHANDLER_DEREGISTER(thread_dtor, linux_thread_dtor_tag);
80178481Sjb		break;
81178481Sjb	default:
82178481Sjb		return (EOPNOTSUPP);
83178481Sjb	}
84178481Sjb	return (0);
85178481Sjb}
86178481Sjb
87178481Sjbstatic moduledata_t linux_common_mod = {
88178481Sjb	"linuxcommon",
89178481Sjb	linux_common_modevent,
90178481Sjb	0
91178481Sjb};
92178481Sjb
93DECLARE_MODULE(linuxcommon, linux_common_mod, SI_SUB_EXEC, SI_ORDER_ANY);
94