1850Sdg/*- 2850Sdg * Copyright (c) 1993, David Greenman 3850Sdg * All rights reserved. 4850Sdg * 5850Sdg * Redistribution and use in source and binary forms, with or without 6850Sdg * modification, are permitted provided that the following conditions 7850Sdg * are met: 8850Sdg * 1. Redistributions of source code must retain the above copyright 9850Sdg * notice, this list of conditions and the following disclaimer. 10850Sdg * 2. Redistributions in binary form must reproduce the above copyright 11850Sdg * notice, this list of conditions and the following disclaimer in the 12850Sdg * documentation and/or other materials provided with the distribution. 13850Sdg * 4. Neither the name of the University nor the names of its contributors 14850Sdg * may be used to endorse or promote products derived from this software 15850Sdg * without specific prior written permission. 16850Sdg * 17850Sdg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18850Sdg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19850Sdg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20850Sdg * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21850Sdg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22850Sdg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23850Sdg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24850Sdg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25850Sdg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26850Sdg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27850Sdg * SUCH DAMAGE. 28850Sdg * 2950477Speter * $FreeBSD: stable/11/sys/sys/imgact.h 366281 2020-09-30 02:28:46Z kib $ 30850Sdg */ 31850Sdg 322165Spaul#ifndef _SYS_IMGACT_H_ 3315494Sbde#define _SYS_IMGACT_H_ 34886Swollman 35210498Skib#include <sys/uio.h> 36210498Skib 37217151Skib#include <vm/vm.h> 38217151Skib 39142453Ssobomax#define MAXSHELLCMDLEN PAGE_SIZE 4059663Sdillon 41300792Sbdrewerystruct ucred; 42300792Sbdrewery 43140992Ssobomaxstruct image_args { 44140992Ssobomax char *buf; /* pointer to string buffer */ 45320797Smarkj void *bufkva; /* cookie for string buffer KVA */ 46140992Ssobomax char *begin_argv; /* beginning of argv in buf */ 47140992Ssobomax char *begin_envv; /* beginning of envv in buf */ 48140992Ssobomax char *endp; /* current `end' pointer of arg & env strings */ 49140992Ssobomax char *fname; /* pointer to filename of executable (system space) */ 50210555Salc char *fname_buf; /* pointer to optional malloc(M_TEMP) buffer */ 51140992Ssobomax int stringspace; /* space left in arg & env buffer */ 52140992Ssobomax int argc; /* count of argument strings */ 53140992Ssobomax int envc; /* count of environment strings */ 54177787Skib int fd; /* file descriptor of the executable */ 55285622Sed struct filedesc *fdp; /* new file descriptor table */ 56140992Ssobomax}; 57140992Ssobomax 58850Sdgstruct image_params { 59850Sdg struct proc *proc; /* our process struct */ 60106468Srwatson struct label *execlabel; /* optional exec label */ 6112130Sdg struct vnode *vp; /* pointer to vnode of file to exec */ 6299487Sjeff struct vm_object *object; /* The vm object for this vp */ 63850Sdg struct vattr *attr; /* attributes of file */ 64850Sdg const char *image_header; /* head of file to exec */ 65850Sdg unsigned long entry_addr; /* entry address of target executable */ 66205643Snwhitehorn unsigned long reloc_base; /* load address of image */ 67850Sdg char vmspace_destroyed; /* flag - we've blown away original vm space */ 68271141Ssbruno#define IMGACT_SHELL 0x1 69271141Ssbruno#define IMGACT_BINMISC 0x2 70271141Ssbruno unsigned char interpreted; /* mask of interpreters that have run */ 71180570Skib char opened; /* flag - we have opened executable vnode */ 72142453Ssobomax char *interpreter_name; /* name of the interpreter */ 7314456Ssos void *auxargs; /* ELF Auxinfo structure pointer */ 74128568Salc struct sf_buf *firstpage; /* first page that we mapped */ 7545270Sjdp unsigned long ps_strings; /* PS_STRINGS for BSD/OS binaries */ 76140992Ssobomax struct image_args *args; /* system call arguments */ 77161302Snetchild struct sysentvec *sysent; /* system entry vector */ 78189927Skib char *execpath; 79189927Skib unsigned long execpathp; 80189927Skib char *freepath; 81211412Skib unsigned long canary; 82211412Skib int canarylen; 83211412Skib unsigned long pagesizes; 84211412Skib int pagesizeslen; 85217151Skib vm_prot_t stack_prot; 86281548Skib u_long stack_sz; 87300792Sbdrewery struct ucred *newcred; /* new credentials if changing */ 88300792Sbdrewery bool credential_setid; /* true if becoming setid */ 89850Sdg}; 90886Swollman 9155205Speter#ifdef _KERNEL 92128599Sbdestruct sysentvec; 93128599Sbdestruct thread; 94282708Skibstruct vmspace; 95128599Sbde 96204552Salfred#define IMGACT_CORE_COMPRESS 0x01 97204552Salfred 98210545Salcint exec_alloc_args(struct image_args *); 9992719Salfredint exec_check_permissions(struct image_params *); 100366281Skibvoid exec_cleanup(struct thread *td, struct vmspace *); 101102808Sjakeregister_t *exec_copyout_strings(struct image_params *); 102210429Salcvoid exec_free_args(struct image_args *); 103103767Sjakeint exec_new_vmspace(struct image_params *, struct sysentvec *); 104205642Snwhitehornvoid exec_setregs(struct thread *, struct image_params *, u_long); 10592719Salfredint exec_shell_imgact(struct image_params *); 106140992Ssobomaxint exec_copyin_args(struct image_args *, char *, enum uio_seg, 107140992Ssobomax char **, char **); 108285622Sedint exec_copyin_data_fds(struct thread *, struct image_args *, const void *, 109285622Sed size_t, const int *, size_t); 110282708Skibint pre_execve(struct thread *td, struct vmspace **oldvmspace); 111282708Skibvoid post_execve(struct thread *td, int error, struct vmspace *oldvmspace); 1123304Sphk#endif 11315494Sbde 11415494Sbde#endif /* !_SYS_IMGACT_H_ */ 115