public inbox for linuxppc-dev@ozlabs.org
 help / color / mirror / Atom feed
From: Jeremy Kerr <jk@ozlabs.org>
To: <linuxppc-dev@ozlabs.org>
Subject: [PATCH 22/25] spufs: Cleanup ELF coredump extra notes logic
Date: Fri, 14 Sep 2007 16:32:54 +1000	[thread overview]
Message-ID: <1189751574.111677.686350189769.22.gpush@pokey> (raw)
In-Reply-To: <1189751574.98527.127994196313.1.gpush@pokey>

From: Michael Ellerman <michael@ellerman.id.au>

To start with, arch_notes_size() etc. is a little too ambiguous a name for
my liking, so change the function names to be more explicit.

Calling through macros is ugly, especially with hidden parameters, so don't
do that, call the routines directly.

Use ARCH_HAVE_EXTRA_ELF_NOTES as the only flag, and based on it decide
whether we want the extern declarations or the empty versions.

Since we have empty routines, actually use them in the coredump code to
save a few #ifdefs.

We want to change the handling of foffset so that the write routine updates
foffset as it goes, instead of using file->f_pos (so that writing to a pipe
works). So pass foffset to the write routine, and for now just set it to
file->f_pos at the end of writing.

It should also be possible for the write routine to fail, so change it to
return int and treat a non-zero return as failure.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>

---
 arch/powerpc/platforms/cell/spu_syscalls.c |   12 +++++++++---
 fs/binfmt_elf.c                            |   14 +++-----------
 include/asm-powerpc/elf.h                  |    9 ++-------
 include/linux/elf.h                        |   14 ++++++++------
 4 files changed, 22 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/platforms/cell/spu_syscalls.c b/arch/powerpc/platforms/cell/spu_syscalls.c
index cf00251..d9b2fd2 100644
--- a/arch/powerpc/platforms/cell/spu_syscalls.c
+++ b/arch/powerpc/platforms/cell/spu_syscalls.c
@@ -21,6 +21,7 @@
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 #include <linux/file.h>
+#include <linux/fs.h>
 #include <linux/module.h>
 #include <linux/syscalls.h>
 #include <linux/mutex.h>
@@ -109,7 +110,7 @@ asmlinkage long sys_spu_run(int fd, __u32 __user *unpc, __u32 __user *ustatus)
 	return ret;
 }
 
-int arch_notes_size(void)
+int elf_coredump_extra_notes_size(void)
 {
 	struct spufs_calls *calls;
 	int ret;
@@ -125,17 +126,22 @@ int arch_notes_size(void)
 	return ret;
 }
 
-void arch_write_notes(struct file *file)
+int elf_coredump_extra_notes_write(struct file *file, loff_t *foffset)
 {
 	struct spufs_calls *calls;
 
 	calls = spufs_calls_get();
 	if (!calls)
-		return;
+		return 0;
 
 	calls->coredump_extra_notes_write(file);
 
 	spufs_calls_put(calls);
+
+	/* Fudge foffset for now */
+	*foffset = file->f_pos;
+
+	return 0;
 }
 
 int register_spu_syscalls(struct spufs_calls *calls)
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 4482a06..b1013f3 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1514,9 +1514,6 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file)
 	int thread_status_size = 0;
 	elf_addr_t *auxv;
 	unsigned long mm_flags;
