xref: /titanic_51/usr/src/uts/common/sys/exec.h (revision 263f549e5da8b32c4922f586afb365b8ae388a6c)
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  */
21a0de58d6SRoger A. Faulkner 
227c478bd9Sstevel@tonic-gate /*
23134a1f4eSCasper H.S. Dik  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
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 #ifndef _SYS_EXEC_H
307c478bd9Sstevel@tonic-gate #define	_SYS_EXEC_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/systm.h>
337c478bd9Sstevel@tonic-gate #include <vm/seg.h>
347c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
357c478bd9Sstevel@tonic-gate #include <sys/model.h>
367c478bd9Sstevel@tonic-gate #include <sys/uio.h>
377c478bd9Sstevel@tonic-gate #include <sys/corectl.h>
38396a100bSedp #include <sys/machelf.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
417c478bd9Sstevel@tonic-gate extern "C" {
427c478bd9Sstevel@tonic-gate #endif
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * Number of bytes to read for magic string
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate #define	MAGIC_BYTES	8
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate #define	getexmag(x)	(((x)[0] << 8) + (x)[1])
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate typedef struct execa {
527c478bd9Sstevel@tonic-gate 	const char *fname;
537c478bd9Sstevel@tonic-gate 	const char **argp;
547c478bd9Sstevel@tonic-gate 	const char **envp;
557c478bd9Sstevel@tonic-gate } execa_t;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate typedef struct execenv {
587c478bd9Sstevel@tonic-gate 	caddr_t ex_bssbase;
597c478bd9Sstevel@tonic-gate 	caddr_t ex_brkbase;
607c478bd9Sstevel@tonic-gate 	size_t	ex_brksize;
617c478bd9Sstevel@tonic-gate 	vnode_t *ex_vp;
627c478bd9Sstevel@tonic-gate 	short   ex_magic;
637c478bd9Sstevel@tonic-gate } execenv_t;
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate #ifdef _KERNEL
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #define	LOADABLE_EXEC(e)	((e)->exec_lock)
687c478bd9Sstevel@tonic-gate #define	LOADED_EXEC(e)		((e)->exec_func)
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * User argument structure for passing exec information around between the
737c478bd9Sstevel@tonic-gate  * common and machine-dependent portions of exec and the exec modules.
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate typedef struct uarg {
767c478bd9Sstevel@tonic-gate 	ssize_t	na;
777c478bd9Sstevel@tonic-gate 	ssize_t	ne;
787c478bd9Sstevel@tonic-gate 	ssize_t	nc;
797c478bd9Sstevel@tonic-gate 	ssize_t arglen;
807c478bd9Sstevel@tonic-gate 	char	*fname;
817c478bd9Sstevel@tonic-gate 	char	*pathname;
827c478bd9Sstevel@tonic-gate 	ssize_t	auxsize;
837c478bd9Sstevel@tonic-gate 	caddr_t	stackend;
847c478bd9Sstevel@tonic-gate 	size_t	stk_align;
857c478bd9Sstevel@tonic-gate 	size_t	stk_size;
867c478bd9Sstevel@tonic-gate 	char	*stk_base;
877c478bd9Sstevel@tonic-gate 	char	*stk_strp;
887c478bd9Sstevel@tonic-gate 	int	*stk_offp;
897c478bd9Sstevel@tonic-gate 	size_t	usrstack_size;
907c478bd9Sstevel@tonic-gate 	uint_t	stk_prot;
917c478bd9Sstevel@tonic-gate 	uint_t	dat_prot;
927c478bd9Sstevel@tonic-gate 	int	traceinval;
93a0de58d6SRoger A. Faulkner 	int	addr32;
947c478bd9Sstevel@tonic-gate 	model_t	to_model;
957c478bd9Sstevel@tonic-gate 	model_t	from_model;
967c478bd9Sstevel@tonic-gate 	size_t	to_ptrsize;
977c478bd9Sstevel@tonic-gate 	size_t	from_ptrsize;
987c478bd9Sstevel@tonic-gate 	size_t	ncargs;
997c478bd9Sstevel@tonic-gate 	struct execsw *execswp;
1007c478bd9Sstevel@tonic-gate 	uintptr_t entry;
1017c478bd9Sstevel@tonic-gate 	uintptr_t thrptr;
10205d3dc4bSpaulsan 	vnode_t	*ex_vp;
1039acbbeafSnn35248 	char	*emulator;
1049acbbeafSnn35248 	char	*brandname;
105b71d513aSedp 	char	*auxp_auxflags; /* addr of auxflags auxv on the user stack */
10607678296Ssl108498 	char	*auxp_brand; /* address of first brand auxv on user stack */
107134a1f4eSCasper H.S. Dik 	cred_t	*pfcred;
108134a1f4eSCasper H.S. Dik 	boolean_t scrubenv;
109*263f549eSPatrick Mooney 	uintptr_t commpage;
1107c478bd9Sstevel@tonic-gate } uarg_t;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /*
1139acbbeafSnn35248  * Possible brand actions for exec.
1149acbbeafSnn35248  */
1159acbbeafSnn35248 #define	EBA_NONE	0
1169acbbeafSnn35248 #define	EBA_NATIVE	1
1179acbbeafSnn35248 #define	EBA_BRAND	2
1189acbbeafSnn35248 
1199acbbeafSnn35248 /*
1207c478bd9Sstevel@tonic-gate  * The following macro is a machine dependent encapsulation of
1217c478bd9Sstevel@tonic-gate  * postfix processing to hide the stack direction from elf.c
1227c478bd9Sstevel@tonic-gate  * thereby making the elf.c code machine independent.
1237c478bd9Sstevel@tonic-gate  */
1247c478bd9Sstevel@tonic-gate #define	execpoststack(ARGS, ARRAYADDR, BYTESIZE) \
1257c478bd9Sstevel@tonic-gate 	(copyout((caddr_t)(ARRAYADDR), (ARGS)->stackend, (BYTESIZE)) ? EFAULT \
1267c478bd9Sstevel@tonic-gate 		: (((ARGS)->stackend += (BYTESIZE)), 0))
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * This provides the current user stack address for an object of size BYTESIZE.
1307c478bd9Sstevel@tonic-gate  * Used to determine the stack address just before applying execpoststack().
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate #define	stackaddress(ARGS, BYTESIZE)	((ARGS)->stackend)
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * Macro to add attribute/values the aux vector under construction.
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate /* BEGIN CSTYLED */
1387c478bd9Sstevel@tonic-gate #if ((_LONG_ALIGNMENT == (2 * _INT_ALIGNMENT)) || \
1397c478bd9Sstevel@tonic-gate      (_POINTER_ALIGNMENT == (2 * _INT_ALIGNMENT)))
1407c478bd9Sstevel@tonic-gate /* END CSTYLED */
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate  * This convoluted stuff is necessitated by the fact that there is
1437c478bd9Sstevel@tonic-gate  * potential padding in the aux vector, but not necessarily and
1447c478bd9Sstevel@tonic-gate  * without clearing the padding there is a small, but potential
1457c478bd9Sstevel@tonic-gate  * security hole.
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate #define	ADDAUX(p, a, v)	{		\
1487c478bd9Sstevel@tonic-gate 		(&(p)->a_type)[1] = 0;	\
1497c478bd9Sstevel@tonic-gate 		(p)->a_type = (a);	\
1507c478bd9Sstevel@tonic-gate 		(p)->a_un.a_val = (v);	\
1517c478bd9Sstevel@tonic-gate 		++(p);			\
1527c478bd9Sstevel@tonic-gate 	}
1537c478bd9Sstevel@tonic-gate #else
1547c478bd9Sstevel@tonic-gate #define	ADDAUX(p, a, v)	{			\
1557c478bd9Sstevel@tonic-gate 		(p)->a_type = (a);		\
1567c478bd9Sstevel@tonic-gate 		((p)++)->a_un.a_val = (v);	\
1577c478bd9Sstevel@tonic-gate 	}
1587c478bd9Sstevel@tonic-gate #endif
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #define	INTPSZ	MAXPATHLEN
1617c478bd9Sstevel@tonic-gate typedef struct intpdata {
1627c478bd9Sstevel@tonic-gate 	char	*intp;
1637c478bd9Sstevel@tonic-gate 	char	*intp_name;
1647c478bd9Sstevel@tonic-gate 	char	*intp_arg;
1657c478bd9Sstevel@tonic-gate } intpdata_t;
1667c478bd9Sstevel@tonic-gate 
167cc4b03b5Scasper #define	EXECSETID_SETID		0x1 /* setid exec */
168cc4b03b5Scasper #define	EXECSETID_UGIDS		0x2 /* [ug]ids mismatch */
169cc4b03b5Scasper #define	EXECSETID_PRIVS		0x4 /* more privs than before */
170cc4b03b5Scasper 
1717c478bd9Sstevel@tonic-gate struct execsw {
1727c478bd9Sstevel@tonic-gate 	char	*exec_magic;
1737c478bd9Sstevel@tonic-gate 	int	exec_magoff;
1747c478bd9Sstevel@tonic-gate 	int	exec_maglen;
1757c478bd9Sstevel@tonic-gate 	int	(*exec_func)(struct vnode *vp, struct execa *uap,
1767c478bd9Sstevel@tonic-gate 		    struct uarg *args, struct intpdata *idata, int level,
1777c478bd9Sstevel@tonic-gate 		    long *execsz, int setid, caddr_t exec_file,
1789acbbeafSnn35248 		    struct cred *cred, int brand_action);
1797c478bd9Sstevel@tonic-gate 	int	(*exec_core)(struct vnode *vp, struct proc *p,
1807c478bd9Sstevel@tonic-gate 		    struct cred *cred, rlim64_t rlimit, int sig,
1817c478bd9Sstevel@tonic-gate 		    core_content_t content);
1827c478bd9Sstevel@tonic-gate 	krwlock_t	*exec_lock;
1837c478bd9Sstevel@tonic-gate };
1847c478bd9Sstevel@tonic-gate 
185d67944fbSScott Rotondo extern int nexectype;		/* number of elements in execsw */
186d67944fbSScott Rotondo extern struct execsw execsw[];
187d67944fbSScott Rotondo extern kmutex_t execsw_lock;
188d67944fbSScott Rotondo 
1897c478bd9Sstevel@tonic-gate extern short elfmagic;
1907c478bd9Sstevel@tonic-gate extern short intpmagic;
1917c478bd9Sstevel@tonic-gate extern short javamagic;
1927c478bd9Sstevel@tonic-gate #if defined(__sparc)
1937c478bd9Sstevel@tonic-gate extern short aout_zmagic;
1947c478bd9Sstevel@tonic-gate extern short aout_nmagic;
1957c478bd9Sstevel@tonic-gate extern short aout_omagic;
1967c478bd9Sstevel@tonic-gate #endif
1977c478bd9Sstevel@tonic-gate extern short nomagic;
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate extern char elf32magicstr[];
2007c478bd9Sstevel@tonic-gate extern char elf64magicstr[];
2017c478bd9Sstevel@tonic-gate extern char intpmagicstr[];
2027c478bd9Sstevel@tonic-gate extern char javamagicstr[];
2037c478bd9Sstevel@tonic-gate #if defined(__sparc)
2047c478bd9Sstevel@tonic-gate extern char aout_nmagicstr[];
2057c478bd9Sstevel@tonic-gate extern char aout_zmagicstr[];
2067c478bd9Sstevel@tonic-gate extern char aout_omagicstr[];
2077c478bd9Sstevel@tonic-gate #endif
2087c478bd9Sstevel@tonic-gate extern char nomagicstr[];
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate extern int exec_args(execa_t *, uarg_t *, intpdata_t *, void **);
2117c478bd9Sstevel@tonic-gate extern int exece(const char *fname, const char **argp, const char **envp);
2127c478bd9Sstevel@tonic-gate extern int exec_common(const char *fname, const char **argp,
2139acbbeafSnn35248     const char **envp, int brand_action);
2147c478bd9Sstevel@tonic-gate extern int gexec(vnode_t **vp, struct execa *uap, struct uarg *args,
2157c478bd9Sstevel@tonic-gate     struct intpdata *idata, int level, long *execsz, caddr_t exec_file,
2169acbbeafSnn35248     struct cred *cred, int brand_action);
2177c478bd9Sstevel@tonic-gate extern struct execsw *allocate_execsw(char *name, char *magic,
2187c478bd9Sstevel@tonic-gate     size_t magic_size);
2197c478bd9Sstevel@tonic-gate extern struct execsw *findexecsw(char *magic);
2207c478bd9Sstevel@tonic-gate extern struct execsw *findexec_by_hdr(char *header);
2217c478bd9Sstevel@tonic-gate extern struct execsw *findexec_by_magic(char *magic);
2227c478bd9Sstevel@tonic-gate extern int execpermissions(struct vnode *vp, struct vattr *vattrp,
2237c478bd9Sstevel@tonic-gate     struct uarg *args);
2247c478bd9Sstevel@tonic-gate extern int execmap(vnode_t *vp, caddr_t addr, size_t len, size_t zfodlen,
2257c478bd9Sstevel@tonic-gate     off_t offset, int prot, int page, uint_t);
2267c478bd9Sstevel@tonic-gate extern void setexecenv(struct execenv *ep);
2277c478bd9Sstevel@tonic-gate extern int execopen(struct vnode **vpp, int *fdp);
2287c478bd9Sstevel@tonic-gate extern int execclose(int fd);
2297c478bd9Sstevel@tonic-gate extern void setregs(uarg_t *);
2307c478bd9Sstevel@tonic-gate extern void exec_set_sp(size_t);
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate /*
233396a100bSedp  * Utility functions for branded process executing
234396a100bSedp  */
235396a100bSedp #if !defined(_ELF32_COMPAT)
236396a100bSedp /*
237396a100bSedp  * When compiling 64-bit kernels we don't want these definitions included
238396a100bSedp  * when compiling the 32-bit compatability elf code in the elfexec module.
239396a100bSedp  */
240396a100bSedp extern int elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
241396a100bSedp     long *, int, caddr_t, cred_t *, int);
242396a100bSedp extern int mapexec_brand(vnode_t *, uarg_t *, Ehdr *, Addr *,
24307678296Ssl108498     intptr_t *, caddr_t, int *, caddr_t *, caddr_t *, size_t *, uintptr_t *);
244396a100bSedp #endif /* !_ELF32_COMPAT */
245396a100bSedp 
246396a100bSedp #if defined(_LP64)
247396a100bSedp extern int elf32exec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
248396a100bSedp     long *, int, caddr_t, cred_t *, int);
249396a100bSedp extern int mapexec32_brand(vnode_t *, uarg_t *, Elf32_Ehdr *, Elf32_Addr *,
25007678296Ssl108498     intptr_t *, caddr_t, int *, caddr_t *, caddr_t *, size_t *, uintptr_t *);
251396a100bSedp #endif  /* _LP64 */
252396a100bSedp 
253396a100bSedp /*
2547c478bd9Sstevel@tonic-gate  * Utility functions for exec module core routines:
2557c478bd9Sstevel@tonic-gate  */
2567c478bd9Sstevel@tonic-gate extern int core_seg(proc_t *, vnode_t *, offset_t, caddr_t,
2577c478bd9Sstevel@tonic-gate     size_t, rlim64_t, cred_t *);
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate extern int core_write(vnode_t *, enum uio_seg, offset_t,
2607c478bd9Sstevel@tonic-gate     const void *, size_t, rlim64_t, cred_t *);
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate /* a.out stuff */
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate struct exec;
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate extern caddr_t gettmem(struct exec *exp);
2677c478bd9Sstevel@tonic-gate extern caddr_t getdmem(struct exec *exp);
2687c478bd9Sstevel@tonic-gate extern ulong_t getdfile(struct exec *exp);
2697c478bd9Sstevel@tonic-gate extern uint_t gettfile(struct exec *exp);
2707c478bd9Sstevel@tonic-gate extern int chkaout(struct exdata *exp);
2717c478bd9Sstevel@tonic-gate extern void getexinfo(struct exdata *edp_in, struct exdata *edp_out,
2727c478bd9Sstevel@tonic-gate     int *pagetext, int *pagedata);
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate #endif
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate #endif /* _SYS_EXEC_H */
281