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)
10 #include <linux/config.h>
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/kmod.h>
14 #include <linux/module.h>
15 #include <linux/personality.h>
16 #include <linux/sched.h>
17 #include <linux/sysctl.h>
18 #include <linux/types.h>
21 static void default_handler(int, struct pt_regs *);
23 static struct exec_domain *exec_domains = &default_exec_domain;
24 static rwlock_t exec_domains_lock = RW_LOCK_UNLOCKED;
27 static u_long ident_map[32] = {
28 0, 1, 2, 3, 4, 5, 6, 7,
29 8, 9, 10, 11, 12, 13, 14, 15,
30 16, 17, 18, 19, 20, 21, 22, 23,
31 24, 25, 26, 27, 28, 29, 30, 31
34 struct exec_domain default_exec_domain = {
36 default_handler, /* lcall7 causes a seg fault. */
37 0, 0, /* PER_LINUX personality. */
38 ident_map, /* Identity map signals. */
39 ident_map, /* - both ways. */
44 default_handler(int segment, struct pt_regs *regp)
49 * This may have been a static linked SVr4 binary, so we would
50 * have the personality set incorrectly. Or it might have been
51 * a Solaris/x86 binary. We can tell which because the former
52 * uses lcall7, while the latter used lcall 0x27.
53 * Try to find or load the appropriate personality, and fall back
54 * to just forcing a SEGV.
56 * XXX: this is IA32-specific and should be moved to the MD-tree.
61 pers = abi_defhandler_lcall7;
68 set_personality(pers);
70 if (current->exec_domain->handler != default_handler)
71 current->exec_domain->handler(segment, regp);
73 send_sig(SIGSEGV, current, 1);
76 static struct exec_domain *
77 lookup_exec_domain(u_long personality)
79 struct exec_domain * ep;
80 u_long pers = personality(personality);
82 read_lock(&exec_domains_lock);
83 for (ep = exec_domains; ep; ep = ep->next) {
84 if (pers >= ep->pers_low && pers <= ep->pers_high)
85 if (try_inc_mod_count(ep->module))
90 read_unlock(&exec_domains_lock);
93 sprintf(buffer, "personality-%ld", pers);
94 request_module(buffer);
96 read_lock(&exec_domains_lock);
98 for (ep = exec_domains; ep; ep = ep->next) {
99 if (pers >= ep->pers_low && pers <= ep->pers_high)
100 if (try_inc_mod_count(ep->module))
105 ep = &default_exec_domain;
107 read_unlock(&exec_domains_lock);
112 register_exec_domain(struct exec_domain *ep)
114 struct exec_domain *tmp;
120 if (ep->next != NULL)
123 write_lock(&exec_domains_lock);
124 for (tmp = exec_domains; tmp; tmp = tmp->next) {
129 ep->next = exec_domains;
134 write_unlock(&exec_domains_lock);
139 unregister_exec_domain(struct exec_domain *ep)
141 struct exec_domain **epp;
144 write_lock(&exec_domains_lock);
145 for (epp = &exec_domains; *epp; epp = &(*epp)->next) {
149 write_unlock(&exec_domains_lock);
155 write_unlock(&exec_domains_lock);
160 __set_personality(u_long personality)
162 struct exec_domain *ep, *oep;
164 ep = lookup_exec_domain(personality);
165 if (ep == current->exec_domain) {
166 current->personality = personality;
170 if (atomic_read(¤t->fs->count) != 1) {
171 struct fs_struct *fsp, *ofsp;
173 fsp = copy_fs_struct(current->fs);
182 task_unlock(current);
188 * At that point we are guaranteed to be the sole owner of
192 current->personality = personality;
193 oep = current->exec_domain;
194 current->exec_domain = ep;
197 put_exec_domain(oep);
199 printk(KERN_DEBUG "[%s:%d]: set personality to %lx\n",
200 current->comm, current->pid, personality);
205 get_exec_domain_list(char *page)
207 struct exec_domain *ep;
210 read_lock(&exec_domains_lock);
211 for (ep = exec_domains; ep && len < PAGE_SIZE - 80; ep = ep->next)
212 len += sprintf(page + len, "%d-%d\t%-16s\t[%s]\n",
213 ep->pers_low, ep->pers_high, ep->name,
214 ep->module ? ep->module->name : "kernel");
215 read_unlock(&exec_domains_lock);
220 sys_personality(u_long personality)
222 u_long old = current->personality;;
224 if (personality != 0xffffffff) {
225 set_personality(personality);
226 if (current->personality != personality)
234 EXPORT_SYMBOL(register_exec_domain);
235 EXPORT_SYMBOL(unregister_exec_domain);
236 EXPORT_SYMBOL(__set_personality);
239 * We have to have all sysctl handling for the Linux-ABI
240 * in one place as the dynamic registration of sysctls is
241 * horribly crufty in Linux <= 2.4.
243 * I hope the new sysctl schemes discussed for future versions
244 * will obsolete this.
249 u_long abi_defhandler_coff = PER_SCOSVR3;
250 u_long abi_defhandler_elf = PER_LINUX;
251 u_long abi_defhandler_lcall7 = PER_SVR4;
252 u_long abi_defhandler_libcso = PER_SVR4;
254 int abi_fake_utsname;
256 static struct ctl_table abi_table[] = {
257 {ABI_DEFHANDLER_COFF, "defhandler_coff", &abi_defhandler_coff,
258 sizeof(int), 0644, NULL, &proc_doulongvec_minmax},
259 {ABI_DEFHANDLER_ELF, "defhandler_elf", &abi_defhandler_elf,
260 sizeof(int), 0644, NULL, &proc_doulongvec_minmax},
261 {ABI_DEFHANDLER_LCALL7, "defhandler_lcall7", &abi_defhandler_lcall7,
262 sizeof(int), 0644, NULL, &proc_doulongvec_minmax},
263 {ABI_DEFHANDLER_LIBCSO, "defhandler_libcso", &abi_defhandler_libcso,
264 sizeof(int), 0644, NULL, &proc_doulongvec_minmax},
265 {ABI_TRACE, "trace", &abi_traceflg,
266 sizeof(u_int), 0644, NULL, &proc_dointvec},
267 {ABI_FAKE_UTSNAME, "fake_utsname", &abi_fake_utsname,
268 sizeof(int), 0644, NULL, &proc_dointvec},
272 static struct ctl_table abi_root_table[] = {
273 {CTL_ABI, "abi", NULL, 0, 0555, abi_table},
278 abi_register_sysctl(void)
280 register_sysctl_table(abi_root_table, 1);
284 __initcall(abi_register_sysctl);
287 EXPORT_SYMBOL(abi_defhandler_coff);
288 EXPORT_SYMBOL(abi_defhandler_elf);
289 EXPORT_SYMBOL(abi_defhandler_lcall7);
290 EXPORT_SYMBOL(abi_defhandler_libcso);
291 EXPORT_SYMBOL(abi_traceflg);
292 EXPORT_SYMBOL(abi_fake_utsname);