xref: /freebsd/sys/compat/linux/linux_emul.h (revision eb69d1f144a6fcc765d1b9d44a5ae8082353e70b)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2006 Roman Divacky
5  * Copyright (c) 2013 Dmitry Chagin
6  * All rights reserved.
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  *    in this position and unchanged.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * $FreeBSD$
32  */
33 
34 #ifndef _LINUX_EMUL_H_
35 #define	_LINUX_EMUL_H_
36 
37 /*
38  * modeled after similar structure in NetBSD
39  * this will be extended as we need more functionality
40  */
41 struct linux_emuldata {
42 	int    *child_set_tid;	/* in clone(): Child's TID to set on clone */
43 	int    *child_clear_tid;/* in clone(): Child's TID to clear on exit */
44 
45 	int	pdeath_signal;		/* parent death signal */
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 *, int);
55 void	linux_proc_exit(void *, struct proc *);
56 void	linux_schedtail(struct thread *);
57 void	linux_proc_exec(void *, struct proc *, struct image_params *);
58 void	linux_thread_dtor(void *arg __unused, struct thread *);
59 void	linux_thread_detach(struct thread *);
60 int	linux_common_execve(struct thread *, struct image_args *);
61 
62 /* process emuldata flags */
63 #define	LINUX_XDEPR_REQUEUEOP	0x00000001	/* uses deprecated
64 						   futex REQUEUE op*/
65 #define	LINUX_XUNSUP_EPOLL	0x00000002	/* unsupported epoll events */
66 #define	LINUX_XUNSUP_FUTEXPIOP	0x00000004	/* uses unsupported pi futex */
67 
68 struct linux_pemuldata {
69 	uint32_t	flags;		/* process emuldata flags */
70 	struct sx	pem_sx;		/* lock for this struct */
71 	void		*epoll;		/* epoll data */
72 	uint32_t	persona;	/* process execution domain */
73 };
74 
75 #define	LINUX_PEM_XLOCK(p)	sx_xlock(&(p)->pem_sx)
76 #define	LINUX_PEM_XUNLOCK(p)	sx_xunlock(&(p)->pem_sx)
77 #define	LINUX_PEM_SLOCK(p)	sx_slock(&(p)->pem_sx)
78 #define	LINUX_PEM_SUNLOCK(p)	sx_sunlock(&(p)->pem_sx)
79 
80 struct linux_pemuldata	*pem_find(struct proc *);
81 
82 #endif	/* !_LINUX_EMUL_H_ */
83