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