Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 2 | * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include "linux/sched.h" |
Anton Vorontsov | 9bd0a07 | 2012-05-31 16:26:25 -0700 | [diff] [blame] | 7 | #include "linux/spinlock.h" |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 8 | #include "linux/slab.h" |
Anton Vorontsov | 2c922c5 | 2012-05-31 16:26:26 -0700 | [diff] [blame] | 9 | #include "linux/oom.h" |
Jeff Dike | edea138 | 2008-02-04 22:30:46 -0800 | [diff] [blame] | 10 | #include "kern_util.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include "os.h" |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 12 | #include "skas.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
Eric W. Biederman | 5e38291 | 2006-01-08 01:03:46 -0800 | [diff] [blame] | 14 | void (*pm_power_off)(void); |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | static void kill_off_processes(void) |
| 17 | { |
Jeff Dike | c5d4bb1 | 2008-02-04 22:31:14 -0800 | [diff] [blame] | 18 | if (proc_mm) |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 19 | /* |
| 20 | * FIXME: need to loop over userspace_pids |
| 21 | */ |
| 22 | os_kill_ptraced_process(userspace_pid[0], 1); |
| 23 | else { |
| 24 | struct task_struct *p; |
Richard Weinberger | f1c93e4 | 2011-07-25 17:12:55 -0700 | [diff] [blame] | 25 | int pid; |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 26 | |
Anton Vorontsov | 9bd0a07 | 2012-05-31 16:26:25 -0700 | [diff] [blame] | 27 | read_lock(&tasklist_lock); |
Jeff Dike | c5d4bb1 | 2008-02-04 22:31:14 -0800 | [diff] [blame] | 28 | for_each_process(p) { |
Anton Vorontsov | 2c922c5 | 2012-05-31 16:26:26 -0700 | [diff] [blame] | 29 | struct task_struct *t; |
| 30 | |
| 31 | t = find_lock_task_mm(p); |
| 32 | if (!t) |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 33 | continue; |
Anton Vorontsov | 2c922c5 | 2012-05-31 16:26:26 -0700 | [diff] [blame] | 34 | pid = t->mm->context.id.u.pid; |
| 35 | task_unlock(t); |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 36 | os_kill_ptraced_process(pid, 1); |
| 37 | } |
Anton Vorontsov | 9bd0a07 | 2012-05-31 16:26:25 -0700 | [diff] [blame] | 38 | read_unlock(&tasklist_lock); |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 39 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void uml_cleanup(void) |
| 43 | { |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 44 | kmalloc_ok = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | do_uml_exitcalls(); |
Jeff Dike | 026549d | 2005-06-25 14:55:23 -0700 | [diff] [blame] | 46 | kill_off_processes(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void machine_restart(char * __unused) |
| 50 | { |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 51 | uml_cleanup(); |
Jeff Dike | 6aa802c | 2007-10-16 01:26:56 -0700 | [diff] [blame] | 52 | reboot_skas(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | void machine_power_off(void) |
| 56 | { |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 57 | uml_cleanup(); |
Jeff Dike | 6aa802c | 2007-10-16 01:26:56 -0700 | [diff] [blame] | 58 | halt_skas(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | void machine_halt(void) |
| 62 | { |
| 63 | machine_power_off(); |
| 64 | } |