USB: usbtmc: fix switch statment
[linux-2.6/mini2440.git] / kernel / exec_domain.c
blobcb8e9626c21522f9665b95d7d3500af797714494
1 /*
2 * Handling of different ABIs (personalities).
4 * We group personalities into execution domains which have their
5 * own handlers for kernel entry points, signal mapping, etc...
7 * 2001-05-06 Complete rewrite, Christoph Hellwig (hch@infradead.org)
8 */
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/kmod.h>
13 #include <linux/module.h>
14 #include <linux/personality.h>
15 #include <linux/proc_fs.h>
16 #include <linux/sched.h>
17 #include <linux/seq_file.h>
18 #include <linux/syscalls.h>
19 #include <linux/sysctl.h>
20 #include <linux/types.h>
23 static void default_handler(int, struct pt_regs *);
25 static struct exec_domain *exec_domains = &default_exec_domain;
26 static DEFINE_RWLOCK(exec_domains_lock);
29 static u_long ident_map[32] = {
30 0, 1, 2, 3, 4, 5, 6, 7,
31 8, 9, 10, 11, 12, 13, 14, 15,
32 16, 17, 18, 19, 20, 21, 22, 23,
33 24, 25, 26, 27, 28, 29, 30, 31
36 struct exec_domain default_exec_domain = {
37 .name = "Linux", /* name */
38 .handler = default_handler, /* lcall7 causes a seg fault. */
39 .pers_low = 0, /* PER_LINUX personality. */
40 .pers_high = 0, /* PER_LINUX personality. */
41 .signal_map = ident_map, /* Identity map signals. */
42 .signal_invmap = ident_map, /* - both ways. */
46 static void
47 default_handler(int segment, struct pt_regs *regp)
49 set_personality(0);
51 if (current_thread_info()->exec_domain->handler != default_handler)
52 current_thread_info()->exec_domain->handler(segment, regp);
53 else
54 send_sig(SIGSEGV, current, 1);
57 static struct exec_domain *
58 lookup_exec_domain(u_long personality)
60 struct exec_domain * ep;
61 u_long pers = personality(personality);
63 read_lock(&exec_domains_lock);
64 for (ep = exec_domains; ep; ep = ep->next) {
65 if (pers >= ep->pers_low && pers <= ep->pers_high)
66 if (try_module_get(ep->module))
67 goto out;
70 #ifdef CONFIG_MODULES
71 read_unlock(&exec_domains_lock);
72 request_module("personality-%ld", pers);
73 read_lock(&exec_domains_lock);
75 for (ep = exec_domains; ep; ep = ep->next) {
76 if (pers >= ep->pers_low && pers <= ep->pers_high)
77 if (try_module_get(ep->module))
78 goto out;
80 #endif
82 ep = &default_exec_domain;
83 out:
84 read_unlock(&exec_domains_lock);
85 return (ep);
88 int
89 register_exec_domain(struct exec_domain *ep)
91 struct exec_domain *tmp;
92 int err = -EBUSY;
94 if (ep == NULL)
95 return -EINVAL;
97 if (ep->next != NULL)
98 return -EBUSY;
100 write_lock(&exec_domains_lock);
101 for (tmp = exec_domains; tmp; tmp = tmp->next) {
102 if (tmp == ep)
103 goto out;
106 ep->next = exec_domains;
107 exec_domains = ep;
108 err = 0;
110 out:
111 write_unlock(&exec_domains_lock);
112 return (err);
116 unregister_exec_domain(struct exec_domain *ep)
118 struct exec_domain **epp;
120 epp = &exec_domains;
121 write_lock(&exec_domains_lock);
122 for (epp = &exec_domains; *epp; epp = &(*epp)->next) {
123 if (ep == *epp)
124 goto unregister;
126 write_unlock(&exec_domains_lock);
127 return -EINVAL;
129 unregister:
130 *epp = ep->next;
131 ep->next = NULL;
132 write_unlock(&exec_domains_lock);
133 return 0;
137 __set_personality(u_long personality)
139 struct exec_domain *ep, *oep;
141 ep = lookup_exec_domain(personality);
142 if (ep == current_thread_info()->exec_domain) {
143 current->personality = personality;
144 module_put(ep->module);
145 return 0;
148 current->personality = personality;
149 oep = current_thread_info()->exec_domain;
150 current_thread_info()->exec_domain = ep;
152 module_put(oep->module);
153 return 0;
156 #ifdef CONFIG_PROC_FS
157 static int execdomains_proc_show(struct seq_file *m, void *v)
159 struct exec_domain *ep;
161 read_lock(&exec_domains_lock);
162 for (ep = exec_domains; ep; ep = ep->next)
163 seq_printf(m, "%d-%d\t%-16s\t[%s]\n",
164 ep->pers_low, ep->pers_high, ep->name,
165 module_name(ep->module));
166 read_unlock(&exec_domains_lock);
167 return 0;
170 static int execdomains_proc_open(struct inode *inode, struct file *file)
172 return single_open(file, execdomains_proc_show, NULL);
175 static const struct file_operations execdomains_proc_fops = {
176 .open = execdomains_proc_open,
177 .read = seq_read,
178 .llseek = seq_lseek,
179 .release = single_release,
182 static int __init proc_execdomains_init(void)
184 proc_create("execdomains", 0, NULL, &execdomains_proc_fops);
185 return 0;
187 module_init(proc_execdomains_init);
188 #endif
190 SYSCALL_DEFINE1(personality, u_long, personality)
192 u_long old = current->personality;
194 if (personality != 0xffffffff) {
195 set_personality(personality);
196 if (current->personality != personality)
197 return -EINVAL;
200 return (long)old;
204 EXPORT_SYMBOL(register_exec_domain);
205 EXPORT_SYMBOL(unregister_exec_domain);
206 EXPORT_SYMBOL(__set_personality);