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