blob: 3d15243ce69234c3ddbac961ef58b0282247a4e4 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include "linux/sched.h"
Anton Vorontsov9bd0a072012-05-31 16:26:25 -07007#include "linux/spinlock.h"
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include "linux/slab.h"
Anton Vorontsov2c922c52012-05-31 16:26:26 -07009#include "linux/oom.h"
Jeff Dikeedea1382008-02-04 22:30:46 -080010#include "kern_util.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include "os.h"
Jeff Dike77bf4402007-10-16 01:26:58 -070012#include "skas.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Eric W. Biederman5e382912006-01-08 01:03:46 -080014void (*pm_power_off)(void);
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016static void kill_off_processes(void)
17{
Jeff Dikec5d4bb12008-02-04 22:31:14 -080018 if (proc_mm)
Jeff Dike77bf4402007-10-16 01:26:58 -070019 /*
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 Weinbergerf1c93e42011-07-25 17:12:55 -070025 int pid;
Jeff Dike77bf4402007-10-16 01:26:58 -070026
Anton Vorontsov9bd0a072012-05-31 16:26:25 -070027 read_lock(&tasklist_lock);
Jeff Dikec5d4bb12008-02-04 22:31:14 -080028 for_each_process(p) {
Anton Vorontsov2c922c52012-05-31 16:26:26 -070029 struct task_struct *t;
30
31 t = find_lock_task_mm(p);
32 if (!t)
Jeff Dike77bf4402007-10-16 01:26:58 -070033 continue;
Anton Vorontsov2c922c52012-05-31 16:26:26 -070034 pid = t->mm->context.id.u.pid;
35 task_unlock(t);
Jeff Dike77bf4402007-10-16 01:26:58 -070036 os_kill_ptraced_process(pid, 1);
37 }
Anton Vorontsov9bd0a072012-05-31 16:26:25 -070038 read_unlock(&tasklist_lock);
Jeff Dike77bf4402007-10-16 01:26:58 -070039 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070040}
41
42void uml_cleanup(void)
43{
Jeff Dikeba180fd2007-10-16 01:27:00 -070044 kmalloc_ok = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 do_uml_exitcalls();
Jeff Dike026549d2005-06-25 14:55:23 -070046 kill_off_processes();
Linus Torvalds1da177e2005-04-16 15:20:36 -070047}
48
49void machine_restart(char * __unused)
50{
Jeff Dikeba180fd2007-10-16 01:27:00 -070051 uml_cleanup();
Jeff Dike6aa802c2007-10-16 01:26:56 -070052 reboot_skas();
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
Linus Torvalds1da177e2005-04-16 15:20:36 -070055void machine_power_off(void)
56{
Jeff Dikeba180fd2007-10-16 01:27:00 -070057 uml_cleanup();
Jeff Dike6aa802c2007-10-16 01:26:56 -070058 halt_skas();
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061void machine_halt(void)
62{
63 machine_power_off();
64}