xref: /freebsd/sys/arm64/linux/linux.h (revision 270e01d4)
1e248c237SEd Maste /*-
2e248c237SEd Maste  * Copyright (c) 1994-1996 Søren Schmidt
31ca6b15bSDmitry Chagin  * Copyright (c) 2013 Dmitry Chagin <dchagin@FreeBSD.org>
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 #ifndef _ARM64_LINUX_H_
29e248c237SEd Maste #define	_ARM64_LINUX_H_
30e248c237SEd Maste 
31562894f0SBrooks Davis #include <sys/abi_compat.h>
32562894f0SBrooks Davis 
33e248c237SEd Maste #include <compat/linux/linux.h>
34e248c237SEd Maste #include <arm64/linux/linux_syscall.h>
35e248c237SEd Maste 
36e248c237SEd Maste #define	LINUX_DTRACE	linuxulator
37e248c237SEd Maste 
38e248c237SEd Maste /* Provide a separate set of types for the Linux types */
39e248c237SEd Maste typedef int32_t		l_int;
40e248c237SEd Maste typedef int64_t		l_long;
41e248c237SEd Maste typedef int16_t		l_short;
42e248c237SEd Maste typedef uint32_t	l_uint;
43e248c237SEd Maste typedef uint64_t	l_ulong;
44e248c237SEd Maste typedef uint16_t	l_ushort;
45e248c237SEd Maste 
46e248c237SEd Maste typedef l_ulong		l_uintptr_t;
47e248c237SEd Maste typedef l_long		l_clock_t;
48e248c237SEd Maste typedef l_int		l_daddr_t;
49e248c237SEd Maste typedef l_uint		l_gid_t;
50e248c237SEd Maste typedef l_ushort	l_gid16_t;	/* XXX */
51e248c237SEd Maste typedef l_uint		l_uid_t;
52e248c237SEd Maste typedef l_ushort	l_uid16_t;	/* XXX */
53e248c237SEd Maste typedef l_ulong		l_ino_t;
54e248c237SEd Maste typedef l_int		l_key_t;
55e248c237SEd Maste typedef l_long		l_loff_t;
56e248c237SEd Maste typedef l_uint		l_mode_t;
57e248c237SEd Maste typedef l_long		l_off_t;
58e248c237SEd Maste typedef l_int		l_pid_t;
59e248c237SEd Maste typedef l_ulong		l_size_t;
60e248c237SEd Maste typedef l_long		l_suseconds_t;
61e248c237SEd Maste typedef l_long		l_time_t;
62e248c237SEd Maste typedef l_int		l_timer_t;	/* XXX */
63308e194cSEdward Tomasz Napierala typedef l_int		l_mqd_t;
64e248c237SEd Maste typedef l_ulong		l_fd_mask;
65e248c237SEd Maste 
66af557e64SDmitry Chagin #include <compat/linux/linux_siginfo.h>
67af557e64SDmitry Chagin 
68e248c237SEd Maste typedef struct {
69e248c237SEd Maste 	l_int		val[2];
70e248c237SEd Maste } l_fsid_t;
71e248c237SEd Maste 
72e248c237SEd Maste typedef struct {
73e248c237SEd Maste 	l_time_t	tv_sec;
74e248c237SEd Maste 	l_suseconds_t	tv_usec;
75e248c237SEd Maste } l_timeval;
76e248c237SEd Maste 
77e248c237SEd Maste #define	l_fd_set	fd_set
78e248c237SEd Maste 
79e248c237SEd Maste /* Miscellaneous */
8056c5230aSDmitry Chagin #define	LINUX_AT_COUNT		21	/* Count of used aux entry types.
8156c5230aSDmitry Chagin 					 * Keep this synchronized with
8256c5230aSDmitry Chagin 					 * linux_copyout_auxargs() code.
8356c5230aSDmitry Chagin 					 */
84e248c237SEd Maste 
85e248c237SEd Maste struct l___sysctl_args
86e248c237SEd Maste {
87e248c237SEd Maste 	l_uintptr_t	name;
88e248c237SEd Maste 	l_int		nlen;
89e248c237SEd Maste 	l_uintptr_t	oldval;
90e248c237SEd Maste 	l_uintptr_t	oldlenp;
91e248c237SEd Maste 	l_uintptr_t	newval;
92e248c237SEd Maste 	l_uintptr_t	newlen;
93e248c237SEd Maste 	l_ulong		__spare[4];
94e248c237SEd Maste };
95e248c237SEd Maste 
96e248c237SEd Maste /* Resource limits */
97e248c237SEd Maste #define	LINUX_RLIMIT_CPU	0
98e248c237SEd Maste #define	LINUX_RLIMIT_FSIZE	1
99e248c237SEd Maste #define	LINUX_RLIMIT_DATA	2
100e248c237SEd Maste #define	LINUX_RLIMIT_STACK	3
101e248c237SEd Maste #define	LINUX_RLIMIT_CORE	4
102e248c237SEd Maste #define	LINUX_RLIMIT_RSS	5
103e248c237SEd Maste #define	LINUX_RLIMIT_NPROC	6
104e248c237SEd Maste #define	LINUX_RLIMIT_NOFILE	7
105e248c237SEd Maste #define	LINUX_RLIMIT_MEMLOCK	8
106e248c237SEd Maste #define	LINUX_RLIMIT_AS		9	/* Address space limit */
107e248c237SEd Maste 
108e248c237SEd Maste #define	LINUX_RLIM_NLIMITS	10
109e248c237SEd Maste 
110e248c237SEd Maste struct l_rlimit {
111e248c237SEd Maste 	l_ulong		rlim_cur;
112e248c237SEd Maste 	l_ulong		rlim_max;
113e248c237SEd Maste };
114e248c237SEd Maste 
115e248c237SEd Maste /* stat family of syscalls */
116e248c237SEd Maste struct l_timespec {
117e248c237SEd Maste 	l_time_t	tv_sec;
118e248c237SEd Maste 	l_long		tv_nsec;
119e248c237SEd Maste };
120e248c237SEd Maste 
121fc37be24SDmitry Chagin #define	LINUX_O_DIRECTORY	000040000	/* Must be a directory */
122fc37be24SDmitry Chagin #define	LINUX_O_NOFOLLOW	000100000	/* Do not follow links */
123fc37be24SDmitry Chagin #define	LINUX_O_DIRECT		000200000	/* Direct disk access hint */
124fc37be24SDmitry Chagin #define	LINUX_O_LARGEFILE	000400000
125fc37be24SDmitry Chagin 
126e248c237SEd Maste struct l_newstat {
127e0bfe0d6SDmitry Chagin 	l_ulong		st_dev;
128e248c237SEd Maste 	l_ino_t		st_ino;
129e248c237SEd Maste 	l_uint		st_mode;
130e248c237SEd Maste 	l_uint		st_nlink;
131e248c237SEd Maste 
132e248c237SEd Maste 	l_uid_t		st_uid;
133e248c237SEd Maste 	l_gid_t		st_gid;
134e248c237SEd Maste 
135e0bfe0d6SDmitry Chagin 	l_ulong		st_rdev;
136e248c237SEd Maste 	l_ulong		__st_pad1;
137e248c237SEd Maste 	l_off_t		st_size;
138e248c237SEd Maste 	l_int		st_blksize;
139e248c237SEd Maste 	l_int		__st_pad2;
140e248c237SEd Maste 	l_long		st_blocks;
141e248c237SEd Maste 
142e248c237SEd Maste 	struct l_timespec	st_atim;
143e248c237SEd Maste 	struct l_timespec	st_mtim;
144e248c237SEd Maste 	struct l_timespec	st_ctim;
145e248c237SEd Maste 	l_uint		__unused1;
146e248c237SEd Maste 	l_uint		__unused2;
147e248c237SEd Maste };
148e248c237SEd Maste 
149e248c237SEd Maste /* sigaction flags */
150e248c237SEd Maste #define	LINUX_SA_NOCLDSTOP	0x00000001
151e248c237SEd Maste #define	LINUX_SA_NOCLDWAIT	0x00000002
152e248c237SEd Maste #define	LINUX_SA_SIGINFO	0x00000004
153e248c237SEd Maste #define	LINUX_SA_RESTORER	0x04000000
154e248c237SEd Maste #define	LINUX_SA_ONSTACK	0x08000000
155e248c237SEd Maste #define	LINUX_SA_RESTART	0x10000000
156e248c237SEd Maste #define	LINUX_SA_INTERRUPT	0x20000000	/* XXX */
157e248c237SEd Maste #define	LINUX_SA_NOMASK		0x40000000	/* SA_NODEFER */
158e248c237SEd Maste #define	LINUX_SA_ONESHOT	0x80000000	/* SA_RESETHAND */
159e248c237SEd Maste 
160e248c237SEd Maste typedef void	(*l_handler_t)(l_int);
161e248c237SEd Maste 
162e248c237SEd Maste typedef struct {
163e248c237SEd Maste 	l_handler_t	lsa_handler;
164e248c237SEd Maste 	l_ulong		lsa_flags;
165e248c237SEd Maste 	l_uintptr_t	lsa_restorer;
16695e1f42eSMitchell Horne 	l_sigset_t	lsa_mask;
167e248c237SEd Maste } l_sigaction_t;				/* XXX */
168e248c237SEd Maste 
169e248c237SEd Maste typedef struct {
170e248c237SEd Maste 	l_uintptr_t	ss_sp;
171e248c237SEd Maste 	l_int		ss_flags;
172e248c237SEd Maste 	l_size_t	ss_size;
173e248c237SEd Maste } l_stack_t;
174e248c237SEd Maste 
175e248c237SEd Maste union l_semun {
176e248c237SEd Maste 	l_int		val;
177e248c237SEd Maste 	l_uintptr_t	buf;
178e248c237SEd Maste 	l_uintptr_t	array;
179e248c237SEd Maste 	l_uintptr_t	__buf;
180e248c237SEd Maste 	l_uintptr_t	__pad;
181e248c237SEd Maste };
182e248c237SEd Maste 
183e248c237SEd Maste #define	linux_copyout_rusage(r, u)	copyout(r, u, sizeof(*r))
184e248c237SEd Maste 
18545d99014SEdward Tomasz Napierala struct linux_pt_regset {
18645d99014SEdward Tomasz Napierala 	l_ulong x[31];
18745d99014SEdward Tomasz Napierala 	l_ulong sp;
18845d99014SEdward Tomasz Napierala 	l_ulong pc;
18945d99014SEdward Tomasz Napierala 	l_ulong cpsr;
19045d99014SEdward Tomasz Napierala };
19145d99014SEdward Tomasz Napierala 
192d416ee86SDmitry Chagin #ifdef _KERNEL
19345d99014SEdward Tomasz Napierala struct reg;
1940bf8d5d5SEdward Tomasz Napierala struct syscall_info;
19545d99014SEdward Tomasz Napierala 
1963417c298SEdward Tomasz Napierala void	bsd_to_linux_regset(const struct reg *b_reg,
19745d99014SEdward Tomasz Napierala 	    struct linux_pt_regset *l_regset);
1986f397bc0SEdward Tomasz Napierala void	linux_to_bsd_regset(struct reg *b_reg,
1996f397bc0SEdward Tomasz Napierala 	    const struct linux_pt_regset *l_regset);
2000bf8d5d5SEdward Tomasz Napierala void	linux_ptrace_get_syscall_info_machdep(const struct reg *reg,
2010bf8d5d5SEdward Tomasz Napierala 	    struct syscall_info *si);
2020bf8d5d5SEdward Tomasz Napierala int	linux_ptrace_getregs_machdep(struct thread *td, pid_t pid,
2030bf8d5d5SEdward Tomasz Napierala 	    struct linux_pt_regset *l_regset);
204dd2a6cd7SDmitry Chagin int	linux_ptrace_peekuser(struct thread *td, pid_t pid,
205dd2a6cd7SDmitry Chagin 	    void *addr, void *data);
2063d0addcdSDmitry Chagin int	linux_ptrace_pokeuser(struct thread *td, pid_t pid,
2073d0addcdSDmitry Chagin 	    void *addr, void *data);
208d416ee86SDmitry Chagin #endif /* _KERNEL */
20945d99014SEdward Tomasz Napierala 
210e248c237SEd Maste #endif /* _ARM64_LINUX_H_ */
211