-#ifdef ELF_CORE_WRITE_EXTRA_NOTES
-	int extra_notes_size;
-#endif
 
 	/*
 	 * We no longer stop all VM operations.
@@ -1645,10 +1642,7 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file)
 		
 		sz += thread_status_size;
 
-#ifdef ELF_CORE_WRITE_EXTRA_NOTES
-		extra_notes_size = ELF_CORE_EXTRA_NOTES_SIZE;
-		sz += extra_notes_size;
-#endif
+		sz += elf_coredump_extra_notes_size();
 
 		fill_elf_note_phdr(&phdr, sz, offset);
 		offset += sz;
@@ -1698,10 +1692,8 @@ static int elf_core_dump(long signr, struct pt_regs *regs, struct file *file)
 		if (!writenote(notes + i, file, &foffset))
 			goto end_coredump;
 
-#ifdef ELF_CORE_WRITE_EXTRA_NOTES
-	ELF_CORE_WRITE_EXTRA_NOTES;
-	foffset += extra_notes_size;
-#endif
+	if (elf_coredump_extra_notes_write(file, &foffset))
+		goto end_coredump;
 
 	/* write out the thread status notes section */
 	list_for_each(t, &thread_list) {
diff --git a/include/asm-powerpc/elf.h b/include/asm-powerpc/elf.h
index de50799..e42820d 100644
--- a/include/asm-powerpc/elf.h
+++ b/include/asm-powerpc/elf.h
@@ -413,13 +413,8 @@ do {									\
 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
 #define NT_SPU		1
 
-extern int arch_notes_size(void);
-extern void arch_write_notes(struct file *file);
-
-#define ELF_CORE_EXTRA_NOTES_SIZE arch_notes_size()
-#define ELF_CORE_WRITE_EXTRA_NOTES arch_write_notes(file)
-
 #define ARCH_HAVE_EXTRA_ELF_NOTES
-#endif /* CONFIG_PPC_CELL */
+
+#endif /* CONFIG_SPU_BASE */
 
 #endif /* _ASM_POWERPC_ELF_H */
diff --git a/include/linux/elf.h b/include/linux/elf.h
index 8b17ffe..d2da84a 100644
--- a/include/linux/elf.h
+++ b/include/linux/elf.h
@@ -389,12 +389,14 @@ extern Elf64_Dyn _DYNAMIC [];
 
 #endif
 
+/* Optional callbacks to write extra ELF notes. */
 #ifndef ARCH_HAVE_EXTRA_ELF_NOTES
-static inline int arch_notes_size(void) { return 0; }
-static inline void arch_write_notes(struct file *file) { }
-
-#define ELF_CORE_EXTRA_NOTES_SIZE arch_notes_size()
-#define ELF_CORE_WRITE_EXTRA_NOTES arch_write_notes(file)
-#endif /* ARCH_HAVE_EXTRA_ELF_NOTES */
+static inline int elf_coredump_extra_notes_size(void) { return 0; }
+static inline int elf_coredump_extra_notes_write(struct file *file,
+			loff_t *foffset) { return 0; }
+#else
+extern int elf_coredump_extra_notes_size(void);
+extern int elf_coredump_extra_notes_write(struct file *file, loff_t *foffset);
+#endif
 
 #endif /* _LINUX_ELF_H */

  reply	other threads:[~2007-09-14  6:32 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-14  6:32 [PATCH 01/25] spufs: staticify file-internal functions & variables Jeremy Kerr
2007-09-14  6:32 ` Jeremy Kerr [this message]
2007-09-14  6:32 ` [PATCH 07/25] spufs: remove asmlinkage from spufs_calls Jeremy Kerr
2007-09-14  6:32 ` [PATCH 13/25] spufs: Call spu_acquire_saved() before calculating the SPU note sizes Jeremy Kerr
2007-09-14  6:32 ` [PATCH 04/25] spufs: make isolated loader properly aligned Jeremy Kerr
2007-09-14  6:32 ` [PATCH 25/25] spufs: Add DEFINE_SPUFS_ATTRIBUTE() Jeremy Kerr
2007-09-14  6:32 ` [PATCH 20/25] spufs: Add contents of npc file to SPU coredumps Jeremy Kerr
2007-09-14  6:32 ` [PATCH 23/25] spufs: Handle errors in SPU coredump code, and support coredump to a pipe Jeremy Kerr
2007-09-14  6:32 ` [PATCH 15/25] spufs: Write some SPU coredump values as ASCII Jeremy Kerr
2007-09-14  6:32 ` [PATCH 12/25] spufs: Remove ctx_info and ctx_info_list Jeremy Kerr
2007-09-14  6:32 ` [PATCH 21/25] spufs: Combine spufs_coredump_calls with spufs_calls Jeremy Kerr
2007-09-14  6:32 ` [PATCH 11/25] spufs: Extract the file descriptor search logic in SPU coredump code Jeremy Kerr
2007-09-14  6:32 ` [PATCH 17/25] spufs: Don't return -ENOSYS as extra notes size if spufs is not loaded Jeremy Kerr
2007-09-14  6:32 ` [PATCH 06/25] cell: unify spufs syscall path Jeremy Kerr
2007-09-14  6:32 ` [PATCH 16/25] spufs: Correctly calculate the size of the local-store to dump Jeremy Kerr
2007-09-14  6:32 ` [PATCH 18/25] spufs: Get rid of spufs_coredump_num_notes, it's not needed if we NULL terminate Jeremy Kerr
2007-09-14  6:32 ` [PATCH 09/25] cell: remove DEBUG for spu callbacks Jeremy Kerr
2007-09-14  7:43   ` Christoph Hellwig
2007-09-14  6:32 ` [PATCH 05/25] spufs: fix race condition on gang->aff_ref_spu Jeremy Kerr
2007-09-14  6:32 ` [PATCH 10/25] spusched: fix null pointer dereference in find_victim Jeremy Kerr
2007-09-14  7:44   ` Christoph Hellwig
2007-09-20  0:13     ` Jeremy Kerr
2007-09-14  6:32 ` [PATCH 24/25] spufs: Respect RLIMIT_CORE in spu coredump code Jeremy Kerr
2007-09-14  6:32 ` [PATCH 08/25] Fix restore_decr_wrapped() to match CBE Handbook Jeremy Kerr
2007-09-14  6:32 ` [PATCH 14/25] spufs: Use computed sizes/#defines rather than literals in SPU coredump code Jeremy Kerr
2007-09-14  6:32 ` [PATCH 19/25] spufs: Internal __spufs_get_foo() routines should take a spu_context * Jeremy Kerr
2007-09-14  7:43   ` Christoph Hellwig
2007-09-14  6:32 ` [PATCH 02/25] spufs: remove asmlinkage from do_spu_create Jeremy Kerr
2007-09-14  7:44   ` Christoph Hellwig
2007-09-14  6:32 ` [PATCH 03/25] spufs: remove spu_harvest Jeremy Kerr
2007-09-14  7:42 ` [PATCH 01/25] spufs: staticify file-internal functions & variables Christoph Hellwig

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=1189751574.111677.686350189769.22.gpush@pokey \
    --to=jk@ozlabs.org \
    --cc=linuxppc-dev@ozlabs.org \
    /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