coredump.h 974 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef _LINUX_COREDUMP_H
  2. #define _LINUX_COREDUMP_H
  3. #include <linux/types.h>
  4. #include <linux/mm.h>
  5. #include <linux/fs.h>
  6. /*
  7. * These are the only things you should do on a core-file: use only these
  8. * functions to write out all the necessary info.
  9. */
  10. static inline int dump_write(struct file *file, const void *addr, int nr)
  11. {
  12. return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
  13. }
  14. static inline int dump_seek(struct file *file, loff_t off)
  15. {
  16. int ret = 1;
  17. if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
  18. if (file->f_op->llseek(file, off, SEEK_CUR) < 0)
  19. return 0;
  20. } else {
  21. char *buf = (char *)get_zeroed_page(GFP_KERNEL);
  22. if (!buf)
  23. return 0;
  24. while (off > 0) {
  25. unsigned long n = off;
  26. if (n > PAGE_SIZE)
  27. n = PAGE_SIZE;
  28. if (!dump_write(file, buf, n)) {
  29. ret = 0;
  30. break;
  31. }
  32. off -= n;
  33. }
  34. free_page((unsigned long)buf);
  35. }
  36. return ret;
  37. }
  38. #endif /* _LINUX_COREDUMP_H */