reboot.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  4. */
  5. #include <linux/sched/signal.h>
  6. #include <linux/sched/task.h>
  7. #include <linux/sched/mm.h>
  8. #include <linux/spinlock.h>
  9. #include <linux/slab.h>
  10. #include <linux/oom.h>
  11. #include <linux/reboot.h>
  12. #include <kern_util.h>
  13. #include <os.h>
  14. #include <skas.h>
  15. void (*pm_power_off)(void);
  16. EXPORT_SYMBOL(pm_power_off);
  17. static void kill_off_processes(void)
  18. {
  19. struct task_struct *p;
  20. int pid;
  21. read_lock(&tasklist_lock);
  22. for_each_process(p) {
  23. struct task_struct *t;
  24. t = find_lock_task_mm(p);
  25. if (!t)
  26. continue;
  27. pid = t->mm->context.id.pid;
  28. task_unlock(t);
  29. os_kill_ptraced_process(pid, 1);
  30. }
  31. read_unlock(&tasklist_lock);
  32. }
  33. void uml_cleanup(void)
  34. {
  35. kmalloc_ok = 0;
  36. do_uml_exitcalls();
  37. kill_off_processes();
  38. }
  39. void machine_restart(char * __unused)
  40. {
  41. uml_cleanup();
  42. reboot_skas();
  43. }
  44. void machine_power_off(void)
  45. {
  46. uml_cleanup();
  47. halt_skas();
  48. }
  49. void machine_halt(void)
  50. {
  51. machine_power_off();
  52. }
  53. static int sys_power_off_handler(struct sys_off_data *data)
  54. {
  55. machine_power_off();
  56. return 0;
  57. }
  58. static int register_power_off(void)
  59. {
  60. register_sys_off_handler(SYS_OFF_MODE_POWER_OFF,
  61. SYS_OFF_PRIO_DEFAULT,
  62. sys_power_off_handler, NULL);
  63. return 0;
  64. }
  65. __initcall(register_power_off);