1161304Snetchild/*-
2161304Snetchild * Copyright (c) 2006 Roman Divacky
3161304Snetchild * All rights reserved.
4161304Snetchild *
5161304Snetchild * Redistribution and use in source and binary forms, with or without
6161304Snetchild * modification, are permitted provided that the following conditions
7161304Snetchild * are met:
8161304Snetchild * 1. Redistributions of source code must retain the above copyright
9161304Snetchild *    notice, this list of conditions and the following disclaimer
10161304Snetchild *    in this position and unchanged.
11161304Snetchild * 2. Redistributions in binary form must reproduce the above copyright
12161304Snetchild *    notice, this list of conditions and the following disclaimer in the
13161304Snetchild *    documentation and/or other materials provided with the distribution.
14161304Snetchild * 3. The name of the author may not be used to endorse or promote products
15161304Snetchild *    derived from this software without specific prior written permission
16161304Snetchild *
17161304Snetchild * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18161304Snetchild * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19161304Snetchild * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20161304Snetchild * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21161304Snetchild * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22161304Snetchild * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23161304Snetchild * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24161304Snetchild * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25161304Snetchild * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26161304Snetchild * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27161304Snetchild *
28161304Snetchild * $FreeBSD$
29161304Snetchild */
30161304Snetchild
31161304Snetchild#ifndef _LINUX_EMUL_H_
32168275Sjkim#define	_LINUX_EMUL_H_
33161304Snetchild
34215664Snetchild#define EMUL_SHARED_HASXSTAT	0x01
35215664Snetchild
36161304Snetchildstruct linux_emuldata_shared {
37165688Snetchild	int	refs;
38215664Snetchild	int	flags;
39215664Snetchild	int	xstat;
40161304Snetchild	pid_t	group_pid;
41161304Snetchild
42165688Snetchild	LIST_HEAD(, linux_emuldata) threads; /* head of list of linux threads */
43161304Snetchild};
44161304Snetchild
45165688Snetchild/*
46165688Snetchild * modeled after similar structure in NetBSD
47161304Snetchild * this will be extended as we need more functionality
48161304Snetchild */
49161304Snetchildstruct linux_emuldata {
50165688Snetchild	pid_t	pid;
51161304Snetchild
52165688Snetchild	int    *child_set_tid;	/* in clone(): Child's TID to set on clone */
53165688Snetchild	int    *child_clear_tid;/* in clone(): Child's TID to clear on exit */
54161304Snetchild
55161304Snetchild	struct linux_emuldata_shared *shared;
56161304Snetchild
57165688Snetchild	int	pdeath_signal;		/* parent death signal */
58218621Sdchagin	int	flags;			/* different emuldata flags */
59163734Snetchild
60178976Srdivacky	struct	linux_robust_list_head	*robust_futexes;
61178976Srdivacky
62161304Snetchild	LIST_ENTRY(linux_emuldata) threads;	/* list of linux threads */
63161304Snetchild};
64161304Snetchild
65168275Sjkimstruct linux_emuldata	*em_find(struct proc *, int locked);
66161304Snetchild
67246290Sdchagin/*
68246290Sdchagin * DTrace probes for locks should be fired after locking and before releasing
69246290Sdchagin * to prevent races (to provide data/function stability in dtrace, see the
70246290Sdchagin * output of "dtrace -v ..." and the corresponding dtrace docs).
71246290Sdchagin */
72246290Sdchagin#define	EMUL_LOCK(l)		do { \
73246290Sdchagin				    mtx_lock(l); \
74246290Sdchagin				    LIN_SDT_PROBE1(locks, emul_lock, \
75246290Sdchagin					locked, l); \
76246290Sdchagin				} while (0)
77246290Sdchagin#define	EMUL_UNLOCK(l)		do { \
78246290Sdchagin				    LIN_SDT_PROBE1(locks, emul_lock, \
79246290Sdchagin					unlock, l); \
80246290Sdchagin				    mtx_unlock(l); \
81246290Sdchagin				} while (0)
82161304Snetchild
83246290Sdchagin#define	EMUL_SHARED_RLOCK(l)	do { \
84246290Sdchagin				    sx_slock(l); \
85246290Sdchagin				    LIN_SDT_PROBE1(locks, emul_shared_rlock, \
86246290Sdchagin					locked, l); \
87246290Sdchagin				} while (0)
88246290Sdchagin#define	EMUL_SHARED_RUNLOCK(l)	do { \
89246290Sdchagin				    LIN_SDT_PROBE1(locks, emul_shared_rlock, \
90246290Sdchagin					unlock, l); \
91246290Sdchagin				    sx_sunlock(l); \
92246290Sdchagin				} while (0)
93246290Sdchagin#define	EMUL_SHARED_WLOCK(l)	do { \
94246290Sdchagin				    sx_xlock(l); \
95246290Sdchagin				    LIN_SDT_PROBE1(locks, emul_shared_wlock, \
96246290Sdchagin					locked, l); \
97246290Sdchagin				} while (0)
98246290Sdchagin#define	EMUL_SHARED_WUNLOCK(l)	do { \
99246290Sdchagin				    LIN_SDT_PROBE1(locks, emul_shared_wlock, \
100246290Sdchagin					unlock, l); \
101246290Sdchagin				    sx_xunlock(l); \
102246290Sdchagin				} while (0)
103161304Snetchild
104161304Snetchild/* for em_find use */
105168275Sjkim#define	EMUL_DOLOCK		1
106168275Sjkim#define	EMUL_DONTLOCK		0
107161304Snetchild
108218621Sdchagin/* emuldata flags */
109218621Sdchagin#define	LINUX_XDEPR_REQUEUEOP	0x00000001	/* uses deprecated
110218621Sdchagin						   futex REQUEUE op*/
111218621Sdchagin
112165688Snetchildint	linux_proc_init(struct thread *, pid_t, int);
113165688Snetchildvoid	linux_proc_exit(void *, struct proc *);
114219405Sdchaginvoid	linux_schedtail(struct thread *);
115165688Snetchildvoid	linux_proc_exec(void *, struct proc *, struct image_params *);
116215664Snetchildvoid	linux_kill_threads(struct thread *, int);
117161304Snetchild
118168275Sjkimextern struct sx	emul_shared_lock;
119168275Sjkimextern struct mtx	emul_lock;
120161419Snetchild
121165688Snetchild#endif	/* !_LINUX_EMUL_H_ */
122