xref: /netbsd-src/sys/compat/linux/common/linux_misc.h (revision e5014a45d857e6639905eec7f40943a207fed007)
1 /*	$NetBSD: linux_misc.h,v 1.29 2023/08/18 19:41:19 christos 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 #ifdef __mips__  /* XXX only mips32. On mips64, it's ~0ul */
98 #define	LINUX_RLIM_INFINITY	0x7fffffffUL
99 #define	LINUX32_RLIM_INFINITY	0x7fffffffU
100 #else
101 #define	LINUX_RLIM_INFINITY	~0ul
102 #define	LINUX32_RLIM_INFINITY	~0u
103 #endif
104 
105 
106 /* When we don't know what to do, let it believe it is local */
107 #define	LINUX_DEFAULT_SUPER_MAGIC	LINUX_EXT2_SUPER_MAGIC
108 
109 #define	LINUX_ADFS_SUPER_MAGIC		0x0000adf5
110 #define	LINUX_AFFS_SUPER_MAGIC		0x0000adff
111 #define	LINUX_CODA_SUPER_MAGIC		0x73757245
112 #define	LINUX_COH_SUPER_MAGIC		(LINUX_SYSV_MAGIC_BASE + 4)
113 #define	LINUX_DEVFS_SUPER_MAGIC		0x00001373
114 #define	LINUX_EFS_SUPER_MAGIC		0x00414A53
115 #define	LINUX_EXT2_SUPER_MAGIC		0x0000EF53
116 #define	LINUX_HPFS_SUPER_MAGIC		0xf995e849
117 #define	LINUX_ISOFS_SUPER_MAGIC		0x00009660
118 #define	LINUX_MINIX2_SUPER_MAGIC	0x00002468
119 #define	LINUX_MINIX2_SUPER_MAGIC2	0x00002478
120 #define	LINUX_MINIX_SUPER_MAGIC		0x0000137F
121 #define	LINUX_MINIX_SUPER_MAGIC2	0x0000138F
122 #define	LINUX_MSDOS_SUPER_MAGIC		0x00004d44
123 #define	LINUX_NCP_SUPER_MAGIC		0x0000564c
124 #define	LINUX_NFS_SUPER_MAGIC		0x00006969
125 #define	LINUX_OPENPROM_SUPER_MAGIC	0x00009fa1
126 #define	LINUX_PROC_SUPER_MAGIC		0x00009fa0
127 #define	LINUX_QNX4_SUPER_MAGIC		0x0000002f
128 #define	LINUX_REISERFS_SUPER_MAGIC	0x52654973
129 #define	LINUX_SMB_SUPER_MAGIC		0x0000517B
130 #define	LINUX_SYSV2_SUPER_MAGIC		(LINUX_SYSV_MAGIC_BASE + 3)
131 #define	LINUX_SYSV4_SUPER_MAGIC		(LINUX_SYSV_MAGIC_BASE + 2)
132 #define	LINUX_SYSV_MAGIC_BASE		0x012FF7B3
133 #define	LINUX_TMPFS_SUPER_MAGIC		0x01021994
134 #define	LINUX_USBDEVICE_SUPER_MAGIC	0x00009fa2
135 #define	LINUX_DEVPTS_SUPER_MAGIC	0x00001cd1
136 #define	LINUX_XENIX_SUPER_MAGIC		(LINUX_SYSV_MAGIC_BASE + 1)
137 
138 struct linux_mnttypes {
139 	const char *mty_bsd;
140 	int mty_linux;
141 };
142 extern const struct linux_mnttypes linux_fstypes[];
143 extern const int linux_fstypes_cnt;
144 
145 /* Personality types. */
146 #define LINUX_PER_QUERY		0xffffffff
147 #define LINUX_PER_LINUX		0x00
148 #define LINUX_PER_LINUX32	0x08
149 #define LINUX_PER_MASK		0xff
150 
151 /* Personality flags. */
152 #define LINUX_PER_ADDR_NO_RANDOMIZE	0x00040000
153 
154 /*
155  * Convert POSIX_FADV_* constants from Linux to NetBSD
156  * (it's f(x)=x everywhere except S390)
157  */
158 #define linux_to_bsd_posix_fadv(advice) (advice)
159 
160 struct linux_epoll_event {
161 	uint32_t	events;
162 	uint64_t	data;
163 }
164 #if defined(__amd64__)
165 /* Only for x86_64. See include/uapi/linux/eventpoll.h. */
166 __packed
167 #endif
168 ;
169 
170 #ifdef _KERNEL
171 __BEGIN_DECLS
172 int bsd_to_linux_wstat(int);
173 int linux_select1(struct lwp *, register_t *, int, fd_set *, fd_set *,
174 		       fd_set *, struct linux_timeval *);
175 int linux_do_sys_utimensat(struct lwp *, int, const char *,
176     struct timespec *, int, register_t *);
177 int linux_do_futex(int *, int, int, struct timespec *, int *, int, int,
178     register_t *);
179 __END_DECLS
180 #endif /* !_KERNEL */
181 
182 #endif /* !_LINUX_MISC_H */
183