xref: /freebsd/sys/compat/linux/linux_emul.h (revision d59c7ea2701fe7b73b32eef49a7c712ef38de5a0)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2006 Roman Divacky
5  * All rights reserved.
6  * Copyright (c) 2013 Dmitry Chagin <dchagin@FreeBSD.org>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef _LINUX_EMUL_H_
31 #define	_LINUX_EMUL_H_
32 
33 #include <machine/../linux/linux_emul_md.h>
34 
35 struct image_args;
36 struct image_params;
37 
38 /*
39  * modeled after similar structure in NetBSD
40  * this will be extended as we need more functionality
41  */
42 struct linux_emuldata {
43 	int    *child_set_tid;	/* in clone(): Child's TID to set on clone */
44 	int    *child_clear_tid;/* in clone(): Child's TID to clear on exit */
45 
46 	int	flags;			/* thread emuldata flags */
47 	int	em_tid;			/* thread id */
48 
49 	struct	linux_robust_list_head	*robust_futexes;
50 };
51 
52 struct linux_emuldata	*em_find(struct thread *);
53 
54 void	linux_proc_init(struct thread *, struct thread *, bool);
55 void	linux_on_exit(struct proc *);
56 void	linux_schedtail(struct thread *);
57 int	linux_on_exec(struct proc *, struct image_params *);
58 void	linux_thread_dtor(struct thread *);
59 int	linux_common_execve(struct thread *, struct image_args *);
60 
61 /* process emuldata flags */
62 #define	LINUX_XDEPR_REQUEUEOP	0x00000001	/* uses deprecated
63 						   futex REQUEUE op*/
64 #define	LINUX_XUNSUP_EPOLL	0x00000002	/* unsupported epoll events */
65 #define	LINUX_XUNSUP_FUTEXPIOP	0x00000004	/* uses unsupported pi futex */
66 
67 struct linux_pemuldata {
68 	uint32_t	flags;		/* process emuldata flags */
69 	struct sx	pem_sx;		/* lock for this struct */
70 	uint32_t	persona;	/* process execution domain */
71 	uint32_t	ptrace_flags;	/* used by ptrace(2) */
72 	uint32_t	oom_score_adj;	/* /proc/self/oom_score_adj */
73 	uint32_t	so_timestamp;	/* requested timeval */
74 	uint32_t	so_timestampns;	/* requested timespec */
75 	struct linux_pemuldata_md pem_md; /* machine-dependent state */
76 };
77 
78 #define	LINUX_PEM_XLOCK(p)	sx_xlock(&(p)->pem_sx)
79 #define	LINUX_PEM_XUNLOCK(p)	sx_xunlock(&(p)->pem_sx)
80 #define	LINUX_PEM_SLOCK(p)	sx_slock(&(p)->pem_sx)
81 #define	LINUX_PEM_SUNLOCK(p)	sx_sunlock(&(p)->pem_sx)
82 
83 struct linux_pemuldata	*pem_find(struct proc *);
84 
85 /*
86  * Machine-dependent hooks for struct linux_pemuldata lifecycle
87  * events, implemented per-arch: initialization of pem_md when the
88  * emuldata is created (fork, or a process switching to the Linux
89  * ABI) and reset at exec.
90  */
91 void	linux_pemuldata_init_md(struct thread *, struct linux_pemuldata *);
92 void	linux_pemuldata_exec_md(struct linux_pemuldata *);
93 
94 #endif	/* !_LINUX_EMUL_H_ */
95