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