xref: /titanic_51/usr/src/uts/common/exec/aout/aout.c (revision 89b43686db1fe9681d80a7cf5662730cb9378cae)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
59acbbeafSnn35248  * Common Development and Distribution License (the "License").
69acbbeafSnn35248  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22b71d513aSedp  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*89b43686SBayard Bell  * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <sys/types.h>
287c478bd9Sstevel@tonic-gate #include <sys/param.h>
297c478bd9Sstevel@tonic-gate #include <sys/systm.h>
307c478bd9Sstevel@tonic-gate #include <sys/fpu/fpusystm.h>
317c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
327c478bd9Sstevel@tonic-gate #include <sys/signal.h>
337c478bd9Sstevel@tonic-gate #include <sys/cred.h>
347c478bd9Sstevel@tonic-gate #include <sys/user.h>
357c478bd9Sstevel@tonic-gate #include <sys/errno.h>
367c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
377c478bd9Sstevel@tonic-gate #include <sys/mman.h>
387c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
397c478bd9Sstevel@tonic-gate #include <sys/proc.h>
407c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
417c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
427c478bd9Sstevel@tonic-gate #include <sys/debug.h>
437c478bd9Sstevel@tonic-gate #include <sys/exec.h>
447c478bd9Sstevel@tonic-gate #include <sys/exechdr.h>
457c478bd9Sstevel@tonic-gate #include <sys/auxv.h>
467c478bd9Sstevel@tonic-gate #include <sys/core.h>
477c478bd9Sstevel@tonic-gate #include <sys/vmparam.h>
487c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
497c478bd9Sstevel@tonic-gate #include <sys/fs/swapnode.h>
507c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
517c478bd9Sstevel@tonic-gate #include <vm/anon.h>
527c478bd9Sstevel@tonic-gate #include <vm/as.h>
537c478bd9Sstevel@tonic-gate #include <vm/seg.h>
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate static int aoutexec(vnode_t *vp, execa_t *uap, uarg_t *args,
567c478bd9Sstevel@tonic-gate     intpdata_t *idatap, int level, long *execsz, int setid,
579acbbeafSnn35248     caddr_t exec_file, cred_t *cred, int brand_action);
587c478bd9Sstevel@tonic-gate static int get_aout_head(struct vnode **vpp, struct exdata *edp, long *execsz,
597c478bd9Sstevel@tonic-gate     int *isdyn);
607c478bd9Sstevel@tonic-gate static int aoutcore(vnode_t *vp, proc_t *pp, cred_t *credp,
617c478bd9Sstevel@tonic-gate     rlim64_t rlimit, int sig, core_content_t content);
627c478bd9Sstevel@tonic-gate extern int elf32exec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
639acbbeafSnn35248     long *, int, caddr_t, cred_t *, int);
647c478bd9Sstevel@tonic-gate extern int elf32core(vnode_t *, proc_t *, cred_t *, rlim64_t, int,
657c478bd9Sstevel@tonic-gate     core_content_t);
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate static struct execsw nesw = {
687c478bd9Sstevel@tonic-gate 	aout_nmagicstr,
697c478bd9Sstevel@tonic-gate 	2,
707c478bd9Sstevel@tonic-gate 	2,
717c478bd9Sstevel@tonic-gate 	aoutexec,
727c478bd9Sstevel@tonic-gate 	aoutcore
737c478bd9Sstevel@tonic-gate };
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate static struct execsw zesw = {
767c478bd9Sstevel@tonic-gate 	aout_zmagicstr,
777c478bd9Sstevel@tonic-gate 	2,
787c478bd9Sstevel@tonic-gate 	2,
797c478bd9Sstevel@tonic-gate 	aoutexec,
807c478bd9Sstevel@tonic-gate 	aoutcore
817c478bd9Sstevel@tonic-gate };
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate static struct execsw oesw = {
847c478bd9Sstevel@tonic-gate 	aout_omagicstr,
857c478bd9Sstevel@tonic-gate 	2,
867c478bd9Sstevel@tonic-gate 	2,
877c478bd9Sstevel@tonic-gate 	aoutexec,
887c478bd9Sstevel@tonic-gate 	aoutcore
897c478bd9Sstevel@tonic-gate };
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * Module linkage information for the kernel.
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate static struct modlexec nexec = {
957c478bd9Sstevel@tonic-gate 	&mod_execops, "exec for NMAGIC", &nesw
967c478bd9Sstevel@tonic-gate };
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate static struct modlexec zexec = {
997c478bd9Sstevel@tonic-gate 	&mod_execops, "exec for ZMAGIC", &zesw
1007c478bd9Sstevel@tonic-gate };
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate static struct modlexec oexec = {
1037c478bd9Sstevel@tonic-gate 	&mod_execops, "exec for OMAGIC", &oesw
1047c478bd9Sstevel@tonic-gate };
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1077c478bd9Sstevel@tonic-gate 	MODREV_1, &nexec, &zexec, &oexec, NULL
1087c478bd9Sstevel@tonic-gate };
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate int
1117c478bd9Sstevel@tonic-gate _init(void)
1127c478bd9Sstevel@tonic-gate {
1137c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate int
1177c478bd9Sstevel@tonic-gate _fini(void)
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate int
1237c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1247c478bd9Sstevel@tonic-gate {
1257c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1307c478bd9Sstevel@tonic-gate static int
1317c478bd9Sstevel@tonic-gate aoutexec(vnode_t *vp, struct execa *uap, struct uarg *args,
1327c478bd9Sstevel@tonic-gate     struct intpdata *idatap, int level, long *execsz, int setid,
1339acbbeafSnn35248     caddr_t exec_file, cred_t *cred, int brand_action)
1347c478bd9Sstevel@tonic-gate {
135b71d513aSedp 	auxv32_t auxflags_auxv32;
1367c478bd9Sstevel@tonic-gate 	int error;
1377c478bd9Sstevel@tonic-gate 	struct exdata edp, edpout;
1387c478bd9Sstevel@tonic-gate 	struct execenv exenv;
1397c478bd9Sstevel@tonic-gate 	proc_t *pp = ttoproc(curthread);
1407c478bd9Sstevel@tonic-gate 	struct vnode *nvp;
1417c478bd9Sstevel@tonic-gate 	int pagetext, pagedata;
1427c478bd9Sstevel@tonic-gate 	int dataprot = PROT_ALL;
1437c478bd9Sstevel@tonic-gate 	int textprot = PROT_ALL & ~PROT_WRITE;
1447c478bd9Sstevel@tonic-gate 	int isdyn;
1457c478bd9Sstevel@tonic-gate 
146b71d513aSedp 
1477c478bd9Sstevel@tonic-gate 	args->to_model = DATAMODEL_ILP32;
1487c478bd9Sstevel@tonic-gate 	*execsz = btopr(SINCR) + btopr(SSIZE) + btopr(NCARGS32-1);
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	/*
1517c478bd9Sstevel@tonic-gate 	 * Read in and validate the file header.
1527c478bd9Sstevel@tonic-gate 	 */
1537c478bd9Sstevel@tonic-gate 	if (error = get_aout_head(&vp, &edp, execsz, &isdyn))
1547c478bd9Sstevel@tonic-gate 		return (error);
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	if (error = chkaout(&edp))
1577c478bd9Sstevel@tonic-gate 		return (error);
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	/*
1607c478bd9Sstevel@tonic-gate 	 * Take a quick look to see if it looks like we will have
1617c478bd9Sstevel@tonic-gate 	 * enough swap space for the program to get started.  This
1627c478bd9Sstevel@tonic-gate 	 * is not a guarantee that we will succeed, but it is definitely
1637c478bd9Sstevel@tonic-gate 	 * better than finding this out after we are committed to the
1647c478bd9Sstevel@tonic-gate 	 * new memory image.  Maybe what is needed is a way to "prereserve"
1657c478bd9Sstevel@tonic-gate 	 * swap space for some segment mappings here.
1667c478bd9Sstevel@tonic-gate 	 *
1677c478bd9Sstevel@tonic-gate 	 * But with shared libraries the process can make it through
1687c478bd9Sstevel@tonic-gate 	 * the exec only to have ld.so fail to get the program going
1697c478bd9Sstevel@tonic-gate 	 * because its mmap's will not be able to succeed if the system
1707c478bd9Sstevel@tonic-gate 	 * is running low on swap space.  In fact this is a far more
1717c478bd9Sstevel@tonic-gate 	 * common failure mode, but we cannot do much about this here
1727c478bd9Sstevel@tonic-gate 	 * other than add some slop to our anonymous memory resources
1737c478bd9Sstevel@tonic-gate 	 * requirements estimate based on some guess since we cannot know
1747c478bd9Sstevel@tonic-gate 	 * what else the program will really need to get to a useful state.
1757c478bd9Sstevel@tonic-gate 	 *
1767c478bd9Sstevel@tonic-gate 	 * XXX - The stack size (clrnd(SSIZE + btopr(nargc))) should also
1777c478bd9Sstevel@tonic-gate 	 * be used when checking for swap space.  This requires some work
1787c478bd9Sstevel@tonic-gate 	 * since nargc is actually determined in exec_args() which is done
1797c478bd9Sstevel@tonic-gate 	 * after this check and hence we punt for now.
1807c478bd9Sstevel@tonic-gate 	 *
1817c478bd9Sstevel@tonic-gate 	 * nargc = SA(nc + (na + 4) * NBPW) + sizeof (struct rwindow);
1827c478bd9Sstevel@tonic-gate 	 */
1837c478bd9Sstevel@tonic-gate 	if (CURRENT_TOTAL_AVAILABLE_SWAP < btopr(edp.ux_dsize) + btopr(SSIZE))
1847c478bd9Sstevel@tonic-gate 		return (ENOMEM);
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	/*
1877c478bd9Sstevel@tonic-gate 	 * Load the trap 0 interpreter.
1887c478bd9Sstevel@tonic-gate 	 */
1897c478bd9Sstevel@tonic-gate 	if (error = lookupname("/usr/4lib/sbcp", UIO_SYSSPACE, FOLLOW,
1907c478bd9Sstevel@tonic-gate 	    NULLVPP, &nvp)) {
1917c478bd9Sstevel@tonic-gate 		goto done;
1927c478bd9Sstevel@tonic-gate 	}
1937c478bd9Sstevel@tonic-gate 	if (error = elf32exec(nvp, uap, args, idatap, level, execsz,
194b71d513aSedp 	    setid, exec_file, cred, brand_action)) {
1957c478bd9Sstevel@tonic-gate 		VN_RELE(nvp);
1967c478bd9Sstevel@tonic-gate 		return (error);
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 	VN_RELE(nvp);
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	/*
2017c478bd9Sstevel@tonic-gate 	 * Determine the a.out's characteristics.
2027c478bd9Sstevel@tonic-gate 	 */
2037c478bd9Sstevel@tonic-gate 	getexinfo(&edp, &edpout, &pagetext, &pagedata);
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	/*
2067c478bd9Sstevel@tonic-gate 	 * Load the a.out's text and data.
2077c478bd9Sstevel@tonic-gate 	 */
2087c478bd9Sstevel@tonic-gate 	if (error = execmap(edp.vp, edp.ux_txtorg, edp.ux_tsize,
2097c478bd9Sstevel@tonic-gate 	    (size_t)0, edp.ux_toffset, textprot, pagetext, 0))
2107c478bd9Sstevel@tonic-gate 		goto done;
2117c478bd9Sstevel@tonic-gate 	if (error = execmap(edp.vp, edp.ux_datorg, edp.ux_dsize,
2127c478bd9Sstevel@tonic-gate 	    edp.ux_bsize, edp.ux_doffset, dataprot, pagedata, 0))
2137c478bd9Sstevel@tonic-gate 		goto done;
2147c478bd9Sstevel@tonic-gate 
215ec25b48fSsusans 	exenv.ex_bssbase = (caddr_t)edp.ux_datorg;
2167c478bd9Sstevel@tonic-gate 	exenv.ex_brkbase = (caddr_t)edp.ux_datorg;
2177c478bd9Sstevel@tonic-gate 	exenv.ex_brksize = edp.ux_dsize + edp.ux_bsize;
2187c478bd9Sstevel@tonic-gate 	exenv.ex_magic = edp.ux_mag;
2197c478bd9Sstevel@tonic-gate 	exenv.ex_vp = edp.vp;
2207c478bd9Sstevel@tonic-gate 	setexecenv(&exenv);
2217c478bd9Sstevel@tonic-gate 
222b71d513aSedp 	/*
223b71d513aSedp 	 * It's time to manipulate the process aux vectors.
224b71d513aSedp 	 * We need to update the AT_SUN_AUXFLAGS aux vector to set
225b71d513aSedp 	 * the AF_SUN_NOPLM flag.
226b71d513aSedp 	 */
227b71d513aSedp 	if (copyin(args->auxp_auxflags, &auxflags_auxv32,
228b71d513aSedp 	    sizeof (auxflags_auxv32)) != 0)
229b71d513aSedp 		return (EFAULT);
230b71d513aSedp 
231b71d513aSedp 	ASSERT(auxflags_auxv32.a_type == AT_SUN_AUXFLAGS);
232b71d513aSedp 	auxflags_auxv32.a_un.a_val |= AF_SUN_NOPLM;
233b71d513aSedp 	if (copyout(&auxflags_auxv32, args->auxp_auxflags,
234b71d513aSedp 	    sizeof (auxflags_auxv32)) != 0)
235b71d513aSedp 		return (EFAULT);
236b71d513aSedp 
2377c478bd9Sstevel@tonic-gate done:
2387c478bd9Sstevel@tonic-gate 	if (error != 0)
2397c478bd9Sstevel@tonic-gate 		psignal(pp, SIGKILL);
2407c478bd9Sstevel@tonic-gate 	else {
2417c478bd9Sstevel@tonic-gate 		/*
2427c478bd9Sstevel@tonic-gate 		 * Ensure that the max fds do not exceed 256 (this is
2437c478bd9Sstevel@tonic-gate 		 * applicable to 4.x binaries, which is why we only
2447c478bd9Sstevel@tonic-gate 		 * do it on a.out files).
2457c478bd9Sstevel@tonic-gate 		 */
2467c478bd9Sstevel@tonic-gate 		struct rlimit64 fdno_rlim;
2477c478bd9Sstevel@tonic-gate 		rctl_alloc_gp_t *gp = rctl_rlimit_set_prealloc(1);
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 		mutex_enter(&curproc->p_lock);
2507c478bd9Sstevel@tonic-gate 		(void) rctl_rlimit_get(rctlproc_legacy[RLIMIT_NOFILE], curproc,
2517c478bd9Sstevel@tonic-gate 		    &fdno_rlim);
2527c478bd9Sstevel@tonic-gate 		if (fdno_rlim.rlim_cur > 256) {
2537c478bd9Sstevel@tonic-gate 			fdno_rlim.rlim_cur = fdno_rlim.rlim_max = 256;
2547c478bd9Sstevel@tonic-gate 			(void) rctl_rlimit_set(rctlproc_legacy[RLIMIT_NOFILE],
2557c478bd9Sstevel@tonic-gate 			    curproc, &fdno_rlim, gp,
2567c478bd9Sstevel@tonic-gate 			    rctlproc_flags[RLIMIT_NOFILE],
2577c478bd9Sstevel@tonic-gate 			    rctlproc_signals[RLIMIT_NOFILE], CRED());
2587c478bd9Sstevel@tonic-gate 		} else if (fdno_rlim.rlim_max > 256) {
2597c478bd9Sstevel@tonic-gate 			fdno_rlim.rlim_max = 256;
2607c478bd9Sstevel@tonic-gate 			(void) rctl_rlimit_set(rctlproc_legacy[RLIMIT_NOFILE],
2617c478bd9Sstevel@tonic-gate 			    curproc, &fdno_rlim, gp,
2627c478bd9Sstevel@tonic-gate 			    rctlproc_flags[RLIMIT_NOFILE],
2637c478bd9Sstevel@tonic-gate 			    rctlproc_signals[RLIMIT_NOFILE], CRED());
2647c478bd9Sstevel@tonic-gate 		}
2657c478bd9Sstevel@tonic-gate 		mutex_exit(&curproc->p_lock);
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 		rctl_prealloc_destroy(gp);
2687c478bd9Sstevel@tonic-gate 	}
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	return (error);
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate  * Read in and validate the file header.
2757c478bd9Sstevel@tonic-gate  */
2767c478bd9Sstevel@tonic-gate static int
2777c478bd9Sstevel@tonic-gate get_aout_head(struct vnode **vpp, struct exdata *edp, long *execsz, int *isdyn)
2787c478bd9Sstevel@tonic-gate {
2797c478bd9Sstevel@tonic-gate 	struct vnode *vp = *vpp;
2807c478bd9Sstevel@tonic-gate 	struct exec filhdr;
2817c478bd9Sstevel@tonic-gate 	int error;
2827c478bd9Sstevel@tonic-gate 	ssize_t resid;
2837c478bd9Sstevel@tonic-gate 	rlim64_t limit;
2847c478bd9Sstevel@tonic-gate 	rlim64_t roundlimit;
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	if (error = vn_rdwr(UIO_READ, vp, (caddr_t)&filhdr,
2877c478bd9Sstevel@tonic-gate 	    (ssize_t)sizeof (filhdr), (offset_t)0, UIO_SYSSPACE, 0,
2887c478bd9Sstevel@tonic-gate 	    (rlim64_t)0, CRED(), &resid))
2897c478bd9Sstevel@tonic-gate 		return (error);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	if (resid != 0)
2927c478bd9Sstevel@tonic-gate 		return (ENOEXEC);
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	switch (filhdr.a_magic) {
2957c478bd9Sstevel@tonic-gate 	case OMAGIC:
2967c478bd9Sstevel@tonic-gate 		filhdr.a_data += filhdr.a_text;
2977c478bd9Sstevel@tonic-gate 		filhdr.a_text = 0;
2987c478bd9Sstevel@tonic-gate 		break;
2997c478bd9Sstevel@tonic-gate 	case ZMAGIC:
3007c478bd9Sstevel@tonic-gate 	case NMAGIC:
3017c478bd9Sstevel@tonic-gate 		break;
3027c478bd9Sstevel@tonic-gate 	default:
3037c478bd9Sstevel@tonic-gate 		return (ENOEXEC);
3047c478bd9Sstevel@tonic-gate 	}
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	/*
3077c478bd9Sstevel@tonic-gate 	 * Check total memory requirements (in pages) for a new process
3087c478bd9Sstevel@tonic-gate 	 * against the available memory or upper limit of memory allowed.
3097c478bd9Sstevel@tonic-gate 	 *
3107c478bd9Sstevel@tonic-gate 	 * For the 64-bit kernel, the limit can be set large enough so that
3117c478bd9Sstevel@tonic-gate 	 * rounding it up to a page can overflow, so we check for btopr()
3127c478bd9Sstevel@tonic-gate 	 * overflowing here by comparing it with the unrounded limit in pages.
3137c478bd9Sstevel@tonic-gate 	 */
3147c478bd9Sstevel@tonic-gate 	*execsz += btopr(filhdr.a_text + filhdr.a_data);
3157c478bd9Sstevel@tonic-gate 	limit = btop(curproc->p_vmem_ctl);
3167c478bd9Sstevel@tonic-gate 	roundlimit = btopr(curproc->p_vmem_ctl);
3177c478bd9Sstevel@tonic-gate 	if ((roundlimit > limit && *execsz > roundlimit) ||
3187c478bd9Sstevel@tonic-gate 	    (roundlimit < limit && *execsz > limit)) {
3197c478bd9Sstevel@tonic-gate 		mutex_enter(&curproc->p_lock);
3207c478bd9Sstevel@tonic-gate 		(void) rctl_action(rctlproc_legacy[RLIMIT_VMEM],
3217c478bd9Sstevel@tonic-gate 		    curproc->p_rctls, curproc, RCA_SAFE);
3227c478bd9Sstevel@tonic-gate 		mutex_exit(&curproc->p_lock);
3237c478bd9Sstevel@tonic-gate 		return (ENOMEM);
3247c478bd9Sstevel@tonic-gate 	}
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	edp->ux_mach = filhdr.a_machtype;
3277c478bd9Sstevel@tonic-gate 	edp->ux_tsize = filhdr.a_text;
3287c478bd9Sstevel@tonic-gate 	edp->ux_dsize = filhdr.a_data;
3297c478bd9Sstevel@tonic-gate 	edp->ux_bsize = filhdr.a_bss;
3307c478bd9Sstevel@tonic-gate 	edp->ux_mag = filhdr.a_magic;
3317c478bd9Sstevel@tonic-gate 	edp->ux_toffset = gettfile(&filhdr);
3327c478bd9Sstevel@tonic-gate 	edp->ux_doffset = getdfile(&filhdr);
3337c478bd9Sstevel@tonic-gate 	edp->ux_txtorg = gettmem(&filhdr);
3347c478bd9Sstevel@tonic-gate 	edp->ux_datorg = getdmem(&filhdr);
335be10f7d9Smuffin 	edp->ux_entloc = (caddr_t)(uintptr_t)filhdr.a_entry;
3367c478bd9Sstevel@tonic-gate 	edp->vp = vp;
3377c478bd9Sstevel@tonic-gate 	*isdyn = filhdr.a_dynamic;
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 	return (0);
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate static int
3437c478bd9Sstevel@tonic-gate aoutcore(vnode_t *vp, proc_t *pp, struct cred *credp, rlim64_t rlimit, int sig,
3447c478bd9Sstevel@tonic-gate     core_content_t content)
3457c478bd9Sstevel@tonic-gate {
3467c478bd9Sstevel@tonic-gate 	return (elf32core(vp, pp, credp, rlimit, sig, content));
3477c478bd9Sstevel@tonic-gate }
348