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 */ 217838SRoger.Faulkner@Sun.COM 220Sstevel@tonic-gate /* 23*12273SCasper.Dik@Sun.COM * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 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 #ifndef _SYS_EXEC_H 300Sstevel@tonic-gate #define _SYS_EXEC_H 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/systm.h> 330Sstevel@tonic-gate #include <vm/seg.h> 340Sstevel@tonic-gate #include <vm/seg_vn.h> 350Sstevel@tonic-gate #include <sys/model.h> 360Sstevel@tonic-gate #include <sys/uio.h> 370Sstevel@tonic-gate #include <sys/corectl.h> 384440Sedp #include <sys/machelf.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate #ifdef __cplusplus 410Sstevel@tonic-gate extern "C" { 420Sstevel@tonic-gate #endif 430Sstevel@tonic-gate 440Sstevel@tonic-gate /* 450Sstevel@tonic-gate * Number of bytes to read for magic string 460Sstevel@tonic-gate */ 470Sstevel@tonic-gate #define MAGIC_BYTES 8 480Sstevel@tonic-gate 490Sstevel@tonic-gate #define getexmag(x) (((x)[0] << 8) + (x)[1]) 500Sstevel@tonic-gate 510Sstevel@tonic-gate typedef struct execa { 520Sstevel@tonic-gate const char *fname; 530Sstevel@tonic-gate const char **argp; 540Sstevel@tonic-gate const char **envp; 550Sstevel@tonic-gate } execa_t; 560Sstevel@tonic-gate 570Sstevel@tonic-gate typedef struct execenv { 580Sstevel@tonic-gate caddr_t ex_bssbase; 590Sstevel@tonic-gate caddr_t ex_brkbase; 600Sstevel@tonic-gate size_t ex_brksize; 610Sstevel@tonic-gate vnode_t *ex_vp; 620Sstevel@tonic-gate short ex_magic; 630Sstevel@tonic-gate } execenv_t; 640Sstevel@tonic-gate 650Sstevel@tonic-gate #ifdef _KERNEL 660Sstevel@tonic-gate 670Sstevel@tonic-gate #define LOADABLE_EXEC(e) ((e)->exec_lock) 680Sstevel@tonic-gate #define LOADED_EXEC(e) ((e)->exec_func) 690Sstevel@tonic-gate 700Sstevel@tonic-gate 710Sstevel@tonic-gate /* 720Sstevel@tonic-gate * User argument structure for passing exec information around between the 730Sstevel@tonic-gate * common and machine-dependent portions of exec and the exec modules. 740Sstevel@tonic-gate */ 750Sstevel@tonic-gate typedef struct uarg { 760Sstevel@tonic-gate ssize_t na; 770Sstevel@tonic-gate ssize_t ne; 780Sstevel@tonic-gate ssize_t nc; 790Sstevel@tonic-gate ssize_t arglen; 800Sstevel@tonic-gate char *fname; 810Sstevel@tonic-gate char *pathname; 820Sstevel@tonic-gate ssize_t auxsize; 830Sstevel@tonic-gate caddr_t stackend; 840Sstevel@tonic-gate size_t stk_align; 850Sstevel@tonic-gate size_t stk_size; 860Sstevel@tonic-gate char *stk_base; 870Sstevel@tonic-gate char *stk_strp; 880Sstevel@tonic-gate int *stk_offp; 890Sstevel@tonic-gate size_t usrstack_size; 900Sstevel@tonic-gate uint_t stk_prot; 910Sstevel@tonic-gate uint_t dat_prot; 920Sstevel@tonic-gate int traceinval; 937838SRoger.Faulkner@Sun.COM int addr32; 940Sstevel@tonic-gate model_t to_model; 950Sstevel@tonic-gate model_t from_model; 960Sstevel@tonic-gate size_t to_ptrsize; 970Sstevel@tonic-gate size_t from_ptrsize; 980Sstevel@tonic-gate size_t ncargs; 990Sstevel@tonic-gate struct execsw *execswp; 1000Sstevel@tonic-gate uintptr_t entry; 1010Sstevel@tonic-gate uintptr_t thrptr; 1024528Spaulsan vnode_t *ex_vp; 1032712Snn35248 char *emulator; 1042712Snn35248 char *brandname; 1056229Sedp char *auxp_auxflags; /* addr of auxflags auxv on the user stack */ 1064642Ssl108498 char *auxp_brand; /* address of first brand auxv on user stack */ 107*12273SCasper.Dik@Sun.COM cred_t *pfcred; 108*12273SCasper.Dik@Sun.COM boolean_t scrubenv; 1090Sstevel@tonic-gate } uarg_t; 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1122712Snn35248 * Possible brand actions for exec. 1132712Snn35248 */ 1142712Snn35248 #define EBA_NONE 0 1152712Snn35248 #define EBA_NATIVE 1 1162712Snn35248 #define EBA_BRAND 2 1172712Snn35248 1182712Snn35248 /* 1190Sstevel@tonic-gate * The following macro is a machine dependent encapsulation of 1200Sstevel@tonic-gate * postfix processing to hide the stack direction from elf.c 1210Sstevel@tonic-gate * thereby making the elf.c code machine independent. 1220Sstevel@tonic-gate */ 1230Sstevel@tonic-gate #define execpoststack(ARGS, ARRAYADDR, BYTESIZE) \ 1240Sstevel@tonic-gate (copyout((caddr_t)(ARRAYADDR), (ARGS)->stackend, (BYTESIZE)) ? EFAULT \ 1250Sstevel@tonic-gate : (((ARGS)->stackend += (BYTESIZE)), 0)) 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate /* 1280Sstevel@tonic-gate * This provides the current user stack address for an object of size BYTESIZE. 1290Sstevel@tonic-gate * Used to determine the stack address just before applying execpoststack(). 1300Sstevel@tonic-gate */ 1310Sstevel@tonic-gate #define stackaddress(ARGS, BYTESIZE) ((ARGS)->stackend) 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate /* 1340Sstevel@tonic-gate * Macro to add attribute/values the aux vector under construction. 1350Sstevel@tonic-gate */ 1360Sstevel@tonic-gate /* BEGIN CSTYLED */ 1370Sstevel@tonic-gate #if ((_LONG_ALIGNMENT == (2 * _INT_ALIGNMENT)) || \ 1380Sstevel@tonic-gate (_POINTER_ALIGNMENT == (2 * _INT_ALIGNMENT))) 1390Sstevel@tonic-gate /* END CSTYLED */ 1400Sstevel@tonic-gate /* 1410Sstevel@tonic-gate * This convoluted stuff is necessitated by the fact that there is 1420Sstevel@tonic-gate * potential padding in the aux vector, but not necessarily and 1430Sstevel@tonic-gate * without clearing the padding there is a small, but potential 1440Sstevel@tonic-gate * security hole. 1450Sstevel@tonic-gate */ 1460Sstevel@tonic-gate #define ADDAUX(p, a, v) { \ 1470Sstevel@tonic-gate (&(p)->a_type)[1] = 0; \ 1480Sstevel@tonic-gate (p)->a_type = (a); \ 1490Sstevel@tonic-gate (p)->a_un.a_val = (v); \ 1500Sstevel@tonic-gate ++(p); \ 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate #else 1530Sstevel@tonic-gate #define ADDAUX(p, a, v) { \ 1540Sstevel@tonic-gate (p)->a_type = (a); \ 1550Sstevel@tonic-gate ((p)++)->a_un.a_val = (v); \ 1560Sstevel@tonic-gate } 1570Sstevel@tonic-gate #endif 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate #define INTPSZ MAXPATHLEN 1600Sstevel@tonic-gate typedef struct intpdata { 1610Sstevel@tonic-gate char *intp; 1620Sstevel@tonic-gate char *intp_name; 1630Sstevel@tonic-gate char *intp_arg; 1640Sstevel@tonic-gate } intpdata_t; 1650Sstevel@tonic-gate 1661335Scasper #define EXECSETID_SETID 0x1 /* setid exec */ 1671335Scasper #define EXECSETID_UGIDS 0x2 /* [ug]ids mismatch */ 1681335Scasper #define EXECSETID_PRIVS 0x4 /* more privs than before */ 1691335Scasper 1700Sstevel@tonic-gate struct execsw { 1710Sstevel@tonic-gate char *exec_magic; 1720Sstevel@tonic-gate int exec_magoff; 1730Sstevel@tonic-gate int exec_maglen; 1740Sstevel@tonic-gate int (*exec_func)(struct vnode *vp, struct execa *uap, 1750Sstevel@tonic-gate struct uarg *args, struct intpdata *idata, int level, 1760Sstevel@tonic-gate long *execsz, int setid, caddr_t exec_file, 1772712Snn35248 struct cred *cred, int brand_action); 1780Sstevel@tonic-gate int (*exec_core)(struct vnode *vp, struct proc *p, 1790Sstevel@tonic-gate struct cred *cred, rlim64_t rlimit, int sig, 1800Sstevel@tonic-gate core_content_t content); 1810Sstevel@tonic-gate krwlock_t *exec_lock; 1820Sstevel@tonic-gate }; 1830Sstevel@tonic-gate 1849694SScott.Rotondo@Sun.COM extern int nexectype; /* number of elements in execsw */ 1859694SScott.Rotondo@Sun.COM extern struct execsw execsw[]; 1869694SScott.Rotondo@Sun.COM extern kmutex_t execsw_lock; 1879694SScott.Rotondo@Sun.COM 1880Sstevel@tonic-gate extern short elfmagic; 1890Sstevel@tonic-gate extern short intpmagic; 1900Sstevel@tonic-gate extern short javamagic; 1910Sstevel@tonic-gate #if defined(__sparc) 1920Sstevel@tonic-gate extern short aout_zmagic; 1930Sstevel@tonic-gate extern short aout_nmagic; 1940Sstevel@tonic-gate extern short aout_omagic; 1950Sstevel@tonic-gate #endif 1960Sstevel@tonic-gate extern short nomagic; 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate extern char elf32magicstr[]; 1990Sstevel@tonic-gate extern char elf64magicstr[]; 2000Sstevel@tonic-gate extern char intpmagicstr[]; 2010Sstevel@tonic-gate extern char javamagicstr[]; 2020Sstevel@tonic-gate #if defined(__sparc) 2030Sstevel@tonic-gate extern char aout_nmagicstr[]; 2040Sstevel@tonic-gate extern char aout_zmagicstr[]; 2050Sstevel@tonic-gate extern char aout_omagicstr[]; 2060Sstevel@tonic-gate #endif 2070Sstevel@tonic-gate extern char nomagicstr[]; 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate extern int exec_args(execa_t *, uarg_t *, intpdata_t *, void **); 2100Sstevel@tonic-gate extern int exece(const char *fname, const char **argp, const char **envp); 2110Sstevel@tonic-gate extern int exec_common(const char *fname, const char **argp, 2122712Snn35248 const char **envp, int brand_action); 2130Sstevel@tonic-gate extern int gexec(vnode_t **vp, struct execa *uap, struct uarg *args, 2140Sstevel@tonic-gate struct intpdata *idata, int level, long *execsz, caddr_t exec_file, 2152712Snn35248 struct cred *cred, int brand_action); 2160Sstevel@tonic-gate extern struct execsw *allocate_execsw(char *name, char *magic, 2170Sstevel@tonic-gate size_t magic_size); 2180Sstevel@tonic-gate extern struct execsw *findexecsw(char *magic); 2190Sstevel@tonic-gate extern struct execsw *findexec_by_hdr(char *header); 2200Sstevel@tonic-gate extern struct execsw *findexec_by_magic(char *magic); 2210Sstevel@tonic-gate extern int execpermissions(struct vnode *vp, struct vattr *vattrp, 2220Sstevel@tonic-gate struct uarg *args); 2230Sstevel@tonic-gate extern int execmap(vnode_t *vp, caddr_t addr, size_t len, size_t zfodlen, 2240Sstevel@tonic-gate off_t offset, int prot, int page, uint_t); 2250Sstevel@tonic-gate extern void setexecenv(struct execenv *ep); 2260Sstevel@tonic-gate extern int execopen(struct vnode **vpp, int *fdp); 2270Sstevel@tonic-gate extern int execclose(int fd); 2280Sstevel@tonic-gate extern void setregs(uarg_t *); 2290Sstevel@tonic-gate extern void exec_set_sp(size_t); 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate /* 2324440Sedp * Utility functions for branded process executing 2334440Sedp */ 2344440Sedp #if !defined(_ELF32_COMPAT) 2354440Sedp /* 2364440Sedp * When compiling 64-bit kernels we don't want these definitions included 2374440Sedp * when compiling the 32-bit compatability elf code in the elfexec module. 2384440Sedp */ 2394440Sedp extern int elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int, 2404440Sedp long *, int, caddr_t, cred_t *, int); 2414440Sedp extern int mapexec_brand(vnode_t *, uarg_t *, Ehdr *, Addr *, 2424642Ssl108498 intptr_t *, caddr_t, int *, caddr_t *, caddr_t *, size_t *, uintptr_t *); 2434440Sedp #endif /* !_ELF32_COMPAT */ 2444440Sedp 2454440Sedp #if defined(_LP64) 2464440Sedp extern int elf32exec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int, 2474440Sedp long *, int, caddr_t, cred_t *, int); 2484440Sedp extern int mapexec32_brand(vnode_t *, uarg_t *, Elf32_Ehdr *, Elf32_Addr *, 2494642Ssl108498 intptr_t *, caddr_t, int *, caddr_t *, caddr_t *, size_t *, uintptr_t *); 2504642Ssl108498 #endif /* _LP64 */ 2514440Sedp 2524440Sedp /* 2530Sstevel@tonic-gate * Utility functions for exec module core routines: 2540Sstevel@tonic-gate */ 2550Sstevel@tonic-gate extern int core_seg(proc_t *, vnode_t *, offset_t, caddr_t, 2560Sstevel@tonic-gate size_t, rlim64_t, cred_t *); 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate extern int core_write(vnode_t *, enum uio_seg, offset_t, 2590Sstevel@tonic-gate const void *, size_t, rlim64_t, cred_t *); 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate /* a.out stuff */ 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate struct exec; 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate extern caddr_t gettmem(struct exec *exp); 2660Sstevel@tonic-gate extern caddr_t getdmem(struct exec *exp); 2670Sstevel@tonic-gate extern ulong_t getdfile(struct exec *exp); 2680Sstevel@tonic-gate extern uint_t gettfile(struct exec *exp); 2690Sstevel@tonic-gate extern int chkaout(struct exdata *exp); 2700Sstevel@tonic-gate extern void getexinfo(struct exdata *edp_in, struct exdata *edp_out, 2710Sstevel@tonic-gate int *pagetext, int *pagedata); 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate #endif /* _KERNEL */ 2740Sstevel@tonic-gate 2750Sstevel@tonic-gate #ifdef __cplusplus 2760Sstevel@tonic-gate } 2770Sstevel@tonic-gate #endif 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate #endif /* _SYS_EXEC_H */ 280