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