Linux Audio

Check our new training course

Loading...
v6.13.7
  1/*
  2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3 * Licensed under the GPL
  4 */
  5
  6#include <linux/mm.h>
  7#include <linux/sched.h>
  8#include <linux/uaccess.h>
  9#include <linux/regset.h>
 10#include <asm/ptrace-abi.h>
 11#include <registers.h>
 12#include <skas.h>
 13
 
 
 14void arch_switch_to(struct task_struct *to)
 15{
 16	int err = arch_switch_tls(to);
 17	if (!err)
 18		return;
 19
 20	if (err != -EINVAL)
 21		printk(KERN_WARNING "arch_switch_tls failed, errno %d, "
 22		       "not EINVAL\n", -err);
 23	else
 24		printk(KERN_WARNING "arch_switch_tls failed, errno = EINVAL\n");
 25}
 26
 27/* determines which flags the user has access to. */
 28/* 1 = access 0 = no access */
 29#define FLAG_MASK 0x00044dd5
 30
 31static const int reg_offsets[] = {
 32	[EBX] = HOST_BX,
 33	[ECX] = HOST_CX,
 34	[EDX] = HOST_DX,
 35	[ESI] = HOST_SI,
 36	[EDI] = HOST_DI,
 37	[EBP] = HOST_BP,
 38	[EAX] = HOST_AX,
 39	[DS] = HOST_DS,
 40	[ES] = HOST_ES,
 41	[FS] = HOST_FS,
 42	[GS] = HOST_GS,
 43	[EIP] = HOST_IP,
 44	[CS] = HOST_CS,
 45	[EFL] = HOST_EFLAGS,
 46	[UESP] = HOST_SP,
 47	[SS] = HOST_SS,
 48	[ORIG_EAX] = HOST_ORIG_AX,
 49};
 50
 51int putreg(struct task_struct *child, int regno, unsigned long value)
 52{
 53	regno >>= 2;
 54	switch (regno) {
 55	case EBX:
 56	case ECX:
 57	case EDX:
 58	case ESI:
 59	case EDI:
 60	case EBP:
 61	case EAX:
 62	case EIP:
 63	case UESP:
 64		break;
 65	case ORIG_EAX:
 66		/* Update the syscall number. */
 67		UPT_SYSCALL_NR(&child->thread.regs.regs) = value;
 68		break;
 69	case FS:
 70		if (value && (value & 3) != 3)
 71			return -EIO;
 72		break;
 73	case GS:
 74		if (value && (value & 3) != 3)
 75			return -EIO;
 76		break;
 77	case DS:
 78	case ES:
 79		if (value && (value & 3) != 3)
 80			return -EIO;
 81		value &= 0xffff;
 82		break;
 83	case SS:
 84	case CS:
 85		if ((value & 3) != 3)
 86			return -EIO;
 87		value &= 0xffff;
 88		break;
 89	case EFL:
 90		value &= FLAG_MASK;
 91		child->thread.regs.regs.gp[HOST_EFLAGS] |= value;
 92		return 0;
 93	default :
 94		panic("Bad register in putreg() : %d\n", regno);
 95	}
 96	child->thread.regs.regs.gp[reg_offsets[regno]] = value;
 97	return 0;
 98}
 99
