1 #include <linux/mm.h> 2 #include <linux/kernel.h> 3 #include <linux/slab.h> 4 #include <linux/sched.h> 5 6 struct kmem_cache *task_xstate_cachep = NULL; 7 unsigned int xstate_size; 8 9 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) 10 { 11 *dst = *src; 12 13 if (src->thread.xstate) { 14 dst->thread.xstate = kmem_cache_alloc(task_xstate_cachep, 15 GFP_KERNEL); 16 if (!dst->thread.xstate) 17 return -ENOMEM; 18 memcpy(dst->thread.xstate, src->thread.xstate, xstate_size); 19 } 20 21 return 0; 22 } 23 24 void free_thread_xstate(struct task_struct *tsk) 25 { 26 if (tsk->thread.xstate) { 27 kmem_cache_free(task_xstate_cachep, tsk->thread.xstate); 28 tsk->thread.xstate = NULL; 29 } 30 } 31 32 void arch_release_task_struct(struct task_struct *tsk) 33 { 34 free_thread_xstate(tsk); 35 } 36 37 void arch_task_cache_init(void) 38 { 39 if (!xstate_size) 40 return; 41 42 task_xstate_cachep = kmem_cache_create("task_xstate", xstate_size, 43 __alignof__(union thread_xstate), 44 SLAB_PANIC | SLAB_NOTRACK, NULL); 45 } 46 47 #ifdef CONFIG_SH_FPU_EMU 48 # define HAVE_SOFTFP 1 49 #else 50 # define HAVE_SOFTFP 0 51 #endif 52 53 void __cpuinit init_thread_xstate(void) 54 { 55 if (boot_cpu_data.flags & CPU_HAS_FPU) 56 xstate_size = sizeof(struct sh_fpu_hard_struct); 57 else if (HAVE_SOFTFP) 58 xstate_size = sizeof(struct sh_fpu_soft_struct); 59 else 60 xstate_size = 0; 61 } 62