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