2 * Copyright (c) 1993, David Greenman
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/sys/kern/kern_exec.c,v 1.107.2.15 2002/07/30 15:40:46 nectar Exp $
27 * $DragonFly: src/sys/kern/kern_exec.c,v 1.25 2004/04/24 04:32:03 drhodus Exp $
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/sysproto.h>
33 #include <sys/kernel.h>
34 #include <sys/mount.h>
35 #include <sys/filedesc.h>
36 #include <sys/fcntl.h>
39 #include <sys/imgact.h>
40 #include <sys/imgact_elf.h>
41 #include <sys/kern_syscall.h>
43 #include <sys/malloc.h>
45 #include <sys/signalvar.h>
46 #include <sys/pioctl.h>
47 #include <sys/namei.h>
48 #include <sys/sfbuf.h>
49 #include <sys/sysent.h>
51 #include <sys/sysctl.h>
52 #include <sys/vnode.h>
53 #include <sys/vmmeter.h>
57 #include <vm/vm_param.h>
60 #include <vm/vm_page.h>
61 #include <vm/vm_map.h>
62 #include <vm/vm_kern.h>
63 #include <vm/vm_extern.h>
64 #include <vm/vm_object.h>
65 #include <vm/vm_pager.h>
68 #include <machine/reg.h>
70 MALLOC_DEFINE(M_PARGS, "proc-args", "Process arguments");
72 static register_t *exec_copyout_strings (struct image_params *);
74 /* XXX This should be vm_size_t. */
75 static u_long ps_strings = PS_STRINGS;
76 SYSCTL_ULONG(_kern, KERN_PS_STRINGS, ps_strings, CTLFLAG_RD, &ps_strings, 0, "");
78 /* XXX This should be vm_size_t. */
79 static u_long usrstack = USRSTACK;
80 SYSCTL_ULONG(_kern, KERN_USRSTACK, usrstack, CTLFLAG_RD, &usrstack, 0, "");
82 u_long ps_arg_cache_limit = PAGE_SIZE / 16;
83 SYSCTL_LONG(_kern, OID_AUTO, ps_arg_cache_limit, CTLFLAG_RW,
84 &ps_arg_cache_limit, 0, "");
87 SYSCTL_INT(_kern, OID_AUTO, ps_argsopen, CTLFLAG_RW, &ps_argsopen, 0, "");
89 void print_execve_args(struct image_args *args);
90 int debug_execve_args = 0;
91 SYSCTL_INT(_kern, OID_AUTO, debug_execve_args, CTLFLAG_RW, &debug_execve_args,
95 print_execve_args(struct image_args *args)
100 cp = args->begin_argv;
101 for (ndx = 0; ndx < args->argc; ndx++) {
102 printf("\targv[%d]: %s\n", ndx, cp);
103 while (*cp++ != '\0');
105 for (ndx = 0; ndx < args->envc; ndx++) {
106 printf("\tenvv[%d]: %s\n", ndx, cp);
107 while (*cp++ != '\0');
112 * Each of the items is a pointer to a `const struct execsw', hence the
113 * double pointer here.
115 static const struct execsw **execsw;
118 kern_execve(struct nameidata *ndp, struct image_args *args)
120 struct thread *td = curthread;
121 struct proc *p = td->td_proc;
122 register_t *stack_base;
124 struct image_params image_params, *imgp;
126 int (*img_first) (struct image_params *);
128 if (debug_execve_args) {
129 printf("%s()\n", __func__);
130 print_execve_args(args);
134 imgp = &image_params;
137 * Lock the process and set the P_INEXEC flag to indicate that
138 * it should be left alone until we're done here. This is
139 * necessary to avoid race conditions - e.g. in ptrace() -
140 * that might allow a local user to illicitly obtain elevated
143 p->p_flag |= P_INEXEC;
146 * Initialize part of the common data
151 imgp->entry_addr = 0;
153 imgp->vmspace_destroyed = 0;
154 imgp->interpreted = 0;
155 imgp->interpreter_name[0] = 0;
156 imgp->auxargs = NULL;
158 imgp->firstpage = NULL;
159 imgp->ps_strings = 0;
160 imgp->image_header = NULL;
165 * Translate the file name. namei() returns a vnode pointer
166 * in ni_vp amoung other things.
168 if ((error = namei(ndp)) != 0)
171 imgp->vp = ndp->ni_vp;
174 * Check file permissions (also 'opens' file)
176 error = exec_check_permissions(imgp);
178 VOP_UNLOCK(imgp->vp, NULL, 0, td);
179 goto exec_fail_dealloc;
182 error = exec_map_first_page(imgp);
183 VOP_UNLOCK(imgp->vp, NULL, 0, td);
185 goto exec_fail_dealloc;
187 if (debug_execve_args && imgp->interpreted) {
188 printf(" target is interpreted -- recursive pass\n");
189 printf(" interpreter: %s\n", imgp->interpreter_name);
190 print_execve_args(args);
194 * If the current process has a special image activator it
195 * wants to try first, call it. For example, emulating shell
196 * scripts differently.
199 if ((img_first = imgp->proc->p_sysent->sv_imgact_try) != NULL)
200 error = img_first(imgp);
203 * If the vnode has a registered vmspace, exec the vmspace
205 if (error == -1 && imgp->vp->v_resident) {
206 error = exec_resident_imgact(imgp);
210 * Loop through the list of image activators, calling each one.
211 * An activator returns -1 if there is no match, 0 on success,
212 * and an error otherwise.
214 for (i = 0; error == -1 && execsw[i]; ++i) {
215 if (execsw[i]->ex_imgact == NULL ||
216 execsw[i]->ex_imgact == img_first) {
219 error = (*execsw[i]->ex_imgact)(imgp);
225 goto exec_fail_dealloc;
229 * Special interpreter operation, cleanup and loop up to try to
230 * activate the interpreter.
232 if (imgp->interpreted) {
233 exec_unmap_first_page(imgp);
234 /* free name buffer and old vnode */
235 NDFREE(ndp, NDF_ONLY_PNBUF);
237 /* set new name to that of the interpreter */
238 NDINIT(ndp, NAMEI_LOOKUP,
239 CNP_LOCKLEAF | CNP_FOLLOW | CNP_SAVENAME,
240 UIO_SYSSPACE, imgp->interpreter_name, td);
245 * Copy out strings (args and env) and initialize stack base
247 stack_base = exec_copyout_strings(imgp);
248 p->p_vmspace->vm_minsaddr = (char *)stack_base;
251 * If custom stack fixup routine present for this process
252 * let it do the stack setup. If we are running a resident
253 * image there is no auxinfo or other image activator context
254 * so don't try to add fixups to the stack.
256 * Else stuff argument count as first item on stack
258 if (p->p_sysent->sv_fixup && imgp->resident == 0)
259 (*p->p_sysent->sv_fixup)(&stack_base, imgp);
261 suword(--stack_base, imgp->args->argc);
264 * For security and other reasons, the file descriptor table cannot
265 * be shared after an exec.
267 if (p->p_fd->fd_refcnt > 1) {
268 struct filedesc *tmp;
276 * For security and other reasons, signal handlers cannot
277 * be shared after an exec. The new proces gets a copy of the old
278 * handlers. In execsigs(), the new process will have its signals
281 if (p->p_procsig->ps_refcnt > 1) {
282 struct procsig *newprocsig;
284 MALLOC(newprocsig, struct procsig *, sizeof(struct procsig),
285 M_SUBPROC, M_WAITOK);
286 bcopy(p->p_procsig, newprocsig, sizeof(*newprocsig));
287 p->p_procsig->ps_refcnt--;
288 p->p_procsig = newprocsig;
289 p->p_procsig->ps_refcnt = 1;
290 if (p->p_sigacts == &p->p_addr->u_sigacts)
291 panic("shared procsig but private sigacts?");
293 p->p_addr->u_sigacts = *p->p_sigacts;
294 p->p_sigacts = &p->p_addr->u_sigacts;
300 /* close files on exec */
303 /* reset caught signals */
306 /* name this process - nameiexec(p, ndp) */
307 len = min(ndp->ni_cnd.cn_namelen,MAXCOMLEN);
308 bcopy(ndp->ni_cnd.cn_nameptr, p->p_comm, len);
312 * mark as execed, wakeup the process that vforked (if any) and tell
313 * it that it now has its own resources back
316 if (p->p_pptr && (p->p_flag & P_PPWAIT)) {
317 p->p_flag &= ~P_PPWAIT;
318 wakeup((caddr_t)p->p_pptr);
322 * Implement image setuid/setgid.
324 * Don't honor setuid/setgid if the filesystem prohibits it or if
325 * the process is being traced.
327 if ((((attr.va_mode & VSUID) && p->p_ucred->cr_uid != attr.va_uid) ||
328 ((attr.va_mode & VSGID) && p->p_ucred->cr_gid != attr.va_gid)) &&
329 (imgp->vp->v_mount->mnt_flag & MNT_NOSUID) == 0 &&
330 (p->p_flag & P_TRACED) == 0) {
332 * Turn off syscall tracing for set-id programs, except for
333 * root. Record any set-id flags first to make sure that
334 * we do not regain any tracing during a possible block.
337 if (p->p_tracep && suser(td)) {
340 if ((vtmp = p->p_tracep) != NULL) {
346 /* Close any file descriptors 0..2 that reference procfs */
348 /* Make sure file descriptors 0..2 are in use. */
349 error = fdcheckstd(p);
351 goto exec_fail_dealloc;
353 * Set the new credentials.
356 if (attr.va_mode & VSUID)
357 change_euid(attr.va_uid);
358 if (attr.va_mode & VSGID)
359 p->p_ucred->cr_gid = attr.va_gid;
362 * Clear local varsym variables
364 varsymset_clean(&p->p_varsymset);
366 if (p->p_ucred->cr_uid == p->p_ucred->cr_ruid &&
367 p->p_ucred->cr_gid == p->p_ucred->cr_rgid)
368 p->p_flag &= ~P_SUGID;
372 * Implement correct POSIX saved-id behavior.
374 if (p->p_ucred->cr_svuid != p->p_ucred->cr_uid ||
375 p->p_ucred->cr_svgid != p->p_ucred->cr_gid) {
377 p->p_ucred->cr_svuid = p->p_ucred->cr_uid;
378 p->p_ucred->cr_svgid = p->p_ucred->cr_gid;
382 * Store the vp for use in procfs
384 if (p->p_textvp) /* release old reference */
387 p->p_textvp = ndp->ni_vp;
390 * Notify others that we exec'd, and clear the P_INEXEC flag
391 * as we're now a bona fide freshly-execed process.
393 KNOTE(&p->p_klist, NOTE_EXEC);
394 p->p_flag &= ~P_INEXEC;
397 * If tracing the process, trap to debugger so breakpoints
398 * can be set before the program executes.
400 STOPEVENT(p, S_EXEC, 0);
402 if (p->p_flag & P_TRACED)
405 /* clear "fork but no exec" flag, as we _are_ execing */
406 p->p_acflag &= ~AFORK;
408 /* Set values passed into the program in registers. */
409 setregs(p, imgp->entry_addr, (u_long)(uintptr_t)stack_base,
412 /* Free any previous argument cache */
413 if (p->p_args && --p->p_args->ar_ref == 0)
414 FREE(p->p_args, M_PARGS);
417 /* Cache arguments if they fit inside our allowance */
418 i = imgp->args->begin_envv - imgp->args->begin_argv;
419 if (ps_arg_cache_limit >= i + sizeof(struct pargs)) {
420 MALLOC(p->p_args, struct pargs *, sizeof(struct pargs) + i,
422 p->p_args->ar_ref = 1;
423 p->p_args->ar_length = i;
424 bcopy(imgp->args->begin_argv, p->p_args->ar_args, i);
430 * free various allocated resources
433 exec_unmap_first_page(imgp);
436 NDFREE(ndp, NDF_ONLY_PNBUF);
441 ++mycpu->gd_cnt.v_exec;
446 /* we're done here, clear P_INEXEC */
447 p->p_flag &= ~P_INEXEC;
448 if (imgp->vmspace_destroyed) {
449 /* sorry, no more process anymore. exit gracefully */
450 exit1(W_EXITCODE(0, SIGABRT));
459 * execve() system call.
462 execve(struct execve_args *uap)
464 struct thread *td = curthread;
466 struct image_args args;
469 NDINIT(&nd, NAMEI_LOOKUP, CNP_LOCKLEAF | CNP_FOLLOW | CNP_SAVENAME,
470 UIO_USERSPACE, uap->fname, td);
472 error = exec_copyin_args(&args, uap->fname, PATH_USERSPACE,
473 uap->argv, uap->envv);
475 error = kern_execve(&nd, &args);
477 exec_free_args(&args);
480 * The syscall result is returned in registers to the new program.
481 * Linux will register %edx as an atexit function and we must be
482 * sure to set it to 0. XXX
485 uap->sysmsg_result64 = 0;
491 exec_map_first_page(struct image_params *imgp)
495 vm_page_t ma[VM_INITIAL_PAGEIN];
499 exec_unmap_first_page(imgp);
501 VOP_GETVOBJECT(imgp->vp, &object);
504 ma[0] = vm_page_grab(object, 0, VM_ALLOC_NORMAL | VM_ALLOC_RETRY);
506 if ((ma[0]->valid & VM_PAGE_BITS_ALL) != VM_PAGE_BITS_ALL) {
507 initial_pagein = VM_INITIAL_PAGEIN;
508 if (initial_pagein > object->size)
509 initial_pagein = object->size;
510 for (i = 1; i < initial_pagein; i++) {
511 if ((ma[i] = vm_page_lookup(object, i)) != NULL) {
512 if ((ma[i]->flags & PG_BUSY) || ma[i]->busy)
518 ma[i] = vm_page_alloc(object, i, VM_ALLOC_NORMAL);
525 rv = vm_pager_get_pages(object, ma, initial_pagein, 0);
526 ma[0] = vm_page_lookup(object, 0);
528 if ((rv != VM_PAGER_OK) || (ma[0] == NULL) || (ma[0]->valid == 0)) {
530 vm_page_protect(ma[0], VM_PROT_NONE);
539 vm_page_wakeup(ma[0]);
542 imgp->firstpage = sf_buf_alloc(ma[0], SFBA_QUICK);
543 imgp->image_header = (void *)sf_buf_kva(imgp->firstpage);
549 exec_unmap_first_page(imgp)
550 struct image_params *imgp;
554 if (imgp->firstpage != NULL) {
555 m = sf_buf_page(imgp->firstpage);
556 sf_buf_free(imgp->firstpage);
557 imgp->firstpage = NULL;
558 imgp->image_header = NULL;
564 * Destroy old address space, and allocate a new stack
565 * The new stack is only SGROWSIZ large because it is grown
566 * automatically in trap.c.
569 exec_new_vmspace(struct image_params *imgp, struct vmspace *vmcopy)
572 struct vmspace *vmspace = imgp->proc->p_vmspace;
573 vm_offset_t stack_addr = USRSTACK - maxssiz;
576 imgp->vmspace_destroyed = 1;
579 * Prevent a pending AIO from modifying the new address space.
581 aio_proc_rundown(imgp->proc);
584 * Blow away entire process VM, if address space not shared,
585 * otherwise, create a new VM space so that other threads are
586 * not disrupted. If we are execing a resident vmspace we
587 * create a duplicate of it and remap the stack.
589 * The exitingcnt test is not strictly necessary but has been
590 * included for code sanity (to make the code more deterministic).
592 map = &vmspace->vm_map;
594 vmspace_exec(imgp->proc, vmcopy);
595 vmspace = imgp->proc->p_vmspace;
596 pmap_remove_pages(vmspace_pmap(vmspace), stack_addr, USRSTACK);
597 map = &vmspace->vm_map;
598 } else if (vmspace->vm_refcnt == 1 && vmspace->vm_exitingcnt == 0) {
600 if (vmspace->vm_upcalls)
601 upc_release(vmspace, imgp->proc);
602 pmap_remove_pages(vmspace_pmap(vmspace), 0, VM_MAXUSER_ADDRESS);
603 vm_map_remove(map, 0, VM_MAXUSER_ADDRESS);
605 vmspace_exec(imgp->proc, NULL);
606 vmspace = imgp->proc->p_vmspace;
607 map = &vmspace->vm_map;
610 /* Allocate a new stack */
611 error = vm_map_stack(&vmspace->vm_map, stack_addr, (vm_size_t)maxssiz,
612 VM_PROT_ALL, VM_PROT_ALL, 0);
616 /* vm_ssize and vm_maxsaddr are somewhat antiquated concepts in the
617 * VM_STACK case, but they are still used to monitor the size of the
618 * process stack so we can check the stack rlimit.
620 vmspace->vm_ssize = sgrowsiz >> PAGE_SHIFT;
621 vmspace->vm_maxsaddr = (char *)USRSTACK - maxssiz;
627 * Copy out argument and environment strings from the old process
628 * address space into the temporary string buffer.
631 exec_copyin_args(struct image_args *args, char *fname,
632 enum exec_path_segflg segflg, char **argv, char **envv)
638 bzero(args, sizeof(*args));
639 args->buf = (char *) kmem_alloc_wait(exec_map, PATH_MAX + ARG_MAX);
640 if (args->buf == NULL)
642 args->begin_argv = args->buf;
643 args->endp = args->begin_argv;
644 args->space = ARG_MAX;
646 args->fname = args->buf + ARG_MAX;
649 * Copy the file name.
651 if (segflg == PATH_SYSSPACE) {
652 error = copystr(fname, args->fname, PATH_MAX, &length);
653 } else if (segflg == PATH_USERSPACE) {
654 error = copyinstr(fname, args->fname, PATH_MAX, &length);
658 * extract argument strings
661 if (argv && error == 0) {
663 * The argv0 argument for execv() is allowed to be NULL,
664 * in which case we use our filename as argv[0].
665 * This guarantees that
666 * the interpreter knows what file to open in the case
667 * that we exec an interpreted file.
669 argp = (caddr_t) (intptr_t) fuword(argv);
671 length = strlen(args->fname) + 1;
672 KKASSERT(length <= args->space);
673 bcopy(args->fname, args->endp, length);
674 args->space -= length;
675 args->endp += length;
679 while ((argp = (caddr_t) (intptr_t) fuword(argv++))) {
680 if (argp == (caddr_t) -1) {
684 error = copyinstr(argp, args->endp,
685 args->space, &length);
686 if (error == ENAMETOOLONG)
690 args->space -= length;
691 args->endp += length;
696 args->begin_envv = args->endp;
699 * extract environment strings
701 if (envv && error == 0) {
702 while ((envp = (caddr_t) (intptr_t) fuword(envv++))) {
703 if (envp == (caddr_t) -1) {
707 error = copyinstr(envp, args->endp, args->space,
709 if (error == ENAMETOOLONG)
713 args->space -= length;
714 args->endp += length;
724 exec_free_args(struct image_args *args)
727 kmem_free_wakeup(exec_map,
728 (vm_offset_t)args->buf, PATH_MAX + ARG_MAX);
734 * Copy strings out to the new process address space, constructing
735 * new arg and env vector tables. Return a pointer to the base
736 * so that it can be used as the initial stack pointer.
739 exec_copyout_strings(struct image_params *imgp)
743 char *stringp, *destp;
744 register_t *stack_base;
745 struct ps_strings *arginfo;
749 * Calculate string base and vector table pointers.
750 * Also deal with signal trampoline code for this exec type.
752 arginfo = (struct ps_strings *)PS_STRINGS;
753 szsigcode = *(imgp->proc->p_sysent->sv_szsigcode);
754 destp = (caddr_t)arginfo - szsigcode - SPARE_USRSPACE -
755 roundup((ARG_MAX - imgp->args->space), sizeof(char *));
761 copyout(imgp->proc->p_sysent->sv_sigcode,
762 ((caddr_t)arginfo - szsigcode), szsigcode);
765 * If we have a valid auxargs ptr, prepare some room
768 * The '+ 2' is for the null pointers at the end of each of the
769 * arg and env vector sets, and 'AT_COUNT*2' is room for the
773 vectp = (char **)(destp - (imgp->args->argc +
774 imgp->args->envc + 2 + AT_COUNT * 2) * sizeof(char*));
776 vectp = (char **)(destp - (imgp->args->argc +
777 imgp->args->envc + 2) * sizeof(char*));
781 * NOTE: don't bother aligning the stack here for GCC 2.x, it will
782 * be done in crt1.o. Note that GCC 3.x aligns the stack in main.
786 * vectp also becomes our initial stack base
788 stack_base = (register_t *)vectp;
790 stringp = imgp->args->begin_argv;
791 argc = imgp->args->argc;
792 envc = imgp->args->envc;
795 * Copy out strings - arguments and environment.
797 copyout(stringp, destp, ARG_MAX - imgp->args->space);
800 * Fill in "ps_strings" struct for ps, w, etc.
802 suword(&arginfo->ps_argvstr, (long)(intptr_t)vectp);
803 suword(&arginfo->ps_nargvstr, argc);
806 * Fill in argument portion of vector table.
808 for (; argc > 0; --argc) {
809 suword(vectp++, (long)(intptr_t)destp);
810 while (*stringp++ != 0)
815 /* a null vector table pointer separates the argp's from the envp's */
818 suword(&arginfo->ps_envstr, (long)(intptr_t)vectp);
819 suword(&arginfo->ps_nenvstr, envc);
822 * Fill in environment portion of vector table.
824 for (; envc > 0; --envc) {
825 suword(vectp++, (long)(intptr_t)destp);
826 while (*stringp++ != 0)
831 /* end of vector table is a null pointer */
838 * Check permissions of file to execute.
839 * Return 0 for success or error code on failure.
842 exec_check_permissions(imgp)
843 struct image_params *imgp;
845 struct proc *p = imgp->proc;
846 struct vnode *vp = imgp->vp;
847 struct vattr *attr = imgp->attr;
848 struct thread *td = p->p_thread;
851 /* Get file attributes */
852 error = VOP_GETATTR(vp, attr, td);
857 * 1) Check if file execution is disabled for the filesystem that this
859 * 2) Insure that at least one execute bit is on - otherwise root
860 * will always succeed, and we don't want to happen unless the
861 * file really is executable.
862 * 3) Insure that the file is a regular file.
864 if ((vp->v_mount->mnt_flag & MNT_NOEXEC) ||
865 ((attr->va_mode & 0111) == 0) ||
866 (attr->va_type != VREG)) {
871 * Zero length files can't be exec'd
873 if (attr->va_size == 0)
877 * Check for execute permission to file based on current credentials.
879 error = VOP_ACCESS(vp, VEXEC, p->p_ucred, td);
884 * Check number of open-for-writes on the file and deny execution
887 if (vp->v_writecount)
891 * Call filesystem specific open routine (which does nothing in the
894 error = VOP_OPEN(vp, FREAD, p->p_ucred, td);
902 * Exec handler registration
905 exec_register(execsw_arg)
906 const struct execsw *execsw_arg;
908 const struct execsw **es, **xs, **newexecsw;
909 int count = 2; /* New slot and trailing NULL */
912 for (es = execsw; *es; es++)
914 newexecsw = malloc(count * sizeof(*es), M_TEMP, M_WAITOK);
915 if (newexecsw == NULL)
919 for (es = execsw; *es; es++)
924 free(execsw, M_TEMP);
930 exec_unregister(execsw_arg)
931 const struct execsw *execsw_arg;
933 const struct execsw **es, **xs, **newexecsw;
937 panic("unregister with no handlers left?\n");
939 for (es = execsw; *es; es++) {
940 if (*es == execsw_arg)
945 for (es = execsw; *es; es++)
946 if (*es != execsw_arg)
948 newexecsw = malloc(count * sizeof(*es), M_TEMP, M_WAITOK);
949 if (newexecsw == NULL)
952 for (es = execsw; *es; es++)
953 if (*es != execsw_arg)
957 free(execsw, M_TEMP);