process.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #ifdef CONFIG_SUPERH32
  24. unlazy_fpu(src, task_pt_regs(src));
  25. #endif
  26. *dst = *src;
  27. if (src->thread.xstate) {
  28. dst->thread.xstate = kmem_cache_alloc(task_xstate_cachep,
  29. GFP_KERNEL);
  30. if (!dst->thread.xstate)
  31. return -ENOMEM;
  32. memcpy(dst->thread.xstate, src->thread.xstate, xstate_size);
  33. }
  34. return 0;
  35. }
  36. void free_thread_xstate(struct task_struct *tsk)
  37. {
  38. if (tsk->thread.xstate) {
  39. kmem_cache_free(task_xstate_cachep, tsk->thread.xstate);
  40. tsk->thread.xstate = NULL;
  41. }
  42. }
  43. void arch_release_task_struct(struct task_struct *tsk)
  44. {
  45. free_thread_xstate(tsk);
  46. }
  47. void arch_task_cache_init(void)
  48. {
  49. if (!xstate_size)
  50. return;
  51. task_xstate_cachep = kmem_cache_create("task_xstate", xstate_size,
  52. __alignof__(union thread_xstate),
  53. SLAB_PANIC, NULL);
  54. }
  55. #ifdef CONFIG_SH_FPU_EMU
  56. # define HAVE_SOFTFP 1
  57. #else
  58. # define HAVE_SOFTFP 0
  59. #endif
  60. void init_thread_xstate(void)
  61. {
  62. if (boot_cpu_data.flags & CPU_HAS_FPU)
  63. xstate_size = sizeof(struct sh_fpu_hard_struct);
  64. else if (HAVE_SOFTFP)
  65. xstate_size = sizeof(struct sh_fpu_soft_struct);
  66. else
  67. xstate_size = 0;
  68. }