Skip to content

Commit c3a6981

Browse files
author
victor
committed
Added registers
1 parent 00efb0d commit c3a6981

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

fs/proc/base.c

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,98 @@ static const struct file_operations proc_single_file_operations = {
808808
.release= single_release,
809809
};
810810

811+
812+
813+
static int reg_open(struct inode* inode, struct file* file)
814+
{
815+
file->private_data = (void*)((long)current->self_exec_id);
816+
/* OK to pass negative loff_t, we can catch out-of-range */
817+
file->f_mode |= FMODE_UNSIGNED_OFFSET;
818+
return 0;
819+
}
820+
821+
822+
static int ureg_open(struct inode* inode, struct file* file)
823+
{
824+
file->private_data = (void*)((long)current->self_exec_id);
825+
/* OK to pass negative loff_t, we can catch out-of-range */
826+
file->f_mode |= FMODE_UNSIGNED_OFFSET;
827+
return 0;
828+
}
829+
830+
831+
static ssize_t reg_read(struct file * file, char __user * buf,
832+
size_t count, loff_t *ppos)
833+
{
834+
struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
835+
if (count < 0) /* SOME SIZE? */
836+
{
837+
return -EINVAL; /* Is this correct error? */
838+
}
839+
ptrace_request(task, PTRACE_GETREGSET, 0,
840+
(unsigned long) buf);
841+
return 0;
842+
}
843+
844+
static ssize_t ureg_read(struct file * file, char __user * buf,
845+
size_t count, loff_t *ppos)
846+
{
847+
struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
848+
if (count < 0) /* SOME SIZE? */
849+
{
850+
return -EINVAL; /* Is this correct error? */
851+
}
852+
853+
long word = arch_ptrace(task, PTRACE_PEEKUSR, (unsigned long) *ppos,
854+
NULL);
855+
/* word may = -1, if so, this could be an error, but we cannot know */
856+
long *p = (long*) buf;
857+
*p = word;
858+
return 0;
859+
}
860+
861+
static ssize_t reg_write(struct file * file, const char __user *buf,
862+
size_t count, loff_t *ppos)
863+
{
864+
struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
865+
if (count < 0) /* SOME SIZE? */
866+
{
867+
return -EINVAL; /* Is this correct error? */
868+
}
869+
ptrace_request(task, PTRACE_SETREGSET, 0,
870+
(unsigned long) buf);
871+
return 0;
872+
}
873+
874+
static ssize_t ureg_write(struct file * file, const char __user *buf,
875+
size_t count, loff_t *ppos)
876+
{
877+
struct task_struct *task = get_proc_task(file->f_path.dentry->d_inode);
878+
if (count < 0) /* SOME SIZE? */
879+
{
880+
return -EINVAL; /* Is this correct error? */
881+
}
882+
unsigned long *b = (unsigned long*) buf;
883+
ptrace_request(task, PTRACE_POKEUSR, *ppos,
884+
*b);
885+
return 0;
886+
}
887+
888+
static const struct file_operations proc_reg_operations = {
889+
.llseek= generic_file_llseek,
890+
.read= reg_read,
891+
.write= reg_write,
892+
.open= reg_open,
893+
};
894+
895+
static const struct file_operations proc_ureg_operations = {
896+
.llseek= generic_file_llseek,
897+
.read= ureg_read,
898+
.write= ureg_write,
899+
.open= ureg_open,
900+
};
901+
902+
811903
static int mem_open(struct inode* inode, struct file* file)
812904
{
813905
file->private_data = (void*)((long)current->self_exec_id);
@@ -3365,6 +3457,8 @@ static const struct pid_entry tid_base_stuff[] = {
33653457
#ifdef CONFIG_HARDWALL
33663458
INF("hardwall", S_IRUGO, proc_pid_hardwall),
33673459
#endif
3460+
REG("regs", S_IRUGO, proc_reg_operations),
3461+
REG("uregs", S_IRUGO, proc_ureg_operations),
33683462
};
33693463

33703464
static int proc_tid_base_readdir(struct file * filp,

0 commit comments

Comments
 (0)