process.c 1.6 KB

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