4 * Copyright (C) 1991, 1992 Linus Torvalds
7 #include <linux/types.h>
8 #include <linux/errno.h>
9 #include <linux/sched.h>
10 #include <linux/kernel.h>
12 #include <asm/segment.h>
16 * mem_write isn't really a good idea right now. It needs
17 * to check a lot more: if the process we try to write to
18 * dies in the middle right now, mem_write will overwrite
19 * kernel memory.. This disables it altogether.
21 #define mem_write NULL
23 static int mem_read(struct inode
* inode
, struct file
* file
,char * buf
, int count
)
25 unsigned long addr
, pid
, cr3
;
27 unsigned long pte
, page
;
35 for (i
= 1 ; i
< NR_TASKS
; i
++)
36 if (task
[i
] && task
[i
]->pid
== pid
) {
37 cr3
= task
[i
]->tss
.cr3
;
45 if (current
->signal
& ~current
->blocked
)
47 pte
= *PAGE_DIR_OFFSET(cr3
,addr
);
48 if (!(pte
& PAGE_PRESENT
))
51 pte
+= PAGE_PTR(addr
);
52 page
= *(unsigned long *) pte
;
56 page
+= addr
& ~PAGE_MASK
;
57 i
= PAGE_SIZE
-(addr
& ~PAGE_MASK
);
60 memcpy_tofs(tmp
,(void *) page
,i
);
71 static int mem_write(struct inode
* inode
, struct file
* file
,char * buf
, int count
)
73 unsigned long addr
, pid
, cr3
;
75 unsigned long pte
, page
;
84 for (i
= 1 ; i
< NR_TASKS
; i
++)
85 if (task
[i
] && task
[i
]->pid
== pid
) {
86 cr3
= task
[i
]->tss
.cr3
;
93 if (current
->signal
& ~current
->blocked
)
95 pte
= *PAGE_DIR_OFFSET(cr3
,addr
);
96 if (!(pte
& PAGE_PRESENT
))
99 pte
+= PAGE_PTR(addr
);
100 page
= *(unsigned long *) pte
;
101 if (!(page
& PAGE_PRESENT
))
104 do_wp_page(0,addr
,current
,0);
108 page
+= addr
& ~PAGE_MASK
;
109 i
= PAGE_SIZE
-(addr
& ~PAGE_MASK
);
112 memcpy_fromfs((void *) page
,tmp
,i
);
120 if (current
->signal
& ~current
->blocked
)
127 static int mem_lseek(struct inode
* inode
, struct file
* file
, off_t offset
, int orig
)
131 file
->f_pos
= offset
;
134 file
->f_pos
+= offset
;
141 static struct file_operations proc_mem_operations
= {
145 NULL
, /* mem_readdir */
146 NULL
, /* mem_select */
147 NULL
, /* mem_ioctl */
149 NULL
, /* no special open code */
150 NULL
, /* no special release code */
151 NULL
/* can't fsync */
154 struct inode_operations proc_mem_inode_operations
= {
155 &proc_mem_operations
, /* default base directory file-ops */
166 NULL
, /* follow_link */
169 NULL
/* permission */