10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51335Scasper * Common Development and Distribution License (the "License"). 61335Scasper * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*4440Sedp * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate 300Sstevel@tonic-gate #ifndef _SYS_EXEC_H 310Sstevel@tonic-gate #define _SYS_EXEC_H 320Sstevel@tonic-gate 330Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/systm.h> 360Sstevel@tonic-gate #include <vm/seg.h> 370Sstevel@tonic-gate #include <vm/seg_vn.h> 380Sstevel@tonic-gate #include <sys/model.h> 390Sstevel@tonic-gate #include <sys/uio.h> 400Sstevel@tonic-gate #include <sys/corectl.h> 41*4440Sedp #include <sys/machelf.h> 420Sstevel@tonic-gate 430Sstevel@tonic-gate #ifdef __cplusplus 440Sstevel@tonic-gate extern "C" { 450Sstevel@tonic-gate #endif 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * Number of bytes to read for magic string 490Sstevel@tonic-gate */ 500Sstevel@tonic-gate #define MAGIC_BYTES 8 510Sstevel@tonic-gate 520Sstevel@tonic-gate #define getexmag(x) (((x)[0] << 8) + (x)[1]) 530Sstevel@tonic-gate 540Sstevel@tonic-gate typedef struct execa { 550Sstevel@tonic-gate const char *fname; 560Sstevel@tonic-gate const char **argp; 570Sstevel@tonic-gate const char **envp; 580Sstevel@tonic-gate } execa_t; 590Sstevel@tonic-gate 600Sstevel@tonic-gate typedef struct execenv { 610Sstevel@tonic-gate caddr_t ex_bssbase; 620Sstevel@tonic-gate caddr_t ex_brkbase; 630Sstevel@tonic-gate size_t ex_brksize; 640Sstevel@tonic-gate vnode_t *ex_vp; 650Sstevel@tonic-gate short ex_magic; 660Sstevel@tonic-gate } execenv_t; 670Sstevel@tonic-gate 680Sstevel@tonic-gate #ifdef _KERNEL 690Sstevel@tonic-gate 700Sstevel@tonic-gate #define LOADABLE_EXEC(e) ((e)->exec_lock) 710Sstevel@tonic-gate #define LOADED_EXEC(e) ((e)->exec_func) 720Sstevel@tonic-gate 730Sstevel@tonic-gate extern int nexectype; /* number of elements in execsw */ 740Sstevel@tonic-gate extern struct execsw execsw[]; 750Sstevel@tonic-gate extern kmutex_t execsw_lock; 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* 780Sstevel@tonic-gate * User argument structure for passing exec information around between the 790Sstevel@tonic-gate * common and machine-dependent portions of exec and the exec modules. 800Sstevel@tonic-gate */ 810Sstevel@tonic-gate typedef struct uarg { 820Sstevel@tonic-gate ssize_t na; 830Sstevel@tonic-gate ssize_t ne; 840Sstevel@tonic-gate ssize_t nc; 850Sstevel@tonic-gate ssize_t arglen; 860Sstevel@tonic-gate char *fname; 870Sstevel@tonic-gate char *pathname; 880Sstevel@tonic-gate ssize_t auxsize; 890Sstevel@tonic-gate caddr_t stackend; 900Sstevel@tonic-gate size_t stk_align; 910Sstevel@tonic-gate size_t stk_size; 920Sstevel@tonic-gate char *stk_base; 930Sstevel@tonic-gate char *stk_strp; 940Sstevel@tonic-gate int *stk_offp; 950Sstevel@tonic-gate size_t usrstack_size; 960Sstevel@tonic-gate uint_t stk_prot; 970Sstevel@tonic-gate uint_t dat_prot; 980Sstevel@tonic-gate int traceinval; 990Sstevel@tonic-gate model_t to_model; 1000Sstevel@tonic-gate model_t from_model; 1010Sstevel@tonic-gate size_t to_ptrsize; 1020Sstevel@tonic-gate size_t from_ptrsize; 1030Sstevel@tonic-gate size_t ncargs; 1040Sstevel@tonic-gate struct execsw *execswp; 1050Sstevel@tonic-gate uintptr_t entry; 1060Sstevel@tonic-gate uintptr_t thrptr; 1072712Snn35248 char *emulator; 1082712Snn35248 char *brandname; 109*4440Sedp char *auxp_brand_phdr; /* addr of brand phdr auxv on user stack */ 1100Sstevel@tonic-gate } uarg_t; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate /* 1132712Snn35248 * Possible brand actions for exec. 1142712Snn35248 */ 1152712Snn35248 #define EBA_NONE 0 1162712Snn35248 #define EBA_NATIVE 1 1172712Snn35248 #define EBA_BRAND 2 1182712Snn35248 1192712Snn35248 /* 1200Sstevel@tonic-gate * The following macro is a machine dependent encapsulation of 1210Sstevel@tonic-gate * postfix processing to hide the stack direction from elf.c 1220Sstevel@tonic-gate * thereby making the elf.c code machine independent. 1230Sstevel@tonic-gate */ 1240Sstevel@tonic-gate #define execpoststack(ARGS, ARRAYADDR, BYTESIZE) \ 1250Sstevel@tonic-gate (copyout((caddr_t)(ARRAYADDR), (ARGS)->stackend, (BYTESIZE)) ? EFAULT \ 1260Sstevel@tonic-gate : (((ARGS)->stackend += (BYTESIZE)), 0)) 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * This provides the current user stack address for an object of size BYTESIZE. 1300Sstevel@tonic-gate * Used to determine the stack address just before applying execpoststack(). 1310Sstevel@tonic-gate */ 1320Sstevel@tonic-gate #define stackaddress(ARGS, BYTESIZE) ((ARGS)->stackend) 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate /* 1350Sstevel@tonic-gate * Macro to add attribute/values the aux vector under construction. 1360Sstevel@tonic-gate */ 1370Sstevel@tonic-gate /* BEGIN CSTYLED */ 1380Sstevel@tonic-gate #if ((_LONG_ALIGNMENT == (2 * _INT_ALIGNMENT)) || \ 1390Sstevel@tonic-gate (_POINTER_ALIGNMENT == (2 * _INT_ALIGNMENT))) 1400Sstevel@tonic-gate /* END CSTYLED */ 1410Sstevel@tonic-gate /* 1420Sstevel@tonic-gate * This convoluted stuff is necessitated by the fact that there is 1430Sstevel@tonic-gate * potential padding in the aux vector, but not necessarily and 1440Sstevel@tonic-gate * without clearing the padding there is a small, but potential 1450Sstevel@tonic-gate * security hole. 1460Sstevel@tonic-gate */ 1470Sstevel@tonic-gate #define ADDAUX(p, a, v) { \ 1480Sstevel@tonic-gate (&(p)->a_type)[1] = 0; \ 1490Sstevel@tonic-gate (p)->a_type = (a); \ 1500Sstevel@tonic-gate (p)->a_un.a_val = (v); \ 1510Sstevel@tonic-gate ++(p); \ 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate #else 1540Sstevel@tonic-gate #define ADDAUX(p, a, v) { \ 1550Sstevel@tonic-gate (p)->a_type = (a); \ 1560Sstevel@tonic-gate ((p)++)->a_un.a_val = (v); \ 1570Sstevel@tonic-gate } 1580Sstevel@tonic-gate #endif 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate #define INTPSZ MAXPATHLEN 1610Sstevel@tonic-gate typedef struct intpdata { 1620Sstevel@tonic-gate char *intp; 1630Sstevel@tonic-gate char *intp_name; 1640Sstevel@tonic-gate char *intp_arg; 1650Sstevel@tonic-gate } intpdata_t; 1660Sstevel@tonic-gate 1671335Scasper #define EXECSETID_SETID 0x1 /* setid exec */ 1681335Scasper #define EXECSETID_UGIDS 0x2 /* [ug]ids mismatch */ 1691335Scasper #define EXECSETID_PRIVS 0x4 /* more privs than before */ 1701335Scasper 1710Sstevel@tonic-gate struct execsw { 1720Sstevel@tonic-gate char *exec_magic; 1730Sstevel@tonic-gate int exec_magoff; 1740Sstevel@tonic-gate int exec_maglen; 1750Sstevel@tonic-gate int (*exec_func)(struct vnode *vp, struct execa *uap, 1760Sstevel@tonic-gate struct uarg *args, struct intpdata *idata, int level, 1770Sstevel@tonic-gate long *execsz, int setid, caddr_t exec_file, 1782712Snn35248 struct cred *cred, int brand_action); 1790Sstevel@tonic-gate int (*exec_core)(struct vnode *vp, struct proc *p, 1800Sstevel@tonic-gate struct cred *cred, rlim64_t rlimit, int sig, 1810Sstevel@tonic-gate core_content_t content); 1820Sstevel@tonic-gate krwlock_t *exec_lock; 1830Sstevel@tonic-gate }; 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate extern short elfmagic; 1860Sstevel@tonic-gate extern short intpmagic; 1870Sstevel@tonic-gate extern short javamagic; 1880Sstevel@tonic-gate #if defined(__sparc) 1890Sstevel@tonic-gate extern short aout_zmagic; 1900Sstevel@tonic-gate extern short aout_nmagic; 1910Sstevel@tonic-gate extern short aout_omagic; 1920Sstevel@tonic-gate #endif 1930Sstevel@tonic-gate extern short nomagic; 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate extern char elf32magicstr[]; 1960Sstevel@tonic-gate extern char elf64magicstr[]; 1970Sstevel@tonic-gate extern char intpmagicstr[]; 1980Sstevel@tonic-gate extern char javamagicstr[]; 1990Sstevel@tonic-gate #if defined(__sparc) 2000Sstevel@tonic-gate extern char aout_nmagicstr[]; 2010Sstevel@tonic-gate extern char aout_zmagicstr[]; 2020Sstevel@tonic-gate extern char aout_omagicstr[]; 2030Sstevel@tonic-gate #endif 2040Sstevel@tonic-gate extern char nomagicstr[]; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate extern int exec_args(execa_t *, uarg_t *, intpdata_t *, void **); 2070Sstevel@tonic-gate extern int exec(const char *fname, const char **argp); 2080Sstevel@tonic-gate extern int exece(const char *fname, const char **argp, const char **envp); 2090Sstevel@tonic-gate extern int exec_common(const char *fname, const char **argp, 2102712Snn35248 const char **envp, int brand_action); 2110Sstevel@tonic-gate extern int gexec(vnode_t **vp, struct execa *uap, struct uarg *args, 2120Sstevel@tonic-gate struct intpdata *idata, int level, long *execsz, caddr_t exec_file, 2132712Snn35248 struct cred *cred, int brand_action); 2140Sstevel@tonic-gate extern struct execsw *allocate_execsw(char *name, char *magic, 2150Sstevel@tonic-gate size_t magic_size); 2160Sstevel@tonic-gate extern struct execsw *findexecsw(char *magic); 2170Sstevel@tonic-gate extern struct execsw *findexec_by_hdr(char *header); 2180Sstevel@tonic-gate extern struct execsw *findexec_by_magic(char *magic); 2190Sstevel@tonic-gate extern int execpermissions(struct vnode *vp, struct vattr *vattrp, 2200Sstevel@tonic-gate struct uarg *args); 2210Sstevel@tonic-gate extern int execmap(vnode_t *vp, caddr_t addr, size_t len, size_t zfodlen, 2220Sstevel@tonic-gate off_t offset, int prot, int page, uint_t); 2230Sstevel@tonic-gate extern void setexecenv(struct execenv *ep); 2240Sstevel@tonic-gate extern int execopen(struct vnode **vpp, int *fdp); 2250Sstevel@tonic-gate extern int execclose(int fd); 2260Sstevel@tonic-gate extern void setregs(uarg_t *); 2270Sstevel@tonic-gate extern void exec_set_sp(size_t); 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate /* 230*4440Sedp * Utility functions for branded process executing 231*4440Sedp */ 232*4440Sedp #if !defined(_ELF32_COMPAT) 233*4440Sedp /* 234*4440Sedp * When compiling 64-bit kernels we don't want these definitions included 235*4440Sedp * when compiling the 32-bit compatability elf code in the elfexec module. 236*4440Sedp */ 237*4440Sedp extern int elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int, 238*4440Sedp long *, int, caddr_t, cred_t *, int); 239*4440Sedp extern int mapexec_brand(vnode_t *, uarg_t *, Ehdr *, Addr *, 240*4440Sedp intptr_t *, caddr_t, int *, caddr_t *, caddr_t *, size_t *); 241*4440Sedp #endif /* !_ELF32_COMPAT */ 242*4440Sedp 243*4440Sedp #if defined(_LP64) 244*4440Sedp extern int elf32exec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int, 245*4440Sedp long *, int, caddr_t, cred_t *, int); 246*4440Sedp extern int mapexec32_brand(vnode_t *, uarg_t *, Elf32_Ehdr *, Elf32_Addr *, 247*4440Sedp intptr_t *, caddr_t, int *, caddr_t *, caddr_t *, size_t *); 248*4440Sedp #endif /* _LP64 */ 249*4440Sedp 250*4440Sedp /* 2510Sstevel@tonic-gate * Utility functions for exec module core routines: 2520Sstevel@tonic-gate */ 2530Sstevel@tonic-gate extern int core_seg(proc_t *, vnode_t *, offset_t, caddr_t, 2540Sstevel@tonic-gate size_t, rlim64_t, cred_t *); 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate extern int core_write(vnode_t *, enum uio_seg, offset_t, 2570Sstevel@tonic-gate const void *, size_t, rlim64_t, cred_t *); 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate /* a.out stuff */ 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate struct exec; 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate extern caddr_t gettmem(struct exec *exp); 2640Sstevel@tonic-gate extern caddr_t getdmem(struct exec *exp); 2650Sstevel@tonic-gate extern ulong_t getdfile(struct exec *exp); 2660Sstevel@tonic-gate extern uint_t gettfile(struct exec *exp); 2670Sstevel@tonic-gate extern int chkaout(struct exdata *exp); 2680Sstevel@tonic-gate extern void getexinfo(struct exdata *edp_in, struct exdata *edp_out, 2690Sstevel@tonic-gate int *pagetext, int *pagedata); 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate #endif /* _KERNEL */ 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate #ifdef __cplusplus 2740Sstevel@tonic-gate } 2750Sstevel@tonic-gate #endif 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate #endif /* _SYS_EXEC_H */ 278