1 /*- 2 * Copyright (c) 1994-1996 Søren Schmidt 3 * Copyright (c) 2013 Dmitry Chagin <dchagin@FreeBSD.org> 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 <sys/abi_compat.h> 35 36 #include <compat/linux/linux.h> 37 #include <arm64/linux/linux_syscall.h> 38 39 #define LINUX_DTRACE linuxulator 40 41 /* Provide a separate set of types for the Linux types */ 42 typedef int32_t l_int; 43 typedef int64_t l_long; 44 typedef int16_t l_short; 45 typedef uint32_t l_uint; 46 typedef uint64_t l_ulong; 47 typedef uint16_t l_ushort; 48 49 typedef l_ulong l_uintptr_t; 50 typedef l_long l_clock_t; 51 typedef l_int l_daddr_t; 52 typedef l_ulong l_dev_t; 53 typedef l_uint l_gid_t; 54 typedef l_ushort l_gid16_t; /* XXX */ 55 typedef l_uint l_uid_t; 56 typedef l_ushort l_uid16_t; /* XXX */ 57 typedef l_ulong l_ino_t; 58 typedef l_int l_key_t; 59 typedef l_long l_loff_t; 60 typedef l_uint l_mode_t; 61 typedef l_long l_off_t; 62 typedef l_int l_pid_t; 63 typedef l_ulong l_size_t; 64 typedef l_long l_suseconds_t; 65 typedef l_long l_time_t; 66 typedef l_int l_timer_t; /* XXX */ 67 typedef l_int l_mqd_t; 68 typedef l_ulong l_fd_mask; 69 70 typedef struct { 71 l_int val[2]; 72 } l_fsid_t; 73 74 typedef struct { 75 l_time_t tv_sec; 76 l_suseconds_t tv_usec; 77 } l_timeval; 78 79 #define l_fd_set fd_set 80 81 /* Miscellaneous */ 82 #define LINUX_AT_COUNT 20 83 84 struct l___sysctl_args 85 { 86 l_uintptr_t name; 87 l_int nlen; 88 l_uintptr_t oldval; 89 l_uintptr_t oldlenp; 90 l_uintptr_t newval; 91 l_uintptr_t newlen; 92 l_ulong __spare[4]; 93 }; 94 95 /* Resource limits */ 96 #define LINUX_RLIMIT_CPU 0 97 #define LINUX_RLIMIT_FSIZE 1 98 #define LINUX_RLIMIT_DATA 2 99 #define LINUX_RLIMIT_STACK 3 100 #define LINUX_RLIMIT_CORE 4 101 #define LINUX_RLIMIT_RSS 5 102 #define LINUX_RLIMIT_NPROC 6 103 #define LINUX_RLIMIT_NOFILE 7 104 #define LINUX_RLIMIT_MEMLOCK 8 105 #define LINUX_RLIMIT_AS 9 /* Address space limit */ 106 107 #define LINUX_RLIM_NLIMITS 10 108 109 struct l_rlimit { 110 l_ulong rlim_cur; 111 l_ulong rlim_max; 112 }; 113 114 /* stat family of syscalls */ 115 struct l_timespec { 116 l_time_t tv_sec; 117 l_long tv_nsec; 118 }; 119 120 #define LINUX_O_DIRECTORY 000040000 /* Must be a directory */ 121 #define LINUX_O_NOFOLLOW 000100000 /* Do not follow links */ 122 #define LINUX_O_DIRECT 000200000 /* Direct disk access hint */ 123 #define LINUX_O_LARGEFILE 000400000 124 125 struct l_newstat { 126 l_dev_t st_dev; 127 l_ino_t st_ino; 128 l_uint st_mode; 129 l_uint st_nlink; 130 131 l_uid_t st_uid; 132 l_gid_t st_gid; 133 134 l_dev_t st_rdev; 135 l_ulong __st_pad1; 136 l_off_t st_size; 137 l_int st_blksize; 138 l_int __st_pad2; 139 l_long st_blocks; 140 141 struct l_timespec st_atim; 142 struct l_timespec st_mtim; 143 struct l_timespec st_ctim; 144 l_uint __unused1; 145 l_uint __unused2; 146 }; 147 148 /* sigaction flags */ 149 #define LINUX_SA_NOCLDSTOP 0x00000001 150 #define LINUX_SA_NOCLDWAIT 0x00000002 151 #define LINUX_SA_SIGINFO 0x00000004 152 #define LINUX_SA_RESTORER 0x04000000 153 #define LINUX_SA_ONSTACK 0x08000000 154 #define LINUX_SA_RESTART 0x10000000 155 #define LINUX_SA_INTERRUPT 0x20000000 /* XXX */ 156 #define LINUX_SA_NOMASK 0x40000000 /* SA_NODEFER */ 157 #define LINUX_SA_ONESHOT 0x80000000 /* SA_RESETHAND */ 158 159 /* sigprocmask actions */ 160 #define LINUX_SIG_BLOCK 0 161 #define LINUX_SIG_UNBLOCK 1 162 #define LINUX_SIG_SETMASK 2 163 164 /* sigaltstack */ 165 #define LINUX_MINSIGSTKSZ 2048 /* XXX */ 166 167 typedef void (*l_handler_t)(l_int); 168 169 typedef struct { 170 l_handler_t lsa_handler; 171 l_ulong lsa_flags; 172 l_uintptr_t lsa_restorer; 173 l_sigset_t lsa_mask; 174 } l_sigaction_t; /* XXX */ 175 176 typedef struct { 177 l_uintptr_t ss_sp; 178 l_int ss_flags; 179 l_size_t ss_size; 180 } l_stack_t; 181 182 #define LINUX_SI_PREAMBLE_SIZE (4 * sizeof(int)) 183 #define LINUX_SI_MAX_SIZE 128 184 #define LINUX_SI_PAD_SIZE ((LINUX_SI_MAX_SIZE - \ 185 LINUX_SI_PREAMBLE_SIZE) / sizeof(l_int)) 186 typedef union l_sigval { 187 l_int sival_int; 188 l_uintptr_t sival_ptr; 189 } l_sigval_t; 190 191 typedef struct l_siginfo { 192 l_int lsi_signo; 193 l_int lsi_errno; 194 l_int lsi_code; 195 union { 196 l_int _pad[LINUX_SI_PAD_SIZE]; 197 198 struct { 199 l_pid_t _pid; 200 l_uid_t _uid; 201 } _kill; 202 203 struct { 204 l_timer_t _tid; 205 l_int _overrun; 206 char _pad[sizeof(l_uid_t) - sizeof(int)]; 207 union l_sigval _sigval; 208 l_uint _sys_private; 209 } _timer; 210 211 struct { 212 l_pid_t _pid; /* sender's pid */ 213 l_uid_t _uid; /* sender's uid */ 214 union l_sigval _sigval; 215 } _rt; 216 217 struct { 218 l_pid_t _pid; /* which child */ 219 l_uid_t _uid; /* sender's uid */ 220 l_int _status; /* exit code */ 221 l_clock_t _utime; 222 l_clock_t _stime; 223 } _sigchld; 224 225 struct { 226 l_uintptr_t _addr; /* Faulting insn/memory ref. */ 227 } _sigfault; 228 229 struct { 230 l_long _band; /* POLL_IN,POLL_OUT,POLL_MSG */ 231 l_int _fd; 232 } _sigpoll; 233 } _sifields; 234 } l_siginfo_t; 235 236 #define lsi_pid _sifields._kill._pid 237 #define lsi_uid _sifields._kill._uid 238 #define lsi_tid _sifields._timer._tid 239 #define lsi_overrun _sifields._timer._overrun 240 #define lsi_sys_private _sifields._timer._sys_private 241 #define lsi_status _sifields._sigchld._status 242 #define lsi_utime _sifields._sigchld._utime 243 #define lsi_stime _sifields._sigchld._stime 244 #define lsi_value _sifields._rt._sigval 245 #define lsi_int _sifields._rt._sigval.sival_int 246 #define lsi_ptr _sifields._rt._sigval.sival_ptr 247 #define lsi_addr _sifields._sigfault._addr 248 #define lsi_band _sifields._sigpoll._band 249 #define lsi_fd _sifields._sigpoll._fd 250 251 /* 252 * This structure is different from the one used by Linux, 253 * but it doesn't matter - it's not user-accessible. We need 254 * it instead of the native one because of l_siginfo. 255 */ 256 struct l_sigframe { 257 struct l_siginfo sf_si; 258 ucontext_t sf_uc; 259 }; 260 261 union l_semun { 262 l_int val; 263 l_uintptr_t buf; 264 l_uintptr_t array; 265 l_uintptr_t __buf; 266 l_uintptr_t __pad; 267 }; 268 269 struct l_ifmap { 270 l_ulong mem_start; 271 l_ulong mem_end; 272 l_ushort base_addr; 273 u_char irq; 274 u_char dma; 275 u_char port; 276 /* 3 bytes spare*/ 277 }; 278 279 struct l_ifreq { 280 union { 281 char ifrn_name[LINUX_IFNAMSIZ]; 282 } ifr_ifrn; 283 284 union { 285 struct l_sockaddr ifru_addr; 286 struct l_sockaddr ifru_dstaddr; 287 struct l_sockaddr ifru_broadaddr; 288 struct l_sockaddr ifru_netmask; 289 struct l_sockaddr ifru_hwaddr; 290 l_short ifru_flags[1]; 291 l_int ifru_ivalue; 292 l_int ifru_mtu; 293 struct l_ifmap ifru_map; 294 char ifru_slave[LINUX_IFNAMSIZ]; 295 l_uintptr_t ifru_data; 296 } ifr_ifru; 297 }; 298 299 #define ifr_name ifr_ifrn.ifrn_name /* Interface name */ 300 #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ 301 #define ifr_ifindex ifr_ifru.ifru_ivalue /* Interface index */ 302 303 #define linux_copyout_rusage(r, u) copyout(r, u, sizeof(*r)) 304 305 /* robust futexes */ 306 struct linux_robust_list { 307 l_uintptr_t next; 308 }; 309 310 struct linux_robust_list_head { 311 struct linux_robust_list list; 312 l_long futex_offset; 313 l_uintptr_t pending_list; 314 }; 315 316 struct linux_pt_regset { 317 l_ulong x[31]; 318 l_ulong sp; 319 l_ulong pc; 320 l_ulong cpsr; 321 }; 322 323 struct reg; 324 struct syscall_info; 325 326 void bsd_to_linux_regset(const struct reg *b_reg, 327 struct linux_pt_regset *l_regset); 328 void linux_to_bsd_regset(struct reg *b_reg, 329 const struct linux_pt_regset *l_regset); 330 void linux_ptrace_get_syscall_info_machdep(const struct reg *reg, 331 struct syscall_info *si); 332 int linux_ptrace_getregs_machdep(struct thread *td, pid_t pid, 333 struct linux_pt_regset *l_regset); 334 335 #endif /* _ARM64_LINUX_H_ */ 336