xref: /freebsd/sys/compat/linux/linux_emul.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1ad2056f2SAlexander Leidinger /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
37f2d13d6SPedro F. Giffuni  *
4ad2056f2SAlexander Leidinger  * Copyright (c) 2006 Roman Divacky
5ad2056f2SAlexander Leidinger  * All rights reserved.
61ca6b15bSDmitry Chagin  * Copyright (c) 2013 Dmitry Chagin <dchagin@FreeBSD.org>
7ad2056f2SAlexander Leidinger  *
8ad2056f2SAlexander Leidinger  * Redistribution and use in source and binary forms, with or without
9ad2056f2SAlexander Leidinger  * modification, are permitted provided that the following conditions
10ad2056f2SAlexander Leidinger  * are met:
11ad2056f2SAlexander Leidinger  * 1. Redistributions of source code must retain the above copyright
12023b850bSEd Maste  *    notice, this list of conditions and the following disclaimer.
13ad2056f2SAlexander Leidinger  * 2. Redistributions in binary form must reproduce the above copyright
14ad2056f2SAlexander Leidinger  *    notice, this list of conditions and the following disclaimer in the
15ad2056f2SAlexander Leidinger  *    documentation and/or other materials provided with the distribution.
16ad2056f2SAlexander Leidinger  *
17023b850bSEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18023b850bSEd Maste  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19023b850bSEd Maste  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20023b850bSEd Maste  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21023b850bSEd Maste  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22023b850bSEd Maste  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23023b850bSEd Maste  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24023b850bSEd Maste  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25023b850bSEd Maste  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26023b850bSEd Maste  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27023b850bSEd Maste  * SUCH DAMAGE.
28ad2056f2SAlexander Leidinger  *
29ad2056f2SAlexander Leidinger  * $FreeBSD$
30ad2056f2SAlexander Leidinger  */
31ad2056f2SAlexander Leidinger 
32ad2056f2SAlexander Leidinger #ifndef _LINUX_EMUL_H_
33ad2056f2SAlexander Leidinger #define	_LINUX_EMUL_H_
34ad2056f2SAlexander Leidinger 
35d49fb289SEdward Tomasz Napierala struct image_params;
36d49fb289SEdward Tomasz Napierala 
370eef2f8aSAlexander Leidinger /*
380eef2f8aSAlexander Leidinger  * modeled after similar structure in NetBSD
39ad2056f2SAlexander Leidinger  * this will be extended as we need more functionality
40ad2056f2SAlexander Leidinger  */
41ad2056f2SAlexander Leidinger struct linux_emuldata {
42ad2056f2SAlexander Leidinger 	int    *child_set_tid;	/* in clone(): Child's TID to set on clone */
43ad2056f2SAlexander Leidinger 	int    *child_clear_tid;/* in clone(): Child's TID to clear on exit */
44ad2056f2SAlexander Leidinger 
45bc273677SDmitry Chagin 	int	flags;			/* thread emuldata flags */
4681338031SDmitry Chagin 	int	em_tid;			/* thread id */
47955d762aSAlexander Leidinger 
484732e446SRoman Divacky 	struct	linux_robust_list_head	*robust_futexes;
49ad2056f2SAlexander Leidinger };
50ad2056f2SAlexander Leidinger 
5181338031SDmitry Chagin struct linux_emuldata	*em_find(struct thread *);
52ad2056f2SAlexander Leidinger 
53b267239dSEd Maste int	linux_exec_imgact_try(struct image_params *);
540a4b664aSDmitry Chagin void	linux_proc_init(struct thread *, struct thread *, bool);
554815f175SKonstantin Belousov void	linux_on_exit(struct proc *);
56e5d81ef1SDmitry Chagin void	linux_schedtail(struct thread *);
574815f175SKonstantin Belousov void	linux_on_exec(struct proc *, struct image_params *);
584815f175SKonstantin Belousov void	linux_thread_dtor(struct thread *);
5981338031SDmitry Chagin int	linux_common_execve(struct thread *, struct image_args *);
6094cb2ecfSAlexander Leidinger 
61bc273677SDmitry Chagin /* process emuldata flags */
62bc273677SDmitry Chagin #define	LINUX_XDEPR_REQUEUEOP	0x00000001	/* uses deprecated
63bc273677SDmitry Chagin 						   futex REQUEUE op*/
64e16fe1c7SDmitry Chagin #define	LINUX_XUNSUP_EPOLL	0x00000002	/* unsupported epoll events */
655dd1d097SDmitry Chagin #define	LINUX_XUNSUP_FUTEXPIOP	0x00000004	/* uses unsupported pi futex */
66e16fe1c7SDmitry Chagin 
67bc273677SDmitry Chagin struct linux_pemuldata {
68bc273677SDmitry Chagin 	uint32_t	flags;		/* process emuldata flags */
69bc273677SDmitry Chagin 	struct sx	pem_sx;		/* lock for this struct */
7023e8912cSDmitry Chagin 	uint32_t	persona;	/* process execution domain */
71d49fb289SEdward Tomasz Napierala 	uint32_t	ptrace_flags;	/* used by ptrace(2) */
72b7df7b98SDmitry Chagin 	uint32_t	oom_score_adj;	/* /proc/self/oom_score_adj */
730e26e54bSDmitry Chagin 	uint32_t	so_timestamp;	/* requested timeval */
7471bc8bcfSDmitry Chagin 	uint32_t	so_timestampns;	/* requested timespec */
75bc273677SDmitry Chagin };
76bc273677SDmitry Chagin 
77bc273677SDmitry Chagin #define	LINUX_PEM_XLOCK(p)	sx_xlock(&(p)->pem_sx)
78bc273677SDmitry Chagin #define	LINUX_PEM_XUNLOCK(p)	sx_xunlock(&(p)->pem_sx)
79bc273677SDmitry Chagin #define	LINUX_PEM_SLOCK(p)	sx_slock(&(p)->pem_sx)
80bc273677SDmitry Chagin #define	LINUX_PEM_SUNLOCK(p)	sx_sunlock(&(p)->pem_sx)
81bc273677SDmitry Chagin 
82bc273677SDmitry Chagin struct linux_pemuldata	*pem_find(struct proc *);
83bc273677SDmitry Chagin 
84ad2056f2SAlexander Leidinger #endif	/* !_LINUX_EMUL_H_ */
85