xref: /titanic_51/usr/src/uts/common/sys/exec.h (revision 396a100be44de1a20eabaee45519160dea8333b4)
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 /*
22*396a100bSedp  * 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>
41*396a100bSedp #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;
1079acbbeafSnn35248 	char	*emulator;
1089acbbeafSnn35248 	char	*brandname;
109*396a100bSedp 	char	*auxp_brand_phdr; /* addr of brand phdr auxv on user stack */
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 
1857c478bd9Sstevel@tonic-gate extern short elfmagic;
1867c478bd9Sstevel@tonic-gate extern short intpmagic;
1877c478bd9Sstevel@tonic-gate extern short javamagic;
1887c478bd9Sstevel@tonic-gate #if defined(__sparc)
1897c478bd9Sstevel@tonic-gate extern short aout_zmagic;
1907c478bd9Sstevel@tonic-gate extern short aout_nmagic;
1917c478bd9Sstevel@tonic-gate extern short aout_omagic;
1927c478bd9Sstevel@tonic-gate #endif
1937c478bd9Sstevel@tonic-gate extern short nomagic;
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate extern char elf32magicstr[];
1967c478bd9Sstevel@tonic-gate extern char elf64magicstr[];
1977c478bd9Sstevel@tonic-gate extern char intpmagicstr[];
1987c478bd9Sstevel@tonic-gate extern char javamagicstr[];
1997c478bd9Sstevel@tonic-gate #if defined(__sparc)
2007c478bd9Sstevel@tonic-gate extern char aout_nmagicstr[];
2017c478bd9Sstevel@tonic-gate extern char aout_zmagicstr[];
2027c478bd9Sstevel@tonic-gate extern char aout_omagicstr[];
2037c478bd9Sstevel@tonic-gate #endif
2047c478bd9Sstevel@tonic-gate extern char nomagicstr[];
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate extern int exec_args(execa_t *, uarg_t *, intpdata_t *, void **);
2077c478bd9Sstevel@tonic-gate extern int exec(const char *fname, const char **argp);
2087c478bd9Sstevel@tonic-gate extern int exece(const char *fname, const char **argp, const char **envp);
2097c478bd9Sstevel@tonic-gate extern int exec_common(const char *fname, const char **argp,
2109acbbeafSnn35248     const char **envp, int brand_action);
2117c478bd9Sstevel@tonic-gate extern int gexec(vnode_t **vp, struct execa *uap, struct uarg *args,
2127c478bd9Sstevel@tonic-gate     struct intpdata *idata, int level, long *execsz, caddr_t exec_file,
2139acbbeafSnn35248     struct cred *cred, int brand_action);
2147c478bd9Sstevel@tonic-gate extern struct execsw *allocate_execsw(char *name, char *magic,
2157c478bd9Sstevel@tonic-gate     size_t magic_size);
2167c478bd9Sstevel@tonic-gate extern struct execsw *findexecsw(char *magic);
2177c478bd9Sstevel@tonic-gate extern struct execsw *findexec_by_hdr(char *header);
2187c478bd9Sstevel@tonic-gate extern struct execsw *findexec_by_magic(char *magic);
2197c478bd9Sstevel@tonic-gate extern int execpermissions(struct vnode *vp, struct vattr *vattrp,
2207c478bd9Sstevel@tonic-gate     struct uarg *args);
2217c478bd9Sstevel@tonic-gate extern int execmap(vnode_t *vp, caddr_t addr, size_t len, size_t zfodlen,
2227c478bd9Sstevel@tonic-gate     off_t offset, int prot, int page, uint_t);
2237c478bd9Sstevel@tonic-gate extern void setexecenv(struct execenv *ep);
2247c478bd9Sstevel@tonic-gate extern int execopen(struct vnode **vpp, int *fdp);
2257c478bd9Sstevel@tonic-gate extern int execclose(int fd);
2267c478bd9Sstevel@tonic-gate extern void setregs(uarg_t *);
2277c478bd9Sstevel@tonic-gate extern void exec_set_sp(size_t);
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate /*
230*396a100bSedp  * Utility functions for branded process executing
231*396a100bSedp  */
232*396a100bSedp #if !defined(_ELF32_COMPAT)
233*396a100bSedp /*
234*396a100bSedp  * When compiling 64-bit kernels we don't want these definitions included
235*396a100bSedp  * when compiling the 32-bit compatability elf code in the elfexec module.
236*396a100bSedp  */
237*396a100bSedp extern int elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
238*396a100bSedp     long *, int, caddr_t, cred_t *, int);
239*396a100bSedp extern int mapexec_brand(vnode_t *, uarg_t *, Ehdr *, Addr *,
240*396a100bSedp     intptr_t *, caddr_t, int *, caddr_t *, caddr_t *, size_t *);
241*396a100bSedp #endif /* !_ELF32_COMPAT */
242*396a100bSedp 
243*396a100bSedp #if defined(_LP64)
244*396a100bSedp extern int elf32exec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
245*396a100bSedp     long *, int, caddr_t, cred_t *, int);
246*396a100bSedp extern int mapexec32_brand(vnode_t *, uarg_t *, Elf32_Ehdr *, Elf32_Addr *,
247*396a100bSedp     intptr_t *, caddr_t, int *, caddr_t *, caddr_t *, size_t *);
248*396a100bSedp #endif	/* _LP64 */
249*396a100bSedp 
250*396a100bSedp /*
2517c478bd9Sstevel@tonic-gate  * Utility functions for exec module core routines:
2527c478bd9Sstevel@tonic-gate  */
2537c478bd9Sstevel@tonic-gate extern int core_seg(proc_t *, vnode_t *, offset_t, caddr_t,
2547c478bd9Sstevel@tonic-gate     size_t, rlim64_t, cred_t *);
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate extern int core_write(vnode_t *, enum uio_seg, offset_t,
2577c478bd9Sstevel@tonic-gate     const void *, size_t, rlim64_t, cred_t *);
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate /* a.out stuff */
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate struct exec;
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate extern caddr_t gettmem(struct exec *exp);
2647c478bd9Sstevel@tonic-gate extern caddr_t getdmem(struct exec *exp);
2657c478bd9Sstevel@tonic-gate extern ulong_t getdfile(struct exec *exp);
2667c478bd9Sstevel@tonic-gate extern uint_t gettfile(struct exec *exp);
2677c478bd9Sstevel@tonic-gate extern int chkaout(struct exdata *exp);
2687c478bd9Sstevel@tonic-gate extern void getexinfo(struct exdata *edp_in, struct exdata *edp_out,
2697c478bd9Sstevel@tonic-gate     int *pagetext, int *pagedata);
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2747c478bd9Sstevel@tonic-gate }
2757c478bd9Sstevel@tonic-gate #endif
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate #endif /* _SYS_EXEC_H */
278