video: lcdc: rk3228: fix colorspace for output YCBCR
[firefly-linux-kernel-4.4.55.git] / kernel / exec_domain.c
1 /*
2  * Handling of different ABIs (personalities).
3  *
4  * We group personalities into execution domains which have their
5  * own handlers for kernel entry points, signal mapping, etc...
6  *
7  * 2001-05-06   Complete rewrite,  Christoph Hellwig (hch@infradead.org)
8  */
9
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>
22
23
24 static void default_handler(int, struct pt_regs *);
25
26 static struct exec_domain *exec_domains = &default_exec_domain;
27 static DEFINE_RWLOCK(exec_domains_lock);
28
29
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
35 };
36
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. */
44 };
45
46
47 static void
48 default_handler(int segment, struct pt_regs *regp)
49 {
50         set_personality(0);
51
52         if (current_thread_info()->exec_domain->handler != default_handler)
53                 current_thread_info()->exec_domain->handler(segment, regp);
54         else
55                 send_sig(SIGSEGV, current, 1);
56 }
57
58 static struct exec_domain *
59 lookup_exec_domain(unsigned int personality)
60 {
61         unsigned int pers = personality(personality);
62         struct exec_domain *ep;
63
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))
68                                 goto out;
69         }
70
71 #ifdef CONFIG_MODULES
72 #ifndef CONFIG_ARCH_ROCKCHIP
73         read_unlock(&exec_domains_lock);
74         request_module("personality-%d", pers);
75         read_lock(&exec_domains_lock);
76
77         for (ep = exec_domains; ep; ep = ep->next) {
78                 if (pers >= ep->pers_low && pers <= ep->pers_high)
79                         if (try_module_get(ep->module))
80                                 goto out;
81         }
82 #endif
83 #endif
84
85         ep = &default_exec_domain;
86 out:
87         read_unlock(&exec_domains_lock);
88         return (ep);
89 }
90
91 int
92 register_exec_domain(struct exec_domain *ep)
93 {
94         struct exec_domain      *tmp;
95         int                     err = -EBUSY;
96
97         if (ep == NULL)
98                 return -EINVAL;
99
100         if (ep->next != NULL)
101                 return -EBUSY;
102
103         write_lock(&exec_domains_lock);
104         for (tmp = exec_domains; tmp; tmp = tmp->next) {
105                 if (tmp == ep)
106                         goto out;
107         }
108
109         ep->next = exec_domains;
110         exec_domains = ep;
111         err = 0;
112
113 out:
114         write_unlock(&exec_domains_lock);
115         return (err);
116 }
117
118 int
119 unregister_exec_domain(struct exec_domain *ep)
120 {
121         struct exec_domain      **epp;
122
123         epp = &exec_domains;
124         write_lock(&exec_domains_lock);
125         for (epp = &exec_domains; *epp; epp = &(*epp)->next) {
126                 if (ep == *epp)
127                         goto unregister;
128         }
129         write_unlock(&exec_domains_lock);
130         return -EINVAL;
131
132 unregister:
133         *epp = ep->next;
134         ep->next = NULL;
135         write_unlock(&exec_domains_lock);
136         return 0;
137 }
138
139 int __set_personality(unsigned int personality)
140 {
141         struct exec_domain *oep = current_thread_info()->exec_domain;
142
143         current_thread_info()->exec_domain = lookup_exec_domain(personality);
144         current->personality = personality;
145         module_put(oep->module);
146
147         return 0;
148 }
149
150 #ifdef CONFIG_PROC_FS
151 static int execdomains_proc_show(struct seq_file *m, void *v)
152 {
153         struct exec_domain      *ep;
154
155         read_lock(&exec_domains_lock);
156         for (ep = exec_domains; ep; ep = ep->next)
157                 seq_printf(m, "%d-%d\t%-16s\t[%s]\n",
158                                ep->pers_low, ep->pers_high, ep->name,
159                                module_name(ep->module));
160         read_unlock(&exec_domains_lock);
161         return 0;
162 }
163
164 static int execdomains_proc_open(struct inode *inode, struct file *file)
165 {
166         return single_open(file, execdomains_proc_show, NULL);
167 }
168
169 static const struct file_operations execdomains_proc_fops = {
170         .open           = execdomains_proc_open,
171         .read           = seq_read,
172         .llseek         = seq_lseek,
173         .release        = single_release,
174 };
175
176 static int __init proc_execdomains_init(void)
177 {
178         proc_create("execdomains", 0, NULL, &execdomains_proc_fops);
179         return 0;
180 }
181 module_init(proc_execdomains_init);
182 #endif
183
184 SYSCALL_DEFINE1(personality, unsigned int, personality)
185 {
186         unsigned int old = current->personality;
187
188         if (personality != 0xffffffff)
189                 set_personality(personality);
190
191         return old;
192 }
193
194
195 EXPORT_SYMBOL(register_exec_domain);
196 EXPORT_SYMBOL(unregister_exec_domain);
197 EXPORT_SYMBOL(__set_personality);