1 #include <linux/sched/signal.h>
2 #include <linux/sched/task.h>
3 #include <linux/sched/task_stack.h>
4 #include <linux/slab.h>
5 #include <asm/processor.h>
8 #include <asm/ptrace.h>
10 int init_fpu(struct task_struct *tsk)
12 if (tsk_used_math(tsk)) {
13 if ((boot_cpu_data.flags & CPU_HAS_FPU) && tsk == current)
14 unlazy_fpu(tsk, task_pt_regs(tsk));
19 * Memory allocation at the first usage of the FPU and other state.
21 if (!tsk->thread.xstate) {
22 tsk->thread.xstate = kmem_cache_alloc(task_xstate_cachep,
24 if (!tsk->thread.xstate)
28 if (boot_cpu_data.flags & CPU_HAS_FPU) {
29 struct sh_fpu_hard_struct *fp = &tsk->thread.xstate->hardfpu;
30 memset(fp, 0, xstate_size);
31 fp->fpscr = FPSCR_INIT;
33 struct sh_fpu_soft_struct *fp = &tsk->thread.xstate->softfpu;
34 memset(fp, 0, xstate_size);
35 fp->fpscr = FPSCR_INIT;
38 set_stopped_child_used_math(tsk);
43 void __fpu_state_restore(void)
45 struct task_struct *tsk = current;
49 task_thread_info(tsk)->status |= TS_USEDFPU;
50 tsk->thread.fpu_counter++;
53 void fpu_state_restore(struct pt_regs *regs)
55 struct task_struct *tsk = current;
57 if (unlikely(!user_mode(regs))) {
58 printk(KERN_ERR "BUG: FPU is used in kernel mode.\n");
63 if (!tsk_used_math(tsk)) {
66 * does a slab alloc which can sleep
72 do_group_exit(SIGKILL);
80 __fpu_state_restore();
83 BUILD_TRAP_HANDLER(fpu_state_restore)
87 fpu_state_restore(regs);
89 #endif /* CONFIG_SH_FPU */