1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 1994-1996 Søren Schmidt 5 * Copyright (c) 2018 Turing Robotic Industries Inc. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 #define __ELF_WORD_SIZE 64 31 32 #include <sys/param.h> 33 #include <sys/elf.h> 34 #include <sys/exec.h> 35 #include <sys/imgact.h> 36 #include <sys/imgact_elf.h> 37 #include <sys/kernel.h> 38 #include <sys/ktr.h> 39 #include <sys/lock.h> 40 #include <sys/module.h> 41 #include <sys/mutex.h> 42 #include <sys/proc.h> 43 #include <sys/stddef.h> 44 #include <sys/syscallsubr.h> 45 #include <sys/sysctl.h> 46 #include <sys/sysent.h> 47 48 #include <vm/pmap.h> 49 #include <vm/vm.h> 50 #include <vm/vm_map.h> 51 #include <vm/vm_page.h> 52 53 #include <arm64/linux/linux.h> 54 #include <arm64/linux/linux_proto.h> 55 #include <compat/linux/linux_dtrace.h> 56 #include <compat/linux/linux_elf.h> 57 #include <compat/linux/linux_emul.h> 58 #include <compat/linux/linux_fork.h> 59 #include <compat/linux/linux_ioctl.h> 60 #include <compat/linux/linux_mib.h> 61 #include <compat/linux/linux_misc.h> 62 #include <compat/linux/linux_signal.h> 63 #include <compat/linux/linux_util.h> 64 #include <compat/linux/linux_vdso.h> 65 66 #include <arm64/linux/linux_sigframe.h> 67 68 #include <machine/md_var.h> 69 #include <machine/pcb.h> 70 #ifdef VFP 71 #include <machine/vfp.h> 72 #endif 73 74 MODULE_VERSION(linux64elf, 1); 75 76 #define LINUX_VDSOPAGE_SIZE PAGE_SIZE * 2 77 #define LINUX_VDSOPAGE (VM_MAXUSER_ADDRESS - \ 78 LINUX_VDSOPAGE_SIZE) 79 #define LINUX_SHAREDPAGE (LINUX_VDSOPAGE - PAGE_SIZE) 80 /* 81 * PAGE_SIZE - the size 82 * of the native SHAREDPAGE 83 */ 84 #define LINUX_USRSTACK LINUX_SHAREDPAGE 85 #define LINUX_PS_STRINGS (LINUX_USRSTACK - \ 86 sizeof(struct ps_strings)) 87 88 static int linux_szsigcode; 89 static vm_object_t linux_vdso_obj; 90 static char *linux_vdso_mapping; 91 extern char _binary_linux_vdso_so_o_start; 92 extern char _binary_linux_vdso_so_o_end; 93 static vm_offset_t linux_vdso_base; 94 95 extern struct sysent linux_sysent[LINUX_SYS_MAXSYSCALL]; 96 extern const char *linux_syscallnames[]; 97 98 SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler); 99 100 static void linux_vdso_install(const void *param); 101 static void linux_vdso_deinstall(const void *param); 102 static void linux_vdso_reloc(char *mapping, Elf_Addr offset); 103 static void linux_set_syscall_retval(struct thread *td, int error); 104 static int linux_fetch_syscall_args(struct thread *td); 105 static void linux_exec_setregs(struct thread *td, struct image_params *imgp, 106 uintptr_t stack); 107 static void linux_exec_sysvec_init(void *param); 108 static int linux_on_exec_vmspace(struct proc *p, 109 struct image_params *imgp); 110 111 /* DTrace init */ 112 LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE); 113 114 /* DTrace probes */ 115 LIN_SDT_PROBE_DEFINE0(sysvec, linux_exec_setregs, todo); 116 117 LINUX_VDSO_SYM_CHAR(linux_platform); 118 LINUX_VDSO_SYM_INTPTR(kern_timekeep_base); 119 LINUX_VDSO_SYM_INTPTR(__user_rt_sigreturn); 120 121 static int 122 linux_fetch_syscall_args(struct thread *td) 123 { 124 struct proc *p; 125 struct syscall_args *sa; 126 register_t *ap; 127 128 p = td->td_proc; 129 ap = td->td_frame->tf_x; 130 sa = &td->td_sa; 131 132 sa->code = td->td_frame->tf_x[8]; 133 sa->original_code = sa->code; 134 /* LINUXTODO: generic syscall? */ 135 if (sa->code >= p->p_sysent->sv_size) 136 sa->callp = &p->p_sysent->sv_table[0]; 137 else 138 sa->callp = &p->p_sysent->sv_table[sa->code]; 139 140 if (sa->callp->sy_narg > nitems(sa->args)) 141 panic("ARM64TODO: Could we have more than %zu args?", 142 nitems(sa->args)); 143 memcpy(sa->args, ap, nitems(sa->args) * sizeof(register_t)); 144 145 td->td_retval[0] = 0; 146 return (0); 147 } 148 149 static void 150 linux_set_syscall_retval(struct thread *td, int error) 151 { 152 153 td->td_retval[1] = td->td_frame->tf_x[1]; 154 cpu_set_syscall_retval(td, error); 155 156 if (__predict_false(error != 0)) { 157 if (error != ERESTART && error != EJUSTRETURN) 158 td->td_frame->tf_x[0] = bsd_to_linux_errno(error); 159 } 160 } 161 162 void 163 linux64_arch_copyout_auxargs(struct image_params *imgp, Elf_Auxinfo **pos) 164 { 165 166 AUXARGS_ENTRY((*pos), LINUX_AT_SYSINFO_EHDR, linux_vdso_base); 167 AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP, *imgp->sysent->sv_hwcap); 168 AUXARGS_ENTRY((*pos), LINUX_AT_HWCAP2, *imgp->sysent->sv_hwcap2); 169 AUXARGS_ENTRY((*pos), LINUX_AT_PLATFORM, PTROUT(linux_platform)); 170 } 171 172 /* 173 * Reset registers to default values on exec. 174 */ 175 static void 176 linux_exec_setregs(struct thread *td, struct image_params *imgp, 177 uintptr_t stack) 178 { 179 struct trapframe *regs = td->td_frame; 180 struct pcb *pcb = td->td_pcb; 181 182 /* LINUXTODO: validate */ 183 LIN_SDT_PROBE0(sysvec, linux_exec_setregs, todo); 184 185 memset(regs, 0, sizeof(*regs)); 186 /* glibc start.S registers function pointer in x0 with atexit. */ 187 regs->tf_sp = stack; 188 #if 0 /* LINUXTODO: See if this is used. */ 189 regs->tf_lr = imgp->entry_addr; 190 #else 191 regs->tf_lr = 0xffffffffffffffff; 192 #endif 193 regs->tf_elr = imgp->entry_addr; 194 195 pcb->pcb_tpidr_el0 = 0; 196 pcb->pcb_tpidrro_el0 = 0; 197 WRITE_SPECIALREG(tpidrro_el0, 0); 198 WRITE_SPECIALREG(tpidr_el0, 0); 199 200 #ifdef VFP 201 vfp_reset_state(td, pcb); 202 #endif 203 204 /* 205 * Clear debug register state. It is not applicable to the new process. 206 */ 207 bzero(&pcb->pcb_dbg_regs, sizeof(pcb->pcb_dbg_regs)); 208 } 209 210 int 211 linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args) 212 { 213 struct l_sigframe *frame; 214 ucontext_t uc; 215 struct trapframe *tf; 216 int error; 217 218 tf = td->td_frame; 219 frame = (struct l_sigframe *)tf->tf_sp; 220 221 if (copyin((void *)&frame->uc, &uc, sizeof(uc))) 222 return (EFAULT); 223 224 error = set_mcontext(td, &uc.uc_mcontext); 225 if (error != 0) 226 return (error); 227 228 /* Restore signal mask. */ 229 kern_sigprocmask(td, SIG_SETMASK, &uc.uc_sigmask, NULL, 0); 230 231 return (EJUSTRETURN); 232 } 233 234 static void 235 linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask) 236 { 237 struct thread *td; 238 struct proc *p; 239 struct trapframe *tf; 240 struct l_sigframe *fp, *frame; 241 struct l_fpsimd_context *fpsimd; 242 struct l_esr_context *esr; 243 l_stack_t uc_stack; 244 ucontext_t uc; 245 uint8_t *scr; 246 struct sigacts *psp; 247 int onstack, sig, issiginfo; 248 249 td = curthread; 250 p = td->td_proc; 251 PROC_LOCK_ASSERT(p, MA_OWNED); 252 253 sig = ksi->ksi_signo; 254 psp = p->p_sigacts; 255 mtx_assert(&psp->ps_mtx, MA_OWNED); 256 257 tf = td->td_frame; 258 onstack = sigonstack(tf->tf_sp); 259 issiginfo = SIGISMEMBER(psp->ps_siginfo, sig); 260 261 CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm, 262 catcher, sig); 263 264 /* Allocate and validate space for the signal handler context. */ 265 if ((td->td_pflags & TDP_ALTSTACK) != 0 && !onstack && 266 SIGISMEMBER(psp->ps_sigonstack, sig)) { 267 fp = (struct l_sigframe *)((uintptr_t)td->td_sigstk.ss_sp + 268 td->td_sigstk.ss_size); 269 #if defined(COMPAT_43) 270 td->td_sigstk.ss_flags |= SS_ONSTACK; 271 #endif 272 } else { 273 fp = (struct l_sigframe *)td->td_frame->tf_sp; 274 } 275 276 /* Make room, keeping the stack aligned */ 277 fp--; 278 fp = (struct l_sigframe *)STACKALIGN(fp); 279 280 get_mcontext(td, &uc.uc_mcontext, 0); 281 uc.uc_sigmask = *mask; 282 283 uc_stack.ss_sp = PTROUT(td->td_sigstk.ss_sp); 284 uc_stack.ss_size = td->td_sigstk.ss_size; 285 uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK) != 0 ? 286 (onstack ? LINUX_SS_ONSTACK : 0) : LINUX_SS_DISABLE; 287 mtx_unlock(&psp->ps_mtx); 288 PROC_UNLOCK(td->td_proc); 289 290 /* Fill in the frame to copy out */ 291 frame = malloc(sizeof(*frame), M_LINUX, M_WAITOK | M_ZERO); 292 293 memcpy(&frame->sf.sf_uc.uc_sc.regs, tf->tf_x, sizeof(tf->tf_x)); 294 frame->sf.sf_uc.uc_sc.regs[30] = tf->tf_lr; 295 frame->sf.sf_uc.uc_sc.sp = tf->tf_sp; 296 frame->sf.sf_uc.uc_sc.pc = tf->tf_elr; 297 frame->sf.sf_uc.uc_sc.pstate = tf->tf_spsr; 298 frame->sf.sf_uc.uc_sc.fault_address = (register_t)ksi->ksi_addr; 299 300 /* Stack frame for unwinding */ 301 frame->fp = tf->tf_x[29]; 302 frame->lr = tf->tf_elr; 303 304 /* Translate the signal. */ 305 sig = bsd_to_linux_signal(sig); 306 siginfo_to_lsiginfo(&ksi->ksi_info, &frame->sf.sf_si, sig); 307 bsd_to_linux_sigset(mask, &frame->sf.sf_uc.uc_sigmask); 308 309 /* 310 * Prepare fpsimd & esr. Does not check sizes, as 311 * __reserved is big enougth. 312 */ 313 scr = (uint8_t *)&frame->sf.sf_uc.uc_sc.__reserved; 314 #ifdef VFP 315 fpsimd = (struct l_fpsimd_context *) scr; 316 fpsimd->head.magic = L_FPSIMD_MAGIC; 317 fpsimd->head.size = sizeof(struct l_fpsimd_context); 318 fpsimd->fpsr = uc.uc_mcontext.mc_fpregs.fp_sr; 319 fpsimd->fpcr = uc.uc_mcontext.mc_fpregs.fp_cr; 320 321 memcpy(fpsimd->vregs, &uc.uc_mcontext.mc_fpregs.fp_q, 322 sizeof(uc.uc_mcontext.mc_fpregs.fp_q)); 323 scr += roundup(sizeof(struct l_fpsimd_context), 16); 324 #endif 325 if (ksi->ksi_addr != 0) { 326 esr = (struct l_esr_context *) scr; 327 esr->head.magic = L_ESR_MAGIC; 328 esr->head.size = sizeof(struct l_esr_context); 329 esr->esr = tf->tf_esr; 330 } 331 332 memcpy(&frame->sf.sf_uc.uc_stack, &uc_stack, sizeof(uc_stack)); 333 memcpy(&frame->uc, &uc, sizeof(uc)); 334 335 /* Copy the sigframe out to the user's stack. */ 336 if (copyout(frame, fp, sizeof(*fp)) != 0) { 337 /* Process has trashed its stack. Kill it. */ 338 free(frame, M_LINUX); 339 CTR2(KTR_SIG, "sendsig: sigexit td=%p fp=%p", td, fp); 340 PROC_LOCK(p); 341 sigexit(td, SIGILL); 342 } 343 free(frame, M_LINUX); 344 345 tf->tf_x[0]= sig; 346 if (issiginfo) { 347 tf->tf_x[1] = (register_t)&fp->sf.sf_si; 348 tf->tf_x[2] = (register_t)&fp->sf.sf_uc; 349 } else { 350 tf->tf_x[1] = 0; 351 tf->tf_x[2] = 0; 352 } 353 tf->tf_x[29] = (register_t)&fp->fp; 354 tf->tf_elr = (register_t)catcher; 355 tf->tf_sp = (register_t)fp; 356 tf->tf_lr = (register_t)__user_rt_sigreturn; 357 358 CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td, tf->tf_elr, 359 tf->tf_sp); 360 361 PROC_LOCK(p); 362 mtx_lock(&psp->ps_mtx); 363 } 364 365 struct sysentvec elf_linux_sysvec = { 366 .sv_size = LINUX_SYS_MAXSYSCALL, 367 .sv_table = linux_sysent, 368 .sv_fixup = __elfN(freebsd_fixup), 369 .sv_sendsig = linux_rt_sendsig, 370 .sv_sigcode = &_binary_linux_vdso_so_o_start, 371 .sv_szsigcode = &linux_szsigcode, 372 .sv_name = "Linux ELF64", 373 .sv_coredump = elf64_coredump, 374 .sv_elf_core_osabi = ELFOSABI_NONE, 375 .sv_elf_core_abi_vendor = LINUX_ABI_VENDOR, 376 .sv_elf_core_prepare_notes = linux64_prepare_notes, 377 .sv_minsigstksz = LINUX_MINSIGSTKSZ, 378 .sv_minuser = VM_MIN_ADDRESS, 379 .sv_maxuser = VM_MAXUSER_ADDRESS, 380 .sv_usrstack = LINUX_USRSTACK, 381 .sv_psstrings = LINUX_PS_STRINGS, 382 .sv_psstringssz = sizeof(struct ps_strings), 383 .sv_stackprot = VM_PROT_READ | VM_PROT_WRITE, 384 .sv_copyout_auxargs = __linuxN(copyout_auxargs), 385 .sv_copyout_strings = __linuxN(copyout_strings), 386 .sv_setregs = linux_exec_setregs, 387 .sv_fixlimit = NULL, 388 .sv_maxssiz = NULL, 389 .sv_flags = SV_ABI_LINUX | SV_LP64 | SV_SHP | SV_SIG_DISCIGN | 390 SV_SIG_WAITNDQ | SV_TIMEKEEP, 391 .sv_set_syscall_retval = linux_set_syscall_retval, 392 .sv_fetch_syscall_args = linux_fetch_syscall_args, 393 .sv_syscallnames = linux_syscallnames, 394 .sv_shared_page_base = LINUX_SHAREDPAGE, 395 .sv_shared_page_len = PAGE_SIZE, 396 .sv_schedtail = linux_schedtail, 397 .sv_thread_detach = linux_thread_detach, 398 .sv_trap = NULL, 399 .sv_hwcap = &elf_hwcap, 400 .sv_hwcap2 = &elf_hwcap2, 401 .sv_onexec = linux_on_exec_vmspace, 402 .sv_onexit = linux_on_exit, 403 .sv_ontdexit = linux_thread_dtor, 404 .sv_setid_allowed = &linux_setid_allowed_query, 405 }; 406 407 static int 408 linux_on_exec_vmspace(struct proc *p, struct image_params *imgp) 409 { 410 int error; 411 412 error = linux_map_vdso(p, linux_vdso_obj, linux_vdso_base, 413 LINUX_VDSOPAGE_SIZE, imgp); 414 if (error == 0) 415 error = linux_on_exec(p, imgp); 416 return (error); 417 } 418 419 /* 420 * linux_vdso_install() and linux_exec_sysvec_init() must be called 421 * after exec_sysvec_init() which is SI_SUB_EXEC (SI_ORDER_ANY). 422 */ 423 static void 424 linux_exec_sysvec_init(void *param) 425 { 426 l_uintptr_t *ktimekeep_base; 427 struct sysentvec *sv; 428 ptrdiff_t tkoff; 429 430 sv = param; 431 /* Fill timekeep_base */ 432 exec_sysvec_init(sv); 433 434 tkoff = kern_timekeep_base - linux_vdso_base; 435 ktimekeep_base = (l_uintptr_t *)(linux_vdso_mapping + tkoff); 436 *ktimekeep_base = sv->sv_shared_page_base + sv->sv_timekeep_offset; 437 } 438 SYSINIT(elf_linux_exec_sysvec_init, SI_SUB_EXEC + 1, SI_ORDER_ANY, 439 linux_exec_sysvec_init, &elf_linux_sysvec); 440 441 static void 442 linux_vdso_install(const void *param) 443 { 444 char *vdso_start = &_binary_linux_vdso_so_o_start; 445 char *vdso_end = &_binary_linux_vdso_so_o_end; 446 447 linux_szsigcode = vdso_end - vdso_start; 448 MPASS(linux_szsigcode <= LINUX_VDSOPAGE_SIZE); 449 450 linux_vdso_base = LINUX_VDSOPAGE; 451 452 __elfN(linux_vdso_fixup)(vdso_start, linux_vdso_base); 453 454 linux_vdso_obj = __elfN(linux_shared_page_init) 455 (&linux_vdso_mapping, LINUX_VDSOPAGE_SIZE); 456 bcopy(vdso_start, linux_vdso_mapping, linux_szsigcode); 457 458 linux_vdso_reloc(linux_vdso_mapping, linux_vdso_base); 459 } 460 SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC + 1, SI_ORDER_FIRST, 461 linux_vdso_install, NULL); 462 463 static void 464 linux_vdso_deinstall(const void *param) 465 { 466 467 __elfN(linux_shared_page_fini)(linux_vdso_obj, 468 linux_vdso_mapping, LINUX_VDSOPAGE_SIZE); 469 } 470 SYSUNINIT(elf_linux_vdso_uninit, SI_SUB_EXEC, SI_ORDER_FIRST, 471 linux_vdso_deinstall, NULL); 472 473 static void 474 linux_vdso_reloc(char *mapping, Elf_Addr offset) 475 { 476 Elf_Size rtype, symidx; 477 const Elf_Rela *rela; 478 const Elf_Shdr *shdr; 479 const Elf_Ehdr *ehdr; 480 Elf_Addr *where; 481 Elf_Addr addr, addend; 482 int i, relacnt; 483 484 MPASS(offset != 0); 485 486 relacnt = 0; 487 ehdr = (const Elf_Ehdr *)mapping; 488 shdr = (const Elf_Shdr *)(mapping + ehdr->e_shoff); 489 for (i = 0; i < ehdr->e_shnum; i++) 490 { 491 switch (shdr[i].sh_type) { 492 case SHT_REL: 493 printf("Linux Aarch64 vDSO: unexpected Rel section\n"); 494 break; 495 case SHT_RELA: 496 rela = (const Elf_Rela *)(mapping + shdr[i].sh_offset); 497 relacnt = shdr[i].sh_size / sizeof(*rela); 498 } 499 } 500 501 for (i = 0; i < relacnt; i++, rela++) { 502 where = (Elf_Addr *)(mapping + rela->r_offset); 503 addend = rela->r_addend; 504 rtype = ELF_R_TYPE(rela->r_info); 505 symidx = ELF_R_SYM(rela->r_info); 506 507 switch (rtype) { 508 case R_AARCH64_NONE: /* none */ 509 break; 510 511 case R_AARCH64_RELATIVE: /* B + A */ 512 addr = (Elf_Addr)(mapping + addend); 513 if (*where != addr) 514 *where = addr; 515 break; 516 default: 517 printf("Linux Aarch64 vDSO: unexpected relocation type %ld, " 518 "symbol index %ld\n", rtype, symidx); 519 } 520 } 521 } 522 523 static Elf_Brandnote linux64_brandnote = { 524 .hdr.n_namesz = sizeof(GNU_ABI_VENDOR), 525 .hdr.n_descsz = 16, 526 .hdr.n_type = 1, 527 .vendor = GNU_ABI_VENDOR, 528 .flags = BN_TRANSLATE_OSREL, 529 .trans_osrel = linux_trans_osrel 530 }; 531 532 static Elf64_Brandinfo linux_glibc2brand = { 533 .brand = ELFOSABI_LINUX, 534 .machine = EM_AARCH64, 535 .compat_3_brand = "Linux", 536 .interp_path = "/lib64/ld-linux-x86-64.so.2", 537 .sysvec = &elf_linux_sysvec, 538 .interp_newpath = NULL, 539 .brand_note = &linux64_brandnote, 540 .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE 541 }; 542 543 Elf64_Brandinfo *linux_brandlist[] = { 544 &linux_glibc2brand, 545 NULL 546 }; 547 548 static int 549 linux64_elf_modevent(module_t mod, int type, void *data) 550 { 551 Elf64_Brandinfo **brandinfo; 552 struct linux_ioctl_handler**lihp; 553 int error; 554 555 error = 0; 556 switch(type) { 557 case MOD_LOAD: 558 for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL; 559 ++brandinfo) 560 if (elf64_insert_brand_entry(*brandinfo) < 0) 561 error = EINVAL; 562 if (error == 0) { 563 SET_FOREACH(lihp, linux_ioctl_handler_set) 564 linux_ioctl_register_handler(*lihp); 565 stclohz = (stathz ? stathz : hz); 566 if (bootverbose) 567 printf("Linux arm64 ELF exec handler installed\n"); 568 } 569 break; 570 case MOD_UNLOAD: 571 for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL; 572 ++brandinfo) 573 if (elf64_brand_inuse(*brandinfo)) 574 error = EBUSY; 575 if (error == 0) { 576 for (brandinfo = &linux_brandlist[0]; 577 *brandinfo != NULL; ++brandinfo) 578 if (elf64_remove_brand_entry(*brandinfo) < 0) 579 error = EINVAL; 580 } 581 if (error == 0) { 582 SET_FOREACH(lihp, linux_ioctl_handler_set) 583 linux_ioctl_unregister_handler(*lihp); 584 if (bootverbose) 585 printf("Linux arm64 ELF exec handler removed\n"); 586 } else 587 printf("Could not deinstall Linux arm64 ELF interpreter entry\n"); 588 break; 589 default: 590 return (EOPNOTSUPP); 591 } 592 return (error); 593 } 594 595 static moduledata_t linux64_elf_mod = { 596 "linux64elf", 597 linux64_elf_modevent, 598 0 599 }; 600 601 DECLARE_MODULE_TIED(linux64elf, linux64_elf_mod, SI_SUB_EXEC, SI_ORDER_ANY); 602 MODULE_DEPEND(linux64elf, linux_common, 1, 1, 1); 603 FEATURE(linux64, "AArch64 Linux 64bit support"); 604