xref: /onnv-gate/usr/src/uts/common/sys/exec.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #ifndef _SYS_EXEC_H
32*0Sstevel@tonic-gate #define	_SYS_EXEC_H
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #include <sys/systm.h>
37*0Sstevel@tonic-gate #include <vm/seg.h>
38*0Sstevel@tonic-gate #include <vm/seg_vn.h>
39*0Sstevel@tonic-gate #include <sys/model.h>
40*0Sstevel@tonic-gate #include <sys/uio.h>
41*0Sstevel@tonic-gate #include <sys/corectl.h>
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate #ifdef	__cplusplus
44*0Sstevel@tonic-gate extern "C" {
45*0Sstevel@tonic-gate #endif
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate /*
48*0Sstevel@tonic-gate  * Number of bytes to read for magic string
49*0Sstevel@tonic-gate  */
50*0Sstevel@tonic-gate #define	MAGIC_BYTES	8
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate #define	getexmag(x)	(((x)[0] << 8) + (x)[1])
53*0Sstevel@tonic-gate 
54*0Sstevel@tonic-gate typedef struct execa {
55*0Sstevel@tonic-gate 	const char *fname;
56*0Sstevel@tonic-gate 	const char **argp;
57*0Sstevel@tonic-gate 	const char **envp;
58*0Sstevel@tonic-gate } execa_t;
59*0Sstevel@tonic-gate 
60*0Sstevel@tonic-gate typedef struct execenv {
61*0Sstevel@tonic-gate 	caddr_t ex_bssbase;
62*0Sstevel@tonic-gate 	caddr_t ex_brkbase;
63*0Sstevel@tonic-gate 	size_t	ex_brksize;
64*0Sstevel@tonic-gate 	vnode_t *ex_vp;
65*0Sstevel@tonic-gate 	short   ex_magic;
66*0Sstevel@tonic-gate } execenv_t;
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate #ifdef _KERNEL
69*0Sstevel@tonic-gate 
70*0Sstevel@tonic-gate #define	LOADABLE_EXEC(e)	((e)->exec_lock)
71*0Sstevel@tonic-gate #define	LOADED_EXEC(e)		((e)->exec_func)
72*0Sstevel@tonic-gate 
73*0Sstevel@tonic-gate extern int nexectype;		/* number of elements in execsw */
74*0Sstevel@tonic-gate extern struct execsw execsw[];
75*0Sstevel@tonic-gate extern kmutex_t execsw_lock;
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate /*
78*0Sstevel@tonic-gate  * User argument structure for passing exec information around between the
79*0Sstevel@tonic-gate  * common and machine-dependent portions of exec and the exec modules.
80*0Sstevel@tonic-gate  */
81*0Sstevel@tonic-gate typedef struct uarg {
82*0Sstevel@tonic-gate 	ssize_t	na;
83*0Sstevel@tonic-gate 	ssize_t	ne;
84*0Sstevel@tonic-gate 	ssize_t	nc;
85*0Sstevel@tonic-gate 	ssize_t arglen;
86*0Sstevel@tonic-gate 	char	*fname;
87*0Sstevel@tonic-gate 	char	*pathname;
88*0Sstevel@tonic-gate 	ssize_t	auxsize;
89*0Sstevel@tonic-gate 	caddr_t	stackend;
90*0Sstevel@tonic-gate 	size_t	stk_align;
91*0Sstevel@tonic-gate 	size_t	stk_size;
92*0Sstevel@tonic-gate 	char	*stk_base;
93*0Sstevel@tonic-gate 	char	*stk_strp;
94*0Sstevel@tonic-gate 	int	*stk_offp;
95*0Sstevel@tonic-gate 	size_t	usrstack_size;
96*0Sstevel@tonic-gate 	uint_t	stk_prot;
97*0Sstevel@tonic-gate 	uint_t	dat_prot;
98*0Sstevel@tonic-gate 	int	traceinval;
99*0Sstevel@tonic-gate 	model_t	to_model;
100*0Sstevel@tonic-gate 	model_t	from_model;
101*0Sstevel@tonic-gate 	size_t	to_ptrsize;
102*0Sstevel@tonic-gate 	size_t	from_ptrsize;
103*0Sstevel@tonic-gate 	size_t	ncargs;
104*0Sstevel@tonic-gate 	struct execsw *execswp;
105*0Sstevel@tonic-gate 	uint_t	stkpageszc;
106*0Sstevel@tonic-gate 	uint_t	brkpageszc;
107*0Sstevel@tonic-gate 	uintptr_t entry;
108*0Sstevel@tonic-gate 	uintptr_t thrptr;
109*0Sstevel@tonic-gate } uarg_t;
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate /*
112*0Sstevel@tonic-gate  * The following macro is a machine dependent encapsulation of
113*0Sstevel@tonic-gate  * postfix processing to hide the stack direction from elf.c
114*0Sstevel@tonic-gate  * thereby making the elf.c code machine independent.
115*0Sstevel@tonic-gate  */
116*0Sstevel@tonic-gate #define	execpoststack(ARGS, ARRAYADDR, BYTESIZE) \
117*0Sstevel@tonic-gate 	(copyout((caddr_t)(ARRAYADDR), (ARGS)->stackend, (BYTESIZE)) ? EFAULT \
118*0Sstevel@tonic-gate 		: (((ARGS)->stackend += (BYTESIZE)), 0))
119*0Sstevel@tonic-gate 
120*0Sstevel@tonic-gate /*
121*0Sstevel@tonic-gate  * This provides the current user stack address for an object of size BYTESIZE.
122*0Sstevel@tonic-gate  * Used to determine the stack address just before applying execpoststack().
123*0Sstevel@tonic-gate  */
124*0Sstevel@tonic-gate #define	stackaddress(ARGS, BYTESIZE)	((ARGS)->stackend)
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate /*
127*0Sstevel@tonic-gate  * Macro to add attribute/values the aux vector under construction.
128*0Sstevel@tonic-gate  */
129*0Sstevel@tonic-gate /* BEGIN CSTYLED */
130*0Sstevel@tonic-gate #if ((_LONG_ALIGNMENT == (2 * _INT_ALIGNMENT)) || \
131*0Sstevel@tonic-gate      (_POINTER_ALIGNMENT == (2 * _INT_ALIGNMENT)))
132*0Sstevel@tonic-gate /* END CSTYLED */
133*0Sstevel@tonic-gate /*
134*0Sstevel@tonic-gate  * This convoluted stuff is necessitated by the fact that there is
135*0Sstevel@tonic-gate  * potential padding in the aux vector, but not necessarily and
136*0Sstevel@tonic-gate  * without clearing the padding there is a small, but potential
137*0Sstevel@tonic-gate  * security hole.
138*0Sstevel@tonic-gate  */
139*0Sstevel@tonic-gate #define	ADDAUX(p, a, v)	{		\
140*0Sstevel@tonic-gate 		(&(p)->a_type)[1] = 0;	\
141*0Sstevel@tonic-gate 		(p)->a_type = (a);	\
142*0Sstevel@tonic-gate 		(p)->a_un.a_val = (v);	\
143*0Sstevel@tonic-gate 		++(p);			\
144*0Sstevel@tonic-gate 	}
145*0Sstevel@tonic-gate #else
146*0Sstevel@tonic-gate #define	ADDAUX(p, a, v)	{			\
147*0Sstevel@tonic-gate 		(p)->a_type = (a);		\
148*0Sstevel@tonic-gate 		((p)++)->a_un.a_val = (v);	\
149*0Sstevel@tonic-gate 	}
150*0Sstevel@tonic-gate #endif
151*0Sstevel@tonic-gate 
152*0Sstevel@tonic-gate #define	INTPSZ	MAXPATHLEN
153*0Sstevel@tonic-gate typedef struct intpdata {
154*0Sstevel@tonic-gate 	char	*intp;
155*0Sstevel@tonic-gate 	char	*intp_name;
156*0Sstevel@tonic-gate 	char	*intp_arg;
157*0Sstevel@tonic-gate } intpdata_t;
158*0Sstevel@tonic-gate 
159*0Sstevel@tonic-gate struct execsw {
160*0Sstevel@tonic-gate 	char	*exec_magic;
161*0Sstevel@tonic-gate 	int	exec_magoff;
162*0Sstevel@tonic-gate 	int	exec_maglen;
163*0Sstevel@tonic-gate 	int	(*exec_func)(struct vnode *vp, struct execa *uap,
164*0Sstevel@tonic-gate 		    struct uarg *args, struct intpdata *idata, int level,
165*0Sstevel@tonic-gate 		    long *execsz, int setid, caddr_t exec_file,
166*0Sstevel@tonic-gate 		    struct cred *cred);
167*0Sstevel@tonic-gate 	int	(*exec_core)(struct vnode *vp, struct proc *p,
168*0Sstevel@tonic-gate 		    struct cred *cred, rlim64_t rlimit, int sig,
169*0Sstevel@tonic-gate 		    core_content_t content);
170*0Sstevel@tonic-gate 	krwlock_t	*exec_lock;
171*0Sstevel@tonic-gate };
172*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate extern short elfmagic;
174*0Sstevel@tonic-gate extern short intpmagic;
175*0Sstevel@tonic-gate extern short javamagic;
176*0Sstevel@tonic-gate #if defined(__sparc)
177*0Sstevel@tonic-gate extern short aout_zmagic;
178*0Sstevel@tonic-gate extern short aout_nmagic;
179*0Sstevel@tonic-gate extern short aout_omagic;
180*0Sstevel@tonic-gate #endif
181*0Sstevel@tonic-gate extern short nomagic;
182*0Sstevel@tonic-gate 
183*0Sstevel@tonic-gate extern char elf32magicstr[];
184*0Sstevel@tonic-gate extern char elf64magicstr[];
185*0Sstevel@tonic-gate extern char intpmagicstr[];
186*0Sstevel@tonic-gate extern char javamagicstr[];
187*0Sstevel@tonic-gate #if defined(__sparc)
188*0Sstevel@tonic-gate extern char aout_nmagicstr[];
189*0Sstevel@tonic-gate extern char aout_zmagicstr[];
190*0Sstevel@tonic-gate extern char aout_omagicstr[];
191*0Sstevel@tonic-gate #endif
192*0Sstevel@tonic-gate extern char nomagicstr[];
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate extern int exec_args(execa_t *, uarg_t *, intpdata_t *, void **);
195*0Sstevel@tonic-gate extern int exec(const char *fname, const char **argp);
196*0Sstevel@tonic-gate extern int exece(const char *fname, const char **argp, const char **envp);
197*0Sstevel@tonic-gate extern int exec_common(const char *fname, const char **argp,
198*0Sstevel@tonic-gate     const char **envp);
199*0Sstevel@tonic-gate extern int gexec(vnode_t **vp, struct execa *uap, struct uarg *args,
200*0Sstevel@tonic-gate     struct intpdata *idata, int level, long *execsz, caddr_t exec_file,
201*0Sstevel@tonic-gate     struct cred *cred);
202*0Sstevel@tonic-gate extern struct execsw *allocate_execsw(char *name, char *magic,
203*0Sstevel@tonic-gate     size_t magic_size);
204*0Sstevel@tonic-gate extern struct execsw *findexecsw(char *magic);
205*0Sstevel@tonic-gate extern struct execsw *findexec_by_hdr(char *header);
206*0Sstevel@tonic-gate extern struct execsw *findexec_by_magic(char *magic);
207*0Sstevel@tonic-gate extern int execpermissions(struct vnode *vp, struct vattr *vattrp,
208*0Sstevel@tonic-gate     struct uarg *args);
209*0Sstevel@tonic-gate extern int execmap(vnode_t *vp, caddr_t addr, size_t len, size_t zfodlen,
210*0Sstevel@tonic-gate     off_t offset, int prot, int page, uint_t);
211*0Sstevel@tonic-gate extern void setexecenv(struct execenv *ep);
212*0Sstevel@tonic-gate extern int execopen(struct vnode **vpp, int *fdp);
213*0Sstevel@tonic-gate extern int execclose(int fd);
214*0Sstevel@tonic-gate extern void setregs(uarg_t *);
215*0Sstevel@tonic-gate extern void exec_set_sp(size_t);
216*0Sstevel@tonic-gate 
217*0Sstevel@tonic-gate /*
218*0Sstevel@tonic-gate  * Utility functions for exec module core routines:
219*0Sstevel@tonic-gate  */
220*0Sstevel@tonic-gate extern int core_seg(proc_t *, vnode_t *, offset_t, caddr_t,
221*0Sstevel@tonic-gate     size_t, rlim64_t, cred_t *);
222*0Sstevel@tonic-gate 
223*0Sstevel@tonic-gate extern int core_write(vnode_t *, enum uio_seg, offset_t,
224*0Sstevel@tonic-gate     const void *, size_t, rlim64_t, cred_t *);
225*0Sstevel@tonic-gate 
226*0Sstevel@tonic-gate /* a.out stuff */
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate struct exec;
229*0Sstevel@tonic-gate 
230*0Sstevel@tonic-gate extern caddr_t gettmem(struct exec *exp);
231*0Sstevel@tonic-gate extern caddr_t getdmem(struct exec *exp);
232*0Sstevel@tonic-gate extern ulong_t getdfile(struct exec *exp);
233*0Sstevel@tonic-gate extern uint_t gettfile(struct exec *exp);
234*0Sstevel@tonic-gate extern int chkaout(struct exdata *exp);
235*0Sstevel@tonic-gate extern void getexinfo(struct exdata *edp_in, struct exdata *edp_out,
236*0Sstevel@tonic-gate     int *pagetext, int *pagedata);
237*0Sstevel@tonic-gate 
238*0Sstevel@tonic-gate #endif	/* _KERNEL */
239*0Sstevel@tonic-gate 
240*0Sstevel@tonic-gate #ifdef	__cplusplus
241*0Sstevel@tonic-gate }
242*0Sstevel@tonic-gate #endif
243*0Sstevel@tonic-gate 
244*0Sstevel@tonic-gate #endif /* _SYS_EXEC_H */
245