xref: /freebsd/sys/arm64/linux/linux.h (revision e248c237)
1e248c237SEd Maste /*-
2e248c237SEd Maste  * Copyright (c) 1994-1996 Søren Schmidt
3e248c237SEd Maste  * Copyright (c) 2013 Dmitry Chagin
4e248c237SEd Maste  * Copyright (c) 2018 Turing Robotic Industries Inc.
5e248c237SEd Maste  *
6e248c237SEd Maste  * Redistribution and use in source and binary forms, with or without
7e248c237SEd Maste  * modification, are permitted provided that the following conditions
8e248c237SEd Maste  * are met:
9e248c237SEd Maste  * 1. Redistributions of source code must retain the above copyright
10e248c237SEd Maste  *    notice, this list of conditions and the following disclaimer.
11e248c237SEd Maste  * 2. Redistributions in binary form must reproduce the above copyright
12e248c237SEd Maste  *    notice, this list of conditions and the following disclaimer in the
13e248c237SEd Maste  *    documentation and/or other materials provided with the distribution.
14e248c237SEd Maste  *
15e248c237SEd Maste  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16e248c237SEd Maste  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17e248c237SEd Maste  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18e248c237SEd Maste  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19e248c237SEd Maste  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20e248c237SEd Maste  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21e248c237SEd Maste  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22e248c237SEd Maste  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23e248c237SEd Maste  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24e248c237SEd Maste  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25e248c237SEd Maste  * SUCH DAMAGE.
26e248c237SEd Maste  */
27e248c237SEd Maste 
28e248c237SEd Maste /*
29e248c237SEd Maste  * $FreeBSD$
30e248c237SEd Maste  */
31e248c237SEd Maste #ifndef _ARM64_LINUX_H_
32e248c237SEd Maste #define	_ARM64_LINUX_H_
33e248c237SEd Maste 
34e248c237SEd Maste #include <compat/linux/linux.h>
35e248c237SEd Maste #include <arm64/linux/linux_syscall.h>
36e248c237SEd Maste 
37e248c237SEd Maste /* Debugging support */
38e248c237SEd Maste #define DEBUG
39e248c237SEd Maste extern u_char linux_debug_map[];
40e248c237SEd Maste #define	ldebug(name)	isclr(linux_debug_map, LINUX_SYS_linux_ ## name)
41e248c237SEd Maste #define	ARGS(nm, fmt)	"linux(%ld/%ld): "#nm"("fmt")\n",			\
42e248c237SEd Maste 			(long)td->td_proc->p_pid, (long)td->td_tid
43e248c237SEd Maste #define	LMSG(fmt)	"linux(%ld/%ld): "fmt"\n",				\
44e248c237SEd Maste 			(long)td->td_proc->p_pid, (long)td->td_tid
45e248c237SEd Maste #define	LINUX_DTRACE	linuxulator
46e248c237SEd Maste 
47e248c237SEd Maste #define	PTRIN(v)	(void *)(v)
48e248c237SEd Maste #define	PTROUT(v)	(uintptr_t)(v)
49e248c237SEd Maste 
50e248c237SEd Maste #define	CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
51e248c237SEd Maste #define	CP2(src,dst,sfld,dfld) do { (dst).dfld = (src).sfld; } while (0)
52e248c237SEd Maste #define	PTRIN_CP(src,dst,fld) \
53e248c237SEd Maste 	do { (dst).fld = PTRIN((src).fld); } while (0)
54e248c237SEd Maste 
55e248c237SEd Maste /* Provide a separate set of types for the Linux types */
56e248c237SEd Maste typedef int32_t		l_int;
57e248c237SEd Maste typedef int64_t		l_long;
58e248c237SEd Maste typedef int16_t		l_short;
59e248c237SEd Maste typedef uint32_t	l_uint;
60e248c237SEd Maste typedef uint64_t	l_ulong;
61e248c237SEd Maste typedef uint16_t	l_ushort;
62e248c237SEd Maste 
63e248c237SEd Maste typedef l_ulong		l_uintptr_t;
64e248c237SEd Maste typedef l_long		l_clock_t;
65e248c237SEd Maste typedef l_int		l_daddr_t;
66e248c237SEd Maste typedef l_ulong		l_dev_t;
67e248c237SEd Maste typedef l_uint		l_gid_t;
68e248c237SEd Maste typedef l_ushort	l_gid16_t;	/* XXX */
69e248c237SEd Maste typedef l_uint		l_uid_t;
70e248c237SEd Maste typedef l_ushort	l_uid16_t;	/* XXX */
71e248c237SEd Maste typedef l_ulong		l_ino_t;
72e248c237SEd Maste typedef l_int		l_key_t;
73e248c237SEd Maste typedef l_long		l_loff_t;
74e248c237SEd Maste typedef l_uint		l_mode_t;
75e248c237SEd Maste typedef l_long		l_off_t;
76e248c237SEd Maste typedef l_int		l_pid_t;
77e248c237SEd Maste typedef l_ulong		l_size_t;
78e248c237SEd Maste typedef l_long		l_suseconds_t;
79e248c237SEd Maste typedef l_long		l_time_t;
80e248c237SEd Maste typedef l_int		l_timer_t;	/* XXX */
81e248c237SEd Maste typedef l_ulong		l_fd_mask;
82e248c237SEd Maste 
83e248c237SEd Maste typedef struct {
84e248c237SEd Maste 	l_int		val[2];
85e248c237SEd Maste } l_fsid_t;
86e248c237SEd Maste 
87e248c237SEd Maste typedef struct {
88e248c237SEd Maste 	l_time_t	tv_sec;
89e248c237SEd Maste 	l_suseconds_t	tv_usec;
90e248c237SEd Maste } l_timeval;
91e248c237SEd Maste 
92e248c237SEd Maste #define	l_fd_set	fd_set
93e248c237SEd Maste 
94e248c237SEd Maste /* Miscellaneous */
95e248c237SEd Maste #define	LINUX_AT_COUNT		20
96e248c237SEd Maste 
97e248c237SEd Maste struct l___sysctl_args
98e248c237SEd Maste {
99e248c237SEd Maste 	l_uintptr_t	name;
100e248c237SEd Maste 	l_int		nlen;
101e248c237SEd Maste 	l_uintptr_t	oldval;
102e248c237SEd Maste 	l_uintptr_t	oldlenp;
103e248c237SEd Maste 	l_uintptr_t	newval;
104e248c237SEd Maste 	l_uintptr_t	newlen;
105e248c237SEd Maste 	l_ulong		__spare[4];
106e248c237SEd Maste };
107e248c237SEd Maste 
108e248c237SEd Maste /* Resource limits */
109e248c237SEd Maste #define	LINUX_RLIMIT_CPU	0
110e248c237SEd Maste #define	LINUX_RLIMIT_FSIZE	1
111e248c237SEd Maste #define	LINUX_RLIMIT_DATA	2
112e248c237SEd Maste #define	LINUX_RLIMIT_STACK	3
113e248c237SEd Maste #define	LINUX_RLIMIT_CORE	4
114e248c237SEd Maste #define	LINUX_RLIMIT_RSS	5
115e248c237SEd Maste #define	LINUX_RLIMIT_NPROC	6
116e248c237SEd Maste #define	LINUX_RLIMIT_NOFILE	7
117e248c237SEd Maste #define	LINUX_RLIMIT_MEMLOCK	8
118e248c237SEd Maste #define	LINUX_RLIMIT_AS		9	/* Address space limit */
119e248c237SEd Maste 
120e248c237SEd Maste #define	LINUX_RLIM_NLIMITS	10
121e248c237SEd Maste 
122e248c237SEd Maste struct l_rlimit {
123e248c237SEd Maste 	l_ulong		rlim_cur;
124e248c237SEd Maste 	l_ulong		rlim_max;
125e248c237SEd Maste };
126e248c237SEd Maste 
127e248c237SEd Maste /* stat family of syscalls */
128e248c237SEd Maste struct l_timespec {
129e248c237SEd Maste 	l_time_t	tv_sec;
130e248c237SEd Maste 	l_long		tv_nsec;
131e248c237SEd Maste };
132e248c237SEd Maste 
133e248c237SEd Maste struct l_newstat {
134e248c237SEd Maste 	l_dev_t		st_dev;
135e248c237SEd Maste 	l_ino_t		st_ino;
136e248c237SEd Maste 	l_uint		st_mode;
137e248c237SEd Maste 	l_uint		st_nlink;
138e248c237SEd Maste 
139e248c237SEd Maste 	l_uid_t		st_uid;
140e248c237SEd Maste 	l_gid_t		st_gid;
141e248c237SEd Maste 
142e248c237SEd Maste 	l_dev_t		st_rdev;
143e248c237SEd Maste 	l_ulong		__st_pad1;
144e248c237SEd Maste 	l_off_t		st_size;
145e248c237SEd Maste 	l_int		st_blksize;
146e248c237SEd Maste 	l_int		__st_pad2;
147e248c237SEd Maste 	l_long		st_blocks;
148e248c237SEd Maste 
149e248c237SEd Maste 	struct l_timespec	st_atim;
150e248c237SEd Maste 	struct l_timespec	st_mtim;
151e248c237SEd Maste 	struct l_timespec	st_ctim;
152e248c237SEd Maste 	l_uint		__unused1;
153e248c237SEd Maste 	l_uint		__unused2;
154e248c237SEd Maste };
155e248c237SEd Maste 
156e248c237SEd Maste /* sigaction flags */
157e248c237SEd Maste #define	LINUX_SA_NOCLDSTOP	0x00000001
158e248c237SEd Maste #define	LINUX_SA_NOCLDWAIT	0x00000002
159e248c237SEd Maste #define	LINUX_SA_SIGINFO	0x00000004
160e248c237SEd Maste #define	LINUX_SA_RESTORER	0x04000000
161e248c237SEd Maste #define	LINUX_SA_ONSTACK	0x08000000
162e248c237SEd Maste #define	LINUX_SA_RESTART	0x10000000
163e248c237SEd Maste #define	LINUX_SA_INTERRUPT	0x20000000	/* XXX */
164e248c237SEd Maste #define	LINUX_SA_NOMASK		0x40000000	/* SA_NODEFER */
165e248c237SEd Maste #define	LINUX_SA_ONESHOT	0x80000000	/* SA_RESETHAND */
166e248c237SEd Maste 
167e248c237SEd Maste /* sigprocmask actions */
168e248c237SEd Maste #define	LINUX_SIG_BLOCK		0
169e248c237SEd Maste #define	LINUX_SIG_UNBLOCK	1
170e248c237SEd Maste #define	LINUX_SIG_SETMASK	2
171e248c237SEd Maste 
172e248c237SEd Maste /* sigaltstack */
173e248c237SEd Maste #define	LINUX_MINSIGSTKSZ	2048		/* XXX */
174e248c237SEd Maste 
175e248c237SEd Maste typedef void	(*l_handler_t)(l_int);
176e248c237SEd Maste 
177e248c237SEd Maste typedef struct {
178e248c237SEd Maste 	l_handler_t	lsa_handler;
179e248c237SEd Maste 	l_sigset_t	lsa_mask;
180e248c237SEd Maste 	l_ulong		lsa_flags;
181e248c237SEd Maste 	l_uintptr_t	lsa_restorer;
182e248c237SEd Maste } l_sigaction_t;				/* XXX */
183e248c237SEd Maste 
184e248c237SEd Maste typedef struct {
185e248c237SEd Maste 	l_uintptr_t	ss_sp;
186e248c237SEd Maste 	l_int		ss_flags;
187e248c237SEd Maste 	l_size_t	ss_size;
188e248c237SEd Maste } l_stack_t;
189e248c237SEd Maste 
190e248c237SEd Maste #define	LINUX_SI_PREAMBLE_SIZE	(4 * sizeof(int))
191e248c237SEd Maste #define	LINUX_SI_MAX_SIZE	128
192e248c237SEd Maste #define	LINUX_SI_PAD_SIZE	((LINUX_SI_MAX_SIZE - \
193e248c237SEd Maste 				    LINUX_SI_PREAMBLE_SIZE) / sizeof(l_int))
194e248c237SEd Maste typedef union l_sigval {
195e248c237SEd Maste 	l_int		sival_int;
196e248c237SEd Maste 	l_uintptr_t	sival_ptr;
197e248c237SEd Maste } l_sigval_t;
198e248c237SEd Maste 
199e248c237SEd Maste typedef struct l_siginfo {
200e248c237SEd Maste 	l_int		lsi_signo;
201e248c237SEd Maste 	l_int		lsi_errno;
202e248c237SEd Maste 	l_int		lsi_code;
203e248c237SEd Maste 	union {
204e248c237SEd Maste 		l_int	_pad[LINUX_SI_PAD_SIZE];
205e248c237SEd Maste 
206e248c237SEd Maste 		struct {
207e248c237SEd Maste 			l_pid_t		_pid;
208e248c237SEd Maste 			l_uid_t		_uid;
209e248c237SEd Maste 		} _kill;
210e248c237SEd Maste 
211e248c237SEd Maste 		struct {
212e248c237SEd Maste 			l_timer_t	_tid;
213e248c237SEd Maste 			l_int		_overrun;
214e248c237SEd Maste 			char		_pad[sizeof(l_uid_t) - sizeof(int)];
215e248c237SEd Maste 			union l_sigval	_sigval;
216e248c237SEd Maste 			l_uint		_sys_private;
217e248c237SEd Maste 		} _timer;
218e248c237SEd Maste 
219e248c237SEd Maste 		struct {
220e248c237SEd Maste 			l_pid_t		_pid;		/* sender's pid */
221e248c237SEd Maste 			l_uid_t		_uid;		/* sender's uid */
222e248c237SEd Maste 			union l_sigval	_sigval;
223e248c237SEd Maste 		} _rt;
224e248c237SEd Maste 
225e248c237SEd Maste 		struct {
226e248c237SEd Maste 			l_pid_t		_pid;		/* which child */
227e248c237SEd Maste 			l_uid_t		_uid;		/* sender's uid */
228e248c237SEd Maste 			l_int		_status;	/* exit code */
229e248c237SEd Maste 			l_clock_t	_utime;
230e248c237SEd Maste 			l_clock_t	_stime;
231e248c237SEd Maste 		} _sigchld;
232e248c237SEd Maste 
233e248c237SEd Maste 		struct {
234e248c237SEd Maste 			l_uintptr_t	_addr;	/* Faulting insn/memory ref. */
235e248c237SEd Maste 		} _sigfault;
236e248c237SEd Maste 
237e248c237SEd Maste 		struct {
238e248c237SEd Maste 			l_long		_band;	/* POLL_IN,POLL_OUT,POLL_MSG */
239e248c237SEd Maste 			l_int		_fd;
240e248c237SEd Maste 		} _sigpoll;
241e248c237SEd Maste 	} _sifields;
242e248c237SEd Maste } l_siginfo_t;
243e248c237SEd Maste 
244e248c237SEd Maste #define	lsi_pid		_sifields._kill._pid
245e248c237SEd Maste #define	lsi_uid		_sifields._kill._uid
246e248c237SEd Maste #define	lsi_tid		_sifields._timer._tid
247e248c237SEd Maste #define	lsi_overrun	_sifields._timer._overrun
248e248c237SEd Maste #define	lsi_sys_private	_sifields._timer._sys_private
249e248c237SEd Maste #define	lsi_status	_sifields._sigchld._status
250e248c237SEd Maste #define	lsi_utime	_sifields._sigchld._utime
251e248c237SEd Maste #define	lsi_stime	_sifields._sigchld._stime
252e248c237SEd Maste #define	lsi_value	_sifields._rt._sigval
253e248c237SEd Maste #define	lsi_int		_sifields._rt._sigval.sival_int
254e248c237SEd Maste #define	lsi_ptr		_sifields._rt._sigval.sival_ptr
255e248c237SEd Maste #define	lsi_addr	_sifields._sigfault._addr
256e248c237SEd Maste #define	lsi_band	_sifields._sigpoll._band
257e248c237SEd Maste #define	lsi_fd		_sifields._sigpoll._fd
258e248c237SEd Maste 
259e248c237SEd Maste union l_semun {
260e248c237SEd Maste 	l_int		val;
261e248c237SEd Maste 	l_uintptr_t	buf;
262e248c237SEd Maste 	l_uintptr_t	array;
263e248c237SEd Maste 	l_uintptr_t	__buf;
264e248c237SEd Maste 	l_uintptr_t	__pad;
265e248c237SEd Maste };
266e248c237SEd Maste 
267e248c237SEd Maste struct l_sockaddr {
268e248c237SEd Maste 	l_ushort	sa_family;
269e248c237SEd Maste 	char		sa_data[14];
270e248c237SEd Maste };
271e248c237SEd Maste 
272e248c237SEd Maste struct l_ifmap {
273e248c237SEd Maste 	l_ulong		mem_start;
274e248c237SEd Maste 	l_ulong		mem_end;
275e248c237SEd Maste 	l_ushort	base_addr;
276e248c237SEd Maste 	u_char		irq;
277e248c237SEd Maste 	u_char		dma;
278e248c237SEd Maste 	u_char		port;
279e248c237SEd Maste } __packed;
280e248c237SEd Maste 
281e248c237SEd Maste #define	LINUX_IFHWADDRLEN	6
282e248c237SEd Maste #define	LINUX_IFNAMSIZ		16
283e248c237SEd Maste 
284e248c237SEd Maste struct l_ifreq {
285e248c237SEd Maste 	union {
286e248c237SEd Maste 		char	ifrn_name[LINUX_IFNAMSIZ];
287e248c237SEd Maste 	} ifr_ifrn;
288e248c237SEd Maste 
289e248c237SEd Maste 	union {
290e248c237SEd Maste 		struct l_sockaddr	ifru_addr;
291e248c237SEd Maste 		struct l_sockaddr	ifru_dstaddr;
292e248c237SEd Maste 		struct l_sockaddr	ifru_broadaddr;
293e248c237SEd Maste 		struct l_sockaddr	ifru_netmask;
294e248c237SEd Maste 		struct l_sockaddr	ifru_hwaddr;
295e248c237SEd Maste 		l_short		ifru_flags[1];
296e248c237SEd Maste 		l_int		ifru_ivalue;
297e248c237SEd Maste 		l_int		ifru_mtu;
298e248c237SEd Maste 		struct l_ifmap	ifru_map;
299e248c237SEd Maste 		char		ifru_slave[LINUX_IFNAMSIZ];
300e248c237SEd Maste 		l_uintptr_t	ifru_data;
301e248c237SEd Maste 	} ifr_ifru;
302e248c237SEd Maste } __packed;
303e248c237SEd Maste 
304e248c237SEd Maste #define	ifr_name	ifr_ifrn.ifrn_name	/* Interface name */
305e248c237SEd Maste #define	ifr_hwaddr	ifr_ifru.ifru_hwaddr	/* MAC address */
306e248c237SEd Maste #define	ifr_ifindex	ifr_ifru.ifru_ivalue	/* Interface index */
307e248c237SEd Maste 
308e248c237SEd Maste #define	linux_copyout_rusage(r, u)	copyout(r, u, sizeof(*r))
309e248c237SEd Maste 
310e248c237SEd Maste /* robust futexes */
311e248c237SEd Maste struct linux_robust_list {
312e248c237SEd Maste 	l_uintptr_t			next;
313e248c237SEd Maste };
314e248c237SEd Maste 
315e248c237SEd Maste struct linux_robust_list_head {
316e248c237SEd Maste 	struct linux_robust_list	list;
317e248c237SEd Maste 	l_long				futex_offset;
318e248c237SEd Maste 	l_uintptr_t			pending_list;
319e248c237SEd Maste };
320e248c237SEd Maste 
321e248c237SEd Maste #endif /* _ARM64_LINUX_H_ */
322