xref: /freebsd/sys/arm64/linux/linux_sysvec.c (revision 3ff01b231dfa83d518854c63e7c9cd1debd1139e)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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 __FBSDID("$FreeBSD$");
31 
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/cdefs.h>
35 #include <sys/elf.h>
36 #include <sys/exec.h>
37 #include <sys/imgact.h>
38 #include <sys/imgact_elf.h>
39 #include <sys/kernel.h>
40 #include <sys/lock.h>
41 #include <sys/module.h>
42 #include <sys/mutex.h>
43 #include <sys/proc.h>
44 #include <sys/signalvar.h>
45 #include <sys/sysctl.h>
46 #include <sys/sysent.h>
47 
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_dtrace.h>
53 #include <compat/linux/linux_emul.h>
54 #include <compat/linux/linux_ioctl.h>
55 #include <compat/linux/linux_mib.h>
56 #include <compat/linux/linux_misc.h>
57 #include <compat/linux/linux_util.h>
58 #include <compat/linux/linux_vdso.h>
59 
60 #include <machine/md_var.h>
61 
62 #ifdef VFP
63 #include <machine/vfp.h>
64 #endif
65 
66 MODULE_VERSION(linux64elf, 1);
67 
68 const char *linux_kplatform;
69 static int linux_szsigcode;
70 static vm_object_t linux_shared_page_obj;
71 static char *linux_shared_page_mapping;
72 extern char _binary_linux_locore_o_start;
73 extern char _binary_linux_locore_o_end;
74 
75 extern struct sysent linux_sysent[LINUX_SYS_MAXSYSCALL];
76 
77 SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler);
78 
79 static int	linux_copyout_strings(struct image_params *imgp,
80 		    uintptr_t *stack_base);
81 static int	linux_elf_fixup(uintptr_t *stack_base,
82 		    struct image_params *iparams);
83 static bool	linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
84 static void	linux_vdso_install(const void *param);
85 static void	linux_vdso_deinstall(const void *param);
86 static void	linux_set_syscall_retval(struct thread *td, int error);
87 static int	linux_fetch_syscall_args(struct thread *td);
88 static void	linux_exec_setregs(struct thread *td, struct image_params *imgp,
89 		    uintptr_t stack);
90 static int	linux_vsyscall(struct thread *td);
91 
92 /* DTrace init */
93 LIN_SDT_PROVIDER_DECLARE(LINUX_DTRACE);
94 
95 /* DTrace probes */
96 LIN_SDT_PROBE_DEFINE2(sysvec, linux_translate_traps, todo, "int", "int");
97 LIN_SDT_PROBE_DEFINE0(sysvec, linux_exec_setregs, todo);
98 LIN_SDT_PROBE_DEFINE0(sysvec, linux_copyout_auxargs, todo);
99 LIN_SDT_PROBE_DEFINE0(sysvec, linux_elf_fixup, todo);
100 LIN_SDT_PROBE_DEFINE0(sysvec, linux_rt_sigreturn, todo);
101 LIN_SDT_PROBE_DEFINE0(sysvec, linux_rt_sendsig, todo);
102 LIN_SDT_PROBE_DEFINE0(sysvec, linux_vsyscall, todo);
103 LIN_SDT_PROBE_DEFINE0(sysvec, linux_vdso_install, todo);
104 LIN_SDT_PROBE_DEFINE0(sysvec, linux_vdso_deinstall, todo);
105 
106 /* LINUXTODO: do we have traps to translate? */
107 static int
108 linux_translate_traps(int signal, int trap_code)
109 {
110 
111 	LIN_SDT_PROBE2(sysvec, linux_translate_traps, todo, signal, trap_code);
112 	return (signal);
113 }
114 
115 LINUX_VDSO_SYM_CHAR(linux_platform);
116 
117 static int
118 linux_fetch_syscall_args(struct thread *td)
119 {
120 	struct proc *p;
121 	struct syscall_args *sa;
122 	register_t *ap;
123 
124 	p = td->td_proc;
125 	ap = td->td_frame->tf_x;
126 	sa = &td->td_sa;
127 
128 	sa->code = td->td_frame->tf_x[8];
129 	/* LINUXTODO: generic syscall? */
130 	if (sa->code >= p->p_sysent->sv_size)
131 		sa->callp = &p->p_sysent->sv_table[0];
132 	else
133 		sa->callp = &p->p_sysent->sv_table[sa->code];
134 
135 	if (sa->callp->sy_narg > MAXARGS)
136 		panic("ARM64TODO: Could we have more than %d args?", MAXARGS);
137 	memcpy(sa->args, ap, MAXARGS * sizeof(register_t));
138 
139 	td->td_retval[0] = 0;
140 	return (0);
141 }
142 
143 static void
144 linux_set_syscall_retval(struct thread *td, int error)
145 {
146 
147 	td->td_retval[1] = td->td_frame->tf_x[1];
148 	cpu_set_syscall_retval(td, error);
149 
150 	if (__predict_false(error != 0)) {
151 		if (error != ERESTART && error != EJUSTRETURN)
152 			td->td_frame->tf_x[0] = bsd_to_linux_errno(error);
153 	}
154 }
155 
156 static int
157 linux_copyout_auxargs(struct image_params *imgp, uintptr_t base)
158 {
159 	Elf_Auxargs *args;
160 	Elf_Auxinfo *argarray, *pos;
161 	struct proc *p;
162 	int error, issetugid;
163 
164 	LIN_SDT_PROBE0(sysvec, linux_copyout_auxargs, todo);
165 	p = imgp->proc;
166 
167 	args = (Elf64_Auxargs *)imgp->auxargs;
168 	argarray = pos = malloc(LINUX_AT_COUNT * sizeof(*pos), M_TEMP,
169 	    M_WAITOK | M_ZERO);
170 
171 	issetugid = p->p_flag & P_SUGID ? 1 : 0;
172 	AUXARGS_ENTRY(pos, LINUX_AT_SYSINFO_EHDR,
173 	    imgp->proc->p_sysent->sv_shared_page_base);
174 	AUXARGS_ENTRY(pos, LINUX_AT_HWCAP, *imgp->sysent->sv_hwcap);
175 	AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz);
176 	AUXARGS_ENTRY(pos, LINUX_AT_CLKTCK, stclohz);
177 	AUXARGS_ENTRY(pos, AT_PHDR, args->phdr);
178 	AUXARGS_ENTRY(pos, AT_PHENT, args->phent);
179 	AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum);
180 	AUXARGS_ENTRY(pos, AT_BASE, args->base);
181 	AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
182 	AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
183 	AUXARGS_ENTRY(pos, AT_UID, imgp->proc->p_ucred->cr_ruid);
184 	AUXARGS_ENTRY(pos, AT_EUID, imgp->proc->p_ucred->cr_svuid);
185 	AUXARGS_ENTRY(pos, AT_GID, imgp->proc->p_ucred->cr_rgid);
186 	AUXARGS_ENTRY(pos, AT_EGID, imgp->proc->p_ucred->cr_svgid);
187 	AUXARGS_ENTRY(pos, LINUX_AT_SECURE, issetugid);
188 	AUXARGS_ENTRY_PTR(pos, LINUX_AT_RANDOM, imgp->canary);
189 	AUXARGS_ENTRY(pos, LINUX_AT_HWCAP2, *imgp->sysent->sv_hwcap2);
190 	if (imgp->execpathp != 0)
191 		AUXARGS_ENTRY_PTR(pos, LINUX_AT_EXECFN, imgp->execpathp);
192 	if (args->execfd != -1)
193 		AUXARGS_ENTRY(pos, AT_EXECFD, args->execfd);
194 	AUXARGS_ENTRY(pos, LINUX_AT_PLATFORM, PTROUT(linux_platform));
195 	AUXARGS_ENTRY(pos, AT_NULL, 0);
196 
197 	free(imgp->auxargs, M_TEMP);
198 	imgp->auxargs = NULL;
199 	KASSERT(pos - argarray <= LINUX_AT_COUNT, ("Too many auxargs"));
200 
201 	error = copyout(argarray, (void *)base,
202 	    sizeof(*argarray) * LINUX_AT_COUNT);
203 	free(argarray, M_TEMP);
204 	return (error);
205 }
206 
207 static int
208 linux_elf_fixup(uintptr_t *stack_base, struct image_params *imgp)
209 {
210 
211 	LIN_SDT_PROBE0(sysvec, linux_elf_fixup, todo);
212 
213 	return (0);
214 }
215 
216 /*
217  * Copy strings out to the new process address space, constructing new arg
218  * and env vector tables. Return a pointer to the base so that it can be used
219  * as the initial stack pointer.
220  * LINUXTODO: deduplicate against other linuxulator archs
221  */
222 static int
223 linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
224 {
225 	char **vectp;
226 	char *stringp;
227 	uintptr_t destp, ustringp;
228 	struct ps_strings *arginfo;
229 	char canary[LINUX_AT_RANDOM_LEN];
230 	size_t execpath_len;
231 	struct proc *p;
232 	int argc, envc, error;
233 
234 	/* Calculate string base and vector table pointers. */
235 	if (imgp->execpath != NULL && imgp->auxargs != NULL)
236 		execpath_len = strlen(imgp->execpath) + 1;
237 	else
238 		execpath_len = 0;
239 
240 	p = imgp->proc;
241 	arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
242 	destp = (uintptr_t)arginfo;
243 
244 	if (execpath_len != 0) {
245 		destp -= execpath_len;
246 		destp = rounddown2(destp, sizeof(void *));
247 		imgp->execpathp = (void *)destp;
248 		error = copyout(imgp->execpath, imgp->execpathp, execpath_len);
249 		if (error != 0)
250 			return (error);
251 	}
252 
253 	/* Prepare the canary for SSP. */
254 	arc4rand(canary, sizeof(canary), 0);
255 	destp -= roundup(sizeof(canary), sizeof(void *));
256 	imgp->canary = (void *)destp;
257 	error = copyout(canary, imgp->canary, sizeof(canary));
258 	if (error != 0)
259 		return (error);
260 
261 	/* Allocate room for the argument and environment strings. */
262 	destp -= ARG_MAX - imgp->args->stringspace;
263 	destp = rounddown2(destp, sizeof(void *));
264 	ustringp = destp;
265 
266 	if (imgp->auxargs) {
267 		/*
268 		 * Allocate room on the stack for the ELF auxargs
269 		 * array.  It has up to LINUX_AT_COUNT entries.
270 		 */
271 		destp -= LINUX_AT_COUNT * sizeof(Elf64_Auxinfo);
272 		destp = rounddown2(destp, sizeof(void *));
273 	}
274 
275 	vectp = (char **)destp;
276 
277 	/*
278 	 * Allocate room for argc and the argv[] and env vectors including the
279 	 * terminating NULL pointers.
280 	 */
281 	vectp -= 1 + imgp->args->argc + 1 + imgp->args->envc + 1;
282 	vectp = (char **)STACKALIGN(vectp);
283 
284 	/* vectp also becomes our initial stack base. */
285 	*stack_base = (uintptr_t)vectp;
286 
287 	stringp = imgp->args->begin_argv;
288 	argc = imgp->args->argc;
289 	envc = imgp->args->envc;
290 
291 	/* Copy out strings - arguments and environment. */
292 	error = copyout(stringp, (void *)ustringp,
293 	    ARG_MAX - imgp->args->stringspace);
294 	if (error != 0)
295 		return (error);
296 
297 	/* Fill in "ps_strings" struct for ps, w, etc. */
298 	if (suword(&arginfo->ps_argvstr, (long)(intptr_t)vectp) != 0 ||
299 	    suword(&arginfo->ps_nargvstr, argc) != 0)
300 		return (EFAULT);
301 
302 	if (suword(vectp++, argc) != 0)
303 		return (EFAULT);
304 
305 	/* Fill in argument portion of vector table. */
306 	for (; argc > 0; --argc) {
307 		if (suword(vectp++, ustringp) != 0)
308 			return (EFAULT);
309 		while (*stringp++ != 0)
310 			ustringp++;
311 		ustringp++;
312 	}
313 
314 	/* A null vector table pointer separates the argp's from the envp's. */
315 	if (suword(vectp++, 0) != 0)
316 		return (EFAULT);
317 
318 	if (suword(&arginfo->ps_envstr, (long)(intptr_t)vectp) != 0 ||
319 	    suword(&arginfo->ps_nenvstr, envc) != 0)
320 		return (EFAULT);
321 
322 	/* Fill in environment portion of vector table. */
323 	for (; envc > 0; --envc) {
324 		if (suword(vectp++, ustringp) != 0)
325 			return (EFAULT);
326 		while (*stringp++ != 0)
327 			ustringp++;
328 		ustringp++;
329 	}
330 
331 	/* The end of the vector table is a null pointer. */
332 	if (suword(vectp, 0) != 0)
333 		return (EFAULT);
334 
335 	if (imgp->auxargs) {
336 		vectp++;
337 		error = imgp->sysent->sv_copyout_auxargs(imgp,
338 		    (uintptr_t)vectp);
339 		if (error != 0)
340 			return (error);
341 	}
342 
343 	return (0);
344 }
345 
346 /*
347  * Reset registers to default values on exec.
348  */
349 static void
350 linux_exec_setregs(struct thread *td, struct image_params *imgp,
351     uintptr_t stack)
352 {
353 	struct trapframe *regs = td->td_frame;
354 	struct pcb *pcb = td->td_pcb;
355 
356 	/* LINUXTODO: validate */
357 	LIN_SDT_PROBE0(sysvec, linux_exec_setregs, todo);
358 
359 	memset(regs, 0, sizeof(*regs));
360 	/* glibc start.S registers function pointer in x0 with atexit. */
361         regs->tf_sp = stack;
362 #if 0	/* LINUXTODO: See if this is used. */
363 	regs->tf_lr = imgp->entry_addr;
364 #else
365         regs->tf_lr = 0xffffffffffffffff;
366 #endif
367         regs->tf_elr = imgp->entry_addr;
368 
369 	pcb->pcb_tpidr_el0 = 0;
370 	pcb->pcb_tpidrro_el0 = 0;
371 	WRITE_SPECIALREG(tpidrro_el0, 0);
372 	WRITE_SPECIALREG(tpidr_el0, 0);
373 
374 #ifdef VFP
375 	vfp_reset_state(td, pcb);
376 #endif
377 
378 	/*
379 	 * Clear debug register state. It is not applicable to the new process.
380 	 */
381 	bzero(&pcb->pcb_dbg_regs, sizeof(pcb->pcb_dbg_regs));
382 }
383 
384 int
385 linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args)
386 {
387 
388 	/* LINUXTODO: implement */
389 	LIN_SDT_PROBE0(sysvec, linux_rt_sigreturn, todo);
390 	return (EDOOFUS);
391 }
392 
393 static void
394 linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
395 {
396 
397 	/* LINUXTODO: implement */
398 	LIN_SDT_PROBE0(sysvec, linux_rt_sendsig, todo);
399 }
400 
401 static int
402 linux_vsyscall(struct thread *td)
403 {
404 
405 	/* LINUXTODO: implement */
406 	LIN_SDT_PROBE0(sysvec, linux_vsyscall, todo);
407 	return (EDOOFUS);
408 }
409 
410 struct sysentvec elf_linux_sysvec = {
411 	.sv_size	= LINUX_SYS_MAXSYSCALL,
412 	.sv_table	= linux_sysent,
413 	.sv_transtrap	= linux_translate_traps,
414 	.sv_fixup	= linux_elf_fixup,
415 	.sv_sendsig	= linux_rt_sendsig,
416 	.sv_sigcode	= &_binary_linux_locore_o_start,
417 	.sv_szsigcode	= &linux_szsigcode,
418 	.sv_name	= "Linux ELF64",
419 	.sv_coredump	= elf64_coredump,
420 	.sv_imgact_try	= linux_exec_imgact_try,
421 	.sv_minsigstksz	= LINUX_MINSIGSTKSZ,
422 	.sv_minuser	= VM_MIN_ADDRESS,
423 	.sv_maxuser	= VM_MAXUSER_ADDRESS,
424 	.sv_usrstack	= USRSTACK,
425 	.sv_psstrings	= PS_STRINGS, /* XXX */
426 	.sv_stackprot	= VM_PROT_READ | VM_PROT_WRITE,
427 	.sv_copyout_auxargs = linux_copyout_auxargs,
428 	.sv_copyout_strings = linux_copyout_strings,
429 	.sv_setregs	= linux_exec_setregs,
430 	.sv_fixlimit	= NULL,
431 	.sv_maxssiz	= NULL,
432 	.sv_flags	= SV_ABI_LINUX | SV_LP64 | SV_SHP,
433 	.sv_set_syscall_retval = linux_set_syscall_retval,
434 	.sv_fetch_syscall_args = linux_fetch_syscall_args,
435 	.sv_syscallnames = NULL,
436 	.sv_shared_page_base = SHAREDPAGE,
437 	.sv_shared_page_len = PAGE_SIZE,
438 	.sv_schedtail	= linux_schedtail,
439 	.sv_thread_detach = linux_thread_detach,
440 	.sv_trap	= linux_vsyscall,
441 	.sv_hwcap	= &elf_hwcap,
442 	.sv_hwcap2	= &elf_hwcap2,
443 	.sv_onexec	= linux_on_exec,
444 	.sv_onexit	= linux_on_exit,
445 	.sv_ontdexit	= linux_thread_dtor,
446 	.sv_setid_allowed = &linux_setid_allowed_query,
447 };
448 
449 static void
450 linux_vdso_install(const void *param)
451 {
452 
453 	linux_szsigcode = (&_binary_linux_locore_o_end -
454 	    &_binary_linux_locore_o_start);
455 
456 	if (linux_szsigcode > elf_linux_sysvec.sv_shared_page_len)
457 		panic("invalid Linux VDSO size\n");
458 
459 	__elfN(linux_vdso_fixup)(&elf_linux_sysvec);
460 
461 	linux_shared_page_obj = __elfN(linux_shared_page_init)
462 	    (&linux_shared_page_mapping);
463 
464 	__elfN(linux_vdso_reloc)(&elf_linux_sysvec);
465 
466 	memcpy(linux_shared_page_mapping, elf_linux_sysvec.sv_sigcode,
467 	    linux_szsigcode);
468 	elf_linux_sysvec.sv_shared_page_obj = linux_shared_page_obj;
469 
470 	linux_kplatform = linux_shared_page_mapping +
471 	    (linux_platform - (caddr_t)elf_linux_sysvec.sv_shared_page_base);
472 }
473 SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC, SI_ORDER_ANY,
474     linux_vdso_install, NULL);
475 
476 static void
477 linux_vdso_deinstall(const void *param)
478 {
479 
480 	LIN_SDT_PROBE0(sysvec, linux_vdso_deinstall, todo);
481 	__elfN(linux_shared_page_fini)(linux_shared_page_obj,
482 	    linux_shared_page_mapping);
483 }
484 SYSUNINIT(elf_linux_vdso_uninit, SI_SUB_EXEC, SI_ORDER_FIRST,
485     linux_vdso_deinstall, NULL);
486 
487 static char GNU_ABI_VENDOR[] = "GNU";
488 static int GNU_ABI_LINUX = 0;
489 
490 /* LINUXTODO: deduplicate */
491 static bool
492 linux_trans_osrel(const Elf_Note *note, int32_t *osrel)
493 {
494 	const Elf32_Word *desc;
495 	uintptr_t p;
496 
497 	p = (uintptr_t)(note + 1);
498 	p += roundup2(note->n_namesz, sizeof(Elf32_Addr));
499 
500 	desc = (const Elf32_Word *)p;
501 	if (desc[0] != GNU_ABI_LINUX)
502 		return (false);
503 
504 	*osrel = LINUX_KERNVER(desc[1], desc[2], desc[3]);
505 	return (true);
506 }
507 
508 static Elf_Brandnote linux64_brandnote = {
509 	.hdr.n_namesz	= sizeof(GNU_ABI_VENDOR),
510 	.hdr.n_descsz	= 16,
511 	.hdr.n_type	= 1,
512 	.vendor		= GNU_ABI_VENDOR,
513 	.flags		= BN_TRANSLATE_OSREL,
514 	.trans_osrel	= linux_trans_osrel
515 };
516 
517 static Elf64_Brandinfo linux_glibc2brand = {
518 	.brand		= ELFOSABI_LINUX,
519 	.machine	= EM_AARCH64,
520 	.compat_3_brand	= "Linux",
521 	.emul_path	= linux_emul_path,
522 	.interp_path	= "/lib64/ld-linux-x86-64.so.2",
523 	.sysvec		= &elf_linux_sysvec,
524 	.interp_newpath	= NULL,
525 	.brand_note	= &linux64_brandnote,
526 	.flags		= BI_CAN_EXEC_DYN | BI_BRAND_NOTE
527 };
528 
529 Elf64_Brandinfo *linux_brandlist[] = {
530 	&linux_glibc2brand,
531 	NULL
532 };
533 
534 static int
535 linux64_elf_modevent(module_t mod, int type, void *data)
536 {
537 	Elf64_Brandinfo **brandinfo;
538 	struct linux_ioctl_handler**lihp;
539 	int error;
540 
541 	error = 0;
542 	switch(type) {
543 	case MOD_LOAD:
544 		for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL;
545 		    ++brandinfo)
546 			if (elf64_insert_brand_entry(*brandinfo) < 0)
547 				error = EINVAL;
548 		if (error == 0) {
549 			SET_FOREACH(lihp, linux_ioctl_handler_set)
550 				linux_ioctl_register_handler(*lihp);
551 			stclohz = (stathz ? stathz : hz);
552 			if (bootverbose)
553 				printf("Linux arm64 ELF exec handler installed\n");
554 		}
555 		break;
556 	case MOD_UNLOAD:
557 		for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL;
558 		    ++brandinfo)
559 			if (elf64_brand_inuse(*brandinfo))
560 				error = EBUSY;
561 		if (error == 0) {
562 			for (brandinfo = &linux_brandlist[0];
563 			    *brandinfo != NULL; ++brandinfo)
564 				if (elf64_remove_brand_entry(*brandinfo) < 0)
565 					error = EINVAL;
566 		}
567 		if (error == 0) {
568 			SET_FOREACH(lihp, linux_ioctl_handler_set)
569 				linux_ioctl_unregister_handler(*lihp);
570 			if (bootverbose)
571 				printf("Linux ELF exec handler removed\n");
572 		} else
573 			printf("Could not deinstall ELF interpreter entry\n");
574 		break;
575 	default:
576 		return (EOPNOTSUPP);
577 	}
578 	return (error);
579 }
580 
581 static moduledata_t linux64_elf_mod = {
582 	"linux64elf",
583 	linux64_elf_modevent,
584 	0
585 };
586 
587 DECLARE_MODULE_TIED(linux64elf, linux64_elf_mod, SI_SUB_EXEC, SI_ORDER_ANY);
588 MODULE_DEPEND(linux64elf, linux_common, 1, 1, 1);
589 FEATURE(linux64, "AArch64 Linux 64bit support");
590