Import 2.3.1pre2
[davej-history.git] / kernel / exec_domain.c
blob3c5881ee2bed14ed2fea1581961624fa0665be55
1 #include <linux/mm.h>
2 #include <linux/smp_lock.h>
3 #include <linux/module.h>
5 static asmlinkage void no_lcall7(struct pt_regs * regs);
8 static unsigned long ident_map[32] = {
9 0, 1, 2, 3, 4, 5, 6, 7,
10 8, 9, 10, 11, 12, 13, 14, 15,
11 16, 17, 18, 19, 20, 21, 22, 23,
12 24, 25, 26, 27, 28, 29, 30, 31
15 struct exec_domain default_exec_domain = {
16 "Linux", /* name */
17 no_lcall7, /* lcall7 causes a seg fault. */
18 0, 0xff, /* All personalities. */
19 ident_map, /* Identity map signals. */
20 ident_map, /* - both ways. */
21 NULL, /* No usage counter. */
22 NULL /* Nothing after this in the list. */
25 static struct exec_domain *exec_domains = &default_exec_domain;
28 static asmlinkage void no_lcall7(struct pt_regs * regs)
32 * This may have been a static linked SVr4 binary, so we would have the
33 * personality set incorrectly. Check to see whether SVr4 is available,
34 * and use it, otherwise give the user a SEGV.
36 if (current->exec_domain && current->exec_domain->module)
37 __MOD_DEC_USE_COUNT(current->exec_domain->module);
39 current->personality = PER_SVR4;
40 current->exec_domain = lookup_exec_domain(current->personality);
42 if (current->exec_domain && current->exec_domain->module)
43 __MOD_INC_USE_COUNT(current->exec_domain->module);
45 if (current->exec_domain && current->exec_domain->handler
46 && current->exec_domain->handler != no_lcall7) {
47 current->exec_domain->handler(regs);
48 return;
51 send_sig(SIGSEGV, current, 1);
54 struct exec_domain *lookup_exec_domain(unsigned long personality)
56 unsigned long pers = personality & PER_MASK;
57 struct exec_domain *it;
59 for (it=exec_domains; it; it=it->next)
60 if (pers >= it->pers_low
61 && pers <= it->pers_high)
62 return it;
64 /* Should never get this far. */
65 printk(KERN_ERR "No execution domain for personality 0x%02lx\n", pers);
66 return NULL;
69 int register_exec_domain(struct exec_domain *it)
71 struct exec_domain *tmp;
73 if (!it)
74 return -EINVAL;
75 if (it->next)
76 return -EBUSY;
77 for (tmp=exec_domains; tmp; tmp=tmp->next)
78 if (tmp == it)
79 return -EBUSY;
80 it->next = exec_domains;
81 exec_domains = it;
82 return 0;
85 int unregister_exec_domain(struct exec_domain *it)
87 struct exec_domain ** tmp;
89 tmp = &exec_domains;
90 while (*tmp) {
91 if (it == *tmp) {
92 *tmp = it->next;
93 it->next = NULL;
94 return 0;
96 tmp = &(*tmp)->next;
98 return -EINVAL;
101 asmlinkage int sys_personality(unsigned long personality)
103 struct exec_domain *it;
104 unsigned long old_personality;
105 int ret;
107 lock_kernel();
108 ret = current->personality;
109 if (personality == 0xffffffff)
110 goto out;
112 ret = -EINVAL;
113 it = lookup_exec_domain(personality);
114 if (!it)
115 goto out;
117 old_personality = current->personality;
118 if (current->exec_domain && current->exec_domain->module)
119 __MOD_DEC_USE_COUNT(current->exec_domain->module);
120 current->personality = personality;
121 current->exec_domain = it;
122 if (current->exec_domain->module)
123 __MOD_INC_USE_COUNT(current->exec_domain->module);
124 ret = old_personality;
125 out:
126 unlock_kernel();
127 return ret;