100int poke_user(struct task_struct *child, long addr, long data)
101{
102	if ((addr & 3) || addr < 0)
103		return -EIO;
104
105	if (addr < MAX_REG_OFFSET)
106		return putreg(child, addr, data);
107	else if ((addr >= offsetof(struct user, u_debugreg[0])) &&
108		 (addr <= offsetof(struct user, u_debugreg[7]))) {
109		addr -= offsetof(struct user, u_debugreg[0]);
110		addr = addr >> 2;
111		if ((addr == 4) || (addr == 5))
112			return -EIO;
113		child->thread.arch.debugregs[addr] = data;
114		return 0;
115	}
116	return -EIO;
117}
118
119unsigned long getreg(struct task_struct *child, int regno)
120{
121	unsigned long mask = ~0UL;
122
123	regno >>= 2;
124	switch (regno) {
125	case FS:
126	case GS:
127	case DS:
128	case ES:
129	case SS:
130	case CS:
131		mask = 0xffff;
132		break;
133	case EIP:
134	case UESP:
135	case EAX:
136	case EBX:
137	case ECX:
138	case EDX:
139	case ESI:
140	case EDI:
141	case EBP:
142	case EFL:
143	case ORIG_EAX:
144		break;
145	default:
146		panic("Bad register in getreg() : %d\n", regno);
147	}
148	return mask & child->thread.regs.regs.gp[reg_offsets[regno]];
149}
150
151/* read the word at location addr in the USER area. */
152int peek_user(struct task_struct *child, long addr, long data)
153{
154	unsigned long tmp;
155
156	if ((addr & 3) || addr < 0)
157		return -EIO;
158
159	tmp = 0;  /* Default return condition */
160	if (addr < MAX_REG_OFFSET) {
161		tmp = getreg(child, addr);
162	}
163	else if ((addr >= offsetof(struct user, u_debugreg[0])) &&
164		 (addr <= offsetof(struct user, u_debugreg[7]))) {
165		addr -= offsetof(struct user, u_debugreg[0]);
166		addr = addr >> 2;
167		tmp = child->thread.arch.debugregs[addr];
168	}
169	return put_user(tmp, (unsigned long __user *) data);
170}
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172long subarch_ptrace(struct task_struct *child, long request,
173		    unsigned long addr, unsigned long data)
174{
175	int ret = -EIO;
176	void __user *datap = (void __user *) data;
177	switch (request) {
178	case PTRACE_GETFPREGS: /* Get the child FPU state. */
179		return copy_regset_to_user(child, task_user_regset_view(child),
180					   REGSET_FP_LEGACY,
181					   0, sizeof(struct user_i387_struct),
182					   datap);
183	case PTRACE_SETFPREGS: /* Set the child FPU state. */
184		return copy_regset_from_user(child, task_user_regset_view(child),
185					     REGSET_FP_LEGACY,
186					     0, sizeof(struct user_i387_struct),
187					     datap);
188	case PTRACE_GETFPXREGS: /* Get the child FPU state. */
189		return copy_regset_to_user(child, task_user_regset_view(child),
190					   REGSET_FP,
191					   0, sizeof(struct user_fxsr_struct),
192					   datap);
193	case PTRACE_SETFPXREGS: /* Set the child FPU state. */
194		return copy_regset_from_user(child, task_user_regset_view(child),
195					     REGSET_FP,
196					     0, sizeof(struct user_fxsr_struct),
197					     datap);
198	default:
199		ret = -EIO;
200	}
201	return ret;
202}
v6.8
  1/*
  2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  3 * Licensed under the GPL
  4 */
  5
  6#include <linux/mm.h>
  7#include <linux/sched.h>
  8#include <linux/uaccess.h>
 
  9#include <asm/ptrace-abi.h>
 10#include <registers.h>
 11#include <skas.h>
 12
 13extern int arch_switch_tls(struct task_struct *to);
 14
 15void arch_switch_to(struct task_struct *to)
 16{
 17	int err = arch_switch_tls(to);
 18	if (!err)
 19		return;
 20
 21	if (err != -EINVAL)
 22		printk(KERN_WARNING "arch_switch_tls failed, errno %d, "
 23		       "not EINVAL\n", -err);
 24	else
 25		printk(KERN_WARNING "arch_switch_tls failed, errno = EINVAL\n");
 26}
 27
 28/* determines which flags the user has access to. */
 29/* 1 = access 0 = no access */
 30#define FLAG_MASK 0x00044dd5
 31
 32static const int reg_offsets[] = {
 33	[EBX] = HOST_BX,
 34	[ECX] = HOST_CX,
 35	[EDX] = HOST_DX,
 36	[ESI] = HOST_SI,
 37	[EDI] = HOST_DI,
 38	[EBP] = HOST_BP,
 39	[EAX] = HOST_AX,
 40	[DS] = HOST_DS,
 41	[ES] = HOST_ES,
 42	[FS] = HOST_FS,
 43	[GS] = HOST_GS,
 44	[EIP] = HOST_IP,
 45	[CS] = HOST_CS,
 46	[EFL] = HOST_EFLAGS,
 47	[UESP] = HOST_SP,
 48	[SS] = HOST_SS,
 49	[ORIG_EAX] = HOST_ORIG_AX,
 50};
 51
 52int putreg(struct task_struct *child, int regno, unsigned long value)
 53{
 54	regno >>= 2;
 55	switch (regno) {
 56	case EBX:
 57	case ECX:
 58	case EDX:
 59	case ESI:
 60	case EDI:
 61	case EBP:
 62	case EAX:
 63	case EIP:
 64	case UESP:
 65		break;
 66	case ORIG_EAX:
 67		/* Update the syscall number. */
 68		UPT_SYSCALL_NR(&child->thread.regs.regs) = value;
 69		break;
 70	case FS:
 71		if (value && (value & 3) != 3)
 72			return -EIO;
 73		break;
 74	case GS:
 75		if (value && (value & 3) != 3)
 76			return -EIO;
 77		break;
 78	case DS:
 79	case ES:
 80		if (value && (value & 3) != 3)
 81			return -EIO;
 82		value &= 0xffff;
 83		break;
 84	case SS:
 85	case CS:
 86		if ((value & 3) != 3)
 87			return -EIO;
 88		value &= 0xffff;
 89		break;
 90	case EFL:
 91		value &= FLAG_MASK;
 92		child->thread.regs.regs.gp[HOST_EFLAGS] |= value;
 93		return 0;
 94	default :
 95		panic("Bad register in putreg() : %d\n", regno);
 96	}
 97	child->thread.regs.regs.gp[reg_offsets[regno]] = value;
 98	return 0;
 99}
