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