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