100
101int poke_user(struct task_struct *child, long addr, long data)
102{
103	if ((addr & 3) || addr < 0)
104		return -EIO;
105
106	if (addr < MAX_REG_OFFSET)
107		return putreg(child, addr, data);
108	else if ((addr >= offsetof(struct user, u_debugreg[0])) &&
109		 (addr <= offsetof(struct user, u_debugreg[7]))) {
110		addr -= offsetof(struct user, u_debugreg[0]);
111		addr = addr >> 2;
112		if ((addr == 4) || (addr == 5))
113			return -EIO;
114		child->thread.arch.debugregs[addr] = data;
115		return 0;
116	}
117	return -EIO;
118}
119
120unsigned long getreg(struct task_struct *child, int regno)
121{
122	unsigned long mask = ~0UL;
123
124	regno >>= 2;
125	switch (regno) {
126	case FS:
127	case GS:
128	case DS:
129	case ES:
130	case SS:
131	case CS:
132		mask = 0xffff;
133		break;
134	case EIP:
135	case UESP:
136	case EAX:
137	case EBX:
138	case ECX:
139	case EDX:
140	case ESI:
141	case EDI:
142	case EBP:
143	case EFL:
144	case ORIG_EAX:
145		break;
146	default:
147		panic("Bad register in getreg() : %d\n", regno);
148	}
149	return mask & child->thread.regs.regs.gp[reg_offsets[regno]];
150}
151
152/* read the word at location addr in the USER area. */
153int peek_user(struct task_struct *child, long addr, long data)
154{
155	unsigned long tmp;
156
157	if ((addr & 3) || addr < 0)
158		return -EIO;
159
160	tmp = 0;  /* Default return condition */
161	if (addr < MAX_REG_OFFSET) {
162		tmp = getreg(child, addr);
163	}
164	else if ((addr >= offsetof(struct user, u_debugreg[0])) &&
165		 (addr <= offsetof(struct user, u_debugreg[7]))) {
166		addr -= offsetof(struct user, u_debugreg[0]);
167		addr = addr >> 2;
168		tmp = child->thread.arch.debugregs[addr];
169	}
170	return put_user(tmp, (unsigned long __user *) data);
171}
172
173static int get_fpregs(struct user_i387_struct __user *buf, struct task_struct *child)
174{
175	int err, n, cpu = task_cpu(child);
176	struct user_i387_struct fpregs;
177
178	err = save_i387_registers(userspace_pid[cpu],
179				  (unsigned long *) &fpregs);
180	if (err)
181		return err;
182
183	n = copy_to_user(buf, &fpregs, sizeof(fpregs));
184	if(n > 0)
185		return -EFAULT;
186
187	return n;
188}
189
190static int set_fpregs(struct user_i387_struct __user *buf, struct task_struct *child)
191{
192	int n, cpu = task_cpu(child);
193	struct user_i387_struct fpregs;
194
195	n = copy_from_user(&fpregs, buf, sizeof(fpregs));
196	if (n > 0)
197		return -EFAULT;
198
199	return restore_i387_registers(userspace_pid[cpu],
200				    (unsigned long *) &fpregs);
201}
202
203static int get_fpxregs(struct user_fxsr_struct __user *buf, struct task_struct *child)
204{
205	int err, n, cpu = task_cpu(child);
206	struct user_fxsr_struct fpregs;
207
208	err = save_fpx_registers(userspace_pid[cpu], (unsigned long *) &fpregs);
209	if (err)
210		return err;
211
212	n = copy_to_user(buf, &fpregs, sizeof(fpregs));
213	if(n > 0)
214		return -EFAULT;
215
216	return n;
217}
218
219static int set_fpxregs(struct user_fxsr_struct __user *buf, struct task_struct *child)
220{
221	int n, cpu = task_cpu(child);
222	struct user_fxsr_struct fpregs;
223
224	n = copy_from_user(&fpregs, buf, sizeof(fpregs));
225	if (n > 0)
226		return -EFAULT;
227
228	return restore_fpx_registers(userspace_pid[cpu],
229				     (unsigned long *) &fpregs);
230}
231
232long subarch_ptrace(struct task_struct *child, long request,
233		    unsigned long addr, unsigned long data)
234{
235	int ret = -EIO;
236	void __user *datap = (void __user *) data;
237	switch (request) {
238	case PTRACE_GETFPREGS: /* Get the child FPU state. */
239		ret = get_fpregs(datap, child);
240		break;
 
 
241	case PTRACE_SETFPREGS: /* Set the child FPU state. */
242		ret = set_fpregs(datap, child);
243		break;
 
 
244	case PTRACE_GETFPXREGS: /* Get the child FPU state. */
245		ret = get_fpxregs(datap, child);
246		break;
 
 
247	case PTRACE_SETFPXREGS: /* Set the child FPU state. */
248		ret = set_fpxregs(datap, child);
249		break;
 
 
250	default:
251		ret = -EIO;
252	}
253	return ret;
254}