1 #include <linux/sched/signal.h>
2 #include <linux/slab.h>
3 #include <asm/processor.h>
6 #include <asm/ptrace.h>
8 int init_fpu(struct task_struct *tsk)
10 if (tsk_used_math(tsk)) {
11 if ((boot_cpu_data.flags & CPU_HAS_FPU) && tsk == current)
12 unlazy_fpu(tsk, task_pt_regs(tsk));
17 * Memory allocation at the first usage of the FPU and other state.
19 if (!tsk->thread.xstate) {
20 tsk->thread.xstate = kmem_cache_alloc(task_xstate_cachep,
22 if (!tsk->thread.xstate)
26 if (boot_cpu_data.flags & CPU_HAS_FPU) {
27 struct sh_fpu_hard_struct *fp = &tsk->thread.xstate->hardfpu;
28 memset(fp, 0, xstate_size);
29 fp->fpscr = FPSCR_INIT;
31 struct sh_fpu_soft_struct *fp = &tsk->thread.xstate->softfpu;
32 memset(fp, 0, xstate_size);
33 fp->fpscr = FPSCR_INIT;
36 set_stopped_child_used_math(tsk);
41 void __fpu_state_restore(void)
43 struct task_struct *tsk = current;
47 task_thread_info(tsk)->status |= TS_USEDFPU;
48 tsk->thread.fpu_counter++;
51 void fpu_state_restore(struct pt_regs *regs)
53 struct task_struct *tsk = current;
55 if (unlikely(!user_mode(regs))) {
56 printk(KERN_ERR "BUG: FPU is used in kernel mode.\n");
61 if (!tsk_used_math(tsk)) {
64 * does a slab alloc which can sleep
70 do_group_exit(SIGKILL);
78 __fpu_state_restore();
81 BUILD_TRAP_HANDLER(fpu_state_restore)
85 fpu_state_restore(regs);
87 #endif /* CONFIG_SH_FPU */