process.c 1.6 KB

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