linux_sysvec.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. /*-
  2. * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
  3. *
  4. * Copyright (c) 1994-1996 Søren Schmidt
  5. * All rights reserved.
  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. #include <sys/cdefs.h>
  29. __FBSDID("$FreeBSD$");
  30. #include <sys/param.h>
  31. #include <sys/systm.h>
  32. #include <sys/exec.h>
  33. #include <sys/fcntl.h>
  34. #include <sys/imgact.h>
  35. #include <sys/imgact_aout.h>
  36. #include <sys/imgact_elf.h>
  37. #include <sys/kernel.h>
  38. #include <sys/lock.h>
  39. #include <sys/malloc.h>
  40. #include <sys/module.h>
  41. #include <sys/mutex.h>
  42. #include <sys/proc.h>
  43. #include <sys/signalvar.h>
  44. #include <sys/syscallsubr.h>
  45. #include <sys/sysctl.h>
  46. #include <sys/sysent.h>
  47. #include <sys/sysproto.h>
  48. #include <sys/vnode.h>
  49. #include <vm/vm.h>
  50. #include <vm/pmap.h>
  51. #include <vm/vm_extern.h>
  52. #include <vm/vm_map.h>
  53. #include <vm/vm_object.h>
  54. #include <vm/vm_page.h>
  55. #include <vm/vm_param.h>
  56. #include <machine/cpu.h>
  57. #include <machine/cputypes.h>
  58. #include <machine/md_var.h>
  59. #include <machine/pcb.h>
  60. #include <machine/trap.h>
  61. #include <i386/linux/linux.h>
  62. #include <i386/linux/linux_proto.h>
  63. #include <compat/linux/linux_emul.h>
  64. #include <compat/linux/linux_ioctl.h>
  65. #include <compat/linux/linux_mib.h>
  66. #include <compat/linux/linux_misc.h>
  67. #include <compat/linux/linux_signal.h>
  68. #include <compat/linux/linux_util.h>
  69. #include <compat/linux/linux_vdso.h>
  70. MODULE_VERSION(linux, 1);
  71. #define LINUX_PS_STRINGS (LINUX_USRSTACK - sizeof(struct ps_strings))
  72. static int linux_szsigcode;
  73. static vm_object_t linux_shared_page_obj;
  74. static char *linux_shared_page_mapping;
  75. extern char _binary_linux_locore_o_start;
  76. extern char _binary_linux_locore_o_end;
  77. extern struct sysent linux_sysent[LINUX_SYS_MAXSYSCALL];
  78. SET_DECLARE(linux_ioctl_handler_set, struct linux_ioctl_handler);
  79. static int linux_fixup(uintptr_t *stack_base,
  80. struct image_params *iparams);
  81. static int linux_fixup_elf(uintptr_t *stack_base,
  82. struct image_params *iparams);
  83. static void linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask);
  84. static void linux_exec_setregs(struct thread *td,
  85. struct image_params *imgp, uintptr_t stack);
  86. static int linux_copyout_strings(struct image_params *imgp,
  87. uintptr_t *stack_base);
  88. static bool linux_trans_osrel(const Elf_Note *note, int32_t *osrel);
  89. static void linux_vdso_install(void *param);
  90. static void linux_vdso_deinstall(void *param);
  91. static int linux_szplatform;
  92. const char *linux_kplatform;
  93. #define LINUX_T_UNKNOWN 255
  94. static int _bsd_to_linux_trapcode[] = {
  95. LINUX_T_UNKNOWN, /* 0 */
  96. 6, /* 1 T_PRIVINFLT */
  97. LINUX_T_UNKNOWN, /* 2 */
  98. 3, /* 3 T_BPTFLT */
  99. LINUX_T_UNKNOWN, /* 4 */
  100. LINUX_T_UNKNOWN, /* 5 */
  101. 16, /* 6 T_ARITHTRAP */
  102. 254, /* 7 T_ASTFLT */
  103. LINUX_T_UNKNOWN, /* 8 */
  104. 13, /* 9 T_PROTFLT */
  105. 1, /* 10 T_TRCTRAP */
  106. LINUX_T_UNKNOWN, /* 11 */
  107. 14, /* 12 T_PAGEFLT */
  108. LINUX_T_UNKNOWN, /* 13 */
  109. 17, /* 14 T_ALIGNFLT */
  110. LINUX_T_UNKNOWN, /* 15 */
  111. LINUX_T_UNKNOWN, /* 16 */
  112. LINUX_T_UNKNOWN, /* 17 */
  113. 0, /* 18 T_DIVIDE */
  114. 2, /* 19 T_NMI */
  115. 4, /* 20 T_OFLOW */
  116. 5, /* 21 T_BOUND */
  117. 7, /* 22 T_DNA */
  118. 8, /* 23 T_DOUBLEFLT */
  119. 9, /* 24 T_FPOPFLT */
  120. 10, /* 25 T_TSSFLT */
  121. 11, /* 26 T_SEGNPFLT */
  122. 12, /* 27 T_STKFLT */
  123. 18, /* 28 T_MCHK */
  124. 19, /* 29 T_XMMFLT */
  125. 15 /* 30 T_RESERVED */
  126. };
  127. #define bsd_to_linux_trapcode(code) \
  128. ((code)<nitems(_bsd_to_linux_trapcode)? \
  129. _bsd_to_linux_trapcode[(code)]: \
  130. LINUX_T_UNKNOWN)
  131. LINUX_VDSO_SYM_INTPTR(linux_sigcode);
  132. LINUX_VDSO_SYM_INTPTR(linux_rt_sigcode);
  133. LINUX_VDSO_SYM_INTPTR(linux_vsyscall);
  134. /*
  135. * If FreeBSD & Linux have a difference of opinion about what a trap
  136. * means, deal with it here.
  137. *
  138. * MPSAFE
  139. */
  140. static int
  141. linux_translate_traps(int signal, int trap_code)
  142. {
  143. if (signal != SIGBUS)
  144. return (signal);
  145. switch (trap_code) {
  146. case T_PROTFLT:
  147. case T_TSSFLT:
  148. case T_DOUBLEFLT:
  149. case T_PAGEFLT:
  150. return (SIGSEGV);
  151. default:
  152. return (signal);
  153. }
  154. }
  155. static int
  156. linux_fixup(uintptr_t *stack_base, struct image_params *imgp)
  157. {
  158. register_t *base, *argv, *envp;
  159. base = (register_t *)*stack_base;
  160. argv = base;
  161. envp = base + (imgp->args->argc + 1);
  162. base--;
  163. suword(base, (intptr_t)envp);
  164. base--;
  165. suword(base, (intptr_t)argv);
  166. base--;
  167. suword(base, imgp->args->argc);
  168. *stack_base = (uintptr_t)base;
  169. return (0);
  170. }
  171. static int
  172. linux_copyout_auxargs(struct image_params *imgp, uintptr_t base)
  173. {
  174. struct proc *p;
  175. Elf32_Auxargs *args;
  176. Elf32_Auxinfo *argarray, *pos;
  177. Elf32_Addr *uplatform;
  178. struct ps_strings *arginfo;
  179. int error, issetugid;
  180. p = imgp->proc;
  181. issetugid = imgp->proc->p_flag & P_SUGID ? 1 : 0;
  182. arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
  183. uplatform = (Elf32_Addr *)((caddr_t)arginfo - linux_szplatform);
  184. args = (Elf32_Auxargs *)imgp->auxargs;
  185. argarray = pos = malloc(LINUX_AT_COUNT * sizeof(*pos), M_TEMP,
  186. M_WAITOK | M_ZERO);
  187. AUXARGS_ENTRY(pos, LINUX_AT_SYSINFO_EHDR,
  188. imgp->proc->p_sysent->sv_shared_page_base);
  189. AUXARGS_ENTRY(pos, LINUX_AT_SYSINFO, linux_vsyscall);
  190. AUXARGS_ENTRY(pos, LINUX_AT_HWCAP, cpu_feature);
  191. /*
  192. * Do not export AT_CLKTCK when emulating Linux kernel prior to 2.4.0,
  193. * as it has appeared in the 2.4.0-rc7 first time.
  194. * Being exported, AT_CLKTCK is returned by sysconf(_SC_CLK_TCK),
  195. * glibc falls back to the hard-coded CLK_TCK value when aux entry
  196. * is not present.
  197. * Also see linux_times() implementation.
  198. */
  199. if (linux_kernver(curthread) >= LINUX_KERNVER_2004000)
  200. AUXARGS_ENTRY(pos, LINUX_AT_CLKTCK, stclohz);
  201. AUXARGS_ENTRY(pos, AT_PHDR, args->phdr);
  202. AUXARGS_ENTRY(pos, AT_PHENT, args->phent);
  203. AUXARGS_ENTRY(pos, AT_PHNUM, args->phnum);
  204. AUXARGS_ENTRY(pos, AT_PAGESZ, args->pagesz);
  205. AUXARGS_ENTRY(pos, AT_FLAGS, args->flags);
  206. AUXARGS_ENTRY(pos, AT_ENTRY, args->entry);
  207. AUXARGS_ENTRY(pos, AT_BASE, args->base);
  208. AUXARGS_ENTRY(pos, LINUX_AT_SECURE, issetugid);
  209. AUXARGS_ENTRY(pos, AT_UID, imgp->proc->p_ucred->cr_ruid);
  210. AUXARGS_ENTRY(pos, AT_EUID, imgp->proc->p_ucred->cr_svuid);
  211. AUXARGS_ENTRY(pos, AT_GID, imgp->proc->p_ucred->cr_rgid);
  212. AUXARGS_ENTRY(pos, AT_EGID, imgp->proc->p_ucred->cr_svgid);
  213. AUXARGS_ENTRY(pos, LINUX_AT_PLATFORM, PTROUT(uplatform));
  214. AUXARGS_ENTRY_PTR(pos, LINUX_AT_RANDOM, imgp->canary);
  215. if (imgp->execpathp != 0)
  216. AUXARGS_ENTRY_PTR(pos, LINUX_AT_EXECFN, imgp->execpathp);
  217. if (args->execfd != -1)
  218. AUXARGS_ENTRY(pos, AT_EXECFD, args->execfd);
  219. AUXARGS_ENTRY(pos, AT_NULL, 0);
  220. free(imgp->auxargs, M_TEMP);
  221. imgp->auxargs = NULL;
  222. KASSERT(pos - argarray <= LINUX_AT_COUNT, ("Too many auxargs"));
  223. error = copyout(argarray, (void *)base,
  224. sizeof(*argarray) * LINUX_AT_COUNT);
  225. free(argarray, M_TEMP);
  226. return (error);
  227. }
  228. static int
  229. linux_fixup_elf(uintptr_t *stack_base, struct image_params *imgp)
  230. {
  231. register_t *base;
  232. base = (register_t *)*stack_base;
  233. base--;
  234. if (suword(base, (register_t)imgp->args->argc) == -1)
  235. return (EFAULT);
  236. *stack_base = (uintptr_t)base;
  237. return (0);
  238. }
  239. /*
  240. * Copied from kern/kern_exec.c
  241. */
  242. static int
  243. linux_copyout_strings(struct image_params *imgp, uintptr_t *stack_base)
  244. {
  245. int argc, envc, error;
  246. char **vectp;
  247. char *stringp;
  248. uintptr_t destp, ustringp;
  249. struct ps_strings *arginfo;
  250. char canary[LINUX_AT_RANDOM_LEN];
  251. size_t execpath_len;
  252. struct proc *p;
  253. /* Calculate string base and vector table pointers. */
  254. p = imgp->proc;
  255. if (imgp->execpath != NULL && imgp->auxargs != NULL)
  256. execpath_len = strlen(imgp->execpath) + 1;
  257. else
  258. execpath_len = 0;
  259. arginfo = (struct ps_strings *)p->p_sysent->sv_psstrings;
  260. destp = (uintptr_t)arginfo;
  261. /* Install LINUX_PLATFORM. */
  262. destp -= linux_szplatform;
  263. destp = rounddown2(destp, sizeof(void *));
  264. error = copyout(linux_kplatform, (void *)destp, linux_szplatform);
  265. if (error != 0)
  266. return (error);
  267. if (execpath_len != 0) {
  268. destp -= execpath_len;
  269. destp = rounddown2(destp, sizeof(void *));
  270. imgp->execpathp = (void *)destp;
  271. error = copyout(imgp->execpath, imgp->execpathp, execpath_len);
  272. if (error != 0)
  273. return (error);
  274. }
  275. /* Prepare the canary for SSP. */
  276. arc4rand(canary, sizeof(canary), 0);
  277. destp -= roundup(sizeof(canary), sizeof(void *));
  278. imgp->canary = (void *)destp;
  279. error = copyout(canary, imgp->canary, sizeof(canary));
  280. if (error != 0)
  281. return (error);
  282. /* Allocate room for the argument and environment strings. */
  283. destp -= ARG_MAX - imgp->args->stringspace;
  284. destp = rounddown2(destp, sizeof(void *));
  285. ustringp = destp;
  286. if (imgp->auxargs) {
  287. /*
  288. * Allocate room on the stack for the ELF auxargs
  289. * array. It has LINUX_AT_COUNT entries.
  290. */
  291. destp -= LINUX_AT_COUNT * sizeof(Elf32_Auxinfo);
  292. destp = rounddown2(destp, sizeof(void *));
  293. }
  294. vectp = (char **)destp;
  295. /*
  296. * Allocate room for the argv[] and env vectors including the
  297. * terminating NULL pointers.
  298. */
  299. vectp -= imgp->args->argc + 1 + imgp->args->envc + 1;
  300. /* vectp also becomes our initial stack base. */
  301. *stack_base = (uintptr_t)vectp;
  302. stringp = imgp->args->begin_argv;
  303. argc = imgp->args->argc;
  304. envc = imgp->args->envc;
  305. /* Copy out strings - arguments and environment. */
  306. error = copyout(stringp, (void *)ustringp,
  307. ARG_MAX - imgp->args->stringspace);
  308. if (error != 0)
  309. return (error);
  310. /* Fill in "ps_strings" struct for ps, w, etc. */
  311. if (suword(&arginfo->ps_argvstr, (long)(intptr_t)vectp) != 0 ||
  312. suword(&arginfo->ps_nargvstr, argc) != 0)
  313. return (EFAULT);
  314. /* Fill in argument portion of vector table. */
  315. for (; argc > 0; --argc) {
  316. if (suword(vectp++, ustringp) != 0)
  317. return (EFAULT);
  318. while (*stringp++ != 0)
  319. ustringp++;
  320. ustringp++;
  321. }
  322. /* A null vector table pointer separates the argp's from the envp's. */
  323. if (suword(vectp++, 0) != 0)
  324. return (EFAULT);
  325. if (suword(&arginfo->ps_envstr, (long)(intptr_t)vectp) != 0 ||
  326. suword(&arginfo->ps_nenvstr, envc) != 0)
  327. return (EFAULT);
  328. /* Fill in environment portion of vector table. */
  329. for (; envc > 0; --envc) {
  330. if (suword(vectp++, ustringp) != 0)
  331. return (EFAULT);
  332. while (*stringp++ != 0)
  333. ustringp++;
  334. ustringp++;
  335. }
  336. /* The end of the vector table is a null pointer. */
  337. if (suword(vectp, 0) != 0)
  338. return (EFAULT);
  339. if (imgp->auxargs) {
  340. vectp++;
  341. error = imgp->sysent->sv_copyout_auxargs(imgp,
  342. (uintptr_t)vectp);
  343. if (error != 0)
  344. return (error);
  345. }
  346. return (0);
  347. }
  348. static void
  349. linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
  350. {
  351. struct thread *td = curthread;
  352. struct proc *p = td->td_proc;
  353. struct sigacts *psp;
  354. struct trapframe *regs;
  355. struct l_rt_sigframe *fp, frame;
  356. int sig, code;
  357. int oonstack;
  358. sig = ksi->ksi_signo;
  359. code = ksi->ksi_code;
  360. PROC_LOCK_ASSERT(p, MA_OWNED);
  361. psp = p->p_sigacts;
  362. mtx_assert(&psp->ps_mtx, MA_OWNED);
  363. regs = td->td_frame;
  364. oonstack = sigonstack(regs->tf_esp);
  365. /* Allocate space for the signal handler context. */
  366. if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
  367. SIGISMEMBER(psp->ps_sigonstack, sig)) {
  368. fp = (struct l_rt_sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
  369. td->td_sigstk.ss_size - sizeof(struct l_rt_sigframe));
  370. } else
  371. fp = (struct l_rt_sigframe *)regs->tf_esp - 1;
  372. mtx_unlock(&psp->ps_mtx);
  373. /* Build the argument list for the signal handler. */
  374. sig = bsd_to_linux_signal(sig);
  375. bzero(&frame, sizeof(frame));
  376. frame.sf_handler = catcher;
  377. frame.sf_sig = sig;
  378. frame.sf_siginfo = &fp->sf_si;
  379. frame.sf_ucontext = &fp->sf_sc;
  380. /* Fill in POSIX parts. */
  381. ksiginfo_to_lsiginfo(ksi, &frame.sf_si, sig);
  382. /* Build the signal context to be used by sigreturn. */
  383. frame.sf_sc.uc_flags = 0; /* XXX ??? */
  384. frame.sf_sc.uc_link = NULL; /* XXX ??? */
  385. frame.sf_sc.uc_stack.ss_sp = td->td_sigstk.ss_sp;
  386. frame.sf_sc.uc_stack.ss_size = td->td_sigstk.ss_size;
  387. frame.sf_sc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
  388. ? ((oonstack) ? LINUX_SS_ONSTACK : 0) : LINUX_SS_DISABLE;
  389. PROC_UNLOCK(p);
  390. bsd_to_linux_sigset(mask, &frame.sf_sc.uc_sigmask);
  391. frame.sf_sc.uc_mcontext.sc_mask = frame.sf_sc.uc_sigmask.__mask;
  392. frame.sf_sc.uc_mcontext.sc_gs = rgs();
  393. frame.sf_sc.uc_mcontext.sc_fs = regs->tf_fs;
  394. frame.sf_sc.uc_mcontext.sc_es = regs->tf_es;
  395. frame.sf_sc.uc_mcontext.sc_ds = regs->tf_ds;
  396. frame.sf_sc.uc_mcontext.sc_edi = regs->tf_edi;
  397. frame.sf_sc.uc_mcontext.sc_esi = regs->tf_esi;
  398. frame.sf_sc.uc_mcontext.sc_ebp = regs->tf_ebp;
  399. frame.sf_sc.uc_mcontext.sc_ebx = regs->tf_ebx;
  400. frame.sf_sc.uc_mcontext.sc_esp = regs->tf_esp;
  401. frame.sf_sc.uc_mcontext.sc_edx = regs->tf_edx;
  402. frame.sf_sc.uc_mcontext.sc_ecx = regs->tf_ecx;
  403. frame.sf_sc.uc_mcontext.sc_eax = regs->tf_eax;
  404. frame.sf_sc.uc_mcontext.sc_eip = regs->tf_eip;
  405. frame.sf_sc.uc_mcontext.sc_cs = regs->tf_cs;
  406. frame.sf_sc.uc_mcontext.sc_eflags = regs->tf_eflags;
  407. frame.sf_sc.uc_mcontext.sc_esp_at_signal = regs->tf_esp;
  408. frame.sf_sc.uc_mcontext.sc_ss = regs->tf_ss;
  409. frame.sf_sc.uc_mcontext.sc_err = regs->tf_err;
  410. frame.sf_sc.uc_mcontext.sc_cr2 = (register_t)ksi->ksi_addr;
  411. frame.sf_sc.uc_mcontext.sc_trapno = bsd_to_linux_trapcode(code);
  412. if (copyout(&frame, fp, sizeof(frame)) != 0) {
  413. /*
  414. * Process has trashed its stack; give it an illegal
  415. * instruction to halt it in its tracks.
  416. */
  417. PROC_LOCK(p);
  418. sigexit(td, SIGILL);
  419. }
  420. /* Build context to run handler in. */
  421. regs->tf_esp = (int)fp;
  422. regs->tf_eip = linux_rt_sigcode;
  423. regs->tf_eflags &= ~(PSL_T | PSL_VM | PSL_D);
  424. regs->tf_cs = _ucodesel;
  425. regs->tf_ds = _udatasel;
  426. regs->tf_es = _udatasel;
  427. regs->tf_fs = _udatasel;
  428. regs->tf_ss = _udatasel;
  429. PROC_LOCK(p);
  430. mtx_lock(&psp->ps_mtx);
  431. }
  432. /*
  433. * Send an interrupt to process.
  434. *
  435. * Stack is set up to allow sigcode stored
  436. * in u. to call routine, followed by kcall
  437. * to sigreturn routine below. After sigreturn
  438. * resets the signal mask, the stack, and the
  439. * frame pointer, it returns to the user
  440. * specified pc, psl.
  441. */
  442. static void
  443. linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
  444. {
  445. struct thread *td = curthread;
  446. struct proc *p = td->td_proc;
  447. struct sigacts *psp;
  448. struct trapframe *regs;
  449. struct l_sigframe *fp, frame;
  450. l_sigset_t lmask;
  451. int sig, code;
  452. int oonstack;
  453. PROC_LOCK_ASSERT(p, MA_OWNED);
  454. psp = p->p_sigacts;
  455. sig = ksi->ksi_signo;
  456. code = ksi->ksi_code;
  457. mtx_assert(&psp->ps_mtx, MA_OWNED);
  458. if (SIGISMEMBER(psp->ps_siginfo, sig)) {
  459. /* Signal handler installed with SA_SIGINFO. */
  460. linux_rt_sendsig(catcher, ksi, mask);
  461. return;
  462. }
  463. regs = td->td_frame;
  464. oonstack = sigonstack(regs->tf_esp);
  465. /* Allocate space for the signal handler context. */
  466. if ((td->td_pflags & TDP_ALTSTACK) && !oonstack &&
  467. SIGISMEMBER(psp->ps_sigonstack, sig)) {
  468. fp = (struct l_sigframe *)((uintptr_t)td->td_sigstk.ss_sp +
  469. td->td_sigstk.ss_size - sizeof(struct l_sigframe));
  470. } else
  471. fp = (struct l_sigframe *)regs->tf_esp - 1;
  472. mtx_unlock(&psp->ps_mtx);
  473. PROC_UNLOCK(p);
  474. /* Build the argument list for the signal handler. */
  475. sig = bsd_to_linux_signal(sig);
  476. bzero(&frame, sizeof(frame));
  477. frame.sf_handler = catcher;
  478. frame.sf_sig = sig;
  479. bsd_to_linux_sigset(mask, &lmask);
  480. /* Build the signal context to be used by sigreturn. */
  481. frame.sf_sc.sc_mask = lmask.__mask;
  482. frame.sf_sc.sc_gs = rgs();
  483. frame.sf_sc.sc_fs = regs->tf_fs;
  484. frame.sf_sc.sc_es = regs->tf_es;
  485. frame.sf_sc.sc_ds = regs->tf_ds;
  486. frame.sf_sc.sc_edi = regs->tf_edi;
  487. frame.sf_sc.sc_esi = regs->tf_esi;
  488. frame.sf_sc.sc_ebp = regs->tf_ebp;
  489. frame.sf_sc.sc_ebx = regs->tf_ebx;
  490. frame.sf_sc.sc_esp = regs->tf_esp;
  491. frame.sf_sc.sc_edx = regs->tf_edx;
  492. frame.sf_sc.sc_ecx = regs->tf_ecx;
  493. frame.sf_sc.sc_eax = regs->tf_eax;
  494. frame.sf_sc.sc_eip = regs->tf_eip;
  495. frame.sf_sc.sc_cs = regs->tf_cs;
  496. frame.sf_sc.sc_eflags = regs->tf_eflags;
  497. frame.sf_sc.sc_esp_at_signal = regs->tf_esp;
  498. frame.sf_sc.sc_ss = regs->tf_ss;
  499. frame.sf_sc.sc_err = regs->tf_err;
  500. frame.sf_sc.sc_cr2 = (register_t)ksi->ksi_addr;
  501. frame.sf_sc.sc_trapno = bsd_to_linux_trapcode(ksi->ksi_trapno);
  502. frame.sf_extramask[0] = lmask.__mask;
  503. if (copyout(&frame, fp, sizeof(frame)) != 0) {
  504. /*
  505. * Process has trashed its stack; give it an illegal
  506. * instruction to halt it in its tracks.
  507. */
  508. PROC_LOCK(p);
  509. sigexit(td, SIGILL);
  510. }
  511. /* Build context to run handler in. */
  512. regs->tf_esp = (int)fp;
  513. regs->tf_eip = linux_sigcode;
  514. regs->tf_eflags &= ~(PSL_T | PSL_VM | PSL_D);
  515. regs->tf_cs = _ucodesel;
  516. regs->tf_ds = _udatasel;
  517. regs->tf_es = _udatasel;
  518. regs->tf_fs = _udatasel;
  519. regs->tf_ss = _udatasel;
  520. PROC_LOCK(p);
  521. mtx_lock(&psp->ps_mtx);
  522. }
  523. /*
  524. * System call to cleanup state after a signal
  525. * has been taken. Reset signal mask and
  526. * stack state from context left by sendsig (above).
  527. * Return to previous pc and psl as specified by
  528. * context left by sendsig. Check carefully to
  529. * make sure that the user has not modified the
  530. * psl to gain improper privileges or to cause
  531. * a machine fault.
  532. */
  533. int
  534. linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
  535. {
  536. struct l_sigframe frame;
  537. struct trapframe *regs;
  538. l_sigset_t lmask;
  539. sigset_t bmask;
  540. int eflags;
  541. ksiginfo_t ksi;
  542. regs = td->td_frame;
  543. /*
  544. * The trampoline code hands us the sigframe.
  545. * It is unsafe to keep track of it ourselves, in the event that a
  546. * program jumps out of a signal handler.
  547. */
  548. if (copyin(args->sfp, &frame, sizeof(frame)) != 0)
  549. return (EFAULT);
  550. /* Check for security violations. */
  551. #define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0)
  552. eflags = frame.sf_sc.sc_eflags;
  553. if (!EFLAGS_SECURE(eflags, regs->tf_eflags))
  554. return (EINVAL);
  555. /*
  556. * Don't allow users to load a valid privileged %cs. Let the
  557. * hardware check for invalid selectors, excess privilege in
  558. * other selectors, invalid %eip's and invalid %esp's.
  559. */
  560. #define CS_SECURE(cs) (ISPL(cs) == SEL_UPL)
  561. if (!CS_SECURE(frame.sf_sc.sc_cs)) {
  562. ksiginfo_init_trap(&ksi);
  563. ksi.ksi_signo = SIGBUS;
  564. ksi.ksi_code = BUS_OBJERR;
  565. ksi.ksi_trapno = T_PROTFLT;
  566. ksi.ksi_addr = (void *)regs->tf_eip;
  567. trapsignal(td, &ksi);
  568. return (EINVAL);
  569. }
  570. lmask.__mask = frame.sf_sc.sc_mask;
  571. linux_to_bsd_sigset(&lmask, &bmask);
  572. kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0);
  573. /* Restore signal context. */
  574. /* %gs was restored by the trampoline. */
  575. regs->tf_fs = frame.sf_sc.sc_fs;
  576. regs->tf_es = frame.sf_sc.sc_es;
  577. regs->tf_ds = frame.sf_sc.sc_ds;
  578. regs->tf_edi = frame.sf_sc.sc_edi;
  579. regs->tf_esi = frame.sf_sc.sc_esi;
  580. regs->tf_ebp = frame.sf_sc.sc_ebp;
  581. regs->tf_ebx = frame.sf_sc.sc_ebx;
  582. regs->tf_edx = frame.sf_sc.sc_edx;
  583. regs->tf_ecx = frame.sf_sc.sc_ecx;
  584. regs->tf_eax = frame.sf_sc.sc_eax;
  585. regs->tf_eip = frame.sf_sc.sc_eip;
  586. regs->tf_cs = frame.sf_sc.sc_cs;
  587. regs->tf_eflags = eflags;
  588. regs->tf_esp = frame.sf_sc.sc_esp_at_signal;
  589. regs->tf_ss = frame.sf_sc.sc_ss;
  590. return (EJUSTRETURN);
  591. }
  592. /*
  593. * System call to cleanup state after a signal
  594. * has been taken. Reset signal mask and
  595. * stack state from context left by rt_sendsig (above).
  596. * Return to previous pc and psl as specified by
  597. * context left by sendsig. Check carefully to
  598. * make sure that the user has not modified the
  599. * psl to gain improper privileges or to cause
  600. * a machine fault.
  601. */
  602. int
  603. linux_rt_sigreturn(struct thread *td, struct linux_rt_sigreturn_args *args)
  604. {
  605. struct l_ucontext uc;
  606. struct l_sigcontext *context;
  607. sigset_t bmask;
  608. l_stack_t *lss;
  609. stack_t ss;
  610. struct trapframe *regs;
  611. int eflags;
  612. ksiginfo_t ksi;
  613. regs = td->td_frame;
  614. /*
  615. * The trampoline code hands us the ucontext.
  616. * It is unsafe to keep track of it ourselves, in the event that a
  617. * program jumps out of a signal handler.
  618. */
  619. if (copyin(args->ucp, &uc, sizeof(uc)) != 0)
  620. return (EFAULT);
  621. context = &uc.uc_mcontext;
  622. /* Check for security violations. */
  623. #define EFLAGS_SECURE(ef, oef) ((((ef) ^ (oef)) & ~PSL_USERCHANGE) == 0)
  624. eflags = context->sc_eflags;
  625. if (!EFLAGS_SECURE(eflags, regs->tf_eflags))
  626. return (EINVAL);
  627. /*
  628. * Don't allow users to load a valid privileged %cs. Let the
  629. * hardware check for invalid selectors, excess privilege in
  630. * other selectors, invalid %eip's and invalid %esp's.
  631. */
  632. #define CS_SECURE(cs) (ISPL(cs) == SEL_UPL)
  633. if (!CS_SECURE(context->sc_cs)) {
  634. ksiginfo_init_trap(&ksi);
  635. ksi.ksi_signo = SIGBUS;
  636. ksi.ksi_code = BUS_OBJERR;
  637. ksi.ksi_trapno = T_PROTFLT;
  638. ksi.ksi_addr = (void *)regs->tf_eip;
  639. trapsignal(td, &ksi);
  640. return (EINVAL);
  641. }
  642. linux_to_bsd_sigset(&uc.uc_sigmask, &bmask);
  643. kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0);
  644. /* Restore signal context. */
  645. /* %gs was restored by the trampoline. */
  646. regs->tf_fs = context->sc_fs;
  647. regs->tf_es = context->sc_es;
  648. regs->tf_ds = context->sc_ds;
  649. regs->tf_edi = context->sc_edi;
  650. regs->tf_esi = context->sc_esi;
  651. regs->tf_ebp = context->sc_ebp;
  652. regs->tf_ebx = context->sc_ebx;
  653. regs->tf_edx = context->sc_edx;
  654. regs->tf_ecx = context->sc_ecx;
  655. regs->tf_eax = context->sc_eax;
  656. regs->tf_eip = context->sc_eip;
  657. regs->tf_cs = context->sc_cs;
  658. regs->tf_eflags = eflags;
  659. regs->tf_esp = context->sc_esp_at_signal;
  660. regs->tf_ss = context->sc_ss;
  661. /* Call sigaltstack & ignore results. */
  662. lss = &uc.uc_stack;
  663. ss.ss_sp = lss->ss_sp;
  664. ss.ss_size = lss->ss_size;
  665. ss.ss_flags = linux_to_bsd_sigaltstack(lss->ss_flags);
  666. (void)kern_sigaltstack(td, &ss, NULL);
  667. return (EJUSTRETURN);
  668. }
  669. static int
  670. linux_fetch_syscall_args(struct thread *td)
  671. {
  672. struct proc *p;
  673. struct trapframe *frame;
  674. struct syscall_args *sa;
  675. p = td->td_proc;
  676. frame = td->td_frame;
  677. sa = &td->td_sa;
  678. sa->code = frame->tf_eax;
  679. sa->args[0] = frame->tf_ebx;
  680. sa->args[1] = frame->tf_ecx;
  681. sa->args[2] = frame->tf_edx;
  682. sa->args[3] = frame->tf_esi;
  683. sa->args[4] = frame->tf_edi;
  684. sa->args[5] = frame->tf_ebp; /* Unconfirmed */
  685. if (sa->code >= p->p_sysent->sv_size)
  686. /* nosys */
  687. sa->callp = &p->p_sysent->sv_table[p->p_sysent->sv_size - 1];
  688. else
  689. sa->callp = &p->p_sysent->sv_table[sa->code];
  690. td->td_retval[0] = 0;
  691. td->td_retval[1] = frame->tf_edx;
  692. return (0);
  693. }
  694. static void
  695. linux_set_syscall_retval(struct thread *td, int error)
  696. {
  697. struct trapframe *frame = td->td_frame;
  698. cpu_set_syscall_retval(td, error);
  699. if (__predict_false(error != 0)) {
  700. if (error != ERESTART && error != EJUSTRETURN)
  701. frame->tf_eax = bsd_to_linux_errno(error);
  702. }
  703. }
  704. /*
  705. * exec_setregs may initialize some registers differently than Linux
  706. * does, thus potentially confusing Linux binaries. If necessary, we
  707. * override the exec_setregs default(s) here.
  708. */
  709. static void
  710. linux_exec_setregs(struct thread *td, struct image_params *imgp,
  711. uintptr_t stack)
  712. {
  713. struct pcb *pcb = td->td_pcb;
  714. exec_setregs(td, imgp, stack);
  715. /* Linux sets %gs to 0, we default to _udatasel. */
  716. pcb->pcb_gs = 0;
  717. load_gs(0);
  718. pcb->pcb_initial_npxcw = __LINUX_NPXCW__;
  719. }
  720. static void
  721. linux_get_machine(const char **dst)
  722. {
  723. switch (cpu_class) {
  724. case CPUCLASS_686:
  725. *dst = "i686";
  726. break;
  727. case CPUCLASS_586:
  728. *dst = "i586";
  729. break;
  730. case CPUCLASS_486:
  731. *dst = "i486";
  732. break;
  733. default:
  734. *dst = "i386";
  735. }
  736. }
  737. struct sysentvec linux_sysvec = {
  738. .sv_size = LINUX_SYS_MAXSYSCALL,
  739. .sv_table = linux_sysent,
  740. .sv_transtrap = linux_translate_traps,
  741. .sv_fixup = linux_fixup,
  742. .sv_sendsig = linux_sendsig,
  743. .sv_sigcode = &_binary_linux_locore_o_start,
  744. .sv_szsigcode = &linux_szsigcode,
  745. .sv_name = "Linux a.out",
  746. .sv_coredump = NULL,
  747. .sv_imgact_try = linux_exec_imgact_try,
  748. .sv_minsigstksz = LINUX_MINSIGSTKSZ,
  749. .sv_minuser = VM_MIN_ADDRESS,
  750. .sv_maxuser = VM_MAXUSER_ADDRESS,
  751. .sv_usrstack = LINUX_USRSTACK,
  752. .sv_psstrings = PS_STRINGS,
  753. .sv_stackprot = VM_PROT_ALL,
  754. .sv_copyout_strings = exec_copyout_strings,
  755. .sv_setregs = linux_exec_setregs,
  756. .sv_fixlimit = NULL,
  757. .sv_maxssiz = NULL,
  758. .sv_flags = SV_ABI_LINUX | SV_AOUT | SV_IA32 | SV_ILP32,
  759. .sv_set_syscall_retval = linux_set_syscall_retval,
  760. .sv_fetch_syscall_args = linux_fetch_syscall_args,
  761. .sv_syscallnames = NULL,
  762. .sv_shared_page_base = LINUX_SHAREDPAGE,
  763. .sv_shared_page_len = PAGE_SIZE,
  764. .sv_schedtail = linux_schedtail,
  765. .sv_thread_detach = linux_thread_detach,
  766. .sv_trap = NULL,
  767. .sv_onexec = linux_on_exec,
  768. .sv_onexit = linux_on_exit,
  769. .sv_ontdexit = linux_thread_dtor,
  770. };
  771. INIT_SYSENTVEC(aout_sysvec, &linux_sysvec);
  772. struct sysentvec elf_linux_sysvec = {
  773. .sv_size = LINUX_SYS_MAXSYSCALL,
  774. .sv_table = linux_sysent,
  775. .sv_transtrap = linux_translate_traps,
  776. .sv_fixup = linux_fixup_elf,
  777. .sv_sendsig = linux_sendsig,
  778. .sv_sigcode = &_binary_linux_locore_o_start,
  779. .sv_szsigcode = &linux_szsigcode,
  780. .sv_name = "Linux ELF32",
  781. .sv_coredump = elf32_coredump,
  782. .sv_imgact_try = linux_exec_imgact_try,
  783. .sv_minsigstksz = LINUX_MINSIGSTKSZ,
  784. .sv_minuser = VM_MIN_ADDRESS,
  785. .sv_maxuser = VM_MAXUSER_ADDRESS,
  786. .sv_usrstack = LINUX_USRSTACK,
  787. .sv_psstrings = LINUX_PS_STRINGS,
  788. .sv_stackprot = VM_PROT_ALL,
  789. .sv_copyout_auxargs = linux_copyout_auxargs,
  790. .sv_copyout_strings = linux_copyout_strings,
  791. .sv_setregs = linux_exec_setregs,
  792. .sv_fixlimit = NULL,
  793. .sv_maxssiz = NULL,
  794. .sv_flags = SV_ABI_LINUX | SV_IA32 | SV_ILP32 | SV_SHP,
  795. .sv_set_syscall_retval = linux_set_syscall_retval,
  796. .sv_fetch_syscall_args = linux_fetch_syscall_args,
  797. .sv_syscallnames = NULL,
  798. .sv_shared_page_base = LINUX_SHAREDPAGE,
  799. .sv_shared_page_len = PAGE_SIZE,
  800. .sv_schedtail = linux_schedtail,
  801. .sv_thread_detach = linux_thread_detach,
  802. .sv_trap = NULL,
  803. .sv_onexec = linux_on_exec,
  804. .sv_onexit = linux_on_exit,
  805. .sv_ontdexit = linux_thread_dtor,
  806. };
  807. static void
  808. linux_vdso_install(void *param)
  809. {
  810. linux_szsigcode = (&_binary_linux_locore_o_end -
  811. &_binary_linux_locore_o_start);
  812. if (linux_szsigcode > elf_linux_sysvec.sv_shared_page_len)
  813. panic("Linux invalid vdso size\n");
  814. __elfN(linux_vdso_fixup)(&elf_linux_sysvec);
  815. linux_shared_page_obj = __elfN(linux_shared_page_init)
  816. (&linux_shared_page_mapping);
  817. __elfN(linux_vdso_reloc)(&elf_linux_sysvec);
  818. bcopy(elf_linux_sysvec.sv_sigcode, linux_shared_page_mapping,
  819. linux_szsigcode);
  820. elf_linux_sysvec.sv_shared_page_obj = linux_shared_page_obj;
  821. }
  822. SYSINIT(elf_linux_vdso_init, SI_SUB_EXEC, SI_ORDER_ANY,
  823. linux_vdso_install, NULL);
  824. static void
  825. linux_vdso_deinstall(void *param)
  826. {
  827. __elfN(linux_shared_page_fini)(linux_shared_page_obj);
  828. }
  829. SYSUNINIT(elf_linux_vdso_uninit, SI_SUB_EXEC, SI_ORDER_FIRST,
  830. linux_vdso_deinstall, NULL);
  831. static char GNU_ABI_VENDOR[] = "GNU";
  832. static int GNULINUX_ABI_DESC = 0;
  833. static bool
  834. linux_trans_osrel(const Elf_Note *note, int32_t *osrel)
  835. {
  836. const Elf32_Word *desc;
  837. uintptr_t p;
  838. p = (uintptr_t)(note + 1);
  839. p += roundup2(note->n_namesz, sizeof(Elf32_Addr));
  840. desc = (const Elf32_Word *)p;
  841. if (desc[0] != GNULINUX_ABI_DESC)
  842. return (false);
  843. /*
  844. * For Linux we encode osrel using the Linux convention of
  845. * (version << 16) | (major << 8) | (minor)
  846. * See macro in linux_mib.h
  847. */
  848. *osrel = LINUX_KERNVER(desc[1], desc[2], desc[3]);
  849. return (true);
  850. }
  851. static Elf_Brandnote linux_brandnote = {
  852. .hdr.n_namesz = sizeof(GNU_ABI_VENDOR),
  853. .hdr.n_descsz = 16, /* XXX at least 16 */
  854. .hdr.n_type = 1,
  855. .vendor = GNU_ABI_VENDOR,
  856. .flags = BN_TRANSLATE_OSREL,
  857. .trans_osrel = linux_trans_osrel
  858. };
  859. static Elf32_Brandinfo linux_brand = {
  860. .brand = ELFOSABI_LINUX,
  861. .machine = EM_386,
  862. .compat_3_brand = "Linux",
  863. .emul_path = linux_emul_path,
  864. .interp_path = "/lib/ld-linux.so.1",
  865. .sysvec = &elf_linux_sysvec,
  866. .interp_newpath = NULL,
  867. .brand_note = &linux_brandnote,
  868. .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
  869. };
  870. static Elf32_Brandinfo linux_glibc2brand = {
  871. .brand = ELFOSABI_LINUX,
  872. .machine = EM_386,
  873. .compat_3_brand = "Linux",
  874. .emul_path = linux_emul_path,
  875. .interp_path = "/lib/ld-linux.so.2",
  876. .sysvec = &elf_linux_sysvec,
  877. .interp_newpath = NULL,
  878. .brand_note = &linux_brandnote,
  879. .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
  880. };
  881. static Elf32_Brandinfo linux_muslbrand = {
  882. .brand = ELFOSABI_LINUX,
  883. .machine = EM_386,
  884. .compat_3_brand = "Linux",
  885. .emul_path = linux_emul_path,
  886. .interp_path = "/lib/ld-musl-i386.so.1",
  887. .sysvec = &elf_linux_sysvec,
  888. .interp_newpath = NULL,
  889. .brand_note = &linux_brandnote,
  890. .flags = BI_CAN_EXEC_DYN | BI_BRAND_NOTE
  891. };
  892. Elf32_Brandinfo *linux_brandlist[] = {
  893. &linux_brand,
  894. &linux_glibc2brand,
  895. &linux_muslbrand,
  896. NULL
  897. };
  898. static int
  899. linux_elf_modevent(module_t mod, int type, void *data)
  900. {
  901. Elf32_Brandinfo **brandinfo;
  902. int error;
  903. struct linux_ioctl_handler **lihp;
  904. error = 0;
  905. switch(type) {
  906. case MOD_LOAD:
  907. for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL;
  908. ++brandinfo)
  909. if (elf32_insert_brand_entry(*brandinfo) < 0)
  910. error = EINVAL;
  911. if (error == 0) {
  912. SET_FOREACH(lihp, linux_ioctl_handler_set)
  913. linux_ioctl_register_handler(*lihp);
  914. LIST_INIT(&futex_list);
  915. mtx_init(&futex_mtx, "ftllk", NULL, MTX_DEF);
  916. linux_get_machine(&linux_kplatform);
  917. linux_szplatform = roundup(strlen(linux_kplatform) + 1,
  918. sizeof(char *));
  919. linux_dev_shm_create();
  920. linux_osd_jail_register();
  921. stclohz = (stathz ? stathz : hz);
  922. if (bootverbose)
  923. printf("Linux ELF exec handler installed\n");
  924. } else
  925. printf("cannot insert Linux ELF brand handler\n");
  926. break;
  927. case MOD_UNLOAD:
  928. for (brandinfo = &linux_brandlist[0]; *brandinfo != NULL;
  929. ++brandinfo)
  930. if (elf32_brand_inuse(*brandinfo))
  931. error = EBUSY;
  932. if (error == 0) {
  933. for (brandinfo = &linux_brandlist[0];
  934. *brandinfo != NULL; ++brandinfo)
  935. if (elf32_remove_brand_entry(*brandinfo) < 0)
  936. error = EINVAL;
  937. }
  938. if (error == 0) {
  939. SET_FOREACH(lihp, linux_ioctl_handler_set)
  940. linux_ioctl_unregister_handler(*lihp);
  941. mtx_destroy(&futex_mtx);
  942. linux_dev_shm_destroy();
  943. linux_osd_jail_deregister();
  944. if (bootverbose)
  945. printf("Linux ELF exec handler removed\n");
  946. } else
  947. printf("Could not deinstall ELF interpreter entry\n");
  948. break;
  949. default:
  950. return (EOPNOTSUPP);
  951. }
  952. return (error);
  953. }
  954. static moduledata_t linux_elf_mod = {
  955. "linuxelf",
  956. linux_elf_modevent,
  957. 0
  958. };
  959. DECLARE_MODULE_TIED(linuxelf, linux_elf_mod, SI_SUB_EXEC, SI_ORDER_ANY);
  960. FEATURE(linux, "Linux 32bit support");