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