summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorjdp <jdp@FreeBSD.org>1998-09-14 05:36:51 +0000
committerjdp <jdp@FreeBSD.org>1998-09-14 05:36:51 +0000
commit70bb8503aada512ec1237d4fe781e53761791b6a (patch)
treebcbd3e1c4a1caadaba5890cec117aefdfb8c0612 /sys
parentf69ac0c38654fe24e1fb1f743a634e62b4518e1a (diff)
downloadFreeBSD-src-70bb8503aada512ec1237d4fe781e53761791b6a.zip
FreeBSD-src-70bb8503aada512ec1237d4fe781e53761791b6a.tar.gz
Add provisions for variant core dump file formats, depending on the
object format of the executable being dumped. This is the first step toward producing ELF core dumps in the proper format. I will commit the code to generate the ELF core dumps Real Soon Now. In the meantime, ELF executables won't dump core at all. That is probably no less useful than dumping a.out-style core dumps as they have done until now. Submitted by: Alex <garbanzo@hooked.net> (with very minor changes by me)
Diffstat (limited to 'sys')
-rw-r--r--sys/alpha/linux/linux_sysvec.c9
-rw-r--r--sys/conf/files1
-rw-r--r--sys/i386/ibcs2/ibcs2_sysvec.c5
-rw-r--r--sys/i386/linux/linux_sysvec.c9
-rw-r--r--sys/kern/imgact_aout.c96
-rw-r--r--sys/kern/imgact_elf.c13
-rw-r--r--sys/kern/init_sysvec.c28
-rw-r--r--sys/kern/kern_sig.c82
-rw-r--r--sys/sys/imgact_aout.h10
-rw-r--r--sys/sys/imgact_elf.h7
-rw-r--r--sys/sys/signalvar.h5
-rw-r--r--sys/sys/sysent.h4
12 files changed, 152 insertions, 117 deletions
diff --git a/sys/alpha/linux/linux_sysvec.c b/sys/alpha/linux/linux_sysvec.c
index 67ed448..4b1380c 100644
--- a/sys/alpha/linux/linux_sysvec.c
+++ b/sys/alpha/linux/linux_sysvec.c
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: linux_sysvec.c,v 1.31 1998/07/29 16:43:00 bde Exp $
+ * $Id: linux_sysvec.c,v 1.32 1998/08/16 01:21:50 bde Exp $
*/
/* XXX we use functions that might not exist. */
@@ -41,6 +41,7 @@
#include <sys/systm.h>
#include <sys/sysent.h>
#include <sys/imgact.h>
+#include <sys/imgact_aout.h>
#include <sys/imgact_elf.h>
#include <sys/signalvar.h>
#include <sys/malloc.h>
@@ -401,7 +402,8 @@ struct sysentvec linux_sysvec = {
linux_sigcode,
&linux_szsigcode,
linux_prepsyscall,
- "Linux a.out"
+ "Linux a.out",
+ aout_coredump
};
struct sysentvec elf_linux_sysvec = {
@@ -418,7 +420,8 @@ struct sysentvec elf_linux_sysvec = {
linux_sigcode,
&linux_szsigcode,
linux_prepsyscall,
- "Linux ELF"
+ "Linux ELF",
+ elf_coredump
};
/*
diff --git a/sys/conf/files b/sys/conf/files
index b964538..c68a24b 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -156,7 +156,6 @@ kern/imgact_shell.c standard
kern/inflate.c optional gzip
kern/init_main.c standard
kern/init_sysent.c standard
-kern/init_sysvec.c standard
kern/kern_intr.c standard
kern/kern_module.c standard
kern/kern_linker.c standard
diff --git a/sys/i386/ibcs2/ibcs2_sysvec.c b/sys/i386/ibcs2/ibcs2_sysvec.c
index 7eefe14..2a10b0e 100644
--- a/sys/i386/ibcs2/ibcs2_sysvec.c
+++ b/sys/i386/ibcs2/ibcs2_sysvec.c
@@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: ibcs2_sysvec.c,v 1.6 1997/02/22 09:33:28 peter Exp $
+ * $Id: ibcs2_sysvec.c,v 1.7 1998/04/28 18:15:05 eivind Exp $
*/
#include <sys/param.h>
@@ -55,5 +55,6 @@ struct sysentvec ibcs2_svr3_sysvec = {
sigcode, /* use generic trampoline */
&szsigcode, /* use generic trampoline size */
0, /* prepsyscall */
- "IBCS2 COFF"
+ "IBCS2 COFF",
+ NULL /* we don't have a COFF coredump function */
};
diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c
index 67ed448..4b1380c 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: linux_sysvec.c,v 1.31 1998/07/29 16:43:00 bde Exp $
+ * $Id: linux_sysvec.c,v 1.32 1998/08/16 01:21:50 bde Exp $
*/
/* XXX we use functions that might not exist. */
@@ -41,6 +41,7 @@
#include <sys/systm.h>
#include <sys/sysent.h>
#include <sys/imgact.h>
+#include <sys/imgact_aout.h>
#include <sys/imgact_elf.h>
#include <sys/signalvar.h>
#include <sys/malloc.h>
@@ -401,7 +402,8 @@ struct sysentvec linux_sysvec = {
linux_sigcode,
&linux_szsigcode,
linux_prepsyscall,
- "Linux a.out"
+ "Linux a.out",
+ aout_coredump
};
struct sysentvec elf_linux_sysvec = {
@@ -418,7 +420,8 @@ struct sysentvec elf_linux_sysvec = {
linux_sigcode,
&linux_szsigcode,
linux_prepsyscall,
- "Linux ELF"
+ "Linux ELF",
+ elf_coredump
};
/*
diff --git a/sys/kern/imgact_aout.c b/sys/kern/imgact_aout.c
index 15f613d..7f1d6ec 100644
--- a/sys/kern/imgact_aout.c
+++ b/sys/kern/imgact_aout.c
@@ -23,19 +23,28 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: imgact_aout.c,v 1.40 1998/02/20 13:11:48 bde Exp $
+ * $Id: imgact_aout.c,v 1.41 1998/07/15 05:00:26 bde Exp $
*/
#include <sys/param.h>
+#include <sys/acct.h>
#include <sys/resourcevar.h>
#include <sys/exec.h>
+#include <sys/fcntl.h>
#include <sys/imgact.h>
#include <sys/imgact_aout.h>
#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/namei.h>
+#include <sys/pioctl.h>
#include <sys/proc.h>
+#include <sys/signalvar.h>
+#include <sys/stat.h>
#include <sys/sysent.h>
+#include <sys/syscall.h>
#include <sys/vnode.h>
#include <sys/systm.h>
+#include <machine/md_var.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
@@ -44,9 +53,28 @@
#include <vm/pmap.h>
#include <vm/vm_map.h>
#include <vm/vm_object.h>
+#include <sys/user.h>
static int exec_aout_imgact __P((struct image_params *imgp));
+struct sysentvec aout_sysvec = {
+ SYS_MAXSYSCALL,
+ sysent,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ sendsig,
+ sigcode,
+ &szsigcode,
+ 0,
+ "FreeBSD a.out",
+ aout_coredump
+};
+
static int
exec_aout_imgact(imgp)
struct image_params *imgp;
@@ -204,6 +232,72 @@ exec_aout_imgact(imgp)
}
/*
+ * Dump core, into a file named "progname.core", unless the process was
+ * setuid/setgid.
+ */
+int
+aout_coredump(p)
+ register struct proc *p;
+{
+ register struct vnode *vp;
+ register struct ucred *cred = p->p_cred->pc_ucred;
+ register struct vmspace *vm = p->p_vmspace;
+ struct nameidata nd;
+ struct vattr vattr;
+ int error, error1;
+ char *name; /* name of corefile */
+
+ STOPEVENT(p, S_CORE, 0);
+
+ if (sugid_coredump == 0 && p->p_flag & P_SUGID)
+ return (EFAULT);
+ if (ctob(UPAGES + vm->vm_dsize + vm->vm_ssize) >=
+ p->p_rlimit[RLIMIT_CORE].rlim_cur)
+ return (EFAULT);
+ name = expand_name(p->p_comm, p->p_ucred->cr_uid, p->p_pid);
+ if (name == NULL)
+ return (EFAULT); /* XXX -- not the best error */
+
+ NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p);
+ error = vn_open(&nd, O_CREAT | FWRITE, S_IRUSR | S_IWUSR);
+ free(name, M_TEMP);
+ if (error)
+ return (error);
+ vp = nd.ni_vp;
+
+ /* Don't dump to non-regular files or files with links. */
+ if (vp->v_type != VREG ||
+ VOP_GETATTR(vp, &vattr, cred, p) || vattr.va_nlink != 1) {
+ error = EFAULT;
+ goto out;
+ }
+ VATTR_NULL(&vattr);
+ vattr.va_size = 0;
+ VOP_LEASE(vp, p, cred, LEASE_WRITE);
+ VOP_SETATTR(vp, &vattr, cred, p);
+ p->p_acflag |= ACORE;
+ bcopy(p, &p->p_addr->u_kproc.kp_proc, sizeof(struct proc));
+ fill_eproc(p, &p->p_addr->u_kproc.kp_eproc);
+ error = cpu_coredump(p, vp, cred);
+ if (error == 0)
+ error = vn_rdwr(UIO_WRITE, vp, vm->vm_daddr,
+ (int)ctob(vm->vm_dsize), (off_t)ctob(UPAGES), UIO_USERSPACE,
+ IO_NODELOCKED|IO_UNIT, cred, (int *) NULL, p);
+ if (error == 0)
+ error = vn_rdwr(UIO_WRITE, vp,
+ (caddr_t) trunc_page(USRSTACK - ctob(vm->vm_ssize)),
+ round_page(ctob(vm->vm_ssize)),
+ (off_t)ctob(UPAGES) + ctob(vm->vm_dsize), UIO_USERSPACE,
+ IO_NODELOCKED|IO_UNIT, cred, (int *) NULL, p);
+out:
+ VOP_UNLOCK(vp, 0, p);
+ error1 = vn_close(vp, FWRITE, cred, p);
+ if (error == 0)
+ error = error1;
+ return (error);
+}
+
+/*
* Tell kern_execve.c about it, with a little help from the linker.
* Since `const' objects end up in the text segment, TEXT_SET is the
* correct directive to use.
diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c
index 96c0a5e..e6dc3cf 100644
--- a/sys/kern/imgact_elf.c
+++ b/sys/kern/imgact_elf.c
@@ -26,7 +26,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: imgact_elf.c,v 1.28 1998/07/15 05:00:26 bde Exp $
+ * $Id: imgact_elf.c,v 1.29 1998/07/29 18:39:35 dfr Exp $
*/
#include "opt_rlimit.h"
@@ -101,7 +101,8 @@ static struct sysentvec elf_freebsd_sysvec = {
sigcode,
&szsigcode,
0,
- "FreeBSD ELF"
+ "FreeBSD ELF",
+ elf_coredump
};
static Elf_Brandinfo freebsd_brand_info = {
@@ -638,6 +639,14 @@ fail:
return error;
}
+int
+elf_coredump (p)
+ register struct proc *p;
+{
+ /* Not implemented yet. */
+ return EFAULT;
+}
+
static int
elf_freebsd_fixup(long **stack_base, struct image_params *imgp)
{
diff --git a/sys/kern/init_sysvec.c b/sys/kern/init_sysvec.c
deleted file mode 100644
index 35a04e2..0000000
--- a/sys/kern/init_sysvec.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * sysentvec for native FreeBSD a.out executable format.
- *
- * $Id: init_sysvec.c,v 1.5 1997/08/02 14:31:26 bde Exp $
- */
-
-#include <sys/param.h>
-#include <sys/sysent.h>
-#include <sys/syscall.h>
-#include <sys/signalvar.h>
-#include <machine/md_var.h>
-
-struct sysentvec aout_sysvec = {
- SYS_MAXSYSCALL,
- sysent,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- 0,
- sendsig,
- sigcode,
- &szsigcode,
- 0,
- "FreeBSD a.out"
-};
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index f3dadae..60053f6 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)kern_sig.c 8.7 (Berkeley) 4/18/94
- * $Id: kern_sig.c,v 1.44 1998/07/15 02:32:09 bde Exp $
+ * $Id: kern_sig.c,v 1.45 1998/07/28 22:33:47 joerg Exp $
*/
#include "opt_compat.h"
@@ -76,11 +76,9 @@
#include <vm/vm_map.h>
#include <sys/user.h>
-static int coredump __P((struct proc *p));
static int killpg1 __P((struct proc *cp, int signum, int pgid, int all));
static void setsigvec __P((struct proc *p, int signum, struct sigaction *sa));
static void stop __P((struct proc *));
-static char *expand_name __P((const char*, int, int));
static int kern_logsigexit = 1;
SYSCTL_INT(_kern, KERN_LOGSIGEXIT, logsigexit, CTLFLAG_RW, &kern_logsigexit, 0, "");
@@ -96,7 +94,7 @@ SYSCTL_INT(_kern, KERN_LOGSIGEXIT, logsigexit, CTLFLAG_RW, &kern_logsigexit, 0,
(pc)->pc_ucred->cr_uid == (q)->p_ucred->cr_uid || \
((signum) == SIGCONT && (q)->p_session == (p)->p_session))
-static int sugid_coredump;
+int sugid_coredump;
SYSCTL_INT(_kern, OID_AUTO, sugid_coredump, CTLFLAG_RW, &sugid_coredump, 0, "");
#ifndef _SYS_SYSPROTO_H_
@@ -1239,7 +1237,12 @@ sigexit(p, signum)
* these messages.)
* XXX : Todo, as well as euid, write out ruid too
*/
- if (coredump(p) == 0)
+
+ /* Use the correct function to dump core, as stored in
+ the sysentvec struct. This way we can do ELF and a.out
+ dumps without breaking a sweat. */
+ if (p->p_sysent->sv_coredump != NULL &&
+ (*p->p_sysent->sv_coredump)(p) == 0)
signum |= WCOREFLAG;
if (kern_logsigexit)
log(LOG_INFO,
@@ -1269,7 +1272,7 @@ SYSCTL_STRING(_kern, OID_AUTO, corefile, CTLFLAG_RW, corefilename,
* This is controlled by the sysctl variable kern.corefile (see above).
*/
-static char *
+char *
expand_name(name, uid, pid)
const char *name; int uid; int pid; {
char *temp;
@@ -1334,73 +1337,6 @@ const char *name; int uid; int pid; {
return temp;
}
-
-/*
- * Dump core, into a file named "progname.core", unless the process was
- * setuid/setgid.
- */
-static int
-coredump(p)
- register struct proc *p;
-{
- register struct vnode *vp;
- register struct ucred *cred = p->p_cred->pc_ucred;
- register struct vmspace *vm = p->p_vmspace;
- struct nameidata nd;
- struct vattr vattr;
- int error, error1;
- char *name; /* name of corefile */
-
- STOPEVENT(p, S_CORE, 0);
-
- if (sugid_coredump == 0 && p->p_flag & P_SUGID)
- return (EFAULT);
- if (ctob(UPAGES + vm->vm_dsize + vm->vm_ssize) >=
- p->p_rlimit[RLIMIT_CORE].rlim_cur)
- return (EFAULT);
- name = expand_name(p->p_comm, p->p_ucred->cr_uid, p->p_pid);
- if (name == NULL)
- return (EFAULT); /* XXX -- not the best error */
-
- NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p);
- error = vn_open(&nd, O_CREAT | FWRITE, S_IRUSR | S_IWUSR);
- free(name, M_TEMP);
- if (error)
- return (error);
- vp = nd.ni_vp;
-
- /* Don't dump to non-regular files or files with links. */
- if (vp->v_type != VREG ||
- VOP_GETATTR(vp, &vattr, cred, p) || vattr.va_nlink != 1) {
- error = EFAULT;
- goto out;
- }
- VATTR_NULL(&vattr);
- vattr.va_size = 0;
- VOP_LEASE(vp, p, cred, LEASE_WRITE);
- VOP_SETATTR(vp, &vattr, cred, p);
- p->p_acflag |= ACORE;
- bcopy(p, &p->p_addr->u_kproc.kp_proc, sizeof(struct proc));
- fill_eproc(p, &p->p_addr->u_kproc.kp_eproc);
- error = cpu_coredump(p, vp, cred);
- if (error == 0)
- error = vn_rdwr(UIO_WRITE, vp, vm->vm_daddr,
- (int)ctob(vm->vm_dsize), (off_t)ctob(UPAGES), UIO_USERSPACE,
- IO_NODELOCKED|IO_UNIT, cred, (int *) NULL, p);
- if (error == 0)
- error = vn_rdwr(UIO_WRITE, vp,
- (caddr_t) trunc_page(USRSTACK - ctob(vm->vm_ssize)),
- round_page(ctob(vm->vm_ssize)),
- (off_t)ctob(UPAGES) + ctob(vm->vm_dsize), UIO_USERSPACE,
- IO_NODELOCKED|IO_UNIT, cred, (int *) NULL, p);
-out:
- VOP_UNLOCK(vp, 0, p);
- error1 = vn_close(vp, FWRITE, cred, p);
- if (error == 0)
- error = error1;
- return (error);
-}
-
/*
* Nonexistent system call-- signal process (may want to handle it).
* Flag error in case process won't see signal immediately (blocked or ignored).
diff --git a/sys/sys/imgact_aout.h b/sys/sys/imgact_aout.h
index b577da0..f05c002 100644
--- a/sys/sys/imgact_aout.h
+++ b/sys/sys/imgact_aout.h
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* from: @(#)exec.h 8.1 (Berkeley) 6/11/93
- * $Id: imgact_aout.h,v 1.7 1997/02/22 09:45:18 peter Exp $
+ * $Id: imgact_aout.h,v 1.8 1997/12/19 20:44:48 bde Exp $
*/
#ifndef _IMGACT_AOUT_H_
@@ -147,4 +147,12 @@ struct exec {
#define EX_DYNAMIC 0x20 /* contains run-time link-edit info */
#define EX_DPMASK 0x30 /* mask for the above */
+#ifdef KERNEL
+struct proc;
+
+__BEGIN_DECLS
+int aout_coredump __P((struct proc *));
+__END_DECLS
+#endif /* KERNEL */
+
#endif /* !_IMGACT_AOUT_H_ */
diff --git a/sys/sys/imgact_elf.h b/sys/sys/imgact_elf.h
index 60857f1..d44e4aa 100644
--- a/sys/sys/imgact_elf.h
+++ b/sys/sys/imgact_elf.h
@@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: imgact_elf.h,v 1.7 1998/06/07 17:13:01 dfr Exp $
+ * $Id: imgact_elf.h,v 1.8 1998/09/07 07:30:44 dfr Exp $
*/
#ifndef _SYS_IMGACT_ELF_H_
@@ -99,6 +99,11 @@ int elf_remove_brand_entry __P((Elf64_Brandinfo *entry));
#endif
+struct proc;
+
+__BEGIN_DECLS
+int elf_coredump __P((struct proc *));
+__END_DECLS
#endif /* KERNEL */
diff --git a/sys/sys/signalvar.h b/sys/sys/signalvar.h
index 320120e..3976a4f 100644
--- a/sys/sys/signalvar.h
+++ b/sys/sys/signalvar.h
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)signalvar.h 8.6 (Berkeley) 2/19/95
- * $Id: signalvar.h,v 1.17 1998/02/24 02:01:11 bde Exp $
+ * $Id: signalvar.h,v 1.18 1998/03/28 10:33:23 bde Exp $
*/
#ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */
@@ -153,10 +153,13 @@ static int sigprop[NSIG + 1] = {
struct pgrp;
struct proc;
+extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */
+
/*
* Machine-independent functions:
*/
void execsigs __P((struct proc *p));
+char *expand_name __P((const char*, int, int));
void gsignal __P((int pgid, int sig));
int issignal __P((struct proc *p));
void killproc __P((struct proc *p, char *why));
diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h
index df624aa..114fe35 100644
--- a/sys/sys/sysent.h
+++ b/sys/sys/sysent.h
@@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: sysent.h,v 1.17 1998/04/28 18:15:08 eivind Exp $
+ * $Id: sysent.h,v 1.18 1998/06/07 17:13:03 dfr Exp $
*/
#ifndef _SYS_SYSENT_H_
@@ -69,6 +69,8 @@ struct sysentvec {
void (*sv_prepsyscall) __P((struct trapframe *, int *,
u_int *, caddr_t *));
char *sv_name; /* name of binary type */
+ int (*sv_coredump) __P((struct proc *p));
+ /* function to dump core, or NULL */
};
#ifdef KERNEL
OpenPOWER on IntegriCloud