uvn_attach(vp, VM_PROT_READ);
check_exec(p, epp)	struct proc *p;	struct exec_package *epp;{	int error, i;	struct vnode *vp;	struct nameidata *ndp;	size_t resid;	ndp = epp->ep_ndp;	ndp->ni_cnd.cn_nameiop = LOOKUP;	ndp->ni_cnd.cn_flags = FOLLOW | LOCKLEAF | SAVENAME;	/* first get the vnode */	if ((error = namei(ndp)) != 0)		return (error);	epp->ep_vp = vp = ndp->ni_vp;	/* check for regular file */	if (vp->v_type == VDIR) {		error = EISDIR;		goto bad1;	}	if (vp->v_type != VREG) {		error = EACCES;		goto bad1;	}	/* get attributes */	if ((error = VOP_GETATTR(vp, epp->ep_vap, p->p_ucred, p)) != 0)		goto bad1;	/* Check mount point */	if (vp->v_mount->mnt_flag & MNT_NOEXEC) {		error = EACCES;		goto bad1;	}	if ((vp->v_mount->mnt_flag & MNT_NOSUID))		epp->ep_vap->va_mode &= ~(VSUID | VSGID);	/* check access.  for root we have to see if any exec bit on */	if ((error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p)) != 0)		goto bad1;	if ((epp->ep_vap->va_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0) {		error = EACCES;		goto bad1;	}	/* try to open it */	if ((error = VOP_OPEN(vp, FREAD, p->p_ucred, p)) != 0)		goto bad1;	/* now we have the file, get the exec header */	uvn_attach(vp, VM_PROT_READ);	error = vn_rdwr(UIO_READ, vp, epp->ep_hdr, epp->ep_hdrlen, 0,	    UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred, &resid, p);	if (error)		goto bad2;	epp->ep_hdrvalid = epp->ep_hdrlen - resid;	/*	 * set up the vmcmds for creation of the process	 * address space	 */	error = ENOEXEC;	for (i = 0; i < nexecs && error != 0; i++) {		int newerror;		if (execsw[i].es_check == NULL)			continue;		newerror = (*execsw[i].es_check)(p, epp);		/* make sure the first "interesting" error code is saved. */		if (!newerror || error == ENOEXEC)			error = newerror;		if (epp->ep_flags & EXEC_DESTR && error != 0)			return (error);	}	if (!error) {		/* check that entry point is sane */		if (epp->ep_entry > VM_MAXUSER_ADDRESS) {			error = ENOEXEC;		}		/* check limits */		if ((epp->ep_tsize > MAXTSIZ) ||		    (epp->ep_dsize > p->p_rlimit[RLIMIT_DATA].rlim_cur))			error = ENOMEM;		if (!error)			return (0);	}	/*	 * free any vmspace-creation commands,	 * and release their references	 */	kill_vmcmds(&epp->ep_vmcmds);bad2:	/*	 * unlock and close the vnode, free the	 * pathname buf, and punt.	 */	VOP_UNLOCK(vp, 0, p);	vn_close(vp, FREAD, p->p_ucred, p);	FREE(ndp->ni_cnd.cn_pnbuf, M_NAMEI);	return (error);bad1:	/*	 * free the namei pathname buffer, and put the vnode	 * (which we don't yet have open).	 */	FREE(ndp->ni_cnd.cn_pnbuf, M_NAMEI);	vput(vp);	return (error);}