From: "H . J . Lu" <hjl@lucon.org>
To: Eric Paire <paire@ri.silicomp.fr>
Cc: Andrew Cagney <ac131313@cygnus.com>,
Mark Kettenis <kettenis@science.uva.nl>,
GDB <gdb@sourceware.cygnus.com>
Subject: Re: Is the current gdb 5.1 broken for Linuxthreads?
Date: Thu, 20 Sep 2001 08:03:00 -0000 [thread overview]
Message-ID: <20010920080356.A18774@lucon.org> (raw)
In-Reply-To: <200109200836.f8K8a6p05580@mailhost.ri.silicomp.fr>
On Thu, Sep 20, 2001 at 10:36:06AM +0200, Eric Paire wrote:
>
> There is another difficulty on Linux which seems much more important than
> these ones. There is no support for MT core dumps. As Linus has always
> refused to add such functionality in the kernel (which is somewhat similar
> with your simple interface to stop all threads), a solution should be though
> of in the user space.
>
Try the current Red Hat kernel/ac kernel. They support it. The patch is
very small. I am enclosing it here.
H.J.
--
Index: linux-2.4/fs/binfmt_aout.c
===================================================================
RCS file: /trillian/src/cvs_root/linux-2.4/fs/binfmt_aout.c,v
retrieving revision 1.1
diff -u -r1.1 binfmt_aout.c
--- linux-2.4/fs/binfmt_aout.c 2001/02/06 23:40:30 1.1
+++ linux-2.4/fs/binfmt_aout.c 2001/02/27 16:50:43
@@ -31,7 +31,8 @@
static int load_aout_binary(struct linux_binprm *, struct pt_regs * regs);
static int load_aout_library(struct file*);
-static int aout_core_dump(long signr, struct pt_regs * regs, struct file *file);
+static int aout_core_dump(long signr, struct pt_regs * regs,
+ struct file *file, struct mm_struct * mm);
extern void dump_thread(struct pt_regs *, struct user *);
@@ -78,7 +79,8 @@
* dumping of the process results in another error..
*/
-static int aout_core_dump(long signr, struct pt_regs * regs, struct file *file)
+static int aout_core_dump(long signr, struct pt_regs * regs,
+ struct file * file, struct mm_struct * mm)
{
mm_segment_t fs;
int has_dumped = 0;
Index: linux-2.4/fs/binfmt_elf.c
===================================================================
RCS file: /trillian/src/cvs_root/linux-2.4/fs/binfmt_elf.c,v
retrieving revision 1.1
diff -u -r1.1 binfmt_elf.c
--- linux-2.4/fs/binfmt_elf.c 2001/02/06 23:40:30 1.1
+++ linux-2.4/fs/binfmt_elf.c 2001/02/27 16:50:43
@@ -56,7 +56,8 @@
* don't even try.
*/
#ifdef USE_ELF_CORE_DUMP
-static int elf_core_dump(long signr, struct pt_regs * regs, struct file * file);
+static int elf_core_dump(long signr, struct pt_regs * regs,
+ struct file * file, struct mm_struct * mm);
#else
#define elf_core_dump NULL
#endif
@@ -981,7 +982,8 @@
* and then they are actually written out. If we run out of core limit
* we just truncate.
*/
-static int elf_core_dump(long signr, struct pt_regs * regs, struct file * file)
+static int elf_core_dump(long signr, struct pt_regs * regs,
+ struct file * file, struct mm_struct * mm)
{
int has_dumped = 0;
mm_segment_t fs;
@@ -998,7 +1000,7 @@
elf_fpregset_t fpu; /* NT_PRFPREG */
struct elf_prpsinfo psinfo; /* NT_PRPSINFO */
- segs = current->mm->map_count;
+ segs = mm->map_count;
#ifdef DEBUG
printk("elf_core_dump: %d segs %lu limit\n", segs, limit);
@@ -1158,7 +1160,7 @@
dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
/* Write program headers for segments dump */
- for(vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
+ for(vma = mm->mmap; vma != NULL; vma = vma->vm_next) {
struct elf_phdr phdr;
size_t sz;
@@ -1187,7 +1189,7 @@
DUMP_SEEK(dataoff);
- for(vma = current->mm->mmap; vma != NULL; vma = vma->vm_next) {
+ for(vma = mm->mmap; vma != NULL; vma = vma->vm_next) {
unsigned long addr;
if (!maydump(vma))
Index: linux-2.4/fs/exec.c
===================================================================
RCS file: /trillian/src/cvs_root/linux-2.4/fs/exec.c,v
retrieving revision 1.2
diff -u -r1.2 exec.c
--- linux-2.4/fs/exec.c 2001/02/07 01:17:26 1.2
+++ linux-2.4/fs/exec.c 2001/02/27 16:50:43
@@ -916,16 +916,18 @@
int do_coredump(long signr, struct pt_regs * regs)
{
+ struct mm_struct *mm;
struct linux_binfmt * binfmt;
- char corename[6+sizeof(current->comm)];
+ char corename[6+sizeof(current->comm)+10];
struct file * file;
struct inode * inode;
+ int r;
lock_kernel();
binfmt = current->binfmt;
if (!binfmt || !binfmt->core_dump)
goto fail;
- if (!current->dumpable || atomic_read(¤t->mm->mm_users) != 1)
+ if (!current->dumpable)
goto fail;
current->dumpable = 0;
if (current->rlim[RLIMIT_CORE].rlim_cur < binfmt->min_coredump)
@@ -937,6 +939,8 @@
#else
corename[4] = '\0';
#endif
+ if (atomic_read(¤t->mm->mm_users) != 1)
+ sprintf(&corename[4], ".%d", current->pid);
file = filp_open(corename, O_CREAT | 2 | O_NOFOLLOW, 0600);
if (IS_ERR(file))
goto fail;
@@ -954,10 +958,29 @@
goto close_fail;
if (do_truncate(file->f_dentry, 0) != 0)
goto close_fail;
- if (!binfmt->core_dump(signr, regs, file))
- goto close_fail;
+ /*
+ * Copy the mm structure to avoid potential races with
+ * other threads
+ */
+ if ((mm = kmem_cache_alloc(mm_cachep, SLAB_KERNEL)) == NULL)
+ goto close_fail;
+ memcpy(mm, current->mm, sizeof(*mm));
+ if (!mm_init(mm)) {
+ kmem_cache_free(mm_cachep, mm);
+ goto close_fail;
+ }
+ down(¤t->mm->mmap_sem);
+ r = dup_mmap(mm);
+ up(¤t->mm->mmap_sem);
+ if (r) {
+ mmput(mm);
+ goto close_fail;
+ }
+ r = binfmt->core_dump(signr, regs, file, mm);
+ mmput(mm);
unlock_kernel();
- filp_close(file, NULL);
+ if (r)
+ filp_close(file, NULL);
return 1;
close_fail:
Index: linux-2.4/include/linux/binfmts.h
===================================================================
RCS file: /trillian/src/cvs_root/linux-2.4/include/linux/binfmts.h,v
retrieving revision 1.1
diff -u -r1.1 binfmts.h
--- linux-2.4/include/linux/binfmts.h 2001/02/06 23:41:21 1.1
+++ linux-2.4/include/linux/binfmts.h 2001/02/27 16:50:43
@@ -41,7 +41,8 @@
struct module *module;
int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
int (*load_shlib)(struct file *);
- int (*core_dump)(long signr, struct pt_regs * regs, struct file * file);
+ int (*core_dump)(long signr, struct pt_regs * regs,
+ struct file * file, struct mm_struct *mm);
unsigned long min_coredump; /* minimal dump size */
};
Index: linux-2.4/kernel/fork.c
===================================================================
RCS file: /trillian/src/cvs_root/linux-2.4/kernel/fork.c,v
retrieving revision 1.2
diff -u -r1.2 fork.c
--- linux-2.4/kernel/fork.c 2001/02/07 01:17:29 1.2
+++ linux-2.4/kernel/fork.c 2001/02/27 16:50:43
@@ -122,7 +122,7 @@
return last_pid;
}
-static inline int dup_mmap(struct mm_struct * mm)
+int dup_mmap(struct mm_struct * mm)
{
struct vm_area_struct * mpnt, *tmp, **pprev;
int retval;
@@ -197,7 +197,7 @@
#define allocate_mm() (kmem_cache_alloc(mm_cachep, SLAB_KERNEL))
#define free_mm(mm) (kmem_cache_free(mm_cachep, (mm)))
-static struct mm_struct * mm_init(struct mm_struct * mm)
+struct mm_struct * mm_init(struct mm_struct * mm)
{
atomic_set(&mm->mm_users, 1);
atomic_set(&mm->mm_count, 1);
next prev parent reply other threads:[~2001-09-20 8:03 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-09-17 12:47 H . J . Lu
[not found] ` <20010917161350.A25349@lucon.org>
2001-09-17 19:13 ` H . J . Lu
2001-09-18 13:56 ` H . J . Lu
2001-09-18 15:22 ` RFC: Fix gdb 5.1 for Linuxthreads H . J . Lu
2001-09-19 5:42 ` Duncan Palmer
2001-09-19 9:19 ` H . J . Lu
2001-09-20 8:21 ` Duncan Palmer
2001-09-19 7:06 ` Mark Kettenis
2001-09-19 8:58 ` H . J . Lu
2001-09-19 0:46 ` Is the current gdb 5.1 broken for Linuxthreads? Eli Zaretskii
2001-09-19 8:43 ` H . J . Lu
2001-09-19 6:56 ` Mark Kettenis
2001-09-19 7:39 ` Eric Paire
2001-09-19 9:05 ` H . J . Lu
2001-09-20 0:59 ` Eric Paire
2001-09-19 13:39 ` Andrew Cagney
2001-09-20 1:36 ` Eric Paire
2001-09-20 8:03 ` H . J . Lu [this message]
2001-09-20 21:49 ` Eric Paire
2001-09-19 9:10 ` H . J . Lu
2001-09-19 6:32 ` Mark Kettenis
2001-09-19 9:16 ` H . J . Lu
2001-09-21 2:27 James Cownie
2001-09-21 5:04 ` Eric Paire
2001-09-21 5:25 ` James Cownie
2001-09-21 8:35 ` H . J . Lu
2001-09-21 8:39 ` Andrew Cagney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010920080356.A18774@lucon.org \
--to=hjl@lucon.org \
--cc=ac131313@cygnus.com \
--cc=gdb@sourceware.cygnus.com \
--cc=kettenis@science.uva.nl \
--cc=paire@ri.silicomp.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox