xref: /freebsd/sys/amd64/linux/linux.h (revision ba3c1f5972d7b90feb6e6da47905ff2757e0fe57)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 1994-1996 Søren Schmidt
5  * All rights reserved.
6  * Copyright (c) 2013 Dmitry Chagin <dchagin@FreeBSD.org>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31 
32 #ifndef _AMD64_LINUX_H_
33 #define	_AMD64_LINUX_H_
34 
35 #include <sys/abi_compat.h>
36 
37 #include <compat/linux/linux.h>
38 #include <amd64/linux/linux_syscall.h>
39 
40 #define	LINUX_LEGACY_SYSCALLS
41 
42 #define	LINUX_DTRACE	linuxulator
43 
44 /*
45  * Provide a separate set of types for the Linux types.
46  */
47 typedef int32_t		l_int;
48 typedef int64_t		l_long;
49 typedef int16_t		l_short;
50 typedef uint32_t	l_uint;
51 typedef uint64_t	l_ulong;
52 typedef uint16_t	l_ushort;
53 
54 typedef l_ulong		l_uintptr_t;
55 typedef l_long		l_clock_t;
56 typedef l_int		l_daddr_t;
57 typedef l_uint		l_gid_t;
58 typedef l_ushort	l_gid16_t;
59 typedef l_uint		l_uid_t;
60 typedef	l_ushort	l_uid16_t;
61 typedef l_ulong		l_ino_t;
62 typedef l_int		l_key_t;
63 typedef l_long		l_loff_t;
64 typedef l_uint		l_mode_t;
65 typedef l_long		l_off_t;
66 typedef l_int		l_pid_t;
67 typedef l_ulong		l_size_t;
68 typedef l_long		l_ssize_t;
69 typedef l_long		l_suseconds_t;
70 typedef l_long		l_time_t;
71 typedef l_int		l_timer_t;
72 typedef l_int		l_mqd_t;
73 typedef l_size_t	l_socklen_t;
74 typedef	l_ulong		l_fd_mask;
75 
76 #include <compat/linux/linux_siginfo.h>
77 
78 typedef struct {
79 	l_int		val[2];
80 } l_fsid_t;
81 
82 typedef struct {
83 	l_time_t	tv_sec;
84 	l_suseconds_t	tv_usec;
85 } l_timeval;
86 
87 #define	l_fd_set	fd_set
88 
89 /*
90  * Miscellaneous
91  */
92 #define LINUX_AT_COUNT		21	/* Count of used aux entry types.
93 					 * Keep this synchronized with
94 					 * linux_copyout_auxargs() code.
95 					 */
96 
97 struct l___sysctl_args
98 {
99 	l_uintptr_t	name;
100 	l_int		nlen;
101 	l_uintptr_t	oldval;
102 	l_uintptr_t	oldlenp;
103 	l_uintptr_t	newval;
104 	l_size_t	newlen;
105 	l_ulong		__spare[4];
106 };
107 
108 /* Resource limits */
109 #define	LINUX_RLIMIT_CPU	0
110 #define	LINUX_RLIMIT_FSIZE	1
111 #define	LINUX_RLIMIT_DATA	2
112 #define	LINUX_RLIMIT_STACK	3
113 #define	LINUX_RLIMIT_CORE	4
114 #define	LINUX_RLIMIT_RSS	5
115 #define	LINUX_RLIMIT_NPROC	6
116 #define	LINUX_RLIMIT_NOFILE	7
117 #define	LINUX_RLIMIT_MEMLOCK	8
118 #define	LINUX_RLIMIT_AS		9	/* Address space limit */
119 
120 #define	LINUX_RLIM_NLIMITS	10
121 
122 struct l_rlimit {
123 	l_ulong		rlim_cur;
124 	l_ulong		rlim_max;
125 };
126 
127 /*
128  * stat family of syscalls
129  */
130 struct l_timespec {
131 	l_time_t	tv_sec;
132 	l_long		tv_nsec;
133 };
134 
135 struct l_newstat {
136 	l_ulong		st_dev;
137 	l_ino_t		st_ino;
138 	l_ulong		st_nlink;
139 	l_uint		st_mode;
140 	l_uid_t		st_uid;
141 	l_gid_t		st_gid;
142 	l_uint		__st_pad0;
143 	l_ulong		st_rdev;
144 	l_off_t		st_size;
145 	l_long		st_blksize;
146 	l_long		st_blocks;
147 	struct l_timespec	st_atim;
148 	struct l_timespec	st_mtim;
149 	struct l_timespec	st_ctim;
150 	l_long		__unused1;
151 	l_long		__unused2;
152 	l_long		__unused3;
153 };
154 
155 /* sigaction flags */
156 #define	LINUX_SA_NOCLDSTOP	0x00000001
157 #define	LINUX_SA_NOCLDWAIT	0x00000002
158 #define	LINUX_SA_SIGINFO	0x00000004
159 #define	LINUX_SA_RESTORER	0x04000000
160 #define	LINUX_SA_ONSTACK	0x08000000
161 #define	LINUX_SA_RESTART	0x10000000
162 #define	LINUX_SA_INTERRUPT	0x20000000
163 #define	LINUX_SA_NOMASK		0x40000000
164 #define	LINUX_SA_ONESHOT	0x80000000
165 
166 /* sigaltstack */
167 #define	LINUX_MINSIGSTKSZ	2048
168 
169 typedef void	(*l_handler_t)(l_int);
170 
171 typedef struct {
172 	l_handler_t	lsa_handler;
173 	l_ulong		lsa_flags;
174 	l_uintptr_t	lsa_restorer;
175 	l_sigset_t	lsa_mask;
176 } l_sigaction_t;
177 
178 typedef struct {
179 	l_uintptr_t	ss_sp;
180 	l_int		ss_flags;
181 	l_size_t	ss_size;
182 } l_stack_t;
183 
184 /*
185  * mount flags
186  */
187 #define	LINUX_MS_RDONLY		0x0001
188 #define	LINUX_MS_NOSUID		0x0002
189 #define	LINUX_MS_NODEV		0x0004
190 #define	LINUX_MS_NOEXEC		0x0008
191 #define	LINUX_MS_REMOUNT	0x0020
192 
193 /*
194  * SystemV IPC defines
195  */
196 #define	LINUX_IPC_RMID		0
197 #define	LINUX_IPC_SET		1
198 #define	LINUX_IPC_STAT		2
199 #define	LINUX_IPC_INFO		3
200 
201 #define	LINUX_SHM_LOCK		11
202 #define	LINUX_SHM_UNLOCK	12
203 #define	LINUX_SHM_STAT		13
204 #define	LINUX_SHM_INFO		14
205 
206 #define	LINUX_SHM_RDONLY	0x1000
207 #define	LINUX_SHM_RND		0x2000
208 #define	LINUX_SHM_REMAP		0x4000
209 
210 /* semctl commands */
211 #define	LINUX_GETPID		11
212 #define	LINUX_GETVAL		12
213 #define	LINUX_GETALL		13
214 #define	LINUX_GETNCNT		14
215 #define	LINUX_GETZCNT		15
216 #define	LINUX_SETVAL		16
217 #define	LINUX_SETALL		17
218 #define	LINUX_SEM_STAT		18
219 #define	LINUX_SEM_INFO		19
220 
221 union l_semun {
222 	l_int		val;
223 	l_uintptr_t	buf;
224 	l_uintptr_t	array;
225 	l_uintptr_t	__buf;
226 	l_uintptr_t	__pad;
227 };
228 
229 #define LINUX_ARCH_SET_GS		0x1001
230 #define LINUX_ARCH_SET_FS		0x1002
231 #define LINUX_ARCH_GET_FS		0x1003
232 #define LINUX_ARCH_GET_GS		0x1004
233 #define LINUX_ARCH_CET_STATUS		0x3001
234 
235 #define	linux_copyout_rusage(r, u)	copyout(r, u, sizeof(*r))
236 
237 /* This corresponds to 'struct user_regs_struct' in Linux. */
238 struct linux_pt_regset {
239 	l_ulong	r15;
240 	l_ulong	r14;
241 	l_ulong	r13;
242 	l_ulong	r12;
243 	l_ulong	rbp;
244 	l_ulong	rbx;
245 	l_ulong	r11;
246 	l_ulong	r10;
247 	l_ulong	r9;
248 	l_ulong	r8;
249 	l_ulong	rax;
250 	l_ulong	rcx;
251 	l_ulong	rdx;
252 	l_ulong	rsi;
253 	l_ulong	rdi;
254 	l_ulong	orig_rax;
255 	l_ulong	rip;
256 	l_ulong	cs;
257 	l_ulong	eflags;
258 	l_ulong	rsp;
259 	l_ulong	ss;
260 	l_ulong fs_base;
261 	l_ulong gs_base;
262 	l_ulong ds;
263 	l_ulong es;
264 	l_ulong fs;
265 	l_ulong gs;
266 };
267 
268 #ifdef _KERNEL
269 struct reg;
270 struct syscall_info;
271 
272 void	bsd_to_linux_regset(const struct reg *b_reg,
273 	    struct linux_pt_regset *l_regset);
274 void	linux_to_bsd_regset(struct reg *b_reg,
275 	    const struct linux_pt_regset *l_regset);
276 void	linux_ptrace_get_syscall_info_machdep(const struct reg *reg,
277 	    struct syscall_info *si);
278 int	linux_ptrace_getregs_machdep(struct thread *td, pid_t pid,
279 	    struct linux_pt_regset *l_regset);
280 int	linux_ptrace_peekuser(struct thread *td, pid_t pid,
281 	    void *addr, void *data);
282 int	linux_ptrace_pokeuser(struct thread *td, pid_t pid,
283 	    void *addr, void *data);
284 #endif /* _KERNEL */
285 
286 #endif /* !_AMD64_LINUX_H_ */
287