process.c 1.3 KB

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