CHROMIUM: Add /proc/breakme support
[cascardo/linux.git] / fs / proc / breakme.c
1 #include <linux/cpumask.h>
2 #include <linux/fs.h>
3 #include <linux/gfp.h>
4 #include <linux/init.h>
5 #include <linux/interrupt.h>
6 #include <linux/kernel_stat.h>
7 #include <linux/proc_fs.h>
8 #include <linux/sched.h>
9 #include <linux/seq_file.h>
10 #include <linux/slab.h>
11 #include <linux/time.h>
12 #include <linux/irqnr.h>
13 #include <asm/cputime.h>
14 #include <asm/uaccess.h>
15
16 #define MAX_BREAKME_WRITE 64
17 static ssize_t write_breakme(struct file *file, const char __user *buf,
18                                    size_t count, loff_t *ppos)
19 {
20         char kbuf[MAX_BREAKME_WRITE + 1];
21         DEFINE_SPINLOCK(lock_me_up);
22
23         if (count) {
24                 if (count > MAX_BREAKME_WRITE)
25                         return -EINVAL;
26                 if (copy_from_user(&kbuf, buf, count))
27                         return -EFAULT;
28                 kbuf[min(count, sizeof(kbuf))-1] = '\0';
29
30                 /* Null pointer dereference */
31                 if (!strcmp(kbuf, "nullptr"))
32                         *(unsigned long *)0 = 0;
33                 /* BUG() */
34                 else if (!strcmp(kbuf, "bug"))
35                         BUG();
36                 /* Panic */
37                 else if (!strcmp(kbuf, "panic"))
38                         panic("Testing panic");
39                 /* Set up a deadlock (call this twice) */
40                 else if (!strcmp(kbuf, "deadlock"))
41                         spin_lock(&lock_me_up);
42                 /* lockup */
43                 else if (!strcmp(kbuf, "softlockup")) {
44                         while (1)
45                                 ;
46                 }
47                 /* lockup with interrupts enabled */
48                 else if (!strcmp(kbuf, "irqlockup")) {
49                         spin_lock(&lock_me_up);
50                         while (1)
51                                 ;
52                 }
53                 /* lockup with interrupts disabled */
54                 else if (!strcmp(kbuf, "nmiwatchdog")) {
55                         spin_lock_irq(&lock_me_up);
56                         while (1)
57                                 ;
58                 }
59         }
60         return count;
61 }
62
63 static struct file_operations proc_breakme_operations = {
64         .write          = write_breakme,
65 };
66
67 void __init proc_breakme_init(void)
68 {
69         proc_create("breakme", S_IWUSR, NULL, &proc_breakme_operations);
70 }