summaryrefslogtreecommitdiff
path: root/package/exmap/patches/patch-kernel_exmap_c
blob: 08b22ea0240f498df039b26ae18741adafc400b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
$Id: update-patches 24 2008-08-31 14:56:13Z wbx $
--- exmap-console-0.4.1.orig/kernel/exmap.c	2006-10-24 20:45:11.000000000 +0200
+++ exmap-console-0.4.1/kernel/exmap.c	2013-11-02 18:56:21.000000000 +0100
@@ -340,24 +340,22 @@ static int show_vma_start(struct exmap_v
 }
 
 
-static int exmap_show_next(char *buffer, int length)
+static ssize_t exmap_show_next(char *buffer, size_t length)
 {
-	int offset = 0;
+	ssize_t offset = 0;
 	struct exmap_vma_data *vma_data;
 	pte_t pte;
 	int line_len;
 
 	while (local_data.vma_cursor < local_data.num_vmas) {
 		vma_data = local_data.vma_data + local_data.vma_cursor;
-//		printk (KERN_INFO
-//			"exmap: examining vma %08lx [%d/%d] %d\n",
-//			vma_data->vm_start,
-//			local_data.vma_cursor,
-//			local_data.num_vmas,
-//			vma_data->start_shown);
+		printk (KERN_INFO
+			"exmap: examining vma %08lx [%d/%d] %d\n",
+			vma_data->vm_start,
+			local_data.vma_cursor,
+			local_data.num_vmas,
+			vma_data->start_shown);
 		if (!vma_data->start_shown) {
-//			printk (KERN_INFO
-//				"exmap: svs\n");
 			line_len = show_vma_start(vma_data,
 						  buffer + offset,
 						  length - offset);
@@ -392,7 +390,11 @@ int setup_from_pid(pid_t pid)
 	struct task_struct *tsk;
 	int errcode = -EINVAL;
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26)
+	tsk = find_task_by_vpid(pid);
+#else
 	tsk = find_task_by_pid(pid);
+#endif
 	if (tsk == NULL) {
 		printk (KERN_ALERT
 			"/proc/%s: can't find task for pid %d\n",
@@ -445,10 +447,10 @@ Exit:
  * where deadbeef is the hex addr of the vma to examine
  * and pid is the (decimal) pid of the process to examine
  */
-static int procfile_write (struct file *file,
+static ssize_t procfile_write (struct file *file,
 			   const char __user *buffer,
-			   unsigned long count,
-			   void *data)
+			   size_t count,
+			   loff_t *off)
 {
 	pid_t pid;
 	int errcode = -EINVAL;
@@ -475,14 +477,11 @@ static int procfile_write (struct file *
  * Only support sequential reading of file from start to finish
  * (following a write() to set the pid to examine
  */
-static int procfile_read (char *buffer,
-			  char **buffer_location,
-			  off_t offset,
-			  int buffer_length,
-			  int *eof,
-			  void *data)
+static ssize_t procfile_read (struct file *filp,
+			  char __user *buf,
+			  size_t len,
+			  loff_t *ppos)
 {
-	int ret;
 
 	if (local_data.vma_data == NULL) {
 		printk (KERN_ALERT "/proc/%s: vma data not set\n",
@@ -490,47 +489,40 @@ static int procfile_read (char *buffer,
 		return -EINVAL;
 	}
 	
-	ret = exmap_show_next(buffer, buffer_length);
-	if (ret > 0) {
-		*buffer_location = buffer;
-	}
-	return ret;
+	return exmap_show_next(buf, len);
 }
 
-int init_module ()
+static const struct file_operations proc_file_fops = {
+ .owner = THIS_MODULE,
+ .write  = procfile_write,
+ .read  = procfile_read,
+};
+
+
+static int __init exmap_init(void)
 {
 	struct proc_dir_entry *exmap_proc_file;
 	printk (KERN_INFO "/proc/%s: insert\n", PROCFS_NAME);
 	
-	exmap_proc_file = create_proc_entry (PROCFS_NAME,
+	exmap_proc_file = proc_create (PROCFS_NAME,
 							0644,
-							NULL);
+							NULL,
+					&proc_file_fops);
 
 	if (exmap_proc_file == NULL) {
-		remove_proc_entry (PROCFS_NAME, &proc_root);
 		printk (KERN_ALERT "/proc/%s: could not initialize\n",
 			PROCFS_NAME);
 		return -ENOMEM;
 	}
 	
-	exmap_proc_file->read_proc = procfile_read;
-	exmap_proc_file->write_proc = procfile_write;
-	exmap_proc_file->owner = THIS_MODULE;
-	
-	/*     exmap_proc_file->mode         = S_IFREG | S_IRUGO; */
-	/* TODO - this is quite probably a security problem */
-	exmap_proc_file->mode = 0666;
-	
-	exmap_proc_file->uid = 0;
-	exmap_proc_file->gid = 0;
-	exmap_proc_file->size = 0;
-
 	init_local_data();
 	return 0;
 }
 
-void cleanup_module ()
+static void __exit exmap_exit(void)
 {
-	printk (KERN_INFO "/proc/%s: remove\n", PROCFS_NAME);
-	remove_proc_entry (PROCFS_NAME, &proc_root);
+	remove_proc_entry(PROCFS_NAME, NULL);
 }
+
+module_init(exmap_init);
+module_exit(exmap_exit);