1 /*- 2 * Copyright (c) 1994-1996 Søren Schmidt 3 * Copyright (c) 2013 Dmitry Chagin 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 /* 29 * $FreeBSD$ 30 */ 31 #ifndef _ARM64_LINUX_H_ 32 #define _ARM64_LINUX_H_ 33 34 #include <compat/linux/linux.h> 35 #include <arm64/linux/linux_syscall.h> 36 37 /* Debugging support */ 38 #define DEBUG 39 extern u_char linux_debug_map[]; 40 #define ldebug(name) isclr(linux_debug_map, LINUX_SYS_linux_ ## name) 41 #define ARGS(nm, fmt) "linux(%ld/%ld): "#nm"("fmt")\n", \ 42 (long)td->td_proc->p_pid, (long)td->td_tid 43 #define LMSG(fmt) "linux(%ld/%ld): "fmt"\n", \ 44 (long)td->td_proc->p_pid, (long)td->td_tid 45 #define LINUX_DTRACE linuxulator 46 47 #define PTRIN(v) (void *)(v) 48 #define PTROUT(v) (uintptr_t)(v) 49 50 #define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0) 51 #define CP2(src,dst,sfld,dfld) do { (dst).dfld = (src).sfld; } while (0) 52 #define PTRIN_CP(src,dst,fld) \ 53 do { (dst).fld = PTRIN((src).fld); } while (0) 54 55 /* Provide a separate set of types for the Linux types */ 56 typedef int32_t l_int; 57 typedef int64_t l_long; 58 typedef int16_t l_short; 59 typedef uint32_t l_uint; 60 typedef uint64_t l_ulong; 61 typedef uint16_t l_ushort; 62 63 typedef l_ulong l_uintptr_t; 64 typedef l_long l_clock_t; 65 typedef l_int l_daddr_t; 66 typedef l_ulong l_dev_t; 67 typedef l_uint l_gid_t; 68 typedef l_ushort l_gid16_t; /* XXX */ 69 typedef l_uint l_uid_t; 70 typedef l_ushort l_uid16_t; /* XXX */ 71 typedef l_ulong l_ino_t; 72 typedef l_int l_key_t; 73 typedef l_long l_loff_t; 74 typedef l_uint l_mode_t; 75 typedef l_long l_off_t; 76 typedef l_int l_pid_t; 77 typedef l_ulong l_size_t; 78 typedef l_long l_suseconds_t; 79 typedef l_long l_time_t; 80 typedef l_int l_timer_t; /* XXX */ 81 typedef l_ulong l_fd_mask; 82 83 typedef struct { 84 l_int val[2]; 85 } l_fsid_t; 86 87 typedef struct { 88 l_time_t tv_sec; 89 l_suseconds_t tv_usec; 90 } l_timeval; 91 92 #define l_fd_set fd_set 93 94 /* Miscellaneous */ 95 #define LINUX_AT_COUNT 20 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_uintptr_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 /* stat family of syscalls */ 128 struct l_timespec { 129 l_time_t tv_sec; 130 l_long tv_nsec; 131 }; 132 133 struct l_newstat { 134 l_dev_t st_dev; 135 l_ino_t st_ino; 136 l_uint st_mode; 137 l_uint st_nlink; 138 139 l_uid_t st_uid; 140 l_gid_t st_gid; 141 142 l_dev_t st_rdev; 143 l_ulong __st_pad1; 144 l_off_t st_size; 145 l_int st_blksize; 146 l_int __st_pad2; 147 l_long st_blocks; 148 149 struct l_timespec st_atim; 150 struct l_timespec st_mtim; 151 struct l_timespec st_ctim; 152 l_uint __unused1; 153 l_uint __unused2; 154 }; 155 156 /* sigaction flags */ 157 #define LINUX_SA_NOCLDSTOP 0x00000001 158 #define LINUX_SA_NOCLDWAIT 0x00000002 159 #define LINUX_SA_SIGINFO 0x00000004 160 #define LINUX_SA_RESTORER 0x04000000 161 #define LINUX_SA_ONSTACK 0x08000000 162 #define LINUX_SA_RESTART 0x10000000 163 #define LINUX_SA_INTERRUPT 0x20000000 /* XXX */ 164 #define LINUX_SA_NOMASK 0x40000000 /* SA_NODEFER */ 165 #define LINUX_SA_ONESHOT 0x80000000 /* SA_RESETHAND */ 166 167 /* sigprocmask actions */ 168 #define LINUX_SIG_BLOCK 0 169 #define LINUX_SIG_UNBLOCK 1 170 #define LINUX_SIG_SETMASK 2 171 172 /* sigaltstack */ 173 #define LINUX_MINSIGSTKSZ 2048 /* XXX */ 174 175 typedef void (*l_handler_t)(l_int); 176 177 typedef struct { 178 l_handler_t lsa_handler; 179 l_sigset_t lsa_mask; 180 l_ulong lsa_flags; 181 l_uintptr_t lsa_restorer; 182 } l_sigaction_t; /* XXX */ 183 184 typedef struct { 185 l_uintptr_t ss_sp; 186 l_int ss_flags; 187 l_size_t ss_size; 188 } l_stack_t; 189 190 #define LINUX_SI_PREAMBLE_SIZE (4 * sizeof(int)) 191 #define LINUX_SI_MAX_SIZE 128 192 #define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE - \ 193 LINUX_SI_PREAMBLE_SIZE) / sizeof(l_int)) 194 typedef union l_sigval { 195 l_int sival_int; 196 l_uintptr_t sival_ptr; 197 } l_sigval_t; 198 199 typedef struct l_siginfo { 200 l_int lsi_signo; 201 l_int lsi_errno; 202 l_int lsi_code; 203 union { 204 l_int _pad[LINUX_SI_PAD_SIZE]; 205 206 struct { 207 l_pid_t _pid; 208 l_uid_t _uid; 209 } _kill; 210 211 struct { 212 l_timer_t _tid; 213 l_int _overrun; 214 char _pad[sizeof(l_uid_t) - sizeof(int)]; 215 union l_sigval _sigval; 216 l_uint _sys_private; 217 } _timer; 218 219 struct { 220 l_pid_t _pid; /* sender's pid */ 221 l_uid_t _uid; /* sender's uid */ 222 union l_sigval _sigval; 223 } _rt; 224 225 struct { 226 l_pid_t _pid; /* which child */ 227 l_uid_t _uid; /* sender's uid */ 228 l_int _status; /* exit code */ 229 l_clock_t _utime; 230 l_clock_t _stime; 231 } _sigchld; 232 233 struct { 234 l_uintptr_t _addr; /* Faulting insn/memory ref. */ 235 } _sigfault; 236 237 struct { 238 l_long _band; /* POLL_IN,POLL_OUT,POLL_MSG */ 239 l_int _fd; 240 } _sigpoll; 241 } _sifields; 242 } l_siginfo_t; 243 244 #define lsi_pid _sifields._kill._pid 245 #define lsi_uid _sifields._kill._uid 246 #define lsi_tid _sifields._timer._tid 247 #define lsi_overrun _sifields._timer._overrun 248 #define lsi_sys_private _sifields._timer._sys_private 249 #define lsi_status _sifields._sigchld._status 250 #define lsi_utime _sifields._sigchld._utime 251 #define lsi_stime _sifields._sigchld._stime 252 #define lsi_value _sifields._rt._sigval 253 #define lsi_int _sifields._rt._sigval.sival_int 254 #define lsi_ptr _sifields._rt._sigval.sival_ptr 255 #define lsi_addr _sifields._sigfault._addr 256 #define lsi_band _sifields._sigpoll._band 257 #define lsi_fd _sifields._sigpoll._fd 258 259 union l_semun { 260 l_int val; 261 l_uintptr_t buf; 262 l_uintptr_t array; 263 l_uintptr_t __buf; 264 l_uintptr_t __pad; 265 }; 266 267 struct l_sockaddr { 268 l_ushort sa_family; 269 char sa_data[14]; 270 }; 271 272 struct l_ifmap { 273 l_ulong mem_start; 274 l_ulong mem_end; 275 l_ushort base_addr; 276 u_char irq; 277 u_char dma; 278 u_char port; 279 } __packed; 280 281 #define LINUX_IFHWADDRLEN 6 282 #define LINUX_IFNAMSIZ 16 283 284 struct l_ifreq { 285 union { 286 char ifrn_name[LINUX_IFNAMSIZ]; 287 } ifr_ifrn; 288 289 union { 290 struct l_sockaddr ifru_addr; 291 struct l_sockaddr ifru_dstaddr; 292 struct l_sockaddr ifru_broadaddr; 293 struct l_sockaddr ifru_netmask; 294 struct l_sockaddr ifru_hwaddr; 295 l_short ifru_flags[1]; 296 l_int ifru_ivalue; 297 l_int ifru_mtu; 298 struct l_ifmap ifru_map; 299 char ifru_slave[LINUX_IFNAMSIZ]; 300 l_uintptr_t ifru_data; 301 } ifr_ifru; 302 } __packed; 303 304 #define ifr_name ifr_ifrn.ifrn_name /* Interface name */ 305 #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ 306 #define ifr_ifindex ifr_ifru.ifru_ivalue /* Interface index */ 307 308 #define linux_copyout_rusage(r, u) copyout(r, u, sizeof(*r)) 309 310 /* robust futexes */ 311 struct linux_robust_list { 312 l_uintptr_t next; 313 }; 314 315 struct linux_robust_list_head { 316 struct linux_robust_list list; 317 l_long futex_offset; 318 l_uintptr_t pending_list; 319 }; 320 321 #endif /* _ARM64_LINUX_H_ */ 322