process.c 1.7 KB

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