xref: /netbsd-src/sys/compat/linux/common/linux_misc.h (revision eab380320695b8901777f834601151f48dd29933)
1 /*	$NetBSD: linux_misc.h,v 1.34 2024/10/01 16:41:29 riastradh Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Eric Haszlakiewicz.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _LINUX_MISC_H
33 #define _LINUX_MISC_H
34 
35 /*
36  * Options passed to the Linux wait4() and waitid() system calls.
37  */
38 #define LINUX_WNOHANG		0x00000001
39 #define LINUX_WUNTRACED		0x00000002
40 #define LINUX_WEXITED		0x00000004
41 #define LINUX_WCONTINUED	0x00000008
42 #define LINUX_WNOWAIT		0x01000000
43 #define LINUX_WNOTHREAD		0x20000000
44 #define LINUX_WALL		0x40000000
45 #define LINUX_WCLONE		0x80000000
46 
47 #define LINUX_WAIT4_KNOWNFLAGS (LINUX_WNOHANG | \
48                                 LINUX_WUNTRACED | \
49                                 LINUX_WCONTINUED | \
50                                 LINUX_WNOTHREAD | \
51                                 LINUX_WALL | \
52                                 LINUX_WCLONE)
53 
54 #define LINUX_WAITID_KNOWNFLAGS (LINUX_WNOHANG | \
55 				 LINUX_WEXITED | \
56 				 LINUX_WUNTRACED | \
57 				 LINUX_WCONTINUED | \
58 				 LINUX_WNOWAIT)
59 
60 /*
61  * Passed as the first argument of waitid(2).
62  */
63 #define LINUX_P_ALL	0
64 #define LINUX_P_PID	1
65 #define LINUX_P_PGID	2
66 #define LINUX_P_PIDFD	3
67 
68 /* This looks very unportable to me, but this is how Linux defines it. */
69 struct linux_sysinfo {
70 	long uptime;
71 	unsigned long loads[3];
72 #define LINUX_SYSINFO_LOADS_SCALE 65536
73 	unsigned long totalram;
74 	unsigned long freeram;
75 	unsigned long sharedram;
76 	unsigned long bufferram;
77 	unsigned long totalswap;
78 	unsigned long freeswap;
79 	unsigned short procs;
80 	unsigned long totalbig;
81 	unsigned long freebig;
82 	unsigned int mem_unit;
83 	char _f[20-2*sizeof(long)-sizeof(int)];
84 };
85 
86 #define	LINUX_RLIMIT_CPU	0
87 #define	LINUX_RLIMIT_FSIZE	1
88 #define	LINUX_RLIMIT_DATA	2
89 #define	LINUX_RLIMIT_STACK	3
90 #define	LINUX_RLIMIT_CORE	4
91 #define	LINUX_RLIMIT_RSS	5
92 #define	LINUX_RLIMIT_NPROC	6
93 #define	LINUX_RLIMIT_NOFILE	7
94 #define	LINUX_RLIMIT_MEMLOCK	8
95 #define	LINUX_RLIMIT_AS		9
96 #define	LINUX_RLIMIT_LOCKS	10
97 #define	LINUX_RLIMIT_SIGPENDING	11
98 #define	LINUX_RLIMIT_MSGQUEUE	12
99 #define	LINUX_RLIMIT_NICE	13
100 #define	LINUX_RLIMIT_RTPRIO	14
101 #define	LINUX_RLIMIT_RTTIME	15
102 #ifdef __mips__  /* XXX only mips32. On mips64, it's ~0ul */
103 #define	LINUX_RLIM_INFINITY	0x7fffffffUL
104 #define	LINUX32_RLIM_INFINITY	0x7fffffffU
105 #else
106 #define	LINUX_RLIM_INFINITY	~0ul
107 #define	LINUX32_RLIM_INFINITY	~0u
108 #endif
109 
110 
111 /* When we don't know what to do, let it believe it is local */
112 #define	LINUX_DEFAULT_SUPER_MAGIC	LINUX_EXT2_SUPER_MAGIC
113 
114 #define	LINUX_ADFS_SUPER_MAGIC		0x0000adf5
115 #define	LINUX_AFFS_SUPER_MAGIC		0x0000adff
116 #define	LINUX_CODA_SUPER_MAGIC		0x73757245
117 #define	LINUX_COH_SUPER_MAGIC		(LINUX_SYSV_MAGIC_BASE + 4)
118 #define	LINUX_DEVFS_SUPER_MAGIC		0x00001373
119 #define	LINUX_EFS_SUPER_MAGIC		0x00414A53
120 #define	LINUX_EXT2_SUPER_MAGIC		0x0000EF53
121 #define	LINUX_HPFS_SUPER_MAGIC		0xf995e849
122 #define	LINUX_ISOFS_SUPER_MAGIC		0x00009660
123 #define	LINUX_MINIX2_SUPER_MAGIC	0x00002468
124 #define	LINUX_MINIX2_SUPER_MAGIC2	0x00002478
125 #define	LINUX_MINIX_SUPER_MAGIC		0x0000137F
126 #define	LINUX_MINIX_SUPER_MAGIC2	0x0000138F
127 #define	LINUX_MSDOS_SUPER_MAGIC		0x00004d44
128 #define	LINUX_NCP_SUPER_MAGIC		0x0000564c
129 #define	LINUX_NFS_SUPER_MAGIC		0x00006969
130 #define	LINUX_OPENPROM_SUPER_MAGIC	0x00009fa1
131 #define	LINUX_PROC_SUPER_MAGIC		0x00009fa0
132 #define	LINUX_QNX4_SUPER_MAGIC		0x0000002f
133 #define	LINUX_REISERFS_SUPER_MAGIC	0x52654973
134 #define	LINUX_SMB_SUPER_MAGIC		0x0000517B
135 #define	LINUX_SYSV2_SUPER_MAGIC		(LINUX_SYSV_MAGIC_BASE + 3)
136 #define	LINUX_SYSV4_SUPER_MAGIC		(LINUX_SYSV_MAGIC_BASE + 2)
137 #define	LINUX_SYSV_MAGIC_BASE		0x012FF7B3
138 #define	LINUX_TMPFS_SUPER_MAGIC		0x01021994
139 #define	LINUX_USBDEVICE_SUPER_MAGIC	0x00009fa2
140 #define	LINUX_DEVPTS_SUPER_MAGIC	0x00001cd1
141 #define	LINUX_XENIX_SUPER_MAGIC		(LINUX_SYSV_MAGIC_BASE + 1)
142 
143 struct linux_mnttypes {
144 	const char *mty_bsd;
145 	int mty_linux;
146 };
147 extern const struct linux_mnttypes linux_fstypes[];
148 extern const int linux_fstypes_cnt;
149 
150 /* Personality types. */
151 #define LINUX_PER_QUERY		0xffffffff
152 #define LINUX_PER_LINUX		0x00
153 #define LINUX_PER_LINUX32	0x08
154 #define LINUX_PER_MASK		0xff
155 
156 /* Personality flags. */
157 #define LINUX_PER_ADDR_NO_RANDOMIZE	0x00040000
158 
159 /*
160  * Convert POSIX_FADV_* constants from Linux to NetBSD
161  * (it's f(x)=x everywhere except S390)
162  */
163 #define linux_to_bsd_posix_fadv(advice) (advice)
164 
165 struct linux_getcpu_cache{
166 	unsigned long blob[128 / sizeof(long)];
167 };
168 
169 struct linux_epoll_event {
170 	uint32_t	events;
171 	uint64_t	data;
172 }
173 
174 #if defined(__amd64__)
175 /* Only for x86_64. See include/uapi/linux/eventpoll.h. */
176 __packed
177 #endif
178 ;
179 
180 #ifdef _KERNEL
181 __BEGIN_DECLS
182 struct linux_timeval;
183 int bsd_to_linux_wstat(int);
184 int linux_select1(struct lwp *, register_t *, int, fd_set *, fd_set *,
185 		       fd_set *, struct linux_timeval *);
186 int linux_do_sys_utimensat(struct lwp *, int, const char *,
187     struct timespec *, int, register_t *);
188 int linux_do_futex(int *, int, int, struct timespec *, int *, int, int,
189     register_t *);
190 __END_DECLS
191 #endif /* !_KERNEL */
192 
193 #endif /* !_LINUX_MISC_H */
194