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