process.c 1.7 KB

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