imgact_aout.c (50477) | imgact_aout.c (50717) |
---|---|
1/* 2 * Copyright (c) 1993, David Greenman 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/* 2 * Copyright (c) 1993, David Greenman 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/kern/imgact_aout.c 50477 1999-08-28 01:08:13Z peter $ | 26 * $FreeBSD: head/sys/kern/imgact_aout.c 50717 1999-09-01 00:29:56Z julian $ |
27 */ 28 29#include <sys/param.h> 30#include <sys/acct.h> 31#include <sys/resourcevar.h> 32#include <sys/exec.h> 33#include <sys/fcntl.h> 34#include <sys/imgact.h> --- 35 unchanged lines hidden (view full) --- 70 sendsig, 71 sigcode, 72 &szsigcode, 73 0, 74 "FreeBSD a.out", 75 aout_coredump 76}; 77 | 27 */ 28 29#include <sys/param.h> 30#include <sys/acct.h> 31#include <sys/resourcevar.h> 32#include <sys/exec.h> 33#include <sys/fcntl.h> 34#include <sys/imgact.h> --- 35 unchanged lines hidden (view full) --- 70 sendsig, 71 sigcode, 72 &szsigcode, 73 0, 74 "FreeBSD a.out", 75 aout_coredump 76}; 77 |
78static int | 78int |
79exec_aout_imgact(imgp) 80 struct image_params *imgp; 81{ 82 const struct exec *a_out = (const struct exec *) imgp->image_header; 83 struct vmspace *vmspace; 84 struct vnode *vp; 85 vm_map_t map; 86 vm_object_t object; --- 152 unchanged lines hidden (view full) --- 239 return (0); 240} 241 242/* 243 * Dump core, into a file named as described in the comments for 244 * expand_name(), unless the process was setuid/setgid. 245 */ 246int | 79exec_aout_imgact(imgp) 80 struct image_params *imgp; 81{ 82 const struct exec *a_out = (const struct exec *) imgp->image_header; 83 struct vmspace *vmspace; 84 struct vnode *vp; 85 vm_map_t map; 86 vm_object_t object; --- 152 unchanged lines hidden (view full) --- 239 return (0); 240} 241 242/* 243 * Dump core, into a file named as described in the comments for 244 * expand_name(), unless the process was setuid/setgid. 245 */ 246int |
247aout_coredump(p) | 247aout_coredump(p, vp, limit) |
248 register struct proc *p; | 248 register struct proc *p; |
249{ | |
250 register struct vnode *vp; | 249 register struct vnode *vp; |
250 off_t limit; 251{ |
|
251 register struct ucred *cred = p->p_cred->pc_ucred; 252 register struct vmspace *vm = p->p_vmspace; | 252 register struct ucred *cred = p->p_cred->pc_ucred; 253 register struct vmspace *vm = p->p_vmspace; |
253 struct nameidata nd; 254 struct vattr vattr; 255 int error, error1; 256 char *name; /* name of corefile */ | 254 int error = 0; |
257 | 255 |
258 STOPEVENT(p, S_CORE, 0); 259 if (sugid_coredump == 0 && p->p_flag & P_SUGID) 260 return (EFAULT); | |
261 if (ctob(UPAGES + vm->vm_dsize + vm->vm_ssize) >= | 256 if (ctob(UPAGES + vm->vm_dsize + vm->vm_ssize) >= |
262 p->p_rlimit[RLIMIT_CORE].rlim_cur) | 257 limit) |
263 return (EFAULT); | 258 return (EFAULT); |
264 name = expand_name(p->p_comm, p->p_ucred->cr_uid, p->p_pid); 265 if (name == NULL) 266 return (EFAULT); /* XXX -- not the best error */ 267 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, p); 268 error = vn_open(&nd, O_CREAT | FWRITE | O_NOFOLLOW, S_IRUSR | S_IWUSR); 269 free(name, M_TEMP); 270 if (error) 271 return (error); 272 vp = nd.ni_vp; | |
273 | 259 |
274 /* Don't dump to non-regular files or files with links. */ 275 if (vp->v_type != VREG || 276 VOP_GETATTR(vp, &vattr, cred, p) || vattr.va_nlink != 1) { 277 error = EFAULT; 278 goto out; 279 } 280 VATTR_NULL(&vattr); 281 vattr.va_size = 0; 282 VOP_LEASE(vp, p, cred, LEASE_WRITE); 283 VOP_SETATTR(vp, &vattr, cred, p); 284 p->p_acflag |= ACORE; | |
285 bcopy(p, &p->p_addr->u_kproc.kp_proc, sizeof(struct proc)); 286 fill_eproc(p, &p->p_addr->u_kproc.kp_eproc); 287 error = cpu_coredump(p, vp, cred); 288 if (error == 0) 289 error = vn_rdwr(UIO_WRITE, vp, vm->vm_daddr, 290 (int)ctob(vm->vm_dsize), (off_t)ctob(UPAGES), UIO_USERSPACE, 291 IO_NODELOCKED|IO_UNIT, cred, (int *) NULL, p); 292 if (error == 0) 293 error = vn_rdwr(UIO_WRITE, vp, 294 (caddr_t) trunc_page(USRSTACK - ctob(vm->vm_ssize)), 295 round_page(ctob(vm->vm_ssize)), 296 (off_t)ctob(UPAGES) + ctob(vm->vm_dsize), UIO_USERSPACE, 297 IO_NODELOCKED|IO_UNIT, cred, (int *) NULL, p); | 260 bcopy(p, &p->p_addr->u_kproc.kp_proc, sizeof(struct proc)); 261 fill_eproc(p, &p->p_addr->u_kproc.kp_eproc); 262 error = cpu_coredump(p, vp, cred); 263 if (error == 0) 264 error = vn_rdwr(UIO_WRITE, vp, vm->vm_daddr, 265 (int)ctob(vm->vm_dsize), (off_t)ctob(UPAGES), UIO_USERSPACE, 266 IO_NODELOCKED|IO_UNIT, cred, (int *) NULL, p); 267 if (error == 0) 268 error = vn_rdwr(UIO_WRITE, vp, 269 (caddr_t) trunc_page(USRSTACK - ctob(vm->vm_ssize)), 270 round_page(ctob(vm->vm_ssize)), 271 (off_t)ctob(UPAGES) + ctob(vm->vm_dsize), UIO_USERSPACE, 272 IO_NODELOCKED|IO_UNIT, cred, (int *) NULL, p); |
298out: 299 VOP_UNLOCK(vp, 0, p); 300 error1 = vn_close(vp, FWRITE, cred, p); 301 if (error == 0) 302 error = error1; 303 return (error); | 273 return error; |
304} 305 306/* 307 * Tell kern_execve.c about it, with a little help from the linker. 308 */ 309static struct execsw aout_execsw = { exec_aout_imgact, "a.out" }; 310EXEC_SET(aout, aout_execsw); | 274} 275 276/* 277 * Tell kern_execve.c about it, with a little help from the linker. 278 */ 279static struct execsw aout_execsw = { exec_aout_imgact, "a.out" }; 280EXEC_SET(aout, aout_execsw); |