xref: /titanic_44/usr/src/uts/common/sys/exec.h (revision 07678296a66d425e65d218730836cc0162649ce4)
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 /*
22396a100bSedp  * Copyright 2007 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>
41396a100bSedp #include <sys/machelf.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
447c478bd9Sstevel@tonic-gate extern "C" {
457c478bd9Sstevel@tonic-gate #endif
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Number of bytes to read for magic string
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate #define	MAGIC_BYTES	8
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #define	getexmag(x)	(((x)[0] << 8) + (x)[1])
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate typedef struct execa {
557c478bd9Sstevel@tonic-gate 	const char *fname;
567c478bd9Sstevel@tonic-gate 	const char **argp;
577c478bd9Sstevel@tonic-gate 	const char **envp;
587c478bd9Sstevel@tonic-gate } execa_t;
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate typedef struct execenv {
617c478bd9Sstevel@tonic-gate 	caddr_t ex_bssbase;
627c478bd9Sstevel@tonic-gate 	caddr_t ex_brkbase;
637c478bd9Sstevel@tonic-gate 	size_t	ex_brksize;
647c478bd9Sstevel@tonic-gate 	vnode_t *ex_vp;
657c478bd9Sstevel@tonic-gate 	short   ex_magic;
667c478bd9Sstevel@tonic-gate } execenv_t;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #ifdef _KERNEL
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #define	LOADABLE_EXEC(e)	((e)->exec_lock)
717c478bd9Sstevel@tonic-gate #define	LOADED_EXEC(e)		((e)->exec_func)
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate extern int nexectype;		/* number of elements in execsw */
747c478bd9Sstevel@tonic-gate extern struct execsw execsw[];
757c478bd9Sstevel@tonic-gate extern kmutex_t execsw_lock;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * User argument structure for passing exec information around between the
797c478bd9Sstevel@tonic-gate  * common and machine-dependent portions of exec and the exec modules.
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate typedef struct uarg {
827c478bd9Sstevel@tonic-gate 	ssize_t	na;
837c478bd9Sstevel@tonic-gate 	ssize_t	ne;
847c478bd9Sstevel@tonic-gate 	ssize_t	nc;
857c478bd9Sstevel@tonic-gate 	ssize_t arglen;
867c478bd9Sstevel@tonic-gate 	char	*fname;
877c478bd9Sstevel@tonic-gate 	char	*pathname;
887c478bd9Sstevel@tonic-gate 	ssize_t	auxsize;
897c478bd9Sstevel@tonic-gate 	caddr_t	stackend;
907c478bd9Sstevel@tonic-gate 	size_t	stk_align;
917c478bd9Sstevel@tonic-gate 	size_t	stk_size;
927c478bd9Sstevel@tonic-gate 	char	*stk_base;
937c478bd9Sstevel@tonic-gate 	char	*stk_strp;
947c478bd9Sstevel@tonic-gate 	int	*stk_offp;
957c478bd9Sstevel@tonic-gate 	size_t	usrstack_size;
967c478bd9Sstevel@tonic-gate 	uint_t	stk_prot;
977c478bd9Sstevel@tonic-gate 	uint_t	dat_prot;
987c478bd9Sstevel@tonic-gate 	int	traceinval;
997c478bd9Sstevel@tonic-gate 	model_t	to_model;
1007c478bd9Sstevel@tonic-gate 	model_t	from_model;
1017c478bd9Sstevel@tonic-gate 	size_t	to_ptrsize;
1027c478bd9Sstevel@tonic-gate 	size_t	from_ptrsize;
1037c478bd9Sstevel@tonic-gate 	size_t	ncargs;
1047c478bd9Sstevel@tonic-gate 	struct execsw *execswp;
1057c478bd9Sstevel@tonic-gate 	uintptr_t entry;
1067c478bd9Sstevel@tonic-gate 	uintptr_t thrptr;
10705d3dc4bSpaulsan 	vnode_t	*ex_vp;
1089acbbeafSnn35248 	char	*emulator;
1099acbbeafSnn35248 	char	*brandname;
110*07678296Ssl108498 	char	*auxp_brand; /* address of first brand auxv on user stack */
1117c478bd9Sstevel@tonic-gate } uarg_t;
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
1149acbbeafSnn35248  * Possible brand actions for exec.
1159acbbeafSnn35248  */
1169acbbeafSnn35248 #define	EBA_NONE	0
1179acbbeafSnn35248 #define	EBA_NATIVE	1
1189acbbeafSnn35248 #define	EBA_BRAND	2
1199acbbeafSnn35248 
1209acbbeafSnn35248 /*
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,
1799acbbeafSnn35248 		    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,
2119acbbeafSnn35248     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,
2149acbbeafSnn35248     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 /*
231396a100bSedp  * Utility functions for branded process executing
232396a100bSedp  */
233396a100bSedp #if !defined(_ELF32_COMPAT)
234396a100bSedp /*
235396a100bSedp  * When compiling 64-bit kernels we don't want these definitions included
236396a100bSedp  * when compiling the 32-bit compatability elf code in the elfexec module.
237396a100bSedp  */
238396a100bSedp extern int elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
239396a100bSedp     long *, int, caddr_t, cred_t *, int);
240396a100bSedp extern int mapexec_brand(vnode_t *, uarg_t *, Ehdr *, Addr *,
241*07678296Ssl108498     intptr_t *, caddr_t, int *, caddr_t *, caddr_t *, size_t *, uintptr_t *);
242396a100bSedp #endif /* !_ELF32_COMPAT */
243396a100bSedp 
244396a100bSedp #if defined(_LP64)
245396a100bSedp extern int elf32exec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
246396a100bSedp     long *, int, caddr_t, cred_t *, int);
247396a100bSedp extern int mapexec32_brand(vnode_t *, uarg_t *, Elf32_Ehdr *, Elf32_Addr *,
248*07678296Ssl108498     intptr_t *, caddr_t, int *, caddr_t *, caddr_t *, size_t *, uintptr_t *);
249396a100bSedp #endif  /* _LP64 */
250396a100bSedp 
251396a100bSedp /*
2527c478bd9Sstevel@tonic-gate  * Utility functions for exec module core routines:
2537c478bd9Sstevel@tonic-gate  */
2547c478bd9Sstevel@tonic-gate extern int core_seg(proc_t *, vnode_t *, offset_t, caddr_t,
2557c478bd9Sstevel@tonic-gate     size_t, rlim64_t, cred_t *);
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate extern int core_write(vnode_t *, enum uio_seg, offset_t,
2587c478bd9Sstevel@tonic-gate     const void *, size_t, rlim64_t, cred_t *);
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate /* a.out stuff */
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate struct exec;
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate extern caddr_t gettmem(struct exec *exp);
2657c478bd9Sstevel@tonic-gate extern caddr_t getdmem(struct exec *exp);
2667c478bd9Sstevel@tonic-gate extern ulong_t getdfile(struct exec *exp);
2677c478bd9Sstevel@tonic-gate extern uint_t gettfile(struct exec *exp);
2687c478bd9Sstevel@tonic-gate extern int chkaout(struct exdata *exp);
2697c478bd9Sstevel@tonic-gate extern void getexinfo(struct exdata *edp_in, struct exdata *edp_out,
2707c478bd9Sstevel@tonic-gate     int *pagetext, int *pagedata);
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2757c478bd9Sstevel@tonic-gate }
2767c478bd9Sstevel@tonic-gate #endif
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate #endif /* _SYS_EXEC_H */
279