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/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>
21 #include <linux/fs_struct.h>
24 static void default_handler(int, struct pt_regs
*);
26 static struct exec_domain
*exec_domains
= &default_exec_domain
;
27 static DEFINE_RWLOCK(exec_domains_lock
);
30 static unsigned long ident_map
[32] = {
31 0, 1, 2, 3, 4, 5, 6, 7,
32 8, 9, 10, 11, 12, 13, 14, 15,
33 16, 17, 18, 19, 20, 21, 22, 23,
34 24, 25, 26, 27, 28, 29, 30, 31
37 struct exec_domain default_exec_domain
= {
38 .name
= "Linux", /* name */
39 .handler
= default_handler
, /* lcall7 causes a seg fault. */
40 .pers_low
= 0, /* PER_LINUX personality. */
41 .pers_high
= 0, /* PER_LINUX personality. */
42 .signal_map
= ident_map
, /* Identity map signals. */
43 .signal_invmap
= ident_map
, /* - both ways. */
48 default_handler(int segment
, struct pt_regs
*regp
)
52 if (current_thread_info()->exec_domain
->handler
!= default_handler
)
53 current_thread_info()->exec_domain
->handler(segment
, regp
);
55 send_sig(SIGSEGV
, current
, 1);
58 static struct exec_domain
*
59 lookup_exec_domain(unsigned int personality
)
61 unsigned int pers
= personality(personality
);
62 struct exec_domain
*ep
;
64 read_lock(&exec_domains_lock
);
65 for (ep
= exec_domains
; ep
; ep
= ep
->next
) {
66 if (pers
>= ep
->pers_low
&& pers
<= ep
->pers_high
)
67 if (try_module_get(ep
->module
))
72 read_unlock(&exec_domains_lock
);
73 request_module("personality-%d", pers
);
74 read_lock(&exec_domains_lock
);
76 for (ep
= exec_domains
; ep
; ep
= ep
->next
) {
77 if (pers
>= ep
->pers_low
&& pers
<= ep
->pers_high
)
78 if (try_module_get(ep
->module
))
83 ep
= &default_exec_domain
;
85 read_unlock(&exec_domains_lock
);
90 register_exec_domain(struct exec_domain
*ep
)
92 struct exec_domain
*tmp
;
101 write_lock(&exec_domains_lock
);
102 for (tmp
= exec_domains
; tmp
; tmp
= tmp
->next
) {
107 ep
->next
= exec_domains
;
112 write_unlock(&exec_domains_lock
);
115 EXPORT_SYMBOL(register_exec_domain
);
118 unregister_exec_domain(struct exec_domain
*ep
)
120 struct exec_domain
**epp
;
123 write_lock(&exec_domains_lock
);
124 for (epp
= &exec_domains
; *epp
; epp
= &(*epp
)->next
) {
128 write_unlock(&exec_domains_lock
);
134 write_unlock(&exec_domains_lock
);
137 EXPORT_SYMBOL(unregister_exec_domain
);
139 int __set_personality(unsigned int personality
)
141 struct exec_domain
*oep
= current_thread_info()->exec_domain
;
143 current_thread_info()->exec_domain
= lookup_exec_domain(personality
);
144 current
->personality
= personality
;
145 module_put(oep
->module
);
149 EXPORT_SYMBOL(__set_personality
);
151 #ifdef CONFIG_PROC_FS
152 static int execdomains_proc_show(struct seq_file
*m
, void *v
)
154 struct exec_domain
*ep
;
156 read_lock(&exec_domains_lock
);
157 for (ep
= exec_domains
; ep
; ep
= ep
->next
)
158 seq_printf(m
, "%d-%d\t%-16s\t[%s]\n",
159 ep
->pers_low
, ep
->pers_high
, ep
->name
,
160 module_name(ep
->module
));
161 read_unlock(&exec_domains_lock
);
165 static int execdomains_proc_open(struct inode
*inode
, struct file
*file
)
167 return single_open(file
, execdomains_proc_show
, NULL
);
170 static const struct file_operations execdomains_proc_fops
= {
171 .open
= execdomains_proc_open
,
174 .release
= single_release
,
177 static int __init
proc_execdomains_init(void)
179 proc_create("execdomains", 0, NULL
, &execdomains_proc_fops
);
182 module_init(proc_execdomains_init
);
185 SYSCALL_DEFINE1(personality
, unsigned int, personality
)
187 unsigned int old
= current
->personality
;
189 if (personality
!= 0xffffffff)
190 set_personality(personality
);