1/*- 2 * Copyright (c) 1995-1996 S�ren Schmidt 3 * Copyright (c) 1996 Peter Wemm 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * |
29 * $FreeBSD: head/sys/kern/imgact_elf.c 50717 1999-09-01 00:29:56Z julian $ |
30 */ 31 32#include "opt_rlimit.h" 33 34#include <sys/param.h> 35#include <sys/acct.h> 36#include <sys/exec.h> 37#include <sys/fcntl.h> --- 640 unchanged lines hidden (view full) --- 678static void elf_puthdr __P((struct proc *, void *, size_t *, 679 const prstatus_t *, const prfpregset_t *, const prpsinfo_t *, int)); 680static void elf_putnote __P((void *, size_t *, const char *, int, 681 const void *, size_t)); 682 683extern int osreldate; 684 685int |
686elf_coredump(p, vp, limit) |
687 register struct proc *p; |
688 register struct vnode *vp; |
689 off_t limit; 690{ |
691 register struct ucred *cred = p->p_cred->pc_ucred; |
692 int error = 0; |
693 struct sseg_closure seginfo; 694 void *hdr; 695 size_t hdrsize; 696 |
697 /* Size the program segments. */ 698 seginfo.count = 0; 699 seginfo.size = 0; 700 each_writable_segment(p, cb_size_segment, &seginfo); 701 702 /* 703 * Calculate the size of the core file header area by making 704 * a dry run of generating it. Nothing is written, but the 705 * size is calculated. 706 */ 707 hdrsize = 0; 708 elf_puthdr((struct proc *)NULL, (void *)NULL, &hdrsize, 709 (const prstatus_t *)NULL, (const prfpregset_t *)NULL, 710 (const prpsinfo_t *)NULL, seginfo.count); 711 |
712 if (hdrsize + seginfo.size >= limit) |
713 return (EFAULT); |
714 |
715 /* 716 * Allocate memory for building the header, fill it up, 717 * and write it out. 718 */ 719 hdr = malloc(hdrsize, M_TEMP, M_WAITOK); 720 if (hdr == NULL) { |
721 return EINVAL; |
722 } 723 error = elf_corehdr(p, vp, cred, seginfo.count, hdr, hdrsize); 724 725 /* Write the contents of all of the writable segments. */ 726 if (error == 0) { 727 Elf_Phdr *php; 728 off_t offset; 729 int i; --- 6 unchanged lines hidden (view full) --- 736 IO_NODELOCKED|IO_UNIT, cred, (int *)NULL, p); 737 if (error != 0) 738 break; 739 offset += php->p_filesz; 740 php++; 741 } 742 } 743 free(hdr, M_TEMP); |
744 745 return error; |
746} 747 748/* 749 * A callback for each_writable_segment() to write out the segment's 750 * program header entry. 751 */ 752static void 753cb_put_phdr(entry, closure) --- 236 unchanged lines hidden --- |