xref: /freebsd/sys/amd64/linux32/linux.h (revision 2a1cf1b6b55c8326bbe85d0fdf17b0f2fb9b34ce)
1ea0fabbcSTim J. Robbins /*-
2c49761ddSPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3c49761ddSPedro F. Giffuni  *
4ea0fabbcSTim J. Robbins  * Copyright (c) 2004 Tim J. Robbins
5ea0fabbcSTim J. Robbins  * Copyright (c) 2001 Doug Rabson
69a14aa01SUlrich Spörlein  * Copyright (c) 1994-1996 Søren Schmidt
7ea0fabbcSTim J. Robbins  * All rights reserved.
8ea0fabbcSTim J. Robbins  *
9ea0fabbcSTim J. Robbins  * Redistribution and use in source and binary forms, with or without
10ea0fabbcSTim J. Robbins  * modification, are permitted provided that the following conditions
11ea0fabbcSTim J. Robbins  * are met:
12ea0fabbcSTim J. Robbins  * 1. Redistributions of source code must retain the above copyright
13ea0fabbcSTim J. Robbins  *    notice, this list of conditions and the following disclaimer
14ea0fabbcSTim J. Robbins  *    in this position and unchanged.
15ea0fabbcSTim J. Robbins  * 2. Redistributions in binary form must reproduce the above copyright
16ea0fabbcSTim J. Robbins  *    notice, this list of conditions and the following disclaimer in the
17ea0fabbcSTim J. Robbins  *    documentation and/or other materials provided with the distribution.
18ea0fabbcSTim J. Robbins  * 3. The name of the author may not be used to endorse or promote products
19ea0fabbcSTim J. Robbins  *    derived from this software without specific prior written permission
20ea0fabbcSTim J. Robbins  *
21ea0fabbcSTim J. Robbins  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22ea0fabbcSTim J. Robbins  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23ea0fabbcSTim J. Robbins  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24ea0fabbcSTim J. Robbins  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25ea0fabbcSTim J. Robbins  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26ea0fabbcSTim J. Robbins  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27ea0fabbcSTim J. Robbins  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28ea0fabbcSTim J. Robbins  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29ea0fabbcSTim J. Robbins  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30ea0fabbcSTim J. Robbins  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31ea0fabbcSTim J. Robbins  */
32ea0fabbcSTim J. Robbins 
33a4e3bad7SJung-uk Kim #ifndef _AMD64_LINUX_H_
34a4e3bad7SJung-uk Kim #define	_AMD64_LINUX_H_
35ea0fabbcSTim J. Robbins 
36562894f0SBrooks Davis #include <sys/abi_compat.h>
37562894f0SBrooks Davis 
384ab7403bSDmitry Chagin #include <compat/linux/linux.h>
39ea0fabbcSTim J. Robbins #include <amd64/linux32/linux32_syscall.h>
40ea0fabbcSTim J. Robbins 
41931e2a1aSEd Maste #define	LINUX_LEGACY_SYSCALLS
42931e2a1aSEd Maste 
4319e252baSAlexander Leidinger #define	LINUX_DTRACE	linuxulator32
44ea0fabbcSTim J. Robbins 
45ea0fabbcSTim J. Robbins #define	LINUX32_MAXDSIZ		(512 * 1024 * 1024)	/* 512MB */
46ea0fabbcSTim J. Robbins #define	LINUX32_MAXSSIZ		(64 * 1024 * 1024)	/* 64MB */
47ea0fabbcSTim J. Robbins #define	LINUX32_MAXVMEM		0			/* Unlimited */
48ea0fabbcSTim J. Robbins 
49*2a1cf1b6SDmitry Chagin #define	LINUX_ARCHWANT_MMAP2PGOFF	1	/* 32-bit off_t want offset
50*2a1cf1b6SDmitry Chagin 						 * represented in multiples
51*2a1cf1b6SDmitry Chagin 						 * of page size. */
52*2a1cf1b6SDmitry Chagin 
53ea0fabbcSTim J. Robbins /*
54ea0fabbcSTim J. Robbins  * Provide a separate set of types for the Linux types.
55ea0fabbcSTim J. Robbins  */
56ea0fabbcSTim J. Robbins typedef int		l_int;
57ea0fabbcSTim J. Robbins typedef int32_t		l_long;
58ea0fabbcSTim J. Robbins typedef int64_t		l_longlong;
59ea0fabbcSTim J. Robbins typedef short		l_short;
60ea0fabbcSTim J. Robbins typedef unsigned int	l_uint;
61ea0fabbcSTim J. Robbins typedef uint32_t	l_ulong;
62ea0fabbcSTim J. Robbins typedef uint64_t	l_ulonglong;
63ea0fabbcSTim J. Robbins typedef unsigned short	l_ushort;
64ea0fabbcSTim J. Robbins 
65ea0fabbcSTim J. Robbins typedef l_ulong		l_uintptr_t;
66ea0fabbcSTim J. Robbins typedef l_long		l_clock_t;
67ea0fabbcSTim J. Robbins typedef l_int		l_daddr_t;
68ea0fabbcSTim J. Robbins typedef l_uint		l_gid_t;
69ea0fabbcSTim J. Robbins typedef l_ushort	l_gid16_t;
70ea0fabbcSTim J. Robbins typedef l_ulong		l_ino_t;
71ea0fabbcSTim J. Robbins typedef l_int		l_key_t;
72ea0fabbcSTim J. Robbins typedef l_longlong	l_loff_t;
73ea0fabbcSTim J. Robbins typedef l_ushort	l_mode_t;
740af71035SDoug Ambrisko typedef l_long		l_off_t;
75ea0fabbcSTim J. Robbins typedef l_int		l_pid_t;
76ea0fabbcSTim J. Robbins typedef l_uint		l_size_t;
77ea0fabbcSTim J. Robbins typedef l_long		l_suseconds_t;
78ea0fabbcSTim J. Robbins typedef l_long		l_time_t;
79bfcce1a9SDmitry Chagin typedef l_longlong	l_time64_t;
80ea0fabbcSTim J. Robbins typedef l_uint		l_uid_t;
81ea0fabbcSTim J. Robbins typedef l_ushort	l_uid16_t;
82aa8b2011SKonstantin Belousov typedef l_int		l_timer_t;
83aa8b2011SKonstantin Belousov typedef l_int		l_mqd_t;
843e89b641SDmitry Chagin typedef	l_ulong		l_fd_mask;
85ea0fabbcSTim J. Robbins 
86af557e64SDmitry Chagin #include <compat/linux/linux_siginfo.h>
87af557e64SDmitry Chagin 
88ea0fabbcSTim J. Robbins typedef struct {
89ea0fabbcSTim J. Robbins 	l_int		val[2];
9019593f77SDmitry Chagin } l_fsid_t;
91ea0fabbcSTim J. Robbins 
92ea0fabbcSTim J. Robbins typedef struct {
93ea0fabbcSTim J. Robbins 	l_time_t	tv_sec;
94ea0fabbcSTim J. Robbins 	l_suseconds_t	tv_usec;
9503cc95d2SDmitry Chagin } l_timeval;
96ea0fabbcSTim J. Robbins 
970e26e54bSDmitry Chagin typedef struct {
980e26e54bSDmitry Chagin 	l_time64_t	tv_sec;
990e26e54bSDmitry Chagin 	l_time64_t	tv_usec;
1000e26e54bSDmitry Chagin } l_sock_timeval;
1010e26e54bSDmitry Chagin 
102ea0fabbcSTim J. Robbins #define	l_fd_set	fd_set
103ea0fabbcSTim J. Robbins 
104ea0fabbcSTim J. Robbins /*
105ea0fabbcSTim J. Robbins  * Miscellaneous
106ea0fabbcSTim J. Robbins  */
1077d8c9839SDmitry Chagin #define	LINUX_AT_COUNT		22	/* Count of used aux entry types.
1084d7c2e8aSDmitry Chagin 					 * Keep this synchronized with
10956c5230aSDmitry Chagin 					 * linux_copyout_auxargs() code.
1104d7c2e8aSDmitry Chagin 					 */
111ea0fabbcSTim J. Robbins struct l___sysctl_args
112ea0fabbcSTim J. Robbins {
113ea0fabbcSTim J. Robbins 	l_uintptr_t	name;
114ea0fabbcSTim J. Robbins 	l_int		nlen;
115ea0fabbcSTim J. Robbins 	l_uintptr_t	oldval;
116ea0fabbcSTim J. Robbins 	l_uintptr_t	oldlenp;
117ea0fabbcSTim J. Robbins 	l_uintptr_t	newval;
118ea0fabbcSTim J. Robbins 	l_size_t	newlen;
119ea0fabbcSTim J. Robbins 	l_ulong		__spare[4];
12019593f77SDmitry Chagin };
121ea0fabbcSTim J. Robbins 
122ea0fabbcSTim J. Robbins /* Resource limits */
123ea0fabbcSTim J. Robbins #define	LINUX_RLIMIT_CPU	0
124ea0fabbcSTim J. Robbins #define	LINUX_RLIMIT_FSIZE	1
125ea0fabbcSTim J. Robbins #define	LINUX_RLIMIT_DATA	2
126ea0fabbcSTim J. Robbins #define	LINUX_RLIMIT_STACK	3
127ea0fabbcSTim J. Robbins #define	LINUX_RLIMIT_CORE	4
128ea0fabbcSTim J. Robbins #define	LINUX_RLIMIT_RSS	5
129ea0fabbcSTim J. Robbins #define	LINUX_RLIMIT_NPROC	6
130ea0fabbcSTim J. Robbins #define	LINUX_RLIMIT_NOFILE	7
131ea0fabbcSTim J. Robbins #define	LINUX_RLIMIT_MEMLOCK	8
132a4e3bad7SJung-uk Kim #define	LINUX_RLIMIT_AS		9	/* Address space limit */
133ea0fabbcSTim J. Robbins 
134ea0fabbcSTim J. Robbins #define	LINUX_RLIM_NLIMITS	10
135ea0fabbcSTim J. Robbins 
136ea0fabbcSTim J. Robbins struct l_rlimit {
137ea0fabbcSTim J. Robbins 	l_ulong rlim_cur;
138ea0fabbcSTim J. Robbins 	l_ulong rlim_max;
13919593f77SDmitry Chagin };
140ea0fabbcSTim J. Robbins 
141ea0fabbcSTim J. Robbins struct l_rusage {
142ea0fabbcSTim J. Robbins 	l_timeval ru_utime;
143ea0fabbcSTim J. Robbins 	l_timeval ru_stime;
144ea0fabbcSTim J. Robbins 	l_long	ru_maxrss;
145ea0fabbcSTim J. Robbins 	l_long	ru_ixrss;
146ea0fabbcSTim J. Robbins 	l_long	ru_idrss;
147ea0fabbcSTim J. Robbins 	l_long	ru_isrss;
148ea0fabbcSTim J. Robbins 	l_long	ru_minflt;
149ea0fabbcSTim J. Robbins 	l_long	ru_majflt;
150ea0fabbcSTim J. Robbins 	l_long	ru_nswap;
151ea0fabbcSTim J. Robbins 	l_long	ru_inblock;
152ea0fabbcSTim J. Robbins 	l_long	ru_oublock;
153ea0fabbcSTim J. Robbins 	l_long	ru_msgsnd;
154ea0fabbcSTim J. Robbins 	l_long	ru_msgrcv;
155ea0fabbcSTim J. Robbins 	l_long	ru_nsignals;
156ea0fabbcSTim J. Robbins 	l_long	ru_nvcsw;
157ea0fabbcSTim J. Robbins 	l_long	ru_nivcsw;
15819593f77SDmitry Chagin };
159ea0fabbcSTim J. Robbins 
16010931a46SJung-uk Kim struct l_mmap_argv {
16110931a46SJung-uk Kim 	l_uintptr_t	addr;
16210931a46SJung-uk Kim 	l_size_t	len;
16310931a46SJung-uk Kim 	l_int		prot;
16410931a46SJung-uk Kim 	l_int		flags;
16510931a46SJung-uk Kim 	l_int		fd;
1660af71035SDoug Ambrisko 	l_ulong		pgoff;
1670af71035SDoug Ambrisko };
16810931a46SJung-uk Kim 
169ea0fabbcSTim J. Robbins /*
170ea0fabbcSTim J. Robbins  * stat family of syscalls
171ea0fabbcSTim J. Robbins  */
172ea0fabbcSTim J. Robbins struct l_timespec {
17377424f41SJung-uk Kim 	l_time_t	tv_sec;
17477424f41SJung-uk Kim 	l_long		tv_nsec;
17519593f77SDmitry Chagin };
176ea0fabbcSTim J. Robbins 
177bfcce1a9SDmitry Chagin /* __kernel_timespec */
178bfcce1a9SDmitry Chagin struct l_timespec64 {
179bfcce1a9SDmitry Chagin 	l_time64_t	tv_sec;
180bfcce1a9SDmitry Chagin 	l_longlong	tv_nsec;
181bfcce1a9SDmitry Chagin };
182bfcce1a9SDmitry Chagin 
183ea0fabbcSTim J. Robbins struct l_newstat {
184e0bfe0d6SDmitry Chagin 	l_ulong		st_dev;
185ea0fabbcSTim J. Robbins 	l_ulong		st_ino;
186ea0fabbcSTim J. Robbins 	l_ushort	st_mode;
187ea0fabbcSTim J. Robbins 	l_ushort	st_nlink;
188ea0fabbcSTim J. Robbins 	l_ushort	st_uid;
189ea0fabbcSTim J. Robbins 	l_ushort	st_gid;
190e0bfe0d6SDmitry Chagin 	l_ulong		st_rdev;
191ea0fabbcSTim J. Robbins 	l_ulong		st_size;
192ea0fabbcSTim J. Robbins 	l_ulong		st_blksize;
193ea0fabbcSTim J. Robbins 	l_ulong		st_blocks;
194510ea843SEd Schouten 	struct l_timespec	st_atim;
195510ea843SEd Schouten 	struct l_timespec	st_mtim;
196510ea843SEd Schouten 	struct l_timespec	st_ctim;
197ea0fabbcSTim J. Robbins 	l_ulong		__unused4;
198ea0fabbcSTim J. Robbins 	l_ulong		__unused5;
19919593f77SDmitry Chagin };
200ea0fabbcSTim J. Robbins 
201a408fc09SDmitry Chagin /* __old_kernel_stat now */
202a408fc09SDmitry Chagin struct l_old_stat {
2031f7642e0SAlexander Leidinger 	l_ushort	st_dev;
2041f7642e0SAlexander Leidinger 	l_ulong		st_ino;
2051f7642e0SAlexander Leidinger 	l_ushort	st_mode;
2061f7642e0SAlexander Leidinger 	l_ushort	st_nlink;
2071f7642e0SAlexander Leidinger 	l_ushort	st_uid;
2081f7642e0SAlexander Leidinger 	l_ushort	st_gid;
2091f7642e0SAlexander Leidinger 	l_ushort	st_rdev;
2101f7642e0SAlexander Leidinger 	l_long		st_size;
211510ea843SEd Schouten 	struct l_timespec	st_atim;
212510ea843SEd Schouten 	struct l_timespec	st_mtim;
213510ea843SEd Schouten 	struct l_timespec	st_ctim;
2141f7642e0SAlexander Leidinger 	l_long		st_blksize;
2151f7642e0SAlexander Leidinger 	l_long		st_blocks;
2161f7642e0SAlexander Leidinger 	l_ulong		st_flags;
2171f7642e0SAlexander Leidinger 	l_ulong		st_gen;
2181f7642e0SAlexander Leidinger };
2191f7642e0SAlexander Leidinger 
220ea0fabbcSTim J. Robbins struct l_stat64 {
22180d8a4a0SDmitry Chagin 	l_ulonglong	st_dev;
22280d8a4a0SDmitry Chagin 	u_char		__pad0[4];
223ea0fabbcSTim J. Robbins 	l_ulong		__st_ino;
224ea0fabbcSTim J. Robbins 	l_uint		st_mode;
225ea0fabbcSTim J. Robbins 	l_uint		st_nlink;
226ea0fabbcSTim J. Robbins 	l_ulong		st_uid;
227ea0fabbcSTim J. Robbins 	l_ulong		st_gid;
22880d8a4a0SDmitry Chagin 	l_ulonglong	st_rdev;
22980d8a4a0SDmitry Chagin 	u_char		__pad3[4];
230ea0fabbcSTim J. Robbins 	l_longlong	st_size;
231ea0fabbcSTim J. Robbins 	l_ulong		st_blksize;
23280d8a4a0SDmitry Chagin 	l_ulonglong	st_blocks;
233510ea843SEd Schouten 	struct l_timespec	st_atim;
234510ea843SEd Schouten 	struct l_timespec	st_mtim;
235510ea843SEd Schouten 	struct l_timespec	st_ctim;
236ea0fabbcSTim J. Robbins 	l_ulonglong	st_ino;
237ea0fabbcSTim J. Robbins } __packed;
238ea0fabbcSTim J. Robbins 
2393ab85269SDavid Malone struct l_statfs64 {
2403ab85269SDavid Malone 	l_int		f_type;
2413ab85269SDavid Malone 	l_int		f_bsize;
2423ab85269SDavid Malone 	uint64_t	f_blocks;
2433ab85269SDavid Malone 	uint64_t	f_bfree;
2443ab85269SDavid Malone 	uint64_t	f_bavail;
2453ab85269SDavid Malone 	uint64_t	f_files;
2463ab85269SDavid Malone 	uint64_t	f_ffree;
2473ab85269SDavid Malone 	l_fsid_t	f_fsid;
2483ab85269SDavid Malone 	l_int		f_namelen;
249e801ac78SEdward Tomasz Napierala 	l_int		f_frsize;
250e801ac78SEdward Tomasz Napierala 	l_int		f_flags;
251e801ac78SEdward Tomasz Napierala 	l_int		f_spare[4];
2523ab85269SDavid Malone } __packed;
2533ab85269SDavid Malone 
254ea0fabbcSTim J. Robbins /* sigaction flags */
255ea0fabbcSTim J. Robbins #define	LINUX_SA_NOCLDSTOP	0x00000001
256ea0fabbcSTim J. Robbins #define	LINUX_SA_NOCLDWAIT	0x00000002
257ea0fabbcSTim J. Robbins #define	LINUX_SA_SIGINFO	0x00000004
258ea0fabbcSTim J. Robbins #define	LINUX_SA_RESTORER	0x04000000
259ea0fabbcSTim J. Robbins #define	LINUX_SA_ONSTACK	0x08000000
260ea0fabbcSTim J. Robbins #define	LINUX_SA_RESTART	0x10000000
261ea0fabbcSTim J. Robbins #define	LINUX_SA_INTERRUPT	0x20000000
262ea0fabbcSTim J. Robbins #define	LINUX_SA_NOMASK		0x40000000
263ea0fabbcSTim J. Robbins #define	LINUX_SA_ONESHOT	0x80000000
264ea0fabbcSTim J. Robbins 
265ea0fabbcSTim J. Robbins /* sigaltstack */
266ea0fabbcSTim J. Robbins #define	LINUX_MINSIGSTKSZ	2048
267ea0fabbcSTim J. Robbins 
268ea0fabbcSTim J. Robbins typedef l_uintptr_t l_handler_t;
269ea0fabbcSTim J. Robbins typedef l_ulong	l_osigset_t;
270ea0fabbcSTim J. Robbins 
271ea0fabbcSTim J. Robbins typedef struct {
272ea0fabbcSTim J. Robbins 	l_handler_t	lsa_handler;
273ea0fabbcSTim J. Robbins 	l_osigset_t	lsa_mask;
274ea0fabbcSTim J. Robbins 	l_ulong		lsa_flags;
275ea0fabbcSTim J. Robbins 	l_uintptr_t	lsa_restorer;
27619593f77SDmitry Chagin } l_osigaction_t;
277ea0fabbcSTim J. Robbins 
278ea0fabbcSTim J. Robbins typedef struct {
279ea0fabbcSTim J. Robbins 	l_handler_t	lsa_handler;
280ea0fabbcSTim J. Robbins 	l_ulong		lsa_flags;
281ea0fabbcSTim J. Robbins 	l_uintptr_t	lsa_restorer;
282ea0fabbcSTim J. Robbins 	l_sigset_t	lsa_mask;
283ea0fabbcSTim J. Robbins } __packed l_sigaction_t;
284ea0fabbcSTim J. Robbins 
285ea0fabbcSTim J. Robbins typedef struct {
286ea0fabbcSTim J. Robbins 	l_uintptr_t	ss_sp;
287ea0fabbcSTim J. Robbins 	l_int		ss_flags;
288ea0fabbcSTim J. Robbins 	l_size_t	ss_size;
28919593f77SDmitry Chagin } l_stack_t;
290ea0fabbcSTim J. Robbins 
291ea0fabbcSTim J. Robbins /*
2924d0f380dSDmitry Chagin  * arch specific open/fcntl flags
293ea0fabbcSTim J. Robbins  */
294ea0fabbcSTim J. Robbins #define	LINUX_F_GETLK64		12
295ea0fabbcSTim J. Robbins #define	LINUX_F_SETLK64		13
296ea0fabbcSTim J. Robbins #define	LINUX_F_SETLKW64	14
297ea0fabbcSTim J. Robbins 
298ea0fabbcSTim J. Robbins union l_semun {
299ea0fabbcSTim J. Robbins 	l_int		val;
300ea0fabbcSTim J. Robbins 	l_uintptr_t	buf;
301ea0fabbcSTim J. Robbins 	l_uintptr_t	array;
302ea0fabbcSTim J. Robbins 	l_uintptr_t	__buf;
303ea0fabbcSTim J. Robbins 	l_uintptr_t	__pad;
30419593f77SDmitry Chagin };
305ea0fabbcSTim J. Robbins 
306ea0fabbcSTim J. Robbins struct l_ifconf {
307ea0fabbcSTim J. Robbins 	int	ifc_len;
308ea0fabbcSTim J. Robbins 	union {
309ea0fabbcSTim J. Robbins 		l_uintptr_t	ifcu_buf;
310ea0fabbcSTim J. Robbins 		l_uintptr_t	ifcu_req;
311ea0fabbcSTim J. Robbins 	} ifc_ifcu;
31219593f77SDmitry Chagin };
313ea0fabbcSTim J. Robbins 
314ea0fabbcSTim J. Robbins #define	ifc_buf		ifc_ifcu.ifcu_buf
315ea0fabbcSTim J. Robbins #define	ifc_req		ifc_ifcu.ifcu_req
316ea0fabbcSTim J. Robbins 
3179b44bfc5SAlexander Leidinger struct l_user_desc {
3189b44bfc5SAlexander Leidinger 	l_uint		entry_number;
3199b44bfc5SAlexander Leidinger 	l_uint		base_addr;
3209b44bfc5SAlexander Leidinger 	l_uint		limit;
3219b44bfc5SAlexander Leidinger 	l_uint		seg_32bit:1;
3229b44bfc5SAlexander Leidinger 	l_uint		contents:2;
3239b44bfc5SAlexander Leidinger 	l_uint		read_exec_only:1;
3249b44bfc5SAlexander Leidinger 	l_uint		limit_in_pages:1;
3259b44bfc5SAlexander Leidinger 	l_uint		seg_not_present:1;
3269b44bfc5SAlexander Leidinger 	l_uint		useable:1;
3279b44bfc5SAlexander Leidinger };
3289b44bfc5SAlexander Leidinger 
3299b44bfc5SAlexander Leidinger #define	LINUX_LOWERWORD	0x0000ffff
3309b44bfc5SAlexander Leidinger 
3310eef2f8aSAlexander Leidinger /*
332a4e3bad7SJung-uk Kim  * Macros which does the same thing as those in Linux include/asm-um/ldt-i386.h.
333a4e3bad7SJung-uk Kim  * These convert Linux user space descriptor to machine one.
3349b44bfc5SAlexander Leidinger  */
335a4e3bad7SJung-uk Kim #define	LINUX_LDT_entry_a(info)					\
336a4e3bad7SJung-uk Kim 	((((info)->base_addr & LINUX_LOWERWORD) << 16) |	\
337a4e3bad7SJung-uk Kim 	((info)->limit & LINUX_LOWERWORD))
3389b44bfc5SAlexander Leidinger 
339a4e3bad7SJung-uk Kim #define	LINUX_ENTRY_B_READ_EXEC_ONLY	9
340a4e3bad7SJung-uk Kim #define	LINUX_ENTRY_B_CONTENTS		10
341a4e3bad7SJung-uk Kim #define	LINUX_ENTRY_B_SEG_NOT_PRESENT	15
342a4e3bad7SJung-uk Kim #define	LINUX_ENTRY_B_BASE_ADDR		16
343a4e3bad7SJung-uk Kim #define	LINUX_ENTRY_B_USEABLE		20
344a4e3bad7SJung-uk Kim #define	LINUX_ENTRY_B_SEG32BIT		22
345a4e3bad7SJung-uk Kim #define	LINUX_ENTRY_B_LIMIT		23
3469b44bfc5SAlexander Leidinger 
347a4e3bad7SJung-uk Kim #define	LINUX_LDT_entry_b(info)							\
3489b44bfc5SAlexander Leidinger 	(((info)->base_addr & 0xff000000) |					\
3499b44bfc5SAlexander Leidinger 	((info)->limit & 0xf0000) |						\
350a4e3bad7SJung-uk Kim 	((info)->contents << LINUX_ENTRY_B_CONTENTS) |				\
351a4e3bad7SJung-uk Kim 	(((info)->seg_not_present == 0) << LINUX_ENTRY_B_SEG_NOT_PRESENT) |	\
352a4e3bad7SJung-uk Kim 	(((info)->base_addr & 0x00ff0000) >> LINUX_ENTRY_B_BASE_ADDR) |		\
353a4e3bad7SJung-uk Kim 	(((info)->read_exec_only == 0) << LINUX_ENTRY_B_READ_EXEC_ONLY) |	\
354a4e3bad7SJung-uk Kim 	((info)->seg_32bit << LINUX_ENTRY_B_SEG32BIT) |				\
355a4e3bad7SJung-uk Kim 	((info)->useable << LINUX_ENTRY_B_USEABLE) |				\
356a4e3bad7SJung-uk Kim 	((info)->limit_in_pages << LINUX_ENTRY_B_LIMIT) | 0x7000)
3579b44bfc5SAlexander Leidinger 
358a4e3bad7SJung-uk Kim #define	LINUX_LDT_empty(info)		\
359a4e3bad7SJung-uk Kim 	((info)->base_addr == 0 &&	\
3609b44bfc5SAlexander Leidinger 	(info)->limit == 0 &&		\
3619b44bfc5SAlexander Leidinger 	(info)->contents == 0 &&	\
3629b44bfc5SAlexander Leidinger 	(info)->seg_not_present == 1 &&	\
3639b44bfc5SAlexander Leidinger 	(info)->read_exec_only == 1 &&	\
3649b44bfc5SAlexander Leidinger 	(info)->seg_32bit == 0 &&	\
3659b44bfc5SAlexander Leidinger 	(info)->limit_in_pages == 0 &&	\
3669b44bfc5SAlexander Leidinger 	(info)->useable == 0)
3679b44bfc5SAlexander Leidinger 
368a4e3bad7SJung-uk Kim /*
369a4e3bad7SJung-uk Kim  * Macros for converting segments.
370a4e3bad7SJung-uk Kim  * They do the same as those in arch/i386/kernel/process.c in Linux.
371a4e3bad7SJung-uk Kim  */
372a4e3bad7SJung-uk Kim #define	LINUX_GET_BASE(desc)				\
373a4e3bad7SJung-uk Kim 	((((desc)->a >> 16) & LINUX_LOWERWORD) |	\
3749b44bfc5SAlexander Leidinger 	(((desc)->b << 16) & 0x00ff0000) |		\
3759b44bfc5SAlexander Leidinger 	((desc)->b & 0xff000000))
3769b44bfc5SAlexander Leidinger 
377a4e3bad7SJung-uk Kim #define	LINUX_GET_LIMIT(desc)			\
378a4e3bad7SJung-uk Kim 	(((desc)->a & LINUX_LOWERWORD) |	\
3799b44bfc5SAlexander Leidinger 	((desc)->b & 0xf0000))
3809b44bfc5SAlexander Leidinger 
381a4e3bad7SJung-uk Kim #define	LINUX_GET_32BIT(desc)		\
382a4e3bad7SJung-uk Kim 	(((desc)->b >> LINUX_ENTRY_B_SEG32BIT) & 1)
383a4e3bad7SJung-uk Kim #define	LINUX_GET_CONTENTS(desc)	\
384a4e3bad7SJung-uk Kim 	(((desc)->b >> LINUX_ENTRY_B_CONTENTS) & 3)
385a4e3bad7SJung-uk Kim #define	LINUX_GET_WRITABLE(desc)	\
386a4e3bad7SJung-uk Kim 	(((desc)->b >> LINUX_ENTRY_B_READ_EXEC_ONLY) & 1)
387a4e3bad7SJung-uk Kim #define	LINUX_GET_LIMIT_PAGES(desc)	\
388a4e3bad7SJung-uk Kim 	(((desc)->b >> LINUX_ENTRY_B_LIMIT) & 1)
389a4e3bad7SJung-uk Kim #define	LINUX_GET_PRESENT(desc)		\
390a4e3bad7SJung-uk Kim 	(((desc)->b >> LINUX_ENTRY_B_SEG_NOT_PRESENT) & 1)
391a4e3bad7SJung-uk Kim #define	LINUX_GET_USEABLE(desc)		\
392a4e3bad7SJung-uk Kim 	(((desc)->b >> LINUX_ENTRY_B_USEABLE) & 1)
3939b44bfc5SAlexander Leidinger 
394d416ee86SDmitry Chagin #ifdef _KERNEL
395001398c4SDmitry Chagin int linux_copyout_rusage(struct rusage *ru, void *uaddr);
396d416ee86SDmitry Chagin #endif /* _KERNEL */
39741f53a36SKonstantin Belousov 
39895c19e1dSEdward Tomasz Napierala /* This corresponds to 'struct user_regs_struct32' in Linux. */
39995c19e1dSEdward Tomasz Napierala struct linux_pt_regset32 {
40095c19e1dSEdward Tomasz Napierala 	l_uint ebx;
40195c19e1dSEdward Tomasz Napierala 	l_uint ecx;
40295c19e1dSEdward Tomasz Napierala 	l_uint edx;
40395c19e1dSEdward Tomasz Napierala 	l_uint esi;
40495c19e1dSEdward Tomasz Napierala 	l_uint edi;
40595c19e1dSEdward Tomasz Napierala 	l_uint ebp;
40695c19e1dSEdward Tomasz Napierala 	l_uint eax;
40795c19e1dSEdward Tomasz Napierala 	l_uint ds;
40895c19e1dSEdward Tomasz Napierala 	l_uint es;
40995c19e1dSEdward Tomasz Napierala 	l_uint fs;
41095c19e1dSEdward Tomasz Napierala 	l_uint gs;
41195c19e1dSEdward Tomasz Napierala 	l_uint orig_eax;
41295c19e1dSEdward Tomasz Napierala 	l_uint eip;
41395c19e1dSEdward Tomasz Napierala 	l_uint cs;
41495c19e1dSEdward Tomasz Napierala 	l_uint eflags;
41595c19e1dSEdward Tomasz Napierala 	l_uint esp;
41695c19e1dSEdward Tomasz Napierala 	l_uint ss;
41795c19e1dSEdward Tomasz Napierala };
41895c19e1dSEdward Tomasz Napierala 
419d416ee86SDmitry Chagin #ifdef _KERNEL
42095c19e1dSEdward Tomasz Napierala struct reg32;
42195c19e1dSEdward Tomasz Napierala 
4223417c298SEdward Tomasz Napierala void	bsd_to_linux_regset32(const struct reg32 *b_reg,
42395c19e1dSEdward Tomasz Napierala 	    struct linux_pt_regset32 *l_regset);
424dd2a6cd7SDmitry Chagin int	linux_ptrace_peekuser(struct thread *td, pid_t pid,
425dd2a6cd7SDmitry Chagin 	    void *addr, void *data);
4263d0addcdSDmitry Chagin int	linux_ptrace_pokeuser(struct thread *td, pid_t pid,
4273d0addcdSDmitry Chagin 	    void *addr, void *data);
42895c19e1dSEdward Tomasz Napierala 
429d5dc757eSDmitry Chagin extern bool linux32_emulate_i386;
430d416ee86SDmitry Chagin #endif /* _KERNEL */
431d5dc757eSDmitry Chagin 
432a4e3bad7SJung-uk Kim #endif /* !_AMD64_LINUX_H_ */
433