commit
[crak.git] / src / ckptlib.h
blobd1cddd8b84d4eb1a7a24ecb12d53eb40e95f04ce
1 #ifndef _CKPTLIB_H
2 #define _CKPTLIB_H
4 #if 0
5 #define IS_SYS_CALL(regs) (((regs).orig_eax>=0) && \
6 ((regs).eax == -ERESTARTNOHAND || \
7 (regs).eax == -ERESTARTSYS || \
8 (regs).eax == -ERESTARTNOINTR) )
9 #endif
11 #define IS_FD_NAMED(fdes) ((fdes)->f_dentry->d_name.name)
15 /* dump.c */
16 void dump_header_struct(struct file *, struct task_struct *, int);
17 void dump_registers(struct file *, struct task_struct *, struct pt_regs *, int);
18 void dump_memory_struct(struct file *, struct task_struct *);
19 void dump_segments(struct file *, struct mm_struct *, int);
20 void dump_vm_areas(struct file *, struct task_struct *);
21 int get_file_cnt(struct task_struct *, struct files_struct *);
22 int dump_open_files(struct file *, struct task_struct *,
23 struct files_struct *, int *);
24 void dump_cwd(struct file *, struct task_struct *, int *);
25 void dump_signal(struct file *, struct task_struct *, int *);
27 void write_end(struct file *);
29 /* restore.c */
30 struct header * restore_header_struct(struct file *);
31 struct pt_regs * get_registers(struct file *);
32 void restore_memory_struct(struct file *, struct header *);
33 unsigned long restore_vm_areas(struct file *, int, int);
34 int restore_open_files(struct file *);
35 void restore_cwd(struct file *);
36 void restore_signal(struct file *);
39 /* main.c */
40 char *get_kernel_address(struct task_struct *,
41 struct vm_area_struct *,
42 unsigned long);
43 struct file *open_private_file(int, const char *, int, int);
47 * Extracts flags from vm_flags value.
49 static inline unsigned long get_mmap_flags(unsigned short vm_flags)
52 return MAP_FIXED |
53 (vm_flags & VM_MAYSHARE? MAP_SHARED : MAP_PRIVATE) |
54 (vm_flags & VM_GROWSDOWN) |
55 (vm_flags & VM_DENYWRITE) |
56 (vm_flags & VM_EXECUTABLE);
61 static inline int inside(unsigned long a,
62 unsigned long b,
63 unsigned long c)
65 return (c <= b) && (c >= a);
69 static inline int valid_memory_segment(struct pt_regs *regs,
70 struct mm_struct *mm,
71 struct vm_area_struct *vma)
73 if (inside(mm->start_code, mm->end_code, vma->vm_start))
74 return 1;
75 else if (inside(mm->end_code, mm->end_data, vma->vm_start))
76 return 1;
77 else if (inside(mm->end_data, mm->brk, vma->vm_start))
78 return 1;
79 else if (inside(mm->start_stack, 0xC0000000, vma->vm_start))
80 return 1;
81 else if (inside(vma->vm_start, vma->vm_end, regs->sp))
82 return 1;
83 else
84 return 0;
87 static char prot_char[] = {'r', 'w', 'x'};
88 static inline void print_prot(uint32_t prot)
90 int i = 0;
92 prot &= 7;
93 for (; i < 3; i++) {
94 if (prot & 1)
95 printk("%c", prot_char[i]);
96 else
97 printk("-");
99 prot >>= 1;
103 static inline void print_flags(uint32_t flags)
107 if (get_mmap_flags(flags) & MAP_SHARED)
108 printk("s ");
109 else
110 printk("p ");
112 if (flags & MAP_FIXED)
113 printk("MAP_FIXED ");
114 if (flags & MAP_ANONYMOUS)
115 printk("MAP_ANONYMOUS ");
118 if (flags & MAP_GROWSDOWN)
119 printk("MAP_GROWSDOWN ");
120 if (flags & MAP_DENYWRITE)
121 printk("MAP_DENYWRITE ");
122 if (flags & MAP_EXECUTABLE)
123 printk("MAP_EXECUTABLE ");
124 if (flags & MAP_LOCKED)
125 printk("MAP_LOCKED ");
126 if (flags & MAP_POPULATE)
127 printk("MAP_POPULATE ");
128 if (flags & MAP_NONBLOCK)
129 printk("MAP_NONBLOCK ");
131 printk("\n");
134 #endif