xref: /titanic_52/usr/src/uts/common/sys/exec.h (revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c)
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
5cc4b03b5Scasper  * Common Development and Distribution License (the "License").
6cc4b03b5Scasper  * 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 /*
22cc4b03b5Scasper  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifndef _SYS_EXEC_H
317c478bd9Sstevel@tonic-gate #define	_SYS_EXEC_H
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/systm.h>
367c478bd9Sstevel@tonic-gate #include <vm/seg.h>
377c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
387c478bd9Sstevel@tonic-gate #include <sys/model.h>
397c478bd9Sstevel@tonic-gate #include <sys/uio.h>
407c478bd9Sstevel@tonic-gate #include <sys/corectl.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
437c478bd9Sstevel@tonic-gate extern "C" {
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate /*
477c478bd9Sstevel@tonic-gate  * Number of bytes to read for magic string
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate #define	MAGIC_BYTES	8
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #define	getexmag(x)	(((x)[0] << 8) + (x)[1])
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate typedef struct execa {
547c478bd9Sstevel@tonic-gate 	const char *fname;
557c478bd9Sstevel@tonic-gate 	const char **argp;
567c478bd9Sstevel@tonic-gate 	const char **envp;
577c478bd9Sstevel@tonic-gate } execa_t;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate typedef struct execenv {
607c478bd9Sstevel@tonic-gate 	caddr_t ex_bssbase;
617c478bd9Sstevel@tonic-gate 	caddr_t ex_brkbase;
627c478bd9Sstevel@tonic-gate 	size_t	ex_brksize;
637c478bd9Sstevel@tonic-gate 	vnode_t *ex_vp;
647c478bd9Sstevel@tonic-gate 	short   ex_magic;
657c478bd9Sstevel@tonic-gate } execenv_t;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #ifdef _KERNEL
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate #define	LOADABLE_EXEC(e)	((e)->exec_lock)
707c478bd9Sstevel@tonic-gate #define	LOADED_EXEC(e)		((e)->exec_func)
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate extern int nexectype;		/* number of elements in execsw */
737c478bd9Sstevel@tonic-gate extern struct execsw execsw[];
747c478bd9Sstevel@tonic-gate extern kmutex_t execsw_lock;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate  * User argument structure for passing exec information around between the
787c478bd9Sstevel@tonic-gate  * common and machine-dependent portions of exec and the exec modules.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate typedef struct uarg {
817c478bd9Sstevel@tonic-gate 	ssize_t	na;
827c478bd9Sstevel@tonic-gate 	ssize_t	ne;
837c478bd9Sstevel@tonic-gate 	ssize_t	nc;
847c478bd9Sstevel@tonic-gate 	ssize_t arglen;
857c478bd9Sstevel@tonic-gate 	char	*fname;
867c478bd9Sstevel@tonic-gate 	char	*pathname;
877c478bd9Sstevel@tonic-gate 	ssize_t	auxsize;
887c478bd9Sstevel@tonic-gate 	caddr_t	stackend;
897c478bd9Sstevel@tonic-gate 	size_t	stk_align;
907c478bd9Sstevel@tonic-gate 	size_t	stk_size;
917c478bd9Sstevel@tonic-gate 	char	*stk_base;
927c478bd9Sstevel@tonic-gate 	char	*stk_strp;
937c478bd9Sstevel@tonic-gate 	int	*stk_offp;
947c478bd9Sstevel@tonic-gate 	size_t	usrstack_size;
957c478bd9Sstevel@tonic-gate 	uint_t	stk_prot;
967c478bd9Sstevel@tonic-gate 	uint_t	dat_prot;
977c478bd9Sstevel@tonic-gate 	int	traceinval;
987c478bd9Sstevel@tonic-gate 	model_t	to_model;
997c478bd9Sstevel@tonic-gate 	model_t	from_model;
1007c478bd9Sstevel@tonic-gate 	size_t	to_ptrsize;
1017c478bd9Sstevel@tonic-gate 	size_t	from_ptrsize;
1027c478bd9Sstevel@tonic-gate 	size_t	ncargs;
1037c478bd9Sstevel@tonic-gate 	struct execsw *execswp;
1047c478bd9Sstevel@tonic-gate 	uint_t	stkpageszc;
1057c478bd9Sstevel@tonic-gate 	uint_t	brkpageszc;
1067c478bd9Sstevel@tonic-gate 	uintptr_t entry;
1077c478bd9Sstevel@tonic-gate 	uintptr_t thrptr;
108*9acbbeafSnn35248 	char	*emulator;
109*9acbbeafSnn35248 	char	*brandname;
110*9acbbeafSnn35248 	auxv32_t *brand_auxp;	/* starting user addr of brand auxvs on stack */
1117c478bd9Sstevel@tonic-gate } uarg_t;
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
114*9acbbeafSnn35248  * Possible brand actions for exec.
115*9acbbeafSnn35248  */
116*9acbbeafSnn35248 #define	EBA_NONE	0
117*9acbbeafSnn35248 #define	EBA_NATIVE	1
118*9acbbeafSnn35248 #define	EBA_BRAND	2
119*9acbbeafSnn35248 
120*9acbbeafSnn35248 /*
1217c478bd9Sstevel@tonic-gate  * The following macro is a machine dependent encapsulation of
1227c478bd9Sstevel@tonic-gate  * postfix processing to hide the stack direction from elf.c
1237c478bd9Sstevel@tonic-gate  * thereby making the elf.c code machine independent.
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate #define	execpoststack(ARGS, ARRAYADDR, BYTESIZE) \
1267c478bd9Sstevel@tonic-gate 	(copyout((caddr_t)(ARRAYADDR), (ARGS)->stackend, (BYTESIZE)) ? EFAULT \
1277c478bd9Sstevel@tonic-gate 		: (((ARGS)->stackend += (BYTESIZE)), 0))
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * This provides the current user stack address for an object of size BYTESIZE.
1317c478bd9Sstevel@tonic-gate  * Used to determine the stack address just before applying execpoststack().
1327c478bd9Sstevel@tonic-gate  */
1337c478bd9Sstevel@tonic-gate #define	stackaddress(ARGS, BYTESIZE)	((ARGS)->stackend)
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate /*
1367c478bd9Sstevel@tonic-gate  * Macro to add attribute/values the aux vector under construction.
1377c478bd9Sstevel@tonic-gate  */
1387c478bd9Sstevel@tonic-gate /* BEGIN CSTYLED */
1397c478bd9Sstevel@tonic-gate #if ((_LONG_ALIGNMENT == (2 * _INT_ALIGNMENT)) || \
1407c478bd9Sstevel@tonic-gate      (_POINTER_ALIGNMENT == (2 * _INT_ALIGNMENT)))
1417c478bd9Sstevel@tonic-gate /* END CSTYLED */
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * This convoluted stuff is necessitated by the fact that there is
1447c478bd9Sstevel@tonic-gate  * potential padding in the aux vector, but not necessarily and
1457c478bd9Sstevel@tonic-gate  * without clearing the padding there is a small, but potential
1467c478bd9Sstevel@tonic-gate  * security hole.
1477c478bd9Sstevel@tonic-gate  */
1487c478bd9Sstevel@tonic-gate #define	ADDAUX(p, a, v)	{		\
1497c478bd9Sstevel@tonic-gate 		(&(p)->a_type)[1] = 0;	\
1507c478bd9Sstevel@tonic-gate 		(p)->a_type = (a);	\
1517c478bd9Sstevel@tonic-gate 		(p)->a_un.a_val = (v);	\
1527c478bd9Sstevel@tonic-gate 		++(p);			\
1537c478bd9Sstevel@tonic-gate 	}
1547c478bd9Sstevel@tonic-gate #else
1557c478bd9Sstevel@tonic-gate #define	ADDAUX(p, a, v)	{			\
1567c478bd9Sstevel@tonic-gate 		(p)->a_type = (a);		\
1577c478bd9Sstevel@tonic-gate 		((p)++)->a_un.a_val = (v);	\
1587c478bd9Sstevel@tonic-gate 	}
1597c478bd9Sstevel@tonic-gate #endif
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate #define	INTPSZ	MAXPATHLEN
1627c478bd9Sstevel@tonic-gate typedef struct intpdata {
1637c478bd9Sstevel@tonic-gate 	char	*intp;
1647c478bd9Sstevel@tonic-gate 	char	*intp_name;
1657c478bd9Sstevel@tonic-gate 	char	*intp_arg;
1667c478bd9Sstevel@tonic-gate } intpdata_t;
1677c478bd9Sstevel@tonic-gate 
168cc4b03b5Scasper #define	EXECSETID_SETID		0x1 /* setid exec */
169cc4b03b5Scasper #define	EXECSETID_UGIDS		0x2 /* [ug]ids mismatch */
170cc4b03b5Scasper #define	EXECSETID_PRIVS		0x4 /* more privs than before */
171cc4b03b5Scasper 
1727c478bd9Sstevel@tonic-gate struct execsw {
1737c478bd9Sstevel@tonic-gate 	char	*exec_magic;
1747c478bd9Sstevel@tonic-gate 	int	exec_magoff;
1757c478bd9Sstevel@tonic-gate 	int	exec_maglen;
1767c478bd9Sstevel@tonic-gate 	int	(*exec_func)(struct vnode *vp, struct execa *uap,
1777c478bd9Sstevel@tonic-gate 		    struct uarg *args, struct intpdata *idata, int level,
1787c478bd9Sstevel@tonic-gate 		    long *execsz, int setid, caddr_t exec_file,
179*9acbbeafSnn35248 		    struct cred *cred, int brand_action);
1807c478bd9Sstevel@tonic-gate 	int	(*exec_core)(struct vnode *vp, struct proc *p,
1817c478bd9Sstevel@tonic-gate 		    struct cred *cred, rlim64_t rlimit, int sig,
1827c478bd9Sstevel@tonic-gate 		    core_content_t content);
1837c478bd9Sstevel@tonic-gate 	krwlock_t	*exec_lock;
1847c478bd9Sstevel@tonic-gate };
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate extern short elfmagic;
1877c478bd9Sstevel@tonic-gate extern short intpmagic;
1887c478bd9Sstevel@tonic-gate extern short javamagic;
1897c478bd9Sstevel@tonic-gate #if defined(__sparc)
1907c478bd9Sstevel@tonic-gate extern short aout_zmagic;
1917c478bd9Sstevel@tonic-gate extern short aout_nmagic;
1927c478bd9Sstevel@tonic-gate extern short aout_omagic;
1937c478bd9Sstevel@tonic-gate #endif
1947c478bd9Sstevel@tonic-gate extern short nomagic;
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate extern char elf32magicstr[];
1977c478bd9Sstevel@tonic-gate extern char elf64magicstr[];
1987c478bd9Sstevel@tonic-gate extern char intpmagicstr[];
1997c478bd9Sstevel@tonic-gate extern char javamagicstr[];
2007c478bd9Sstevel@tonic-gate #if defined(__sparc)
2017c478bd9Sstevel@tonic-gate extern char aout_nmagicstr[];
2027c478bd9Sstevel@tonic-gate extern char aout_zmagicstr[];
2037c478bd9Sstevel@tonic-gate extern char aout_omagicstr[];
2047c478bd9Sstevel@tonic-gate #endif
2057c478bd9Sstevel@tonic-gate extern char nomagicstr[];
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate extern int exec_args(execa_t *, uarg_t *, intpdata_t *, void **);
2087c478bd9Sstevel@tonic-gate extern int exec(const char *fname, const char **argp);
2097c478bd9Sstevel@tonic-gate extern int exece(const char *fname, const char **argp, const char **envp);
2107c478bd9Sstevel@tonic-gate extern int exec_common(const char *fname, const char **argp,
211*9acbbeafSnn35248     const char **envp, int brand_action);
2127c478bd9Sstevel@tonic-gate extern int gexec(vnode_t **vp, struct execa *uap, struct uarg *args,
2137c478bd9Sstevel@tonic-gate     struct intpdata *idata, int level, long *execsz, caddr_t exec_file,
214*9acbbeafSnn35248     struct cred *cred, int brand_action);
2157c478bd9Sstevel@tonic-gate extern struct execsw *allocate_execsw(char *name, char *magic,
2167c478bd9Sstevel@tonic-gate     size_t magic_size);
2177c478bd9Sstevel@tonic-gate extern struct execsw *findexecsw(char *magic);
2187c478bd9Sstevel@tonic-gate extern struct execsw *findexec_by_hdr(char *header);
2197c478bd9Sstevel@tonic-gate extern struct execsw *findexec_by_magic(char *magic);
2207c478bd9Sstevel@tonic-gate extern int execpermissions(struct vnode *vp, struct vattr *vattrp,
2217c478bd9Sstevel@tonic-gate     struct uarg *args);
2227c478bd9Sstevel@tonic-gate extern int execmap(vnode_t *vp, caddr_t addr, size_t len, size_t zfodlen,
2237c478bd9Sstevel@tonic-gate     off_t offset, int prot, int page, uint_t);
2247c478bd9Sstevel@tonic-gate extern void setexecenv(struct execenv *ep);
2257c478bd9Sstevel@tonic-gate extern int execopen(struct vnode **vpp, int *fdp);
2267c478bd9Sstevel@tonic-gate extern int execclose(int fd);
2277c478bd9Sstevel@tonic-gate extern void setregs(uarg_t *);
2287c478bd9Sstevel@tonic-gate extern void exec_set_sp(size_t);
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate /*
2317c478bd9Sstevel@tonic-gate  * Utility functions for exec module core routines:
2327c478bd9Sstevel@tonic-gate  */
2337c478bd9Sstevel@tonic-gate extern int core_seg(proc_t *, vnode_t *, offset_t, caddr_t,
2347c478bd9Sstevel@tonic-gate     size_t, rlim64_t, cred_t *);
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate extern int core_write(vnode_t *, enum uio_seg, offset_t,
2377c478bd9Sstevel@tonic-gate     const void *, size_t, rlim64_t, cred_t *);
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate /* a.out stuff */
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate struct exec;
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate extern caddr_t gettmem(struct exec *exp);
2447c478bd9Sstevel@tonic-gate extern caddr_t getdmem(struct exec *exp);
2457c478bd9Sstevel@tonic-gate extern ulong_t getdfile(struct exec *exp);
2467c478bd9Sstevel@tonic-gate extern uint_t gettfile(struct exec *exp);
2477c478bd9Sstevel@tonic-gate extern int chkaout(struct exdata *exp);
2487c478bd9Sstevel@tonic-gate extern void getexinfo(struct exdata *edp_in, struct exdata *edp_out,
2497c478bd9Sstevel@tonic-gate     int *pagetext, int *pagedata);
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2547c478bd9Sstevel@tonic-gate }
2557c478bd9Sstevel@tonic-gate #endif
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate #endif /* _SYS_EXEC_H */
258