diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/sparc64/solaris/misc.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/sparc64/solaris/misc.c')
-rw-r--r-- | arch/sparc64/solaris/misc.c | 784 |
1 files changed, 784 insertions, 0 deletions
diff --git a/arch/sparc64/solaris/misc.c b/arch/sparc64/solaris/misc.c new file mode 100644 index 000000000000..15b4cfe07557 --- /dev/null +++ b/arch/sparc64/solaris/misc.c | |||
@@ -0,0 +1,784 @@ | |||
1 | /* $Id: misc.c,v 1.36 2002/02/09 19:49:31 davem Exp $ | ||
2 | * misc.c: Miscellaneous syscall emulation for Solaris | ||
3 | * | ||
4 | * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) | ||
5 | */ | ||
6 | |||
7 | #include <linux/config.h> | ||
8 | #include <linux/module.h> | ||
9 | #include <linux/types.h> | ||
10 | #include <linux/smp_lock.h> | ||
11 | #include <linux/utsname.h> | ||
12 | #include <linux/limits.h> | ||
13 | #include <linux/mm.h> | ||
14 | #include <linux/smp.h> | ||
15 | #include <linux/mman.h> | ||
16 | #include <linux/file.h> | ||
17 | #include <linux/timex.h> | ||
18 | #include <linux/major.h> | ||
19 | #include <linux/compat.h> | ||
20 | |||
21 | #include <asm/uaccess.h> | ||
22 | #include <asm/string.h> | ||
23 | #include <asm/oplib.h> | ||
24 | #include <asm/idprom.h> | ||
25 | #include <asm/smp.h> | ||
26 | |||
27 | #include "conv.h" | ||
28 | |||
29 | /* Conversion from Linux to Solaris errnos. 0-34 are identity mapped. | ||
30 | Some Linux errnos (EPROCLIM, EDOTDOT, ERREMOTE, EUCLEAN, ENOTNAM, | ||
31 | ENAVAIL, EISNAM, EREMOTEIO, ENOMEDIUM, EMEDIUMTYPE) have no Solaris | ||
32 | equivalents. I return EINVAL in that case, which is very wrong. If | ||
33 | someone suggest a better value for them, you're welcomed. | ||
34 | On the other side, Solaris ECANCELED and ENOTSUP have no Linux equivalents, | ||
35 | but that doesn't matter here. --jj */ | ||
36 | int solaris_err_table[] = { | ||
37 | /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, | ||
38 | /* 10 */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, | ||
39 | /* 20 */ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, | ||
40 | /* 30 */ 30, 31, 32, 33, 34, 22, 150, 149, 95, 96, | ||
41 | /* 40 */ 97, 98, 99, 120, 121, 122, 123, 124, 125, 126, | ||
42 | /* 50 */ 127, 128, 129, 130, 131, 132, 133, 134, 143, 144, | ||
43 | /* 60 */ 145, 146, 90, 78, 147, 148, 93, 22, 94, 49, | ||
44 | /* 70 */ 151, 66, 60, 62, 63, 35, 77, 36, 45, 46, | ||
45 | /* 80 */ 64, 22, 67, 68, 69, 70, 71, 74, 22, 82, | ||
46 | /* 90 */ 89, 92, 79, 81, 37, 38, 39, 40, 41, 42, | ||
47 | /* 100 */ 43, 44, 50, 51, 52, 53, 54, 55, 56, 57, | ||
48 | /* 110 */ 87, 61, 84, 65, 83, 80, 91, 22, 22, 22, | ||
49 | /* 120 */ 22, 22, 88, 86, 85, 22, 22, | ||
50 | }; | ||
51 | |||
52 | #define SOLARIS_NR_OPEN 256 | ||
53 | |||
54 | static u32 do_solaris_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u64 off) | ||
55 | { | ||
56 | struct file *file = NULL; | ||
57 | unsigned long retval, ret_type; | ||
58 | |||
59 | /* Do we need it here? */ | ||
60 | set_personality(PER_SVR4); | ||
61 | if (flags & MAP_NORESERVE) { | ||
62 | static int cnt; | ||
63 | |||
64 | if (cnt < 5) { | ||
65 | printk("%s: unimplemented Solaris MAP_NORESERVE mmap() flag\n", | ||
66 | current->comm); | ||
67 | cnt++; | ||
68 | } | ||
69 | flags &= ~MAP_NORESERVE; | ||
70 | } | ||
71 | retval = -EBADF; | ||
72 | if(!(flags & MAP_ANONYMOUS)) { | ||
73 | if(fd >= SOLARIS_NR_OPEN) | ||
74 | goto out; | ||
75 | file = fget(fd); | ||
76 | if (!file) | ||
77 | goto out; | ||
78 | else { | ||
79 | struct inode * inode = file->f_dentry->d_inode; | ||
80 | if(imajor(inode) == MEM_MAJOR && | ||
81 | iminor(inode) == 5) { | ||
82 | flags |= MAP_ANONYMOUS; | ||
83 | fput(file); | ||
84 | file = NULL; | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | |||
89 | retval = -EINVAL; | ||
90 | len = PAGE_ALIGN(len); | ||
91 | if(!(flags & MAP_FIXED)) | ||
92 | addr = 0; | ||
93 | else if (len > 0xf0000000UL || addr > 0xf0000000UL - len) | ||
94 | goto out_putf; | ||
95 | ret_type = flags & _MAP_NEW; | ||
96 | flags &= ~_MAP_NEW; | ||
97 | |||
98 | down_write(¤t->mm->mmap_sem); | ||
99 | flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); | ||
100 | retval = do_mmap(file, | ||
101 | (unsigned long) addr, (unsigned long) len, | ||
102 | (unsigned long) prot, (unsigned long) flags, off); | ||
103 | up_write(¤t->mm->mmap_sem); | ||
104 | if(!ret_type) | ||
105 | retval = ((retval < 0xf0000000) ? 0 : retval); | ||
106 | |||
107 | out_putf: | ||
108 | if (file) | ||
109 | fput(file); | ||
110 | out: | ||
111 | return (u32) retval; | ||
112 | } | ||
113 | |||
114 | asmlinkage u32 solaris_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u32 off) | ||
115 | { | ||
116 | return do_solaris_mmap(addr, len, prot, flags, fd, (u64) off); | ||
117 | } | ||
118 | |||
119 | asmlinkage u32 solaris_mmap64(struct pt_regs *regs, u32 len, u32 prot, u32 flags, u32 fd, u32 offhi) | ||
120 | { | ||
121 | u32 offlo; | ||
122 | |||
123 | if (regs->u_regs[UREG_G1]) { | ||
124 | if (get_user (offlo, (u32 __user *)(long)((u32)regs->u_regs[UREG_I6] + 0x5c))) | ||
125 | return -EFAULT; | ||
126 | } else { | ||
127 | if (get_user (offlo, (u32 __user *)(long)((u32)regs->u_regs[UREG_I6] + 0x60))) | ||
128 | return -EFAULT; | ||
129 | } | ||
130 | return do_solaris_mmap((u32)regs->u_regs[UREG_I0], len, prot, flags, fd, (((u64)offhi)<<32)|offlo); | ||
131 | } | ||
132 | |||
133 | asmlinkage int solaris_brk(u32 brk) | ||
134 | { | ||
135 | int (*sunos_brk)(u32) = (int (*)(u32))SUNOS(17); | ||
136 | |||
137 | return sunos_brk(brk); | ||
138 | } | ||
139 | |||
140 | static int __set_utsfield(char __user *to, int to_size, | ||
141 | const char *from, int from_size, | ||
142 | int dotchop, int countfrom) | ||
143 | { | ||
144 | int len = countfrom ? (to_size > from_size ? | ||
145 | from_size : to_size) : to_size; | ||
146 | int off; | ||
147 | |||
148 | if (copy_to_user(to, from, len)) | ||
149 | return -EFAULT; | ||
150 | |||
151 | off = len < to_size? len: len - 1; | ||
152 | if (dotchop) { | ||
153 | const char *p = strnchr(from, len, '.'); | ||
154 | if (p) off = p - from; | ||
155 | } | ||
156 | |||
157 | if (__put_user('\0', to + off)) | ||
158 | return -EFAULT; | ||
159 | |||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | #define set_utsfield(to, from, dotchop, countfrom) \ | ||
164 | __set_utsfield((to), sizeof(to), \ | ||
165 | (from), sizeof(from), \ | ||
166 | (dotchop), (countfrom)) | ||
167 | |||
168 | struct sol_uname { | ||
169 | char sysname[9]; | ||
170 | char nodename[9]; | ||
171 | char release[9]; | ||
172 | char version[9]; | ||
173 | char machine[9]; | ||
174 | }; | ||
175 | |||
176 | struct sol_utsname { | ||
177 | char sysname[257]; | ||
178 | char nodename[257]; | ||
179 | char release[257]; | ||
180 | char version[257]; | ||
181 | char machine[257]; | ||
182 | }; | ||
183 | |||
184 | static char *machine(void) | ||
185 | { | ||
186 | switch (sparc_cpu_model) { | ||
187 | case sun4: return "sun4"; | ||
188 | case sun4c: return "sun4c"; | ||
189 | case sun4e: return "sun4e"; | ||
190 | case sun4m: return "sun4m"; | ||
191 | case sun4d: return "sun4d"; | ||
192 | case sun4u: return "sun4u"; | ||
193 | default: return "sparc"; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | static char *platform(char *buffer) | ||
198 | { | ||
199 | int len; | ||
200 | |||
201 | *buffer = 0; | ||
202 | len = prom_getproperty(prom_root_node, "name", buffer, 256); | ||
203 | if(len > 0) | ||
204 | buffer[len] = 0; | ||
205 | if (*buffer) { | ||
206 | char *p; | ||
207 | |||
208 | for (p = buffer; *p; p++) | ||
209 | if (*p == '/' || *p == ' ') *p = '_'; | ||
210 | return buffer; | ||
211 | } | ||
212 | |||
213 | return "sun4u"; | ||
214 | } | ||
215 | |||
216 | static char *serial(char *buffer) | ||
217 | { | ||
218 | int node = prom_getchild(prom_root_node); | ||
219 | int len; | ||
220 | |||
221 | node = prom_searchsiblings(node, "options"); | ||
222 | *buffer = 0; | ||
223 | len = prom_getproperty(node, "system-board-serial#", buffer, 256); | ||
224 | if(len > 0) | ||
225 | buffer[len] = 0; | ||
226 | if (!*buffer) | ||
227 | return "4512348717234"; | ||
228 | else | ||
229 | return buffer; | ||
230 | } | ||
231 | |||
232 | asmlinkage int solaris_utssys(u32 buf, u32 flags, int which, u32 buf2) | ||
233 | { | ||
234 | struct sol_uname __user *v = A(buf); | ||
235 | int err; | ||
236 | |||
237 | switch (which) { | ||
238 | case 0: /* old uname */ | ||
239 | /* Let's cheat */ | ||
240 | err = set_utsfield(v->sysname, "SunOS", 1, 0); | ||
241 | down_read(&uts_sem); | ||
242 | err |= set_utsfield(v->nodename, system_utsname.nodename, | ||
243 | 1, 1); | ||
244 | up_read(&uts_sem); | ||
245 | err |= set_utsfield(v->release, "2.6", 0, 0); | ||
246 | err |= set_utsfield(v->version, "Generic", 0, 0); | ||
247 | err |= set_utsfield(v->machine, machine(), 0, 0); | ||
248 | return (err ? -EFAULT : 0); | ||
249 | case 2: /* ustat */ | ||
250 | return -ENOSYS; | ||
251 | case 3: /* fusers */ | ||
252 | return -ENOSYS; | ||
253 | default: | ||
254 | return -ENOSYS; | ||
255 | } | ||
256 | } | ||
257 | |||
258 | asmlinkage int solaris_utsname(u32 buf) | ||
259 | { | ||
260 | struct sol_utsname __user *v = A(buf); | ||
261 | int err; | ||
262 | |||
263 | /* Why should we not lie a bit? */ | ||
264 | down_read(&uts_sem); | ||
265 | err = set_utsfield(v->sysname, "SunOS", 0, 0); | ||
266 | err |= set_utsfield(v->nodename, system_utsname.nodename, 1, 1); | ||
267 | err |= set_utsfield(v->release, "5.6", 0, 0); | ||
268 | err |= set_utsfield(v->version, "Generic", 0, 0); | ||
269 | err |= set_utsfield(v->machine, machine(), 0, 0); | ||
270 | up_read(&uts_sem); | ||
271 | |||
272 | return (err ? -EFAULT : 0); | ||
273 | } | ||
274 | |||
275 | #define SI_SYSNAME 1 /* return name of operating system */ | ||
276 | #define SI_HOSTNAME 2 /* return name of node */ | ||
277 | #define SI_RELEASE 3 /* return release of operating system */ | ||
278 | #define SI_VERSION 4 /* return version field of utsname */ | ||
279 | #define SI_MACHINE 5 /* return kind of machine */ | ||
280 | #define SI_ARCHITECTURE 6 /* return instruction set arch */ | ||
281 | #define SI_HW_SERIAL 7 /* return hardware serial number */ | ||
282 | #define SI_HW_PROVIDER 8 /* return hardware manufacturer */ | ||
283 | #define SI_SRPC_DOMAIN 9 /* return secure RPC domain */ | ||
284 | #define SI_PLATFORM 513 /* return platform identifier */ | ||
285 | |||
286 | asmlinkage int solaris_sysinfo(int cmd, u32 buf, s32 count) | ||
287 | { | ||
288 | char *p, *q, *r; | ||
289 | char buffer[256]; | ||
290 | int len; | ||
291 | |||
292 | /* Again, we cheat :)) */ | ||
293 | switch (cmd) { | ||
294 | case SI_SYSNAME: r = "SunOS"; break; | ||
295 | case SI_HOSTNAME: | ||
296 | r = buffer + 256; | ||
297 | down_read(&uts_sem); | ||
298 | for (p = system_utsname.nodename, q = buffer; | ||
299 | q < r && *p && *p != '.'; *q++ = *p++); | ||
300 | up_read(&uts_sem); | ||
301 | *q = 0; | ||
302 | r = buffer; | ||
303 | break; | ||
304 | case SI_RELEASE: r = "5.6"; break; | ||
305 | case SI_MACHINE: r = machine(); break; | ||
306 | case SI_ARCHITECTURE: r = "sparc"; break; | ||
307 | case SI_HW_PROVIDER: r = "Sun_Microsystems"; break; | ||
308 | case SI_HW_SERIAL: r = serial(buffer); break; | ||
309 | case SI_PLATFORM: r = platform(buffer); break; | ||
310 | case SI_SRPC_DOMAIN: r = ""; break; | ||
311 | case SI_VERSION: r = "Generic"; break; | ||
312 | default: return -EINVAL; | ||
313 | } | ||
314 | len = strlen(r) + 1; | ||
315 | if (count < len) { | ||
316 | if (copy_to_user(A(buf), r, count - 1) || | ||
317 | __put_user(0, (char __user *)A(buf) + count - 1)) | ||
318 | return -EFAULT; | ||
319 | } else { | ||
320 | if (copy_to_user(A(buf), r, len)) | ||
321 | return -EFAULT; | ||
322 | } | ||
323 | return len; | ||
324 | } | ||
325 | |||
326 | #define SOLARIS_CONFIG_NGROUPS 2 | ||
327 | #define SOLARIS_CONFIG_CHILD_MAX 3 | ||
328 | #define SOLARIS_CONFIG_OPEN_FILES 4 | ||
329 | #define SOLARIS_CONFIG_POSIX_VER 5 | ||
330 | #define SOLARIS_CONFIG_PAGESIZE 6 | ||
331 | #define SOLARIS_CONFIG_CLK_TCK 7 | ||
332 | #define SOLARIS_CONFIG_XOPEN_VER 8 | ||
333 | #define SOLARIS_CONFIG_PROF_TCK 10 | ||
334 | #define SOLARIS_CONFIG_NPROC_CONF 11 | ||
335 | #define SOLARIS_CONFIG_NPROC_ONLN 12 | ||
336 | #define SOLARIS_CONFIG_AIO_LISTIO_MAX 13 | ||
337 | #define SOLARIS_CONFIG_AIO_MAX 14 | ||
338 | #define SOLARIS_CONFIG_AIO_PRIO_DELTA_MAX 15 | ||
339 | #define SOLARIS_CONFIG_DELAYTIMER_MAX 16 | ||
340 | #define SOLARIS_CONFIG_MQ_OPEN_MAX 17 | ||
341 | #define SOLARIS_CONFIG_MQ_PRIO_MAX 18 | ||
342 | #define SOLARIS_CONFIG_RTSIG_MAX 19 | ||
343 | #define SOLARIS_CONFIG_SEM_NSEMS_MAX 20 | ||
344 | #define SOLARIS_CONFIG_SEM_VALUE_MAX 21 | ||
345 | #define SOLARIS_CONFIG_SIGQUEUE_MAX 22 | ||
346 | #define SOLARIS_CONFIG_SIGRT_MIN 23 | ||
347 | #define SOLARIS_CONFIG_SIGRT_MAX 24 | ||
348 | #define SOLARIS_CONFIG_TIMER_MAX 25 | ||
349 | #define SOLARIS_CONFIG_PHYS_PAGES 26 | ||
350 | #define SOLARIS_CONFIG_AVPHYS_PAGES 27 | ||
351 | |||
352 | asmlinkage int solaris_sysconf(int id) | ||
353 | { | ||
354 | switch (id) { | ||
355 | case SOLARIS_CONFIG_NGROUPS: return NGROUPS_MAX; | ||
356 | case SOLARIS_CONFIG_CHILD_MAX: return CHILD_MAX; | ||
357 | case SOLARIS_CONFIG_OPEN_FILES: return OPEN_MAX; | ||
358 | case SOLARIS_CONFIG_POSIX_VER: return 199309; | ||
359 | case SOLARIS_CONFIG_PAGESIZE: return PAGE_SIZE; | ||
360 | case SOLARIS_CONFIG_XOPEN_VER: return 3; | ||
361 | case SOLARIS_CONFIG_CLK_TCK: | ||
362 | case SOLARIS_CONFIG_PROF_TCK: | ||
363 | return sparc64_get_clock_tick(smp_processor_id()); | ||
364 | #ifdef CONFIG_SMP | ||
365 | case SOLARIS_CONFIG_NPROC_CONF: return NR_CPUS; | ||
366 | case SOLARIS_CONFIG_NPROC_ONLN: return num_online_cpus(); | ||
367 | #else | ||
368 | case SOLARIS_CONFIG_NPROC_CONF: return 1; | ||
369 | case SOLARIS_CONFIG_NPROC_ONLN: return 1; | ||
370 | #endif | ||
371 | case SOLARIS_CONFIG_SIGRT_MIN: return 37; | ||
372 | case SOLARIS_CONFIG_SIGRT_MAX: return 44; | ||
373 | case SOLARIS_CONFIG_PHYS_PAGES: | ||
374 | case SOLARIS_CONFIG_AVPHYS_PAGES: | ||
375 | { | ||
376 | struct sysinfo s; | ||
377 | |||
378 | si_meminfo(&s); | ||
379 | if (id == SOLARIS_CONFIG_PHYS_PAGES) | ||
380 | return s.totalram >>= PAGE_SHIFT; | ||
381 | else | ||
382 | return s.freeram >>= PAGE_SHIFT; | ||
383 | } | ||
384 | /* XXX support these as well -jj */ | ||
385 | case SOLARIS_CONFIG_AIO_LISTIO_MAX: return -EINVAL; | ||
386 | case SOLARIS_CONFIG_AIO_MAX: return -EINVAL; | ||
387 | case SOLARIS_CONFIG_AIO_PRIO_DELTA_MAX: return -EINVAL; | ||
388 | case SOLARIS_CONFIG_DELAYTIMER_MAX: return -EINVAL; | ||
389 | case SOLARIS_CONFIG_MQ_OPEN_MAX: return -EINVAL; | ||
390 | case SOLARIS_CONFIG_MQ_PRIO_MAX: return -EINVAL; | ||
391 | case SOLARIS_CONFIG_RTSIG_MAX: return -EINVAL; | ||
392 | case SOLARIS_CONFIG_SEM_NSEMS_MAX: return -EINVAL; | ||
393 | case SOLARIS_CONFIG_SEM_VALUE_MAX: return -EINVAL; | ||
394 | case SOLARIS_CONFIG_SIGQUEUE_MAX: return -EINVAL; | ||
395 | case SOLARIS_CONFIG_TIMER_MAX: return -EINVAL; | ||
396 | default: return -EINVAL; | ||
397 | } | ||
398 | } | ||
399 | |||
400 | asmlinkage int solaris_procids(int cmd, s32 pid, s32 pgid) | ||
401 | { | ||
402 | int ret; | ||
403 | |||
404 | switch (cmd) { | ||
405 | case 0: /* getpgrp */ | ||
406 | return process_group(current); | ||
407 | case 1: /* setpgrp */ | ||
408 | { | ||
409 | int (*sys_setpgid)(pid_t,pid_t) = | ||
410 | (int (*)(pid_t,pid_t))SYS(setpgid); | ||
411 | |||
412 | /* can anyone explain me the difference between | ||
413 | Solaris setpgrp and setsid? */ | ||
414 | ret = sys_setpgid(0, 0); | ||
415 | if (ret) return ret; | ||
416 | current->signal->tty = NULL; | ||
417 | return process_group(current); | ||
418 | } | ||
419 | case 2: /* getsid */ | ||
420 | { | ||
421 | int (*sys_getsid)(pid_t) = (int (*)(pid_t))SYS(getsid); | ||
422 | return sys_getsid(pid); | ||
423 | } | ||
424 | case 3: /* setsid */ | ||
425 | { | ||
426 | int (*sys_setsid)(void) = (int (*)(void))SYS(setsid); | ||
427 | return sys_setsid(); | ||
428 | } | ||
429 | case 4: /* getpgid */ | ||
430 | { | ||
431 | int (*sys_getpgid)(pid_t) = (int (*)(pid_t))SYS(getpgid); | ||
432 | return sys_getpgid(pid); | ||
433 | } | ||
434 | case 5: /* setpgid */ | ||
435 | { | ||
436 | int (*sys_setpgid)(pid_t,pid_t) = | ||
437 | (int (*)(pid_t,pid_t))SYS(setpgid); | ||
438 | return sys_setpgid(pid,pgid); | ||
439 | } | ||
440 | } | ||
441 | return -EINVAL; | ||
442 | } | ||
443 | |||
444 | asmlinkage int solaris_gettimeofday(u32 tim) | ||
445 | { | ||
446 | int (*sys_gettimeofday)(struct timeval *, struct timezone *) = | ||
447 | (int (*)(struct timeval *, struct timezone *))SYS(gettimeofday); | ||
448 | |||
449 | return sys_gettimeofday((struct timeval *)(u64)tim, NULL); | ||
450 | } | ||
451 | |||
452 | #define RLIM_SOL_INFINITY32 0x7fffffff | ||
453 | #define RLIM_SOL_SAVED_MAX32 0x7ffffffe | ||
454 | #define RLIM_SOL_SAVED_CUR32 0x7ffffffd | ||
455 | #define RLIM_SOL_INFINITY ((u64)-3) | ||
456 | #define RLIM_SOL_SAVED_MAX ((u64)-2) | ||
457 | #define RLIM_SOL_SAVED_CUR ((u64)-1) | ||
458 | #define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x) | ||
459 | #define RLIMIT_SOL_NOFILE 5 | ||
460 | #define RLIMIT_SOL_VMEM 6 | ||
461 | |||
462 | struct rlimit32 { | ||
463 | u32 rlim_cur; | ||
464 | u32 rlim_max; | ||
465 | }; | ||
466 | |||
467 | asmlinkage int solaris_getrlimit(unsigned int resource, struct rlimit32 __user *rlim) | ||
468 | { | ||
469 | struct rlimit r; | ||
470 | int ret; | ||
471 | mm_segment_t old_fs = get_fs (); | ||
472 | int (*sys_getrlimit)(unsigned int, struct rlimit *) = | ||
473 | (int (*)(unsigned int, struct rlimit *))SYS(getrlimit); | ||
474 | |||
475 | if (resource > RLIMIT_SOL_VMEM) | ||
476 | return -EINVAL; | ||
477 | switch (resource) { | ||
478 | case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break; | ||
479 | case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break; | ||
480 | default: break; | ||
481 | } | ||
482 | set_fs (KERNEL_DS); | ||
483 | ret = sys_getrlimit(resource, &r); | ||
484 | set_fs (old_fs); | ||
485 | if (!ret) { | ||
486 | if (r.rlim_cur == RLIM_INFINITY) | ||
487 | r.rlim_cur = RLIM_SOL_INFINITY32; | ||
488 | else if ((u64)r.rlim_cur > RLIM_SOL_INFINITY32) | ||
489 | r.rlim_cur = RLIM_SOL_SAVED_CUR32; | ||
490 | if (r.rlim_max == RLIM_INFINITY) | ||
491 | r.rlim_max = RLIM_SOL_INFINITY32; | ||
492 | else if ((u64)r.rlim_max > RLIM_SOL_INFINITY32) | ||
493 | r.rlim_max = RLIM_SOL_SAVED_MAX32; | ||
494 | ret = put_user (r.rlim_cur, &rlim->rlim_cur); | ||
495 | ret |= __put_user (r.rlim_max, &rlim->rlim_max); | ||
496 | } | ||
497 | return ret; | ||
498 | } | ||
499 | |||
500 | asmlinkage int solaris_setrlimit(unsigned int resource, struct rlimit32 __user *rlim) | ||
501 | { | ||
502 | struct rlimit r, rold; | ||
503 | int ret; | ||
504 | mm_segment_t old_fs = get_fs (); | ||
505 | int (*sys_getrlimit)(unsigned int, struct rlimit __user *) = | ||
506 | (int (*)(unsigned int, struct rlimit __user *))SYS(getrlimit); | ||
507 | int (*sys_setrlimit)(unsigned int, struct rlimit __user *) = | ||
508 | (int (*)(unsigned int, struct rlimit __user *))SYS(setrlimit); | ||
509 | |||
510 | if (resource > RLIMIT_SOL_VMEM) | ||
511 | return -EINVAL; | ||
512 | switch (resource) { | ||
513 | case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break; | ||
514 | case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break; | ||
515 | default: break; | ||
516 | } | ||
517 | if (get_user (r.rlim_cur, &rlim->rlim_cur) || | ||
518 | __get_user (r.rlim_max, &rlim->rlim_max)) | ||
519 | return -EFAULT; | ||
520 | set_fs (KERNEL_DS); | ||
521 | ret = sys_getrlimit(resource, &rold); | ||
522 | if (!ret) { | ||
523 | if (r.rlim_cur == RLIM_SOL_INFINITY32) | ||
524 | r.rlim_cur = RLIM_INFINITY; | ||
525 | else if (r.rlim_cur == RLIM_SOL_SAVED_CUR32) | ||
526 | r.rlim_cur = rold.rlim_cur; | ||
527 | else if (r.rlim_cur == RLIM_SOL_SAVED_MAX32) | ||
528 | r.rlim_cur = rold.rlim_max; | ||
529 | if (r.rlim_max == RLIM_SOL_INFINITY32) | ||
530 | r.rlim_max = RLIM_INFINITY; | ||
531 | else if (r.rlim_max == RLIM_SOL_SAVED_CUR32) | ||
532 | r.rlim_max = rold.rlim_cur; | ||
533 | else if (r.rlim_max == RLIM_SOL_SAVED_MAX32) | ||
534 | r.rlim_max = rold.rlim_max; | ||
535 | ret = sys_setrlimit(resource, &r); | ||
536 | } | ||
537 | set_fs (old_fs); | ||
538 | return ret; | ||
539 | } | ||
540 | |||
541 | asmlinkage int solaris_getrlimit64(unsigned int resource, struct rlimit __user *rlim) | ||
542 | { | ||
543 | struct rlimit r; | ||
544 | int ret; | ||
545 | mm_segment_t old_fs = get_fs (); | ||
546 | int (*sys_getrlimit)(unsigned int, struct rlimit __user *) = | ||
547 | (int (*)(unsigned int, struct rlimit __user *))SYS(getrlimit); | ||
548 | |||
549 | if (resource > RLIMIT_SOL_VMEM) | ||
550 | return -EINVAL; | ||
551 | switch (resource) { | ||
552 | case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break; | ||
553 | case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break; | ||
554 | default: break; | ||
555 | } | ||
556 | set_fs (KERNEL_DS); | ||
557 | ret = sys_getrlimit(resource, &r); | ||
558 | set_fs (old_fs); | ||
559 | if (!ret) { | ||
560 | if (r.rlim_cur == RLIM_INFINITY) | ||
561 | r.rlim_cur = RLIM_SOL_INFINITY; | ||
562 | if (r.rlim_max == RLIM_INFINITY) | ||
563 | r.rlim_max = RLIM_SOL_INFINITY; | ||
564 | ret = put_user (r.rlim_cur, &rlim->rlim_cur); | ||
565 | ret |= __put_user (r.rlim_max, &rlim->rlim_max); | ||
566 | } | ||
567 | return ret; | ||
568 | } | ||
569 | |||
570 | asmlinkage int solaris_setrlimit64(unsigned int resource, struct rlimit __user *rlim) | ||
571 | { | ||
572 | struct rlimit r, rold; | ||
573 | int ret; | ||
574 | mm_segment_t old_fs = get_fs (); | ||
575 | int (*sys_getrlimit)(unsigned int, struct rlimit __user *) = | ||
576 | (int (*)(unsigned int, struct rlimit __user *))SYS(getrlimit); | ||
577 | int (*sys_setrlimit)(unsigned int, struct rlimit __user *) = | ||
578 | (int (*)(unsigned int, struct rlimit __user *))SYS(setrlimit); | ||
579 | |||
580 | if (resource > RLIMIT_SOL_VMEM) | ||
581 | return -EINVAL; | ||
582 | switch (resource) { | ||
583 | case RLIMIT_SOL_NOFILE: resource = RLIMIT_NOFILE; break; | ||
584 | case RLIMIT_SOL_VMEM: resource = RLIMIT_AS; break; | ||
585 | default: break; | ||
586 | } | ||
587 | if (get_user (r.rlim_cur, &rlim->rlim_cur) || | ||
588 | __get_user (r.rlim_max, &rlim->rlim_max)) | ||
589 | return -EFAULT; | ||
590 | set_fs (KERNEL_DS); | ||
591 | ret = sys_getrlimit(resource, &rold); | ||
592 | if (!ret) { | ||
593 | if (r.rlim_cur == RLIM_SOL_INFINITY) | ||
594 | r.rlim_cur = RLIM_INFINITY; | ||
595 | else if (r.rlim_cur == RLIM_SOL_SAVED_CUR) | ||
596 | r.rlim_cur = rold.rlim_cur; | ||
597 | else if (r.rlim_cur == RLIM_SOL_SAVED_MAX) | ||
598 | r.rlim_cur = rold.rlim_max; | ||
599 | if (r.rlim_max == RLIM_SOL_INFINITY) | ||
600 | r.rlim_max = RLIM_INFINITY; | ||
601 | else if (r.rlim_max == RLIM_SOL_SAVED_CUR) | ||
602 | r.rlim_max = rold.rlim_cur; | ||
603 | else if (r.rlim_max == RLIM_SOL_SAVED_MAX) | ||
604 | r.rlim_max = rold.rlim_max; | ||
605 | ret = sys_setrlimit(resource, &r); | ||
606 | } | ||
607 | set_fs (old_fs); | ||
608 | return ret; | ||
609 | } | ||
610 | |||
611 | struct sol_ntptimeval { | ||
612 | struct compat_timeval time; | ||
613 | s32 maxerror; | ||
614 | s32 esterror; | ||
615 | }; | ||
616 | |||
617 | struct sol_timex { | ||
618 | u32 modes; | ||
619 | s32 offset; | ||
620 | s32 freq; | ||
621 | s32 maxerror; | ||
622 | s32 esterror; | ||
623 | s32 status; | ||
624 | s32 constant; | ||
625 | s32 precision; | ||
626 | s32 tolerance; | ||
627 | s32 ppsfreq; | ||
628 | s32 jitter; | ||
629 | s32 shift; | ||
630 | s32 stabil; | ||
631 | s32 jitcnt; | ||
632 | s32 calcnt; | ||
633 | s32 errcnt; | ||
634 | s32 stbcnt; | ||
635 | }; | ||
636 | |||
637 | asmlinkage int solaris_ntp_gettime(struct sol_ntptimeval __user *ntp) | ||
638 | { | ||
639 | int (*sys_adjtimex)(struct timex __user *) = | ||
640 | (int (*)(struct timex __user *))SYS(adjtimex); | ||
641 | struct timex t; | ||
642 | int ret; | ||
643 | mm_segment_t old_fs = get_fs(); | ||
644 | |||
645 | set_fs(KERNEL_DS); | ||
646 | t.modes = 0; | ||
647 | ret = sys_adjtimex(&t); | ||
648 | set_fs(old_fs); | ||
649 | if (ret < 0) | ||
650 | return ret; | ||
651 | ret = put_user (t.time.tv_sec, &ntp->time.tv_sec); | ||
652 | ret |= __put_user (t.time.tv_usec, &ntp->time.tv_usec); | ||
653 | ret |= __put_user (t.maxerror, &ntp->maxerror); | ||
654 | ret |= __put_user (t.esterror, &ntp->esterror); | ||
655 | return ret; | ||
656 | } | ||
657 | |||
658 | asmlinkage int solaris_ntp_adjtime(struct sol_timex __user *txp) | ||
659 | { | ||
660 | int (*sys_adjtimex)(struct timex __user *) = | ||
661 | (int (*)(struct timex __user *))SYS(adjtimex); | ||
662 | struct timex t; | ||
663 | int ret, err; | ||
664 | mm_segment_t old_fs = get_fs(); | ||
665 | |||
666 | ret = get_user (t.modes, &txp->modes); | ||
667 | ret |= __get_user (t.offset, &txp->offset); | ||
668 | ret |= __get_user (t.freq, &txp->freq); | ||
669 | ret |= __get_user (t.maxerror, &txp->maxerror); | ||
670 | ret |= __get_user (t.esterror, &txp->esterror); | ||
671 | ret |= __get_user (t.status, &txp->status); | ||
672 | ret |= __get_user (t.constant, &txp->constant); | ||
673 | set_fs(KERNEL_DS); | ||
674 | ret = sys_adjtimex(&t); | ||
675 | set_fs(old_fs); | ||
676 | if (ret < 0) | ||
677 | return ret; | ||
678 | err = put_user (t.offset, &txp->offset); | ||
679 | err |= __put_user (t.freq, &txp->freq); | ||
680 | err |= __put_user (t.maxerror, &txp->maxerror); | ||
681 | err |= __put_user (t.esterror, &txp->esterror); | ||
682 | err |= __put_user (t.status, &txp->status); | ||
683 | err |= __put_user (t.constant, &txp->constant); | ||
684 | err |= __put_user (t.precision, &txp->precision); | ||
685 | err |= __put_user (t.tolerance, &txp->tolerance); | ||
686 | err |= __put_user (t.ppsfreq, &txp->ppsfreq); | ||
687 | err |= __put_user (t.jitter, &txp->jitter); | ||
688 | err |= __put_user (t.shift, &txp->shift); | ||
689 | err |= __put_user (t.stabil, &txp->stabil); | ||
690 | err |= __put_user (t.jitcnt, &txp->jitcnt); | ||
691 | err |= __put_user (t.calcnt, &txp->calcnt); | ||
692 | err |= __put_user (t.errcnt, &txp->errcnt); | ||
693 | err |= __put_user (t.stbcnt, &txp->stbcnt); | ||
694 | if (err) | ||
695 | return -EFAULT; | ||
696 | return ret; | ||
697 | } | ||
698 | |||
699 | asmlinkage int do_sol_unimplemented(struct pt_regs *regs) | ||
700 | { | ||
701 | printk ("Unimplemented Solaris syscall %d %08x %08x %08x %08x\n", | ||
702 | (int)regs->u_regs[UREG_G1], | ||
703 | (int)regs->u_regs[UREG_I0], | ||
704 | (int)regs->u_regs[UREG_I1], | ||
705 | (int)regs->u_regs[UREG_I2], | ||
706 | (int)regs->u_regs[UREG_I3]); | ||
707 | return -ENOSYS; | ||
708 | } | ||
709 | |||
710 | asmlinkage void solaris_register(void) | ||
711 | { | ||
712 | set_personality(PER_SVR4); | ||
713 | } | ||
714 | |||
715 | extern long solaris_to_linux_signals[], linux_to_solaris_signals[]; | ||
716 | |||
717 | struct exec_domain solaris_exec_domain = { | ||
718 | .name = "Solaris", | ||
719 | .handler = NULL, | ||
720 | .pers_low = 1, /* PER_SVR4 personality */ | ||
721 | .pers_high = 1, | ||
722 | .signal_map = solaris_to_linux_signals, | ||
723 | .signal_invmap =linux_to_solaris_signals, | ||
724 | .module = THIS_MODULE, | ||
725 | .next = NULL | ||
726 | }; | ||
727 | |||
728 | extern int init_socksys(void); | ||
729 | |||
730 | #ifdef MODULE | ||
731 | |||
732 | MODULE_AUTHOR("Jakub Jelinek (jj@ultra.linux.cz), Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)"); | ||
733 | MODULE_DESCRIPTION("Solaris binary emulation module"); | ||
734 | MODULE_LICENSE("GPL"); | ||
735 | |||
736 | #ifdef __sparc_v9__ | ||
737 | extern u32 tl0_solaris[8]; | ||
738 | #define update_ttable(x) \ | ||
739 | tl0_solaris[3] = (((long)(x) - (long)tl0_solaris - 3) >> 2) | 0x40000000; \ | ||
740 | __asm__ __volatile__ ("membar #StoreStore; flush %0" : : "r" (&tl0_solaris[3])) | ||
741 | #else | ||
742 | #endif | ||
743 | |||
744 | extern u32 solaris_sparc_syscall[]; | ||
745 | extern u32 solaris_syscall[]; | ||
746 | extern void cleanup_socksys(void); | ||
747 | |||
748 | extern u32 entry64_personality_patch; | ||
749 | |||
750 | int init_module(void) | ||
751 | { | ||
752 | int ret; | ||
753 | |||
754 | SOLDD(("Solaris module at %p\n", solaris_sparc_syscall)); | ||
755 | register_exec_domain(&solaris_exec_domain); | ||
756 | if ((ret = init_socksys())) { | ||
757 | unregister_exec_domain(&solaris_exec_domain); | ||
758 | return ret; | ||
759 | } | ||
760 | update_ttable(solaris_sparc_syscall); | ||
761 | entry64_personality_patch |= | ||
762 | (offsetof(struct task_struct, personality) + | ||
763 | (sizeof(unsigned long) - 1)); | ||
764 | __asm__ __volatile__("membar #StoreStore; flush %0" | ||
765 | : : "r" (&entry64_personality_patch)); | ||
766 | return 0; | ||
767 | } | ||
768 | |||
769 | void cleanup_module(void) | ||
770 | { | ||
771 | update_ttable(solaris_syscall); | ||
772 | cleanup_socksys(); | ||
773 | unregister_exec_domain(&solaris_exec_domain); | ||
774 | } | ||
775 | |||
776 | #else | ||
777 | int init_solaris_emul(void) | ||
778 | { | ||
779 | register_exec_domain(&solaris_exec_domain); | ||
780 | init_socksys(); | ||
781 | return 0; | ||
782 | } | ||
783 | #endif | ||
784 | |||