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.
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.
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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
33 #include <sys/systm.h>
35 #include <vm/seg_vn.h>
36 #include <sys/model.h>
38 #include <sys/corectl.h>
39 #include <sys/machelf.h>
46 * Number of bytes to read for magic string
50 #define getexmag(x) (((x)[0] << 8) + (x)[1])
52 typedef struct execa
{
58 typedef struct execenv
{
68 #define LOADABLE_EXEC(e) ((e)->exec_lock)
69 #define LOADED_EXEC(e) ((e)->exec_func)
71 extern int nexectype
; /* number of elements in execsw */
72 extern struct execsw execsw
[];
73 extern kmutex_t execsw_lock
;
76 * User argument structure for passing exec information around between the
77 * common and machine-dependent portions of exec and the exec modules.
103 struct execsw
*execswp
;
109 char *auxp_auxflags
; /* addr of auxflags auxv on the user stack */
110 char *auxp_brand
; /* address of first brand auxv on user stack */
114 * Possible brand actions for exec.
121 * The following macro is a machine dependent encapsulation of
122 * postfix processing to hide the stack direction from elf.c
123 * thereby making the elf.c code machine independent.
125 #define execpoststack(ARGS, ARRAYADDR, BYTESIZE) \
126 (copyout((caddr_t)(ARRAYADDR), (ARGS)->stackend, (BYTESIZE)) ? EFAULT \
127 : (((ARGS)->stackend += (BYTESIZE)), 0))
130 * This provides the current user stack address for an object of size BYTESIZE.
131 * Used to determine the stack address just before applying execpoststack().
133 #define stackaddress(ARGS, BYTESIZE) ((ARGS)->stackend)
136 * Macro to add attribute/values the aux vector under construction.
139 #if ((_LONG_ALIGNMENT == (2 * _INT_ALIGNMENT)) || \
140 (_POINTER_ALIGNMENT == (2 * _INT_ALIGNMENT)))
143 * This convoluted stuff is necessitated by the fact that there is
144 * potential padding in the aux vector, but not necessarily and
145 * without clearing the padding there is a small, but potential
148 #define ADDAUX(p, a, v) { \
149 (&(p)->a_type)[1] = 0; \
151 (p)->a_un.a_val = (v); \
155 #define ADDAUX(p, a, v) { \
157 ((p)++)->a_un.a_val = (v); \
161 #define INTPSZ MAXPATHLEN
162 typedef struct intpdata
{
168 #define EXECSETID_SETID 0x1 /* setid exec */
169 #define EXECSETID_UGIDS 0x2 /* [ug]ids mismatch */
170 #define EXECSETID_PRIVS 0x4 /* more privs than before */
176 int (*exec_func
)(struct vnode
*vp
, struct execa
*uap
,
177 struct uarg
*args
, struct intpdata
*idata
, int level
,
178 long *execsz
, int setid
, caddr_t exec_file
,
179 struct cred
*cred
, int brand_action
);
180 int (*exec_core
)(struct vnode
*vp
, struct proc
*p
,
181 struct cred
*cred
, rlim64_t rlimit
, int sig
,
182 core_content_t content
);
183 krwlock_t
*exec_lock
;
186 extern short elfmagic
;
187 extern short intpmagic
;
188 extern short javamagic
;
190 extern short aout_zmagic
;
191 extern short aout_nmagic
;
192 extern short aout_omagic
;
194 extern short nomagic
;
196 extern char elf32magicstr
[];
197 extern char elf64magicstr
[];
198 extern char intpmagicstr
[];
199 extern char javamagicstr
[];
201 extern char aout_nmagicstr
[];
202 extern char aout_zmagicstr
[];
203 extern char aout_omagicstr
[];
205 extern char nomagicstr
[];
207 extern int exec_args(execa_t
*, uarg_t
*, intpdata_t
*, void **);
208 extern int exec(const char *fname
, const char **argp
);
209 extern int exece(const char *fname
, const char **argp
, const char **envp
);
210 extern int exec_common(const char *fname
, const char **argp
,
211 const char **envp
, int brand_action
);
212 extern int gexec(vnode_t
**vp
, struct execa
*uap
, struct uarg
*args
,
213 struct intpdata
*idata
, int level
, long *execsz
, caddr_t exec_file
,
214 struct cred
*cred
, int brand_action
);
215 extern struct execsw
*allocate_execsw(char *name
, char *magic
,
217 extern struct execsw
*findexecsw(char *magic
);
218 extern struct execsw
*findexec_by_hdr(char *header
);
219 extern struct execsw
*findexec_by_magic(char *magic
);
220 extern int execpermissions(struct vnode
*vp
, struct vattr
*vattrp
,
222 extern int execmap(vnode_t
*vp
, caddr_t addr
, size_t len
, size_t zfodlen
,
223 off_t offset
, int prot
, int page
, uint_t
);
224 extern void setexecenv(struct execenv
*ep
);
225 extern int execopen(struct vnode
**vpp
, int *fdp
);
226 extern int execclose(int fd
);
227 extern void setregs(uarg_t
*);
228 extern void exec_set_sp(size_t);
231 * Utility functions for branded process executing
233 #if !defined(_ELF32_COMPAT)
235 * When compiling 64-bit kernels we don't want these definitions included
236 * when compiling the 32-bit compatability elf code in the elfexec module.
238 extern int elfexec(vnode_t
*, execa_t
*, uarg_t
*, intpdata_t
*, int,
239 long *, int, caddr_t
, cred_t
*, int);
240 extern int mapexec_brand(vnode_t
*, uarg_t
*, Ehdr
*, Addr
*,
241 intptr_t *, caddr_t
, int *, caddr_t
*, caddr_t
*, size_t *, uintptr_t *);
242 #endif /* !_ELF32_COMPAT */
245 extern int elf32exec(vnode_t
*, execa_t
*, uarg_t
*, intpdata_t
*, int,
246 long *, int, caddr_t
, cred_t
*, int);
247 extern int mapexec32_brand(vnode_t
*, uarg_t
*, Elf32_Ehdr
*, Elf32_Addr
*,
248 intptr_t *, caddr_t
, int *, caddr_t
*, caddr_t
*, size_t *, uintptr_t *);
252 * Utility functions for exec module core routines:
254 extern int core_seg(proc_t
*, vnode_t
*, offset_t
, caddr_t
,
255 size_t, rlim64_t
, cred_t
*);
257 extern int core_write(vnode_t
*, enum uio_seg
, offset_t
,
258 const void *, size_t, rlim64_t
, cred_t
*);
264 extern caddr_t
gettmem(struct exec
*exp
);
265 extern caddr_t
getdmem(struct exec
*exp
);
266 extern ulong_t
getdfile(struct exec
*exp
);
267 extern uint_t
gettfile(struct exec
*exp
);
268 extern int chkaout(struct exdata
*exp
);
269 extern void getexinfo(struct exdata
*edp_in
, struct exdata
*edp_out
,
270 int *pagetext
, int *pagedata
);
278 #endif /* _SYS_EXEC_H */