blob: 71f3e9217cf2a7ac0e39619fd7b8c9178e00b5e9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jeff Dikeba180fd2007-10-16 01:27:00 -07002 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Licensed under the GPL
4 */
5
Ingo Molnar3f07c012017-02-08 18:51:30 +01006#include <linux/sched/signal.h>
Ingo Molnar29930022017-02-08 18:51:36 +01007#include <linux/sched/task.h>
Ingo Molnar589ee622017-02-04 00:16:44 +01008#include <linux/sched/mm.h>
Al Viro37185b32012-10-08 03:27:32 +01009#include <linux/spinlock.h>
10#include <linux/slab.h>
11#include <linux/oom.h>
12#include <kern_util.h>
13#include <os.h>
14#include <skas.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Eric W. Biederman5e382912006-01-08 01:03:46 -080016void (*pm_power_off)(void);
Richard Weinberger0834f9c2016-01-25 23:24:21 +010017EXPORT_SYMBOL(pm_power_off);
Eric W. Biederman5e382912006-01-08 01:03:46 -080018
Linus Torvalds1da177e2005-04-16 15:20:36 -070019static void kill_off_processes(void)
20{
Richard Weinbergerd0b5e152015-03-18 21:31:27 +010021 struct task_struct *p;
22 int pid;
Jeff Dike77bf4402007-10-16 01:26:58 -070023
Richard Weinbergerd0b5e152015-03-18 21:31:27 +010024 read_lock(&tasklist_lock);
25 for_each_process(p) {
26 struct task_struct *t;
Anton Vorontsov2c922c52012-05-31 16:26:26 -070027
Richard Weinbergerd0b5e152015-03-18 21:31:27 +010028 t = find_lock_task_mm(p);
29 if (!t)
30 continue;
31 pid = t->mm->context.id.u.pid;
32 task_unlock(t);
33 os_kill_ptraced_process(pid, 1);
Jeff Dike77bf4402007-10-16 01:26:58 -070034 }
Richard Weinbergerd0b5e152015-03-18 21:31:27 +010035 read_unlock(&tasklist_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
38void uml_cleanup(void)
39{
Jeff Dikeba180fd2007-10-16 01:27:00 -070040 kmalloc_ok = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 do_uml_exitcalls();
Jeff Dike026549d22005-06-25 14:55:23 -070042 kill_off_processes();
Linus Torvalds1da177e2005-04-16 15:20:36 -070043}
44
45void machine_restart(char * __unused)
46{
Jeff Dikeba180fd2007-10-16 01:27:00 -070047 uml_cleanup();
Jeff Dike6aa802c2007-10-16 01:26:56 -070048 reboot_skas();
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051void machine_power_off(void)
52{
Jeff Dikeba180fd2007-10-16 01:27:00 -070053 uml_cleanup();
Jeff Dike6aa802c2007-10-16 01:26:56 -070054 halt_skas();
Linus Torvalds1da177e2005-04-16 15:20:36 -070055}
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057void machine_halt(void)
58{
59 machine_power_off();
60}